From 410426f059773c8d1c0731f7662bd05a275afa36 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 23 Feb 2022 13:00:06 +0100 Subject: [PATCH 001/846] refactor --- compiler/load/src/file.rs | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/compiler/load/src/file.rs b/compiler/load/src/file.rs index 0cfa433b12..5d5b2b7cba 100644 --- a/compiler/load/src/file.rs +++ b/compiler/load/src/file.rs @@ -2260,6 +2260,25 @@ fn load_module<'a>( ident_ids_by_module: Arc>>, ) -> Result<(ModuleId, Msg<'a>), LoadingProblem<'a>> { let module_start_time = SystemTime::now(); + + let (filename, opt_shorthand) = module_name_to_path(src_dir, module_name, arc_shorthands); + + load_filename( + arena, + filename, + false, + opt_shorthand, + module_ids, + ident_ids_by_module, + module_start_time, + ) +} + +fn module_name_to_path<'a>( + src_dir: &Path, + module_name: PQModuleName<'a>, + arc_shorthands: Arc>>>, +) -> (PathBuf, Option<&'a str>) { let mut filename = PathBuf::new(); filename.push(src_dir); @@ -2294,15 +2313,7 @@ fn load_module<'a>( // End with .roc filename.set_extension(ROC_FILE_EXTENSION); - load_filename( - arena, - filename, - false, - opt_shorthand, - module_ids, - ident_ids_by_module, - module_start_time, - ) + (filename, opt_shorthand) } /// Find a task according to the following algorithm: From d1d7cfef44a8a4872fde4f93764654ea4a265d1c Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 23 Feb 2022 17:52:13 +0100 Subject: [PATCH 002/846] reimplement Result --- compiler/constrain/src/module.rs | 47 +++++++++++++ compiler/load/src/file.rs | 99 +++++++++++++++++++++++++++ compiler/module/src/symbol.rs | 2 +- compiler/mono/src/ir.rs | 3 +- compiler/parse/src/header.rs | 2 +- compiler/region/src/all.rs | 6 +- compiler/types/src/builtin_aliases.rs | 2 + 7 files changed, 155 insertions(+), 6 deletions(-) diff --git a/compiler/constrain/src/module.rs b/compiler/constrain/src/module.rs index d116e1731a..15dc6d1c90 100644 --- a/compiler/constrain/src/module.rs +++ b/compiler/constrain/src/module.rs @@ -160,6 +160,53 @@ pub fn pre_constrain_imports( }); } None => { + if module_id == home { + continue; + } + + if module_id == ModuleId::RESULT { + let region = Region::zero(); // TODO this should be the region where this symbol was declared in its home module. Look that up! + let loc_symbol = Loc { + value: symbol, + region, + }; + + match exposed_types.get(&module_id) { + Some(ExposedModuleTypes::Valid(solved_types, new_aliases)) => { + // If the exposed value was invalid (e.g. it didn't have + // a corresponding definition), it won't have an entry + // in solved_types + if let Some(solved_type) = solved_types.get(&symbol) { + // TODO should this be a union? + for (k, v) in new_aliases.clone() { + imported_aliases.insert(k, v); + } + + imported_symbols.push(Import { + loc_symbol, + solved_type: solved_type.clone(), + }); + } + } + Some(ExposedModuleTypes::Invalid) => { + // If that module was invalid, use True constraints + // for everything imported from it. + imported_symbols.push(Import { + loc_symbol, + solved_type: SolvedType::Erroneous(Problem::InvalidModule), + }); + } + None => { + panic!( + "Could not find module {:?} in exposed_types {:?}", + module_id, exposed_types + ); + } + } + + continue; + } + let is_valid_alias = stdlib.applies.contains(&symbol) // This wasn't a builtin value or Apply; maybe it was a builtin alias. || roc_types::builtin_aliases::aliases().contains_key(&symbol); diff --git a/compiler/load/src/file.rs b/compiler/load/src/file.rs index 5d5b2b7cba..a41e0ab502 100644 --- a/compiler/load/src/file.rs +++ b/compiler/load/src/file.rs @@ -74,6 +74,8 @@ macro_rules! log { ($($arg:tt)*) => (if SHOW_MESSAGE_LOG { println!($($arg)*); } else {}) } +const BUILTIN_MODULES: &[(ModuleId, &[ModuleId])] = &[(ModuleId::RESULT, &[])]; + /// Struct storing various intermediate stages by their ModuleId #[derive(Debug, Default)] struct ModuleCache<'a> { @@ -2259,8 +2261,105 @@ fn load_module<'a>( arc_shorthands: Arc>>>, ident_ids_by_module: Arc>>, ) -> Result<(ModuleId, Msg<'a>), LoadingProblem<'a>> { + use PackageQualified::*; + let module_start_time = SystemTime::now(); + dbg!(&module_name); + + match module_name.as_inner().as_str() { + "Result" => { + let parse_start = SystemTime::now(); + let parse_header_duration = parse_start.elapsed().unwrap(); + + // Insert the first entries for this module's timings + let mut module_timing = ModuleTiming::new(module_start_time); + + module_timing.read_roc_file = Default::default(); + module_timing.parse_header = parse_header_duration; + + let filename = PathBuf::from("Result.roc"); + + const EXPOSES: &[Loc] = &[ + Loc::at_zero(ExposedName::new("Result")), + Loc::at_zero(ExposedName::new("isOk")), + Loc::at_zero(ExposedName::new("isErr")), + Loc::at_zero(ExposedName::new("map")), + Loc::at_zero(ExposedName::new("mapErr")), + Loc::at_zero(ExposedName::new("after")), + Loc::at_zero(ExposedName::new("withDefault")), + ]; + let imports = &[]; + + let info = HeaderInfo { + loc_name: Loc { + region: Region::zero(), + value: ModuleNameEnum::Interface(roc_parse::header::ModuleName::new("Result")), + }, + filename, + is_root_module: false, + opt_shorthand: None, + packages: &[], + exposes: &EXPOSES, + imports, + extra: HeaderFor::Interface, + }; + + let src_bytes = r#" + Result ok err : [ Ok ok, Err err ] + + isOk : Result ok err -> Bool + isOk = \result -> + when result is + Ok _ -> True + Err _ -> False + + isErr : Result ok err -> Bool + isErr = \result -> + when result is + Ok _ -> False + Err _ -> True + + withDefault : Result ok err, ok -> ok + withDefault = \result, default -> + when result is + Ok value -> value + Err _ -> default + + map : Result a err, (a -> b) -> Result b err + map = \result, transform -> + when result is + Ok v -> Ok (transform v) + Err e -> Err e + + mapErr : Result ok a, (a -> b) -> Result ok b + mapErr = \result, transform -> + when result is + Ok v -> Ok v + Err e -> Err (transform e) + + after : Result a err, (a -> Result b err) -> Result b err + after = \result, transform -> + when result is + Ok v -> transform v + Err e -> Err e + "#; + + let parse_state = roc_parse::state::State::new(src_bytes.as_bytes()); + + return Ok(send_header( + info, + parse_state, + module_ids, + ident_ids_by_module, + module_timing, + )); + } + _ => { + // fall through + } + } + let (filename, opt_shorthand) = module_name_to_path(src_dir, module_name, arc_shorthands); load_filename( diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index 82778fa6d0..d2a39ba9d2 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -1143,7 +1143,7 @@ define_builtins! { 57 LIST_SORT_DESC_COMPARE: "#sortDescCompare" } 5 RESULT: "Result" => { - 0 RESULT_RESULT: "Result" imported // the Result.Result type alias + 0 RESULT_RESULT: "Result" // the Result.Result type alias 1 RESULT_OK: "Ok" imported // Result.Result a e = [ Ok a, Err e ] // NB: not strictly needed; used for finding global tag names in error suggestions 2 RESULT_ERR: "Err" imported // Result.Result a e = [ Ok a, Err e ] diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 300c4272ef..af8c66b7ac 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -1108,7 +1108,8 @@ impl<'a, 'i> Env<'a, 'i> { } pub fn is_imported_symbol(&self, symbol: Symbol) -> bool { - symbol.module_id() != self.home && !symbol.is_builtin() + // symbol.module_id() != self.home && !symbol.is_builtin() + symbol.module_id() != self.home } } diff --git a/compiler/parse/src/header.rs b/compiler/parse/src/header.rs index 1a1b301f9f..6a36590965 100644 --- a/compiler/parse/src/header.rs +++ b/compiler/parse/src/header.rs @@ -88,7 +88,7 @@ impl<'a> From> for &'a str { } impl<'a> ExposedName<'a> { - pub fn new(name: &'a str) -> Self { + pub const fn new(name: &'a str) -> Self { ExposedName(name) } diff --git a/compiler/region/src/all.rs b/compiler/region/src/all.rs index a22e325f60..e273cb2a10 100644 --- a/compiler/region/src/all.rs +++ b/compiler/region/src/all.rs @@ -279,16 +279,16 @@ pub struct Loc { } impl Loc { - pub fn new(start: u32, end: u32, value: T) -> Loc { + pub const fn new(start: u32, end: u32, value: T) -> Loc { let region = Region::new(Position::new(start), Position::new(end)); Loc { region, value } } - pub fn at(region: Region, value: T) -> Loc { + pub const fn at(region: Region, value: T) -> Loc { Loc { region, value } } - pub fn at_zero(value: T) -> Loc { + pub const fn at_zero(value: T) -> Loc { let region = Region::zero(); Loc { region, value } } diff --git a/compiler/types/src/builtin_aliases.rs b/compiler/types/src/builtin_aliases.rs index f8df53a256..fc09ae90ee 100644 --- a/compiler/types/src/builtin_aliases.rs +++ b/compiler/types/src/builtin_aliases.rs @@ -319,6 +319,7 @@ pub fn aliases() -> MutMap { }, ); + /* // Result ok err : [ Ok ok, Err err ] add_alias( Symbol::RESULT_RESULT, @@ -331,6 +332,7 @@ pub fn aliases() -> MutMap { typ: result_alias_content(flex(TVAR1), flex(TVAR2)), }, ); + */ // Utf8ByteProblem : [ InvalidStartByte, UnexpectedEndOfSequence, ExpectedContinuation, OverlongEncoding, CodepointTooLarge, EncodesSurrogateHalf ] add_alias( From c0d3543d5a5fbfc5301c9debc52317d4d671f561 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 26 Feb 2022 17:52:24 +0100 Subject: [PATCH 003/846] make Str + Result work --- compiler/can/src/effect_module.rs | 2 +- compiler/can/src/module.rs | 198 +++++++++++++--------- compiler/can/src/scope.rs | 20 ++- compiler/constrain/src/module.rs | 2 +- compiler/load/src/file.rs | 261 +++++++++++++++++++++++++---- compiler/module/src/symbol.rs | 2 +- compiler/mono/src/ir.rs | 14 +- compiler/parse/src/ast.rs | 2 +- compiler/parse/src/header.rs | 9 +- compiler/solve/tests/solve_expr.rs | 15 +- examples/effect/Main.roc | 11 +- reporting/src/report.rs | 7 +- 12 files changed, 401 insertions(+), 142 deletions(-) diff --git a/compiler/can/src/effect_module.rs b/compiler/can/src/effect_module.rs index 6c04645b14..5e0a84dff4 100644 --- a/compiler/can/src/effect_module.rs +++ b/compiler/can/src/effect_module.rs @@ -12,7 +12,7 @@ use roc_region::all::{Loc, Region}; use roc_types::subs::{VarStore, Variable}; use roc_types::types::{AliasKind, Type}; -#[derive(Default, Clone, Copy)] +#[derive(Debug, Default, Clone, Copy)] pub(crate) struct HostedGeneratedFunctions { pub(crate) after: bool, pub(crate) map: bool, diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index 39936e8d6e..6d2a95e9a0 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -65,6 +65,96 @@ fn validate_generate_with<'a>( (functions, unknown) } +#[derive(Debug)] +enum GeneratedInfo<'a> { + Hosted { + effect_symbol: Symbol, + generated_functions: HostedGeneratedFunctions, + }, + Builtin { + generated_functions: &'a [Symbol], + }, + NotSpecial, +} + +impl<'a> GeneratedInfo<'a> { + fn from_header_for( + env: &mut Env, + scope: &mut Scope, + var_store: &mut VarStore, + header_for: &HeaderFor<'a>, + ) -> Self { + match header_for { + HeaderFor::Hosted { + generates, + generates_with, + } => { + let name: &str = generates.into(); + let (generated_functions, unknown_generated) = + validate_generate_with(generates_with); + + for unknown in unknown_generated { + env.problem(Problem::UnknownGeneratesWith(unknown)); + } + + let effect_symbol = scope + .introduce( + name.into(), + &env.exposed_ident_ids, + &mut env.ident_ids, + Region::zero(), + ) + .unwrap(); + + let effect_tag_name = TagName::Private(effect_symbol); + + { + let a_var = var_store.fresh(); + + let actual = crate::effect_module::build_effect_actual( + effect_tag_name, + Type::Variable(a_var), + var_store, + ); + + scope.add_alias( + effect_symbol, + Region::zero(), + vec![Loc::at_zero(("a".into(), a_var))], + actual, + AliasKind::Structural, + ); + } + + GeneratedInfo::Hosted { + effect_symbol, + generated_functions, + } + } + HeaderFor::Builtin { generates_with } => GeneratedInfo::Builtin { + generated_functions: generates_with, + }, + _ => GeneratedInfo::NotSpecial, + } + } +} + +fn has_no_implementation(expr: &Expr) -> bool { + match expr { + Expr::RuntimeError(RuntimeError::NoImplementationNamed { .. }) => true, + Expr::Closure(closure_data) + if matches!( + closure_data.loc_body.value, + Expr::RuntimeError(RuntimeError::NoImplementationNamed { .. }) + ) => + { + true + } + + _ => false, + } +} + // TODO trim these down #[allow(clippy::too_many_arguments)] pub fn canonicalize_module_defs<'a>( @@ -95,59 +185,8 @@ pub fn canonicalize_module_defs<'a>( ); } - struct Hosted { - effect_symbol: Symbol, - generated_functions: HostedGeneratedFunctions, - } - - let hosted_info = if let HeaderFor::Hosted { - generates, - generates_with, - } = header_for - { - let name: &str = generates.into(); - let (generated_functions, unknown_generated) = validate_generate_with(generates_with); - - for unknown in unknown_generated { - env.problem(Problem::UnknownGeneratesWith(unknown)); - } - - let effect_symbol = scope - .introduce( - name.into(), - &env.exposed_ident_ids, - &mut env.ident_ids, - Region::zero(), - ) - .unwrap(); - - let effect_tag_name = TagName::Private(effect_symbol); - - { - let a_var = var_store.fresh(); - - let actual = crate::effect_module::build_effect_actual( - effect_tag_name, - Type::Variable(a_var), - var_store, - ); - - scope.add_alias( - effect_symbol, - Region::zero(), - vec![Loc::at_zero(("a".into(), a_var))], - actual, - AliasKind::Structural, - ); - } - - Some(Hosted { - effect_symbol, - generated_functions, - }) - } else { - None - }; + let generated_info = + GeneratedInfo::from_header_for(&mut env, &mut scope, var_store, header_for); // Desugar operators (convert them to Apply calls, taking into account // operator precedence and associativity rules), before doing other canonicalization. @@ -206,11 +245,13 @@ pub fn canonicalize_module_defs<'a>( } else { // This is a type alias + dbg!(scope.aliases.keys().collect::>()); // the symbol should already be added to the scope when this module is canonicalized debug_assert!( scope.contains_alias(symbol), - "apparently, {:?} is not actually a type alias", - symbol + "The {:?} is not a type alias known in {:?}", + symbol, + home ); // but now we know this symbol by a different identifier, so we still need to add it to @@ -291,10 +332,10 @@ pub fn canonicalize_module_defs<'a>( (Ok(mut declarations), output) => { use crate::def::Declaration::*; - if let Some(Hosted { + if let GeneratedInfo::Hosted { effect_symbol, generated_functions, - }) = hosted_info + } = generated_info { let mut exposed_symbols = MutSet::default(); @@ -327,9 +368,23 @@ pub fn canonicalize_module_defs<'a>( // Temporary hack: we don't know exactly what symbols are hosted symbols, // and which are meant to be normal definitions without a body. So for now // we just assume they are hosted functions (meant to be provided by the platform) - if let Some(Hosted { effect_symbol, .. }) = hosted_info { - macro_rules! make_hosted_def { - () => { + if has_no_implementation(&def.loc_expr.value) { + match generated_info { + GeneratedInfo::Builtin { + generated_functions, + } => { + let symbol = def.pattern_vars.iter().next().unwrap().0; + match crate::builtins::builtin_defs_map(*symbol, var_store) { + None => { + panic!("A builtin module contains a signature without implementation") + } + Some(mut replacement_def) => { + replacement_def.annotation = def.annotation.take(); + *def = replacement_def; + } + } + } + GeneratedInfo::Hosted { effect_symbol, .. } => { let symbol = def.pattern_vars.iter().next().unwrap().0; let ident_id = symbol.ident_id(); let ident = @@ -353,27 +408,8 @@ pub fn canonicalize_module_defs<'a>( ); *def = hosted_def; - }; - } - - match &def.loc_expr.value { - Expr::RuntimeError(RuntimeError::NoImplementationNamed { - .. - }) => { - make_hosted_def!(); } - Expr::Closure(closure_data) - if matches!( - closure_data.loc_body.value, - Expr::RuntimeError( - RuntimeError::NoImplementationNamed { .. } - ) - ) => - { - make_hosted_def!(); - } - - _ => {} + _ => (), } } } @@ -408,7 +444,7 @@ pub fn canonicalize_module_defs<'a>( let mut aliases = MutMap::default(); - if let Some(Hosted { effect_symbol, .. }) = hosted_info { + if let GeneratedInfo::Hosted { effect_symbol, .. } = generated_info { // Remove this from exposed_symbols, // so that at the end of the process, // we can see if there were any diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index b3db4c9e5e..246a36d13f 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -17,7 +17,7 @@ pub struct Scope { symbols: SendMap, /// The type aliases currently in scope - aliases: SendMap, + pub aliases: SendMap, /// The current module being processed. This will be used to turn /// unqualified idents into Symbols. @@ -88,13 +88,17 @@ impl Scope { pub fn lookup(&self, ident: &Ident, region: Region) -> Result { match self.idents.get(ident) { Some((symbol, _)) => Ok(*symbol), - None => Err(RuntimeError::LookupNotInScope( - Loc { - region, - value: ident.clone(), - }, - self.idents.keys().map(|v| v.as_ref().into()).collect(), - )), + None => { + let error = RuntimeError::LookupNotInScope( + Loc { + region, + value: ident.clone(), + }, + self.idents.keys().map(|v| v.as_ref().into()).collect(), + ); + + Err(error) + } } } diff --git a/compiler/constrain/src/module.rs b/compiler/constrain/src/module.rs index 15dc6d1c90..5454a3b20d 100644 --- a/compiler/constrain/src/module.rs +++ b/compiler/constrain/src/module.rs @@ -144,7 +144,7 @@ pub fn pre_constrain_imports( // We used this module, so clearly it is not unused! unused_imports.remove(&module_id); - if module_id.is_builtin() { + if module_id.is_builtin() && module_id != ModuleId::STR { // For builtin modules, we create imports from the // hardcoded builtin map. match stdlib.types.get(&symbol) { diff --git a/compiler/load/src/file.rs b/compiler/load/src/file.rs index a41e0ab502..013a9eba7c 100644 --- a/compiler/load/src/file.rs +++ b/compiler/load/src/file.rs @@ -23,7 +23,7 @@ use roc_mono::ir::{ UpdateModeIds, }; use roc_mono::layout::{Layout, LayoutCache, LayoutProblem}; -use roc_parse::ast::{self, ExtractSpaces, Spaced, StrLiteral}; +use roc_parse::ast::{self, Collection, ExtractSpaces, Spaced, StrLiteral}; use roc_parse::header::{ExposedName, ImportsEntry, PackageEntry, PlatformHeader, To, TypedIdent}; use roc_parse::header::{HeaderFor, ModuleNameEnum, PackageName}; use roc_parse::ident::UppercaseIdent; @@ -65,7 +65,7 @@ const PKG_CONFIG_FILE_NAME: &str = "Package-Config"; /// The . in between module names like Foo.Bar.Baz const MODULE_SEPARATOR: char = '.'; -const SHOW_MESSAGE_LOG: bool = false; +const SHOW_MESSAGE_LOG: bool = true; const EXPANDED_STACK_SIZE: usize = 8 * 1024 * 1024; @@ -77,7 +77,7 @@ macro_rules! log { const BUILTIN_MODULES: &[(ModuleId, &[ModuleId])] = &[(ModuleId::RESULT, &[])]; /// Struct storing various intermediate stages by their ModuleId -#[derive(Debug, Default)] +#[derive(Debug)] struct ModuleCache<'a> { module_names: MutMap>, @@ -101,6 +101,40 @@ struct ModuleCache<'a> { sources: MutMap, } +impl Default for ModuleCache<'_> { + fn default() -> Self { + let mut module_names = MutMap::default(); + + module_names.insert( + ModuleId::RESULT, + PQModuleName::Unqualified(ModuleName::from(ModuleName::RESULT)), + ); + + module_names.insert( + ModuleId::STR, + PQModuleName::Unqualified(ModuleName::from(ModuleName::STR)), + ); + + Self { + module_names, + headers: Default::default(), + parsed: Default::default(), + aliases: Default::default(), + constrained: Default::default(), + typechecked: Default::default(), + found_specializations: Default::default(), + external_specializations_requested: Default::default(), + imports: Default::default(), + top_level_thunks: Default::default(), + documentation: Default::default(), + can_problems: Default::default(), + type_problems: Default::default(), + mono_problems: Default::default(), + sources: Default::default(), + } + } +} + fn start_phase<'a>( module_id: ModuleId, phase: Phase, @@ -130,20 +164,24 @@ fn start_phase<'a>( let task = { match phase { Phase::LoadHeader => { - let dep_name = state - .module_cache - .module_names - .get(&module_id) - .expect("module id is present") - .clone(); + let opt_dep_name = state.module_cache.module_names.get(&module_id); - BuildTask::LoadModule { - module_name: dep_name, - // Provide mutexes of ModuleIds and IdentIds by module, - // so other modules can populate them as they load. - module_ids: Arc::clone(&state.arc_modules), - shorthands: Arc::clone(&state.arc_shorthands), - ident_ids_by_module: Arc::clone(&state.ident_ids_by_module), + match opt_dep_name { + None => { + panic!("Module {:?} is not in module_cache.module_names", module_id) + } + Some(dep_name) => { + let module_name = dep_name.clone(); + + BuildTask::LoadModule { + module_name, + // Provide mutexes of ModuleIds and IdentIds by module, + // so other modules can populate them as they load. + module_ids: Arc::clone(&state.arc_modules), + shorthands: Arc::clone(&state.arc_shorthands), + ident_ids_by_module: Arc::clone(&state.ident_ids_by_module), + } + } } } Phase::Parse => { @@ -215,6 +253,8 @@ fn start_phase<'a>( } } + dbg!(module_id, &parsed.imported_modules); + BuildTask::CanonicalizeAndConstrain { parsed, dep_idents, @@ -1037,7 +1077,7 @@ fn load<'a>( ) -> Result, LoadingProblem<'a>> { // When compiling to wasm, we cannot spawn extra threads // so we have a single-threaded implementation - if cfg!(target_family = "wasm") { + if true || cfg!(target_family = "wasm") { load_single_threaded( arena, load_start, @@ -1613,7 +1653,7 @@ fn update<'a>( state.platform_path = PlatformPath::RootIsPkgConfig; } } - Interface => { + Builtin { .. } | Interface => { if header.is_root_module { debug_assert!(matches!(state.platform_path, PlatformPath::NotSpecified)); state.platform_path = PlatformPath::RootIsInterface; @@ -1649,6 +1689,37 @@ fn update<'a>( .exposed_symbols_by_module .insert(home, exposed_symbols); + // add the prelude + let mut header = header; + // let mut imports = header.package_qualified_imported_modules.clone(); + + if header.module_id != ModuleId::RESULT { + header + .package_qualified_imported_modules + .insert(PackageQualified::Unqualified(ModuleId::RESULT)); + + header + .imported_modules + .insert(ModuleId::RESULT, Region::zero()); + + header.exposed_imports.insert( + Ident::from("Result"), + (Symbol::RESULT_RESULT, Region::zero()), + ); + } + + if !header.module_id.is_builtin() { + header + .package_qualified_imported_modules + .insert(PackageQualified::Unqualified(ModuleId::STR)); + + header + .imported_modules + .insert(ModuleId::STR, Region::zero()); + } + + dbg!(header.module_id, &header.exposed_imports); + state .module_cache .imports @@ -1770,7 +1841,9 @@ fn update<'a>( }; for (unused, region) in unused_imports.drain() { - existing.push(roc_problem::can::Problem::UnusedImport(unused, region)); + if !unused.is_builtin() { + existing.push(roc_problem::can::Problem::UnusedImport(unused, region)); + } } let work = state.dependencies.notify(module_id, Phase::SolveTypes); @@ -2209,6 +2282,12 @@ fn load_pkg_config<'a>( header ))) } + Ok((ast::Module::Hosted { header }, _parse_state)) => { + Err(LoadingProblem::UnexpectedHeader(format!( + "expected platform/package module, got Hosted module with header\n{:?}", + header + ))) + } Ok((ast::Module::App { header }, _parse_state)) => { Err(LoadingProblem::UnexpectedHeader(format!( "expected platform/package module, got App with header\n{:?}", @@ -2232,12 +2311,6 @@ fn load_pkg_config<'a>( Ok(pkg_config_module_msg) } - Ok((ast::Module::Hosted { header }, _parse_state)) => { - Err(LoadingProblem::UnexpectedHeader(format!( - "expected platform/package module, got Hosted module with header\n{:?}", - header - ))) - } Err(fail) => Err(LoadingProblem::ParsingFailed( fail.map_problem(SyntaxError::Header) .into_file_error(filename), @@ -2261,12 +2334,8 @@ fn load_module<'a>( arc_shorthands: Arc>>>, ident_ids_by_module: Arc>>, ) -> Result<(ModuleId, Msg<'a>), LoadingProblem<'a>> { - use PackageQualified::*; - let module_start_time = SystemTime::now(); - dbg!(&module_name); - match module_name.as_inner().as_str() { "Result" => { let parse_start = SystemTime::now(); @@ -2302,7 +2371,9 @@ fn load_module<'a>( packages: &[], exposes: &EXPOSES, imports, - extra: HeaderFor::Interface, + extra: HeaderFor::Builtin { + generates_with: &[], + }, }; let src_bytes = r#" @@ -2355,6 +2426,136 @@ fn load_module<'a>( module_timing, )); } + "Str" => { + let parse_start = SystemTime::now(); + let parse_header_duration = parse_start.elapsed().unwrap(); + + // Insert the first entries for this module's timings + let mut module_timing = ModuleTiming::new(module_start_time); + + module_timing.read_roc_file = Default::default(); + module_timing.parse_header = parse_header_duration; + + let filename = PathBuf::from("Str.roc"); + + const EXPOSES: &[Loc] = &[ + Loc::at_zero(ExposedName::new("Utf8Problem")), + Loc::at_zero(ExposedName::new("Utf8ByteProblem")), + Loc::at_zero(ExposedName::new("isEmpty")), + Loc::at_zero(ExposedName::new("concat")), + Loc::at_zero(ExposedName::new("joinWith")), + Loc::at_zero(ExposedName::new("split")), + Loc::at_zero(ExposedName::new("repeat")), + Loc::at_zero(ExposedName::new("countGraphemes")), + Loc::at_zero(ExposedName::new("startsWithCodePt")), + Loc::at_zero(ExposedName::new("toUtf8")), + Loc::at_zero(ExposedName::new("fromUtf8")), + Loc::at_zero(ExposedName::new("fromUtf8Range")), + Loc::at_zero(ExposedName::new("startsWith")), + Loc::at_zero(ExposedName::new("endsWith")), + Loc::at_zero(ExposedName::new("trim")), + Loc::at_zero(ExposedName::new("trimLeft")), + Loc::at_zero(ExposedName::new("trimRight")), + Loc::at_zero(ExposedName::new("toDec")), + Loc::at_zero(ExposedName::new("toF64")), + Loc::at_zero(ExposedName::new("toF32")), + Loc::at_zero(ExposedName::new("toNat")), + Loc::at_zero(ExposedName::new("toU128")), + Loc::at_zero(ExposedName::new("toI128")), + Loc::at_zero(ExposedName::new("toU64")), + Loc::at_zero(ExposedName::new("toI64")), + Loc::at_zero(ExposedName::new("toU32")), + Loc::at_zero(ExposedName::new("toI32")), + Loc::at_zero(ExposedName::new("toU16")), + Loc::at_zero(ExposedName::new("toI16")), + Loc::at_zero(ExposedName::new("toU8")), + Loc::at_zero(ExposedName::new("toI8")), + ]; + const IMPORTS: &[Loc] = &[Loc::at_zero(ImportsEntry::Module( + roc_parse::header::ModuleName::new("Result"), + Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("Result")))]), + ))]; + + const GENERATES_WITH: &[Symbol] = &[Symbol::STR_IS_EMPTY, Symbol::STR_CONCAT]; + + let info = HeaderInfo { + loc_name: Loc { + region: Region::zero(), + value: ModuleNameEnum::Interface(roc_parse::header::ModuleName::new("Str")), + }, + filename, + is_root_module: false, + opt_shorthand: None, + packages: &[], + exposes: &EXPOSES, + imports: &IMPORTS, + extra: HeaderFor::Builtin { + generates_with: GENERATES_WITH, + }, + }; + + let src_bytes = r#" + Utf8ByteProblem : + [ + InvalidStartByte, + UnexpectedEndOfSequence, + ExpectedContinuation, + OverlongEncoding, + CodepointTooLarge, + EncodesSurrogateHalf, + ] + + Utf8Problem : { byteIndex : Nat, problem : Utf8ByteProblem } + + isEmpty : Str -> Bool + concat : Str, Str -> Str + joinWith : List Str, Str -> Str + split : Str, Str -> List Str + repeat : Str, Nat -> Str + countGraphemes : Str -> Nat + startsWithCodePt : Str, U32 -> Bool + + toUtf8 : Str -> List U8 + + # fromUtf8 : List U8 -> Result Str [ BadUtf8 Utf8Problem ]* + # fromUtf8Range : List U8 -> Result Str [ BadUtf8 Utf8Problem, OutOfBounds ]* + + fromUtf8 : List U8 -> Result Str [ BadUtf8 Utf8ByteProblem Nat ]* + fromUtf8Range : List U8 -> Result Str [ BadUtf8 Utf8ByteProblem Nat, OutOfBounds ]* + + startsWith : Str, Str -> Bool + endsWith : Str, Str -> Bool + + trim : Str -> Str + trimLeft : Str -> Str + trimRight : Str -> Str + + toDec : Str -> Result Dec [ InvalidNumStr ]* + toF64 : Str -> Result F64 [ InvalidNumStr ]* + toF32 : Str -> Result F32 [ InvalidNumStr ]* + toNat : Str -> Result Nat [ InvalidNumStr ]* + toU128 : Str -> Result U128 [ InvalidNumStr ]* + toI128 : Str -> Result I128 [ InvalidNumStr ]* + toU64 : Str -> Result U64 [ InvalidNumStr ]* + toI64 : Str -> Result I64 [ InvalidNumStr ]* + toU32 : Str -> Result U32 [ InvalidNumStr ]* + toI32 : Str -> Result I32 [ InvalidNumStr ]* + toU16 : Str -> Result U16 [ InvalidNumStr ]* + toI16 : Str -> Result I16 [ InvalidNumStr ]* + toU8 : Str -> Result U8 [ InvalidNumStr ]* + toI8 : Str -> Result I8 [ InvalidNumStr ]* + "#; + + let parse_state = roc_parse::state::State::new(src_bytes.as_bytes()); + + return Ok(send_header( + info, + parse_state, + module_ids, + ident_ids_by_module, + module_timing, + )); + } _ => { // fall through } diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index d2a39ba9d2..e01ebef291 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -1048,7 +1048,7 @@ define_builtins! { 0 STR_STR: "Str" imported // the Str.Str type alias 1 STR_AT_STR: "@Str" // the Str.@Str private tag 2 STR_IS_EMPTY: "isEmpty" - 3 STR_APPEND: "append" + 3 STR_APPEND: "#append" // unused 4 STR_CONCAT: "concat" 5 STR_JOIN_WITH: "joinWith" 6 STR_SPLIT: "split" diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index af8c66b7ac..3c66b52ee6 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -6589,7 +6589,19 @@ fn can_reuse_symbol<'a>( if let roc_can::expr::Expr::Var(symbol) = expr { let symbol = *symbol; - if env.is_imported_symbol(symbol) { + let arguments = [ + Symbol::ARG_1, + Symbol::ARG_2, + Symbol::ARG_3, + Symbol::ARG_4, + Symbol::ARG_5, + Symbol::ARG_6, + Symbol::ARG_7, + ]; + + if arguments.contains(&symbol) { + Value(symbol) + } else if env.is_imported_symbol(symbol) { Imported(symbol) } else if procs.partial_procs.contains_key(symbol) { LocalFunction(symbol) diff --git a/compiler/parse/src/ast.rs b/compiler/parse/src/ast.rs index 43405d158b..eea45b2ceb 100644 --- a/compiler/parse/src/ast.rs +++ b/compiler/parse/src/ast.rs @@ -620,7 +620,7 @@ impl<'a, T> Collection<'a, T> { } } - pub fn with_items(items: &'a [T]) -> Collection<'a, T> { + pub const fn with_items(items: &'a [T]) -> Collection<'a, T> { Collection { items, final_comments: None, diff --git a/compiler/parse/src/header.rs b/compiler/parse/src/header.rs index 6a36590965..fcd534e0d6 100644 --- a/compiler/parse/src/header.rs +++ b/compiler/parse/src/header.rs @@ -6,6 +6,7 @@ use crate::parser::{specialize, word1, EPackageEntry, EPackageName, Parser}; use crate::state::State; use crate::string_literal; use bumpalo::collections::Vec; +use roc_module::symbol::Symbol; use roc_region::all::Loc; #[derive(Debug)] @@ -17,6 +18,10 @@ pub enum HeaderFor<'a> { generates: UppercaseIdent<'a>, generates_with: &'a [Loc>], }, + /// Only created during canonicalization, never actually parsed from source + Builtin { + generates_with: &'a [Symbol], + }, PkgConfig { /// usually `pf` config_shorthand: &'a str, @@ -60,11 +65,11 @@ impl<'a> From> for &'a str { } impl<'a> ModuleName<'a> { - pub fn new(name: &'a str) -> Self { + pub const fn new(name: &'a str) -> Self { ModuleName(name) } - pub fn as_str(&'a self) -> &'a str { + pub const fn as_str(&'a self) -> &'a str { self.0 } } diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index 6b1eab6f4f..05b2c42251 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -126,8 +126,15 @@ mod solve_expr { } fn promote_expr_to_module(src: &str) -> String { - let mut buffer = - String::from("app \"test\" provides [ main ] to \"./platform\"\n\nmain =\n"); + let mut buffer = String::from(indoc!( + r#" + app "test" + imports [ Result.{ Result } ] + provides [ main ] to "./platform" + + main = + "# + )); for line in src.lines() { // indent the body! @@ -3503,7 +3510,7 @@ mod solve_expr { infer_eq_without_problem( indoc!( r#" - app "test" provides [ main ] to "./platform" + app "test" imports [ Result.{ Result } ] provides [ main ] to "./platform" boom = \_ -> boom {} @@ -4728,7 +4735,7 @@ mod solve_expr { infer_eq_without_problem( indoc!( r#" - canIGo : _ -> Result _ _ + canIGo : _ -> Result.Result _ _ canIGo = \color -> when color is "green" -> Ok "go!" diff --git a/examples/effect/Main.roc b/examples/effect/Main.roc index d980596cfe..f9843b6eb4 100644 --- a/examples/effect/Main.roc +++ b/examples/effect/Main.roc @@ -5,13 +5,4 @@ app "effect-example" main : Effect.Effect {} main = - Effect.after - (Effect.getLine) - \line -> - Effect.after - (Effect.putLine "You entered: \(line)") - \{ } -> - Effect.after - (Effect.putLine "It is known") - \{ } -> - Effect.always {} + (Effect.putLine (Str.concat "It is known" "foo")) diff --git a/reporting/src/report.rs b/reporting/src/report.rs index c74de2e0ff..7cfb684375 100644 --- a/reporting/src/report.rs +++ b/reporting/src/report.rs @@ -509,8 +509,11 @@ impl<'a> RocDocAllocator<'a> { // debug_assert!(region.contains(&sub_region)); // If the outer region takes more than 1 full screen (~60 lines), only show the inner region - if region.end().line - region.start().line > 60 { - return self.region_with_subregion(sub_region, sub_region); + match region.end().line.checked_sub(region.start().line) { + Some(v) if v > 60 => { + return self.region_with_subregion(sub_region, sub_region); + } + _ => {} } // if true, the final line of the snippet will be some ^^^ that point to the region where From 65b1b3fcceba26219cb70aa12ab31d87768f3ef4 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 26 Feb 2022 23:11:40 +0100 Subject: [PATCH 004/846] just before Num --- compiler/can/src/builtins.rs | 6 + compiler/can/src/env.rs | 23 +- compiler/can/src/module.rs | 11 +- compiler/gen_llvm/src/llvm/build.rs | 7 + compiler/gen_wasm/src/low_level.rs | 2 +- compiler/load/src/file.rs | 949 ++++++++++++++++++++++++++-- compiler/module/src/low_level.rs | 1 + compiler/module/src/symbol.rs | 37 +- compiler/mono/src/borrow.rs | 1 + compiler/solve/src/solve.rs | 7 +- reporting/src/error/type.rs | 22 +- 11 files changed, 976 insertions(+), 90 deletions(-) diff --git a/compiler/can/src/builtins.rs b/compiler/can/src/builtins.rs index a8228c6ecb..2b9676b5a7 100644 --- a/compiler/can/src/builtins.rs +++ b/compiler/can/src/builtins.rs @@ -169,6 +169,7 @@ pub fn builtin_defs_map(symbol: Symbol, var_store: &mut VarStore) -> Option SET_DIFFERENCE => set_difference, SET_TO_LIST => set_to_list, SET_FROM_LIST => set_from_list, + SET_TO_DICT=> set_to_dict, SET_INSERT => set_insert, SET_REMOVE => set_remove, SET_CONTAINS => set_contains, @@ -3963,6 +3964,11 @@ fn set_from_list(symbol: Symbol, var_store: &mut VarStore) -> Def { lowlevel_1(symbol, LowLevel::SetFromList, var_store) } +/// Set.toDict : Set k -> Dict k {} +fn set_to_dict(symbol: Symbol, var_store: &mut VarStore) -> Def { + lowlevel_1(symbol, LowLevel::SetToDict, var_store) +} + /// Set.insert : Set k, k -> Set k fn set_insert(symbol: Symbol, var_store: &mut VarStore) -> Def { let dict_var = var_store.fresh(); diff --git a/compiler/can/src/env.rs b/compiler/can/src/env.rs index 46f627d7d9..221d89c96b 100644 --- a/compiler/can/src/env.rs +++ b/compiler/can/src/env.rs @@ -87,16 +87,19 @@ impl<'a> Env<'a> { Ok(symbol) } - None => Err(RuntimeError::LookupNotInScope( - Loc { - value: ident, - region, - }, - self.ident_ids - .idents() - .map(|(_, string)| string.as_ref().into()) - .collect(), - )), + None => { + let error = RuntimeError::LookupNotInScope( + Loc { + value: ident, + region, + }, + self.ident_ids + .idents() + .map(|(_, string)| string.as_ref().into()) + .collect(), + ); + Err(error) + } } } else { match self.dep_idents.get(&module_id) { diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index 6d2a95e9a0..653e970fbc 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -242,6 +242,8 @@ pub fn canonicalize_module_defs<'a>( panic!("TODO gracefully handle shadowing in imports.") } } + } else if symbol == Symbol::LIST_LIST || symbol == Symbol::STR_STR { + // These are not aliases but Apply's and we make sure they are always in scope } else { // This is a type alias @@ -260,8 +262,11 @@ pub fn canonicalize_module_defs<'a>( Ok(()) => { // here we do nothing special } - Err((_shadowed_symbol, _region)) => { - panic!("TODO gracefully handle shadowing in imports.") + Err((shadowed_symbol, _region)) => { + panic!( + "TODO gracefully handle shadowing in imports, {:?} is shadowed.", + shadowed_symbol + ) } } } @@ -376,7 +381,7 @@ pub fn canonicalize_module_defs<'a>( let symbol = def.pattern_vars.iter().next().unwrap().0; match crate::builtins::builtin_defs_map(*symbol, var_store) { None => { - panic!("A builtin module contains a signature without implementation") + panic!("A builtin module contains a signature without implementation for {:?}", symbol) } Some(mut replacement_def) => { replacement_def.annotation = def.annotation.take(); diff --git a/compiler/gen_llvm/src/llvm/build.rs b/compiler/gen_llvm/src/llvm/build.rs index af42090989..d25825694e 100644 --- a/compiler/gen_llvm/src/llvm/build.rs +++ b/compiler/gen_llvm/src/llvm/build.rs @@ -6065,6 +6065,13 @@ fn run_low_level<'a, 'ctx, 'env>( let key_layout = list_element_layout!(list_layout); set_from_list(env, layout_ids, list, key_layout) } + SetToDict => { + debug_assert_eq!(args.len(), 1); + + let (set, _set_layout) = load_symbol_and_layout(scope, &args[0]); + + set + } ExpectTrue => { debug_assert_eq!(args.len(), 1); diff --git a/compiler/gen_wasm/src/low_level.rs b/compiler/gen_wasm/src/low_level.rs index a5875e1813..a58a0544b3 100644 --- a/compiler/gen_wasm/src/low_level.rs +++ b/compiler/gen_wasm/src/low_level.rs @@ -267,7 +267,7 @@ impl<'a> LowLevelCall<'a> { | ListSublist | ListDropAt | ListSwap | ListAny | ListAll | ListFindUnsafe | DictSize | DictEmpty | DictInsert | DictRemove | DictContains | DictGetUnsafe | DictKeys | DictValues | DictUnion | DictIntersection | DictDifference | DictWalk - | SetFromList => { + | SetFromList | SetToDict => { todo!("{:?}", self.lowlevel); } diff --git a/compiler/load/src/file.rs b/compiler/load/src/file.rs index 013a9eba7c..de34d6255a 100644 --- a/compiler/load/src/file.rs +++ b/compiler/load/src/file.rs @@ -110,11 +110,36 @@ impl Default for ModuleCache<'_> { PQModuleName::Unqualified(ModuleName::from(ModuleName::RESULT)), ); + module_names.insert( + ModuleId::LIST, + PQModuleName::Unqualified(ModuleName::from(ModuleName::LIST)), + ); + module_names.insert( ModuleId::STR, PQModuleName::Unqualified(ModuleName::from(ModuleName::STR)), ); + module_names.insert( + ModuleId::DICT, + PQModuleName::Unqualified(ModuleName::from(ModuleName::DICT)), + ); + + module_names.insert( + ModuleId::SET, + PQModuleName::Unqualified(ModuleName::from(ModuleName::SET)), + ); + + module_names.insert( + ModuleId::BOOL, + PQModuleName::Unqualified(ModuleName::from(ModuleName::BOOL)), + ); + + // module_names.insert( + // ModuleId::NUM, + // PQModuleName::Unqualified(ModuleName::from(ModuleName::NUM)), + // ); + Self { module_names, headers: Default::default(), @@ -1692,8 +1717,9 @@ fn update<'a>( // add the prelude let mut header = header; // let mut imports = header.package_qualified_imported_modules.clone(); + // - if header.module_id != ModuleId::RESULT { + if ![ModuleId::RESULT, ModuleId::BOOL].contains(&header.module_id) { header .package_qualified_imported_modules .insert(PackageQualified::Unqualified(ModuleId::RESULT)); @@ -1708,6 +1734,36 @@ fn update<'a>( ); } + /* + if ![ModuleId::NUM, ModuleId::BOOL, ModuleId::RESULT].contains(&header.module_id) { + header + .package_qualified_imported_modules + .insert(PackageQualified::Unqualified(ModuleId::NUM)); + + header + .imported_modules + .insert(ModuleId::NUM, Region::zero()); + + header + .exposed_imports + .insert(Ident::from("Num"), (Symbol::NUM_NUM, Region::zero())); + } + */ + + if header.module_id != ModuleId::BOOL { + header + .package_qualified_imported_modules + .insert(PackageQualified::Unqualified(ModuleId::BOOL)); + + header + .imported_modules + .insert(ModuleId::BOOL, Region::zero()); + + header + .exposed_imports + .insert(Ident::from("Bool"), (Symbol::BOOL_BOOL, Region::zero())); + } + if !header.module_id.is_builtin() { header .package_qualified_imported_modules @@ -1716,9 +1772,31 @@ fn update<'a>( header .imported_modules .insert(ModuleId::STR, Region::zero()); - } - dbg!(header.module_id, &header.exposed_imports); + header + .package_qualified_imported_modules + .insert(PackageQualified::Unqualified(ModuleId::DICT)); + + header + .imported_modules + .insert(ModuleId::DICT, Region::zero()); + + header + .package_qualified_imported_modules + .insert(PackageQualified::Unqualified(ModuleId::SET)); + + header + .imported_modules + .insert(ModuleId::SET, Region::zero()); + + header + .package_qualified_imported_modules + .insert(PackageQualified::Unqualified(ModuleId::LIST)); + + header + .imported_modules + .insert(ModuleId::LIST, Region::zero()); + } state .module_cache @@ -1746,6 +1824,8 @@ fn update<'a>( start_tasks(arena, &mut state, work, injector, worker_listeners)?; + dbg!(&state.dependencies); + Ok(state) } Parsed(parsed) => { @@ -2336,17 +2416,16 @@ fn load_module<'a>( ) -> Result<(ModuleId, Msg<'a>), LoadingProblem<'a>> { let module_start_time = SystemTime::now(); + let parse_start = SystemTime::now(); + let parse_header_duration = parse_start.elapsed().unwrap(); + + // Insert the first entries for this module's timings + let mut module_timing = ModuleTiming::new(module_start_time); + + module_timing.read_roc_file = Default::default(); + module_timing.parse_header = parse_header_duration; match module_name.as_inner().as_str() { "Result" => { - let parse_start = SystemTime::now(); - let parse_header_duration = parse_start.elapsed().unwrap(); - - // Insert the first entries for this module's timings - let mut module_timing = ModuleTiming::new(module_start_time); - - module_timing.read_roc_file = Default::default(); - module_timing.parse_header = parse_header_duration; - let filename = PathBuf::from("Result.roc"); const EXPOSES: &[Loc] = &[ @@ -2358,7 +2437,11 @@ fn load_module<'a>( Loc::at_zero(ExposedName::new("after")), Loc::at_zero(ExposedName::new("withDefault")), ]; - let imports = &[]; + + const IMPORTS: &[Loc] = &[Loc::at_zero(ImportsEntry::Module( + roc_parse::header::ModuleName::new("Bool"), + Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("Bool")))]), + ))]; let info = HeaderInfo { loc_name: Loc { @@ -2369,8 +2452,8 @@ fn load_module<'a>( is_root_module: false, opt_shorthand: None, packages: &[], - exposes: &EXPOSES, - imports, + exposes: EXPOSES, + imports: IMPORTS, extra: HeaderFor::Builtin { generates_with: &[], }, @@ -2394,7 +2477,7 @@ fn load_module<'a>( withDefault : Result ok err, ok -> ok withDefault = \result, default -> when result is - Ok value -> value + Ok value -> value Err _ -> default map : Result a err, (a -> b) -> Result b err @@ -2406,7 +2489,7 @@ fn load_module<'a>( mapErr : Result ok a, (a -> b) -> Result ok b mapErr = \result, transform -> when result is - Ok v -> Ok v + Ok v -> Ok v Err e -> Err (transform e) after : Result a err, (a -> Result b err) -> Result b err @@ -2426,23 +2509,174 @@ fn load_module<'a>( module_timing, )); } + "List" => { + let filename = PathBuf::from("List.roc"); + + const EXPOSES: &[Loc] = &[ + Loc::at_zero(ExposedName::new("isEmpty")), + Loc::at_zero(ExposedName::new("get")), + Loc::at_zero(ExposedName::new("set")), + Loc::at_zero(ExposedName::new("append")), + Loc::at_zero(ExposedName::new("map")), + Loc::at_zero(ExposedName::new("len")), + Loc::at_zero(ExposedName::new("walkBackwards")), + Loc::at_zero(ExposedName::new("concat")), + Loc::at_zero(ExposedName::new("first")), + Loc::at_zero(ExposedName::new("single")), + Loc::at_zero(ExposedName::new("repeat")), + Loc::at_zero(ExposedName::new("reverse")), + Loc::at_zero(ExposedName::new("prepend")), + Loc::at_zero(ExposedName::new("join")), + Loc::at_zero(ExposedName::new("keepIf")), + Loc::at_zero(ExposedName::new("contains")), + Loc::at_zero(ExposedName::new("sum")), + Loc::at_zero(ExposedName::new("walk")), + Loc::at_zero(ExposedName::new("last")), + Loc::at_zero(ExposedName::new("keepOks")), + Loc::at_zero(ExposedName::new("keepErrs")), + Loc::at_zero(ExposedName::new("mapWithIndex")), + Loc::at_zero(ExposedName::new("map2")), + Loc::at_zero(ExposedName::new("map3")), + Loc::at_zero(ExposedName::new("product")), + Loc::at_zero(ExposedName::new("walkUntil")), + Loc::at_zero(ExposedName::new("range")), + Loc::at_zero(ExposedName::new("sortWith")), + Loc::at_zero(ExposedName::new("drop")), + Loc::at_zero(ExposedName::new("swap")), + Loc::at_zero(ExposedName::new("dropAt")), + Loc::at_zero(ExposedName::new("dropLast")), + Loc::at_zero(ExposedName::new("min")), + Loc::at_zero(ExposedName::new("max")), + Loc::at_zero(ExposedName::new("map4")), + Loc::at_zero(ExposedName::new("dropFirst")), + Loc::at_zero(ExposedName::new("joinMap")), + Loc::at_zero(ExposedName::new("any")), + Loc::at_zero(ExposedName::new("takeFirst")), + Loc::at_zero(ExposedName::new("takeLast")), + Loc::at_zero(ExposedName::new("find")), + Loc::at_zero(ExposedName::new("sublist")), + Loc::at_zero(ExposedName::new("intersperse")), + Loc::at_zero(ExposedName::new("split")), + Loc::at_zero(ExposedName::new("all")), + Loc::at_zero(ExposedName::new("dropIf")), + Loc::at_zero(ExposedName::new("sortAsc")), + Loc::at_zero(ExposedName::new("sortDesc")), + ]; + + const IMPORTS: &[Loc] = &[ + Loc::at_zero(ImportsEntry::Module( + roc_parse::header::ModuleName::new("Result"), + Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new( + "Result", + )))]), + )), + Loc::at_zero(ImportsEntry::Module( + roc_parse::header::ModuleName::new("Bool"), + Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("Bool")))]), + )), + // Loc::at_zero(ImportsEntry::Module( + // roc_parse::header::ModuleName::new("Num"), + // Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("Nat")))]), + // )), + ]; + + const GENERATES_WITH: &[Symbol] = &[]; + + let info = HeaderInfo { + loc_name: Loc { + region: Region::zero(), + value: ModuleNameEnum::Interface(roc_parse::header::ModuleName::new("List")), + }, + filename, + is_root_module: false, + opt_shorthand: None, + packages: &[], + exposes: EXPOSES, + imports: IMPORTS, + extra: HeaderFor::Builtin { + generates_with: GENERATES_WITH, + }, + }; + + let src_bytes = r#" + isEmpty : List a -> Bool + get : List a, Nat -> Result a [ OutOfBounds ]* + set : List a, Nat, a -> List a + append : List a, a -> List a + prepend : List a, a -> List a + len : List a -> Nat + concat : List a, List a -> List a + last : List a -> Result a [ ListWasEmpty ]* + single : a -> List a + repeat : a, Nat -> List a + reverse : List a -> List a + join : List (List a) -> List a + contains : List a, a -> Bool + walk : List elem, state, (state, elem -> state) -> state + walkBackwards : List elem, state, (state, elem -> state) -> state + walkUntil : List elem, state, (state, elem -> [ Continue state, Stop state ]) -> state + + sum : List (Num a) -> Num a + product : List (Num a) -> Num a + + any : List a, (a -> Bool) -> Bool + all : List a, (a -> Bool) -> Bool + + keepIf : List a, (a -> Bool) -> List a + dropIf : List a, (a -> Bool) -> List a + + keepOks : List (Result ok err) -> List ok + keepErrs : List (Result ok err) -> List err + map : List a, (a -> b) -> List b + map2 : List a, List b, (a, b -> c) -> List c + map3 : List a, List b, List c, (a, b, c -> d) -> List d + map4 : List a, List b, List c, List d, (a, b, c, d -> e) -> List e + mapWithIndex : List a, (a -> b) -> List b + range : Int a, Int a -> List (Int a) + sortWith : List a, (a, a -> [ LT, EQ, GT ] ) -> List a + sortAsc : List (Num a) -> List (Num a) + sortDesc : List (Num a) -> List (Num a) + swap : List a, Nat, Nat -> List a + + first : List a -> Result a [ ListWasEmpty ]* + + dropFirst : List elem -> List elem + dropLast : List elem -> List elem + + takeFirst : List elem, Nat -> List elem + takeLast : List elem, Nat -> List elem + + drop : List elem, Nat -> List elem + dropAt : List elem, Nat -> List elem + + min : List (Num a) -> Result (Num a) [ ListWasEmpty ]* + max : List (Num a) -> Result (Num a) [ ListWasEmpty ]* + + joinMap : List a, (a -> List b) -> List b + find : List elem, (elem -> Bool) -> Result elem [ NotFound ]* + sublist : List elem, { start : Nat, len : Nat } -> List elem + intersperse : List elem, elem -> List elem + split : List elem, Nat -> { before: List elem, others: List elem } + "#; + + let parse_state = roc_parse::state::State::new(src_bytes.as_bytes()); + + return Ok(send_header( + info, + parse_state, + module_ids, + ident_ids_by_module, + module_timing, + )); + } "Str" => { - let parse_start = SystemTime::now(); - let parse_header_duration = parse_start.elapsed().unwrap(); - - // Insert the first entries for this module's timings - let mut module_timing = ModuleTiming::new(module_start_time); - - module_timing.read_roc_file = Default::default(); - module_timing.parse_header = parse_header_duration; - let filename = PathBuf::from("Str.roc"); const EXPOSES: &[Loc] = &[ + Loc::at_zero(ExposedName::new("concat")), Loc::at_zero(ExposedName::new("Utf8Problem")), Loc::at_zero(ExposedName::new("Utf8ByteProblem")), Loc::at_zero(ExposedName::new("isEmpty")), - Loc::at_zero(ExposedName::new("concat")), Loc::at_zero(ExposedName::new("joinWith")), Loc::at_zero(ExposedName::new("split")), Loc::at_zero(ExposedName::new("repeat")), @@ -2471,12 +2705,46 @@ fn load_module<'a>( Loc::at_zero(ExposedName::new("toU8")), Loc::at_zero(ExposedName::new("toI8")), ]; - const IMPORTS: &[Loc] = &[Loc::at_zero(ImportsEntry::Module( - roc_parse::header::ModuleName::new("Result"), - Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("Result")))]), - ))]; - const GENERATES_WITH: &[Symbol] = &[Symbol::STR_IS_EMPTY, Symbol::STR_CONCAT]; + const IMPORTS: &[Loc] = &[ + Loc::at_zero(ImportsEntry::Module( + roc_parse::header::ModuleName::new("Result"), + Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new( + "Result", + )))]), + )), + Loc::at_zero(ImportsEntry::Module( + roc_parse::header::ModuleName::new("Bool"), + Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("Bool")))]), + )), + Loc::at_zero(ImportsEntry::Module( + roc_parse::header::ModuleName::new("List"), + Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("List")))]), + )), + // Loc::at_zero(ImportsEntry::Module( + // roc_parse::header::ModuleName::new("Num"), + // Collection::with_items(&[ + // Loc::at_zero(Spaced::Item(ExposedName::new("Int"))), // needed because used by the aliases below + // Loc::at_zero(Spaced::Item(ExposedName::new("Float"))), // needed because used by the aliases below + // Loc::at_zero(Spaced::Item(ExposedName::new("Dec"))), + // Loc::at_zero(Spaced::Item(ExposedName::new("F64"))), + // Loc::at_zero(Spaced::Item(ExposedName::new("F32"))), + // Loc::at_zero(Spaced::Item(ExposedName::new("Nat"))), + // Loc::at_zero(Spaced::Item(ExposedName::new("U128"))), + // Loc::at_zero(Spaced::Item(ExposedName::new("I128"))), + // Loc::at_zero(Spaced::Item(ExposedName::new("U64"))), + // Loc::at_zero(Spaced::Item(ExposedName::new("I64"))), + // Loc::at_zero(Spaced::Item(ExposedName::new("U32"))), + // Loc::at_zero(Spaced::Item(ExposedName::new("I32"))), + // Loc::at_zero(Spaced::Item(ExposedName::new("U16"))), + // Loc::at_zero(Spaced::Item(ExposedName::new("I16"))), + // Loc::at_zero(Spaced::Item(ExposedName::new("U8"))), + // Loc::at_zero(Spaced::Item(ExposedName::new("I8"))), + // ]), + // )), + ]; + + const GENERATES_WITH: &[Symbol] = &[]; let info = HeaderInfo { loc_name: Loc { @@ -2487,16 +2755,16 @@ fn load_module<'a>( is_root_module: false, opt_shorthand: None, packages: &[], - exposes: &EXPOSES, - imports: &IMPORTS, + exposes: EXPOSES, + imports: IMPORTS, extra: HeaderFor::Builtin { generates_with: GENERATES_WITH, }, }; let src_bytes = r#" - Utf8ByteProblem : - [ + Utf8ByteProblem : + [ InvalidStartByte, UnexpectedEndOfSequence, ExpectedContinuation, @@ -2506,7 +2774,7 @@ fn load_module<'a>( ] Utf8Problem : { byteIndex : Nat, problem : Utf8ByteProblem } - + isEmpty : Str -> Bool concat : Str, Str -> Str joinWith : List Str, Str -> Str @@ -2530,20 +2798,599 @@ fn load_module<'a>( trimLeft : Str -> Str trimRight : Str -> Str - toDec : Str -> Result Dec [ InvalidNumStr ]* - toF64 : Str -> Result F64 [ InvalidNumStr ]* - toF32 : Str -> Result F32 [ InvalidNumStr ]* - toNat : Str -> Result Nat [ InvalidNumStr ]* - toU128 : Str -> Result U128 [ InvalidNumStr ]* - toI128 : Str -> Result I128 [ InvalidNumStr ]* - toU64 : Str -> Result U64 [ InvalidNumStr ]* - toI64 : Str -> Result I64 [ InvalidNumStr ]* - toU32 : Str -> Result U32 [ InvalidNumStr ]* - toI32 : Str -> Result I32 [ InvalidNumStr ]* - toU16 : Str -> Result U16 [ InvalidNumStr ]* - toI16 : Str -> Result I16 [ InvalidNumStr ]* - toU8 : Str -> Result U8 [ InvalidNumStr ]* - toI8 : Str -> Result I8 [ InvalidNumStr ]* + toDec : Str -> Result Dec [ InvalidNumStr ]* + toF64 : Str -> Result F64 [ InvalidNumStr ]* + toF32 : Str -> Result F32 [ InvalidNumStr ]* + toNat : Str -> Result Nat [ InvalidNumStr ]* + toU128 : Str -> Result U128 [ InvalidNumStr ]* + toI128 : Str -> Result I128 [ InvalidNumStr ]* + toU64 : Str -> Result U64 [ InvalidNumStr ]* + toI64 : Str -> Result I64 [ InvalidNumStr ]* + toU32 : Str -> Result U32 [ InvalidNumStr ]* + toI32 : Str -> Result I32 [ InvalidNumStr ]* + toU16 : Str -> Result U16 [ InvalidNumStr ]* + toI16 : Str -> Result I16 [ InvalidNumStr ]* + toU8 : Str -> Result U8 [ InvalidNumStr ]* + toI8 : Str -> Result I8 [ InvalidNumStr ]* + "#; + + let parse_state = roc_parse::state::State::new(src_bytes.as_bytes()); + + return Ok(send_header( + info, + parse_state, + module_ids, + ident_ids_by_module, + module_timing, + )); + } + "Dict" => { + let filename = PathBuf::from("Dict.roc"); + + const EXPOSES: &[Loc] = &[ + Loc::at_zero(ExposedName::new("empty")), + Loc::at_zero(ExposedName::new("single")), + Loc::at_zero(ExposedName::new("get")), + Loc::at_zero(ExposedName::new("walk")), + Loc::at_zero(ExposedName::new("insert")), + Loc::at_zero(ExposedName::new("len")), + Loc::at_zero(ExposedName::new("remove")), + Loc::at_zero(ExposedName::new("contains")), + Loc::at_zero(ExposedName::new("keys")), + Loc::at_zero(ExposedName::new("values")), + Loc::at_zero(ExposedName::new("union")), + Loc::at_zero(ExposedName::new("intersection")), + Loc::at_zero(ExposedName::new("difference")), + ]; + const IMPORTS: &[Loc] = &[ + Loc::at_zero(ImportsEntry::Module( + roc_parse::header::ModuleName::new("Result"), + Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new( + "Result", + )))]), + )), + Loc::at_zero(ImportsEntry::Module( + roc_parse::header::ModuleName::new("Bool"), + Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("Bool")))]), + )), + Loc::at_zero(ImportsEntry::Module( + roc_parse::header::ModuleName::new("List"), + Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("List")))]), + )), + // Loc::at_zero(ImportsEntry::Module( + // roc_parse::header::ModuleName::new("Num"), + // Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("Nat")))]), + // )), + ]; + + const GENERATES_WITH: &[Symbol] = &[]; + + let info = HeaderInfo { + loc_name: Loc { + region: Region::zero(), + value: ModuleNameEnum::Interface(roc_parse::header::ModuleName::new("Dict")), + }, + filename, + is_root_module: false, + opt_shorthand: None, + packages: &[], + exposes: EXPOSES, + imports: IMPORTS, + extra: HeaderFor::Builtin { + generates_with: GENERATES_WITH, + }, + }; + + let src_bytes = r#" + empty : Dict k v + single : k, v -> Dict k v + get : Dict k v, k -> Result v [ KeyNotFound ]* + walk : Dict k v, state, (state, k, v -> state) -> state + insert : Dict k v, k, v -> Dict k v + len : Dict k v -> Nat + remove : Dict k v, k -> Dict k v + contains : Dict k v, k -> Bool + keys : Dict k v -> List k + values : Dict k v -> List v + union : Dict k v, Dict k v -> Dict k v + intersection : Dict k v, Dict k v -> Dict k v + difference : Dict k v, Dict k v -> Dict k v + "#; + + let parse_state = roc_parse::state::State::new(src_bytes.as_bytes()); + + return Ok(send_header( + info, + parse_state, + module_ids, + ident_ids_by_module, + module_timing, + )); + } + "Set" => { + let filename = PathBuf::from("Dict.roc"); + + const EXPOSES: &[Loc] = &[ + Loc::at_zero(ExposedName::new("empty")), + Loc::at_zero(ExposedName::new("single")), + Loc::at_zero(ExposedName::new("walk")), + Loc::at_zero(ExposedName::new("insert")), + Loc::at_zero(ExposedName::new("len")), + Loc::at_zero(ExposedName::new("remove")), + Loc::at_zero(ExposedName::new("contains")), + Loc::at_zero(ExposedName::new("toList")), + Loc::at_zero(ExposedName::new("fromList")), + Loc::at_zero(ExposedName::new("union")), + Loc::at_zero(ExposedName::new("intersection")), + Loc::at_zero(ExposedName::new("difference")), + ]; + const IMPORTS: &[Loc] = &[ + Loc::at_zero(ImportsEntry::Module( + roc_parse::header::ModuleName::new("Result"), + Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new( + "Result", + )))]), + )), + Loc::at_zero(ImportsEntry::Module( + roc_parse::header::ModuleName::new("Bool"), + Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("Bool")))]), + )), + Loc::at_zero(ImportsEntry::Module( + roc_parse::header::ModuleName::new("List"), + Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("List")))]), + )), + // Loc::at_zero(ImportsEntry::Module( + // roc_parse::header::ModuleName::new("Num"), + // Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("Nat")))]), + // )), + ]; + + const GENERATES_WITH: &[Symbol] = &[]; + + let info = HeaderInfo { + loc_name: Loc { + region: Region::zero(), + value: ModuleNameEnum::Interface(roc_parse::header::ModuleName::new("Set")), + }, + filename, + is_root_module: false, + opt_shorthand: None, + packages: &[], + exposes: EXPOSES, + imports: IMPORTS, + extra: HeaderFor::Builtin { + generates_with: GENERATES_WITH, + }, + }; + + let src_bytes = r#" + empty : Set k + single : k -> Set k + insert : Set k, k -> Set k + len : Set k -> Nat + remove : Set k, k -> Set k + contains : Set k, k -> Bool + + # toList = \set -> Dict.keys (toDict set) + toList : Set k -> List k + fromList : List k -> Set k + + union : Set k, Set k -> Set k + intersection : Set k, Set k -> Set k + difference : Set k, Set k -> Set k + + toDict : Set k -> Dict k {} + + walk : Set k, state, (state, k -> state) -> state + walk = \set, state, step -> + Dict.walk (toDict set) state (\s, k, _ -> step s k) + "#; + + let parse_state = roc_parse::state::State::new(src_bytes.as_bytes()); + + return Ok(send_header( + info, + parse_state, + module_ids, + ident_ids_by_module, + module_timing, + )); + } + "Num" => { + let filename = PathBuf::from("Num.roc"); + + const EXPOSES: &[Loc] = &[ + Loc::at_zero(ExposedName::new("Num")), + Loc::at_zero(ExposedName::new("Int")), + Loc::at_zero(ExposedName::new("Float")), + // + Loc::at_zero(ExposedName::new("I128")), + Loc::at_zero(ExposedName::new("I64")), + Loc::at_zero(ExposedName::new("I32")), + Loc::at_zero(ExposedName::new("I16")), + Loc::at_zero(ExposedName::new("I8")), + // + Loc::at_zero(ExposedName::new("U128")), + Loc::at_zero(ExposedName::new("U64")), + Loc::at_zero(ExposedName::new("U32")), + Loc::at_zero(ExposedName::new("U16")), + Loc::at_zero(ExposedName::new("U8")), + // + Loc::at_zero(ExposedName::new("Nat")), + Loc::at_zero(ExposedName::new("Dec")), + // + // Loc::at_zero(ExposedName::new("maxFloat")), + // Loc::at_zero(ExposedName::new("minFloat")), + Loc::at_zero(ExposedName::new("abs")), + Loc::at_zero(ExposedName::new("neg")), + Loc::at_zero(ExposedName::new("add")), + Loc::at_zero(ExposedName::new("sub")), + Loc::at_zero(ExposedName::new("mul")), + Loc::at_zero(ExposedName::new("isLt")), + Loc::at_zero(ExposedName::new("isLte")), + Loc::at_zero(ExposedName::new("isGt")), + Loc::at_zero(ExposedName::new("isGte")), + Loc::at_zero(ExposedName::new("toFloat")), + Loc::at_zero(ExposedName::new("sin")), + Loc::at_zero(ExposedName::new("cos")), + Loc::at_zero(ExposedName::new("tan")), + Loc::at_zero(ExposedName::new("isZero")), + Loc::at_zero(ExposedName::new("isEven")), + Loc::at_zero(ExposedName::new("isOdd")), + Loc::at_zero(ExposedName::new("isPositive")), + Loc::at_zero(ExposedName::new("isNegative")), + Loc::at_zero(ExposedName::new("rem")), + Loc::at_zero(ExposedName::new("div")), + //Loc::at_zero(ExposedName::new("divFloor")), + //Loc::at_zero(ExposedName::new("modInt")), + //Loc::at_zero(ExposedName::new("modFloat")), + Loc::at_zero(ExposedName::new("sqrt")), + Loc::at_zero(ExposedName::new("log")), + Loc::at_zero(ExposedName::new("round")), + Loc::at_zero(ExposedName::new("compare")), + Loc::at_zero(ExposedName::new("pow")), + Loc::at_zero(ExposedName::new("ceiling")), + Loc::at_zero(ExposedName::new("powInt")), + Loc::at_zero(ExposedName::new("floor")), + Loc::at_zero(ExposedName::new("addWrap")), + Loc::at_zero(ExposedName::new("addChecked")), + Loc::at_zero(ExposedName::new("addSaturated")), + Loc::at_zero(ExposedName::new("atan")), + Loc::at_zero(ExposedName::new("acos")), + Loc::at_zero(ExposedName::new("asin")), + Loc::at_zero(ExposedName::new("bitwiseAnd")), + Loc::at_zero(ExposedName::new("bitwiseXor")), + Loc::at_zero(ExposedName::new("bitwiseOr")), + Loc::at_zero(ExposedName::new("shiftLeftBy")), + Loc::at_zero(ExposedName::new("shiftRightBy")), + Loc::at_zero(ExposedName::new("shiftRightZfBy")), + Loc::at_zero(ExposedName::new("subWrap")), + Loc::at_zero(ExposedName::new("subChecked")), + Loc::at_zero(ExposedName::new("subSaturated")), + Loc::at_zero(ExposedName::new("mulWrap")), + Loc::at_zero(ExposedName::new("mulChecked")), + Loc::at_zero(ExposedName::new("intCast")), + Loc::at_zero(ExposedName::new("isMultipleOf")), + Loc::at_zero(ExposedName::new("bytesToU16")), + Loc::at_zero(ExposedName::new("bytesToU32")), + Loc::at_zero(ExposedName::new("divCeil")), + Loc::at_zero(ExposedName::new("toStr")), + Loc::at_zero(ExposedName::new("minI8")), + Loc::at_zero(ExposedName::new("maxI8")), + Loc::at_zero(ExposedName::new("minU8")), + Loc::at_zero(ExposedName::new("maxU8")), + Loc::at_zero(ExposedName::new("minI16")), + Loc::at_zero(ExposedName::new("maxI16")), + Loc::at_zero(ExposedName::new("minU16")), + Loc::at_zero(ExposedName::new("maxU16")), + Loc::at_zero(ExposedName::new("minI32")), + Loc::at_zero(ExposedName::new("maxI32")), + Loc::at_zero(ExposedName::new("minU32")), + Loc::at_zero(ExposedName::new("maxU32")), + Loc::at_zero(ExposedName::new("minI64")), + Loc::at_zero(ExposedName::new("maxI64")), + Loc::at_zero(ExposedName::new("minU64")), + Loc::at_zero(ExposedName::new("maxU64")), + Loc::at_zero(ExposedName::new("minI128")), + Loc::at_zero(ExposedName::new("maxI128")), + Loc::at_zero(ExposedName::new("toI8")), + Loc::at_zero(ExposedName::new("toI8Checked")), + Loc::at_zero(ExposedName::new("toI16")), + Loc::at_zero(ExposedName::new("toI16Checked")), + Loc::at_zero(ExposedName::new("toI32")), + Loc::at_zero(ExposedName::new("toI32Checked")), + Loc::at_zero(ExposedName::new("toI64")), + Loc::at_zero(ExposedName::new("toI64Checked")), + Loc::at_zero(ExposedName::new("toI128")), + Loc::at_zero(ExposedName::new("toI128Checked")), + Loc::at_zero(ExposedName::new("toU8")), + Loc::at_zero(ExposedName::new("toU8Checked")), + Loc::at_zero(ExposedName::new("toU16")), + Loc::at_zero(ExposedName::new("toU16Checked")), + Loc::at_zero(ExposedName::new("toU32")), + Loc::at_zero(ExposedName::new("toU32Checked")), + Loc::at_zero(ExposedName::new("toU64")), + Loc::at_zero(ExposedName::new("toU64Checked")), + Loc::at_zero(ExposedName::new("toU128")), + Loc::at_zero(ExposedName::new("toU128Checked")), + ]; + const IMPORTS: &[Loc] = &[]; + + const GENERATES_WITH: &[Symbol] = &[]; + + let info = HeaderInfo { + loc_name: Loc { + region: Region::zero(), + value: ModuleNameEnum::Interface(roc_parse::header::ModuleName::new("Num")), + }, + filename, + is_root_module: false, + opt_shorthand: None, + packages: &[], + exposes: EXPOSES, + imports: IMPORTS, + extra: HeaderFor::Builtin { + generates_with: GENERATES_WITH, + }, + }; + + let src_bytes = r#" + + Num range : [ @Num range ] + Integer range : [ @Integer range ] + Float range : [ @Float range ] + + Natural : [ @Natural ] + Nat : Int Natural + + Signed128 : [ @Signed128 ] + I128 : Int Signed128 + + Unsigned128 : [ @Unsigned128 ] + U128 : Int Unsigned128 + + Signed64 : [ @Signed64 ] + I64 : Int Signed64 + + Unsigned64 : [ @Unsigned64 ] + U64 : Int Unsigned64 + + Signed32 : [ @Signed32 ] + I32 : Int Signed32 + + Unsigned32 : [ @Unsigned32 ] + U32 : Int Unsigned32 + + Signed16 : [ @Signed16 ] + I16 : Int Signed16 + + Unsigned16 : [ @Unsigned16 ] + U16 : Int Unsigned16 + + Signed8 : [ @Signed8 ] + I8 : Int Signed8 + + Unsigned8 : [ @Unsigned8 ] + U8 : Int Unsigned8 + + Decimal : [ @Decimal ] + Dec : Float Decimal + + Binary64 : [ @Binary64 ] + F64 : Float Binary64 + + Binary32 : [ @Binary32 ] + F32 : Float Binary32 + + compare : Num a, Num a -> [ LT, EQ, GT ] + + isLt : Num a, Num a -> Bool + isGt : Num a, Num a -> Bool + isLte : Num a, Num a -> Bool + isLte : Num a, Num a -> Bool + + isZero : Num a -> Bool + + isEven : Int a -> Bool + isOdd : Int a -> Bool + + toFloat : Num * -> Float * + + abs : Num a -> Num a + neg : Num a -> Num a + + add : Num a, Num a -> Num a + sub : Num a, Num a -> Num a + mul : Num a, Num a -> Num a + + # maxFloat : Float a + # minFloat : Float a + + sin : Float a -> Float a + cos : Float a -> Float a + tan : Float a -> Float a + + asin : Float a -> Float a + acos : Float a -> Float a + atan : Float a -> Float a + + sqrt : Float a -> Float a + log : Float a, Float a -> Float a + mod : Float a, Float a -> Result (Float a) [ DivByZero ]* + + rem : Int a, Int a -> Result (Int a) [ DivByZero ]* + mod : Int a, Int a -> Result (Int a) [ DivByZero ]* + isMultipleOf : Int a, Int a -> Bool + + round : Float a -> Int b + floor : Float a -> Int b + ceiling : Float a -> Int b + + pow : Float a, Float a -> Float a + powInt : Int a, Int a -> Int a + + addWrap : Int range, Int range -> Int range + addSaturated : Num a, Num a -> Num a + addChecked : Num a, Num a -> Result (Num a) [ Overflow ]* + + subWrap : Int range, Int range -> Int range + subSaturated : Num a, Num a -> Num a + subChecked : Num a, Num a -> Result (Num a) [ Overflow ]* + + mulWrap : Int range, Int range -> Int range + # mulSaturated : Num a, Num a -> Num a + mulChecked : Num a, Num a -> Result (Num a) [ Overflow ]* + + bitwiseAnd : Int a, Int a -> Int a + bitwiseXor : Int a, Int a -> Int a + bitwiseOr : Int a, Int a -> Int a + shiftLeftBy : Int a, Int a -> Int a + shiftRightBy : Int a, Int a -> Int a + shiftRightZfBy : Int a, Int a -> Int a + + intCast : Int a -> Int b + + minI8 : I8 + maxI8 : I8 + minU8 : U8 + maxU8 : U8 + minI16 : I16 + maxI16 : I16 + minU16 : U16 + maxU16 : U16 + minI32 : I32 + maxI32 : I32 + minU32 : U32 + maxU32 : U32 + minI64 : I64 + maxI64 : I64 + minU64 : U64 + maxU64 : U64 + + toI8 : Int * -> I8 + toI16 : Int * -> I16 + toI32 : Int * -> I32 + toI64 : Int * -> I64 + toI128 : Int * -> I128 + toU8 : Int * -> U8 + toU16 : Int * -> U16 + toU32 : Int * -> U32 + toU64 : Int * -> U64 + toU128 : Int * -> U128 + + toI8Checked : Int * -> Result I8 [ OutOfBounds ]* + toI16Checked : Int * -> Result I16 [ OutOfBounds ]* + toI32Checked : Int * -> Result I32 [ OutOfBounds ]* + toI64Checked : Int * -> Result I64 [ OutOfBounds ]* + toI128Checked : Int * -> Result I128 [ OutOfBounds ]* + toU8Checked : Int * -> Result U8 [ OutOfBounds ]* + toU16Checked : Int * -> Result U16 [ OutOfBounds ]* + toU32Checked : Int * -> Result U32 [ OutOfBounds ]* + toU64Checked : Int * -> Result U64 [ OutOfBounds ]* + toU128Checked : Int * -> Result U128 [ OutOfBounds ]* + "#; + + let parse_state = roc_parse::state::State::new(src_bytes.as_bytes()); + + return Ok(send_header( + info, + parse_state, + module_ids, + ident_ids_by_module, + module_timing, + )); + } + "Bool" => { + let filename = PathBuf::from("Bool.roc"); + + const EXPOSES: &[Loc] = &[ + Loc::at_zero(ExposedName::new("and")), + Loc::at_zero(ExposedName::new("or")), + // Loc::at_zero(ExposedName::new("xor")), + Loc::at_zero(ExposedName::new("not")), + Loc::at_zero(ExposedName::new("isEq")), + Loc::at_zero(ExposedName::new("isNotEq")), + ]; + const IMPORTS: &[Loc] = &[]; + + const GENERATES_WITH: &[Symbol] = &[]; + + let info = HeaderInfo { + loc_name: Loc { + region: Region::zero(), + value: ModuleNameEnum::Interface(roc_parse::header::ModuleName::new("Bool")), + }, + filename, + is_root_module: false, + opt_shorthand: None, + packages: &[], + exposes: EXPOSES, + imports: IMPORTS, + extra: HeaderFor::Builtin { + generates_with: GENERATES_WITH, + }, + }; + + let src_bytes = r#" + Bool : [ True, False ] + + and : Bool, Bool -> Bool + or : Bool, Bool -> Bool + # xor : Bool, Bool -> Bool # currently unimplemented + + not : Bool -> Bool + + isEq : a, a -> Bool + isNotEq : a, a -> Bool + "#; + + let parse_state = roc_parse::state::State::new(src_bytes.as_bytes()); + + return Ok(send_header( + info, + parse_state, + module_ids, + ident_ids_by_module, + module_timing, + )); + } + "Box" => { + let filename = PathBuf::from("Box.roc"); + + const EXPOSES: &[Loc] = &[ + Loc::at_zero(ExposedName::new("box")), + Loc::at_zero(ExposedName::new("unbox")), + ]; + const IMPORTS: &[Loc] = &[]; + + const GENERATES_WITH: &[Symbol] = &[]; + + let info = HeaderInfo { + loc_name: Loc { + region: Region::zero(), + value: ModuleNameEnum::Interface(roc_parse::header::ModuleName::new("Box")), + }, + filename, + is_root_module: false, + opt_shorthand: None, + packages: &[], + exposes: EXPOSES, + imports: IMPORTS, + extra: HeaderFor::Builtin { + generates_with: GENERATES_WITH, + }, + }; + + let src_bytes = r#" + box : a -> Box a + unbox : Box a -> a + + map : Box a, (a -> b) -> Box b + map = \boxed, transform = + boxed + |> Box.unbox + |> transform + |> Box.box "#; let parse_state = roc_parse::state::State::new(src_bytes.as_bytes()); diff --git a/compiler/module/src/low_level.rs b/compiler/module/src/low_level.rs index be5a8394d3..940328dbb5 100644 --- a/compiler/module/src/low_level.rs +++ b/compiler/module/src/low_level.rs @@ -66,6 +66,7 @@ pub enum LowLevel { DictDifference, DictWalk, SetFromList, + SetToDict, NumAdd, NumAddWrap, NumAddChecked, diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index e01ebef291..713f7a50f6 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -897,11 +897,11 @@ define_builtins! { 9 NUM_U16: "U16" imported // the Num.U16 type alias 10 NUM_I8: "I8" imported // the Num.I8 type alias 11 NUM_U8: "U8" imported // the Num.U8 type alias - 12 NUM_INTEGER: "Integer" imported // Int : Num Integer + 12 NUM_INTEGER: "Integer" // Int : Num Integer 13 NUM_AT_INTEGER: "@Integer" // the Int.@Integer private tag 14 NUM_F64: "F64" imported // the Num.F64 type alias 15 NUM_F32: "F32" imported // the Num.F32 type alias - 16 NUM_FLOATINGPOINT: "FloatingPoint" imported // Float : Num FloatingPoint + 16 NUM_FLOATINGPOINT: "FloatingPoint" // Float : Num FloatingPoint 17 NUM_AT_FLOATINGPOINT: "@FloatingPoint" // the Float.@FloatingPoint private tag 18 NUM_MAX_FLOAT: "maxFloat" 19 NUM_MIN_FLOAT: "minFloat" @@ -943,29 +943,29 @@ define_builtins! { 55 NUM_ACOS: "acos" 56 NUM_ASIN: "asin" 57 NUM_AT_SIGNED128: "@Signed128" - 58 NUM_SIGNED128: "Signed128" imported + 58 NUM_SIGNED128: "Signed128" 59 NUM_AT_SIGNED64: "@Signed64" - 60 NUM_SIGNED64: "Signed64" imported + 60 NUM_SIGNED64: "Signed64" 61 NUM_AT_SIGNED32: "@Signed32" - 62 NUM_SIGNED32: "Signed32" imported + 62 NUM_SIGNED32: "Signed32" 63 NUM_AT_SIGNED16: "@Signed16" - 64 NUM_SIGNED16: "Signed16" imported + 64 NUM_SIGNED16: "Signed16" 65 NUM_AT_SIGNED8: "@Signed8" - 66 NUM_SIGNED8: "Signed8" imported + 66 NUM_SIGNED8: "Signed8" 67 NUM_AT_UNSIGNED128: "@Unsigned128" - 68 NUM_UNSIGNED128: "Unsigned128" imported + 68 NUM_UNSIGNED128: "Unsigned128" 69 NUM_AT_UNSIGNED64: "@Unsigned64" - 70 NUM_UNSIGNED64: "Unsigned64" imported + 70 NUM_UNSIGNED64: "Unsigned64" 71 NUM_AT_UNSIGNED32: "@Unsigned32" - 72 NUM_UNSIGNED32: "Unsigned32" imported + 72 NUM_UNSIGNED32: "Unsigned32" 73 NUM_AT_UNSIGNED16: "@Unsigned16" - 74 NUM_UNSIGNED16: "Unsigned16" imported + 74 NUM_UNSIGNED16: "Unsigned16" 75 NUM_AT_UNSIGNED8: "@Unsigned8" - 76 NUM_UNSIGNED8: "Unsigned8" imported + 76 NUM_UNSIGNED8: "Unsigned8" 77 NUM_AT_BINARY64: "@Binary64" - 78 NUM_BINARY64: "Binary64" imported + 78 NUM_BINARY64: "Binary64" 79 NUM_AT_BINARY32: "@Binary32" - 80 NUM_BINARY32: "Binary32" imported + 80 NUM_BINARY32: "Binary32" 81 NUM_BITWISE_AND: "bitwiseAnd" 82 NUM_BITWISE_XOR: "bitwiseXor" 83 NUM_BITWISE_OR: "bitwiseOr" @@ -980,13 +980,13 @@ define_builtins! { 92 NUM_INT: "Int" imported 93 NUM_FLOAT: "Float" imported 94 NUM_AT_NATURAL: "@Natural" - 95 NUM_NATURAL: "Natural" imported + 95 NUM_NATURAL: "Natural" 96 NUM_NAT: "Nat" imported 97 NUM_INT_CAST: "intCast" 98 NUM_IS_MULTIPLE_OF: "isMultipleOf" 99 NUM_AT_DECIMAL: "@Decimal" - 100 NUM_DECIMAL: "Decimal" imported - 101 NUM_DEC: "Dec" imported // the Num.Dectype alias + 100 NUM_DECIMAL: "Decimal" + 101 NUM_DEC: "Dec" imported // the Num.Dectype alias 102 NUM_BYTES_TO_U16: "bytesToU16" 103 NUM_BYTES_TO_U32: "bytesToU32" 104 NUM_CAST_TO_NAT: "#castToNat" @@ -1032,7 +1032,7 @@ define_builtins! { 144 NUM_TO_U128_CHECKED: "toU128Checked" } 2 BOOL: "Bool" => { - 0 BOOL_BOOL: "Bool" imported // the Bool.Bool type alias + 0 BOOL_BOOL: "Bool" // the Bool.Bool type alias 1 BOOL_FALSE: "False" imported // Bool.Bool = [ False, True ] // NB: not strictly needed; used for finding global tag names in error suggestions 2 BOOL_TRUE: "True" imported // Bool.Bool = [ False, True ] @@ -1191,6 +1191,7 @@ define_builtins! { 12 SET_WALK: "walk" 13 SET_WALK_USER_FUNCTION: "#walk_user_function" 14 SET_CONTAINS: "contains" + 15 SET_TO_DICT: "toDict" } num_modules: 8 // Keep this count up to date by hand! (TODO: see the mut_map! macro for how we could determine this count correctly in the macro) diff --git a/compiler/mono/src/borrow.rs b/compiler/mono/src/borrow.rs index 3f6a0bbc4e..df1bc9c731 100644 --- a/compiler/mono/src/borrow.rs +++ b/compiler/mono/src/borrow.rs @@ -1008,6 +1008,7 @@ pub fn lowlevel_borrow_signature(arena: &Bump, op: LowLevel) -> &[bool] { DictWalk => arena.alloc_slice_copy(&[owned, owned, function, closure_data]), SetFromList => arena.alloc_slice_copy(&[owned]), + SetToDict => arena.alloc_slice_copy(&[owned]), ExpectTrue => arena.alloc_slice_copy(&[irrelevant]), diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index 37678aef34..707cd0eac7 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -3,7 +3,7 @@ use roc_can::constraint::PresenceConstraint; use roc_can::expected::{Expected, PExpected}; use roc_collections::all::MutMap; use roc_module::ident::TagName; -use roc_module::symbol::Symbol; +use roc_module::symbol::{ModuleId, Symbol}; use roc_region::all::{Loc, Region}; use roc_types::solved_types::Solved; use roc_types::subs::{ @@ -326,7 +326,10 @@ fn solve( } } None => { - problems.push(TypeError::UnexposedLookup(*symbol)); + // TODO fix this properly + if symbol.module_id() != ModuleId::ATTR { + problems.push(TypeError::UnexposedLookup(*symbol)); + } state } diff --git a/reporting/src/error/type.rs b/reporting/src/error/type.rs index a9c1251647..537fcfdafe 100644 --- a/reporting/src/error/type.rs +++ b/reporting/src/error/type.rs @@ -948,13 +948,25 @@ fn to_expr_report<'b>( None, ), - Reason::LowLevelOpArg { op, arg_index } => { - panic!( - "Compiler bug: argument #{} to low-level operation {:?} was the wrong type!", + Reason::LowLevelOpArg { op, arg_index } => report_mismatch( + alloc, + lines, + filename, + &category, + found, + expected_type, + region, + Some(expr_region), + alloc.text(format!( + "The {} argument to low level operation {:?} has the wrong type:", arg_index.ordinal(), op - ); - } + )), + alloc.text("Here the value is used as a:"), + alloc.text("But the lowlevel expects it to be:"), + None, + ), + Reason::ForeignCallArg { foreign_symbol, arg_index, From 0107d78ea0534747a5071c7892ba03d0342953e2 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 27 Feb 2022 13:03:47 +0100 Subject: [PATCH 005/846] most of Num --- compiler/load/src/file.rs | 357 +++++++++++++++++-------------- compiler/module/src/symbol.rs | 34 +-- compiler/test_gen/src/gen_num.rs | 2 +- 3 files changed, 218 insertions(+), 175 deletions(-) diff --git a/compiler/load/src/file.rs b/compiler/load/src/file.rs index de34d6255a..3c102ee456 100644 --- a/compiler/load/src/file.rs +++ b/compiler/load/src/file.rs @@ -135,10 +135,10 @@ impl Default for ModuleCache<'_> { PQModuleName::Unqualified(ModuleName::from(ModuleName::BOOL)), ); - // module_names.insert( - // ModuleId::NUM, - // PQModuleName::Unqualified(ModuleName::from(ModuleName::NUM)), - // ); + module_names.insert( + ModuleId::NUM, + PQModuleName::Unqualified(ModuleName::from(ModuleName::NUM)), + ); Self { module_names, @@ -1734,7 +1734,6 @@ fn update<'a>( ); } - /* if ![ModuleId::NUM, ModuleId::BOOL, ModuleId::RESULT].contains(&header.module_id) { header .package_qualified_imported_modules @@ -1744,11 +1743,32 @@ fn update<'a>( .imported_modules .insert(ModuleId::NUM, Region::zero()); - header - .exposed_imports - .insert(Ident::from("Num"), (Symbol::NUM_NUM, Region::zero())); + let prelude_types = [ + Symbol::NUM_NUM, + Symbol::NUM_INT, + Symbol::NUM_FLOAT, + Symbol::NUM_NAT, + Symbol::NUM_I8, + Symbol::NUM_I16, + Symbol::NUM_I32, + Symbol::NUM_I64, + Symbol::NUM_I128, + Symbol::NUM_U8, + Symbol::NUM_U16, + Symbol::NUM_U32, + Symbol::NUM_U64, + Symbol::NUM_U128, + Symbol::NUM_F32, + Symbol::NUM_F64, + Symbol::NUM_DEC, + ]; + + for symbol in prelude_types { + header + .exposed_imports + .insert(Ident::from("Num"), (symbol, Region::zero())); + } } - */ if header.module_id != ModuleId::BOOL { header @@ -1765,14 +1785,15 @@ fn update<'a>( } if !header.module_id.is_builtin() { - header - .package_qualified_imported_modules - .insert(PackageQualified::Unqualified(ModuleId::STR)); - - header - .imported_modules - .insert(ModuleId::STR, Region::zero()); + // header + // .package_qualified_imported_modules + // .insert(PackageQualified::Unqualified(ModuleId::STR)); + // + // header + // .imported_modules + // .insert(ModuleId::STR, Region::zero()); + /* header .package_qualified_imported_modules .insert(PackageQualified::Unqualified(ModuleId::DICT)); @@ -1796,6 +1817,7 @@ fn update<'a>( header .imported_modules .insert(ModuleId::LIST, Region::zero()); + */ } state @@ -2574,10 +2596,10 @@ fn load_module<'a>( roc_parse::header::ModuleName::new("Bool"), Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("Bool")))]), )), - // Loc::at_zero(ImportsEntry::Module( - // roc_parse::header::ModuleName::new("Num"), - // Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("Nat")))]), - // )), + Loc::at_zero(ImportsEntry::Module( + roc_parse::header::ModuleName::new("Num"), + Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("Nat")))]), + )), ]; const GENERATES_WITH: &[Symbol] = &[]; @@ -2682,14 +2704,15 @@ fn load_module<'a>( Loc::at_zero(ExposedName::new("repeat")), Loc::at_zero(ExposedName::new("countGraphemes")), Loc::at_zero(ExposedName::new("startsWithCodePt")), - Loc::at_zero(ExposedName::new("toUtf8")), - Loc::at_zero(ExposedName::new("fromUtf8")), - Loc::at_zero(ExposedName::new("fromUtf8Range")), + // Loc::at_zero(ExposedName::new("toUtf8")), + // Loc::at_zero(ExposedName::new("fromUtf8")), + // Loc::at_zero(ExposedName::new("fromUtf8Range")), Loc::at_zero(ExposedName::new("startsWith")), Loc::at_zero(ExposedName::new("endsWith")), Loc::at_zero(ExposedName::new("trim")), Loc::at_zero(ExposedName::new("trimLeft")), Loc::at_zero(ExposedName::new("trimRight")), + /* Loc::at_zero(ExposedName::new("toDec")), Loc::at_zero(ExposedName::new("toF64")), Loc::at_zero(ExposedName::new("toF32")), @@ -2704,6 +2727,7 @@ fn load_module<'a>( Loc::at_zero(ExposedName::new("toI16")), Loc::at_zero(ExposedName::new("toU8")), Loc::at_zero(ExposedName::new("toI8")), + */ ]; const IMPORTS: &[Loc] = &[ @@ -2717,31 +2741,33 @@ fn load_module<'a>( roc_parse::header::ModuleName::new("Bool"), Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("Bool")))]), )), + /* Loc::at_zero(ImportsEntry::Module( roc_parse::header::ModuleName::new("List"), Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("List")))]), )), - // Loc::at_zero(ImportsEntry::Module( - // roc_parse::header::ModuleName::new("Num"), - // Collection::with_items(&[ - // Loc::at_zero(Spaced::Item(ExposedName::new("Int"))), // needed because used by the aliases below - // Loc::at_zero(Spaced::Item(ExposedName::new("Float"))), // needed because used by the aliases below - // Loc::at_zero(Spaced::Item(ExposedName::new("Dec"))), - // Loc::at_zero(Spaced::Item(ExposedName::new("F64"))), - // Loc::at_zero(Spaced::Item(ExposedName::new("F32"))), - // Loc::at_zero(Spaced::Item(ExposedName::new("Nat"))), - // Loc::at_zero(Spaced::Item(ExposedName::new("U128"))), - // Loc::at_zero(Spaced::Item(ExposedName::new("I128"))), - // Loc::at_zero(Spaced::Item(ExposedName::new("U64"))), - // Loc::at_zero(Spaced::Item(ExposedName::new("I64"))), - // Loc::at_zero(Spaced::Item(ExposedName::new("U32"))), - // Loc::at_zero(Spaced::Item(ExposedName::new("I32"))), - // Loc::at_zero(Spaced::Item(ExposedName::new("U16"))), - // Loc::at_zero(Spaced::Item(ExposedName::new("I16"))), - // Loc::at_zero(Spaced::Item(ExposedName::new("U8"))), - // Loc::at_zero(Spaced::Item(ExposedName::new("I8"))), - // ]), - // )), + */ + Loc::at_zero(ImportsEntry::Module( + roc_parse::header::ModuleName::new("Num"), + Collection::with_items(&[ + Loc::at_zero(Spaced::Item(ExposedName::new("Int"))), // needed because used by the aliases below + Loc::at_zero(Spaced::Item(ExposedName::new("Float"))), // needed because used by the aliases below + Loc::at_zero(Spaced::Item(ExposedName::new("Dec"))), + Loc::at_zero(Spaced::Item(ExposedName::new("F64"))), + Loc::at_zero(Spaced::Item(ExposedName::new("F32"))), + Loc::at_zero(Spaced::Item(ExposedName::new("Nat"))), + Loc::at_zero(Spaced::Item(ExposedName::new("U128"))), + Loc::at_zero(Spaced::Item(ExposedName::new("I128"))), + Loc::at_zero(Spaced::Item(ExposedName::new("U64"))), + Loc::at_zero(Spaced::Item(ExposedName::new("I64"))), + Loc::at_zero(Spaced::Item(ExposedName::new("U32"))), + Loc::at_zero(Spaced::Item(ExposedName::new("I32"))), + Loc::at_zero(Spaced::Item(ExposedName::new("U16"))), + Loc::at_zero(Spaced::Item(ExposedName::new("I16"))), + Loc::at_zero(Spaced::Item(ExposedName::new("U8"))), + Loc::at_zero(Spaced::Item(ExposedName::new("I8"))), + ]), + )), ]; const GENERATES_WITH: &[Symbol] = &[]; @@ -2773,23 +2799,24 @@ fn load_module<'a>( EncodesSurrogateHalf, ] - Utf8Problem : { byteIndex : Nat, problem : Utf8ByteProblem } + # Utf8Problem : { byteIndex : Nat, problem : Utf8ByteProblem } isEmpty : Str -> Bool concat : Str, Str -> Str + joinWith : List Str, Str -> Str split : Str, Str -> List Str repeat : Str, Nat -> Str countGraphemes : Str -> Nat startsWithCodePt : Str, U32 -> Bool - toUtf8 : Str -> List U8 + # toUtf8 : Str -> List U8 # fromUtf8 : List U8 -> Result Str [ BadUtf8 Utf8Problem ]* # fromUtf8Range : List U8 -> Result Str [ BadUtf8 Utf8Problem, OutOfBounds ]* - fromUtf8 : List U8 -> Result Str [ BadUtf8 Utf8ByteProblem Nat ]* - fromUtf8Range : List U8 -> Result Str [ BadUtf8 Utf8ByteProblem Nat, OutOfBounds ]* + # fromUtf8 : List U8 -> Result Str [ BadUtf8 Utf8ByteProblem Nat ]* + # fromUtf8Range : List U8 -> Result Str [ BadUtf8 Utf8ByteProblem Nat, OutOfBounds ]* startsWith : Str, Str -> Bool endsWith : Str, Str -> Bool @@ -2797,21 +2824,6 @@ fn load_module<'a>( trim : Str -> Str trimLeft : Str -> Str trimRight : Str -> Str - - toDec : Str -> Result Dec [ InvalidNumStr ]* - toF64 : Str -> Result F64 [ InvalidNumStr ]* - toF32 : Str -> Result F32 [ InvalidNumStr ]* - toNat : Str -> Result Nat [ InvalidNumStr ]* - toU128 : Str -> Result U128 [ InvalidNumStr ]* - toI128 : Str -> Result I128 [ InvalidNumStr ]* - toU64 : Str -> Result U64 [ InvalidNumStr ]* - toI64 : Str -> Result I64 [ InvalidNumStr ]* - toU32 : Str -> Result U32 [ InvalidNumStr ]* - toI32 : Str -> Result I32 [ InvalidNumStr ]* - toU16 : Str -> Result U16 [ InvalidNumStr ]* - toI16 : Str -> Result I16 [ InvalidNumStr ]* - toU8 : Str -> Result U8 [ InvalidNumStr ]* - toI8 : Str -> Result I8 [ InvalidNumStr ]* "#; let parse_state = roc_parse::state::State::new(src_bytes.as_bytes()); @@ -2939,10 +2951,10 @@ fn load_module<'a>( roc_parse::header::ModuleName::new("List"), Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("List")))]), )), - // Loc::at_zero(ImportsEntry::Module( - // roc_parse::header::ModuleName::new("Num"), - // Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("Nat")))]), - // )), + Loc::at_zero(ImportsEntry::Module( + roc_parse::header::ModuleName::new("Num"), + Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("Nat")))]), + )), ]; const GENERATES_WITH: &[Symbol] = &[]; @@ -3004,6 +3016,9 @@ fn load_module<'a>( Loc::at_zero(ExposedName::new("Int")), Loc::at_zero(ExposedName::new("Float")), // + Loc::at_zero(ExposedName::new("Integer")), + Loc::at_zero(ExposedName::new("FloatingPoint")), + // Loc::at_zero(ExposedName::new("I128")), Loc::at_zero(ExposedName::new("I64")), Loc::at_zero(ExposedName::new("I32")), @@ -3016,9 +3031,30 @@ fn load_module<'a>( Loc::at_zero(ExposedName::new("U16")), Loc::at_zero(ExposedName::new("U8")), // + Loc::at_zero(ExposedName::new("Signed128")), + Loc::at_zero(ExposedName::new("Signed64")), + Loc::at_zero(ExposedName::new("Signed32")), + Loc::at_zero(ExposedName::new("Signed16")), + Loc::at_zero(ExposedName::new("Signed8")), + // + Loc::at_zero(ExposedName::new("Unsigned128")), + Loc::at_zero(ExposedName::new("Unsigned64")), + Loc::at_zero(ExposedName::new("Unsigned32")), + Loc::at_zero(ExposedName::new("Unsigned16")), + Loc::at_zero(ExposedName::new("Unsigned8")), + // Loc::at_zero(ExposedName::new("Nat")), Loc::at_zero(ExposedName::new("Dec")), // + Loc::at_zero(ExposedName::new("F32")), + Loc::at_zero(ExposedName::new("F64")), + // + Loc::at_zero(ExposedName::new("Natural")), + Loc::at_zero(ExposedName::new("Decimal")), + // + Loc::at_zero(ExposedName::new("Binary32")), + Loc::at_zero(ExposedName::new("Binary64")), + // // Loc::at_zero(ExposedName::new("maxFloat")), // Loc::at_zero(ExposedName::new("minFloat")), Loc::at_zero(ExposedName::new("abs")), @@ -3030,13 +3066,16 @@ fn load_module<'a>( Loc::at_zero(ExposedName::new("isLte")), Loc::at_zero(ExposedName::new("isGt")), Loc::at_zero(ExposedName::new("isGte")), - Loc::at_zero(ExposedName::new("toFloat")), Loc::at_zero(ExposedName::new("sin")), Loc::at_zero(ExposedName::new("cos")), Loc::at_zero(ExposedName::new("tan")), + Loc::at_zero(ExposedName::new("atan")), + Loc::at_zero(ExposedName::new("acos")), + Loc::at_zero(ExposedName::new("asin")), Loc::at_zero(ExposedName::new("isZero")), Loc::at_zero(ExposedName::new("isEven")), Loc::at_zero(ExposedName::new("isOdd")), + Loc::at_zero(ExposedName::new("toFloat")), Loc::at_zero(ExposedName::new("isPositive")), Loc::at_zero(ExposedName::new("isNegative")), Loc::at_zero(ExposedName::new("rem")), @@ -3047,17 +3086,14 @@ fn load_module<'a>( Loc::at_zero(ExposedName::new("sqrt")), Loc::at_zero(ExposedName::new("log")), Loc::at_zero(ExposedName::new("round")), + Loc::at_zero(ExposedName::new("ceiling")), + Loc::at_zero(ExposedName::new("floor")), Loc::at_zero(ExposedName::new("compare")), Loc::at_zero(ExposedName::new("pow")), - Loc::at_zero(ExposedName::new("ceiling")), Loc::at_zero(ExposedName::new("powInt")), - Loc::at_zero(ExposedName::new("floor")), Loc::at_zero(ExposedName::new("addWrap")), Loc::at_zero(ExposedName::new("addChecked")), Loc::at_zero(ExposedName::new("addSaturated")), - Loc::at_zero(ExposedName::new("atan")), - Loc::at_zero(ExposedName::new("acos")), - Loc::at_zero(ExposedName::new("asin")), Loc::at_zero(ExposedName::new("bitwiseAnd")), Loc::at_zero(ExposedName::new("bitwiseXor")), Loc::at_zero(ExposedName::new("bitwiseOr")), @@ -3069,30 +3105,33 @@ fn load_module<'a>( Loc::at_zero(ExposedName::new("subSaturated")), Loc::at_zero(ExposedName::new("mulWrap")), Loc::at_zero(ExposedName::new("mulChecked")), + /* Loc::at_zero(ExposedName::new("intCast")), - Loc::at_zero(ExposedName::new("isMultipleOf")), Loc::at_zero(ExposedName::new("bytesToU16")), Loc::at_zero(ExposedName::new("bytesToU32")), Loc::at_zero(ExposedName::new("divCeil")), Loc::at_zero(ExposedName::new("toStr")), - Loc::at_zero(ExposedName::new("minI8")), - Loc::at_zero(ExposedName::new("maxI8")), - Loc::at_zero(ExposedName::new("minU8")), - Loc::at_zero(ExposedName::new("maxU8")), - Loc::at_zero(ExposedName::new("minI16")), - Loc::at_zero(ExposedName::new("maxI16")), - Loc::at_zero(ExposedName::new("minU16")), - Loc::at_zero(ExposedName::new("maxU16")), - Loc::at_zero(ExposedName::new("minI32")), - Loc::at_zero(ExposedName::new("maxI32")), - Loc::at_zero(ExposedName::new("minU32")), - Loc::at_zero(ExposedName::new("maxU32")), - Loc::at_zero(ExposedName::new("minI64")), - Loc::at_zero(ExposedName::new("maxI64")), - Loc::at_zero(ExposedName::new("minU64")), - Loc::at_zero(ExposedName::new("maxU64")), - Loc::at_zero(ExposedName::new("minI128")), - Loc::at_zero(ExposedName::new("maxI128")), + */ + Loc::at_zero(ExposedName::new("isMultipleOf")), + // Loc::at_zero(ExposedName::new("minI8")), + // Loc::at_zero(ExposedName::new("maxI8")), + // Loc::at_zero(ExposedName::new("minU8")), + // Loc::at_zero(ExposedName::new("maxU8")), + // Loc::at_zero(ExposedName::new("minI16")), + // Loc::at_zero(ExposedName::new("maxI16")), + // Loc::at_zero(ExposedName::new("minU16")), + // Loc::at_zero(ExposedName::new("maxU16")), + // Loc::at_zero(ExposedName::new("minI32")), + // Loc::at_zero(ExposedName::new("maxI32")), + // Loc::at_zero(ExposedName::new("minU32")), + // Loc::at_zero(ExposedName::new("maxU32")), + // Loc::at_zero(ExposedName::new("minI64")), + // Loc::at_zero(ExposedName::new("maxI64")), + // Loc::at_zero(ExposedName::new("minU64")), + // Loc::at_zero(ExposedName::new("maxU64")), + // Unimplemented + // Loc::at_zero(ExposedName::new("minI128")), + // Loc::at_zero(ExposedName::new("maxI128")), Loc::at_zero(ExposedName::new("toI8")), Loc::at_zero(ExposedName::new("toI8Checked")), Loc::at_zero(ExposedName::new("toI16")), @@ -3135,65 +3174,67 @@ fn load_module<'a>( }; let src_bytes = r#" - Num range : [ @Num range ] - Integer range : [ @Integer range ] - Float range : [ @Float range ] - - Natural : [ @Natural ] - Nat : Int Natural + Int range : Num (Integer range) + Float range : Num (FloatingPoint range) Signed128 : [ @Signed128 ] - I128 : Int Signed128 + Signed64 : [ @Signed64 ] + Signed32 : [ @Signed32 ] + Signed16 : [ @Signed16 ] + Signed8 : [ @Signed8 ] Unsigned128 : [ @Unsigned128 ] - U128 : Int Unsigned128 - - Signed64 : [ @Signed64 ] - I64 : Int Signed64 - Unsigned64 : [ @Unsigned64 ] - U64 : Int Unsigned64 - - Signed32 : [ @Signed32 ] - I32 : Int Signed32 - Unsigned32 : [ @Unsigned32 ] - U32 : Int Unsigned32 - - Signed16 : [ @Signed16 ] - I16 : Int Signed16 - Unsigned16 : [ @Unsigned16 ] - U16 : Int Unsigned16 - - Signed8 : [ @Signed8 ] - I8 : Int Signed8 - Unsigned8 : [ @Unsigned8 ] - U8 : Int Unsigned8 + + Natural : [ @Natural ] + + Integer range : [ @Integer range ] + + I128 : Num (Integer Signed128) + I64 : Num (Integer Signed64) + I32 : Num (Integer Signed32) + I16 : Num (Integer Signed16) + I8 : Int Signed8 + + U128 : Num (Integer Unsigned128) + U64 : Num (Integer Unsigned64) + U32 : Num (Integer Unsigned32) + U16 : Num (Integer Unsigned16) + U8 : Num (Integer Unsigned8) + + Nat : Num (Integer Natural) Decimal : [ @Decimal ] - Dec : Float Decimal - Binary64 : [ @Binary64 ] - F64 : Float Binary64 - Binary32 : [ @Binary32 ] - F32 : Float Binary32 + + FloatingPoint range : [ @FloatingPoint range ] + + F64 : Num (FloatingPoint Binary64) + F32 : Num (FloatingPoint Binary32) + Dec : Num (FloatingPoint Decimal) + + # ------- Functions compare : Num a, Num a -> [ LT, EQ, GT ] isLt : Num a, Num a -> Bool isGt : Num a, Num a -> Bool isLte : Num a, Num a -> Bool - isLte : Num a, Num a -> Bool + isGte : Num a, Num a -> Bool isZero : Num a -> Bool isEven : Int a -> Bool isOdd : Int a -> Bool + isPositive : Num a -> Bool + isNegative : Num a -> Bool + toFloat : Num * -> Float * abs : Num a -> Num a @@ -3203,9 +3244,6 @@ fn load_module<'a>( sub : Num a, Num a -> Num a mul : Num a, Num a -> Num a - # maxFloat : Float a - # minFloat : Float a - sin : Float a -> Float a cos : Float a -> Float a tan : Float a -> Float a @@ -3214,14 +3252,22 @@ fn load_module<'a>( acos : Float a -> Float a atan : Float a -> Float a - sqrt : Float a -> Float a - log : Float a, Float a -> Float a - mod : Float a, Float a -> Result (Float a) [ DivByZero ]* + sqrt : Float a -> Result (Float a) [ SqrtOfNegative ]* + log : Float a, Float a -> Result (Float a) [ LogNeedsPositive ]* + div : Float a -> Result (Float a) [ DivByZero ]* + # mod : Float a, Float a -> Result (Float a) [ DivByZero ]* rem : Int a, Int a -> Result (Int a) [ DivByZero ]* - mod : Int a, Int a -> Result (Int a) [ DivByZero ]* + # mod : Int a, Int a -> Result (Int a) [ DivByZero ]* isMultipleOf : Int a, Int a -> Bool + bitwiseAnd : Int a, Int a -> Int a + bitwiseXor : Int a, Int a -> Int a + bitwiseOr : Int a, Int a -> Int a + shiftLeftBy : Int a, Int a -> Int a + shiftRightBy : Int a, Int a -> Int a + shiftRightZfBy : Int a, Int a -> Int a + round : Float a -> Int b floor : Float a -> Int b ceiling : Float a -> Int b @@ -3241,31 +3287,27 @@ fn load_module<'a>( # mulSaturated : Num a, Num a -> Num a mulChecked : Num a, Num a -> Result (Num a) [ Overflow ]* - bitwiseAnd : Int a, Int a -> Int a - bitwiseXor : Int a, Int a -> Int a - bitwiseOr : Int a, Int a -> Int a - shiftLeftBy : Int a, Int a -> Int a - shiftRightBy : Int a, Int a -> Int a - shiftRightZfBy : Int a, Int a -> Int a + # minI8 : I8 + # maxI8 : I8 + # minU8 : U8 + # maxU8 : U8 + # minI16 : I16 + # maxI16 : I16 + # minU16 : U16 + # maxU16 : U16 + # minI32 : I32 + # maxI32 : I32 + # minU32 : U32 + # maxU32 : U32 + # minI64 : I64 + # maxI64 : I64 + # minU64 : U64 + # maxU64 : U64 - intCast : Int a -> Int b - - minI8 : I8 - maxI8 : I8 - minU8 : U8 - maxU8 : U8 - minI16 : I16 - maxI16 : I16 - minU16 : U16 - maxU16 : U16 - minI32 : I32 - maxI32 : I32 - minU32 : U32 - maxU32 : U32 - minI64 : I64 - maxI64 : I64 - minU64 : U64 - maxU64 : U64 + # minI128 : I128 + # maxI128 : I128 + # minU128 : U128 + # maxU128 : U128 toI8 : Int * -> I8 toI16 : Int * -> I16 @@ -4243,6 +4285,7 @@ fn run_solve<'a>( // Finish constraining the module by wrapping the existing Constraint // in the ones we just computed. We can do this off the main thread. let constraint = constrain_imports(imported_symbols, constraint, &mut var_store); + dbg!(&constraint); let constrain_end = SystemTime::now(); diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index 713f7a50f6..0888f71e86 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -885,22 +885,22 @@ define_builtins! { 26 DEV_TMP: "#dev_tmp" } 1 NUM: "Num" => { - 0 NUM_NUM: "Num" imported // the Num.Num type alias + 0 NUM_NUM: "Num" // the Num.Num type alias 1 NUM_AT_NUM: "@Num" // the Num.@Num private tag - 2 NUM_I128: "I128" imported // the Num.I128 type alias - 3 NUM_U128: "U128" imported // the Num.U128 type alias - 4 NUM_I64: "I64" imported // the Num.I64 type alias - 5 NUM_U64: "U64" imported // the Num.U64 type alias - 6 NUM_I32: "I32" imported // the Num.I32 type alias - 7 NUM_U32: "U32" imported // the Num.U32 type alias - 8 NUM_I16: "I16" imported // the Num.I16 type alias - 9 NUM_U16: "U16" imported // the Num.U16 type alias - 10 NUM_I8: "I8" imported // the Num.I8 type alias - 11 NUM_U8: "U8" imported // the Num.U8 type alias + 2 NUM_I128: "I128" // the Num.I128 type alias + 3 NUM_U128: "U128" // the Num.U128 type alias + 4 NUM_I64: "I64" // the Num.I64 type alias + 5 NUM_U64: "U64" // the Num.U64 type alias + 6 NUM_I32: "I32" // the Num.I32 type alias + 7 NUM_U32: "U32" // the Num.U32 type alias + 8 NUM_I16: "I16" // the Num.I16 type alias + 9 NUM_U16: "U16" // the Num.U16 type alias + 10 NUM_I8: "I8" // the Num.I8 type alias + 11 NUM_U8: "U8" // the Num.U8 type alias 12 NUM_INTEGER: "Integer" // Int : Num Integer 13 NUM_AT_INTEGER: "@Integer" // the Int.@Integer private tag - 14 NUM_F64: "F64" imported // the Num.F64 type alias - 15 NUM_F32: "F32" imported // the Num.F32 type alias + 14 NUM_F64: "F64" // the Num.F64 type alias + 15 NUM_F32: "F32" // the Num.F32 type alias 16 NUM_FLOATINGPOINT: "FloatingPoint" // Float : Num FloatingPoint 17 NUM_AT_FLOATINGPOINT: "@FloatingPoint" // the Float.@FloatingPoint private tag 18 NUM_MAX_FLOAT: "maxFloat" @@ -977,16 +977,16 @@ define_builtins! { 89 NUM_SUB_SATURATED: "subSaturated" 90 NUM_MUL_WRAP: "mulWrap" 91 NUM_MUL_CHECKED: "mulChecked" - 92 NUM_INT: "Int" imported - 93 NUM_FLOAT: "Float" imported + 92 NUM_INT: "Int" + 93 NUM_FLOAT: "Float" 94 NUM_AT_NATURAL: "@Natural" 95 NUM_NATURAL: "Natural" - 96 NUM_NAT: "Nat" imported + 96 NUM_NAT: "Nat" 97 NUM_INT_CAST: "intCast" 98 NUM_IS_MULTIPLE_OF: "isMultipleOf" 99 NUM_AT_DECIMAL: "@Decimal" 100 NUM_DECIMAL: "Decimal" - 101 NUM_DEC: "Dec" imported // the Num.Dectype alias + 101 NUM_DEC: "Dec" // the Num.Dectype alias 102 NUM_BYTES_TO_U16: "bytesToU16" 103 NUM_BYTES_TO_U32: "bytesToU32" 104 NUM_CAST_TO_NAT: "#castToNat" diff --git a/compiler/test_gen/src/gen_num.rs b/compiler/test_gen/src/gen_num.rs index f7a5bccc4b..8b7d51f7f2 100644 --- a/compiler/test_gen/src/gen_num.rs +++ b/compiler/test_gen/src/gen_num.rs @@ -19,7 +19,7 @@ fn nat_alias() { assert_evals_to!( indoc!( r#" - i : Nat + i : Num.Nat i = 1 i From 5c31234b24fe72ba1489f0603875acf8e7adc2f3 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 27 Feb 2022 13:07:45 +0100 Subject: [PATCH 006/846] stack overflow in Num type inference --- compiler/load/src/file.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/load/src/file.rs b/compiler/load/src/file.rs index 3c102ee456..80693489f9 100644 --- a/compiler/load/src/file.rs +++ b/compiler/load/src/file.rs @@ -3287,7 +3287,7 @@ fn load_module<'a>( # mulSaturated : Num a, Num a -> Num a mulChecked : Num a, Num a -> Result (Num a) [ Overflow ]* - # minI8 : I8 + minI8 : I8 # maxI8 : I8 # minU8 : U8 # maxU8 : U8 From db1669154e574f731dfbd273deb83b7a5bbaec11 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 27 Feb 2022 21:53:56 +0100 Subject: [PATCH 007/846] WIP --- compiler/builtins/src/std.rs | 2 +- compiler/can/src/annotation.rs | 3 +- compiler/can/src/module.rs | 11 ++- compiler/constrain/src/module.rs | 20 ++-- compiler/load/src/file.rs | 144 +++++++++++++++++++---------- compiler/solve/tests/solve_expr.rs | 2 +- 6 files changed, 118 insertions(+), 64 deletions(-) diff --git a/compiler/builtins/src/std.rs b/compiler/builtins/src/std.rs index 97394b969b..1d6737d9ae 100644 --- a/compiler/builtins/src/std.rs +++ b/compiler/builtins/src/std.rs @@ -314,7 +314,7 @@ pub fn types() -> MutMap { Box::new(result_type(int_type(flex(TVAR1)), div_by_zero.clone())), ); - //divCeil: Int a, Int a -> Result (Int a) [ DivByZero ]* + // divCeil: Int a, Int a -> Result (Int a) [ DivByZero ]* add_top_level_function_type!( Symbol::NUM_DIV_CEIL, vec![int_type(flex(TVAR1)), int_type(flex(TVAR1))], diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index 8d3febe818..a2a32e3120 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -383,8 +383,7 @@ fn can_annotation_help( As( loc_inner, _spaces, - alias_header - @ TypeHeader { + alias_header @ TypeHeader { name, vars: loc_vars, }, diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index 653e970fbc..60f8631fd3 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -242,12 +242,19 @@ pub fn canonicalize_module_defs<'a>( panic!("TODO gracefully handle shadowing in imports.") } } - } else if symbol == Symbol::LIST_LIST || symbol == Symbol::STR_STR { + } else if [ + Symbol::LIST_LIST, + Symbol::STR_STR, + Symbol::DICT_DICT, + Symbol::SET_SET, + // Symbol::BOX_BOX, + ] + .contains(&symbol) + { // These are not aliases but Apply's and we make sure they are always in scope } else { // This is a type alias - dbg!(scope.aliases.keys().collect::>()); // the symbol should already be added to the scope when this module is canonicalized debug_assert!( scope.contains_alias(symbol), diff --git a/compiler/constrain/src/module.rs b/compiler/constrain/src/module.rs index 5454a3b20d..e2f9b3066b 100644 --- a/compiler/constrain/src/module.rs +++ b/compiler/constrain/src/module.rs @@ -144,7 +144,14 @@ pub fn pre_constrain_imports( // We used this module, so clearly it is not unused! unused_imports.remove(&module_id); - if module_id.is_builtin() && module_id != ModuleId::STR { + let builtin_applies = [ + Symbol::LIST_LIST, + Symbol::STR_STR, + Symbol::DICT_DICT, + Symbol::SET_SET, + ]; + + if module_id.is_builtin() && builtin_applies.contains(&symbol) { // For builtin modules, we create imports from the // hardcoded builtin map. match stdlib.types.get(&symbol) { @@ -197,10 +204,7 @@ pub fn pre_constrain_imports( }); } None => { - panic!( - "Could not find module {:?} in exposed_types {:?}", - module_id, exposed_types - ); + panic!("Module {:?} does not have info for module {:?} in its exposed types", module_id, home) } } @@ -254,9 +258,9 @@ pub fn pre_constrain_imports( } None => { panic!( - "Could not find module {:?} in exposed_types {:?}", - module_id, exposed_types - ); + "Module {:?} does not have info for module {:?} in its exposed types.\n I was looking for symbol {:?}", + home, module_id, symbol, + ) } } } diff --git a/compiler/load/src/file.rs b/compiler/load/src/file.rs index 80693489f9..7c005ab5f9 100644 --- a/compiler/load/src/file.rs +++ b/compiler/load/src/file.rs @@ -278,8 +278,6 @@ fn start_phase<'a>( } } - dbg!(module_id, &parsed.imported_modules); - BuildTask::CanonicalizeAndConstrain { parsed, dep_idents, @@ -1744,29 +1742,45 @@ fn update<'a>( .insert(ModuleId::NUM, Region::zero()); let prelude_types = [ - Symbol::NUM_NUM, - Symbol::NUM_INT, - Symbol::NUM_FLOAT, - Symbol::NUM_NAT, - Symbol::NUM_I8, - Symbol::NUM_I16, - Symbol::NUM_I32, - Symbol::NUM_I64, - Symbol::NUM_I128, - Symbol::NUM_U8, - Symbol::NUM_U16, - Symbol::NUM_U32, - Symbol::NUM_U64, - Symbol::NUM_U128, - Symbol::NUM_F32, - Symbol::NUM_F64, - Symbol::NUM_DEC, + (Ident::from("Num"), Symbol::NUM_NUM), + (Ident::from("Int"), Symbol::NUM_INT), + (Ident::from("Float"), Symbol::NUM_FLOAT), + (Ident::from("Integer"), Symbol::NUM_INTEGER), + (Ident::from("FloatingPoint"), Symbol::NUM_FLOATINGPOINT), + (Ident::from("Binary32"), Symbol::NUM_BINARY32), + (Ident::from("Binary64"), Symbol::NUM_BINARY64), + (Ident::from("Signed128"), Symbol::NUM_SIGNED128), + (Ident::from("Signed64"), Symbol::NUM_SIGNED64), + (Ident::from("Signed32"), Symbol::NUM_SIGNED32), + (Ident::from("Signed16"), Symbol::NUM_SIGNED16), + (Ident::from("Signed8"), Symbol::NUM_SIGNED8), + (Ident::from("Unsigned128"), Symbol::NUM_UNSIGNED128), + (Ident::from("Unsigned64"), Symbol::NUM_UNSIGNED64), + (Ident::from("Unsigned32"), Symbol::NUM_UNSIGNED32), + (Ident::from("Unsigned16"), Symbol::NUM_UNSIGNED16), + (Ident::from("Unsigned8"), Symbol::NUM_UNSIGNED8), + (Ident::from("Natural"), Symbol::NUM_NATURAL), + (Ident::from("Decimal"), Symbol::NUM_DECIMAL), + (Ident::from("Nat"), Symbol::NUM_NAT), + (Ident::from("I8"), Symbol::NUM_I8), + (Ident::from("I16"), Symbol::NUM_I16), + (Ident::from("I32"), Symbol::NUM_I32), + (Ident::from("I64"), Symbol::NUM_I64), + (Ident::from("I128"), Symbol::NUM_I128), + (Ident::from("U8"), Symbol::NUM_U8), + (Ident::from("U16"), Symbol::NUM_U16), + (Ident::from("U32"), Symbol::NUM_U32), + (Ident::from("U64"), Symbol::NUM_U64), + (Ident::from("U128"), Symbol::NUM_U128), + (Ident::from("F32"), Symbol::NUM_F32), + (Ident::from("F64"), Symbol::NUM_F64), + (Ident::from("Dec"), Symbol::NUM_DEC), ]; - for symbol in prelude_types { + for (ident, symbol) in prelude_types { header .exposed_imports - .insert(Ident::from("Num"), (symbol, Region::zero())); + .insert(ident, (symbol, Region::zero())); } } @@ -1785,15 +1799,14 @@ fn update<'a>( } if !header.module_id.is_builtin() { - // header - // .package_qualified_imported_modules - // .insert(PackageQualified::Unqualified(ModuleId::STR)); - // - // header - // .imported_modules - // .insert(ModuleId::STR, Region::zero()); + header + .package_qualified_imported_modules + .insert(PackageQualified::Unqualified(ModuleId::STR)); + + header + .imported_modules + .insert(ModuleId::STR, Region::zero()); - /* header .package_qualified_imported_modules .insert(PackageQualified::Unqualified(ModuleId::DICT)); @@ -1817,7 +1830,6 @@ fn update<'a>( header .imported_modules .insert(ModuleId::LIST, Region::zero()); - */ } state @@ -2622,6 +2634,9 @@ fn load_module<'a>( let src_bytes = r#" isEmpty : List a -> Bool + isEmpty = \list -> + List.len list == 0 + get : List a, Nat -> Result a [ OutOfBounds ]* set : List a, Nat, a -> List a append : List a, a -> List a @@ -2639,7 +2654,12 @@ fn load_module<'a>( walkUntil : List elem, state, (state, elem -> [ Continue state, Stop state ]) -> state sum : List (Num a) -> Num a + sum = \list -> + List.walk list 0 Num.add + product : List (Num a) -> Num a + product = \list -> + List.walk list 1 Num.mul any : List a, (a -> Bool) -> Bool all : List a, (a -> Bool) -> Bool @@ -2657,7 +2677,11 @@ fn load_module<'a>( range : Int a, Int a -> List (Int a) sortWith : List a, (a, a -> [ LT, EQ, GT ] ) -> List a sortAsc : List (Num a) -> List (Num a) + sortAsc = \list -> List.sortWith list Num.compare + sortDesc : List (Num a) -> List (Num a) + sortDesc = \list -> List.sortWith list (\a, b -> Num.compare b a) + swap : List a, Nat, Nat -> List a first : List a -> Result a [ ListWasEmpty ]* @@ -2704,15 +2728,15 @@ fn load_module<'a>( Loc::at_zero(ExposedName::new("repeat")), Loc::at_zero(ExposedName::new("countGraphemes")), Loc::at_zero(ExposedName::new("startsWithCodePt")), - // Loc::at_zero(ExposedName::new("toUtf8")), - // Loc::at_zero(ExposedName::new("fromUtf8")), - // Loc::at_zero(ExposedName::new("fromUtf8Range")), + Loc::at_zero(ExposedName::new("toUtf8")), + Loc::at_zero(ExposedName::new("fromUtf8")), + Loc::at_zero(ExposedName::new("fromUtf8Range")), Loc::at_zero(ExposedName::new("startsWith")), Loc::at_zero(ExposedName::new("endsWith")), Loc::at_zero(ExposedName::new("trim")), Loc::at_zero(ExposedName::new("trimLeft")), Loc::at_zero(ExposedName::new("trimRight")), - /* + // Loc::at_zero(ExposedName::new("toDec")), Loc::at_zero(ExposedName::new("toF64")), Loc::at_zero(ExposedName::new("toF32")), @@ -2727,7 +2751,6 @@ fn load_module<'a>( Loc::at_zero(ExposedName::new("toI16")), Loc::at_zero(ExposedName::new("toU8")), Loc::at_zero(ExposedName::new("toI8")), - */ ]; const IMPORTS: &[Loc] = &[ @@ -2741,12 +2764,10 @@ fn load_module<'a>( roc_parse::header::ModuleName::new("Bool"), Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("Bool")))]), )), - /* Loc::at_zero(ImportsEntry::Module( roc_parse::header::ModuleName::new("List"), Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("List")))]), )), - */ Loc::at_zero(ImportsEntry::Module( roc_parse::header::ModuleName::new("Num"), Collection::with_items(&[ @@ -2799,7 +2820,7 @@ fn load_module<'a>( EncodesSurrogateHalf, ] - # Utf8Problem : { byteIndex : Nat, problem : Utf8ByteProblem } + Utf8Problem : { byteIndex : Nat, problem : Utf8ByteProblem } isEmpty : Str -> Bool concat : Str, Str -> Str @@ -2810,13 +2831,13 @@ fn load_module<'a>( countGraphemes : Str -> Nat startsWithCodePt : Str, U32 -> Bool - # toUtf8 : Str -> List U8 + toUtf8 : Str -> List U8 # fromUtf8 : List U8 -> Result Str [ BadUtf8 Utf8Problem ]* # fromUtf8Range : List U8 -> Result Str [ BadUtf8 Utf8Problem, OutOfBounds ]* - # fromUtf8 : List U8 -> Result Str [ BadUtf8 Utf8ByteProblem Nat ]* - # fromUtf8Range : List U8 -> Result Str [ BadUtf8 Utf8ByteProblem Nat, OutOfBounds ]* + fromUtf8 : List U8 -> Result Str [ BadUtf8 Utf8ByteProblem Nat ]* + fromUtf8Range : List U8 -> Result Str [ BadUtf8 Utf8ByteProblem Nat, OutOfBounds ]* startsWith : Str, Str -> Bool endsWith : Str, Str -> Bool @@ -2824,6 +2845,21 @@ fn load_module<'a>( trim : Str -> Str trimLeft : Str -> Str trimRight : Str -> Str + + toDec : Str -> Result Dec [ InvalidNumStr ]* + toF64 : Str -> Result F64 [ InvalidNumStr ]* + toF32 : Str -> Result F32 [ InvalidNumStr ]* + toNat : Str -> Result Nat [ InvalidNumStr ]* + toU128 : Str -> Result U128 [ InvalidNumStr ]* + toI128 : Str -> Result I128 [ InvalidNumStr ]* + toU64 : Str -> Result U64 [ InvalidNumStr ]* + toI64 : Str -> Result I64 [ InvalidNumStr ]* + toU32 : Str -> Result U32 [ InvalidNumStr ]* + toI32 : Str -> Result I32 [ InvalidNumStr ]* + toU16 : Str -> Result U16 [ InvalidNumStr ]* + toI16 : Str -> Result I16 [ InvalidNumStr ]* + toU8 : Str -> Result U8 [ InvalidNumStr ]* + toI8 : Str -> Result I8 [ InvalidNumStr ]* "#; let parse_state = roc_parse::state::State::new(src_bytes.as_bytes()); @@ -2869,10 +2905,10 @@ fn load_module<'a>( roc_parse::header::ModuleName::new("List"), Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("List")))]), )), - // Loc::at_zero(ImportsEntry::Module( - // roc_parse::header::ModuleName::new("Num"), - // Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("Nat")))]), - // )), + Loc::at_zero(ImportsEntry::Module( + roc_parse::header::ModuleName::new("Num"), + Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("Nat")))]), + )), ]; const GENERATES_WITH: &[Symbol] = &[]; @@ -2920,7 +2956,7 @@ fn load_module<'a>( )); } "Set" => { - let filename = PathBuf::from("Dict.roc"); + let filename = PathBuf::from("Set.roc"); const EXPOSES: &[Loc] = &[ Loc::at_zero(ExposedName::new("empty")), @@ -2951,6 +2987,10 @@ fn load_module<'a>( roc_parse::header::ModuleName::new("List"), Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("List")))]), )), + Loc::at_zero(ImportsEntry::Module( + roc_parse::header::ModuleName::new("Dict"), + Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("Dict")))]), + )), Loc::at_zero(ImportsEntry::Module( roc_parse::header::ModuleName::new("Num"), Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("Nat")))]), @@ -3109,9 +3149,9 @@ fn load_module<'a>( Loc::at_zero(ExposedName::new("intCast")), Loc::at_zero(ExposedName::new("bytesToU16")), Loc::at_zero(ExposedName::new("bytesToU32")), - Loc::at_zero(ExposedName::new("divCeil")), - Loc::at_zero(ExposedName::new("toStr")), */ + // Loc::at_zero(ExposedName::new("divCeil")), + // Loc::at_zero(ExposedName::new("toStr")), Loc::at_zero(ExposedName::new("isMultipleOf")), // Loc::at_zero(ExposedName::new("minI8")), // Loc::at_zero(ExposedName::new("maxI8")), @@ -3255,6 +3295,8 @@ fn load_module<'a>( sqrt : Float a -> Result (Float a) [ SqrtOfNegative ]* log : Float a, Float a -> Result (Float a) [ LogNeedsPositive ]* div : Float a -> Result (Float a) [ DivByZero ]* + + # divCeil: Int a, Int a -> Result (Int a) [ DivByZero ]* # mod : Float a, Float a -> Result (Float a) [ DivByZero ]* rem : Int a, Int a -> Result (Int a) [ DivByZero ]* @@ -3287,7 +3329,7 @@ fn load_module<'a>( # mulSaturated : Num a, Num a -> Num a mulChecked : Num a, Num a -> Result (Num a) [ Overflow ]* - minI8 : I8 + # minI8 : I8 # maxI8 : I8 # minU8 : U8 # maxU8 : U8 @@ -4285,7 +4327,7 @@ fn run_solve<'a>( // Finish constraining the module by wrapping the existing Constraint // in the ones we just computed. We can do this off the main thread. let constraint = constrain_imports(imported_symbols, constraint, &mut var_store); - dbg!(&constraint); + // dbg!(&constraint); let constrain_end = SystemTime::now(); @@ -4305,6 +4347,8 @@ fn run_solve<'a>( let (solved_subs, solved_env, problems) = roc_solve::module::run_solve(aliases, rigid_variables, constraint, var_store); + dbg!(module_id, &problems); + let mut exposed_vars_by_symbol: MutMap = solved_env.vars_by_symbol.clone(); exposed_vars_by_symbol.retain(|k, _| exposed_symbols.contains(k)); diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index 05b2c42251..c7af8c2323 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -129,7 +129,7 @@ mod solve_expr { let mut buffer = String::from(indoc!( r#" app "test" - imports [ Result.{ Result } ] + imports [] provides [ main ] to "./platform" main = From db6b5bfd386360c4fab6e265af96b7c00774fd8f Mon Sep 17 00:00:00 2001 From: Folkert Date: Mon, 28 Feb 2022 19:40:18 +0100 Subject: [PATCH 008/846] get Num to fully work again --- compiler/builtins/src/std.rs | 2 +- compiler/load/src/file.rs | 105 +++++++++++++++++------------------ compiler/mono/src/ir.rs | 2 - 3 files changed, 53 insertions(+), 56 deletions(-) diff --git a/compiler/builtins/src/std.rs b/compiler/builtins/src/std.rs index 1d6737d9ae..7d373fe06b 100644 --- a/compiler/builtins/src/std.rs +++ b/compiler/builtins/src/std.rs @@ -876,7 +876,7 @@ pub fn types() -> MutMap { ); } - // fromUtf8Range : List U8 -> Result Str [ BadUtf8 Utf8Problem, OutOfBounds ]* + // fromUtf8Range : List U8, { start : Nat, count : Nat } -> Result Str [ BadUtf8 Utf8Problem, OutOfBounds ]* { let bad_utf8 = SolvedType::TagUnion( vec![ diff --git a/compiler/load/src/file.rs b/compiler/load/src/file.rs index 7c005ab5f9..bc70e16ac2 100644 --- a/compiler/load/src/file.rs +++ b/compiler/load/src/file.rs @@ -1858,8 +1858,6 @@ fn update<'a>( start_tasks(arena, &mut state, work, injector, worker_listeners)?; - dbg!(&state.dependencies); - Ok(state) } Parsed(parsed) => { @@ -2834,10 +2832,10 @@ fn load_module<'a>( toUtf8 : Str -> List U8 # fromUtf8 : List U8 -> Result Str [ BadUtf8 Utf8Problem ]* - # fromUtf8Range : List U8 -> Result Str [ BadUtf8 Utf8Problem, OutOfBounds ]* + # fromUtf8Range : List U8 -> Result Str [ BadUtf8 Utf8Problem Nat, OutOfBounds ]* fromUtf8 : List U8 -> Result Str [ BadUtf8 Utf8ByteProblem Nat ]* - fromUtf8Range : List U8 -> Result Str [ BadUtf8 Utf8ByteProblem Nat, OutOfBounds ]* + fromUtf8Range : List U8, { start : Nat, count : Nat } -> Result Str [ BadUtf8 Utf8ByteProblem Nat, OutOfBounds ]* startsWith : Str, Str -> Bool endsWith : Str, Str -> Bool @@ -3120,7 +3118,6 @@ fn load_module<'a>( Loc::at_zero(ExposedName::new("isNegative")), Loc::at_zero(ExposedName::new("rem")), Loc::at_zero(ExposedName::new("div")), - //Loc::at_zero(ExposedName::new("divFloor")), //Loc::at_zero(ExposedName::new("modInt")), //Loc::at_zero(ExposedName::new("modFloat")), Loc::at_zero(ExposedName::new("sqrt")), @@ -3145,33 +3142,31 @@ fn load_module<'a>( Loc::at_zero(ExposedName::new("subSaturated")), Loc::at_zero(ExposedName::new("mulWrap")), Loc::at_zero(ExposedName::new("mulChecked")), - /* Loc::at_zero(ExposedName::new("intCast")), Loc::at_zero(ExposedName::new("bytesToU16")), Loc::at_zero(ExposedName::new("bytesToU32")), - */ - // Loc::at_zero(ExposedName::new("divCeil")), - // Loc::at_zero(ExposedName::new("toStr")), + Loc::at_zero(ExposedName::new("divCeil")), + Loc::at_zero(ExposedName::new("divFloor")), + Loc::at_zero(ExposedName::new("toStr")), Loc::at_zero(ExposedName::new("isMultipleOf")), - // Loc::at_zero(ExposedName::new("minI8")), - // Loc::at_zero(ExposedName::new("maxI8")), - // Loc::at_zero(ExposedName::new("minU8")), - // Loc::at_zero(ExposedName::new("maxU8")), - // Loc::at_zero(ExposedName::new("minI16")), - // Loc::at_zero(ExposedName::new("maxI16")), - // Loc::at_zero(ExposedName::new("minU16")), - // Loc::at_zero(ExposedName::new("maxU16")), - // Loc::at_zero(ExposedName::new("minI32")), - // Loc::at_zero(ExposedName::new("maxI32")), - // Loc::at_zero(ExposedName::new("minU32")), - // Loc::at_zero(ExposedName::new("maxU32")), - // Loc::at_zero(ExposedName::new("minI64")), - // Loc::at_zero(ExposedName::new("maxI64")), - // Loc::at_zero(ExposedName::new("minU64")), - // Loc::at_zero(ExposedName::new("maxU64")), - // Unimplemented - // Loc::at_zero(ExposedName::new("minI128")), - // Loc::at_zero(ExposedName::new("maxI128")), + Loc::at_zero(ExposedName::new("minI8")), + Loc::at_zero(ExposedName::new("maxI8")), + Loc::at_zero(ExposedName::new("minU8")), + Loc::at_zero(ExposedName::new("maxU8")), + Loc::at_zero(ExposedName::new("minI16")), + Loc::at_zero(ExposedName::new("maxI16")), + Loc::at_zero(ExposedName::new("minU16")), + Loc::at_zero(ExposedName::new("maxU16")), + Loc::at_zero(ExposedName::new("minI32")), + Loc::at_zero(ExposedName::new("maxI32")), + Loc::at_zero(ExposedName::new("minU32")), + Loc::at_zero(ExposedName::new("maxU32")), + Loc::at_zero(ExposedName::new("minI64")), + Loc::at_zero(ExposedName::new("maxI64")), + Loc::at_zero(ExposedName::new("minU64")), + Loc::at_zero(ExposedName::new("maxU64")), + Loc::at_zero(ExposedName::new("minI128")), + Loc::at_zero(ExposedName::new("maxI128")), Loc::at_zero(ExposedName::new("toI8")), Loc::at_zero(ExposedName::new("toI8Checked")), Loc::at_zero(ExposedName::new("toI16")), @@ -3260,6 +3255,12 @@ fn load_module<'a>( # ------- Functions + toStr : Num * -> Str + intCast : Int a -> Int b + + bytesToU16 : List U8, Nat -> Result U16 [ OutOfBounds ] + bytesToU32 : List U8, Nat -> Result U32 [ OutOfBounds ] + compare : Num a, Num a -> [ LT, EQ, GT ] isLt : Num a, Num a -> Bool @@ -3275,7 +3276,7 @@ fn load_module<'a>( isPositive : Num a -> Bool isNegative : Num a -> Bool - toFloat : Num * -> Float * + toFloat : Num a -> Float b abs : Num a -> Num a neg : Num a -> Num a @@ -3293,10 +3294,11 @@ fn load_module<'a>( atan : Float a -> Float a sqrt : Float a -> Result (Float a) [ SqrtOfNegative ]* - log : Float a, Float a -> Result (Float a) [ LogNeedsPositive ]* - div : Float a -> Result (Float a) [ DivByZero ]* + log : Float a -> Result (Float a) [ LogNeedsPositive ]* + div : Float a, Float a -> Result (Float a) [ DivByZero ]* - # divCeil: Int a, Int a -> Result (Int a) [ DivByZero ]* + divCeil: Int a, Int a -> Result (Int a) [ DivByZero ]* + divFloor: Int a, Int a -> Result (Int a) [ DivByZero ]* # mod : Float a, Float a -> Result (Float a) [ DivByZero ]* rem : Int a, Int a -> Result (Int a) [ DivByZero ]* @@ -3329,25 +3331,25 @@ fn load_module<'a>( # mulSaturated : Num a, Num a -> Num a mulChecked : Num a, Num a -> Result (Num a) [ Overflow ]* - # minI8 : I8 - # maxI8 : I8 - # minU8 : U8 - # maxU8 : U8 - # minI16 : I16 - # maxI16 : I16 - # minU16 : U16 - # maxU16 : U16 - # minI32 : I32 - # maxI32 : I32 - # minU32 : U32 - # maxU32 : U32 - # minI64 : I64 - # maxI64 : I64 - # minU64 : U64 - # maxU64 : U64 + minI8 : I8 + maxI8 : I8 + minU8 : U8 + maxU8 : U8 + minI16 : I16 + maxI16 : I16 + minU16 : U16 + maxU16 : U16 + minI32 : I32 + maxI32 : I32 + minU32 : U32 + maxU32 : U32 + minI64 : I64 + maxI64 : I64 + minU64 : U64 + maxU64 : U64 - # minI128 : I128 - # maxI128 : I128 + minI128 : I128 + maxI128 : I128 # minU128 : U128 # maxU128 : U128 @@ -4327,7 +4329,6 @@ fn run_solve<'a>( // Finish constraining the module by wrapping the existing Constraint // in the ones we just computed. We can do this off the main thread. let constraint = constrain_imports(imported_symbols, constraint, &mut var_store); - // dbg!(&constraint); let constrain_end = SystemTime::now(); @@ -4347,8 +4348,6 @@ fn run_solve<'a>( let (solved_subs, solved_env, problems) = roc_solve::module::run_solve(aliases, rigid_variables, constraint, var_store); - dbg!(module_id, &problems); - let mut exposed_vars_by_symbol: MutMap = solved_env.vars_by_symbol.clone(); exposed_vars_by_symbol.retain(|k, _| exposed_symbols.contains(k)); diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 528948eb7c..b712ca8dc8 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -7420,8 +7420,6 @@ fn call_by_name_module_thunk<'a>( assigned: Symbol, hole: &'a Stmt<'a>, ) -> Stmt<'a> { - debug_assert!(!env.is_imported_symbol(proc_name)); - let top_level_layout = ProcLayout::new(env.arena, &[], *ret_layout); let inner_layout = *ret_layout; From ba709095199784fdbed0379320e55444a0150fb3 Mon Sep 17 00:00:00 2001 From: Folkert Date: Mon, 28 Feb 2022 22:23:11 +0100 Subject: [PATCH 009/846] fix more tests --- compiler/can/src/builtins.rs | 2 +- compiler/load/src/file.rs | 8 ++++---- compiler/mono/src/ir.rs | 23 ++++++++++++++++------- repl_eval/src/eval.rs | 3 +++ 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/compiler/can/src/builtins.rs b/compiler/can/src/builtins.rs index 2b9676b5a7..290f822eeb 100644 --- a/compiler/can/src/builtins.rs +++ b/compiler/can/src/builtins.rs @@ -1961,7 +1961,7 @@ fn str_from_utf8(symbol: Symbol, var_store: &mut VarStore) -> Def { ret_var, ) } -/// Str.fromUtf8Range : List U8, { start : Nat, count : Nat } -> Result Str [ BadUtf8 { byteIndex : Nat, problem : Utf8Problem } } ]* +/// Str.romUtf8Range : List U8, { start : Nat, count : Nat } -> Result Str [ BadUtf8 { byteIndex : Nat, problem : Utf8Problem } } ]* fn str_from_utf8_range(symbol: Symbol, var_store: &mut VarStore) -> Def { let bytes_var = var_store.fresh(); let bool_var = var_store.fresh(); diff --git a/compiler/load/src/file.rs b/compiler/load/src/file.rs index bc70e16ac2..442c9375e6 100644 --- a/compiler/load/src/file.rs +++ b/compiler/load/src/file.rs @@ -65,7 +65,7 @@ const PKG_CONFIG_FILE_NAME: &str = "Package-Config"; /// The . in between module names like Foo.Bar.Baz const MODULE_SEPARATOR: char = '.'; -const SHOW_MESSAGE_LOG: bool = true; +const SHOW_MESSAGE_LOG: bool = false; const EXPANDED_STACK_SIZE: usize = 8 * 1024 * 1024; @@ -1100,7 +1100,7 @@ fn load<'a>( ) -> Result, LoadingProblem<'a>> { // When compiling to wasm, we cannot spawn extra threads // so we have a single-threaded implementation - if true || cfg!(target_family = "wasm") { + if cfg!(target_family = "wasm") { load_single_threaded( arena, load_start, @@ -2665,8 +2665,8 @@ fn load_module<'a>( keepIf : List a, (a -> Bool) -> List a dropIf : List a, (a -> Bool) -> List a - keepOks : List (Result ok err) -> List ok - keepErrs : List (Result ok err) -> List err + keepOks : List before, (before -> Result after *) -> List after + keepErrs: List before, (before -> Result * after) -> List after map : List a, (a -> b) -> List b map2 : List a, List b, (a, b -> c) -> List c map3 : List a, List b, List c, (a, b, c -> d) -> List d diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index b712ca8dc8..4761f17530 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -1108,7 +1108,6 @@ impl<'a, 'i> Env<'a, 'i> { } pub fn is_imported_symbol(&self, symbol: Symbol) -> bool { - // symbol.module_id() != self.home && !symbol.is_builtin() symbol.module_id() != self.home } } @@ -7259,13 +7258,23 @@ fn call_by_name_help<'a>( assigned, hole, ) - } else { - debug_assert!( - !field_symbols.is_empty(), - "{} should be in the list of imported_module_thunks", - proc_name - ); + } else if field_symbols.is_empty() { + // this is a case like `Str.concat`, an imported standard function, applied to zero arguments + // imported symbols cannot capture anything + let captured= &[]; + + construct_closure_data( + env, + procs, + layout_cache, + lambda_set, + proc_name, + captured, + assigned, + hole, + ) + } else { debug_assert_eq!( argument_layouts.len(), field_symbols.len(), diff --git a/repl_eval/src/eval.rs b/repl_eval/src/eval.rs index e706ddde0a..ce4f1dda4c 100644 --- a/repl_eval/src/eval.rs +++ b/repl_eval/src/eval.rs @@ -63,6 +63,7 @@ pub fn jit_to_ast<'a, A: ReplApp<'a>>( arguments: [], result, } => { + dbg!(content, &result); // this is a thunk jit_to_ast_help(&env, app, main_fn_name, &result, content) } @@ -1176,6 +1177,8 @@ fn num_to_ast<'a>(env: &Env<'a, '_>, num_expr: Expr<'a>, content: &Content) -> E let arena = env.arena; + dbg!(&num_expr, content); + match content { Structure(flat_type) => { match flat_type { From 38fd3108f2f769e89ec86965adfdda8476bd6c87 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sun, 27 Feb 2022 21:09:38 -0500 Subject: [PATCH 010/846] Use Program in examples/gui --- examples/gui/Hello.roc | 6 ++- examples/gui/platform/Package-Config.roc | 13 +++-- examples/gui/platform/src/lib.rs | 64 ++++++++++++++++++++++-- 3 files changed, 74 insertions(+), 9 deletions(-) diff --git a/examples/gui/Hello.roc b/examples/gui/Hello.roc index c15f5bd21a..3c40a7b48f 100644 --- a/examples/gui/Hello.roc +++ b/examples/gui/Hello.roc @@ -1,9 +1,11 @@ app "hello-gui" packages { pf: "platform" } imports []# [ pf.Action.{ Action }, pf.Elem.{ button, text, row, col } ] - provides [ render ] to pf + provides [ program ] to pf -render = +program = { render } + +render = \state -> div0 = \numerator, denominator -> (numerator / denominator) |> Result.withDefault 0 rgba = \r, g, b, a -> { r: div0 r 255, g: div0 g 255, b: div0 b 255, a } diff --git a/examples/gui/platform/Package-Config.roc b/examples/gui/platform/Package-Config.roc index 855c45e23b..659adbda94 100644 --- a/examples/gui/platform/Package-Config.roc +++ b/examples/gui/platform/Package-Config.roc @@ -1,9 +1,9 @@ platform "examples/hello-world" - requires {} { render : Elem } + requires {} { program : Program State } exposes [] packages {} imports [] - provides [ renderForHost ] + provides [ programForHost ] Rgba : { r : F32, g : F32, b : F32, a : F32 } @@ -11,5 +11,10 @@ ButtonStyles : { bgColor : Rgba, borderColor : Rgba, borderWidth : F32, textColo Elem : [ Button Elem ButtonStyles, Col (List Elem), Row (List Elem), Text Str ] -renderForHost : Elem -renderForHost = render +State : { width : U32, height : U32 } # TODO change from U32 to F32 once Num.toStr supports floats + +Program state : { render : state -> Elem } + +# TODO allow changing the title - maybe via Action.setTitle +programForHost : { render : (State -> Elem) as Render } +programForHost = program diff --git a/examples/gui/platform/src/lib.rs b/examples/gui/platform/src/lib.rs index 17fa0b4d4a..65e55452b0 100644 --- a/examples/gui/platform/src/lib.rs +++ b/examples/gui/platform/src/lib.rs @@ -4,18 +4,76 @@ mod rects_and_texts; mod roc; use crate::roc::RocElem; +use core::alloc::Layout; +use core::mem::MaybeUninit; +use roc_std::RocStr; extern "C" { - #[link_name = "roc__renderForHost_1_exposed"] - fn roc_render() -> RocElem; + #[link_name = "roc__programForHost_1_exposed_generic"] + fn roc_program(args: State, output: *mut u8) -> (); + + #[link_name = "roc__programForHost_size"] + fn roc_program_size() -> i64; + + #[link_name = "roc__programForHost_1_Render_caller"] + fn call_Render(flags: *const u8, closure_data: *const u8, output: *mut u8) -> RocElem; + + #[allow(dead_code)] + #[link_name = "roc__programForHost_1_Render_size"] + fn size_Render() -> i64; + + #[link_name = "roc__programForHost_1_Render_result_size"] + fn size_Render_result() -> i64; +} + +#[repr(C)] +struct State { + height: u32, + width: u32, } #[no_mangle] pub extern "C" fn rust_main() -> i32 { - let root_elem = unsafe { roc_render() }; + let size = unsafe { roc_program_size() } as usize; + let layout = Layout::array::(size).unwrap(); + let state = State { + height: 42, + width: 123, + }; + + let root_elem = unsafe { + // TODO allocate on the stack if it's under a certain size + let buffer = std::alloc::alloc(layout); + + roc_program(state, buffer); + + // Call the program's render function + let result = call_the_closure(buffer); + + std::alloc::dealloc(buffer, layout); + + result + }; gui::render("test title".into(), root_elem); // Exit code 0 } + +unsafe fn call_the_closure(closure_data_ptr: *const u8) -> RocElem { + let size = size_Render_result() as usize; + let layout = Layout::array::(size).unwrap(); + let buffer = std::alloc::alloc(layout) as *mut u8; + + let answer = call_Render( + // This flags pointer will never get dereferenced + MaybeUninit::uninit().as_ptr(), + closure_data_ptr as *const u8, + buffer as *mut u8, + ); + + std::alloc::dealloc(buffer, layout); + + answer +} From 3b6c66ccb268cb177dca6b38a4c8253f63651f6d Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sat, 5 Mar 2022 11:34:22 -0500 Subject: [PATCH 011/846] Make a separate .gitignore for gui platform This is just so I can open it in my editor and have the editor pick up on the .gitignore --- examples/gui/platform/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 examples/gui/platform/.gitignore diff --git a/examples/gui/platform/.gitignore b/examples/gui/platform/.gitignore new file mode 100644 index 0000000000..eb5a316cbd --- /dev/null +++ b/examples/gui/platform/.gitignore @@ -0,0 +1 @@ +target From 9bf513b55cbc0264865f16347eaf7597a585632d Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sun, 27 Feb 2022 21:09:51 -0500 Subject: [PATCH 012/846] Render height and width --- examples/gui/Hello.roc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/gui/Hello.roc b/examples/gui/Hello.roc index 3c40a7b48f..46656498de 100644 --- a/examples/gui/Hello.roc +++ b/examples/gui/Hello.roc @@ -12,6 +12,9 @@ render = \state -> styles = { bgColor: rgba 100 50 50 1, borderColor: rgba 10 20 30 1, borderWidth: 10, textColor: rgba 220 220 250 1 } + height = Num.toStr state.height + width = Num.toStr state.width + Col [ Row @@ -22,4 +25,6 @@ render = \state -> ], Button (Text "Mid Left ") { styles & bgColor: rgba 150 100 100 1 }, Button (Text "Bottom Left") { styles & bgColor: rgba 150 50 50 1 }, + Button (Text "height: \(height)") { styles & bgColor: rgba 50 150 50 1 }, + Button (Text "width: \(width)") { styles & bgColor: rgba 50 100 50 1 }, ] From 8302b732b817011e6b1931b5981340754b27a639 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 28 Feb 2022 17:35:17 -0500 Subject: [PATCH 013/846] First pass at Focus --- examples/gui/platform/Cargo.toml | 1 - examples/gui/platform/build.rs | 4 - examples/gui/platform/src/focus.rs | 148 +++++++++++++++++++ examples/gui/platform/src/graphics/colors.rs | 2 +- examples/gui/platform/src/gui.rs | 22 ++- examples/gui/platform/src/lib.rs | 1 + examples/gui/platform/src/roc.rs | 100 ++++++++++++- 7 files changed, 265 insertions(+), 13 deletions(-) delete mode 100644 examples/gui/platform/build.rs create mode 100644 examples/gui/platform/src/focus.rs diff --git a/examples/gui/platform/Cargo.toml b/examples/gui/platform/Cargo.toml index b82712e562..dee9bee179 100644 --- a/examples/gui/platform/Cargo.toml +++ b/examples/gui/platform/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" authors = ["The Roc Contributors"] license = "UPL-1.0" edition = "2018" -links = "app" # Needed to be able to run on non-Windows systems for some reason. Without this, cargo panics with: # diff --git a/examples/gui/platform/build.rs b/examples/gui/platform/build.rs deleted file mode 100644 index 73159e387c..0000000000 --- a/examples/gui/platform/build.rs +++ /dev/null @@ -1,4 +0,0 @@ -fn main() { - println!("cargo:rustc-link-lib=dylib=app"); - println!("cargo:rustc-link-search=."); -} diff --git a/examples/gui/platform/src/focus.rs b/examples/gui/platform/src/focus.rs new file mode 100644 index 0000000000..4d844fdd6a --- /dev/null +++ b/examples/gui/platform/src/focus.rs @@ -0,0 +1,148 @@ +use crate::roc::{RocElem, RocElemTag}; + +#[derive(Debug, PartialEq, Eq)] +pub struct Focus { + focused: *const RocElem, + focused_ancestors: Vec<(*const RocElem, usize)>, +} + +impl Default for Focus { + fn default() -> Self { + Self { + focused: std::ptr::null(), + focused_ancestors: Vec::new(), + } + } +} + +impl Focus { + pub fn focused_elem(&self) -> *const RocElem { + self.focused + } + + /// e.g. the user pressed Tab. + pub fn advance(&mut self, root: &RocElem) { + if self.focused.is_null() { + // Nothing was focused in the first place, so try to focus the root. + if root.is_focusable() { + self.focused = root as *const RocElem; + self.focused_ancestors = Vec::new(); + } else if let Some((new_ptr, new_ancestors)) = + Self::next_focusable_sibling(root, None, None) + { + // If the root itself is not focusable, use its next focusable sibling. + self.focused = new_ptr; + self.focused_ancestors = new_ancestors; + } + + // Regardless of whether we found a focusable Elem, we're done. + return; + } + + let focused = unsafe { &*self.focused }; + + while let Some((ancestor_ptr, index)) = self.focused_ancestors.pop() { + let ancestor = unsafe { &*ancestor_ptr }; + + // TODO FIXME - right now this will re-traverse a lot of ground! To prevent this, + // we should remember past indices searched, and tell the ancestors "hey stop searching when" + // you reach these indices, because they were already covered previously. + // One potentially easy way to do this: pass a min_index and max_index, and only look between those! + // + // Related idea: instead of doing .pop() here, iterate normally so we can `break;` after storing + // `new_ancestors = Some(next_ancestors);` - this way, we still have access to the full ancestry, and + // can maybe even pass it in to make it clear what work has already been done! + if let Some((new_ptr, new_ancestors)) = + Self::next_focusable_sibling(focused, Some(ancestor), Some(index)) + { + debug_assert!( + !new_ptr.is_null(), + "next_focusable returned a null Elem pointer!" + ); + + // We found the next element to focus, so record that. + self.focused = new_ptr; + + // We got a path to the new focusable's ancestor(s), so add them to the path. + // (This may restore some of the ancestors we've been .pop()-ing as we iterated.) + self.focused_ancestors.extend(new_ancestors); + + return; + } + + // Need to write a bunch of tests for this, especially tests of focus wrapping around - e.g. + // what happens if it wraps around to a sibling? What happens if it wraps around to something + // higher up the tree? Lower down the tree? What if nothing is focusable? + // A separate question: what if we should have a separate text-to-speech concept separate from focus? + } + } + + /// Return the next focusable sibling element after this one. + /// If this element has no siblings, or no *next* sibling after the given index + /// (e.g. the given index refers to the last element in a Row element), return None. + fn next_focusable_sibling( + elem: &RocElem, + ancestor: Option<&RocElem>, + opt_index: Option, + ) -> Option<(*const RocElem, Vec<(*const RocElem, usize)>)> { + use RocElemTag::*; + + match elem.tag() { + Button | Text => None, + Row | Col => { + let children = unsafe { &elem.entry().row_or_col.children.as_slice() }; + let iter = match opt_index { + Some(focus_index) => children[0..focus_index].iter(), + None => children.iter(), + }; + + for child in iter { + if let Some(focused) = Self::next_focusable_sibling(child, ancestor, None) { + return Some(focused); + } + } + + None + } + } + } +} + +#[test] +fn next_focus_button_root() { + use crate::roc::{ButtonStyles, RocElem}; + + let child = RocElem::text(""); + let root = RocElem::button(ButtonStyles::default(), child); + let mut focus = Focus::default(); + + // At first, nothing should be focused. + assert_eq!(focus.focused_elem(), std::ptr::null()); + + focus.advance(&root); + + // Buttons should be focusable, so advancing focus should give the button focus. + assert_eq!(focus.focused_elem(), &root as *const RocElem); + + // Since the button is at the root, advancing again should maintain focus on it. + focus.advance(&root); + assert_eq!(focus.focused_elem(), &root as *const RocElem); +} + +#[test] +fn next_focus_text_root() { + let root = RocElem::text(""); + let mut focus = Focus::default(); + + // At first, nothing should be focused. + assert_eq!(focus.focused_elem(), std::ptr::null()); + + focus.advance(&root); + + // Text should not be focusable, so advancing focus should have no effect here. + assert_eq!(focus.focused_elem(), std::ptr::null()); + + // Just to double-check, advancing a second time should not change this. + focus.advance(&root); + assert_eq!(focus.focused_elem(), std::ptr::null()); +} diff --git a/examples/gui/platform/src/graphics/colors.rs b/examples/gui/platform/src/graphics/colors.rs index e0932a1d69..3ec448413f 100644 --- a/examples/gui/platform/src/graphics/colors.rs +++ b/examples/gui/platform/src/graphics/colors.rs @@ -3,7 +3,7 @@ use palette::{FromColor, Hsv, Srgb}; /// This order is optimized for what Roc will send #[repr(C)] -#[derive(Copy, Clone, Debug, PartialEq)] +#[derive(Copy, Clone, Debug, PartialEq, Default)] pub struct Rgba { a: f32, b: f32, diff --git a/examples/gui/platform/src/gui.rs b/examples/gui/platform/src/gui.rs index 0e6bc8b24b..d811eeb552 100644 --- a/examples/gui/platform/src/gui.rs +++ b/examples/gui/platform/src/gui.rs @@ -1,4 +1,5 @@ use crate::{ + focus::Focus, graphics::{ colors::Rgba, lowlevel::buffer::create_rect_buffers, @@ -231,9 +232,15 @@ fn run_event_loop(title: &str, root: RocElem) -> Result<(), Box> { // wgpu::LoadOp::Load, // ); - // TODO use with_capacity based on some heuristic + let focus_ancestry: Vec<(*const RocElem, usize)> = Vec::new(); // TODO test that root node can get focus! + let focused_elem: *const RocElem = match focus_ancestry.first() { + Some((ptr_ref, _)) => *ptr_ref, + None => std::ptr::null(), + }; + let (_bounds, drawable) = to_drawable( &root, + focused_elem, Bounds { width: size.width as f32, height: size.height as f32, @@ -496,18 +503,23 @@ fn draw( } } +/// focused_elem is the currently-focused element (or NULL if nothing has the focus) fn to_drawable( elem: &RocElem, + focused_elem: *const RocElem, bounds: Bounds, glyph_brush: &mut GlyphBrush<()>, ) -> (Bounds, Drawable) { use RocElemTag::*; + let is_focused = focused_elem == elem as *const RocElem; + match elem.tag() { Button => { let button = unsafe { &elem.entry().button }; let styles = button.styles; - let (child_bounds, child_drawable) = to_drawable(&*button.child, bounds, glyph_brush); + let (child_bounds, child_drawable) = + to_drawable(&*button.child, focused_elem, bounds, glyph_brush); let button_drawable = Drawable { bounds: child_bounds, @@ -574,7 +586,8 @@ fn to_drawable( let mut offset_entries = Vec::with_capacity(row.children.len()); for child in row.children.as_slice().iter() { - let (child_bounds, child_drawable) = to_drawable(&child, bounds, glyph_brush); + let (child_bounds, child_drawable) = + to_drawable(&child, focused_elem, bounds, glyph_brush); offset_entries.push((offset, child_drawable)); @@ -603,7 +616,8 @@ fn to_drawable( let mut offset_entries = Vec::with_capacity(col.children.len()); for child in col.children.as_slice().iter() { - let (child_bounds, child_drawable) = to_drawable(&child, bounds, glyph_brush); + let (child_bounds, child_drawable) = + to_drawable(&child, focused_elem, bounds, glyph_brush); offset_entries.push((offset, child_drawable)); diff --git a/examples/gui/platform/src/lib.rs b/examples/gui/platform/src/lib.rs index 65e55452b0..9f78d35fcf 100644 --- a/examples/gui/platform/src/lib.rs +++ b/examples/gui/platform/src/lib.rs @@ -1,3 +1,4 @@ +mod focus; mod graphics; mod gui; mod rects_and_texts; diff --git a/examples/gui/platform/src/roc.rs b/examples/gui/platform/src/roc.rs index 034181deed..005ca4e6ba 100644 --- a/examples/gui/platform/src/roc.rs +++ b/examples/gui/platform/src/roc.rs @@ -62,16 +62,106 @@ impl RocElem { } pub fn entry(&self) -> &RocElemEntry { + unsafe { &*self.entry_ptr() } + } + + pub fn entry_ptr(&self) -> *const RocElemEntry { // On a 64-bit system, the last 3 bits of the pointer store the tag let cleared = self.entry as usize & !0b111; - unsafe { &*(cleared as *const RocElemEntry) } + cleared as *const RocElemEntry + } + + fn diff(self, other: RocElem, patches: &mut Vec<(usize, Patch)>, index: usize) { + use RocElemTag::*; + + let tag = self.tag(); + + if tag != other.tag() { + // They were totally different elem types! + + // TODO should we handle Row -> Col or Col -> Row differently? + // Elm doesn't: https://github.com/elm/virtual-dom/blob/5a5bcf48720bc7d53461b3cd42a9f19f119c5503/src/Elm/Kernel/VirtualDom.js#L714 + return; + } + + match tag { + Button => unsafe { + let button_self = &*self.entry().button; + let button_other = &*other.entry().button; + + // TODO compute a diff and patch for the button + }, + Text => unsafe { + let str_self = &*self.entry().text; + let str_other = &*other.entry().text; + + if str_self != str_other { + todo!("fix this"); + // let roc_str = other.entry().text; + // let patch = Patch::Text(ManuallyDrop::into_inner(roc_str)); + + // patches.push((index, patch)); + } + }, + Row => unsafe { + let children_self = &self.entry().row_or_col.children; + let children_other = &other.entry().row_or_col.children; + + // TODO diff children + }, + Col => unsafe { + let children_self = &self.entry().row_or_col.children; + let children_other = &other.entry().row_or_col.children; + + // TODO diff children + }, + } + } + + pub fn is_focusable(&self) -> bool { + use RocElemTag::*; + + match self.tag() { + Button => true, + Text | Row | Col => false, + } + } + + pub fn button(styles: ButtonStyles, child: RocElem) -> RocElem { + let button = RocButton { + child: ManuallyDrop::new(child), + styles, + }; + let entry = RocElemEntry { + button: ManuallyDrop::new(button), + }; + + Self::elem_from_tag(entry, RocElemTag::Button) + } + + pub fn text>(into_roc_str: T) -> RocElem { + let entry = RocElemEntry { + text: ManuallyDrop::new(into_roc_str.into()), + }; + + Self::elem_from_tag(entry, RocElemTag::Text) + } + + fn elem_from_tag(entry: RocElemEntry, tag: RocElemTag) -> Self { + let entry_box = Box::new(entry); + let entry_ptr = entry_box.as_ref() as *const RocElemEntry; + let tagged_ptr = entry_ptr as usize | tag as usize; + + Self { + entry: tagged_ptr as *const RocElemEntry, + } } } #[repr(u8)] #[allow(unused)] // This is actually used, just via a mem::transmute from u8 -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum RocElemTag { Button = 0, Col, @@ -134,7 +224,7 @@ unsafe impl ReferenceCount for RocElem { } #[repr(C)] -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, Default)] pub struct ButtonStyles { pub bg_color: Rgba, pub border_color: Rgba, @@ -148,3 +238,7 @@ pub union RocElemEntry { pub text: ManuallyDrop, pub row_or_col: ManuallyDrop, } + +enum Patch { + Text(RocStr), +} From cb635ef3013fe566d1fab7ba31c3e44b209cb9ed Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sat, 5 Mar 2022 14:21:20 -0500 Subject: [PATCH 014/846] Delete obsolete rects_and_texts --- examples/gui/platform/src/lib.rs | 1 - examples/gui/platform/src/rects_and_texts.rs | 70 -------------------- 2 files changed, 71 deletions(-) delete mode 100644 examples/gui/platform/src/rects_and_texts.rs diff --git a/examples/gui/platform/src/lib.rs b/examples/gui/platform/src/lib.rs index 9f78d35fcf..f609cd518a 100644 --- a/examples/gui/platform/src/lib.rs +++ b/examples/gui/platform/src/lib.rs @@ -1,7 +1,6 @@ mod focus; mod graphics; mod gui; -mod rects_and_texts; mod roc; use crate::roc::RocElem; diff --git a/examples/gui/platform/src/rects_and_texts.rs b/examples/gui/platform/src/rects_and_texts.rs deleted file mode 100644 index 3eed8654ac..0000000000 --- a/examples/gui/platform/src/rects_and_texts.rs +++ /dev/null @@ -1,70 +0,0 @@ -use crate::graphics::primitives::rect::RectElt; -use crate::graphics::primitives::text::{owned_section_from_text, Text}; - -#[derive(Debug)] -pub struct RectsAndTexts { - pub text_sections_behind: Vec, // displayed in front of rect_behind, behind everything else - pub text_sections_front: Vec, // displayed in front of everything - pub rects_behind: Vec, // displayed at lowest depth - pub rects_front: Vec, // displayed in front of text_sections_behind, behind text_sections_front -} - -impl RectsAndTexts { - pub fn new() -> Self { - Self { - text_sections_behind: Vec::new(), - text_sections_front: Vec::new(), - rects_behind: Vec::new(), - rects_front: Vec::new(), - } - } - - pub fn init( - rects_behind: Vec, - texts_behind: Vec, - rects_front: Vec, - texts_front: Vec, - ) -> Self { - Self { - text_sections_behind: texts_behind - .iter() - .map(|txt| owned_section_from_text(txt)) - .collect(), - text_sections_front: texts_front - .iter() - .map(|txt| owned_section_from_text(txt)) - .collect(), - rects_behind, - rects_front, - } - } - - pub fn add_text_behind(&mut self, new_text_section: glyph_brush::OwnedSection) { - self.text_sections_behind.push(new_text_section); - } - - pub fn add_text_front(&mut self, new_text_section: glyph_brush::OwnedSection) { - self.text_sections_front.push(new_text_section); - } - - pub fn add_rect_behind(&mut self, new_rect: RectElt) { - self.rects_behind.push(new_rect); - } - - pub fn add_rects_behind(&mut self, new_rects: Vec) { - self.rects_behind.extend(new_rects); - } - - pub fn add_rect_front(&mut self, new_rect: RectElt) { - self.rects_front.push(new_rect); - } - - pub fn extend(&mut self, rects_and_texts: RectsAndTexts) { - self.text_sections_behind - .extend(rects_and_texts.text_sections_behind); - self.text_sections_front - .extend(rects_and_texts.text_sections_front); - self.rects_behind.extend(rects_and_texts.rects_behind); - self.rects_front.extend(rects_and_texts.rects_front); - } -} From de498a37cedce4ad9f1b975cfb6c6fea0db59d50 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 5 Mar 2022 21:02:35 +0100 Subject: [PATCH 015/846] manually define min/max integer functions --- compiler/can/src/builtins.rs | 18 --------------- compiler/load/src/file.rs | 44 ++++++++++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 20 deletions(-) diff --git a/compiler/can/src/builtins.rs b/compiler/can/src/builtins.rs index aa537b9931..d1c8008a84 100644 --- a/compiler/can/src/builtins.rs +++ b/compiler/can/src/builtins.rs @@ -227,24 +227,6 @@ pub fn builtin_defs_map(symbol: Symbol, var_store: &mut VarStore) -> Option NUM_SHIFT_RIGHT => num_shift_right_by, NUM_SHIFT_RIGHT_ZERO_FILL => num_shift_right_zf_by, NUM_INT_CAST=> num_int_cast, - NUM_MIN_I8=> num_min_i8, - NUM_MAX_I8=> num_max_i8, - NUM_MIN_U8=> num_min_u8, - NUM_MAX_U8=> num_max_u8, - NUM_MIN_I16=> num_min_i16, - NUM_MAX_I16=> num_max_i16, - NUM_MIN_U16=> num_min_u16, - NUM_MAX_U16=> num_max_u16, - NUM_MIN_I32=> num_min_i32, - NUM_MAX_I32=> num_max_i32, - NUM_MIN_U32=> num_min_u32, - NUM_MAX_U32=> num_max_u32, - NUM_MIN_I64=> num_min_i64, - NUM_MAX_I64=> num_max_i64, - NUM_MIN_U64=> num_min_u64, - NUM_MAX_U64=> num_max_u64, - NUM_MIN_I128=> num_min_i128, - NUM_MAX_I128=> num_max_i128, NUM_TO_I8 => num_to_i8, NUM_TO_I8_CHECKED => num_to_i8_checked, NUM_TO_I16 => num_to_i16, diff --git a/compiler/load/src/file.rs b/compiler/load/src/file.rs index 816aaf3fa0..83a2d6e4a5 100644 --- a/compiler/load/src/file.rs +++ b/compiler/load/src/file.rs @@ -3173,6 +3173,8 @@ fn load_module<'a>( Loc::at_zero(ExposedName::new("maxU64")), Loc::at_zero(ExposedName::new("minI128")), Loc::at_zero(ExposedName::new("maxI128")), + Loc::at_zero(ExposedName::new("minU128")), + Loc::at_zero(ExposedName::new("maxU128")), Loc::at_zero(ExposedName::new("toI8")), Loc::at_zero(ExposedName::new("toI8Checked")), Loc::at_zero(ExposedName::new("toI16")), @@ -3338,26 +3340,64 @@ fn load_module<'a>( mulChecked : Num a, Num a -> Result (Num a) [ Overflow ]* minI8 : I8 + minI8 = -128i8 + maxI8 : I8 + maxI8 = 127i8 + minU8 : U8 + minU8 = 0u8 + maxU8 : U8 + maxU8 = 255u8 + minI16 : I16 + minI16 = -32768i16 + maxI16 : I16 + maxI16 = 32767i16 + minU16 : U16 + minU16 = 0u16 + maxU16 : U16 + maxU16 = 65535u16 + minI32 : I32 + minI32 = -2147483648 + maxI32 : I32 + maxI32 = 2147483647 + minU32 : U32 + minU32 = 0 + maxU32 : U32 + maxU32 = 4294967295 + minI64 : I64 + minI64 = -9223372036854775808 + maxI64 : I64 + maxI64 = 9223372036854775807 + minU64 : U64 + minU64 = 0 + maxU64 : U64 + maxU64 = 18446744073709551615 minI128 : I128 + minI128 = -170141183460469231731687303715884105728 + maxI128 : I128 - # minU128 : U128 - # maxU128 : U128 + maxI128 = 170141183460469231731687303715884105727 + + minU128 : U128 + minU128 = 0 + + maxU128 : U128 + maxU128 = 0340282366920938463463374607431768211455 toI8 : Int * -> I8 toI16 : Int * -> I16 From 602355903daf90cf27bfddff2a21eb3e6d0e683a Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 5 Mar 2022 21:28:59 +0100 Subject: [PATCH 016/846] constraint.rs tweaks --- compiler/can/src/constraint.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/compiler/can/src/constraint.rs b/compiler/can/src/constraint.rs index 8ffd1ec896..ae24ba78c9 100644 --- a/compiler/can/src/constraint.rs +++ b/compiler/can/src/constraint.rs @@ -172,6 +172,7 @@ impl Constraints { } } + #[inline(always)] pub fn equal_types( &mut self, typ: Type, @@ -262,9 +263,15 @@ impl Constraints { fn def_types_slice(&mut self, it: I) -> Slice<(Symbol, Loc>)> where I: IntoIterator)>, + I::IntoIter: ExactSizeIterator, { + let it = it.into_iter(); + let start = self.def_types.len(); + // because we have an ExactSizeIterator, we can reserve space here + self.def_types.reserve(it.len()); + for (symbol, loc_type) in it { let Loc { region, value } = loc_type; let type_index = Index::push_new(&mut self.types, value); @@ -277,6 +284,7 @@ impl Constraints { Slice::new(start as _, length as _) } + #[inline(always)] pub fn exists(&mut self, flex_vars: I, defs_constraint: Constraint) -> Constraint where I: IntoIterator, @@ -299,6 +307,7 @@ impl Constraints { Constraint::Let(let_index) } + #[inline(always)] pub fn exists_many(&mut self, flex_vars: I, defs_constraint: C) -> Constraint where I: IntoIterator, @@ -324,6 +333,7 @@ impl Constraints { Constraint::Let(let_index) } + #[inline(always)] pub fn let_constraint( &mut self, rigid_vars: I1, @@ -336,6 +346,7 @@ impl Constraints { I1: IntoIterator, I2: IntoIterator, I3: IntoIterator)>, + I3::IntoIter: ExactSizeIterator, { let defs_and_ret_constraint = Index::new(self.constraints.len() as _); @@ -355,6 +366,7 @@ impl Constraints { Constraint::Let(let_index) } + #[inline(always)] pub fn and_constraint(&mut self, constraints: I) -> Constraint where I: IntoIterator, From ce393974bf7b89095f16116e8c61d1241fb880fc Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 5 Mar 2022 21:29:17 +0100 Subject: [PATCH 017/846] prevent frequent expectation cloning --- compiler/constrain/src/expr.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/compiler/constrain/src/expr.rs b/compiler/constrain/src/expr.rs index 0a97de4327..e534e5a45f 100644 --- a/compiler/constrain/src/expr.rs +++ b/compiler/constrain/src/expr.rs @@ -1363,7 +1363,7 @@ fn constrain_def( def_pattern_state.constraints.push(constraints.equal_types( expr_type, - annotation_expected.clone(), + annotation_expected, Category::Storage(std::file!(), std::line!()), Region::span_across(&annotation.region, &def.loc_expr.region), )); @@ -1528,14 +1528,21 @@ fn constrain_def( } _ => { - let expected = annotation_expected; + let annotation_expected = FromAnnotation( + def.loc_pattern.clone(), + arity, + AnnotationSource::TypedBody { + region: annotation.region, + }, + signature.clone(), + ); let ret_constraint = constrain_expr( constraints, env, def.loc_expr.region, &def.loc_expr.value, - expected, + annotation_expected, ); let cons = [ From fd179c8b4e7dee4d077941ff1a2013c520555839 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 5 Mar 2022 23:07:57 +0100 Subject: [PATCH 018/846] improve pool_to_rank_table --- compiler/solve/src/solve.rs | 19 +++++++++++++------ compiler/types/src/subs.rs | 1 + 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index 0e30a52104..4c2dc253e6 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -1508,13 +1508,20 @@ fn pool_to_rank_table( ) -> Pools { let mut pools = Pools::new(young_rank.into_usize() + 1); - // Sort the variables into buckets by rank. - for &var in young_vars.iter() { - let rank = subs.get_rank_set_mark(var, young_mark); + // the vast majority of young variables have young_rank + let mut young_vars = young_vars.to_vec(); + young_vars.retain(|var| { + let rank = subs.get_rank_set_mark(*var, young_mark); - debug_assert!(rank.into_usize() < young_rank.into_usize() + 1); - pools.get_mut(rank).push(var); - } + if rank != young_rank { + pools.get_mut(rank).push(*var); + false + } else { + true + } + }); + + std::mem::swap(pools.get_mut(young_rank), &mut young_vars); pools } diff --git a/compiler/types/src/subs.rs b/compiler/types/src/subs.rs index b636c1efa8..243ac16f54 100644 --- a/compiler/types/src/subs.rs +++ b/compiler/types/src/subs.rs @@ -1432,6 +1432,7 @@ impl Subs { mapper(self.get_ref_mut(key)); } + #[inline(always)] pub fn get_rank_set_mark(&mut self, key: Variable, mark: Mark) -> Rank { let l_key = self.utable.get_root_key(key); From ed496bfb2ae012f098c073b1a3d1d7250f210d16 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sat, 5 Mar 2022 17:10:04 -0500 Subject: [PATCH 019/846] Add roc_std/Cargo.lock --- roc_std/Cargo.lock | 252 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 252 insertions(+) create mode 100644 roc_std/Cargo.lock diff --git a/roc_std/Cargo.lock b/roc_std/Cargo.lock new file mode 100644 index 0000000000..5494d0afd5 --- /dev/null +++ b/roc_std/Cargo.lock @@ -0,0 +1,252 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +dependencies = [ + "memchr", +] + +[[package]] +name = "ansi_term" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +dependencies = [ + "winapi", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "ctor" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccc0a48a9b826acdf4028595adc9db92caea352f7af011a3034acd172a52a0aa" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "diff" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e25ea47919b1560c4e3b7fe0aaab9becf5b84a10325ddf7db0f0ba5e1026499" + +[[package]] +name = "env_logger" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a19187fea3ac7e84da7dacf48de0c45d63c6a76f9490dae389aead16c243fce3" +dependencies = [ + "log", + "regex", +] + +[[package]] +name = "getrandom" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d39cd93900197114fa1fcb7ae84ca742095eed9442088988ae74fa744e930e77" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "indoc" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7906a9fababaeacb774f72410e497a1d18de916322e33797bb2cd29baa23c9e" +dependencies = [ + "unindent", +] + +[[package]] +name = "libc" +version = "0.2.119" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4" + +[[package]] +name = "log" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "memchr" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" + +[[package]] +name = "output_vt100" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "628223faebab4e3e40667ee0b2336d34a5b960ff60ea743ddfdbcf7770bcfb66" +dependencies = [ + "winapi", +] + +[[package]] +name = "pretty_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76d5b548b725018ab5496482b45cb8bef21e9fed1858a6d674e3a8a0f0bb5d50" +dependencies = [ + "ansi_term", + "ctor", + "diff", + "output_vt100", +] + +[[package]] +name = "proc-macro2" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quickcheck" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "588f6378e4dd99458b60ec275b4477add41ce4fa9f64dcba6f15adccb19b50d6" +dependencies = [ + "env_logger", + "log", + "rand", +] + +[[package]] +name = "quickcheck_macros" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b22a693222d716a9587786f37ac3f6b4faedb5b80c23914e7303ff5a1d8016e9" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "quote" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "864d3e96a899863136fc6e99f3d7cae289dafe43bf2c5ac19b70df7210c0a145" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +dependencies = [ + "getrandom", +] + +[[package]] +name = "regex" +version = "1.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" + +[[package]] +name = "roc_std" +version = "0.1.0" +dependencies = [ + "indoc", + "libc", + "pretty_assertions", + "quickcheck", + "quickcheck_macros", +] + +[[package]] +name = "syn" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a65b3f4ffa0092e9887669db0eae07941f023991ab58ea44da8fe8e2d511c6b" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "unicode-xid" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" + +[[package]] +name = "unindent" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514672a55d7380da379785a4d70ca8386c8883ff7eaae877be4d2081cebe73d8" + +[[package]] +name = "wasi" +version = "0.10.2+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" From eb663e85a6dd4863c7268b9e926b5156580e7917 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sat, 5 Mar 2022 17:09:37 -0500 Subject: [PATCH 020/846] Allow making a RocList from a slice --- roc_std/src/roc_list.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/roc_std/src/roc_list.rs b/roc_std/src/roc_list.rs index c8b769204d..51848c126a 100644 --- a/roc_std/src/roc_list.rs +++ b/roc_std/src/roc_list.rs @@ -266,6 +266,15 @@ where } } +impl From<&[T]> for RocList +where + T: ReferenceCount, +{ + fn from(slice: &[T]) -> Self { + Self::from_slice(slice) + } +} + impl IntoIterator for RocList where T: ReferenceCount, From 88d15a3c59dfe7c65177edd9729c77630e52dbec Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sat, 5 Mar 2022 17:08:56 -0500 Subject: [PATCH 021/846] Fix typo in comment --- roc_std/src/roc_list.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roc_std/src/roc_list.rs b/roc_std/src/roc_list.rs index 51848c126a..3e995c28b4 100644 --- a/roc_std/src/roc_list.rs +++ b/roc_std/src/roc_list.rs @@ -57,7 +57,7 @@ where let new_size = elements_offset + core::mem::size_of::() * (self.len() + slice.len()); let new_ptr = if let Some((elements, storage)) = self.elements_and_storage() { - // Decrement the lists refence count. + // Decrement the list's refence count. let mut copy = storage.get(); let is_unique = copy.decrease(); From 665e71ba1fab9427171c13a1c42e982158c17eb3 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sat, 5 Mar 2022 17:09:28 -0500 Subject: [PATCH 022/846] Comment out some unused stuff --- .../platform/src/graphics/primitives/text.rs | 148 +++++++++--------- 1 file changed, 74 insertions(+), 74 deletions(-) diff --git a/examples/gui/platform/src/graphics/primitives/text.rs b/examples/gui/platform/src/graphics/primitives/text.rs index f002d506e7..2a01ad2afa 100644 --- a/examples/gui/platform/src/graphics/primitives/text.rs +++ b/examples/gui/platform/src/graphics/primitives/text.rs @@ -38,92 +38,92 @@ impl<'a> Default for Text<'a> { } } -pub fn layout_from_text(text: &Text) -> wgpu_glyph::Layout { - wgpu_glyph::Layout::default().h_align(if text.centered { - wgpu_glyph::HorizontalAlign::Center - } else { - wgpu_glyph::HorizontalAlign::Left - }) -} +// pub fn layout_from_text(text: &Text) -> wgpu_glyph::Layout { +// wgpu_glyph::Layout::default().h_align(if text.centered { +// wgpu_glyph::HorizontalAlign::Center +// } else { +// wgpu_glyph::HorizontalAlign::Left +// }) +// } -fn section_from_text<'a>( - text: &'a Text, - layout: wgpu_glyph::Layout, -) -> wgpu_glyph::Section<'a> { - Section { - screen_position: text.position.into(), - bounds: text.area_bounds.into(), - layout, - ..Section::default() - } - .add_text( - wgpu_glyph::Text::new(text.text) - .with_color(text.color) - .with_scale(text.size), - ) -} +// fn section_from_text<'a>( +// text: &'a Text, +// layout: wgpu_glyph::Layout, +// ) -> wgpu_glyph::Section<'a> { +// Section { +// screen_position: text.position.into(), +// bounds: text.area_bounds.into(), +// layout, +// ..Section::default() +// } +// .add_text( +// wgpu_glyph::Text::new(text.text) +// .with_color(text.color) +// .with_scale(text.size), +// ) +// } -pub fn owned_section_from_text(text: &Text) -> OwnedSection { - let layout = layout_from_text(text); +// pub fn owned_section_from_text(text: &Text) -> OwnedSection { +// let layout = layout_from_text(text); - OwnedSection { - screen_position: text.position.into(), - bounds: text.area_bounds.into(), - layout, - ..OwnedSection::default() - } - .add_text( - glyph_brush::OwnedText::new(text.text) - .with_color(Vector4::from(text.color)) - .with_scale(text.size), - ) -} +// OwnedSection { +// screen_position: text.position.into(), +// bounds: text.area_bounds.into(), +// layout, +// ..OwnedSection::default() +// } +// .add_text( +// glyph_brush::OwnedText::new(text.text) +// .with_color(Vector4::from(text.color)) +// .with_scale(text.size), +// ) +// } -pub fn owned_section_from_glyph_texts( - text: Vec, - screen_position: (f32, f32), - area_bounds: (f32, f32), - layout: wgpu_glyph::Layout, -) -> glyph_brush::OwnedSection { - glyph_brush::OwnedSection { - screen_position, - bounds: area_bounds, - layout, - text, - } -} +// pub fn owned_section_from_glyph_texts( +// text: Vec, +// screen_position: (f32, f32), +// area_bounds: (f32, f32), +// layout: wgpu_glyph::Layout, +// ) -> glyph_brush::OwnedSection { +// glyph_brush::OwnedSection { +// screen_position, +// bounds: area_bounds, +// layout, +// text, +// } +// } -pub fn queue_text_draw(text: &Text, glyph_brush: &mut GlyphBrush<()>) { - let layout = layout_from_text(text); +// pub fn queue_text_draw(text: &Text, glyph_brush: &mut GlyphBrush<()>) { +// let layout = layout_from_text(text); - let section = section_from_text(text, layout); +// let section = section_from_text(text, layout); - glyph_brush.queue(section.clone()); -} +// glyph_brush.queue(section.clone()); +// } -fn glyph_to_rect(glyph: &wgpu_glyph::SectionGlyph) -> Rect { - let position = glyph.glyph.position; - let px_scale = glyph.glyph.scale; - let width = glyph_width(&glyph.glyph); - let height = px_scale.y; - let top_y = glyph_top_y(&glyph.glyph); +// fn glyph_to_rect(glyph: &wgpu_glyph::SectionGlyph) -> Rect { +// let position = glyph.glyph.position; +// let px_scale = glyph.glyph.scale; +// let width = glyph_width(&glyph.glyph); +// let height = px_scale.y; +// let top_y = glyph_top_y(&glyph.glyph); - Rect { - pos: [position.x, top_y].into(), - width, - height, - } -} +// Rect { +// pos: [position.x, top_y].into(), +// width, +// height, +// } +// } -pub fn glyph_top_y(glyph: &Glyph) -> f32 { - let height = glyph.scale.y; +// pub fn glyph_top_y(glyph: &Glyph) -> f32 { +// let height = glyph.scale.y; - glyph.position.y - height * 0.75 -} +// glyph.position.y - height * 0.75 +// } -pub fn glyph_width(glyph: &Glyph) -> f32 { - glyph.scale.x * 0.4765 -} +// pub fn glyph_width(glyph: &Glyph) -> f32 { +// glyph.scale.x * 0.4765 +// } pub fn build_glyph_brush( gpu_device: &wgpu::Device, From c8ad0abec4761468c231a33c806ff3c444328ae6 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sat, 5 Mar 2022 17:08:26 -0500 Subject: [PATCH 023/846] Use ElemId over raw pointers --- examples/gui/platform/src/focus.rs | 111 +++++++++++++++-------------- examples/gui/platform/src/gui.rs | 1 - examples/gui/platform/src/lib.rs | 1 - examples/gui/platform/src/roc.rs | 107 +++++++++++++++++---------- 4 files changed, 126 insertions(+), 94 deletions(-) diff --git a/examples/gui/platform/src/focus.rs b/examples/gui/platform/src/focus.rs index 4d844fdd6a..1cd72d5fd9 100644 --- a/examples/gui/platform/src/focus.rs +++ b/examples/gui/platform/src/focus.rs @@ -1,79 +1,80 @@ -use crate::roc::{RocElem, RocElemTag}; +use crate::roc::{ElemId, RocElem, RocElemTag}; #[derive(Debug, PartialEq, Eq)] pub struct Focus { - focused: *const RocElem, - focused_ancestors: Vec<(*const RocElem, usize)>, + focused: Option, + focused_ancestors: Vec<(ElemId, usize)>, } impl Default for Focus { fn default() -> Self { Self { - focused: std::ptr::null(), + focused: None, focused_ancestors: Vec::new(), } } } impl Focus { - pub fn focused_elem(&self) -> *const RocElem { + pub fn focused_elem(&self) -> Option { self.focused } /// e.g. the user pressed Tab. - pub fn advance(&mut self, root: &RocElem) { - if self.focused.is_null() { - // Nothing was focused in the first place, so try to focus the root. - if root.is_focusable() { - self.focused = root as *const RocElem; - self.focused_ancestors = Vec::new(); - } else if let Some((new_ptr, new_ancestors)) = - Self::next_focusable_sibling(root, None, None) - { - // If the root itself is not focusable, use its next focusable sibling. - self.focused = new_ptr; - self.focused_ancestors = new_ancestors; + /// + /// This is in contrast to next_local, which advances within a button group. + /// For example, if I have three radio buttons in a group, pressing the + /// arrow keys will cycle through them over and over without exiting the group - + /// whereas pressing Tab will cycle through them once and then exit the group. + pub fn next_global(&mut self, root: &RocElem) { + match self.focused { + Some(focused) => { + // while let Some((ancestor_id, index)) = self.focused_ancestors.pop() { + // let ancestor = ancestor_id.elem(); + + // // TODO FIXME - right now this will re-traverse a lot of ground! To prevent this, + // // we should remember past indices searched, and tell the ancestors "hey stop searching when" + // // you reach these indices, because they were already covered previously. + // // One potentially easy way to do this: pass a min_index and max_index, and only look between those! + // // + // // Related idea: instead of doing .pop() here, iterate normally so we can `break;` after storing + // // `new_ancestors = Some(next_ancestors);` - this way, we still have access to the full ancestry, and + // // can maybe even pass it in to make it clear what work has already been done! + // if let Some((new_id, new_ancestors)) = + // Self::next_focusable_sibling(focused, Some(ancestor), Some(index)) + // { + // // We found the next element to focus, so record that. + // self.focused = Some(new_id); + + // // We got a path to the new focusable's ancestor(s), so add them to the path. + // // (This may restore some of the ancestors we've been .pop()-ing as we iterated.) + // self.focused_ancestors.extend(new_ancestors); + + // return; + // } + + // // Need to write a bunch of tests for this, especially tests of focus wrapping around - e.g. + // // what happens if it wraps around to a sibling? What happens if it wraps around to something + // // higher up the tree? Lower down the tree? What if nothing is focusable? + // // A separate question: what if we should have a separate text-to-speech concept separate from focus? + // } } + None => { + // Nothing was focused in the first place, so try to focus the root. + if root.is_focusable() { + self.focused = Some(root.id()); + self.focused_ancestors = Vec::new(); + } else if let Some((new_id, new_ancestors)) = + Self::next_focusable_sibling(root, None, None) + { + // If the root itself is not focusable, use its next focusable sibling. + self.focused = Some(new_id); + self.focused_ancestors = new_ancestors; + } - // Regardless of whether we found a focusable Elem, we're done. - return; - } - - let focused = unsafe { &*self.focused }; - - while let Some((ancestor_ptr, index)) = self.focused_ancestors.pop() { - let ancestor = unsafe { &*ancestor_ptr }; - - // TODO FIXME - right now this will re-traverse a lot of ground! To prevent this, - // we should remember past indices searched, and tell the ancestors "hey stop searching when" - // you reach these indices, because they were already covered previously. - // One potentially easy way to do this: pass a min_index and max_index, and only look between those! - // - // Related idea: instead of doing .pop() here, iterate normally so we can `break;` after storing - // `new_ancestors = Some(next_ancestors);` - this way, we still have access to the full ancestry, and - // can maybe even pass it in to make it clear what work has already been done! - if let Some((new_ptr, new_ancestors)) = - Self::next_focusable_sibling(focused, Some(ancestor), Some(index)) - { - debug_assert!( - !new_ptr.is_null(), - "next_focusable returned a null Elem pointer!" - ); - - // We found the next element to focus, so record that. - self.focused = new_ptr; - - // We got a path to the new focusable's ancestor(s), so add them to the path. - // (This may restore some of the ancestors we've been .pop()-ing as we iterated.) - self.focused_ancestors.extend(new_ancestors); - + // Regardless of whether we found a focusable Elem, we're done. return; } - - // Need to write a bunch of tests for this, especially tests of focus wrapping around - e.g. - // what happens if it wraps around to a sibling? What happens if it wraps around to something - // higher up the tree? Lower down the tree? What if nothing is focusable? - // A separate question: what if we should have a separate text-to-speech concept separate from focus? } } @@ -84,7 +85,7 @@ impl Focus { elem: &RocElem, ancestor: Option<&RocElem>, opt_index: Option, - ) -> Option<(*const RocElem, Vec<(*const RocElem, usize)>)> { + ) -> Option<(ElemId, Vec<(ElemId, usize)>)> { use RocElemTag::*; match elem.tag() { diff --git a/examples/gui/platform/src/gui.rs b/examples/gui/platform/src/gui.rs index d811eeb552..66c55e0746 100644 --- a/examples/gui/platform/src/gui.rs +++ b/examples/gui/platform/src/gui.rs @@ -1,5 +1,4 @@ use crate::{ - focus::Focus, graphics::{ colors::Rgba, lowlevel::buffer::create_rect_buffers, diff --git a/examples/gui/platform/src/lib.rs b/examples/gui/platform/src/lib.rs index f609cd518a..7e1634b34f 100644 --- a/examples/gui/platform/src/lib.rs +++ b/examples/gui/platform/src/lib.rs @@ -6,7 +6,6 @@ mod roc; use crate::roc::RocElem; use core::alloc::Layout; use core::mem::MaybeUninit; -use roc_std::RocStr; extern "C" { #[link_name = "roc__programForHost_1_exposed_generic"] diff --git a/examples/gui/platform/src/roc.rs b/examples/gui/platform/src/roc.rs index 005ca4e6ba..d4f2d5e3d9 100644 --- a/examples/gui/platform/src/roc.rs +++ b/examples/gui/platform/src/roc.rs @@ -48,6 +48,11 @@ pub unsafe extern "C" fn roc_memset(dst: *mut c_void, c: i32, n: usize) -> *mut libc::memset(dst, c, n) } +#[repr(transparent)] +#[cfg(target_pointer_width = "64")] // on a 64-bit system, the tag fits in this pointer's spare 3 bits +#[derive(Copy, Clone, Debug, PartialEq, Eq)] +pub struct ElemId(*const RocElemEntry); + #[repr(transparent)] #[cfg(target_pointer_width = "64")] // on a 64-bit system, the tag fits in this pointer's spare 3 bits pub struct RocElem { @@ -55,12 +60,18 @@ pub struct RocElem { } impl RocElem { + #[allow(unused)] + pub fn id(&self) -> ElemId { + ElemId(self.entry) + } + #[cfg(target_pointer_width = "64")] pub fn tag(&self) -> RocElemTag { // On a 64-bit system, the last 3 bits of the pointer store the tag unsafe { mem::transmute::((self.entry as u8) & 0b0000_0111) } } + #[allow(unused)] pub fn entry(&self) -> &RocElemEntry { unsafe { &*self.entry_ptr() } } @@ -72,53 +83,54 @@ impl RocElem { cleared as *const RocElemEntry } - fn diff(self, other: RocElem, patches: &mut Vec<(usize, Patch)>, index: usize) { - use RocElemTag::*; + // fn diff(self, other: RocElem, patches: &mut Vec<(usize, Patch)>, index: usize) { + // use RocElemTag::*; - let tag = self.tag(); + // let tag = self.tag(); - if tag != other.tag() { - // They were totally different elem types! + // if tag != other.tag() { + // // They were totally different elem types! - // TODO should we handle Row -> Col or Col -> Row differently? - // Elm doesn't: https://github.com/elm/virtual-dom/blob/5a5bcf48720bc7d53461b3cd42a9f19f119c5503/src/Elm/Kernel/VirtualDom.js#L714 - return; - } + // // TODO should we handle Row -> Col or Col -> Row differently? + // // Elm doesn't: https://github.com/elm/virtual-dom/blob/5a5bcf48720bc7d53461b3cd42a9f19f119c5503/src/Elm/Kernel/VirtualDom.js#L714 + // return; + // } - match tag { - Button => unsafe { - let button_self = &*self.entry().button; - let button_other = &*other.entry().button; + // match tag { + // Button => unsafe { + // let button_self = &*self.entry().button; + // let button_other = &*other.entry().button; - // TODO compute a diff and patch for the button - }, - Text => unsafe { - let str_self = &*self.entry().text; - let str_other = &*other.entry().text; + // // TODO compute a diff and patch for the button + // }, + // Text => unsafe { + // let str_self = &*self.entry().text; + // let str_other = &*other.entry().text; - if str_self != str_other { - todo!("fix this"); - // let roc_str = other.entry().text; - // let patch = Patch::Text(ManuallyDrop::into_inner(roc_str)); + // if str_self != str_other { + // todo!("fix this"); + // // let roc_str = other.entry().text; + // // let patch = Patch::Text(ManuallyDrop::into_inner(roc_str)); - // patches.push((index, patch)); - } - }, - Row => unsafe { - let children_self = &self.entry().row_or_col.children; - let children_other = &other.entry().row_or_col.children; + // // patches.push((index, patch)); + // } + // }, + // Row => unsafe { + // let children_self = &self.entry().row_or_col.children; + // let children_other = &other.entry().row_or_col.children; - // TODO diff children - }, - Col => unsafe { - let children_self = &self.entry().row_or_col.children; - let children_other = &other.entry().row_or_col.children; + // // TODO diff children + // }, + // Col => unsafe { + // let children_self = &self.entry().row_or_col.children; + // let children_other = &other.entry().row_or_col.children; - // TODO diff children - }, - } - } + // // TODO diff children + // }, + // } + // } + #[allow(unused)] pub fn is_focusable(&self) -> bool { use RocElemTag::*; @@ -128,6 +140,26 @@ impl RocElem { } } + #[allow(unused)] + pub fn row>>(children: T) -> RocElem { + Self::elem_from_tag(Self::row_or_col(children), RocElemTag::Row) + } + + #[allow(unused)] + pub fn col>>(children: T) -> RocElem { + Self::elem_from_tag(Self::row_or_col(children), RocElemTag::Col) + } + + fn row_or_col>>(children: T) -> RocElemEntry { + let row_or_col = RocRowOrCol { + children: children.into(), + }; + RocElemEntry { + row_or_col: ManuallyDrop::new(row_or_col), + } + } + + #[allow(unused)] pub fn button(styles: ButtonStyles, child: RocElem) -> RocElem { let button = RocButton { child: ManuallyDrop::new(child), @@ -140,6 +172,7 @@ impl RocElem { Self::elem_from_tag(entry, RocElemTag::Button) } + #[allow(unused)] pub fn text>(into_roc_str: T) -> RocElem { let entry = RocElemEntry { text: ManuallyDrop::new(into_roc_str.into()), From 873fad275ff360f92eff78e585f882327695dcaa Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sat, 5 Mar 2022 17:08:45 -0500 Subject: [PATCH 024/846] Add some focus tests --- examples/gui/platform/src/focus.rs | 47 ++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/examples/gui/platform/src/focus.rs b/examples/gui/platform/src/focus.rs index 1cd72d5fd9..71b46b6b1c 100644 --- a/examples/gui/platform/src/focus.rs +++ b/examples/gui/platform/src/focus.rs @@ -110,7 +110,7 @@ impl Focus { } #[test] -fn next_focus_button_root() { +fn next_global_button_root() { use crate::roc::{ButtonStyles, RocElem}; let child = RocElem::text(""); @@ -118,32 +118,55 @@ fn next_focus_button_root() { let mut focus = Focus::default(); // At first, nothing should be focused. - assert_eq!(focus.focused_elem(), std::ptr::null()); + assert_eq!(focus.focused_elem(), None); - focus.advance(&root); + focus.next_global(&root); // Buttons should be focusable, so advancing focus should give the button focus. - assert_eq!(focus.focused_elem(), &root as *const RocElem); + assert_eq!(focus.focused_elem(), Some(root.id())); // Since the button is at the root, advancing again should maintain focus on it. - focus.advance(&root); - assert_eq!(focus.focused_elem(), &root as *const RocElem); + focus.next_global(&root); + assert_eq!(focus.focused_elem(), Some(root.id())); } #[test] -fn next_focus_text_root() { +fn next_global_text_root() { let root = RocElem::text(""); let mut focus = Focus::default(); // At first, nothing should be focused. - assert_eq!(focus.focused_elem(), std::ptr::null()); + assert_eq!(focus.focused_elem(), None); - focus.advance(&root); + focus.next_global(&root); // Text should not be focusable, so advancing focus should have no effect here. - assert_eq!(focus.focused_elem(), std::ptr::null()); + assert_eq!(focus.focused_elem(), None); // Just to double-check, advancing a second time should not change this. - focus.advance(&root); - assert_eq!(focus.focused_elem(), std::ptr::null()); + focus.next_global(&root); + assert_eq!(focus.focused_elem(), None); +} + +#[test] +fn next_global_row() { + use crate::roc::{ButtonStyles, RocElem}; + + let child = RocElem::text(""); + let button = RocElem::button(ButtonStyles::default(), child); + let button_id = button.id(); + let root = RocElem::row(&[button] as &[_]); + let mut focus = Focus::default(); + + // At first, nothing should be focused. + assert_eq!(focus.focused_elem(), None); + + focus.next_global(&root); + + // Buttons should be focusable, so advancing focus should give the first button in the row focus. + assert_eq!(focus.focused_elem(), Some(button_id)); + + // Since the button is the only element in the row, advancing again should maintain focus on it. + focus.next_global(&root); + assert_eq!(focus.focused_elem(), Some(button_id)); } From 258ffee84a84ffb1d819e354b60d6254f55a8237 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sat, 5 Mar 2022 17:09:16 -0500 Subject: [PATCH 025/846] Reproduce RocElem segfault --- examples/gui/platform/src/roc.rs | 36 ++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/examples/gui/platform/src/roc.rs b/examples/gui/platform/src/roc.rs index d4f2d5e3d9..e6be0813ae 100644 --- a/examples/gui/platform/src/roc.rs +++ b/examples/gui/platform/src/roc.rs @@ -272,6 +272,38 @@ pub union RocElemEntry { pub row_or_col: ManuallyDrop, } -enum Patch { - Text(RocStr), +// enum Patch { +// Text(RocStr), +// } + +#[test] +fn make_text() { + let text = RocElem::text("blah"); + + assert_eq!(text.tag(), RocElemTag::Text); +} + +#[test] +fn make_button() { + let text = RocElem::text("blah"); + let button = RocElem::button(ButtonStyles::default(), text); + + assert_eq!(button.tag(), RocElemTag::Button); +} + +#[test] +fn make_row_with_text() { + let text = RocElem::text(""); + let row = RocElem::row(&[text] as &[_]); + + assert_eq!(row.tag(), RocElemTag::Row); +} + +#[test] +fn make_row_with_button() { + let text = RocElem::text(""); + let button = RocElem::button(ButtonStyles::default(), text); + let row = RocElem::row(&[button] as &[_]); + + assert_eq!(row.tag(), RocElemTag::Row); } From 3372d7184e00e33e757893f29ed7cfd005bf9f81 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 5 Mar 2022 23:29:33 +0100 Subject: [PATCH 026/846] improvements to adjust_rank --- compiler/solve/src/solve.rs | 16 ++++++++++------ vendor/ena/src/unify/mod.rs | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index 4c2dc253e6..57869b676f 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -1535,21 +1535,24 @@ fn adjust_rank( group_rank: Rank, var: Variable, ) -> Rank { - let (desc_rank, desc_mark) = subs.get_rank_mark(var); + let desc = subs.get_ref_mut(var); + + let desc_rank = desc.rank; + let desc_mark = desc.mark; if desc_mark == young_mark { - // Mark the variable as visited before adjusting content, as it may be cyclic. - subs.set_mark(var, visit_mark); - // SAFETY: in this function (and functions it calls, we ONLY modify rank and mark, never content! // hence, we can have an immutable reference to it even though we also have a mutable // reference to the Subs as a whole. This prevents a clone of the content, which turns out // to be quite expensive. let content = { - let ptr = &subs.get_ref(var).content as *const _; + let ptr = &desc.content as *const _; unsafe { &*ptr } }; + // Mark the variable as visited before adjusting content, as it may be cyclic. + desc.mark = visit_mark; + let max_rank = adjust_rank_content(subs, young_mark, visit_mark, group_rank, content); subs.set_rank_mark(var, max_rank, visit_mark); @@ -1562,7 +1565,8 @@ fn adjust_rank( let min_rank = group_rank.min(desc_rank); // TODO from elm-compiler: how can min_rank ever be group_rank? - subs.set_rank_mark(var, min_rank, visit_mark); + desc.rank = min_rank; + desc.mark = visit_mark; min_rank } diff --git a/vendor/ena/src/unify/mod.rs b/vendor/ena/src/unify/mod.rs index 6eddcd4d06..00c120ff3d 100644 --- a/vendor/ena/src/unify/mod.rs +++ b/vendor/ena/src/unify/mod.rs @@ -470,7 +470,7 @@ where K1: Into, { let id = id.into(); - let id = self.get_root_key_without_compacting(id); + let id = self.get_root_key(id); self.value_mut(id) } From 69be422d8300869accf6a2c7ecc6d655f79e94e6 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 5 Mar 2022 23:37:41 +0100 Subject: [PATCH 027/846] optimize occurs --- compiler/types/src/subs.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/compiler/types/src/subs.rs b/compiler/types/src/subs.rs index 243ac16f54..164367a28e 100644 --- a/compiler/types/src/subs.rs +++ b/compiler/types/src/subs.rs @@ -1455,7 +1455,7 @@ impl Subs { } pub fn occurs(&self, var: Variable) -> Result<(), (Variable, Vec)> { - occurs(self, &ImSet::default(), var) + occurs(self, &[], var) } pub fn mark_tag_union_recursive( @@ -2381,7 +2381,7 @@ fn is_empty_record(subs: &Subs, mut var: Variable) -> bool { fn occurs( subs: &Subs, - seen: &ImSet, + seen: &[Variable], input_var: Variable, ) -> Result<(), (Variable, Vec)> { use self::Content::*; @@ -2396,9 +2396,9 @@ fn occurs( FlexVar(_) | RigidVar(_) | RecursionVar { .. } | Error => Ok(()), Structure(flat_type) => { - let mut new_seen = seen.clone(); + let mut new_seen = seen.to_owned(); - new_seen.insert(root_var); + new_seen.push(root_var); match flat_type { Apply(_, args) => { @@ -2447,8 +2447,7 @@ fn occurs( } } Alias(_, args, _, _) => { - let mut new_seen = seen.clone(); - new_seen.insert(root_var); + let mut new_seen = seen.to_owned(); for var_index in args.into_iter() { let var = subs[var_index]; @@ -2458,8 +2457,8 @@ fn occurs( Ok(()) } RangedNumber(typ, _range_vars) => { - let mut new_seen = seen.clone(); - new_seen.insert(root_var); + let mut new_seen = seen.to_owned(); + new_seen.push(root_var); short_circuit_help(subs, root_var, &new_seen, *typ)?; // _range_vars excluded because they are not explicitly part of the type. @@ -2470,10 +2469,11 @@ fn occurs( } } +#[inline(always)] fn short_circuit<'a, T>( subs: &Subs, root_key: Variable, - seen: &ImSet, + seen: &[Variable], iter: T, ) -> Result<(), (Variable, Vec)> where @@ -2486,10 +2486,11 @@ where Ok(()) } +#[inline(always)] fn short_circuit_help( subs: &Subs, root_key: Variable, - seen: &ImSet, + seen: &[Variable], var: Variable, ) -> Result<(), (Variable, Vec)> { if let Err((v, mut vec)) = occurs(subs, seen, var) { From 8f7f03343d643537cf4f1fd6e3fdccdde33d3e2b Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sat, 5 Mar 2022 20:46:32 -0500 Subject: [PATCH 028/846] Add Debug instance for RocElem --- examples/gui/platform/src/roc.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/examples/gui/platform/src/roc.rs b/examples/gui/platform/src/roc.rs index e6be0813ae..8285c4a046 100644 --- a/examples/gui/platform/src/roc.rs +++ b/examples/gui/platform/src/roc.rs @@ -3,6 +3,7 @@ use core::ffi::c_void; use core::mem::{self, ManuallyDrop}; use roc_std::{ReferenceCount, RocList, RocStr}; use std::ffi::CStr; +use std::fmt::Debug; use std::os::raw::c_char; #[no_mangle] @@ -59,6 +60,31 @@ pub struct RocElem { entry: *const RocElemEntry, } +impl Debug for RocElem { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + use RocElemTag::*; + + match self.tag() { + Button => unsafe { &*self.entry().button }.fmt(f), + Text => unsafe { &*self.entry().text }.fmt(f), + Row => { + let row_or_col = unsafe { &*self.entry().row_or_col }; + + f.debug_struct("RocRow") + .field("children", &row_or_col.children) + .finish() + } + Col => { + let row_or_col = unsafe { &*self.entry().row_or_col }; + + f.debug_struct("RocCol") + .field("children", &row_or_col.children) + .finish() + } + } + } +} + impl RocElem { #[allow(unused)] pub fn id(&self) -> ElemId { @@ -203,6 +229,7 @@ pub enum RocElemTag { } #[repr(C)] +#[derive(Debug)] pub struct RocButton { pub child: ManuallyDrop, pub styles: ButtonStyles, From 04818292a8051790bf2200bee9bac259f41d1239 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 6 Mar 2022 12:57:01 +0100 Subject: [PATCH 029/846] Make type_to_variable manually tail-recursive by using a work stack and reserving variables. fun stuff --- compiler/solve/src/solve.rs | 558 ++++++++++++++++++++---------------- 1 file changed, 318 insertions(+), 240 deletions(-) diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index 57869b676f..16cc4502c6 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -861,14 +861,65 @@ fn type_to_var( _: &mut MutMap, typ: &Type, ) -> Variable { - let mut arena = take_scratchpad(); + if let Type::Variable(var) = typ { + *var + } else { + let mut arena = take_scratchpad(); - let var = type_to_variable(subs, rank, pools, &arena, typ); + // let var = type_to_variable(subs, rank, pools, &arena, typ); + let var = type_to_variable(subs, rank, pools, &arena, typ); - arena.reset(); - put_scratchpad(arena); + arena.reset(); + put_scratchpad(arena); - var + var + } +} + +enum RegisterVariable { + /// Based on the Type, we already know what variable this will be + Direct(Variable), + /// This Type needs more complicated Content. We reserve a Variable + /// for it, but put a placeholder Content in subs + Deferred, +} + +impl RegisterVariable { + fn from_type( + subs: &mut Subs, + rank: Rank, + pools: &mut Pools, + arena: &'_ bumpalo::Bump, + typ: &Type, + ) -> Self { + use RegisterVariable::*; + + match typ { + Variable(var) => Direct(*var), + EmptyRec => Direct(Variable::EMPTY_RECORD), + EmptyTagUnion => Direct(Variable::EMPTY_TAG_UNION), + Type::Alias { symbol, .. } => { + if let Some(reserved) = Variable::get_reserved(*symbol) { + if rank.is_none() { + // reserved variables are stored with rank NONE + return Direct(reserved); + } else { + // for any other rank, we need to copy; it takes care of adjusting the rank + let copied = deep_copy_var_in(subs, rank, pools, reserved, arena); + return Direct(copied); + } + } + + Deferred + } + _ => Deferred, + } + } +} + +#[derive(Debug)] +enum TypeToVar<'a> { + Defer(&'a Type, Variable), } fn type_to_variable<'a>( @@ -880,255 +931,280 @@ fn type_to_variable<'a>( ) -> Variable { use bumpalo::collections::Vec; - match typ { - Variable(var) => *var, - RangedNumber(typ, vars) => { - let ty_var = type_to_variable(subs, rank, pools, arena, typ); - let vars = VariableSubsSlice::insert_into_subs(subs, vars.iter().copied()); - let content = Content::RangedNumber(ty_var, vars); + let mut stack = Vec::with_capacity_in(8, arena); - register(subs, rank, pools, content) - } - Apply(symbol, arguments, _) => { - let new_arguments = VariableSubsSlice::reserve_into_subs(subs, arguments.len()); - for (target_index, var_index) in (new_arguments.indices()).zip(arguments) { - let var = type_to_variable(subs, rank, pools, arena, var_index); - subs.variables[target_index] = var; - } - - let flat_type = FlatType::Apply(*symbol, new_arguments); - let content = Content::Structure(flat_type); - - register(subs, rank, pools, content) - } - EmptyRec => Variable::EMPTY_RECORD, - EmptyTagUnion => Variable::EMPTY_TAG_UNION, - - ClosureTag { name, ext } => { - let tag_name = TagName::Closure(*name); - let tag_names = SubsSlice::new(subs.tag_names.len() as u32, 1); - - subs.tag_names.push(tag_name); - - // the first VariableSubsSlice in the array is a zero-length slice - let union_tags = UnionTags::from_slices(tag_names, SubsSlice::new(0, 1)); - - let content = Content::Structure(FlatType::TagUnion(union_tags, *ext)); - - register(subs, rank, pools, content) - } - - // This case is important for the rank of boolean variables - Function(arguments, closure_type, ret_type) => { - let new_arguments = VariableSubsSlice::reserve_into_subs(subs, arguments.len()); - for (target_index, var_index) in (new_arguments.indices()).zip(arguments) { - let var = type_to_variable(subs, rank, pools, arena, var_index); - subs.variables[target_index] = var; - } - - let ret_var = type_to_variable(subs, rank, pools, arena, ret_type); - let closure_var = type_to_variable(subs, rank, pools, arena, closure_type); - let content = Content::Structure(FlatType::Func(new_arguments, closure_var, ret_var)); - - register(subs, rank, pools, content) - } - Record(fields, ext) => { - // An empty fields is inefficient (but would be correct) - // If hit, try to turn the value into an EmptyRecord in canonicalization - debug_assert!(!fields.is_empty() || !ext.is_empty_record()); - - let mut field_vars = Vec::with_capacity_in(fields.len(), arena); - - for (field, field_type) in fields { - let field_var = - field_type.map(|typ| type_to_variable(subs, rank, pools, arena, typ)); - - field_vars.push((field.clone(), field_var)); - } - - let temp_ext_var = type_to_variable(subs, rank, pools, arena, ext); - - let (it, new_ext_var) = - gather_fields_unsorted_iter(subs, RecordFields::empty(), temp_ext_var) - .expect("Something ended up weird in this record type"); - - let it = it - .into_iter() - .map(|(field, field_type)| (field.clone(), field_type)); - - field_vars.extend(it); - insertion_sort_by(&mut field_vars, RecordFields::compare); - - let record_fields = RecordFields::insert_into_subs(subs, field_vars); - - let content = Content::Structure(FlatType::Record(record_fields, new_ext_var)); - - register(subs, rank, pools, content) - } - TagUnion(tags, ext) => { - // An empty tags is inefficient (but would be correct) - // If hit, try to turn the value into an EmptyTagUnion in canonicalization - debug_assert!(!tags.is_empty() || !ext.is_empty_tag_union()); - - let (union_tags, ext) = type_to_union_tags(subs, rank, pools, arena, tags, ext); - let content = Content::Structure(FlatType::TagUnion(union_tags, ext)); - - register(subs, rank, pools, content) - } - FunctionOrTagUnion(tag_name, symbol, ext) => { - let temp_ext_var = type_to_variable(subs, rank, pools, arena, ext); - - let (it, ext) = roc_types::types::gather_tags_unsorted_iter( - subs, - UnionTags::default(), - temp_ext_var, - ); - - for _ in it { - unreachable!("we assert that the ext var is empty; otherwise we'd already know it was a tag union!"); - } - - let slice = SubsIndex::new(subs.tag_names.len() as u32); - subs.tag_names.push(tag_name.clone()); - - let content = Content::Structure(FlatType::FunctionOrTagUnion(slice, *symbol, ext)); - - register(subs, rank, pools, content) - } - RecursiveTagUnion(rec_var, tags, ext) => { - // An empty tags is inefficient (but would be correct) - // If hit, try to turn the value into an EmptyTagUnion in canonicalization - debug_assert!(!tags.is_empty() || !ext.is_empty_tag_union()); - - let (union_tags, ext) = type_to_union_tags(subs, rank, pools, arena, tags, ext); - let content = - Content::Structure(FlatType::RecursiveTagUnion(*rec_var, union_tags, ext)); - - let tag_union_var = register(subs, rank, pools, content); - - register_with_known_var( - subs, - *rec_var, - rank, - pools, - Content::RecursionVar { - opt_name: None, - structure: tag_union_var, - }, - ); - - tag_union_var - } - - Type::Alias { - symbol, - type_arguments, - actual, - lambda_set_variables, - kind, - } => { - if let Some(reserved) = Variable::get_reserved(*symbol) { - if rank.is_none() { - // reserved variables are stored with rank NONE - return reserved; - } else { - // for any other rank, we need to copy; it takes care of adjusting the rank - return deep_copy_var_in(subs, rank, pools, reserved, arena); + macro_rules! helper { + ($typ:expr) => {{ + match RegisterVariable::from_type(subs, rank, pools, arena, $typ) { + RegisterVariable::Direct(var) => var, + RegisterVariable::Deferred => { + let var = subs.fresh_unnamed_flex_var(); + stack.push(TypeToVar::Defer($typ, var)); + var } } + }}; + } - let alias_variables = alias_to_var( - subs, - rank, - pools, - arena, - type_arguments, - lambda_set_variables, - ); + let result = helper!(typ); - let alias_variable = if let Symbol::RESULT_RESULT = *symbol { - roc_result_to_var(subs, rank, pools, arena, actual) - } else { - type_to_variable(subs, rank, pools, arena, actual) - }; - let content = Content::Alias(*symbol, alias_variables, alias_variable, *kind); + while let Some(TypeToVar::Defer(typ, destination)) = stack.pop() { + match typ { + Variable(_) | EmptyRec | EmptyTagUnion => { + unreachable!("This variant should never be deferred!") + } + RangedNumber(typ, vars) => { + let ty_var = helper!(typ); + let vars = VariableSubsSlice::insert_into_subs(subs, vars.iter().copied()); + let content = Content::RangedNumber(ty_var, vars); - register(subs, rank, pools, content) - } - HostExposedAlias { - name: symbol, - type_arguments, - actual: alias_type, - actual_var, - lambda_set_variables, - .. - } => { - let alias_variables = alias_to_var( - subs, - rank, - pools, - arena, - type_arguments, - lambda_set_variables, - ); + register_with_known_var(subs, destination, rank, pools, content) + } + Apply(symbol, arguments, _) => { + let new_arguments = VariableSubsSlice::reserve_into_subs(subs, arguments.len()); + for (target_index, var_index) in (new_arguments.indices()).zip(arguments) { + let var = helper!(var_index); + subs.variables[target_index] = var; + } - let alias_variable = type_to_variable(subs, rank, pools, arena, alias_type); - // TODO(opaques): I think host-exposed aliases should always be structural - // (when does it make sense to give a host an opaque type?) - let content = Content::Alias( - *symbol, - alias_variables, - alias_variable, - AliasKind::Structural, - ); - let result = register(subs, rank, pools, content); + let flat_type = FlatType::Apply(*symbol, new_arguments); + let content = Content::Structure(flat_type); - // We only want to unify the actual_var with the alias once - // if it's already redirected (and therefore, redundant) - // don't do it again - if !subs.redundant(*actual_var) { - let descriptor = subs.get(result); - subs.union(result, *actual_var, descriptor); + register_with_known_var(subs, destination, rank, pools, content) } - result - } - Erroneous(problem) => { - let content = Content::Structure(FlatType::Erroneous(Box::new(problem.clone()))); + ClosureTag { name, ext } => { + let tag_name = TagName::Closure(*name); + let tag_names = SubsSlice::new(subs.tag_names.len() as u32, 1); - register(subs, rank, pools, content) - } - } -} + subs.tag_names.push(tag_name); -#[inline(always)] -fn alias_to_var<'a>( - subs: &mut Subs, - rank: Rank, - pools: &mut Pools, - arena: &'a bumpalo::Bump, - type_arguments: &[(roc_module::ident::Lowercase, Type)], - lambda_set_variables: &[roc_types::types::LambdaSet], -) -> AliasVariables { - let length = type_arguments.len() + lambda_set_variables.len(); - let new_variables = VariableSubsSlice::reserve_into_subs(subs, length); + // the first VariableSubsSlice in the array is a zero-length slice + let union_tags = UnionTags::from_slices(tag_names, SubsSlice::new(0, 1)); - for (target_index, (_, arg_type)) in (new_variables.indices()).zip(type_arguments) { - let copy_var = type_to_variable(subs, rank, pools, arena, arg_type); - subs.variables[target_index] = copy_var; + let content = Content::Structure(FlatType::TagUnion(union_tags, *ext)); + + register_with_known_var(subs, destination, rank, pools, content) + } + // This case is important for the rank of boolean variables + Function(arguments, closure_type, ret_type) => { + let new_arguments = VariableSubsSlice::reserve_into_subs(subs, arguments.len()); + for (target_index, var_index) in (new_arguments.indices()).zip(arguments) { + let var = helper!(var_index); + subs.variables[target_index] = var; + } + + let ret_var = helper!(ret_type); + let closure_var = helper!(closure_type); + let content = + Content::Structure(FlatType::Func(new_arguments, closure_var, ret_var)); + + register_with_known_var(subs, destination, rank, pools, content) + } + Record(fields, ext) => { + // An empty fields is inefficient (but would be correct) + // If hit, try to turn the value into an EmptyRecord in canonicalization + debug_assert!(!fields.is_empty() || !ext.is_empty_record()); + + let mut field_vars = Vec::with_capacity_in(fields.len(), arena); + + for (field, field_type) in fields { + let field_var = { + use roc_types::types::RecordField::*; + match &field_type { + Optional(t) => Optional(helper!(t)), + Required(t) => Required(helper!(t)), + Demanded(t) => Demanded(helper!(t)), + } + }; + + field_vars.push((field.clone(), field_var)); + } + + let temp_ext_var = helper!(ext); + + let (it, new_ext_var) = + gather_fields_unsorted_iter(subs, RecordFields::empty(), temp_ext_var) + .expect("Something ended up weird in this record type"); + + let it = it + .into_iter() + .map(|(field, field_type)| (field.clone(), field_type)); + + field_vars.extend(it); + insertion_sort_by(&mut field_vars, RecordFields::compare); + + let record_fields = RecordFields::insert_into_subs(subs, field_vars); + + let content = Content::Structure(FlatType::Record(record_fields, new_ext_var)); + + register_with_known_var(subs, destination, rank, pools, content) + } + + TagUnion(tags, ext) => { + // An empty tags is inefficient (but would be correct) + // If hit, try to turn the value into an EmptyTagUnion in canonicalization + debug_assert!(!tags.is_empty() || !ext.is_empty_tag_union()); + + let (union_tags, ext) = type_to_union_tags(subs, rank, pools, arena, tags, ext); + let content = Content::Structure(FlatType::TagUnion(union_tags, ext)); + + register_with_known_var(subs, destination, rank, pools, content) + } + FunctionOrTagUnion(tag_name, symbol, ext) => { + let temp_ext_var = helper!(ext); + + let (it, ext) = roc_types::types::gather_tags_unsorted_iter( + subs, + UnionTags::default(), + temp_ext_var, + ); + + for _ in it { + unreachable!("we assert that the ext var is empty; otherwise we'd already know it was a tag union!"); + } + + let slice = SubsIndex::new(subs.tag_names.len() as u32); + subs.tag_names.push(tag_name.clone()); + + let content = Content::Structure(FlatType::FunctionOrTagUnion(slice, *symbol, ext)); + + register_with_known_var(subs, destination, rank, pools, content) + } + RecursiveTagUnion(rec_var, tags, ext) => { + // An empty tags is inefficient (but would be correct) + // If hit, try to turn the value into an EmptyTagUnion in canonicalization + debug_assert!(!tags.is_empty() || !ext.is_empty_tag_union()); + + let (union_tags, ext) = type_to_union_tags(subs, rank, pools, arena, tags, ext); + let content = + Content::Structure(FlatType::RecursiveTagUnion(*rec_var, union_tags, ext)); + + let tag_union_var = destination; + register_with_known_var(subs, tag_union_var, rank, pools, content); + + register_with_known_var( + subs, + *rec_var, + rank, + pools, + Content::RecursionVar { + opt_name: None, + structure: tag_union_var, + }, + ); + + tag_union_var + } + + Type::Alias { + symbol, + type_arguments, + actual, + lambda_set_variables, + kind, + } => { + debug_assert!(Variable::get_reserved(*symbol).is_none()); + + let alias_variables = { + let length = type_arguments.len() + lambda_set_variables.len(); + let new_variables = VariableSubsSlice::reserve_into_subs(subs, length); + + for (target_index, (_, arg_type)) in + (new_variables.indices()).zip(type_arguments) + { + let copy_var = helper!(arg_type); + subs.variables[target_index] = copy_var; + } + + let it = (new_variables.indices().skip(type_arguments.len())) + .zip(lambda_set_variables); + for (target_index, ls) in it { + let copy_var = helper!(&ls.0); + subs.variables[target_index] = copy_var; + } + + AliasVariables { + variables_start: new_variables.start, + type_variables_len: type_arguments.len() as _, + all_variables_len: length as _, + } + }; + + let alias_variable = if let Symbol::RESULT_RESULT = *symbol { + roc_result_to_var(subs, rank, pools, arena, actual) + } else { + helper!(actual) + }; + let content = Content::Alias(*symbol, alias_variables, alias_variable, *kind); + + register_with_known_var(subs, destination, rank, pools, content) + } + HostExposedAlias { + name: symbol, + type_arguments, + actual: alias_type, + actual_var, + lambda_set_variables, + .. + } => { + let alias_variables = { + let length = type_arguments.len() + lambda_set_variables.len(); + let new_variables = VariableSubsSlice::reserve_into_subs(subs, length); + + for (target_index, (_, arg_type)) in + (new_variables.indices()).zip(type_arguments) + { + let copy_var = helper!(arg_type); + subs.variables[target_index] = copy_var; + } + + let it = (new_variables.indices().skip(type_arguments.len())) + .zip(lambda_set_variables); + for (target_index, ls) in it { + let copy_var = helper!(&ls.0); + subs.variables[target_index] = copy_var; + } + + AliasVariables { + variables_start: new_variables.start, + type_variables_len: type_arguments.len() as _, + all_variables_len: length as _, + } + }; + + // cannot use helper! here because this variable may be involved in unification below + let alias_variable = type_to_variable(subs, rank, pools, arena, alias_type); + // TODO(opaques): I think host-exposed aliases should always be structural + // (when does it make sense to give a host an opaque type?) + let content = Content::Alias( + *symbol, + alias_variables, + alias_variable, + AliasKind::Structural, + ); + // let result = register(subs, rank, pools, content); + let result = register_with_known_var(subs, destination, rank, pools, content); + + // We only want to unify the actual_var with the alias once + // if it's already redirected (and therefore, redundant) + // don't do it again + if !subs.redundant(*actual_var) { + let descriptor = subs.get(result); + subs.union(result, *actual_var, descriptor); + } + + result + } + Erroneous(problem) => { + let content = Content::Structure(FlatType::Erroneous(Box::new(problem.clone()))); + + register_with_known_var(subs, destination, rank, pools, content) + } + }; } - let it = (new_variables.indices().skip(type_arguments.len())).zip(lambda_set_variables); - for (target_index, ls) in it { - let copy_var = type_to_variable(subs, rank, pools, arena, &ls.0); - subs.variables[target_index] = copy_var; - } - - AliasVariables { - variables_start: new_variables.start, - type_variables_len: type_arguments.len() as _, - all_variables_len: length as _, - } + result } #[inline(always)] @@ -2174,7 +2250,7 @@ fn register_with_known_var( rank: Rank, pools: &mut Pools, content: Content, -) { +) -> Variable { let descriptor = Descriptor { content, rank, @@ -2185,4 +2261,6 @@ fn register_with_known_var( subs.set(var, descriptor); pools.get_mut(rank).push(var); + + var } From 261b40613773203cb5e0bd2afcf163bbe2e8e8cb Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sun, 6 Mar 2022 08:40:29 -0500 Subject: [PATCH 030/846] Use roc_alloc over Box::new when making elems --- examples/gui/platform/src/roc.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/examples/gui/platform/src/roc.rs b/examples/gui/platform/src/roc.rs index 8285c4a046..dd02176168 100644 --- a/examples/gui/platform/src/roc.rs +++ b/examples/gui/platform/src/roc.rs @@ -208,9 +208,16 @@ impl RocElem { } fn elem_from_tag(entry: RocElemEntry, tag: RocElemTag) -> Self { - let entry_box = Box::new(entry); - let entry_ptr = entry_box.as_ref() as *const RocElemEntry; - let tagged_ptr = entry_ptr as usize | tag as usize; + let tagged_ptr = unsafe { + let entry_ptr = roc_alloc( + core::mem::size_of_val(&entry), + core::mem::align_of_val(&entry) as u32, + ) as *mut RocElemEntry; + + *entry_ptr = entry; + + entry_ptr as usize | tag as usize + }; Self { entry: tagged_ptr as *const RocElemEntry, From 76a118db14c3d783ef7cd3f9a514632183a9d359 Mon Sep 17 00:00:00 2001 From: Folkert Date: Tue, 8 Mar 2022 23:53:52 +0100 Subject: [PATCH 031/846] fix needles cloning of ident_ids --- compiler/load/src/file.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/compiler/load/src/file.rs b/compiler/load/src/file.rs index 83a2d6e4a5..a68b73ddf5 100644 --- a/compiler/load/src/file.rs +++ b/compiler/load/src/file.rs @@ -1264,7 +1264,6 @@ fn state_thread_step<'a>( // This is where most of the main thread's work gets done. // Everything up to this point has been setting up the threading // system which lets this logic work efficiently. - let constrained_ident_ids = state.constrained_ident_ids.clone(); let arc_modules = state.arc_modules.clone(); let res_state = update( @@ -1288,8 +1287,13 @@ fn state_thread_step<'a>( .into_inner() .into_module_ids(); - let buf = - to_parse_problem_report(problem, module_ids, constrained_ident_ids); + // if parsing failed, this module did not add anything to IdentIds + let root_exposed_ident_ids = IdentIds::exposed_builtins(0); + let buf = to_parse_problem_report( + problem, + module_ids, + root_exposed_ident_ids, + ); Err(LoadingProblem::FormattedReport(buf)) } Err(e) => Err(e), From 4ce7221c39556fe66adf86d7b4ee587eba8baf96 Mon Sep 17 00:00:00 2001 From: Folkert Date: Thu, 10 Mar 2022 22:29:37 +0100 Subject: [PATCH 032/846] optimize Type::symbols() --- compiler/types/src/types.rs | 106 +++++++++++++++++------------------- 1 file changed, 51 insertions(+), 55 deletions(-) diff --git a/compiler/types/src/types.rs b/compiler/types/src/types.rs index c6f4f360f3..576a0e477b 100644 --- a/compiler/types/src/types.rs +++ b/compiler/types/src/types.rs @@ -713,11 +713,8 @@ impl Type { } } - pub fn symbols(&self) -> ImSet { - let mut found_symbols = ImSet::default(); - symbols_help(self, &mut found_symbols); - - found_symbols + pub fn symbols(&self) -> Vec { + symbols_help(self) } /// a shallow dealias, continue until the first constructor is not an alias. @@ -934,62 +931,61 @@ impl Type { } } -fn symbols_help(tipe: &Type, accum: &mut ImSet) { +fn symbols_help(initial: &Type) -> Vec { use Type::*; - match tipe { - Function(args, closure, ret) => { - symbols_help(ret, accum); - symbols_help(closure, accum); - args.iter().for_each(|arg| symbols_help(arg, accum)); - } - FunctionOrTagUnion(_, _, ext) => { - symbols_help(ext, accum); - } - RecursiveTagUnion(_, tags, ext) | TagUnion(tags, ext) => { - symbols_help(ext, accum); - tags.iter() - .map(|v| v.1.iter()) - .flatten() - .for_each(|arg| symbols_help(arg, accum)); - } + let mut output = vec![]; + let mut stack = vec![initial]; - Record(fields, ext) => { - symbols_help(ext, accum); - fields.values().for_each(|field| { - use RecordField::*; + while let Some(tipe) = stack.pop() { + match tipe { + Function(args, closure, ret) => { + stack.push(ret); + stack.push(closure); + stack.extend(args); + } + FunctionOrTagUnion(_, _, ext) => { + stack.push(ext); + } + RecursiveTagUnion(_, tags, ext) | TagUnion(tags, ext) => { + stack.push(ext); + stack.extend(tags.iter().map(|v| v.1.iter()).flatten()); + } - match field { - Optional(arg) => symbols_help(arg, accum), - Required(arg) => symbols_help(arg, accum), - Demanded(arg) => symbols_help(arg, accum), - } - }); + Record(fields, ext) => { + stack.push(ext); + stack.extend(fields.values().map(|field| field.as_inner())); + } + Alias { + symbol: alias_symbol, + actual: actual_type, + .. + } => { + output.push(*alias_symbol); + stack.push(actual_type); + } + HostExposedAlias { name, actual, .. } => { + output.push(*name); + stack.push(actual); + } + Apply(symbol, args, _) => { + output.push(*symbol); + stack.extend(args); + } + Erroneous(Problem::CyclicAlias(alias, _, _)) => { + output.push(*alias); + } + RangedNumber(typ, _) => { + stack.push(typ); + } + EmptyRec | EmptyTagUnion | ClosureTag { .. } | Erroneous(_) | Variable(_) => {} } - Alias { - symbol: alias_symbol, - actual: actual_type, - .. - } => { - accum.insert(*alias_symbol); - symbols_help(actual_type, accum); - } - HostExposedAlias { name, actual, .. } => { - accum.insert(*name); - symbols_help(actual, accum); - } - Apply(symbol, args, _) => { - accum.insert(*symbol); - args.iter().for_each(|arg| symbols_help(arg, accum)); - } - Erroneous(Problem::CyclicAlias(alias, _, _)) => { - accum.insert(*alias); - } - RangedNumber(typ, _) => { - symbols_help(typ, accum); - } - EmptyRec | EmptyTagUnion | ClosureTag { .. } | Erroneous(_) | Variable(_) => {} } + + output.sort(); + output.dedup(); + + output } fn variables_help(tipe: &Type, accum: &mut ImSet) { From 85fdb6564e3ded2c4d361bb8d34c9639e5f61c55 Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 11 Mar 2022 23:42:59 +0100 Subject: [PATCH 033/846] Revert "optimize Type::symbols()" This reverts commit 4ce7221c39556fe66adf86d7b4ee587eba8baf96. --- compiler/types/src/types.rs | 110 +++++++++++++++++++----------------- 1 file changed, 57 insertions(+), 53 deletions(-) diff --git a/compiler/types/src/types.rs b/compiler/types/src/types.rs index 576a0e477b..c6f4f360f3 100644 --- a/compiler/types/src/types.rs +++ b/compiler/types/src/types.rs @@ -713,8 +713,11 @@ impl Type { } } - pub fn symbols(&self) -> Vec { - symbols_help(self) + pub fn symbols(&self) -> ImSet { + let mut found_symbols = ImSet::default(); + symbols_help(self, &mut found_symbols); + + found_symbols } /// a shallow dealias, continue until the first constructor is not an alias. @@ -931,61 +934,62 @@ impl Type { } } -fn symbols_help(initial: &Type) -> Vec { +fn symbols_help(tipe: &Type, accum: &mut ImSet) { use Type::*; - let mut output = vec![]; - let mut stack = vec![initial]; - - while let Some(tipe) = stack.pop() { - match tipe { - Function(args, closure, ret) => { - stack.push(ret); - stack.push(closure); - stack.extend(args); - } - FunctionOrTagUnion(_, _, ext) => { - stack.push(ext); - } - RecursiveTagUnion(_, tags, ext) | TagUnion(tags, ext) => { - stack.push(ext); - stack.extend(tags.iter().map(|v| v.1.iter()).flatten()); - } - - Record(fields, ext) => { - stack.push(ext); - stack.extend(fields.values().map(|field| field.as_inner())); - } - Alias { - symbol: alias_symbol, - actual: actual_type, - .. - } => { - output.push(*alias_symbol); - stack.push(actual_type); - } - HostExposedAlias { name, actual, .. } => { - output.push(*name); - stack.push(actual); - } - Apply(symbol, args, _) => { - output.push(*symbol); - stack.extend(args); - } - Erroneous(Problem::CyclicAlias(alias, _, _)) => { - output.push(*alias); - } - RangedNumber(typ, _) => { - stack.push(typ); - } - EmptyRec | EmptyTagUnion | ClosureTag { .. } | Erroneous(_) | Variable(_) => {} + match tipe { + Function(args, closure, ret) => { + symbols_help(ret, accum); + symbols_help(closure, accum); + args.iter().for_each(|arg| symbols_help(arg, accum)); } + FunctionOrTagUnion(_, _, ext) => { + symbols_help(ext, accum); + } + RecursiveTagUnion(_, tags, ext) | TagUnion(tags, ext) => { + symbols_help(ext, accum); + tags.iter() + .map(|v| v.1.iter()) + .flatten() + .for_each(|arg| symbols_help(arg, accum)); + } + + Record(fields, ext) => { + symbols_help(ext, accum); + fields.values().for_each(|field| { + use RecordField::*; + + match field { + Optional(arg) => symbols_help(arg, accum), + Required(arg) => symbols_help(arg, accum), + Demanded(arg) => symbols_help(arg, accum), + } + }); + } + Alias { + symbol: alias_symbol, + actual: actual_type, + .. + } => { + accum.insert(*alias_symbol); + symbols_help(actual_type, accum); + } + HostExposedAlias { name, actual, .. } => { + accum.insert(*name); + symbols_help(actual, accum); + } + Apply(symbol, args, _) => { + accum.insert(*symbol); + args.iter().for_each(|arg| symbols_help(arg, accum)); + } + Erroneous(Problem::CyclicAlias(alias, _, _)) => { + accum.insert(*alias); + } + RangedNumber(typ, _) => { + symbols_help(typ, accum); + } + EmptyRec | EmptyTagUnion | ClosureTag { .. } | Erroneous(_) | Variable(_) => {} } - - output.sort(); - output.dedup(); - - output } fn variables_help(tipe: &Type, accum: &mut ImSet) { From bcd100e462a19d8a75fd91ec911abf7adc680536 Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 18 Mar 2022 21:55:20 +0100 Subject: [PATCH 034/846] remove allocation in Symbol creation --- Cargo.lock | 4 ++++ compiler/ident/Cargo.toml | 3 +++ compiler/ident/src/lib.rs | 44 ++++++++++++++++++++++++----------- compiler/module/Cargo.toml | 1 + compiler/module/src/symbol.rs | 8 ++++--- 5 files changed, 43 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 74c0b69c0d..aca639d79a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3647,6 +3647,9 @@ dependencies = [ [[package]] name = "roc_ident" version = "0.1.0" +dependencies = [ + "arrayvec 0.7.2", +] [[package]] name = "roc_linker" @@ -3702,6 +3705,7 @@ dependencies = [ name = "roc_module" version = "0.1.0" dependencies = [ + "arrayvec 0.7.2", "bumpalo", "lazy_static", "roc_collections", diff --git a/compiler/ident/Cargo.toml b/compiler/ident/Cargo.toml index d272f4818f..14edceaab5 100644 --- a/compiler/ident/Cargo.toml +++ b/compiler/ident/Cargo.toml @@ -4,3 +4,6 @@ version = "0.1.0" authors = ["The Roc Contributors"] license = "UPL-1.0" edition = "2018" + +[dependencies] +arrayvec = "0.7.2" diff --git a/compiler/ident/src/lib.rs b/compiler/ident/src/lib.rs index d611241926..6c4163e5d4 100644 --- a/compiler/ident/src/lib.rs +++ b/compiler/ident/src/lib.rs @@ -20,9 +20,6 @@ use std::os::raw::c_char; /// a UTF-8 string). This design works on little-endian targets, but a different /// design for storing length might be necessary on big-endian targets. -// For big-endian, field order must be swapped! -// Otherwise, the discriminant byte will be in the wrong place. -#[cfg(target_endian = "little")] #[repr(C)] pub struct IdentStr { elements: *const u8, @@ -30,6 +27,8 @@ pub struct IdentStr { } impl IdentStr { + const SMALL_STR_BYTES: usize = std::mem::size_of::() - 1; + pub fn len(&self) -> usize { let bytes = self.length.to_ne_bytes(); let last_byte = bytes[mem::size_of::() - 1]; @@ -82,22 +81,39 @@ impl IdentStr { (self as *const IdentStr).cast() } + #[inline(always)] + const fn small_str_from_bytes(slice: &[u8]) -> Self { + assert!(slice.len() <= Self::SMALL_STR_BYTES); + + let len = slice.len(); + let mut bytes = [0; mem::size_of::()]; + + // Copy the bytes from the slice into bytes. + // while because for/Iterator does not work in const context + let mut i = 0; + while i < len { + bytes[i] = slice[i]; + i += 1; + } + + // Write length and small string bit to last byte of length. + bytes[Self::SMALL_STR_BYTES] = u8::MAX - len as u8; + + unsafe { mem::transmute::<[u8; mem::size_of::()], Self>(bytes) } + } + + pub fn from_array_string( + array_string: arrayvec::ArrayString<{ Self::SMALL_STR_BYTES }>, + ) -> Self { + Self::small_str_from_bytes(array_string.as_bytes()) + } + fn from_str(str: &str) -> Self { let slice = str.as_bytes(); let len = slice.len(); match len.cmp(&mem::size_of::()) { - Ordering::Less => { - let mut bytes = [0; mem::size_of::()]; - - // Copy the bytes from the slice into bytes. - bytes[..len].copy_from_slice(slice); - - // Write length and small string bit to last byte of length. - bytes[mem::size_of::() * 2 - 1] = u8::MAX - len as u8; - - unsafe { mem::transmute::<[u8; mem::size_of::()], Self>(bytes) } - } + Ordering::Less => Self::small_str_from_bytes(slice), Ordering::Equal => { // This fits in a small string, and is exactly long enough to // take up the entire available struct diff --git a/compiler/module/Cargo.toml b/compiler/module/Cargo.toml index 9b8c272d54..50dc2e3eb2 100644 --- a/compiler/module/Cargo.toml +++ b/compiler/module/Cargo.toml @@ -14,3 +14,4 @@ bumpalo = { version = "3.8.0", features = ["collections"] } lazy_static = "1.4.0" static_assertions = "1.1.0" snafu = { version = "0.6.10", features = ["backtraces"] } +arrayvec = "0.7.2" diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index 96d5776d55..ec179365dc 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -634,9 +634,11 @@ impl IdentIds { /// This is used, for example, during canonicalization of an Expr::Closure /// to generate a unique symbol to refer to that closure. pub fn gen_unique(&mut self) -> IdentId { - // TODO convert this directly from u32 into IdentStr, - // without allocating an extra string along the way like this. - let ident = self.next_generated_name.to_string().into(); + use std::fmt::Write; + + let mut temp: arrayvec::ArrayString<15> = arrayvec::ArrayString::new(); + write!(temp, "{}", self.next_generated_name).unwrap(); + let ident = Ident(IdentStr::from_array_string(temp)); self.next_generated_name += 1; From 3db44af36f7fb0d5bdc820be12fbffbab9329cd5 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 19 Mar 2022 16:25:45 +0100 Subject: [PATCH 035/846] make timing info available in `check` mode --- compiler/load/src/file.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/load/src/file.rs b/compiler/load/src/file.rs index e3223ec78f..76e1c6eac1 100644 --- a/compiler/load/src/file.rs +++ b/compiler/load/src/file.rs @@ -2054,6 +2054,7 @@ fn update<'a>( .insert(module_id, typechecked); } else { state.constrained_ident_ids.insert(module_id, ident_ids); + state.timings.insert(module_id, module_timing); } start_tasks(arena, &mut state, work, injector, worker_listeners)?; From 2cbe5f52310f00fce68dbca335fb8b078c51f243 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 19 Mar 2022 16:26:38 +0100 Subject: [PATCH 036/846] idea (rejected): only generate work up to constraint gen, then look at what modules are actually used and generate Solve.. work based on that --- cli/src/build.rs | 2 + compiler/constrain/src/module.rs | 12 ++++- compiler/load/src/file.rs | 90 +++++++++++++++++++++++++++----- compiler/load/src/work.rs | 73 +++++++++++++++++++++++--- compiler/module/src/symbol.rs | 2 +- 5 files changed, 156 insertions(+), 23 deletions(-) diff --git a/cli/src/build.rs b/cli/src/build.rs index 2d4f7fae53..d6e7f6fbc6 100644 --- a/cli/src/build.rs +++ b/cli/src/build.rs @@ -157,6 +157,8 @@ pub fn build_file<'a>( buf.push('\n'); + dbg!(module_id); + report_timing(buf, "Read .roc file from disk", module_timing.read_roc_file); report_timing(buf, "Parse header", module_timing.parse_header); report_timing(buf, "Parse body", module_timing.parse_body); diff --git a/compiler/constrain/src/module.rs b/compiler/constrain/src/module.rs index 8af7f4c38e..9128006892 100644 --- a/compiler/constrain/src/module.rs +++ b/compiler/constrain/src/module.rs @@ -32,13 +32,21 @@ impl ExposedByModule { /// /// Useful when we know what modules a particular module imports, and want just /// the exposed types for those exposed modules. - pub fn retain_modules<'a>(&self, it: impl Iterator) -> Self { + pub fn retain_modules<'a>( + &self, + home: ModuleId, + it: impl Iterator, + ) -> Self { let mut output = Self::default(); for module_id in it { match self.exposed.get(module_id) { None => { - internal_error!("Module {:?} did not register its exposed values", module_id) + internal_error!( + "Module {:?} did not register its exposed values for {:?}", + module_id, + home, + ) } Some(exposed_types) => { output.exposed.insert(*module_id, exposed_types.clone()); diff --git a/compiler/load/src/file.rs b/compiler/load/src/file.rs index 76e1c6eac1..3451c2c269 100644 --- a/compiler/load/src/file.rs +++ b/compiler/load/src/file.rs @@ -1099,7 +1099,7 @@ fn load<'a>( ) -> Result, LoadingProblem<'a>> { // When compiling to wasm, we cannot spawn extra threads // so we have a single-threaded implementation - if true || cfg!(target_family = "wasm") { + if cfg!(target_family = "wasm") { load_single_threaded( arena, load_start, @@ -1614,14 +1614,18 @@ fn report_unused_imported_modules<'a>( state: &mut State<'a>, module_id: ModuleId, constrained_module: &ConstrainedModule, -) { +) -> (Vec, Vec) { + let mut kept = vec![]; + let mut removed = vec![]; let mut unused_imported_modules = constrained_module.imported_modules.clone(); for symbol in constrained_module.module.referenced_values.iter() { + kept.push(symbol.module_id()); unused_imported_modules.remove(&symbol.module_id()); } for symbol in constrained_module.module.referenced_types.iter() { + kept.push(symbol.module_id()); unused_imported_modules.remove(&symbol.module_id()); } @@ -1633,8 +1637,23 @@ fn report_unused_imported_modules<'a>( for (unused, region) in unused_imported_modules.drain() { if !unused.is_builtin() { existing.push(roc_problem::can::Problem::UnusedImport(unused, region)); + + // we will still typecheck this module to report errors + kept.push(unused) + } else { + // for builtin modules, we will just skip the rest of the process + // in the future, we can also do this for modules from packages + removed.push(unused); } } + + kept.sort(); + kept.dedup(); + + removed.sort(); + removed.dedup(); + + (kept, removed) } fn update<'a>( @@ -1870,7 +1889,7 @@ fn update<'a>( work.extend(state.dependencies.add_module( header.module_id, &header.package_qualified_imported_modules, - state.goal_phase, + Phase::CanonicalizeAndConstrain, )); state.module_cache.headers.insert(header.module_id, header); @@ -1919,7 +1938,7 @@ fn update<'a>( } CanonicalizedAndConstrained { - constrained_module, + mut constrained_module, canonicalization_problems, module_docs, } => { @@ -1934,7 +1953,51 @@ fn update<'a>( state.module_cache.documentation.insert(module_id, docs); } - report_unused_imported_modules(&mut state, module_id, &constrained_module); + let (kept, removed) = + report_unused_imported_modules(&mut state, module_id, &constrained_module); + + for rem in removed { + constrained_module.imported_modules.remove(&rem); + } + + use std::fmt::Write; + let mut buf = String::new(); + writeln!(buf, "{:?} depends on:", module_id); + for dep in kept { + if !constrained_module.imported_modules.contains_key(&dep) { + continue; + } + writeln!(buf, " {:?} ", dep); + if module_id != dep { + state + .dependencies + .add_dependency(module_id, dep, Phase::SolveTypes); + } + } + println!("{}", buf); + + state.dependencies.add_dependency_help( + module_id, + module_id, + Phase::SolveTypes, + Phase::CanonicalizeAndConstrain, + ); + + state + .dependencies + .add_to_status(module_id, Phase::SolveTypes); + + /* + for dependency in remove_dependencies { + println!("remove dep {:?} <- {:?}", module_id, dependency); + state.dependencies.remove_dependencies( + module_id, + dependency, + Phase::SolveTypes, + state.goal_phase, + ); + } + */ state .module_cache @@ -1996,7 +2059,7 @@ fn update<'a>( if is_host_exposed && state.goal_phase == Phase::SolveTypes { debug_assert!(work.is_empty()); - debug_assert!(state.dependencies.solved_all()); + // debug_assert!(state.dependencies.solved_all()); state.timings.insert(module_id, module_timing); @@ -2787,10 +2850,7 @@ fn load_module<'a>( roc_parse::header::ModuleName::new("Bool"), Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("Bool")))]), )), - Loc::at_zero(ImportsEntry::Module( - roc_parse::header::ModuleName::new("List"), - Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("List")))]), - )), + // Note: List is only used for the type, which we ensure is always in scope Loc::at_zero(ImportsEntry::Module( roc_parse::header::ModuleName::new("Num"), Collection::with_items(&[ @@ -2856,9 +2916,6 @@ fn load_module<'a>( toUtf8 : Str -> List U8 - # fromUtf8 : List U8 -> Result Str [ BadUtf8 Utf8Problem ]* - # fromUtf8Range : List U8 -> Result Str [ BadUtf8 Utf8Problem Nat, OutOfBounds ]* - fromUtf8 : List U8 -> Result Str [ BadUtf8 Utf8ByteProblem Nat ]* fromUtf8Range : List U8, { start : Nat, count : Nat } -> Result Str [ BadUtf8 Utf8ByteProblem Nat, OutOfBounds ]* @@ -4344,7 +4401,8 @@ impl<'a> BuildTask<'a> { dep_idents: MutMap, declarations: Vec, ) -> Self { - let exposed_by_module = exposed_types.retain_modules(imported_modules.keys()); + let exposed_by_module = + exposed_types.retain_modules(module.module_id, imported_modules.keys()); let exposed_for_module = ExposedForModule::new(module.referenced_values.iter(), exposed_by_module); @@ -4635,6 +4693,10 @@ fn canonicalize_and_constrain<'a>( let constraint = constrain_module(&mut constraints, &module_output.declarations, module_id); + if module_id == ModuleId::STR { + dbg!(&constraints); + } + let after = roc_types::types::get_type_clone_count(); log!( diff --git a/compiler/load/src/work.rs b/compiler/load/src/work.rs index f26209163d..9662190fe8 100644 --- a/compiler/load/src/work.rs +++ b/compiler/load/src/work.rs @@ -32,7 +32,7 @@ enum Status { Done, } -#[derive(Clone, Debug, PartialEq, Eq, Hash)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] enum Job<'a> { Step(ModuleId, Phase), ResolveShorthand(&'a str), @@ -74,8 +74,10 @@ impl<'a> Dependencies<'a> { // to canonicalize a module, all its dependencies must be canonicalized self.add_dependency(module_id, dep, Phase::CanonicalizeAndConstrain); - // to typecheck a module, all its dependencies must be type checked already - self.add_dependency(module_id, dep, Phase::SolveTypes); + if goal_phase >= Phase::SolveTypes { + // to typecheck a module, all its dependencies must be type checked already + self.add_dependency(module_id, dep, Phase::SolveTypes); + } if goal_phase >= FindSpecializations { self.add_dependency(module_id, dep, Phase::FindSpecializations); @@ -101,7 +103,7 @@ impl<'a> Dependencies<'a> { output } - fn add_to_status(&mut self, module_id: ModuleId, goal_phase: Phase) { + pub fn add_to_status(&mut self, module_id: ModuleId, goal_phase: Phase) { for phase in PHASES.iter() { if *phase > goal_phase { break; @@ -193,13 +195,72 @@ impl<'a> Dependencies<'a> { } } + pub fn remove_dependencies( + &mut self, + a: ModuleId, + b: ModuleId, + start_phase: Phase, + goal_phase: Phase, + ) { + let mut i = 0; + while PHASES[i] < goal_phase { + let phase = PHASES[i]; + + if phase >= start_phase { + self.remove_dependency(a, b, phase); + } + + i += 1; + } + } + /// A waits for B, and B will notify A when it completes the phase - fn add_dependency(&mut self, a: ModuleId, b: ModuleId, phase: Phase) { + /// we will remove both of these connections + fn remove_dependency(&mut self, a: ModuleId, b: ModuleId, phase: Phase) { + let key = Job::Step(a, phase); + + let mut notifications = vec![]; + + match self.waiting_for.get_mut(&key) { + None => unreachable!(), + Some(x) => { + x.retain(|job| match job { + Job::Step(module, _) => { + if *module == b { + notifications.push(*job); + false + } else { + true + } + } + Job::ResolveShorthand(_) => true, + }); + } + } + + for notification in notifications { + match self.notifies.get_mut(¬ification) { + None => unreachable!(), + Some(x) => { + x.retain(|notify_job| notify_job != &key); + } + } + } + } + + /// A waits for B, and B will notify A when it completes the phase + pub fn add_dependency(&mut self, a: ModuleId, b: ModuleId, phase: Phase) { self.add_dependency_help(a, b, phase, phase); } /// phase_a of module a is waiting for phase_b of module_b - fn add_dependency_help(&mut self, a: ModuleId, b: ModuleId, phase_a: Phase, phase_b: Phase) { + pub fn add_dependency_help( + &mut self, + a: ModuleId, + b: ModuleId, + phase_a: Phase, + phase_b: Phase, + ) { // no need to wait if the dependency is already done! if let Some(Status::Done) = self.status.get(&Job::Step(b, phase_b)) { return; diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index ec179365dc..0ab8982962 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -293,7 +293,7 @@ lazy_static! { } /// A globally unique ID that gets assigned to each module as it is loaded. -#[derive(Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct ModuleId(u32); impl ModuleId { From e914272bf590b1405d94e041e6828d0431e11e01 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 19 Mar 2022 16:26:46 +0100 Subject: [PATCH 037/846] Revert "idea (rejected): only generate work up to constraint gen, then look at what modules are actually used and generate Solve.. work based on that" This reverts commit 2cbe5f52310f00fce68dbca335fb8b078c51f243. --- cli/src/build.rs | 2 - compiler/constrain/src/module.rs | 12 +---- compiler/load/src/file.rs | 90 +++++--------------------------- compiler/load/src/work.rs | 73 +++----------------------- compiler/module/src/symbol.rs | 2 +- 5 files changed, 23 insertions(+), 156 deletions(-) diff --git a/cli/src/build.rs b/cli/src/build.rs index d6e7f6fbc6..2d4f7fae53 100644 --- a/cli/src/build.rs +++ b/cli/src/build.rs @@ -157,8 +157,6 @@ pub fn build_file<'a>( buf.push('\n'); - dbg!(module_id); - report_timing(buf, "Read .roc file from disk", module_timing.read_roc_file); report_timing(buf, "Parse header", module_timing.parse_header); report_timing(buf, "Parse body", module_timing.parse_body); diff --git a/compiler/constrain/src/module.rs b/compiler/constrain/src/module.rs index 9128006892..8af7f4c38e 100644 --- a/compiler/constrain/src/module.rs +++ b/compiler/constrain/src/module.rs @@ -32,21 +32,13 @@ impl ExposedByModule { /// /// Useful when we know what modules a particular module imports, and want just /// the exposed types for those exposed modules. - pub fn retain_modules<'a>( - &self, - home: ModuleId, - it: impl Iterator, - ) -> Self { + pub fn retain_modules<'a>(&self, it: impl Iterator) -> Self { let mut output = Self::default(); for module_id in it { match self.exposed.get(module_id) { None => { - internal_error!( - "Module {:?} did not register its exposed values for {:?}", - module_id, - home, - ) + internal_error!("Module {:?} did not register its exposed values", module_id) } Some(exposed_types) => { output.exposed.insert(*module_id, exposed_types.clone()); diff --git a/compiler/load/src/file.rs b/compiler/load/src/file.rs index 3451c2c269..76e1c6eac1 100644 --- a/compiler/load/src/file.rs +++ b/compiler/load/src/file.rs @@ -1099,7 +1099,7 @@ fn load<'a>( ) -> Result, LoadingProblem<'a>> { // When compiling to wasm, we cannot spawn extra threads // so we have a single-threaded implementation - if cfg!(target_family = "wasm") { + if true || cfg!(target_family = "wasm") { load_single_threaded( arena, load_start, @@ -1614,18 +1614,14 @@ fn report_unused_imported_modules<'a>( state: &mut State<'a>, module_id: ModuleId, constrained_module: &ConstrainedModule, -) -> (Vec, Vec) { - let mut kept = vec![]; - let mut removed = vec![]; +) { let mut unused_imported_modules = constrained_module.imported_modules.clone(); for symbol in constrained_module.module.referenced_values.iter() { - kept.push(symbol.module_id()); unused_imported_modules.remove(&symbol.module_id()); } for symbol in constrained_module.module.referenced_types.iter() { - kept.push(symbol.module_id()); unused_imported_modules.remove(&symbol.module_id()); } @@ -1637,23 +1633,8 @@ fn report_unused_imported_modules<'a>( for (unused, region) in unused_imported_modules.drain() { if !unused.is_builtin() { existing.push(roc_problem::can::Problem::UnusedImport(unused, region)); - - // we will still typecheck this module to report errors - kept.push(unused) - } else { - // for builtin modules, we will just skip the rest of the process - // in the future, we can also do this for modules from packages - removed.push(unused); } } - - kept.sort(); - kept.dedup(); - - removed.sort(); - removed.dedup(); - - (kept, removed) } fn update<'a>( @@ -1889,7 +1870,7 @@ fn update<'a>( work.extend(state.dependencies.add_module( header.module_id, &header.package_qualified_imported_modules, - Phase::CanonicalizeAndConstrain, + state.goal_phase, )); state.module_cache.headers.insert(header.module_id, header); @@ -1938,7 +1919,7 @@ fn update<'a>( } CanonicalizedAndConstrained { - mut constrained_module, + constrained_module, canonicalization_problems, module_docs, } => { @@ -1953,51 +1934,7 @@ fn update<'a>( state.module_cache.documentation.insert(module_id, docs); } - let (kept, removed) = - report_unused_imported_modules(&mut state, module_id, &constrained_module); - - for rem in removed { - constrained_module.imported_modules.remove(&rem); - } - - use std::fmt::Write; - let mut buf = String::new(); - writeln!(buf, "{:?} depends on:", module_id); - for dep in kept { - if !constrained_module.imported_modules.contains_key(&dep) { - continue; - } - writeln!(buf, " {:?} ", dep); - if module_id != dep { - state - .dependencies - .add_dependency(module_id, dep, Phase::SolveTypes); - } - } - println!("{}", buf); - - state.dependencies.add_dependency_help( - module_id, - module_id, - Phase::SolveTypes, - Phase::CanonicalizeAndConstrain, - ); - - state - .dependencies - .add_to_status(module_id, Phase::SolveTypes); - - /* - for dependency in remove_dependencies { - println!("remove dep {:?} <- {:?}", module_id, dependency); - state.dependencies.remove_dependencies( - module_id, - dependency, - Phase::SolveTypes, - state.goal_phase, - ); - } - */ + report_unused_imported_modules(&mut state, module_id, &constrained_module); state .module_cache @@ -2059,7 +1996,7 @@ fn update<'a>( if is_host_exposed && state.goal_phase == Phase::SolveTypes { debug_assert!(work.is_empty()); - // debug_assert!(state.dependencies.solved_all()); + debug_assert!(state.dependencies.solved_all()); state.timings.insert(module_id, module_timing); @@ -2850,7 +2787,10 @@ fn load_module<'a>( roc_parse::header::ModuleName::new("Bool"), Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("Bool")))]), )), - // Note: List is only used for the type, which we ensure is always in scope + Loc::at_zero(ImportsEntry::Module( + roc_parse::header::ModuleName::new("List"), + Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("List")))]), + )), Loc::at_zero(ImportsEntry::Module( roc_parse::header::ModuleName::new("Num"), Collection::with_items(&[ @@ -2916,6 +2856,9 @@ fn load_module<'a>( toUtf8 : Str -> List U8 + # fromUtf8 : List U8 -> Result Str [ BadUtf8 Utf8Problem ]* + # fromUtf8Range : List U8 -> Result Str [ BadUtf8 Utf8Problem Nat, OutOfBounds ]* + fromUtf8 : List U8 -> Result Str [ BadUtf8 Utf8ByteProblem Nat ]* fromUtf8Range : List U8, { start : Nat, count : Nat } -> Result Str [ BadUtf8 Utf8ByteProblem Nat, OutOfBounds ]* @@ -4401,8 +4344,7 @@ impl<'a> BuildTask<'a> { dep_idents: MutMap, declarations: Vec, ) -> Self { - let exposed_by_module = - exposed_types.retain_modules(module.module_id, imported_modules.keys()); + let exposed_by_module = exposed_types.retain_modules(imported_modules.keys()); let exposed_for_module = ExposedForModule::new(module.referenced_values.iter(), exposed_by_module); @@ -4693,10 +4635,6 @@ fn canonicalize_and_constrain<'a>( let constraint = constrain_module(&mut constraints, &module_output.declarations, module_id); - if module_id == ModuleId::STR { - dbg!(&constraints); - } - let after = roc_types::types::get_type_clone_count(); log!( diff --git a/compiler/load/src/work.rs b/compiler/load/src/work.rs index 9662190fe8..f26209163d 100644 --- a/compiler/load/src/work.rs +++ b/compiler/load/src/work.rs @@ -32,7 +32,7 @@ enum Status { Done, } -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +#[derive(Clone, Debug, PartialEq, Eq, Hash)] enum Job<'a> { Step(ModuleId, Phase), ResolveShorthand(&'a str), @@ -74,10 +74,8 @@ impl<'a> Dependencies<'a> { // to canonicalize a module, all its dependencies must be canonicalized self.add_dependency(module_id, dep, Phase::CanonicalizeAndConstrain); - if goal_phase >= Phase::SolveTypes { - // to typecheck a module, all its dependencies must be type checked already - self.add_dependency(module_id, dep, Phase::SolveTypes); - } + // to typecheck a module, all its dependencies must be type checked already + self.add_dependency(module_id, dep, Phase::SolveTypes); if goal_phase >= FindSpecializations { self.add_dependency(module_id, dep, Phase::FindSpecializations); @@ -103,7 +101,7 @@ impl<'a> Dependencies<'a> { output } - pub fn add_to_status(&mut self, module_id: ModuleId, goal_phase: Phase) { + fn add_to_status(&mut self, module_id: ModuleId, goal_phase: Phase) { for phase in PHASES.iter() { if *phase > goal_phase { break; @@ -195,72 +193,13 @@ impl<'a> Dependencies<'a> { } } - pub fn remove_dependencies( - &mut self, - a: ModuleId, - b: ModuleId, - start_phase: Phase, - goal_phase: Phase, - ) { - let mut i = 0; - while PHASES[i] < goal_phase { - let phase = PHASES[i]; - - if phase >= start_phase { - self.remove_dependency(a, b, phase); - } - - i += 1; - } - } - /// A waits for B, and B will notify A when it completes the phase - /// we will remove both of these connections - fn remove_dependency(&mut self, a: ModuleId, b: ModuleId, phase: Phase) { - let key = Job::Step(a, phase); - - let mut notifications = vec![]; - - match self.waiting_for.get_mut(&key) { - None => unreachable!(), - Some(x) => { - x.retain(|job| match job { - Job::Step(module, _) => { - if *module == b { - notifications.push(*job); - false - } else { - true - } - } - Job::ResolveShorthand(_) => true, - }); - } - } - - for notification in notifications { - match self.notifies.get_mut(¬ification) { - None => unreachable!(), - Some(x) => { - x.retain(|notify_job| notify_job != &key); - } - } - } - } - - /// A waits for B, and B will notify A when it completes the phase - pub fn add_dependency(&mut self, a: ModuleId, b: ModuleId, phase: Phase) { + fn add_dependency(&mut self, a: ModuleId, b: ModuleId, phase: Phase) { self.add_dependency_help(a, b, phase, phase); } /// phase_a of module a is waiting for phase_b of module_b - pub fn add_dependency_help( - &mut self, - a: ModuleId, - b: ModuleId, - phase_a: Phase, - phase_b: Phase, - ) { + fn add_dependency_help(&mut self, a: ModuleId, b: ModuleId, phase_a: Phase, phase_b: Phase) { // no need to wait if the dependency is already done! if let Some(Status::Done) = self.status.get(&Job::Step(b, phase_b)) { return; diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index 0ab8982962..ec179365dc 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -293,7 +293,7 @@ lazy_static! { } /// A globally unique ID that gets assigned to each module as it is loaded. -#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] +#[derive(Copy, Clone, PartialEq, Eq, Hash)] pub struct ModuleId(u32); impl ModuleId { From 2516ccf70d89b35d43d132cc3899556d42bd950e Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 20 Mar 2022 00:34:59 +0100 Subject: [PATCH 038/846] inline subs operations more aggressively --- compiler/types/src/subs.rs | 20 ++++---- .../hello-world/zig-platform/helloZig.roc | 48 +++++++++++++++++++ vendor/ena/src/unify/mod.rs | 42 ++++++++++------ 3 files changed, 87 insertions(+), 23 deletions(-) diff --git a/compiler/types/src/subs.rs b/compiler/types/src/subs.rs index 31cbac6363..930acf243e 100644 --- a/compiler/types/src/subs.rs +++ b/compiler/types/src/subs.rs @@ -1406,8 +1406,8 @@ impl Subs { /// Unions two keys without the possibility of failure. pub fn union(&mut self, left: Variable, right: Variable, desc: Descriptor) { - let l_root = self.utable.get_root_key(left); - let r_root = self.utable.get_root_key(right); + let l_root = self.utable.inlined_get_root_key(left); + let r_root = self.utable.inlined_get_root_key(right); // NOTE this swapping is intentional! most of our unifying commands are based on the elm // source, but unify_roots is from `ena`, not the elm source. Turns out that they have @@ -1451,23 +1451,25 @@ impl Subs { &self.utable.probe_value_ref(key).value.content } + #[inline(always)] pub fn get_root_key(&mut self, key: Variable) -> Variable { - self.utable.get_root_key(key) + self.utable.inlined_get_root_key(key) } + #[inline(always)] pub fn get_root_key_without_compacting(&self, key: Variable) -> Variable { self.utable.get_root_key_without_compacting(key) } #[inline(always)] pub fn set(&mut self, key: Variable, r_value: Descriptor) { - let l_key = self.utable.get_root_key(key); + let l_key = self.utable.inlined_get_root_key(key); self.utable.update_value(l_key, |node| node.value = r_value); } pub fn set_rank(&mut self, key: Variable, rank: Rank) { - let l_key = self.utable.get_root_key(key); + let l_key = self.utable.inlined_get_root_key(key); self.utable.update_value(l_key, |node| { node.value.rank = rank; @@ -1475,7 +1477,7 @@ impl Subs { } pub fn set_mark(&mut self, key: Variable, mark: Mark) { - let l_key = self.utable.get_root_key(key); + let l_key = self.utable.inlined_get_root_key(key); self.utable.update_value(l_key, |node| { node.value.mark = mark; @@ -1483,7 +1485,7 @@ impl Subs { } pub fn set_rank_mark(&mut self, key: Variable, rank: Rank, mark: Mark) { - let l_key = self.utable.get_root_key(key); + let l_key = self.utable.inlined_get_root_key(key); self.utable.update_value(l_key, |node| { node.value.rank = rank; @@ -1492,7 +1494,7 @@ impl Subs { } pub fn set_content(&mut self, key: Variable, content: Content) { - let l_key = self.utable.get_root_key(key); + let l_key = self.utable.inlined_get_root_key(key); self.utable.update_value(l_key, |node| { node.value.content = content; @@ -1508,7 +1510,7 @@ impl Subs { #[inline(always)] pub fn get_rank_set_mark(&mut self, key: Variable, mark: Mark) -> Rank { - let l_key = self.utable.get_root_key(key); + let l_key = self.utable.inlined_get_root_key(key); let mut rank = Rank::NONE; diff --git a/examples/hello-world/zig-platform/helloZig.roc b/examples/hello-world/zig-platform/helloZig.roc index 6c7223111a..6a91331c80 100644 --- a/examples/hello-world/zig-platform/helloZig.roc +++ b/examples/hello-world/zig-platform/helloZig.roc @@ -4,3 +4,51 @@ app "helloZig" provides [ main ] to pf main = "Hello, World!\n" + +Utf8ByteProblem : + [ + InvalidStartByte, + UnexpectedEndOfSequence, + ExpectedContinuation, + OverlongEncoding, + CodepointTooLarge, + EncodesSurrogateHalf, + ] + +Utf8Problem : { byteIndex : Nat, problem : Utf8ByteProblem } + +isEmpty : Str -> Bool +concat : Str, Str -> Str + +joinWith : List Str, Str -> Str +split : Str, Str -> List Str +repeat : Str, Nat -> Str +countGraphemes : Str -> Nat +startsWithCodePt : Str, U32 -> Bool + +toUtf8 : Str -> List U8 + +fromUtf8 : List U8 -> Result Str [ BadUtf8 Utf8ByteProblem Nat ]* +fromUtf8Range : List U8, { start : Nat, count : Nat } -> Result Str [ BadUtf8 Utf8ByteProblem Nat, OutOfBounds ]* + +startsWith : Str, Str -> Bool +endsWith : Str, Str -> Bool + +trim : Str -> Str +trimLeft : Str -> Str +trimRight : Str -> Str + +toDec : Str -> Result Dec [ InvalidNumStr ]* +toF64 : Str -> Result F64 [ InvalidNumStr ]* +toF32 : Str -> Result F32 [ InvalidNumStr ]* +toNat : Str -> Result Nat [ InvalidNumStr ]* +toU128 : Str -> Result U128 [ InvalidNumStr ]* +toI128 : Str -> Result I128 [ InvalidNumStr ]* +toU64 : Str -> Result U64 [ InvalidNumStr ]* +toI64 : Str -> Result I64 [ InvalidNumStr ]* +toU32 : Str -> Result U32 [ InvalidNumStr ]* +toI32 : Str -> Result I32 [ InvalidNumStr ]* +toU16 : Str -> Result U16 [ InvalidNumStr ]* +toI16 : Str -> Result I16 [ InvalidNumStr ]* +toU8 : Str -> Result U8 [ InvalidNumStr ]* +toI8 : Str -> Result I8 [ InvalidNumStr ]* diff --git a/vendor/ena/src/unify/mod.rs b/vendor/ena/src/unify/mod.rs index 00c120ff3d..cdcf08cfb7 100644 --- a/vendor/ena/src/unify/mod.rs +++ b/vendor/ena/src/unify/mod.rs @@ -298,21 +298,35 @@ impl UnificationTable { /// /// NB. This is a building-block operation and you would probably /// prefer to call `probe` below. - pub fn get_root_key(&mut self, vid: S::Key) -> S::Key { - match self.value(vid).parent(vid) { - None => vid, - Some(redirect) => { - let root_key: S::Key = self.get_root_key(redirect); - if root_key != redirect { - // Path compression - self.update_value(vid, |value| value.parent = root_key); - } - - root_key + /// + /// This is an always-inlined version of this function for the hot + /// callsites. `uninlined_get_root_key` is the never-inlined version. + #[inline(always)] + pub fn inlined_get_root_key(&mut self, vid: S::Key) -> S::Key { + let redirect = { + match self.value(vid).parent(vid) { + None => return vid, + Some(redirect) => redirect, } + }; + + let root_key: S::Key = self.uninlined_get_root_key(redirect); + if root_key != redirect { + // Path compression + self.update_value(vid, |value| value.parent = root_key); } + + root_key } + // This is a never-inlined version of this function for cold callsites. + // 'inlined_get_root_key` is the always-inlined version. + #[inline(never)] + fn uninlined_get_root_key(&mut self, vid: S::Key) -> S::Key { + self.inlined_get_root_key(vid) + } + + #[inline(always)] pub fn get_root_key_without_compacting(&self, mut vid: S::Key) -> S::Key { while let Some(redirect) = self.value(vid).parent(vid) { vid = redirect; @@ -435,7 +449,7 @@ where K1: Into, { let id = id.into(); - self.get_root_key(id) + self.inlined_get_root_key(id) } /// Returns the current value for the given key. If the key has @@ -446,7 +460,7 @@ where K1: Into, { let id = id.into(); - let id = self.get_root_key(id); + let id = self.inlined_get_root_key(id); self.value(id).value.clone() } @@ -470,7 +484,7 @@ where K1: Into, { let id = id.into(); - let id = self.get_root_key(id); + let id = self.inlined_get_root_key(id); self.value_mut(id) } From a9982a30aa003d277e856de476638d77ba14ab12 Mon Sep 17 00:00:00 2001 From: Folkert Date: Mon, 21 Mar 2022 19:23:13 +0100 Subject: [PATCH 039/846] WIP --- Cargo.lock | 11 ++++++ compiler/load/Cargo.toml | 1 + compiler/load/src/file.rs | 74 ++++++++++++++++++++++++++++---------- compiler/types/src/subs.rs | 31 ++++++++++++---- 4 files changed, 92 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aca639d79a..a373df043a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2076,6 +2076,16 @@ version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" +[[package]] +name = "memmap" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "memmap2" version = "0.1.0" @@ -3677,6 +3687,7 @@ dependencies = [ "crossbeam", "indoc", "maplit", + "memmap", "morphic_lib", "num_cpus", "parking_lot", diff --git a/compiler/load/Cargo.toml b/compiler/load/Cargo.toml index 3945650771..afb62d8b77 100644 --- a/compiler/load/Cargo.toml +++ b/compiler/load/Cargo.toml @@ -27,6 +27,7 @@ bumpalo = { version = "3.8.0", features = ["collections"] } parking_lot = "0.11.2" crossbeam = "0.8.1" num_cpus = "1.13.0" +memmap = "0.7.0" [dev-dependencies] tempfile = "3.2.0" diff --git a/compiler/load/src/file.rs b/compiler/load/src/file.rs index 76586c333c..5eeb735622 100644 --- a/compiler/load/src/file.rs +++ b/compiler/load/src/file.rs @@ -4475,29 +4475,67 @@ fn run_solve<'a>( solve_aliases.insert(*name, alias.clone()); } - let (solved_subs, solved_env, problems) = roc_solve::module::run_solve( - &constraints, - actual_constraint, - rigid_variables, - subs, - solve_aliases, - ); + let (solved_subs, exposed_vars_by_symbol, problems) = if module_id.is_builtin() { + use memmap::MmapOptions; + use std::fs::File; - let solved_subs = if true { - solved_subs + // let file = File::open(&format!("cached_subs/{:?}.dat", module_id)).unwrap(); + // let mmap = unsafe { MmapOptions::new().map(&file).unwrap() }; + + let mmap = std::fs::read(&format!("cached_subs/{:?}.dat", module_id)).unwrap(); + println!("started {:?}", module_id); + let (subs, vars_by_symbol) = Subs::deserialize(&mmap); + println!("deserialized"); + let solved_subs = Solved(subs); + + let exposed_vars_by_symbol: Vec<_> = vars_by_symbol + .into_iter() + .filter(|(k, _)| exposed_symbols.contains(k)) + .collect(); + + (solved_subs, exposed_vars_by_symbol, vec![]) } else { - let mut serialized = Vec::new(); - solved_subs.inner().serialize(&mut serialized).unwrap(); - let subs = Subs::deserialize(&serialized); + let (solved_subs, solved_env, problems) = roc_solve::module::run_solve( + &constraints, + actual_constraint, + rigid_variables, + subs, + solve_aliases, + ); - Solved(subs) + if module_id.is_builtin() { + let mut f = std::fs::File::create(&format!("cached_subs/{:?}.dat", module_id)).unwrap(); + let vars_by_symbol: Vec<(Symbol, Variable)> = solved_env.vars_by_symbol().collect(); + solved_subs + .inner() + .serialize(&vars_by_symbol, &mut f) + .unwrap(); + } + + let solved_subs = if true { + solved_subs + } else { + let vars_by_symbol: Vec<(Symbol, Variable)> = solved_env.vars_by_symbol().collect(); + let mut serialized = Vec::new(); + solved_subs + .inner() + .serialize(&vars_by_symbol, &mut serialized) + .unwrap(); + let (subs, vbs) = Subs::deserialize(&serialized); + + dbg!(vbs); + + Solved(subs) + }; + + let exposed_vars_by_symbol: Vec<_> = solved_env + .vars_by_symbol() + .filter(|(k, _)| exposed_symbols.contains(k)) + .collect(); + + (solved_subs, exposed_vars_by_symbol, problems) }; - let exposed_vars_by_symbol: Vec<_> = solved_env - .vars_by_symbol() - .filter(|(k, _)| exposed_symbols.contains(k)) - .collect(); - let mut solved_subs = solved_subs; let (storage_subs, stored_vars_by_symbol) = roc_solve::module::exposed_types_storage_subs(&mut solved_subs, &exposed_vars_by_symbol); diff --git a/compiler/types/src/subs.rs b/compiler/types/src/subs.rs index ff77bc0683..e9e4aac075 100644 --- a/compiler/types/src/subs.rs +++ b/compiler/types/src/subs.rs @@ -69,10 +69,11 @@ struct SubsHeader { field_names: usize, record_fields: usize, variable_slices: usize, + vars_by_symbol: usize, } impl SubsHeader { - fn from_subs(subs: &Subs) -> Self { + fn from_subs(subs: &Subs, vars_by_symbol: usize) -> Self { // TODO what do we do with problems? they should // be reported and then removed from Subs I think debug_assert!(subs.problems.is_empty()); @@ -84,6 +85,7 @@ impl SubsHeader { field_names: subs.field_names.len(), record_fields: subs.record_fields.len(), variable_slices: subs.variable_slices.len(), + vars_by_symbol, } } @@ -108,10 +110,14 @@ fn round_to_multiple_of(value: usize, base: usize) -> usize { } impl Subs { - pub fn serialize(&self, writer: &mut impl std::io::Write) -> std::io::Result { + pub fn serialize( + &self, + vars_by_symbol: &[(Symbol, Variable)], + writer: &mut impl std::io::Write, + ) -> std::io::Result { let mut written = 0; - let header = SubsHeader::from_subs(self).to_array(); + let header = SubsHeader::from_subs(self, vars_by_symbol.len()).to_array(); written += header.len(); writer.write_all(&header)?; @@ -122,6 +128,7 @@ impl Subs { written = Self::serialize_field_names(&self.field_names, writer, written)?; written = Self::serialize_slice(&self.record_fields, writer, written)?; written = Self::serialize_slice(&self.variable_slices, writer, written)?; + written = Self::serialize_slice(vars_by_symbol, writer, written)?; Ok(written) } @@ -195,7 +202,7 @@ impl Subs { Ok(written + padding_bytes + bytes_slice.len()) } - pub fn deserialize(bytes: &[u8]) -> Self { + pub fn deserialize(bytes: &[u8]) -> (Self, Vec<(Symbol, Variable)>) { use std::convert::TryInto; let mut offset = 0; @@ -205,14 +212,21 @@ impl Subs { let (utable, offset) = Self::deserialize_unification_table(bytes, header.utable, offset); + println!("utable"); + let (variables, offset) = Self::deserialize_slice(bytes, header.variables, offset); let (tag_names, offset) = Self::deserialize_slice(bytes, header.tag_names, offset); let (field_names, offset) = Self::deserialize_field_names(bytes, header.field_names, offset); + println!("field names"); let (record_fields, offset) = Self::deserialize_slice(bytes, header.record_fields, offset); - let (variable_slices, _) = Self::deserialize_slice(bytes, header.variable_slices, offset); + let (variable_slices, offset) = + Self::deserialize_slice(bytes, header.variable_slices, offset); + let (vars_by_symbol, _) = Self::deserialize_slice(bytes, header.vars_by_symbol, offset); + println!("all"); + let x = vars_by_symbol.to_vec(); - Self { + let subs = Self { utable, variables: variables.to_vec(), tag_names: tag_names.to_vec(), @@ -221,7 +235,10 @@ impl Subs { variable_slices: variable_slices.to_vec(), tag_name_cache: Default::default(), problems: Default::default(), - } + }; + println!("to_vec"); + + (subs, x) } fn deserialize_unification_table( From 4c37b6f5fbc1e8cda39263cb5c85de1c6723e822 Mon Sep 17 00:00:00 2001 From: Folkert Date: Mon, 21 Mar 2022 19:45:21 +0100 Subject: [PATCH 040/846] properly serialize tag names --- compiler/types/src/subs.rs | 66 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/compiler/types/src/subs.rs b/compiler/types/src/subs.rs index e9e4aac075..cfc7379a16 100644 --- a/compiler/types/src/subs.rs +++ b/compiler/types/src/subs.rs @@ -109,6 +109,12 @@ fn round_to_multiple_of(value: usize, base: usize) -> usize { (value + (base - 1)) / base * base } +enum SerializedTagName { + Global(SubsSlice), + Private(Symbol), + Closure(Symbol), +} + impl Subs { pub fn serialize( &self, @@ -124,7 +130,7 @@ impl Subs { written = Self::serialize_unification_table(&self.utable, writer, written)?; written = Self::serialize_slice(&self.variables, writer, written)?; - written = Self::serialize_slice(&self.tag_names, writer, written)?; + written = Self::serialize_tag_names(&self.tag_names, writer, written)?; written = Self::serialize_field_names(&self.field_names, writer, written)?; written = Self::serialize_slice(&self.record_fields, writer, written)?; written = Self::serialize_slice(&self.variable_slices, writer, written)?; @@ -184,6 +190,36 @@ impl Subs { Self::serialize_slice(&buf, writer, written) } + /// Lowercase can be heap-allocated + fn serialize_tag_names( + tag_names: &[TagName], + writer: &mut impl std::io::Write, + written: usize, + ) -> std::io::Result { + let mut buf: Vec = Vec::new(); + let mut slices: Vec = Vec::new(); + + for tag_name in tag_names { + let serialized = match tag_name { + TagName::Global(uppercase) => { + let slice = SubsSlice::extend_new( + &mut buf, + uppercase.as_str().as_bytes().iter().copied(), + ); + SerializedTagName::Global(slice) + } + TagName::Private(symbol) => SerializedTagName::Private(*symbol), + TagName::Closure(symbol) => SerializedTagName::Closure(*symbol), + }; + + slices.push(serialized); + } + + let written = Self::serialize_slice(&slices, writer, written)?; + + Self::serialize_slice(&buf, writer, written) + } + fn serialize_slice( slice: &[T], writer: &mut impl std::io::Write, @@ -215,7 +251,7 @@ impl Subs { println!("utable"); let (variables, offset) = Self::deserialize_slice(bytes, header.variables, offset); - let (tag_names, offset) = Self::deserialize_slice(bytes, header.tag_names, offset); + let (tag_names, offset) = Self::deserialize_tag_names(bytes, header.tag_names, offset); let (field_names, offset) = Self::deserialize_field_names(bytes, header.field_names, offset); println!("field names"); @@ -300,6 +336,32 @@ impl Subs { (lowercases, offset) } + fn deserialize_tag_names(bytes: &[u8], length: usize, offset: usize) -> (Vec, usize) { + let (slices, mut offset) = + Self::deserialize_slice::(bytes, length, offset); + + let string_slice = &bytes[offset..]; + + let mut tag_names = Vec::with_capacity(length); + for serialized_tag_name in slices { + let tag_name = match serialized_tag_name { + SerializedTagName::Global(subs_slice) => { + let bytes = &string_slice[subs_slice.indices()]; + offset += bytes.len(); + let string = unsafe { std::str::from_utf8_unchecked(bytes) }; + + TagName::Global(string.into()) + } + SerializedTagName::Private(symbol) => TagName::Private(*symbol), + SerializedTagName::Closure(symbol) => TagName::Closure(*symbol), + }; + + tag_names.push(tag_name); + } + + (tag_names, offset) + } + fn deserialize_slice(bytes: &[u8], length: usize, mut offset: usize) -> (&[T], usize) { let alignment = std::mem::align_of::(); let size = std::mem::size_of::(); From dfa5710932293003aadcdce9bc161d40264a28bb Mon Sep 17 00:00:00 2001 From: Folkert Date: Mon, 21 Mar 2022 20:18:18 +0100 Subject: [PATCH 041/846] optimize variable substitution in instantiate_rigids --- compiler/constrain/src/expr.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/constrain/src/expr.rs b/compiler/constrain/src/expr.rs index f467f6fae5..f093113971 100644 --- a/compiler/constrain/src/expr.rs +++ b/compiler/constrain/src/expr.rs @@ -10,7 +10,7 @@ use roc_can::expected::PExpected; use roc_can::expr::Expr::{self, *}; use roc_can::expr::{AccessorData, ClosureData, Field, WhenBranch}; use roc_can::pattern::Pattern; -use roc_collections::all::{HumanIndex, ImMap, MutMap, SendMap}; +use roc_collections::all::{HumanIndex, MutMap, SendMap}; use roc_module::ident::{Lowercase, TagName}; use roc_module::symbol::{ModuleId, Symbol}; use roc_region::all::{Loc, Region}; @@ -1670,14 +1670,14 @@ fn instantiate_rigids( let mut annotation = annotation.clone(); let mut new_rigid_variables: Vec = Vec::new(); - let mut rigid_substitution: ImMap = ImMap::default(); + let mut rigid_substitution: MutMap = MutMap::default(); for named in introduced_vars.named.iter() { use std::collections::hash_map::Entry::*; match ftv.entry(named.name.clone()) { Occupied(occupied) => { let existing_rigid = occupied.get(); - rigid_substitution.insert(named.variable, Type::Variable(*existing_rigid)); + rigid_substitution.insert(named.variable, *existing_rigid); } Vacant(vacant) => { // It's possible to use this rigid in nested defs @@ -1698,7 +1698,7 @@ fn instantiate_rigids( // Instantiate rigid variables if !rigid_substitution.is_empty() { - annotation.substitute(&rigid_substitution); + annotation.substitute_variables(&rigid_substitution); } // TODO investigate when we can skip this. It seems to only be required for correctness From 8248123ecfcc178e2d87243a73276f8e1cd5efc6 Mon Sep 17 00:00:00 2001 From: Folkert Date: Mon, 21 Mar 2022 20:19:44 +0100 Subject: [PATCH 042/846] restore helloZig --- .../hello-world/zig-platform/helloZig.roc | 48 ------------------- 1 file changed, 48 deletions(-) diff --git a/examples/hello-world/zig-platform/helloZig.roc b/examples/hello-world/zig-platform/helloZig.roc index 6a91331c80..6c7223111a 100644 --- a/examples/hello-world/zig-platform/helloZig.roc +++ b/examples/hello-world/zig-platform/helloZig.roc @@ -4,51 +4,3 @@ app "helloZig" provides [ main ] to pf main = "Hello, World!\n" - -Utf8ByteProblem : - [ - InvalidStartByte, - UnexpectedEndOfSequence, - ExpectedContinuation, - OverlongEncoding, - CodepointTooLarge, - EncodesSurrogateHalf, - ] - -Utf8Problem : { byteIndex : Nat, problem : Utf8ByteProblem } - -isEmpty : Str -> Bool -concat : Str, Str -> Str - -joinWith : List Str, Str -> Str -split : Str, Str -> List Str -repeat : Str, Nat -> Str -countGraphemes : Str -> Nat -startsWithCodePt : Str, U32 -> Bool - -toUtf8 : Str -> List U8 - -fromUtf8 : List U8 -> Result Str [ BadUtf8 Utf8ByteProblem Nat ]* -fromUtf8Range : List U8, { start : Nat, count : Nat } -> Result Str [ BadUtf8 Utf8ByteProblem Nat, OutOfBounds ]* - -startsWith : Str, Str -> Bool -endsWith : Str, Str -> Bool - -trim : Str -> Str -trimLeft : Str -> Str -trimRight : Str -> Str - -toDec : Str -> Result Dec [ InvalidNumStr ]* -toF64 : Str -> Result F64 [ InvalidNumStr ]* -toF32 : Str -> Result F32 [ InvalidNumStr ]* -toNat : Str -> Result Nat [ InvalidNumStr ]* -toU128 : Str -> Result U128 [ InvalidNumStr ]* -toI128 : Str -> Result I128 [ InvalidNumStr ]* -toU64 : Str -> Result U64 [ InvalidNumStr ]* -toI64 : Str -> Result I64 [ InvalidNumStr ]* -toU32 : Str -> Result U32 [ InvalidNumStr ]* -toI32 : Str -> Result I32 [ InvalidNumStr ]* -toU16 : Str -> Result U16 [ InvalidNumStr ]* -toI16 : Str -> Result I16 [ InvalidNumStr ]* -toU8 : Str -> Result U8 [ InvalidNumStr ]* -toI8 : Str -> Result I8 [ InvalidNumStr ]* From 95b206ea15b5072c5678c3702561e9cebeb8f0c0 Mon Sep 17 00:00:00 2001 From: Folkert Date: Mon, 21 Mar 2022 21:02:27 +0100 Subject: [PATCH 043/846] use mmap --- compiler/load/src/file.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/compiler/load/src/file.rs b/compiler/load/src/file.rs index 5eeb735622..0f628a96c3 100644 --- a/compiler/load/src/file.rs +++ b/compiler/load/src/file.rs @@ -4479,13 +4479,9 @@ fn run_solve<'a>( use memmap::MmapOptions; use std::fs::File; - // let file = File::open(&format!("cached_subs/{:?}.dat", module_id)).unwrap(); - // let mmap = unsafe { MmapOptions::new().map(&file).unwrap() }; - - let mmap = std::fs::read(&format!("cached_subs/{:?}.dat", module_id)).unwrap(); - println!("started {:?}", module_id); + let file = File::open(&format!("cached_subs/{:?}.dat", module_id)).unwrap(); + let mmap = unsafe { MmapOptions::new().map(&file).unwrap() }; let (subs, vars_by_symbol) = Subs::deserialize(&mmap); - println!("deserialized"); let solved_subs = Solved(subs); let exposed_vars_by_symbol: Vec<_> = vars_by_symbol From dc3841ec102d10c2318f9e5beb4f2894f92e5308 Mon Sep 17 00:00:00 2001 From: Folkert Date: Mon, 21 Mar 2022 21:13:18 +0100 Subject: [PATCH 044/846] cleanup --- compiler/types/src/subs.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/compiler/types/src/subs.rs b/compiler/types/src/subs.rs index cfc7379a16..2ad070116f 100644 --- a/compiler/types/src/subs.rs +++ b/compiler/types/src/subs.rs @@ -248,18 +248,14 @@ impl Subs { let (utable, offset) = Self::deserialize_unification_table(bytes, header.utable, offset); - println!("utable"); - let (variables, offset) = Self::deserialize_slice(bytes, header.variables, offset); let (tag_names, offset) = Self::deserialize_tag_names(bytes, header.tag_names, offset); let (field_names, offset) = Self::deserialize_field_names(bytes, header.field_names, offset); - println!("field names"); let (record_fields, offset) = Self::deserialize_slice(bytes, header.record_fields, offset); let (variable_slices, offset) = Self::deserialize_slice(bytes, header.variable_slices, offset); let (vars_by_symbol, _) = Self::deserialize_slice(bytes, header.vars_by_symbol, offset); - println!("all"); let x = vars_by_symbol.to_vec(); let subs = Self { @@ -272,7 +268,6 @@ impl Subs { tag_name_cache: Default::default(), problems: Default::default(), }; - println!("to_vec"); (subs, x) } From 0b4531425d5fa927ddd441a2cfd94d24470e52cd Mon Sep 17 00:00:00 2001 From: Folkert Date: Tue, 22 Mar 2022 18:39:50 +0100 Subject: [PATCH 045/846] skip constraining for cached modules --- compiler/load/src/file.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/compiler/load/src/file.rs b/compiler/load/src/file.rs index 0f628a96c3..b393bd5095 100644 --- a/compiler/load/src/file.rs +++ b/compiler/load/src/file.rs @@ -4687,8 +4687,11 @@ fn canonicalize_and_constrain<'a>( let mut constraints = Constraints::new(); - let constraint = - constrain_module(&mut constraints, &module_output.declarations, module_id); + let constraint = if module_id.is_builtin() { + roc_can::constraint::Constraint::True + } else { + constrain_module(&mut constraints, &module_output.declarations, module_id) + }; let after = roc_types::types::get_type_clone_count(); From 5ec2c4f1df379084bb38861d06a9ce7bc48b910f Mon Sep 17 00:00:00 2001 From: Folkert Date: Tue, 22 Mar 2022 22:45:19 +0100 Subject: [PATCH 046/846] make IdentStr len() const --- compiler/ident/src/lib.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/compiler/ident/src/lib.rs b/compiler/ident/src/lib.rs index e5f9bc62fa..85342346db 100644 --- a/compiler/ident/src/lib.rs +++ b/compiler/ident/src/lib.rs @@ -30,7 +30,8 @@ impl IdentStr { // Reserve 1 byte for the discriminant const SMALL_STR_BYTES: usize = std::mem::size_of::() - 1; - pub fn len(&self) -> usize { + #[inline(always)] + pub const fn len(&self) -> usize { let bytes = self.length.to_ne_bytes(); let last_byte = bytes[mem::size_of::() - 1]; @@ -55,11 +56,11 @@ impl IdentStr { } } - pub fn is_empty(&self) -> bool { + pub const fn is_empty(&self) -> bool { self.length == 0 } - pub fn is_small_str(&self) -> bool { + pub const fn is_small_str(&self) -> bool { let bytes = self.length.to_ne_bytes(); let last_byte = bytes[mem::size_of::() - 1]; From d82d1ac2ce7d2c0446020a616230d17fd402e53a Mon Sep 17 00:00:00 2001 From: Folkert Date: Tue, 22 Mar 2022 22:45:39 +0100 Subject: [PATCH 047/846] temporary get_project_root to import builtins --- compiler/load/src/file.rs | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/compiler/load/src/file.rs b/compiler/load/src/file.rs index def794a6e3..9f66b470ee 100644 --- a/compiler/load/src/file.rs +++ b/compiler/load/src/file.rs @@ -4472,7 +4472,10 @@ fn run_solve<'a>( use memmap::MmapOptions; use std::fs::File; - let file = File::open(&format!("cached_subs/{:?}.dat", module_id)).unwrap(); + let root = get_project_root().unwrap(); + let path = format!("{}/cached_subs/{:?}.dat", root.to_str().unwrap(), module_id); + eprintln!("{:?}: {}", module_id, &path); + let file = File::open(&path).unwrap(); let mmap = unsafe { MmapOptions::new().map(&file).unwrap() }; let (subs, vars_by_symbol) = Subs::deserialize(&mmap); let solved_subs = Solved(subs); @@ -4556,6 +4559,34 @@ fn run_solve<'a>( } } +/// Get the project root (relative to closest Cargo.lock file) +/// ```rust +/// match project_root::get_project_root() { +/// Ok(p) => println!("Current project root is {:?}", p), +/// Err(e) => println!("Error obtaining project root {:?}", e) +/// }; +/// ``` +pub fn get_project_root() -> io::Result { + use std::fs::read_dir; + use std::io::ErrorKind; + + let path = env::current_dir()?; + let path_ancestors = path.as_path().ancestors(); + + for p in path_ancestors { + let has_cargo = read_dir(p)? + .into_iter() + .any(|p| p.unwrap().file_name() == *"Cargo.lock"); + if has_cargo { + return Ok(PathBuf::from(p)); + } + } + Err(io::Error::new( + ErrorKind::NotFound, + "Ran out of places to find Cargo.toml", + )) +} + fn unspace<'a, T: Copy>(arena: &'a Bump, items: &[Loc>]) -> &'a [Loc] { bumpalo::collections::Vec::from_iter_in( items From 615aaa9a77b017e1bf6b65a8b85ed54ad8a92aa4 Mon Sep 17 00:00:00 2001 From: Folkert Date: Tue, 22 Mar 2022 23:12:50 +0100 Subject: [PATCH 048/846] remove unused number min/max functions --- compiler/can/src/builtins.rs | 130 ----------------------------------- 1 file changed, 130 deletions(-) diff --git a/compiler/can/src/builtins.rs b/compiler/can/src/builtins.rs index af80221154..54552ac4df 100644 --- a/compiler/can/src/builtins.rs +++ b/compiler/can/src/builtins.rs @@ -1435,106 +1435,6 @@ fn num_int_cast(symbol: Symbol, var_store: &mut VarStore) -> Def { lowlevel_1(symbol, LowLevel::NumIntCast, var_store) } -/// Num.minI8: I8 -fn num_min_i8(symbol: Symbol, var_store: &mut VarStore) -> Def { - int_min_or_max::(symbol, var_store, i8::MIN, IntBound::Exact(IntWidth::I8)) -} - -/// Num.maxI8: I8 -fn num_max_i8(symbol: Symbol, var_store: &mut VarStore) -> Def { - int_min_or_max::(symbol, var_store, i8::MAX, IntBound::Exact(IntWidth::I8)) -} - -/// Num.minU8: U8 -fn num_min_u8(symbol: Symbol, var_store: &mut VarStore) -> Def { - int_min_or_max::(symbol, var_store, u8::MIN, IntBound::Exact(IntWidth::U8)) -} - -/// Num.maxU8: U8 -fn num_max_u8(symbol: Symbol, var_store: &mut VarStore) -> Def { - int_min_or_max::(symbol, var_store, u8::MAX, IntBound::Exact(IntWidth::U8)) -} - -/// Num.minI16: I16 -fn num_min_i16(symbol: Symbol, var_store: &mut VarStore) -> Def { - int_min_or_max::(symbol, var_store, i16::MIN, IntBound::Exact(IntWidth::I16)) -} - -/// Num.maxI16: I16 -fn num_max_i16(symbol: Symbol, var_store: &mut VarStore) -> Def { - int_min_or_max::(symbol, var_store, i16::MAX, IntBound::Exact(IntWidth::I16)) -} - -/// Num.minU16: U16 -fn num_min_u16(symbol: Symbol, var_store: &mut VarStore) -> Def { - int_min_or_max::(symbol, var_store, u16::MIN, IntBound::Exact(IntWidth::U16)) -} - -/// Num.maxU16: U16 -fn num_max_u16(symbol: Symbol, var_store: &mut VarStore) -> Def { - int_min_or_max::(symbol, var_store, u16::MAX, IntBound::Exact(IntWidth::U16)) -} - -/// Num.minI32: I32 -fn num_min_i32(symbol: Symbol, var_store: &mut VarStore) -> Def { - int_min_or_max::(symbol, var_store, i32::MIN, IntBound::Exact(IntWidth::I32)) -} - -/// Num.maxI32: I32 -fn num_max_i32(symbol: Symbol, var_store: &mut VarStore) -> Def { - int_min_or_max::(symbol, var_store, i32::MAX, IntBound::Exact(IntWidth::I32)) -} - -/// Num.minU32: U32 -fn num_min_u32(symbol: Symbol, var_store: &mut VarStore) -> Def { - int_min_or_max::(symbol, var_store, u32::MIN, IntBound::Exact(IntWidth::U32)) -} - -/// Num.maxU32: U32 -fn num_max_u32(symbol: Symbol, var_store: &mut VarStore) -> Def { - int_min_or_max::(symbol, var_store, u32::MAX, IntBound::Exact(IntWidth::U32)) -} - -/// Num.minI64: I64 -fn num_min_i64(symbol: Symbol, var_store: &mut VarStore) -> Def { - int_min_or_max::(symbol, var_store, i64::MIN, IntBound::Exact(IntWidth::I64)) -} - -/// Num.maxI64: I64 -fn num_max_i64(symbol: Symbol, var_store: &mut VarStore) -> Def { - int_min_or_max::(symbol, var_store, i64::MAX, IntBound::Exact(IntWidth::I64)) -} - -/// Num.minU64: U64 -fn num_min_u64(symbol: Symbol, var_store: &mut VarStore) -> Def { - int_min_or_max::(symbol, var_store, u64::MIN, IntBound::Exact(IntWidth::U64)) -} - -/// Num.maxU64: U64 -fn num_max_u64(symbol: Symbol, var_store: &mut VarStore) -> Def { - int_min_or_max::(symbol, var_store, u64::MAX, IntBound::Exact(IntWidth::U64)) -} - -/// Num.minI128: I128 -fn num_min_i128(symbol: Symbol, var_store: &mut VarStore) -> Def { - int_min_or_max::( - symbol, - var_store, - i128::MIN, - IntBound::Exact(IntWidth::I128), - ) -} - -/// Num.maxI128: I128 -fn num_max_i128(symbol: Symbol, var_store: &mut VarStore) -> Def { - int_min_or_max::( - symbol, - var_store, - i128::MAX, - IntBound::Exact(IntWidth::I128), - ) -} - /// List.isEmpty : List * -> Bool fn list_is_empty(symbol: Symbol, var_store: &mut VarStore) -> Def { let list_var = var_store.fresh(); @@ -5363,36 +5263,6 @@ fn defn_help( }) } -#[inline(always)] -fn int_min_or_max(symbol: Symbol, var_store: &mut VarStore, i: I128, bound: IntBound) -> Def -where - I128: Into, -{ - let int_var = var_store.fresh(); - let int_precision_var = var_store.fresh(); - let body = int::(int_var, int_precision_var, i, bound); - - let std = roc_builtins::std::types(); - let solved = std.get(&symbol).unwrap(); - let mut free_vars = roc_types::solved_types::FreeVars::default(); - let signature = roc_types::solved_types::to_type(&solved.0, &mut free_vars, var_store); - - let annotation = crate::def::Annotation { - signature, - introduced_variables: Default::default(), - region: Region::zero(), - aliases: Default::default(), - }; - - Def { - annotation: Some(annotation), - expr_var: int_var, - loc_expr: Loc::at_zero(body), - loc_pattern: Loc::at_zero(Pattern::Identifier(symbol)), - pattern_vars: SendMap::default(), - } -} - fn num_no_bound() -> NumericBound { NumericBound::None } From ac19213fa4656f4eaa3de310f91de2557977c9cb Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 23 Mar 2022 14:49:38 +0100 Subject: [PATCH 049/846] stop using builtins/std --- compiler/load/src/file.rs | 18 ++++++++++++------ compiler/solve/tests/solve_expr.rs | 6 +++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/compiler/load/src/file.rs b/compiler/load/src/file.rs index 9f66b470ee..458fc9e33f 100644 --- a/compiler/load/src/file.rs +++ b/compiler/load/src/file.rs @@ -3307,7 +3307,7 @@ fn load_module<'a>( isPositive : Num a -> Bool isNegative : Num a -> Bool - toFloat : Num a -> Float b + toFloat : Num * -> Float * abs : Num a -> Num a neg : Num a -> Num a @@ -3343,9 +3343,9 @@ fn load_module<'a>( shiftRightBy : Int a, Int a -> Int a shiftRightZfBy : Int a, Int a -> Int a - round : Float a -> Int b - floor : Float a -> Int b - ceiling : Float a -> Int b + round : Float * -> Int * + floor : Float * -> Int * + ceiling : Float * -> Int * pow : Float a, Float a -> Float a powInt : Int a, Int a -> Int a @@ -4391,8 +4391,9 @@ fn run_solve<'a>( // We have more constraining work to do now, so we'll add it to our timings. let constrain_start = SystemTime::now(); - let (mut rigid_vars, mut def_types) = - constrain_builtin_imports(borrow_stdlib(), imported_builtins, &mut var_store); + let mut rigid_vars = Vec::new(); + let mut def_types = Vec::new(); + // let () = constrain_builtin_imports(borrow_stdlib(), imported_builtins, &mut var_store); let constrain_end = SystemTime::now(); @@ -4409,6 +4410,11 @@ fn run_solve<'a>( let mut import_variables = Vec::new(); + // TODO this is suspicious + if !module_id.is_builtin() { + exposed_for_module.imported_values.extend(imported_builtins) + } + for symbol in exposed_for_module.imported_values { let module_id = symbol.module_id(); match exposed_for_module.exposed_by_module.get_mut(&module_id) { diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index 8743cd8801..390479bc71 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -3251,7 +3251,7 @@ mod solve_expr { Dict.insert "# ), - "Dict a b, a, b -> Dict a b", + "Dict k v, k, v -> Dict k v", ); } @@ -3807,7 +3807,7 @@ mod solve_expr { List.walkBackwards "# ), - "List a, b, (b, a -> b) -> b", + "List elem, state, (state, elem -> state) -> state", ); } @@ -3883,7 +3883,7 @@ mod solve_expr { List.takeLast "# ), - "List a, Nat -> List a", + "List elem, Nat -> List elem", ); } From 6353ee095f5175e9c8d773d2f52893b4491c2870 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 23 Mar 2022 17:43:30 +0100 Subject: [PATCH 050/846] use stdlib source from .roc files --- compiler/load_internal/src/file.rs | 438 +---------------------------- 1 file changed, 9 insertions(+), 429 deletions(-) diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index 458fc9e33f..e9c71df149 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -4,6 +4,7 @@ use crossbeam::channel::{bounded, Sender}; use crossbeam::deque::{Injector, Stealer, Worker}; use crossbeam::thread; use parking_lot::Mutex; +use roc_builtins::standard_library::module_source; use roc_builtins::std::borrow_stdlib; use roc_can::constraint::{Constraint as ConstraintSoa, Constraints}; use roc_can::def::Declaration; @@ -2518,45 +2519,7 @@ fn load_module<'a>( }, }; - let src_bytes = r#" - Result ok err : [ Ok ok, Err err ] - - isOk : Result ok err -> Bool - isOk = \result -> - when result is - Ok _ -> True - Err _ -> False - - isErr : Result ok err -> Bool - isErr = \result -> - when result is - Ok _ -> False - Err _ -> True - - withDefault : Result ok err, ok -> ok - withDefault = \result, default -> - when result is - Ok value -> value - Err _ -> default - - map : Result a err, (a -> b) -> Result b err - map = \result, transform -> - when result is - Ok v -> Ok (transform v) - Err e -> Err e - - mapErr : Result ok a, (a -> b) -> Result ok b - mapErr = \result, transform -> - when result is - Ok v -> Ok v - Err e -> Err (transform e) - - after : Result a err, (a -> Result b err) -> Result b err - after = \result, transform -> - when result is - Ok v -> transform v - Err e -> Err e - "#; + let src_bytes = module_source(ModuleId::RESULT); let parse_state = roc_parse::state::State::new(src_bytes.as_bytes()); @@ -2658,79 +2621,7 @@ fn load_module<'a>( }, }; - let src_bytes = r#" - isEmpty : List a -> Bool - isEmpty = \list -> - List.len list == 0 - - get : List a, Nat -> Result a [ OutOfBounds ]* - set : List a, Nat, a -> List a - replace : List a, Nat, a -> { list : List a, value : a } - append : List a, a -> List a - prepend : List a, a -> List a - len : List a -> Nat - concat : List a, List a -> List a - last : List a -> Result a [ ListWasEmpty ]* - single : a -> List a - repeat : a, Nat -> List a - reverse : List a -> List a - join : List (List a) -> List a - contains : List a, a -> Bool - walk : List elem, state, (state, elem -> state) -> state - walkBackwards : List elem, state, (state, elem -> state) -> state - walkUntil : List elem, state, (state, elem -> [ Continue state, Stop state ]) -> state - - sum : List (Num a) -> Num a - sum = \list -> - List.walk list 0 Num.add - - product : List (Num a) -> Num a - product = \list -> - List.walk list 1 Num.mul - - any : List a, (a -> Bool) -> Bool - all : List a, (a -> Bool) -> Bool - - keepIf : List a, (a -> Bool) -> List a - dropIf : List a, (a -> Bool) -> List a - - keepOks : List before, (before -> Result after *) -> List after - keepErrs: List before, (before -> Result * after) -> List after - map : List a, (a -> b) -> List b - map2 : List a, List b, (a, b -> c) -> List c - map3 : List a, List b, List c, (a, b, c -> d) -> List d - map4 : List a, List b, List c, List d, (a, b, c, d -> e) -> List e - mapWithIndex : List a, (a -> b) -> List b - range : Int a, Int a -> List (Int a) - sortWith : List a, (a, a -> [ LT, EQ, GT ] ) -> List a - sortAsc : List (Num a) -> List (Num a) - sortAsc = \list -> List.sortWith list Num.compare - - sortDesc : List (Num a) -> List (Num a) - sortDesc = \list -> List.sortWith list (\a, b -> Num.compare b a) - - swap : List a, Nat, Nat -> List a - - first : List a -> Result a [ ListWasEmpty ]* - - dropFirst : List elem -> List elem - dropLast : List elem -> List elem - - takeFirst : List elem, Nat -> List elem - takeLast : List elem, Nat -> List elem - - drop : List elem, Nat -> List elem - dropAt : List elem, Nat -> List elem - - min : List (Num a) -> Result (Num a) [ ListWasEmpty ]* - max : List (Num a) -> Result (Num a) [ ListWasEmpty ]* - - joinMap : List a, (a -> List b) -> List b - find : List elem, (elem -> Bool) -> Result elem [ NotFound ]* - sublist : List elem, { start : Nat, len : Nat } -> List elem - intersperse : List elem, elem -> List elem - split : List elem, Nat -> { before: List elem, others: List elem } - "#; + let src_bytes = module_source(ModuleId::LIST); let parse_state = roc_parse::state::State::new(src_bytes.as_bytes()); @@ -2836,58 +2727,7 @@ fn load_module<'a>( }, }; - let src_bytes = r#" - Utf8ByteProblem : - [ - InvalidStartByte, - UnexpectedEndOfSequence, - ExpectedContinuation, - OverlongEncoding, - CodepointTooLarge, - EncodesSurrogateHalf, - ] - - Utf8Problem : { byteIndex : Nat, problem : Utf8ByteProblem } - - isEmpty : Str -> Bool - concat : Str, Str -> Str - - joinWith : List Str, Str -> Str - split : Str, Str -> List Str - repeat : Str, Nat -> Str - countGraphemes : Str -> Nat - startsWithCodePt : Str, U32 -> Bool - - toUtf8 : Str -> List U8 - - # fromUtf8 : List U8 -> Result Str [ BadUtf8 Utf8Problem ]* - # fromUtf8Range : List U8 -> Result Str [ BadUtf8 Utf8Problem Nat, OutOfBounds ]* - - fromUtf8 : List U8 -> Result Str [ BadUtf8 Utf8ByteProblem Nat ]* - fromUtf8Range : List U8, { start : Nat, count : Nat } -> Result Str [ BadUtf8 Utf8ByteProblem Nat, OutOfBounds ]* - - startsWith : Str, Str -> Bool - endsWith : Str, Str -> Bool - - trim : Str -> Str - trimLeft : Str -> Str - trimRight : Str -> Str - - toDec : Str -> Result Dec [ InvalidNumStr ]* - toF64 : Str -> Result F64 [ InvalidNumStr ]* - toF32 : Str -> Result F32 [ InvalidNumStr ]* - toNat : Str -> Result Nat [ InvalidNumStr ]* - toU128 : Str -> Result U128 [ InvalidNumStr ]* - toI128 : Str -> Result I128 [ InvalidNumStr ]* - toU64 : Str -> Result U64 [ InvalidNumStr ]* - toI64 : Str -> Result I64 [ InvalidNumStr ]* - toU32 : Str -> Result U32 [ InvalidNumStr ]* - toI32 : Str -> Result I32 [ InvalidNumStr ]* - toU16 : Str -> Result U16 [ InvalidNumStr ]* - toI16 : Str -> Result I16 [ InvalidNumStr ]* - toU8 : Str -> Result U8 [ InvalidNumStr ]* - toI8 : Str -> Result I8 [ InvalidNumStr ]* - "#; + let src_bytes = module_source(ModuleId::STR); let parse_state = roc_parse::state::State::new(src_bytes.as_bytes()); @@ -2956,21 +2796,7 @@ fn load_module<'a>( }, }; - let src_bytes = r#" - empty : Dict k v - single : k, v -> Dict k v - get : Dict k v, k -> Result v [ KeyNotFound ]* - walk : Dict k v, state, (state, k, v -> state) -> state - insert : Dict k v, k, v -> Dict k v - len : Dict k v -> Nat - remove : Dict k v, k -> Dict k v - contains : Dict k v, k -> Bool - keys : Dict k v -> List k - values : Dict k v -> List v - union : Dict k v, Dict k v -> Dict k v - intersection : Dict k v, Dict k v -> Dict k v - difference : Dict k v, Dict k v -> Dict k v - "#; + let src_bytes = module_source(ModuleId::DICT); let parse_state = roc_parse::state::State::new(src_bytes.as_bytes()); @@ -3042,28 +2868,7 @@ fn load_module<'a>( }, }; - let src_bytes = r#" - empty : Set k - single : k -> Set k - insert : Set k, k -> Set k - len : Set k -> Nat - remove : Set k, k -> Set k - contains : Set k, k -> Bool - - # toList = \set -> Dict.keys (toDict set) - toList : Set k -> List k - fromList : List k -> Set k - - union : Set k, Set k -> Set k - intersection : Set k, Set k -> Set k - difference : Set k, Set k -> Set k - - toDict : Set k -> Dict k {} - - walk : Set k, state, (state, k -> state) -> state - walk = \set, state, step -> - Dict.walk (toDict set) state (\s, k, _ -> step s k) - "#; + let src_bytes = module_source(ModuleId::SET); let parse_state = roc_parse::state::State::new(src_bytes.as_bytes()); @@ -3239,211 +3044,7 @@ fn load_module<'a>( }, }; - let src_bytes = r#" - Num range : [ @Num range ] - Int range : Num (Integer range) - Float range : Num (FloatingPoint range) - - Signed128 : [ @Signed128 ] - Signed64 : [ @Signed64 ] - Signed32 : [ @Signed32 ] - Signed16 : [ @Signed16 ] - Signed8 : [ @Signed8 ] - - Unsigned128 : [ @Unsigned128 ] - Unsigned64 : [ @Unsigned64 ] - Unsigned32 : [ @Unsigned32 ] - Unsigned16 : [ @Unsigned16 ] - Unsigned8 : [ @Unsigned8 ] - - Natural : [ @Natural ] - - Integer range : [ @Integer range ] - - I128 : Num (Integer Signed128) - I64 : Num (Integer Signed64) - I32 : Num (Integer Signed32) - I16 : Num (Integer Signed16) - I8 : Int Signed8 - - U128 : Num (Integer Unsigned128) - U64 : Num (Integer Unsigned64) - U32 : Num (Integer Unsigned32) - U16 : Num (Integer Unsigned16) - U8 : Num (Integer Unsigned8) - - Nat : Num (Integer Natural) - - Decimal : [ @Decimal ] - Binary64 : [ @Binary64 ] - Binary32 : [ @Binary32 ] - - FloatingPoint range : [ @FloatingPoint range ] - - F64 : Num (FloatingPoint Binary64) - F32 : Num (FloatingPoint Binary32) - Dec : Num (FloatingPoint Decimal) - - # ------- Functions - - toStr : Num * -> Str - intCast : Int a -> Int b - - bytesToU16 : List U8, Nat -> Result U16 [ OutOfBounds ] - bytesToU32 : List U8, Nat -> Result U32 [ OutOfBounds ] - - compare : Num a, Num a -> [ LT, EQ, GT ] - - isLt : Num a, Num a -> Bool - isGt : Num a, Num a -> Bool - isLte : Num a, Num a -> Bool - isGte : Num a, Num a -> Bool - - isZero : Num a -> Bool - - isEven : Int a -> Bool - isOdd : Int a -> Bool - - isPositive : Num a -> Bool - isNegative : Num a -> Bool - - toFloat : Num * -> Float * - - abs : Num a -> Num a - neg : Num a -> Num a - - add : Num a, Num a -> Num a - sub : Num a, Num a -> Num a - mul : Num a, Num a -> Num a - - sin : Float a -> Float a - cos : Float a -> Float a - tan : Float a -> Float a - - asin : Float a -> Float a - acos : Float a -> Float a - atan : Float a -> Float a - - sqrt : Float a -> Result (Float a) [ SqrtOfNegative ]* - log : Float a -> Result (Float a) [ LogNeedsPositive ]* - div : Float a, Float a -> Result (Float a) [ DivByZero ]* - - divCeil: Int a, Int a -> Result (Int a) [ DivByZero ]* - divFloor: Int a, Int a -> Result (Int a) [ DivByZero ]* - # mod : Float a, Float a -> Result (Float a) [ DivByZero ]* - - rem : Int a, Int a -> Result (Int a) [ DivByZero ]* - # mod : Int a, Int a -> Result (Int a) [ DivByZero ]* - isMultipleOf : Int a, Int a -> Bool - - bitwiseAnd : Int a, Int a -> Int a - bitwiseXor : Int a, Int a -> Int a - bitwiseOr : Int a, Int a -> Int a - shiftLeftBy : Int a, Int a -> Int a - shiftRightBy : Int a, Int a -> Int a - shiftRightZfBy : Int a, Int a -> Int a - - round : Float * -> Int * - floor : Float * -> Int * - ceiling : Float * -> Int * - - pow : Float a, Float a -> Float a - powInt : Int a, Int a -> Int a - - addWrap : Int range, Int range -> Int range - addSaturated : Num a, Num a -> Num a - addChecked : Num a, Num a -> Result (Num a) [ Overflow ]* - - subWrap : Int range, Int range -> Int range - subSaturated : Num a, Num a -> Num a - subChecked : Num a, Num a -> Result (Num a) [ Overflow ]* - - mulWrap : Int range, Int range -> Int range - # mulSaturated : Num a, Num a -> Num a - mulChecked : Num a, Num a -> Result (Num a) [ Overflow ]* - - minI8 : I8 - minI8 = -128i8 - - maxI8 : I8 - maxI8 = 127i8 - - minU8 : U8 - minU8 = 0u8 - - maxU8 : U8 - maxU8 = 255u8 - - minI16 : I16 - minI16 = -32768i16 - - maxI16 : I16 - maxI16 = 32767i16 - - minU16 : U16 - minU16 = 0u16 - - maxU16 : U16 - maxU16 = 65535u16 - - minI32 : I32 - minI32 = -2147483648 - - maxI32 : I32 - maxI32 = 2147483647 - - minU32 : U32 - minU32 = 0 - - maxU32 : U32 - maxU32 = 4294967295 - - minI64 : I64 - minI64 = -9223372036854775808 - - maxI64 : I64 - maxI64 = 9223372036854775807 - - minU64 : U64 - minU64 = 0 - - maxU64 : U64 - maxU64 = 18446744073709551615 - - minI128 : I128 - minI128 = -170141183460469231731687303715884105728 - - maxI128 : I128 - maxI128 = 170141183460469231731687303715884105727 - - minU128 : U128 - minU128 = 0 - - maxU128 : U128 - maxU128 = 0340282366920938463463374607431768211455 - - toI8 : Int * -> I8 - toI16 : Int * -> I16 - toI32 : Int * -> I32 - toI64 : Int * -> I64 - toI128 : Int * -> I128 - toU8 : Int * -> U8 - toU16 : Int * -> U16 - toU32 : Int * -> U32 - toU64 : Int * -> U64 - toU128 : Int * -> U128 - - toI8Checked : Int * -> Result I8 [ OutOfBounds ]* - toI16Checked : Int * -> Result I16 [ OutOfBounds ]* - toI32Checked : Int * -> Result I32 [ OutOfBounds ]* - toI64Checked : Int * -> Result I64 [ OutOfBounds ]* - toI128Checked : Int * -> Result I128 [ OutOfBounds ]* - toU8Checked : Int * -> Result U8 [ OutOfBounds ]* - toU16Checked : Int * -> Result U16 [ OutOfBounds ]* - toU32Checked : Int * -> Result U32 [ OutOfBounds ]* - toU64Checked : Int * -> Result U64 [ OutOfBounds ]* - toU128Checked : Int * -> Result U128 [ OutOfBounds ]* - "#; + let src_bytes = module_source(ModuleId::NUM); let parse_state = roc_parse::state::State::new(src_bytes.as_bytes()); @@ -3486,18 +3087,7 @@ fn load_module<'a>( }, }; - let src_bytes = r#" - Bool : [ True, False ] - - and : Bool, Bool -> Bool - or : Bool, Bool -> Bool - # xor : Bool, Bool -> Bool # currently unimplemented - - not : Bool -> Bool - - isEq : a, a -> Bool - isNotEq : a, a -> Bool - "#; + let src_bytes = module_source(ModuleId::BOOL); let parse_state = roc_parse::state::State::new(src_bytes.as_bytes()); @@ -3536,17 +3126,7 @@ fn load_module<'a>( }, }; - let src_bytes = r#" - box : a -> Box a - unbox : Box a -> a - - map : Box a, (a -> b) -> Box b - map = \boxed, transform = - boxed - |> Box.unbox - |> transform - |> Box.box - "#; + let src_bytes = module_source(ModuleId::BOX); let parse_state = roc_parse::state::State::new(src_bytes.as_bytes()); From 459c411cd232ece9de40b96be7cd727c132299d5 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sat, 26 Mar 2022 13:01:49 -0400 Subject: [PATCH 051/846] Reproduce gui example segfault --- examples/gui/Hello.roc | 8 ++------ examples/gui/platform/Package-Config.roc | 2 +- examples/gui/platform/src/lib.rs | 18 ++++++++++-------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/examples/gui/Hello.roc b/examples/gui/Hello.roc index 46656498de..5699fd38b4 100644 --- a/examples/gui/Hello.roc +++ b/examples/gui/Hello.roc @@ -5,16 +5,13 @@ app "hello-gui" program = { render } -render = \state -> +render = \title -> div0 = \numerator, denominator -> (numerator / denominator) |> Result.withDefault 0 rgba = \r, g, b, a -> { r: div0 r 255, g: div0 g 255, b: div0 b 255, a } styles = { bgColor: rgba 100 50 50 1, borderColor: rgba 10 20 30 1, borderWidth: 10, textColor: rgba 220 220 250 1 } - height = Num.toStr state.height - width = Num.toStr state.width - Col [ Row @@ -25,6 +22,5 @@ render = \state -> ], Button (Text "Mid Left ") { styles & bgColor: rgba 150 100 100 1 }, Button (Text "Bottom Left") { styles & bgColor: rgba 150 50 50 1 }, - Button (Text "height: \(height)") { styles & bgColor: rgba 50 150 50 1 }, - Button (Text "width: \(width)") { styles & bgColor: rgba 50 100 50 1 }, + Button (Text "Title:") { styles & bgColor: rgba 50 100 50 1 }, ] diff --git a/examples/gui/platform/Package-Config.roc b/examples/gui/platform/Package-Config.roc index 8ecb3d14b0..33b1dbc0c3 100644 --- a/examples/gui/platform/Package-Config.roc +++ b/examples/gui/platform/Package-Config.roc @@ -11,7 +11,7 @@ ButtonStyles : { bgColor : Rgba, borderColor : Rgba, borderWidth : F32, textColo Elem : [ Button Elem ButtonStyles, Col (List Elem), Row (List Elem), Text Str ] -State : { width : U32, height : U32 } # TODO change from U32 to F32 once Num.toStr supports floats +State : { width : Str, height : Str } # TODO change from U32 to F32 once Num.toStr supports floats Program state : { render : state -> Elem } diff --git a/examples/gui/platform/src/lib.rs b/examples/gui/platform/src/lib.rs index 7e1634b34f..059dbe7fc4 100644 --- a/examples/gui/platform/src/lib.rs +++ b/examples/gui/platform/src/lib.rs @@ -6,10 +6,11 @@ mod roc; use crate::roc::RocElem; use core::alloc::Layout; use core::mem::MaybeUninit; +use roc_std::{ReferenceCount, RocList, RocStr}; extern "C" { #[link_name = "roc__programForHost_1_exposed_generic"] - fn roc_program(args: State, output: *mut u8) -> (); + fn roc_program(args: RocStr, output: *mut u8) -> (); #[link_name = "roc__programForHost_size"] fn roc_program_size() -> i64; @@ -27,24 +28,25 @@ extern "C" { #[repr(C)] struct State { - height: u32, - width: u32, + height: RocStr, + width: RocStr, } #[no_mangle] pub extern "C" fn rust_main() -> i32 { let size = unsafe { roc_program_size() } as usize; let layout = Layout::array::(size).unwrap(); - let state = State { - height: 42, - width: 123, - }; + let title: RocStr = "t1tl3".into(); + // let state = State { + // height: "big H".into(), + // width: "the W".into(), + // }; let root_elem = unsafe { // TODO allocate on the stack if it's under a certain size let buffer = std::alloc::alloc(layout); - roc_program(state, buffer); + roc_program(title, buffer); // Call the program's render function let result = call_the_closure(buffer); From 4882fb4a06de43ce67eb20541715dfcebf10bde2 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sat, 26 Mar 2022 13:01:54 -0400 Subject: [PATCH 052/846] Revert "Reproduce gui example segfault" This reverts commit 459c411cd232ece9de40b96be7cd727c132299d5. --- examples/gui/Hello.roc | 8 ++++++-- examples/gui/platform/Package-Config.roc | 2 +- examples/gui/platform/src/lib.rs | 18 ++++++++---------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/examples/gui/Hello.roc b/examples/gui/Hello.roc index 5699fd38b4..46656498de 100644 --- a/examples/gui/Hello.roc +++ b/examples/gui/Hello.roc @@ -5,13 +5,16 @@ app "hello-gui" program = { render } -render = \title -> +render = \state -> div0 = \numerator, denominator -> (numerator / denominator) |> Result.withDefault 0 rgba = \r, g, b, a -> { r: div0 r 255, g: div0 g 255, b: div0 b 255, a } styles = { bgColor: rgba 100 50 50 1, borderColor: rgba 10 20 30 1, borderWidth: 10, textColor: rgba 220 220 250 1 } + height = Num.toStr state.height + width = Num.toStr state.width + Col [ Row @@ -22,5 +25,6 @@ render = \title -> ], Button (Text "Mid Left ") { styles & bgColor: rgba 150 100 100 1 }, Button (Text "Bottom Left") { styles & bgColor: rgba 150 50 50 1 }, - Button (Text "Title:") { styles & bgColor: rgba 50 100 50 1 }, + Button (Text "height: \(height)") { styles & bgColor: rgba 50 150 50 1 }, + Button (Text "width: \(width)") { styles & bgColor: rgba 50 100 50 1 }, ] diff --git a/examples/gui/platform/Package-Config.roc b/examples/gui/platform/Package-Config.roc index 33b1dbc0c3..8ecb3d14b0 100644 --- a/examples/gui/platform/Package-Config.roc +++ b/examples/gui/platform/Package-Config.roc @@ -11,7 +11,7 @@ ButtonStyles : { bgColor : Rgba, borderColor : Rgba, borderWidth : F32, textColo Elem : [ Button Elem ButtonStyles, Col (List Elem), Row (List Elem), Text Str ] -State : { width : Str, height : Str } # TODO change from U32 to F32 once Num.toStr supports floats +State : { width : U32, height : U32 } # TODO change from U32 to F32 once Num.toStr supports floats Program state : { render : state -> Elem } diff --git a/examples/gui/platform/src/lib.rs b/examples/gui/platform/src/lib.rs index 059dbe7fc4..7e1634b34f 100644 --- a/examples/gui/platform/src/lib.rs +++ b/examples/gui/platform/src/lib.rs @@ -6,11 +6,10 @@ mod roc; use crate::roc::RocElem; use core::alloc::Layout; use core::mem::MaybeUninit; -use roc_std::{ReferenceCount, RocList, RocStr}; extern "C" { #[link_name = "roc__programForHost_1_exposed_generic"] - fn roc_program(args: RocStr, output: *mut u8) -> (); + fn roc_program(args: State, output: *mut u8) -> (); #[link_name = "roc__programForHost_size"] fn roc_program_size() -> i64; @@ -28,25 +27,24 @@ extern "C" { #[repr(C)] struct State { - height: RocStr, - width: RocStr, + height: u32, + width: u32, } #[no_mangle] pub extern "C" fn rust_main() -> i32 { let size = unsafe { roc_program_size() } as usize; let layout = Layout::array::(size).unwrap(); - let title: RocStr = "t1tl3".into(); - // let state = State { - // height: "big H".into(), - // width: "the W".into(), - // }; + let state = State { + height: 42, + width: 123, + }; let root_elem = unsafe { // TODO allocate on the stack if it's under a certain size let buffer = std::alloc::alloc(layout); - roc_program(title, buffer); + roc_program(state, buffer); // Call the program's render function let result = call_the_closure(buffer); From 2ffb74e5fa071f054dc68d4317bff4fb0887911a Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sat, 26 Mar 2022 13:04:43 -0400 Subject: [PATCH 053/846] Reproduce U32s being wrong --- examples/gui/Hello.roc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/gui/Hello.roc b/examples/gui/Hello.roc index 46656498de..5adcf7a415 100644 --- a/examples/gui/Hello.roc +++ b/examples/gui/Hello.roc @@ -12,8 +12,8 @@ render = \state -> styles = { bgColor: rgba 100 50 50 1, borderColor: rgba 10 20 30 1, borderWidth: 10, textColor: rgba 220 220 250 1 } - height = Num.toStr state.height - width = Num.toStr state.width + height = if state.height == 42 then "correct!" else if state.height == 0 then "zero" else "incorrect" + width = if state.width == 123 then "Correct!" else if state.width == 0 then "zero" else "Incorrect" Col [ From 283d92e3cd3d56a606a9512abd183f2e4f08152d Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sat, 26 Mar 2022 16:14:05 -0700 Subject: [PATCH 054/846] Fix gui example host --- examples/gui/platform/src/lib.rs | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/examples/gui/platform/src/lib.rs b/examples/gui/platform/src/lib.rs index 7e1634b34f..f64bd29db3 100644 --- a/examples/gui/platform/src/lib.rs +++ b/examples/gui/platform/src/lib.rs @@ -9,14 +9,14 @@ use core::mem::MaybeUninit; extern "C" { #[link_name = "roc__programForHost_1_exposed_generic"] - fn roc_program(args: State, output: *mut u8) -> (); + fn roc_program() -> (); + + #[link_name = "roc__programForHost_1_Render_caller"] + fn call_Render(state: *const State, closure_data: *const u8, output: *mut u8) -> RocElem; #[link_name = "roc__programForHost_size"] fn roc_program_size() -> i64; - #[link_name = "roc__programForHost_1_Render_caller"] - fn call_Render(flags: *const u8, closure_data: *const u8, output: *mut u8) -> RocElem; - #[allow(dead_code)] #[link_name = "roc__programForHost_1_Render_size"] fn size_Render() -> i64; @@ -25,6 +25,7 @@ extern "C" { fn size_Render_result() -> i64; } +#[derive(Debug)] #[repr(C)] struct State { height: u32, @@ -41,13 +42,13 @@ pub extern "C" fn rust_main() -> i32 { }; let root_elem = unsafe { + roc_program(); + // TODO allocate on the stack if it's under a certain size let buffer = std::alloc::alloc(layout); - roc_program(state, buffer); - // Call the program's render function - let result = call_the_closure(buffer); + let result = call_the_closure(state, buffer); std::alloc::dealloc(buffer, layout); @@ -60,17 +61,12 @@ pub extern "C" fn rust_main() -> i32 { 0 } -unsafe fn call_the_closure(closure_data_ptr: *const u8) -> RocElem { +unsafe fn call_the_closure(state: State, closure_data_ptr: *const u8) -> RocElem { let size = size_Render_result() as usize; let layout = Layout::array::(size).unwrap(); let buffer = std::alloc::alloc(layout) as *mut u8; - let answer = call_Render( - // This flags pointer will never get dereferenced - MaybeUninit::uninit().as_ptr(), - closure_data_ptr as *const u8, - buffer as *mut u8, - ); + let answer = call_Render(&state, closure_data_ptr as *const u8, buffer as *mut u8); std::alloc::dealloc(buffer, layout); From 76ffb4f278b29b181078b1d6439204390d59ff63 Mon Sep 17 00:00:00 2001 From: Brendan Hansknecht Date: Tue, 29 Mar 2022 18:20:29 -0700 Subject: [PATCH 055/846] Add --no-link flag for more complex linking cases --- Cargo.lock | 1 + cli/src/build.rs | 5 +++++ cli/src/lib.rs | 19 +++++++++++++++---- compiler/build/Cargo.toml | 1 + compiler/build/src/link.rs | 7 +++++-- 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8c69e69d22..06b5dcc0c1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3370,6 +3370,7 @@ dependencies = [ "roc_can", "roc_collections", "roc_constrain", + "roc_error_macros", "roc_gen_dev", "roc_gen_llvm", "roc_gen_wasm", diff --git a/cli/src/build.rs b/cli/src/build.rs index a32c5c1e23..ab3d7d0c42 100644 --- a/cli/src/build.rs +++ b/cli/src/build.rs @@ -246,6 +246,11 @@ pub fn build_file<'a>( todo!("gracefully handle failing to surgically link"); })?; BuildOutcome::NoProblems + } else if matches!(link_type, LinkType::None) { + // Just copy the object file to the output folder. + binary_path.set_extension(app_extension); + std::fs::copy(app_o_file, &binary_path).unwrap(); + BuildOutcome::NoProblems } else { let mut inputs = vec![ host_input_path.as_path().to_str().unwrap(), diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 54620dbfc8..7d82ed074c 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -34,6 +34,7 @@ pub const FLAG_DEV: &str = "dev"; pub const FLAG_OPTIMIZE: &str = "optimize"; pub const FLAG_OPT_SIZE: &str = "opt-size"; pub const FLAG_LIB: &str = "lib"; +pub const FLAG_NO_LINK: &str = "no-link"; pub const FLAG_TARGET: &str = "target"; pub const FLAG_TIME: &str = "time"; pub const FLAG_LINK: &str = "roc-linker"; @@ -88,6 +89,12 @@ pub fn build_app<'a>() -> App<'a> { .about("Build a C library instead of an executable.") .required(false), ) + .arg( + Arg::new(FLAG_NO_LINK) + .long(FLAG_NO_LINK) + .about("Does not link. Instead just outputs the `.o` file") + .required(false), + ) .arg( Arg::new(FLAG_DEBUG) .long(FLAG_DEBUG) @@ -291,10 +298,14 @@ pub fn build(matches: &ArgMatches, config: BuildConfig) -> io::Result { let emit_debug_info = matches.is_present(FLAG_DEBUG); let emit_timings = matches.is_present(FLAG_TIME); - let link_type = if matches.is_present(FLAG_LIB) { - LinkType::Dylib - } else { - LinkType::Executable + let link_type = match ( + matches.is_present(FLAG_LIB), + matches.is_present(FLAG_NO_LINK), + ) { + (true, false) => LinkType::Dylib, + (true, true) => user_error!("build can only be one of `--lib` or `--no-link`"), + (false, true) => LinkType::None, + (false, false) => LinkType::Executable, }; let surgically_link = matches.is_present(FLAG_LINK); let precompiled = matches.is_present(FLAG_PRECOMPILED); diff --git a/compiler/build/Cargo.toml b/compiler/build/Cargo.toml index 54872936b4..323a820d46 100644 --- a/compiler/build/Cargo.toml +++ b/compiler/build/Cargo.toml @@ -24,6 +24,7 @@ roc_gen_llvm = { path = "../gen_llvm", optional = true } roc_gen_wasm = { path = "../gen_wasm", optional = true } roc_gen_dev = { path = "../gen_dev", default-features = false } roc_reporting = { path = "../../reporting" } +roc_error_macros = { path = "../../error_macros" } roc_std = { path = "../../roc_std", default-features = false } bumpalo = { version = "3.8.0", features = ["collections"] } libloading = "0.7.1" diff --git a/compiler/build/src/link.rs b/compiler/build/src/link.rs index 703efb6fbd..02fe79093b 100644 --- a/compiler/build/src/link.rs +++ b/compiler/build/src/link.rs @@ -2,6 +2,7 @@ use crate::target::{arch_str, target_zig_str}; #[cfg(feature = "llvm")] use libloading::{Error, Library}; use roc_builtins::bitcode; +use roc_error_macros::internal_error; // #[cfg(feature = "llvm")] use roc_mono::ir::OptLevel; use std::collections::HashMap; @@ -20,10 +21,10 @@ fn zig_executable() -> String { #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum LinkType { - // These numbers correspond to the --lib flag; if it's present - // (e.g. is_present returns `1 as bool`), this will be 1 as well. + // These numbers correspond to the --lib and --no-link flags Executable = 0, Dylib = 1, + None = 2, } /// input_paths can include the host as well as the app. e.g. &["host.o", "roc_app.o"] @@ -835,6 +836,7 @@ fn link_linux( output_path, ) } + LinkType::None => internal_error!("link_linux should not be called with link type of none"), }; let env_path = env::var("PATH").unwrap_or_else(|_| "".to_string()); @@ -904,6 +906,7 @@ fn link_macos( ("-dylib", output_path) } + LinkType::None => internal_error!("link_macos should not be called with link type of none"), }; let arch = match target.architecture { From 97fff2e84d21b0832ae5e9ab996e3d9c49301327 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sun, 3 Apr 2022 23:32:32 -0400 Subject: [PATCH 056/846] Re-render in reponse to keyboard input --- examples/gui/Hello.roc | 4 +- examples/gui/platform/Package-Config.roc | 2 +- .../platform/src/graphics/primitives/text.rs | 9 +-- examples/gui/platform/src/gui.rs | 76 +++++++++---------- examples/gui/platform/src/lib.rs | 65 +--------------- examples/gui/platform/src/roc.rs | 57 ++++++++++++++ 6 files changed, 103 insertions(+), 110 deletions(-) diff --git a/examples/gui/Hello.roc b/examples/gui/Hello.roc index 5adcf7a415..8ef081fe5c 100644 --- a/examples/gui/Hello.roc +++ b/examples/gui/Hello.roc @@ -12,8 +12,8 @@ render = \state -> styles = { bgColor: rgba 100 50 50 1, borderColor: rgba 10 20 30 1, borderWidth: 10, textColor: rgba 220 220 250 1 } - height = if state.height == 42 then "correct!" else if state.height == 0 then "zero" else "incorrect" - width = if state.width == 123 then "Correct!" else if state.width == 0 then "zero" else "Incorrect" + height = if state.height == 1000 then "correct!" else if state.height == 0 then "zero" else "incorrect" + width = if state.width == 1900 then "Correct!" else if state.width == 0 then "zero" else "Incorrect" Col [ diff --git a/examples/gui/platform/Package-Config.roc b/examples/gui/platform/Package-Config.roc index 8ecb3d14b0..ab31e1fd6b 100644 --- a/examples/gui/platform/Package-Config.roc +++ b/examples/gui/platform/Package-Config.roc @@ -11,7 +11,7 @@ ButtonStyles : { bgColor : Rgba, borderColor : Rgba, borderWidth : F32, textColo Elem : [ Button Elem ButtonStyles, Col (List Elem), Row (List Elem), Text Str ] -State : { width : U32, height : U32 } # TODO change from U32 to F32 once Num.toStr supports floats +State : { width : F32, height : F32 } Program state : { render : state -> Elem } diff --git a/examples/gui/platform/src/graphics/primitives/text.rs b/examples/gui/platform/src/graphics/primitives/text.rs index 2a01ad2afa..4ecaa28d9b 100644 --- a/examples/gui/platform/src/graphics/primitives/text.rs +++ b/examples/gui/platform/src/graphics/primitives/text.rs @@ -6,12 +6,9 @@ use crate::graphics::colors::Rgba; use crate::graphics::style::DEFAULT_FONT_SIZE; -use ab_glyph::{FontArc, Glyph, InvalidFont}; -use cgmath::{Vector2, Vector4}; -use glyph_brush::OwnedSection; -use wgpu_glyph::{ab_glyph, GlyphBrush, GlyphBrushBuilder, Section}; - -use super::rect::Rect; +use ab_glyph::{FontArc, InvalidFont}; +use cgmath::Vector2; +use wgpu_glyph::{ab_glyph, GlyphBrush, GlyphBrushBuilder}; #[derive(Debug)] pub struct Text<'a> { diff --git a/examples/gui/platform/src/gui.rs b/examples/gui/platform/src/gui.rs index 0f6f54d2c8..51dce6fad9 100644 --- a/examples/gui/platform/src/gui.rs +++ b/examples/gui/platform/src/gui.rs @@ -9,12 +9,11 @@ use crate::{ text::build_glyph_brush, }, }, - roc::{RocElem, RocElemTag}, + roc::{self, RocElem, RocElemTag}, }; use cgmath::{Vector2, Vector4}; use glyph_brush::OwnedSection; use pipelines::RectResources; -use roc_std::RocStr; use std::error::Error; use wgpu::{CommandEncoder, LoadOp, RenderPass, TextureView}; use wgpu_glyph::{GlyphBrush, GlyphCruncher}; @@ -32,16 +31,18 @@ use winit::{ // // See this link to learn wgpu: https://sotrh.github.io/learn-wgpu/ -fn run_event_loop(title: &str, root: RocElem) -> Result<(), Box> { +pub fn run_event_loop(title: &str, state: roc::State) -> Result<(), Box> { // Open window and create a surface let mut event_loop = winit::event_loop::EventLoop::new(); let window = winit::window::WindowBuilder::new() - .with_inner_size(PhysicalSize::new(1900.0, 1000.0)) + .with_inner_size(PhysicalSize::new(state.width, state.height)) .with_title(title) .build(&event_loop) .unwrap(); + let mut root = roc::app_render(state); + let instance = wgpu::Instance::new(wgpu::Backends::all()); let surface = unsafe { instance.create_surface(&window) }; @@ -143,42 +144,41 @@ fn run_event_loop(title: &str, root: RocElem) -> Result<(), Box> { &cmd_queue, ); } - //Received Character + // Keyboard input Event::WindowEvent { - event: event::WindowEvent::ReceivedCharacter(_ch), + event: + event::WindowEvent::KeyboardInput { + input: + event::KeyboardInput { + virtual_keycode: Some(keycode), + state: input_state, + .. + }, + .. + }, .. } => { - // let input_outcome_res = - // app_update::handle_new_char(&ch, &mut app_model, keyboard_modifiers); - // if let Err(e) = input_outcome_res { - // print_err(&e) - // } else if let Ok(InputOutcome::Ignored) = input_outcome_res { - // println!("Input '{}' ignored!", ch); - // } - todo!("TODO handle character input"); - } - //Keyboard Input - Event::WindowEvent { - event: event::WindowEvent::KeyboardInput { input: _, .. }, - .. - } => { - // if let Some(virtual_keycode) = input.virtual_keycode { - // if let Some(ref mut ed_model) = app_model.ed_model_opt { - // if ed_model.has_focus { - // let keydown_res = keyboard_input::handle_keydown( - // input.state, - // virtual_keycode, - // keyboard_modifiers, - // &mut app_model, - // ); + use event::ElementState::*; + use event::VirtualKeyCode::*; - // if let Err(e) = keydown_res { - // print_err(&e) - // } - // } - // } - // } - // TODO todo!("TODO handle keyboard input"); + match keycode { + Left => match input_state { + Pressed => println!("Left pressed!"), + Released => println!("Left released!"), + }, + Right => match input_state { + Pressed => println!("Right pressed!"), + Released => println!("Right released!"), + }, + _ => { + println!("Other!"); + } + }; + + root = roc::app_render(roc::State { + height: 0.0, + width: 0.0, + }); } //Modifiers Changed Event::WindowEvent { @@ -347,10 +347,6 @@ fn begin_render_pass<'a>( }) } -pub fn render(title: RocStr, root: RocElem) { - run_event_loop(title.as_str(), root).expect("Error running event loop"); -} - #[derive(Copy, Clone, Debug, Default)] struct Bounds { width: f32, diff --git a/examples/gui/platform/src/lib.rs b/examples/gui/platform/src/lib.rs index f64bd29db3..fb6877881a 100644 --- a/examples/gui/platform/src/lib.rs +++ b/examples/gui/platform/src/lib.rs @@ -3,72 +3,15 @@ mod graphics; mod gui; mod roc; -use crate::roc::RocElem; -use core::alloc::Layout; -use core::mem::MaybeUninit; - -extern "C" { - #[link_name = "roc__programForHost_1_exposed_generic"] - fn roc_program() -> (); - - #[link_name = "roc__programForHost_1_Render_caller"] - fn call_Render(state: *const State, closure_data: *const u8, output: *mut u8) -> RocElem; - - #[link_name = "roc__programForHost_size"] - fn roc_program_size() -> i64; - - #[allow(dead_code)] - #[link_name = "roc__programForHost_1_Render_size"] - fn size_Render() -> i64; - - #[link_name = "roc__programForHost_1_Render_result_size"] - fn size_Render_result() -> i64; -} - -#[derive(Debug)] -#[repr(C)] -struct State { - height: u32, - width: u32, -} - #[no_mangle] pub extern "C" fn rust_main() -> i32 { - let size = unsafe { roc_program_size() } as usize; - let layout = Layout::array::(size).unwrap(); - let state = State { - height: 42, - width: 123, + let state = roc::State { + width: 1900.0, + height: 1000.0, }; - let root_elem = unsafe { - roc_program(); - - // TODO allocate on the stack if it's under a certain size - let buffer = std::alloc::alloc(layout); - - // Call the program's render function - let result = call_the_closure(state, buffer); - - std::alloc::dealloc(buffer, layout); - - result - }; - - gui::render("test title".into(), root_elem); + gui::run_event_loop("test title", state).expect("Error running event loop"); // Exit code 0 } - -unsafe fn call_the_closure(state: State, closure_data_ptr: *const u8) -> RocElem { - let size = size_Render_result() as usize; - let layout = Layout::array::(size).unwrap(); - let buffer = std::alloc::alloc(layout) as *mut u8; - - let answer = call_Render(&state, closure_data_ptr as *const u8, buffer as *mut u8); - - std::alloc::dealloc(buffer, layout); - - answer -} diff --git a/examples/gui/platform/src/roc.rs b/examples/gui/platform/src/roc.rs index dd02176168..9a3ca76439 100644 --- a/examples/gui/platform/src/roc.rs +++ b/examples/gui/platform/src/roc.rs @@ -1,4 +1,5 @@ use crate::graphics::colors::Rgba; +use core::alloc::Layout; use core::ffi::c_void; use core::mem::{self, ManuallyDrop}; use roc_std::{ReferenceCount, RocList, RocStr}; @@ -6,6 +7,31 @@ use std::ffi::CStr; use std::fmt::Debug; use std::os::raw::c_char; +extern "C" { + #[link_name = "roc__programForHost_1_exposed_generic"] + fn roc_program() -> (); + + #[link_name = "roc__programForHost_1_Render_caller"] + fn call_Render(state: *const State, closure_data: *const u8, output: *mut u8) -> RocElem; + + #[link_name = "roc__programForHost_size"] + fn roc_program_size() -> i64; + + #[allow(dead_code)] + #[link_name = "roc__programForHost_1_Render_size"] + fn size_Render() -> i64; + + #[link_name = "roc__programForHost_1_Render_result_size"] + fn size_Render_result() -> i64; +} + +#[derive(Debug)] +#[repr(C)] +pub struct State { + pub height: f32, + pub width: f32, +} + #[no_mangle] pub unsafe extern "C" fn roc_alloc(size: usize, _alignment: u32) -> *mut c_void { return libc::malloc(size); @@ -341,3 +367,34 @@ fn make_row_with_button() { assert_eq!(row.tag(), RocElemTag::Row); } + +pub fn app_render(state: State) -> RocElem { + let size = unsafe { roc_program_size() } as usize; + let layout = Layout::array::(size).unwrap(); + + unsafe { + roc_program(); + + // TODO allocate on the stack if it's under a certain size + let buffer = std::alloc::alloc(layout); + + // Call the program's render function + let result = call_the_closure(state, buffer); + + std::alloc::dealloc(buffer, layout); + + result + } +} + +unsafe fn call_the_closure(state: State, closure_data_ptr: *const u8) -> RocElem { + let size = size_Render_result() as usize; + let layout = Layout::array::(size).unwrap(); + let buffer = std::alloc::alloc(layout) as *mut u8; + + let answer = call_Render(&state, closure_data_ptr as *const u8, buffer as *mut u8); + + std::alloc::dealloc(buffer, layout); + + answer +} From a111f510a4cfc4110f460637908a239f386964ba Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 4 Apr 2022 10:02:13 -0400 Subject: [PATCH 057/846] Add examples/breakout --- examples/breakout/.gitignore | 1 + examples/breakout/breakout.roc | 30 + examples/breakout/platform/.gitignore | 1 + examples/breakout/platform/Action.roc | 20 + examples/breakout/platform/Cargo.lock | 2835 +++++++++++++++++ examples/breakout/platform/Cargo.toml | 75 + examples/breakout/platform/Elem.roc | 193 ++ examples/breakout/platform/Package-Config.roc | 20 + examples/breakout/platform/host.c | 3 + examples/breakout/platform/src/focus.rs | 172 + .../breakout/platform/src/graphics/colors.rs | 50 + .../platform/src/graphics/lowlevel/buffer.rs | 96 + .../platform/src/graphics/lowlevel/mod.rs | 5 + .../platform/src/graphics/lowlevel/ortho.rs | 118 + .../src/graphics/lowlevel/pipelines.rs | 72 + .../platform/src/graphics/lowlevel/quad.rs | 31 + .../platform/src/graphics/lowlevel/vertex.rs | 35 + .../breakout/platform/src/graphics/mod.rs | 4 + .../platform/src/graphics/primitives/mod.rs | 2 + .../platform/src/graphics/primitives/rect.rs | 27 + .../platform/src/graphics/primitives/text.rs | 134 + .../platform/src/graphics/shaders/quad.wgsl | 60 + .../breakout/platform/src/graphics/style.rs | 1 + examples/breakout/platform/src/gui.rs | 631 ++++ examples/breakout/platform/src/lib.rs | 17 + examples/breakout/platform/src/main.rs | 3 + examples/breakout/platform/src/roc.rs | 400 +++ 27 files changed, 5036 insertions(+) create mode 100644 examples/breakout/.gitignore create mode 100644 examples/breakout/breakout.roc create mode 100644 examples/breakout/platform/.gitignore create mode 100644 examples/breakout/platform/Action.roc create mode 100644 examples/breakout/platform/Cargo.lock create mode 100644 examples/breakout/platform/Cargo.toml create mode 100644 examples/breakout/platform/Elem.roc create mode 100644 examples/breakout/platform/Package-Config.roc create mode 100644 examples/breakout/platform/host.c create mode 100644 examples/breakout/platform/src/focus.rs create mode 100644 examples/breakout/platform/src/graphics/colors.rs create mode 100644 examples/breakout/platform/src/graphics/lowlevel/buffer.rs create mode 100644 examples/breakout/platform/src/graphics/lowlevel/mod.rs create mode 100644 examples/breakout/platform/src/graphics/lowlevel/ortho.rs create mode 100644 examples/breakout/platform/src/graphics/lowlevel/pipelines.rs create mode 100644 examples/breakout/platform/src/graphics/lowlevel/quad.rs create mode 100644 examples/breakout/platform/src/graphics/lowlevel/vertex.rs create mode 100644 examples/breakout/platform/src/graphics/mod.rs create mode 100644 examples/breakout/platform/src/graphics/primitives/mod.rs create mode 100644 examples/breakout/platform/src/graphics/primitives/rect.rs create mode 100644 examples/breakout/platform/src/graphics/primitives/text.rs create mode 100644 examples/breakout/platform/src/graphics/shaders/quad.wgsl create mode 100644 examples/breakout/platform/src/graphics/style.rs create mode 100644 examples/breakout/platform/src/gui.rs create mode 100644 examples/breakout/platform/src/lib.rs create mode 100644 examples/breakout/platform/src/main.rs create mode 100644 examples/breakout/platform/src/roc.rs diff --git a/examples/breakout/.gitignore b/examples/breakout/.gitignore new file mode 100644 index 0000000000..8f5562e399 --- /dev/null +++ b/examples/breakout/.gitignore @@ -0,0 +1 @@ +hello-gui diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc new file mode 100644 index 0000000000..8ef081fe5c --- /dev/null +++ b/examples/breakout/breakout.roc @@ -0,0 +1,30 @@ +app "hello-gui" + packages { pf: "platform" } + imports []# [ pf.Action.{ Action }, pf.Elem.{ button, text, row, col } ] + provides [ program ] to pf + +program = { render } + +render = \state -> + div0 = \numerator, denominator -> (numerator / denominator) |> Result.withDefault 0 + + rgba = \r, g, b, a -> { r: div0 r 255, g: div0 g 255, b: div0 b 255, a } + + styles = { bgColor: rgba 100 50 50 1, borderColor: rgba 10 20 30 1, borderWidth: 10, textColor: rgba 220 220 250 1 } + + height = if state.height == 1000 then "correct!" else if state.height == 0 then "zero" else "incorrect" + width = if state.width == 1900 then "Correct!" else if state.width == 0 then "zero" else "Incorrect" + + Col + [ + Row + [ + Button (Text "Corner ") styles, + Button (Text "Top Mid ") { styles & bgColor: rgba 100 100 50 1 }, + Button (Text "Top Right ") { styles & bgColor: rgba 50 50 150 1 }, + ], + Button (Text "Mid Left ") { styles & bgColor: rgba 150 100 100 1 }, + Button (Text "Bottom Left") { styles & bgColor: rgba 150 50 50 1 }, + Button (Text "height: \(height)") { styles & bgColor: rgba 50 150 50 1 }, + Button (Text "width: \(width)") { styles & bgColor: rgba 50 100 50 1 }, + ] diff --git a/examples/breakout/platform/.gitignore b/examples/breakout/platform/.gitignore new file mode 100644 index 0000000000..eb5a316cbd --- /dev/null +++ b/examples/breakout/platform/.gitignore @@ -0,0 +1 @@ +target diff --git a/examples/breakout/platform/Action.roc b/examples/breakout/platform/Action.roc new file mode 100644 index 0000000000..ad15ee728b --- /dev/null +++ b/examples/breakout/platform/Action.roc @@ -0,0 +1,20 @@ +interface Action + exposes [ Action, none, update, map ] + imports [] + +Action state : [ None, Update state ] + +none : Action * +none = None + +update : state -> Action state +update = Update + +map : Action a, (a -> b) -> Action b +map = \action, transform -> + when action is + None -> + None + + Update state -> + Update (transform state) diff --git a/examples/breakout/platform/Cargo.lock b/examples/breakout/platform/Cargo.lock new file mode 100644 index 0000000000..8f8005c26d --- /dev/null +++ b/examples/breakout/platform/Cargo.lock @@ -0,0 +1,2835 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ab_glyph" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61caed9aec6daeee1ea38ccf5fb225e4f96c1eeead1b4a5c267324a63cf02326" +dependencies = [ + "ab_glyph_rasterizer", + "owned_ttf_parser", +] + +[[package]] +name = "ab_glyph_rasterizer" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a13739d7177fbd22bb0ed28badfff9f372f8bef46c863db4e1c6248f6b223b6e" + +[[package]] +name = "addr2line" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "ahash" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = [ + "getrandom", + "once_cell", + "version_check", +] + +[[package]] +name = "aho-corasick" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +dependencies = [ + "memchr", +] + +[[package]] +name = "alsa" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75c4da790adcb2ce5e758c064b4f3ec17a30349f9961d3e5e6c9688b052a9e18" +dependencies = [ + "alsa-sys", + "bitflags", + "libc", + "nix 0.20.0", +] + +[[package]] +name = "alsa-sys" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db8fee663d06c4e303404ef5f40488a53e062f89ba8bfed81f42325aafad1527" +dependencies = [ + "libc", + "pkg-config", +] + +[[package]] +name = "approx" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f2a05fd1bd10b2527e20a2cd32d8873d115b8b39fe219ee25f42a8aca6ba278" +dependencies = [ + "num-traits", +] + +[[package]] +name = "approx" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "072df7202e63b127ab55acfe16ce97013d5b97bf160489336d3f1840fd78e99e" +dependencies = [ + "num-traits", +] + +[[package]] +name = "arrayvec" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" + +[[package]] +name = "ash" +version = "0.35.1+1.2.203" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7fd04def1c9101b5fb488c131022d2d6f87753ef4b1b11b279e2af404fae6b9" +dependencies = [ + "libloading", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + +[[package]] +name = "backtrace" +version = "0.3.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "321629d8ba6513061f26707241fa9bc89524ff1cd7a915a97ef0c62c666ce1b6" +dependencies = [ + "addr2line", + "cc", + "cfg-if 1.0.0", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bindgen" +version = "0.56.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2da379dbebc0b76ef63ca68d8fc6e71c0f13e59432e0987e508c1820e6ab5239" +dependencies = [ + "bitflags", + "cexpr", + "clang-sys", + "lazy_static", + "lazycell", + "peeking_take_while", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", +] + +[[package]] +name = "bit-set" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e11e16035ea35e4e5997b393eacbf6f63983188f7a2ad25bfb13465f5ad59de" +dependencies = [ + "bit-vec", +] + +[[package]] +name = "bit-vec" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "block" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" + +[[package]] +name = "block-buffer" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" +dependencies = [ + "block-padding", + "byte-tools", + "byteorder", + "generic-array", +] + +[[package]] +name = "block-padding" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" +dependencies = [ + "byte-tools", +] + +[[package]] +name = "bumpalo" +version = "3.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a45a46ab1f2412e53d3a0ade76ffad2025804294569aae387231a0cd6e0899" + +[[package]] +name = "byte-tools" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" + +[[package]] +name = "bytemuck" +version = "1.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439989e6b8c38d1b6570a384ef1e49c8848128f5a97f3914baef02920842712f" +dependencies = [ + "bytemuck_derive", +] + +[[package]] +name = "bytemuck_derive" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e215f8c2f9f79cb53c8335e687ffd07d5bfcb6fe5fc80723762d0be46e7cc54" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "bytes" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" + +[[package]] +name = "calloop" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf2eec61efe56aa1e813f5126959296933cf0700030e4314786c48779a66ab82" +dependencies = [ + "log", + "nix 0.22.0", +] + +[[package]] +name = "cc" +version = "1.0.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee" +dependencies = [ + "jobserver", +] + +[[package]] +name = "cesu8" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" + +[[package]] +name = "cexpr" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4aedb84272dbe89af497cf81375129abda4fc0a9e7c5d317498c15cc30c0d27" +dependencies = [ + "nom 5.1.2", +] + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "cfg_aliases" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" + +[[package]] +name = "cgmath" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a98d30140e3296250832bbaaff83b27dcd6fa3cc70fb6f1f3e5c9c0023b5317" +dependencies = [ + "approx 0.4.0", + "num-traits", +] + +[[package]] +name = "clang-sys" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa66045b9cb23c2e9c1520732030608b02ee07e5cfaa5a521ec15ded7fa24c90" +dependencies = [ + "glob", + "libc", + "libloading", +] + +[[package]] +name = "claxon" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bfbf56724aa9eca8afa4fcfadeb479e722935bb2a0900c2d37e0cc477af0688" + +[[package]] +name = "clipboard-win" +version = "3.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fdf5e01086b6be750428ba4a40619f847eb2e95756eee84b18e06e5f0b50342" +dependencies = [ + "lazy-bytes-cast", + "winapi", +] + +[[package]] +name = "cocoa" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f63902e9223530efb4e26ccd0cf55ec30d592d3b42e21a28defc42a9586e832" +dependencies = [ + "bitflags", + "block", + "cocoa-foundation", + "core-foundation 0.9.2", + "core-graphics 0.22.3", + "foreign-types", + "libc", + "objc", +] + +[[package]] +name = "cocoa-foundation" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ade49b65d560ca58c403a479bb396592b155c0185eada742ee323d1d68d6318" +dependencies = [ + "bitflags", + "block", + "core-foundation 0.9.2", + "core-graphics-types", + "foreign-types", + "libc", + "objc", +] + +[[package]] +name = "codespan-reporting" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" +dependencies = [ + "termcolor", + "unicode-width", +] + +[[package]] +name = "colored" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3616f750b84d8f0de8a58bda93e08e2a81ad3f523089b05f1dffecab48c6cbd" +dependencies = [ + "atty", + "lazy_static", + "winapi", +] + +[[package]] +name = "combine" +version = "4.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50b727aacc797f9fc28e355d21f34709ac4fc9adecfe470ad07b8f4464f53062" +dependencies = [ + "bytes", + "memchr", +] + +[[package]] +name = "confy" +version = "0.4.0" +source = "git+https://github.com/rust-cli/confy#664992aecd97b4af0eda8d9d2825885662e1c6b4" +dependencies = [ + "directories-next", + "serde", + "serde_yaml", +] + +[[package]] +name = "copyless" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2df960f5d869b2dd8532793fde43eb5427cceb126c929747a26823ab0eeb536" + +[[package]] +name = "copypasta" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4423d79fed83ebd9ab81ec21fa97144300a961782158287dc9bf7eddac37ff0b" +dependencies = [ + "clipboard-win", + "objc", + "objc-foundation", + "objc_id", + "smithay-clipboard", + "x11-clipboard", +] + +[[package]] +name = "core-foundation" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171" +dependencies = [ + "core-foundation-sys 0.7.0", + "libc", +] + +[[package]] +name = "core-foundation" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6888e10551bb93e424d8df1d07f1a8b4fceb0001a3a4b048bfc47554946f47b3" +dependencies = [ + "core-foundation-sys 0.8.3", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" + +[[package]] +name = "core-foundation-sys" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" + +[[package]] +name = "core-graphics" +version = "0.19.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3889374e6ea6ab25dba90bb5d96202f61108058361f6dc72e8b03e6f8bbe923" +dependencies = [ + "bitflags", + "core-foundation 0.7.0", + "foreign-types", + "libc", +] + +[[package]] +name = "core-graphics" +version = "0.22.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2581bbab3b8ffc6fcbd550bf46c355135d16e9ff2a6ea032ad6b9bf1d7efe4fb" +dependencies = [ + "bitflags", + "core-foundation 0.9.2", + "core-graphics-types", + "foreign-types", + "libc", +] + +[[package]] +name = "core-graphics-types" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a68b68b3446082644c91ac778bf50cd4104bfb002b5a6a7c44cca5a2c70788b" +dependencies = [ + "bitflags", + "core-foundation 0.9.2", + "foreign-types", + "libc", +] + +[[package]] +name = "core-video-sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34ecad23610ad9757664d644e369246edde1803fcb43ed72876565098a5d3828" +dependencies = [ + "cfg-if 0.1.10", + "core-foundation-sys 0.7.0", + "core-graphics 0.19.2", + "libc", + "objc", +] + +[[package]] +name = "coreaudio-rs" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11894b20ebfe1ff903cbdc52259693389eea03b94918a2def2c30c3bf227ad88" +dependencies = [ + "bitflags", + "coreaudio-sys", +] + +[[package]] +name = "coreaudio-sys" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b7e3347be6a09b46aba228d6608386739fb70beff4f61e07422da87b0bb31fa" +dependencies = [ + "bindgen", +] + +[[package]] +name = "cpal" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98f45f0a21f617cd2c788889ef710b63f075c949259593ea09c826f1e47a2418" +dependencies = [ + "alsa", + "core-foundation-sys 0.8.3", + "coreaudio-rs", + "jni", + "js-sys", + "lazy_static", + "libc", + "mach", + "ndk 0.3.0", + "ndk-glue 0.3.0", + "nix 0.20.0", + "oboe", + "parking_lot", + "stdweb", + "thiserror", + "web-sys", + "winapi", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e54ea8bc3fb1ee042f5aace6e3c6e025d3874866da222930f70ce62aceba0bfa" +dependencies = [ + "cfg-if 1.0.0", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e" +dependencies = [ + "cfg-if 1.0.0", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97242a70df9b89a65d0b6df3c4bf5b9ce03c5b7309019777fbde37e7537f8762" +dependencies = [ + "cfg-if 1.0.0", + "crossbeam-utils", + "lazy_static", + "memoffset", + "scopeguard", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcae03edb34f947e64acdb1c33ec169824e20657e9ecb61cef6c8c74dcb8120" +dependencies = [ + "cfg-if 1.0.0", + "lazy_static", +] + +[[package]] +name = "cty" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35" + +[[package]] +name = "d3d12" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2daefd788d1e96e0a9d66dee4b828b883509bc3ea9ce30665f04c3246372690c" +dependencies = [ + "bitflags", + "libloading", + "winapi", +] + +[[package]] +name = "darling" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d706e75d87e35569db781a9b5e2416cff1236a47ed380831f959382ccd5f858" +dependencies = [ + "darling_core 0.10.2", + "darling_macro 0.10.2", +] + +[[package]] +name = "darling" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0d720b8683f8dd83c65155f0530560cba68cd2bf395f6513a483caee57ff7f4" +dependencies = [ + "darling_core 0.13.1", + "darling_macro 0.13.1", +] + +[[package]] +name = "darling_core" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0c960ae2da4de88a91b2d920c2a7233b400bc33cb28453a2987822d8392519b" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim 0.9.3", + "syn", +] + +[[package]] +name = "darling_core" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a340f241d2ceed1deb47ae36c4144b2707ec7dd0b649f894cb39bb595986324" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim 0.10.0", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72" +dependencies = [ + "darling_core 0.10.2", + "quote", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72c41b3b7352feb3211a0d743dc5700a4e3b60f51bd2b368892d1e0f9a95f44b" +dependencies = [ + "darling_core 0.13.1", + "quote", + "syn", +] + +[[package]] +name = "digest" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" +dependencies = [ + "generic-array", +] + +[[package]] +name = "directories-next" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "339ee130d97a610ea5a5872d2bbb130fdf68884ff09d3028b81bec8a1ac23bbc" +dependencies = [ + "cfg-if 1.0.0", + "dirs-sys-next", +] + +[[package]] +name = "dirs-sys-next" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + +[[package]] +name = "dispatch" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd0c93bb4b0c6d9b77f4435b0ae98c24d17f1c45b2ff844c6151a07256ca923b" + +[[package]] +name = "dlib" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac1b7517328c04c2aa68422fc60a41b92208182142ed04a25879c26c8f878794" +dependencies = [ + "libloading", +] + +[[package]] +name = "doc-comment" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" + +[[package]] +name = "downcast-rs" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" + +[[package]] +name = "either" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" + +[[package]] +name = "env_logger" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + +[[package]] +name = "fake-simd" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" + +[[package]] +name = "find-crate" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59a98bbaacea1c0eb6a0876280051b892eb73594fd90cf3b20e9c817029c57d2" +dependencies = [ + "toml", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "fs_extra" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394" + +[[package]] +name = "futures" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28560757fe2bb34e79f907794bb6b22ae8b0e5c669b638a1132f2592b19035b4" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3dda0b6588335f360afc675d0564c17a77a2bda81ca178a4b6081bd86c7f0b" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0c8ff0461b82559810cdccfde3215c3f373807f5e5232b71479bff7bb2583d7" + +[[package]] +name = "futures-executor" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29d6d2ff5bb10fb95c85b8ce46538a2e5f5e7fdc755623a7d4529ab8a4ed9d2a" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f9d34af5a1aac6fb380f735fe510746c38067c5bf16c7fd250280503c971b2" + +[[package]] +name = "futures-macro" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbd947adfffb0efc70599b3ddcf7b5597bb5fa9e245eb99f62b3a5f7bb8bd3c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3055baccb68d74ff6480350f8d6eb8fcfa3aa11bdc1a1ae3afdd0514617d508" + +[[package]] +name = "futures-task" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ee7c6485c30167ce4dfb83ac568a849fe53274c831081476ee13e0dce1aad72" + +[[package]] +name = "futures-util" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b5cf40b47a271f77a8b1bec03ca09044d99d2372c0de244e66430761127164" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "generic-array" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffdf9f34f1447443d37393cc6c2b8313aebddcd96906caf34e54c68d8e57d7bd" +dependencies = [ + "typenum", +] + +[[package]] +name = "getrandom" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418d37c8b1d42553c93648be529cb70f920d3baf8ef469b74b9638df426e0b4c" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "wasi", +] + +[[package]] +name = "gimli" +version = "0.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4" + +[[package]] +name = "glob" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" + +[[package]] +name = "glow" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8bd5877156a19b8ac83a29b2306fe20537429d318f3ff0a1a2119f8d9c61919" +dependencies = [ + "js-sys", + "slotmap", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "glyph_brush" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21932fbf719272848eec4583740d978203c6e7da4c4e203358f5b95946c97409" +dependencies = [ + "glyph_brush_draw_cache", + "glyph_brush_layout", + "log", + "ordered-float", + "rustc-hash", + "twox-hash", +] + +[[package]] +name = "glyph_brush_draw_cache" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6010675390f6889e09a21e2c8b575b3ee25667ea8237a8d59423f73cb8c28610" +dependencies = [ + "ab_glyph", + "crossbeam-channel", + "crossbeam-deque", + "linked-hash-map", + "rayon", + "rustc-hash", +] + +[[package]] +name = "glyph_brush_layout" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc32c2334f00ca5ac3695c5009ae35da21da8c62d255b5b96d56e2597a637a38" +dependencies = [ + "ab_glyph", + "approx 0.5.0", + "xi-unicode", +] + +[[package]] +name = "gpu-alloc" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fc59e5f710e310e76e6707f86c561dd646f69a8876da9131703b2f717de818d" +dependencies = [ + "bitflags", + "gpu-alloc-types", +] + +[[package]] +name = "gpu-alloc-types" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54804d0d6bc9d7f26db4eaec1ad10def69b599315f487d32c334a80d1efe67a5" +dependencies = [ + "bitflags", +] + +[[package]] +name = "gpu-descriptor" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a538f217be4d405ff4719a283ca68323cc2384003eca5baaa87501e821c81dda" +dependencies = [ + "bitflags", + "gpu-descriptor-types", + "hashbrown", +] + +[[package]] +name = "gpu-descriptor-types" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "363e3677e55ad168fef68cf9de3a4a310b53124c5e784c53a1d70e92d23f2126" +dependencies = [ + "bitflags", +] + +[[package]] +name = "hashbrown" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" +dependencies = [ + "ahash", +] + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "hexf-parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df" + +[[package]] +name = "host" +version = "0.1.0" +dependencies = [ + "arrayvec", + "bytemuck", + "cgmath", + "colored", + "confy", + "copypasta", + "env_logger", + "fs_extra", + "futures", + "glyph_brush", + "libc", + "log", + "nonempty", + "page_size", + "palette", + "pest", + "pest_derive", + "roc_std", + "rodio", + "serde", + "snafu", + "threadpool", + "wgpu", + "wgpu_glyph", + "winit", +] + +[[package]] +name = "hound" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a164bb2ceaeff4f42542bdb847c41517c78a60f5649671b2a07312b6e117549" + +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "indexmap" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223" +dependencies = [ + "autocfg", + "hashbrown", +] + +[[package]] +name = "inplace_it" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90953f308a79fe6d62a4643e51f848fbfddcd05975a38e69fdf4ab86a7baf7ca" + +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if 1.0.0", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "jni" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6df18c2e3db7e453d3c6ac5b3e9d5182664d28788126d39b91f2d1e22b017ec" +dependencies = [ + "cesu8", + "combine", + "jni-sys", + "log", + "thiserror", + "walkdir", +] + +[[package]] +name = "jni-sys" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" + +[[package]] +name = "jobserver" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af25a77299a7f711a01975c35a6a424eb6862092cc2d6c72c4ed6cbc56dfc1fa" +dependencies = [ + "libc", +] + +[[package]] +name = "js-sys" +version = "0.3.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a38fc24e30fd564ce974c02bf1d337caddff65be6cc4735a1f7eab22a7440f04" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "khronos-egl" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c2352bd1d0bceb871cb9d40f24360c8133c11d7486b68b5381c1dd1a32015e3" +dependencies = [ + "libc", + "libloading", + "pkg-config", +] + +[[package]] +name = "lazy-bytes-cast" +version = "5.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10257499f089cd156ad82d0a9cd57d9501fa2c989068992a97eb3c27836f206b" + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + +[[package]] +name = "lewton" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "777b48df9aaab155475a83a7df3070395ea1ac6902f5cd062b8f2b028075c030" +dependencies = [ + "byteorder", + "ogg", + "tinyvec", +] + +[[package]] +name = "libc" +version = "0.2.113" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eef78b64d87775463c549fbd80e19249ef436ea3bf1de2a1eb7e717ec7fab1e9" + +[[package]] +name = "libloading" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd" +dependencies = [ + "cfg-if 1.0.0", + "winapi", +] + +[[package]] +name = "linked-hash-map" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3" + +[[package]] +name = "lock_api" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712a4d093c9976e24e7dbca41db895dabcbac38eb5f4045393d17a95bdfb1109" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "mach" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b823e83b2affd8f40a9ee8c29dbc56404c1e34cd2710921f2801e2cf29527afa" +dependencies = [ + "libc", +] + +[[package]] +name = "malloc_buf" +version = "0.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" +dependencies = [ + "libc", +] + +[[package]] +name = "maplit" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" + +[[package]] +name = "memchr" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" + +[[package]] +name = "memmap2" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b6c2ebff6180198788f5db08d7ce3bc1d0b617176678831a7510825973e357" +dependencies = [ + "libc", +] + +[[package]] +name = "memoffset" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" +dependencies = [ + "autocfg", +] + +[[package]] +name = "metal" +version = "0.23.1" +source = "git+https://github.com/gfx-rs/metal-rs?rev=44af5cc#44af5cca340617d42d701264f9bf71d1f3e68096" +dependencies = [ + "bitflags", + "block", + "core-graphics-types", + "foreign-types", + "log", + "objc", +] + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "minimp3" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985438f75febf74c392071a975a29641b420dd84431135a6e6db721de4b74372" +dependencies = [ + "minimp3-sys", + "slice-deque", + "thiserror", +] + +[[package]] +name = "minimp3-sys" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e21c73734c69dc95696c9ed8926a2b393171d98b3f5f5935686a26a487ab9b90" +dependencies = [ + "cc", +] + +[[package]] +name = "miniz_oxide" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" +dependencies = [ + "adler", + "autocfg", +] + +[[package]] +name = "mio" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba272f85fa0b41fc91872be579b3bbe0f56b792aa361a380eb669469f68dafb2" +dependencies = [ + "libc", + "log", + "miow", + "ntapi", + "winapi", +] + +[[package]] +name = "miow" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" +dependencies = [ + "winapi", +] + +[[package]] +name = "naga" +version = "0.8.0" +source = "git+https://github.com/gfx-rs/naga?rev=8e2e39e#8e2e39e4d8fa5bbb657c3b170b4f6607d703e284" +dependencies = [ + "bit-set", + "bitflags", + "codespan-reporting", + "hexf-parse", + "indexmap", + "log", + "num-traits", + "rustc-hash", + "spirv", + "thiserror", +] + +[[package]] +name = "ndk" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8794322172319b972f528bf90c6b467be0079f1fa82780ffb431088e741a73ab" +dependencies = [ + "jni-sys", + "ndk-sys 0.2.2", + "num_enum", + "thiserror", +] + +[[package]] +name = "ndk" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d868f654c72e75f8687572699cdabe755f03effbb62542768e995d5b8d699d" +dependencies = [ + "bitflags", + "jni-sys", + "ndk-sys 0.2.2", + "num_enum", + "thiserror", +] + +[[package]] +name = "ndk" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2032c77e030ddee34a6787a64166008da93f6a352b629261d0fee232b8742dd4" +dependencies = [ + "bitflags", + "jni-sys", + "ndk-sys 0.3.0", + "num_enum", + "thiserror", +] + +[[package]] +name = "ndk-glue" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5caf0c24d51ac1c905c27d4eda4fa0635bbe0de596b8f79235e0b17a4d29385" +dependencies = [ + "lazy_static", + "libc", + "log", + "ndk 0.3.0", + "ndk-macro 0.2.0", + "ndk-sys 0.2.2", +] + +[[package]] +name = "ndk-glue" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc291b8de2095cba8dab7cf381bf582ff4c17a09acf854c32e46545b08085d28" +dependencies = [ + "lazy_static", + "libc", + "log", + "ndk 0.5.0", + "ndk-macro 0.3.0", + "ndk-sys 0.2.2", +] + +[[package]] +name = "ndk-glue" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04c0d14b0858eb9962a5dac30b809b19f19da7e4547d64af2b0bb051d2e55d79" +dependencies = [ + "lazy_static", + "libc", + "log", + "ndk 0.6.0", + "ndk-macro 0.3.0", + "ndk-sys 0.3.0", +] + +[[package]] +name = "ndk-macro" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05d1c6307dc424d0f65b9b06e94f88248e6305726b14729fd67a5e47b2dc481d" +dependencies = [ + "darling 0.10.2", + "proc-macro-crate 0.1.5", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "ndk-macro" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0df7ac00c4672f9d5aece54ee3347520b7e20f158656c7db2e6de01902eb7a6c" +dependencies = [ + "darling 0.13.1", + "proc-macro-crate 1.1.0", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "ndk-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1bcdd74c20ad5d95aacd60ef9ba40fdf77f767051040541df557b7a9b2a2121" + +[[package]] +name = "ndk-sys" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e5a6ae77c8ee183dcbbba6150e2e6b9f3f4196a7666c02a715a95692ec1fa97" +dependencies = [ + "jni-sys", +] + +[[package]] +name = "nix" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa9b4819da1bc61c0ea48b63b7bc8604064dd43013e7cc325df098d49cd7c18a" +dependencies = [ + "bitflags", + "cc", + "cfg-if 1.0.0", + "libc", +] + +[[package]] +name = "nix" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1e25ee6b412c2a1e3fcb6a4499a5c1bfe7f43e014bdce9a6b6666e5aa2d187" +dependencies = [ + "bitflags", + "cc", + "cfg-if 1.0.0", + "libc", + "memoffset", +] + +[[package]] +name = "nom" +version = "5.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af" +dependencies = [ + "memchr", + "version_check", +] + +[[package]] +name = "nom" +version = "7.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b1d11e1ef389c76fe5b81bcaf2ea32cf88b62bc494e19f493d0b30e7a930109" +dependencies = [ + "memchr", + "minimal-lexical", + "version_check", +] + +[[package]] +name = "nonempty" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9e591e719385e6ebaeb5ce5d3887f7d5676fceca6411d1925ccc95745f3d6f7" + +[[package]] +name = "ntapi" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" +dependencies = [ + "winapi", +] + +[[package]] +name = "num-derive" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "num-traits" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "num_enum" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "720d3ea1055e4e4574c0c0b0f8c3fd4f24c4cdaf465948206dea090b57b526ad" +dependencies = [ + "num_enum_derive", +] + +[[package]] +name = "num_enum_derive" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d992b768490d7fe0d8586d9b5745f6c49f557da6d81dc982b1d167ad4edbb21" +dependencies = [ + "proc-macro-crate 1.1.0", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "objc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" +dependencies = [ + "malloc_buf", + "objc_exception", +] + +[[package]] +name = "objc-foundation" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9" +dependencies = [ + "block", + "objc", + "objc_id", +] + +[[package]] +name = "objc_exception" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad970fb455818ad6cba4c122ad012fae53ae8b4795f86378bce65e4f6bab2ca4" +dependencies = [ + "cc", +] + +[[package]] +name = "objc_id" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b" +dependencies = [ + "objc", +] + +[[package]] +name = "object" +version = "0.27.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67ac1d3f9a1d3616fd9a60c8d74296f22406a238b6a72f5cc1e6f314df4ffbf9" +dependencies = [ + "memchr", +] + +[[package]] +name = "oboe" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2463c8f2e19b4e0d0710a21f8e4011501ff28db1c95d7a5482a553b2100502d2" +dependencies = [ + "jni", + "ndk 0.6.0", + "ndk-glue 0.6.0", + "num-derive", + "num-traits", + "oboe-sys", +] + +[[package]] +name = "oboe-sys" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3370abb7372ed744232c12954d920d1a40f1c4686de9e79e800021ef492294bd" +dependencies = [ + "cc", +] + +[[package]] +name = "ogg" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6951b4e8bf21c8193da321bcce9c9dd2e13c858fe078bf9054a288b419ae5d6e" +dependencies = [ + "byteorder", +] + +[[package]] +name = "once_cell" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" + +[[package]] +name = "opaque-debug" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" + +[[package]] +name = "ordered-float" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7940cf2ca942593318d07fcf2596cdca60a85c9e7fab408a5e21a4f9dcd40d87" +dependencies = [ + "num-traits", +] + +[[package]] +name = "owned_ttf_parser" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ef05f2882a8b3e7acc10c153ade2631f7bfc8ce00d2bf3fb8f4e9d2ae6ea5c3" +dependencies = [ + "ttf-parser", +] + +[[package]] +name = "page_size" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eebde548fbbf1ea81a99b128872779c437752fb99f217c45245e1a61dcd9edcd" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "palette" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9735f7e1e51a3f740bacd5dc2724b61a7806f23597a8736e679f38ee3435d18" +dependencies = [ + "approx 0.5.0", + "num-traits", + "palette_derive", + "phf", +] + +[[package]] +name = "palette_derive" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7799c3053ea8a6d8a1193c7ba42f534e7863cf52e378a7f90406f4a645d33bad" +dependencies = [ + "find-crate", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "parking_lot" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" +dependencies = [ + "instant", + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" +dependencies = [ + "cfg-if 1.0.0", + "instant", + "libc", + "redox_syscall", + "smallvec", + "winapi", +] + +[[package]] +name = "peeking_take_while" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" + +[[package]] +name = "percent-encoding" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" + +[[package]] +name = "pest" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53" +dependencies = [ + "ucd-trie", +] + +[[package]] +name = "pest_derive" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "833d1ae558dc601e9a60366421196a8d94bc0ac980476d0b67e1d0988d72b2d0" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99b8db626e31e5b81787b9783425769681b347011cc59471e33ea46d2ea0cf55" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pest_meta" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54be6e404f5317079812fc8f9f5279de376d8856929e21c184ecf6bbd692a11d" +dependencies = [ + "maplit", + "pest", + "sha-1", +] + +[[package]] +name = "phf" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ac8b67553a7ca9457ce0e526948cad581819238f4a9d1ea74545851fa24f37" +dependencies = [ + "phf_macros", + "phf_shared", + "proc-macro-hack", +] + +[[package]] +name = "phf_generator" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d43f3220d96e0080cc9ea234978ccd80d904eafb17be31bb0f76daaea6493082" +dependencies = [ + "phf_shared", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b706f5936eb50ed880ae3009395b43ed19db5bff2ebd459c95e7bf013a89ab86" +dependencies = [ + "phf_generator", + "phf_shared", + "proc-macro-hack", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a68318426de33640f02be62b4ae8eb1261be2efbc337b60c54d845bf4484e0d9" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e280fbe77cc62c91527259e9442153f4688736748d24660126286329742b4c6c" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58893f751c9b0412871a09abd62ecd2a00298c6c83befa223ef98c52aef40cbe" + +[[package]] +name = "ppv-lite86" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" + +[[package]] +name = "proc-macro-crate" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785" +dependencies = [ + "toml", +] + +[[package]] +name = "proc-macro-crate" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ebace6889caf889b4d3f76becee12e90353f2b8c7d875534a71e5742f8f6f83" +dependencies = [ + "thiserror", + "toml", +] + +[[package]] +name = "proc-macro-hack" +version = "0.5.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" + +[[package]] +name = "proc-macro2" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "profiling" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9145ac0af1d93c638c98c40cf7d25665f427b2a44ad0a99b1dccf3e2f25bb987" + +[[package]] +name = "quick-xml" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8533f14c8382aaad0d592c812ac3b826162128b65662331e1127b45c3d18536b" +dependencies = [ + "memchr", +] + +[[package]] +name = "quote" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "864d3e96a899863136fc6e99f3d7cae289dafe43bf2c5ac19b70df7210c0a145" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", + "rand_hc", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rand_hc" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7" +dependencies = [ + "rand_core", +] + +[[package]] +name = "range-alloc" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e935c45e09cc6dcf00d2f0b2d630a58f4095320223d47fc68918722f0538b6" + +[[package]] +name = "raw-window-handle" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fba75eee94a9d5273a68c9e1e105d9cffe1ef700532325788389e5a83e2522b7" +dependencies = [ + "cty", +] + +[[package]] +name = "rayon" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06aca804d41dbc8ba42dfd964f0d01334eceb64314b9ecf7c5fad5188a06d90" +dependencies = [ + "autocfg", + "crossbeam-deque", + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d78120e2c850279833f1dd3582f730c4ab53ed95aeaaaa862a2a5c71b1656d8e" +dependencies = [ + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-utils", + "lazy_static", + "num_cpus", +] + +[[package]] +name = "redox_syscall" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff" +dependencies = [ + "bitflags", +] + +[[package]] +name = "redox_users" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64" +dependencies = [ + "getrandom", + "redox_syscall", +] + +[[package]] +name = "regex" +version = "1.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" + +[[package]] +name = "renderdoc-sys" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1382d1f0a252c4bf97dc20d979a2fdd05b024acd7c2ed0f7595d7817666a157" + +[[package]] +name = "roc_std" +version = "0.1.0" +dependencies = [ + "static_assertions 0.1.1", +] + +[[package]] +name = "rodio" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d98f5e557b61525057e2bc142c8cd7f0e70d75dc32852309bec440e6e046bf9" +dependencies = [ + "claxon", + "cpal", + "hound", + "lewton", + "minimp3", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" + +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "ryu" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "scoped-tls" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "serde" +version = "1.0.135" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2cf9235533494ea2ddcdb794665461814781c53f19d87b76e571a1c35acbad2b" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.135" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8dcde03d87d4c973c04be249e7d8f0b35db1c848c487bd43032808e59dd8328d" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_yaml" +version = "0.8.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a521f2940385c165a24ee286aa8599633d162077a54bdcae2a6fd5a7bfa7a0" +dependencies = [ + "indexmap", + "ryu", + "serde", + "yaml-rust", +] + +[[package]] +name = "sha-1" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d94d0bede923b3cea61f3f1ff57ff8cdfd77b400fb8f9998949e0cf04163df" +dependencies = [ + "block-buffer", + "digest", + "fake-simd", + "opaque-debug", +] + +[[package]] +name = "shlex" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2" + +[[package]] +name = "siphasher" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a86232ab60fa71287d7f2ddae4a7073f6b7aac33631c3015abb556f08c6d0a3e" + +[[package]] +name = "slab" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9def91fd1e018fe007022791f865d0ccc9b3a0d5001e01aabb8b40e46000afb5" + +[[package]] +name = "slice-deque" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31ef6ee280cdefba6d2d0b4b78a84a1c1a3f3a4cec98c2d4231c8bc225de0f25" +dependencies = [ + "libc", + "mach", + "winapi", +] + +[[package]] +name = "slotmap" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1e08e261d0e8f5c43123b7adf3e4ca1690d655377ac93a03b2c9d3e98de1342" +dependencies = [ + "version_check", +] + +[[package]] +name = "smallvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" + +[[package]] +name = "smithay-client-toolkit" +version = "0.15.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1325f292209cee78d5035530932422a30aa4c8fda1a16593ac083c1de211e68a" +dependencies = [ + "bitflags", + "calloop", + "dlib", + "lazy_static", + "log", + "memmap2", + "nix 0.22.0", + "pkg-config", + "wayland-client", + "wayland-cursor", + "wayland-protocols", +] + +[[package]] +name = "smithay-clipboard" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "610b551bd25378bfd2b8e7a0fcbd83d427e8f2f6a40c47ae0f70688e9949dd55" +dependencies = [ + "smithay-client-toolkit", + "wayland-client", +] + +[[package]] +name = "snafu" +version = "0.6.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eab12d3c261b2308b0d80c26fffb58d17eba81a4be97890101f416b478c79ca7" +dependencies = [ + "backtrace", + "doc-comment", + "snafu-derive", +] + +[[package]] +name = "snafu-derive" +version = "0.6.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1508efa03c362e23817f96cde18abed596a25219a8b2c66e8db33c03543d315b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "spirv" +version = "0.2.0+1.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "246bfa38fe3db3f1dfc8ca5a2cdeb7348c78be2112740cc0ec8ef18b6d94f830" +dependencies = [ + "bitflags", + "num-traits", +] + +[[package]] +name = "static_assertions" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f406d6ee68db6796e11ffd7b4d171864c58b7451e79ef9460ea33c287a1f89a7" + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "stdweb" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef5430c8e36b713e13b48a9f709cc21e046723fe44ce34587b73a830203b533e" + +[[package]] +name = "strsim" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c" + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "syn" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a65b3f4ffa0092e9887669db0eae07941f023991ab58ea44da8fe8e2d511c6b" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "termcolor" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "thiserror" +version = "1.0.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "threadpool" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa" +dependencies = [ + "num_cpus", +] + +[[package]] +name = "tinyvec" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c1c1d5a42b6245520c249549ec267180beaffcc0615401ac8e31853d4b6d8d2" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" + +[[package]] +name = "toml" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" +dependencies = [ + "serde", +] + +[[package]] +name = "ttf-parser" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ccbe8381883510b6a2d8f1e32905bddd178c11caef8083086d0c0c9ab0ac281" + +[[package]] +name = "twox-hash" +version = "1.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ee73e6e4924fe940354b8d4d98cad5231175d615cd855b758adc658c0aac6a0" +dependencies = [ + "cfg-if 1.0.0", + "rand", + "static_assertions 1.1.0", +] + +[[package]] +name = "typenum" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" + +[[package]] +name = "ucd-trie" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" + +[[package]] +name = "unicode-width" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" + +[[package]] +name = "unicode-xid" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "walkdir" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" +dependencies = [ + "same-file", + "winapi", + "winapi-util", +] + +[[package]] +name = "wasi" +version = "0.10.2+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" + +[[package]] +name = "wasm-bindgen" +version = "0.2.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25f1af7423d8588a3d840681122e72e6a24ddbcb3f0ec385cac0d12d24256c06" +dependencies = [ + "cfg-if 1.0.0", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b21c0df030f5a177f3cba22e9bc4322695ec43e7257d865302900290bcdedca" +dependencies = [ + "bumpalo", + "lazy_static", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2eb6ec270a31b1d3c7e266b999739109abce8b6c87e4b31fcfcd788b65267395" +dependencies = [ + "cfg-if 1.0.0", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f4203d69e40a52ee523b2529a773d5ffc1dc0071801c87b3d270b471b80ed01" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa8a30d46208db204854cadbb5d4baf5fcf8071ba5bf48190c3e59937962ebc" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d958d035c4438e28c70e4321a2911302f10135ce78a9c7834c0cab4123d06a2" + +[[package]] +name = "wayland-client" +version = "0.29.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91223460e73257f697d9e23d401279123d36039a3f7a449e983f123292d4458f" +dependencies = [ + "bitflags", + "downcast-rs", + "libc", + "nix 0.22.0", + "scoped-tls", + "wayland-commons", + "wayland-scanner", + "wayland-sys", +] + +[[package]] +name = "wayland-commons" +version = "0.29.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94f6e5e340d7c13490eca867898c4cec5af56c27a5ffe5c80c6fc4708e22d33e" +dependencies = [ + "nix 0.22.0", + "once_cell", + "smallvec", + "wayland-sys", +] + +[[package]] +name = "wayland-cursor" +version = "0.29.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c52758f13d5e7861fc83d942d3d99bf270c83269575e52ac29e5b73cb956a6bd" +dependencies = [ + "nix 0.22.0", + "wayland-client", + "xcursor", +] + +[[package]] +name = "wayland-protocols" +version = "0.29.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60147ae23303402e41fe034f74fb2c35ad0780ee88a1c40ac09a3be1e7465741" +dependencies = [ + "bitflags", + "wayland-client", + "wayland-commons", + "wayland-scanner", +] + +[[package]] +name = "wayland-scanner" +version = "0.29.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39a1ed3143f7a143187156a2ab52742e89dac33245ba505c17224df48939f9e0" +dependencies = [ + "proc-macro2", + "quote", + "xml-rs", +] + +[[package]] +name = "wayland-sys" +version = "0.29.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9341df79a8975679188e37dab3889bfa57c44ac2cb6da166f519a81cbe452d4" +dependencies = [ + "dlib", + "lazy_static", + "pkg-config", +] + +[[package]] +name = "web-sys" +version = "0.3.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c060b319f29dd25724f09a2ba1418f142f539b2be99fbf4d2d5a8f7330afb8eb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "wgpu" +version = "0.12.0" +source = "git+https://github.com/gfx-rs/wgpu?rev=0545e36#0545e36aa82709cca78c14eb3813f10eea7a9275" +dependencies = [ + "arrayvec", + "js-sys", + "log", + "naga", + "parking_lot", + "raw-window-handle", + "smallvec", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "wgpu-core", + "wgpu-hal", + "wgpu-types", +] + +[[package]] +name = "wgpu-core" +version = "0.12.0" +source = "git+https://github.com/gfx-rs/wgpu?rev=0545e36#0545e36aa82709cca78c14eb3813f10eea7a9275" +dependencies = [ + "arrayvec", + "bitflags", + "cfg_aliases", + "codespan-reporting", + "copyless", + "fxhash", + "log", + "naga", + "parking_lot", + "profiling", + "raw-window-handle", + "smallvec", + "thiserror", + "wgpu-hal", + "wgpu-types", +] + +[[package]] +name = "wgpu-hal" +version = "0.12.0" +source = "git+https://github.com/gfx-rs/wgpu?rev=0545e36#0545e36aa82709cca78c14eb3813f10eea7a9275" +dependencies = [ + "arrayvec", + "ash", + "bit-set", + "bitflags", + "block", + "core-graphics-types", + "d3d12", + "foreign-types", + "fxhash", + "glow", + "gpu-alloc", + "gpu-descriptor", + "inplace_it", + "js-sys", + "khronos-egl", + "libloading", + "log", + "metal", + "naga", + "objc", + "parking_lot", + "profiling", + "range-alloc", + "raw-window-handle", + "renderdoc-sys", + "thiserror", + "wasm-bindgen", + "web-sys", + "wgpu-types", + "winapi", +] + +[[package]] +name = "wgpu-types" +version = "0.12.0" +source = "git+https://github.com/gfx-rs/wgpu?rev=0545e36#0545e36aa82709cca78c14eb3813f10eea7a9275" +dependencies = [ + "bitflags", +] + +[[package]] +name = "wgpu_glyph" +version = "0.16.0" +source = "git+https://github.com/Anton-4/wgpu_glyph?rev=257d109#257d1098cbafa3c8a0a2465937b06fc730fc6ffb" +dependencies = [ + "bytemuck", + "glyph_brush", + "log", + "wgpu", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "winit" +version = "0.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b43cc931d58b99461188607efd7acb2a093e65fc621f54cad78517a6063e73a" +dependencies = [ + "bitflags", + "cocoa", + "core-foundation 0.9.2", + "core-graphics 0.22.3", + "core-video-sys", + "dispatch", + "instant", + "lazy_static", + "libc", + "log", + "mio", + "ndk 0.5.0", + "ndk-glue 0.5.0", + "ndk-sys 0.2.2", + "objc", + "parking_lot", + "percent-encoding", + "raw-window-handle", + "smithay-client-toolkit", + "wasm-bindgen", + "wayland-client", + "wayland-protocols", + "web-sys", + "winapi", + "x11-dl", +] + +[[package]] +name = "x11-clipboard" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "473068b7b80ac86a18328824f1054e5e007898c47b5bbc281bd7abe32bc3653c" +dependencies = [ + "xcb", +] + +[[package]] +name = "x11-dl" +version = "2.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea26926b4ce81a6f5d9d0f3a0bc401e5a37c6ae14a1bfaa8ff6099ca80038c59" +dependencies = [ + "lazy_static", + "libc", + "pkg-config", +] + +[[package]] +name = "xcb" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "771e2b996df720cd1c6dd9ff90f62d91698fd3610cc078388d0564bdd6622a9c" +dependencies = [ + "libc", + "log", + "quick-xml", +] + +[[package]] +name = "xcursor" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "463705a63313cd4301184381c5e8042f0a7e9b4bb63653f216311d4ae74690b7" +dependencies = [ + "nom 7.1.0", +] + +[[package]] +name = "xi-unicode" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a67300977d3dc3f8034dae89778f502b6ba20b269527b3223ba59c0cf393bb8a" + +[[package]] +name = "xml-rs" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2d7d3948613f75c98fd9328cfdcc45acc4d360655289d0a7d4ec931392200a3" + +[[package]] +name = "yaml-rust" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" +dependencies = [ + "linked-hash-map", +] diff --git a/examples/breakout/platform/Cargo.toml b/examples/breakout/platform/Cargo.toml new file mode 100644 index 0000000000..dee9bee179 --- /dev/null +++ b/examples/breakout/platform/Cargo.toml @@ -0,0 +1,75 @@ +[package] +name = "host" +version = "0.1.0" +authors = ["The Roc Contributors"] +license = "UPL-1.0" +edition = "2018" + +# Needed to be able to run on non-Windows systems for some reason. Without this, cargo panics with: +# +# error: DX12 API enabled on non-Windows OS. If your project is not using resolver="2" in Cargo.toml, it should. +resolver = "2" + +[lib] +name = "host" +path = "src/lib.rs" +crate-type = ["staticlib", "rlib"] + +[[bin]] +name = "host" +path = "src/main.rs" + +[dependencies] +roc_std = { path = "../../../roc_std" } +libc = "0.2" +arrayvec = "0.7.2" +page_size = "0.4.2" +# when changing winit version, check if copypasta can be updated simultaneously so they use the same versions for their dependencies. This will save build time. +winit = "0.26.1" +wgpu = { git = "https://github.com/gfx-rs/wgpu", rev = "0545e36" } +wgpu_glyph = { git = "https://github.com/Anton-4/wgpu_glyph", rev = "257d109" } +glyph_brush = "0.7.2" +log = "0.4.14" +env_logger = "0.9.0" +futures = "0.3.17" +cgmath = "0.18.0" +snafu = { version = "0.6.10", features = ["backtraces"] } +colored = "2.0.0" +pest = "2.1.3" +pest_derive = "2.1.0" +copypasta = "0.7.1" +palette = "0.6.0" +confy = { git = 'https://github.com/rust-cli/confy', features = [ + "yaml_conf" +], default-features = false } +serde = { version = "1.0.130", features = ["derive"] } +nonempty = "0.7.0" +fs_extra = "1.2.0" +rodio = { version = "0.14.0", optional = true } # to play sounds +threadpool = "1.8.1" + +[package.metadata.cargo-udeps.ignore] +# confy is currently unused but should not be removed +normal = ["confy"] +#development = [] +#build = [] + +[features] +default = [] +with_sound = ["rodio"] + +[dependencies.bytemuck] +version = "1.7.2" +features = ["derive"] + +[workspace] + +# Optimizations based on https://deterministic.space/high-performance-rust.html +[profile.release] +lto = "thin" +codegen-units = 1 + +# debug = true # enable when profiling +[profile.bench] +lto = "thin" +codegen-units = 1 diff --git a/examples/breakout/platform/Elem.roc b/examples/breakout/platform/Elem.roc new file mode 100644 index 0000000000..519d007b99 --- /dev/null +++ b/examples/breakout/platform/Elem.roc @@ -0,0 +1,193 @@ +interface Elem + exposes [ Elem, PressEvent, row, col, text, button, none, translate, list ] + imports [ Action.{ Action } ] + +Elem state : + # PERFORMANCE NOTE: + # If there are 8 or fewer tags here, then on a 64-bit system, the tag can be stored + # in the pointer - for massive memory savings. Try extremely hard to always limit the number + # of tags in this union to 8 or fewer! + [ + Button (ButtonConfig state) (Elem state), + Text Str, + Col (List (Elem state)), + Row (List (Elem state)), + Lazy (Result { state, elem : Elem state } [ NotCached ] -> { state, elem : Elem state }), + # TODO FIXME: using this definition of Lazy causes a stack overflow in the compiler! + # Lazy (Result (Cached state) [ NotCached ] -> Cached state), + None, + ] + +## Used internally in the type definition of Lazy +Cached state : { state, elem : Elem state } + +ButtonConfig state : { onPress : state, PressEvent -> Action state } + +PressEvent : { button : [ Touch, Mouse [ Left, Right, Middle ] ] } + +text : Str -> Elem * +text = \str -> + Text str + +button : { onPress : state, PressEvent -> Action state }, Elem state -> Elem state +button = \config, label -> + Button config label + +row : List (Elem state) -> Elem state +row = \children -> + Row children + +col : List (Elem state) -> Elem state +col = \children -> + Col children + +lazy : state, (state -> Elem state) -> Elem state +lazy = \state, render -> + # This function gets called by the host during rendering. It will + # receive the cached state and element (wrapped in Ok) if we've + # ever rendered this before, and Err otherwise. + Lazy + \result -> + when result is + Ok cached if cached.state == state -> + # If we have a cached value, and the new state is the + # same as the cached one, then we can return exactly + # what we had cached. + cached + + _ -> + # Either the state changed or else we didn't have a + # cached value to use. Either way, we need to render + # with the new state and store that for future use. + { state, elem: render state } + +none : Elem * +none = None# I've often wanted this in elm/html. Usually end up resorting to (Html.text "") - this seems nicer. +## Change an element's state type. +## +## TODO: indent the following once https://github.com/rtfeldman/roc/issues/2585 is fixed. +## State : { photo : Photo } +## +## render : State -> Elem State +## render = \state -> +## child : Elem State +## child = +## Photo.render state.photo +## |> Elem.translate .photo &photo +## +## col {} [ child, otherElems ] +## +translate = \child, toChild, toParent -> + when child is + Text str -> + Text str + + Col elems -> + Col (List.map elems \elem -> translate elem toChild toParent) + + Row elems -> + Row (List.map elems \elem -> translate elem toChild toParent) + + Button config label -> + onPress = \parentState, event -> + toChild parentState + |> config.onPress event + |> Action.map \c -> toParent parentState c + + Button { onPress } (translate label toChild toParent) + + Lazy renderChild -> + Lazy + \parentState -> + { elem, state } = renderChild (toChild parentState) + + { + elem: translate toChild toParent newChild, + state: toParent parentState state, + } + + None -> + None + +## Render a list of elements, using [Elem.translate] on each of them. +## +## Convenient when you have a [List] in your state and want to make +## a [List] of child elements out of it. +## +## TODO: indent the following once https://github.com/rtfeldman/roc/issues/2585 is fixed. +## State : { photos : List Photo } +## +## render : State -> Elem State +## render = \state -> +## children : List (Elem State) +## children = +## Elem.list Photo.render state .photos &photos +## +## col {} children +## TODO: format as multiline type annotation once https://github.com/rtfeldman/roc/issues/2586 is fixed +list : (child -> Elem child), parent, (parent -> List child), (parent, List child -> parent) -> List (Elem parent) +list = \renderChild, parent, toChildren, toParent -> + List.mapWithIndex + (toChildren parent) + \index, child -> + toChild = \par -> List.get (toChildren par) index + + newChild = translateOrDrop + child + toChild + \par, ch -> + toChildren par + |> List.set ch index + |> toParent + + renderChild newChild + +## Internal helper function for Elem.list +## +## Tries to translate a child to a parent, but +## if the child has been removed from the parent, +## drops it. +## +## TODO: format as multiline type annotation once https://github.com/rtfeldman/roc/issues/2586 is fixed +translateOrDrop : Elem child, (parent -> Result child *), (parent, child -> parent) -> Elem parent +translateOrDrop = \child, toChild, toParent -> + when child is + Text str -> + Text str + + Col elems -> + Col (List.map elems \elem -> translateOrDrop elem toChild toParent) + + Row elems -> + Row (List.map elems \elem -> translateOrDrop elem toChild toParent) + + Button config label -> + onPress = \parentState, event -> + when toChild parentState is + Ok newChild -> + newChild + |> config.onPress event + |> Action.map \c -> toParent parentState c + + Err _ -> + # The child was removed from the list before this onPress handler resolved. + # (For example, by a previous event handler that fired simultaneously.) + Action.none + + Button { onPress } (translateOrDrop label toChild toParent) + + Lazy childState renderChild -> + Lazy + (toParent childState) + \parentState -> + when toChild parentState is + Ok newChild -> + renderChild newChild + |> translateOrDrop toChild toParent + + Err _ -> + None + + # I don't think this should ever happen in practice. + None -> + None diff --git a/examples/breakout/platform/Package-Config.roc b/examples/breakout/platform/Package-Config.roc new file mode 100644 index 0000000000..ab31e1fd6b --- /dev/null +++ b/examples/breakout/platform/Package-Config.roc @@ -0,0 +1,20 @@ +platform "gui" + requires {} { program : Program State } + exposes [] + packages {} + imports [] + provides [ programForHost ] + +Rgba : { r : F32, g : F32, b : F32, a : F32 } + +ButtonStyles : { bgColor : Rgba, borderColor : Rgba, borderWidth : F32, textColor : Rgba } + +Elem : [ Button Elem ButtonStyles, Col (List Elem), Row (List Elem), Text Str ] + +State : { width : F32, height : F32 } + +Program state : { render : state -> Elem } + +# TODO allow changing the title - maybe via Action.setTitle +programForHost : { render : (State -> Elem) as Render } +programForHost = program diff --git a/examples/breakout/platform/host.c b/examples/breakout/platform/host.c new file mode 100644 index 0000000000..b9214bcf33 --- /dev/null +++ b/examples/breakout/platform/host.c @@ -0,0 +1,3 @@ +extern int rust_main(); + +int main() { return rust_main(); } \ No newline at end of file diff --git a/examples/breakout/platform/src/focus.rs b/examples/breakout/platform/src/focus.rs new file mode 100644 index 0000000000..71b46b6b1c --- /dev/null +++ b/examples/breakout/platform/src/focus.rs @@ -0,0 +1,172 @@ +use crate::roc::{ElemId, RocElem, RocElemTag}; + +#[derive(Debug, PartialEq, Eq)] +pub struct Focus { + focused: Option, + focused_ancestors: Vec<(ElemId, usize)>, +} + +impl Default for Focus { + fn default() -> Self { + Self { + focused: None, + focused_ancestors: Vec::new(), + } + } +} + +impl Focus { + pub fn focused_elem(&self) -> Option { + self.focused + } + + /// e.g. the user pressed Tab. + /// + /// This is in contrast to next_local, which advances within a button group. + /// For example, if I have three radio buttons in a group, pressing the + /// arrow keys will cycle through them over and over without exiting the group - + /// whereas pressing Tab will cycle through them once and then exit the group. + pub fn next_global(&mut self, root: &RocElem) { + match self.focused { + Some(focused) => { + // while let Some((ancestor_id, index)) = self.focused_ancestors.pop() { + // let ancestor = ancestor_id.elem(); + + // // TODO FIXME - right now this will re-traverse a lot of ground! To prevent this, + // // we should remember past indices searched, and tell the ancestors "hey stop searching when" + // // you reach these indices, because they were already covered previously. + // // One potentially easy way to do this: pass a min_index and max_index, and only look between those! + // // + // // Related idea: instead of doing .pop() here, iterate normally so we can `break;` after storing + // // `new_ancestors = Some(next_ancestors);` - this way, we still have access to the full ancestry, and + // // can maybe even pass it in to make it clear what work has already been done! + // if let Some((new_id, new_ancestors)) = + // Self::next_focusable_sibling(focused, Some(ancestor), Some(index)) + // { + // // We found the next element to focus, so record that. + // self.focused = Some(new_id); + + // // We got a path to the new focusable's ancestor(s), so add them to the path. + // // (This may restore some of the ancestors we've been .pop()-ing as we iterated.) + // self.focused_ancestors.extend(new_ancestors); + + // return; + // } + + // // Need to write a bunch of tests for this, especially tests of focus wrapping around - e.g. + // // what happens if it wraps around to a sibling? What happens if it wraps around to something + // // higher up the tree? Lower down the tree? What if nothing is focusable? + // // A separate question: what if we should have a separate text-to-speech concept separate from focus? + // } + } + None => { + // Nothing was focused in the first place, so try to focus the root. + if root.is_focusable() { + self.focused = Some(root.id()); + self.focused_ancestors = Vec::new(); + } else if let Some((new_id, new_ancestors)) = + Self::next_focusable_sibling(root, None, None) + { + // If the root itself is not focusable, use its next focusable sibling. + self.focused = Some(new_id); + self.focused_ancestors = new_ancestors; + } + + // Regardless of whether we found a focusable Elem, we're done. + return; + } + } + } + + /// Return the next focusable sibling element after this one. + /// If this element has no siblings, or no *next* sibling after the given index + /// (e.g. the given index refers to the last element in a Row element), return None. + fn next_focusable_sibling( + elem: &RocElem, + ancestor: Option<&RocElem>, + opt_index: Option, + ) -> Option<(ElemId, Vec<(ElemId, usize)>)> { + use RocElemTag::*; + + match elem.tag() { + Button | Text => None, + Row | Col => { + let children = unsafe { &elem.entry().row_or_col.children.as_slice() }; + let iter = match opt_index { + Some(focus_index) => children[0..focus_index].iter(), + None => children.iter(), + }; + + for child in iter { + if let Some(focused) = Self::next_focusable_sibling(child, ancestor, None) { + return Some(focused); + } + } + + None + } + } + } +} + +#[test] +fn next_global_button_root() { + use crate::roc::{ButtonStyles, RocElem}; + + let child = RocElem::text(""); + let root = RocElem::button(ButtonStyles::default(), child); + let mut focus = Focus::default(); + + // At first, nothing should be focused. + assert_eq!(focus.focused_elem(), None); + + focus.next_global(&root); + + // Buttons should be focusable, so advancing focus should give the button focus. + assert_eq!(focus.focused_elem(), Some(root.id())); + + // Since the button is at the root, advancing again should maintain focus on it. + focus.next_global(&root); + assert_eq!(focus.focused_elem(), Some(root.id())); +} + +#[test] +fn next_global_text_root() { + let root = RocElem::text(""); + let mut focus = Focus::default(); + + // At first, nothing should be focused. + assert_eq!(focus.focused_elem(), None); + + focus.next_global(&root); + + // Text should not be focusable, so advancing focus should have no effect here. + assert_eq!(focus.focused_elem(), None); + + // Just to double-check, advancing a second time should not change this. + focus.next_global(&root); + assert_eq!(focus.focused_elem(), None); +} + +#[test] +fn next_global_row() { + use crate::roc::{ButtonStyles, RocElem}; + + let child = RocElem::text(""); + let button = RocElem::button(ButtonStyles::default(), child); + let button_id = button.id(); + let root = RocElem::row(&[button] as &[_]); + let mut focus = Focus::default(); + + // At first, nothing should be focused. + assert_eq!(focus.focused_elem(), None); + + focus.next_global(&root); + + // Buttons should be focusable, so advancing focus should give the first button in the row focus. + assert_eq!(focus.focused_elem(), Some(button_id)); + + // Since the button is the only element in the row, advancing again should maintain focus on it. + focus.next_global(&root); + assert_eq!(focus.focused_elem(), Some(button_id)); +} diff --git a/examples/breakout/platform/src/graphics/colors.rs b/examples/breakout/platform/src/graphics/colors.rs new file mode 100644 index 0000000000..3ec448413f --- /dev/null +++ b/examples/breakout/platform/src/graphics/colors.rs @@ -0,0 +1,50 @@ +use cgmath::Vector4; +use palette::{FromColor, Hsv, Srgb}; + +/// This order is optimized for what Roc will send +#[repr(C)] +#[derive(Copy, Clone, Debug, PartialEq, Default)] +pub struct Rgba { + a: f32, + b: f32, + g: f32, + r: f32, +} + +impl Rgba { + pub const WHITE: Self = Self::new(1.0, 1.0, 1.0, 1.0); + + pub const fn new(r: f32, g: f32, b: f32, a: f32) -> Self { + Self { r, g, b, a } + } + + pub const fn to_array(self) -> [f32; 4] { + [self.r, self.b, self.g, self.a] + } + + pub fn from_hsb(hue: usize, saturation: usize, brightness: usize) -> Self { + Self::from_hsba(hue, saturation, brightness, 1.0) + } + + pub fn from_hsba(hue: usize, saturation: usize, brightness: usize, alpha: f32) -> Self { + let rgb = Srgb::from_color(Hsv::new( + hue as f32, + (saturation as f32) / 100.0, + (brightness as f32) / 100.0, + )); + + Self::new(rgb.red, rgb.green, rgb.blue, alpha) + } +} + +impl From for [f32; 4] { + fn from(rgba: Rgba) -> Self { + rgba.to_array() + } +} + +impl From for Vector4 { + fn from(rgba: Rgba) -> Self { + Vector4::new(rgba.r, rgba.b, rgba.g, rgba.a) + } +} diff --git a/examples/breakout/platform/src/graphics/lowlevel/buffer.rs b/examples/breakout/platform/src/graphics/lowlevel/buffer.rs new file mode 100644 index 0000000000..a5a7f54161 --- /dev/null +++ b/examples/breakout/platform/src/graphics/lowlevel/buffer.rs @@ -0,0 +1,96 @@ +// Contains parts of https://github.com/sotrh/learn-wgpu +// by Benjamin Hansen - license information can be found in the LEGAL_DETAILS +// file in the root directory of this distribution. +// +// Thank you, Benjamin! + +// Contains parts of https://github.com/iced-rs/iced/blob/adce9e04213803bd775538efddf6e7908d1c605e/wgpu/src/shader/quad.wgsl +// By Héctor Ramón, Iced contributors Licensed under the MIT license. +// The license is included in the LEGAL_DETAILS file in the root directory of this distribution. + +// Thank you Héctor Ramón and Iced contributors! + +use std::mem; + +use super::{quad::Quad, vertex::Vertex}; +use crate::graphics::primitives::rect::RectElt; +use wgpu::util::DeviceExt; + +pub struct RectBuffers { + pub vertex_buffer: wgpu::Buffer, + pub index_buffer: wgpu::Buffer, + pub quad_buffer: wgpu::Buffer, +} + +pub const QUAD_INDICES: [u16; 6] = [0, 1, 2, 0, 2, 3]; + +const QUAD_VERTS: [Vertex; 4] = [ + Vertex { + _position: [0.0, 0.0], + }, + Vertex { + _position: [1.0, 0.0], + }, + Vertex { + _position: [1.0, 1.0], + }, + Vertex { + _position: [0.0, 1.0], + }, +]; + +pub const MAX_QUADS: usize = 1_000; + +pub fn create_rect_buffers( + gpu_device: &wgpu::Device, + cmd_encoder: &mut wgpu::CommandEncoder, + rects: &[RectElt], +) -> RectBuffers { + let vertex_buffer = gpu_device.create_buffer_init(&wgpu::util::BufferInitDescriptor { + label: None, + contents: bytemuck::cast_slice(&QUAD_VERTS), + usage: wgpu::BufferUsages::VERTEX, + }); + + let index_buffer = gpu_device.create_buffer_init(&wgpu::util::BufferInitDescriptor { + label: None, + contents: bytemuck::cast_slice(&QUAD_INDICES), + usage: wgpu::BufferUsages::INDEX, + }); + + let quad_buffer = gpu_device.create_buffer(&wgpu::BufferDescriptor { + label: None, + size: mem::size_of::() as u64 * MAX_QUADS as u64, + usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST, + mapped_at_creation: false, + }); + + let quads: Vec = rects.iter().map(|rect| to_quad(rect)).collect(); + + let buffer_size = (quads.len() as u64) * Quad::SIZE; + + let staging_buffer = gpu_device.create_buffer_init(&wgpu::util::BufferInitDescriptor { + label: None, + contents: bytemuck::cast_slice(&quads), + usage: wgpu::BufferUsages::COPY_SRC, + }); + + cmd_encoder.copy_buffer_to_buffer(&staging_buffer, 0, &quad_buffer, 0, buffer_size); + + RectBuffers { + vertex_buffer, + index_buffer, + quad_buffer, + } +} + +pub fn to_quad(rect_elt: &RectElt) -> Quad { + Quad { + pos: rect_elt.rect.pos.into(), + width: rect_elt.rect.width, + height: rect_elt.rect.height, + color: (rect_elt.color.to_array()), + border_color: rect_elt.border_color.into(), + border_width: rect_elt.border_width, + } +} diff --git a/examples/breakout/platform/src/graphics/lowlevel/mod.rs b/examples/breakout/platform/src/graphics/lowlevel/mod.rs new file mode 100644 index 0000000000..0add45385d --- /dev/null +++ b/examples/breakout/platform/src/graphics/lowlevel/mod.rs @@ -0,0 +1,5 @@ +pub mod buffer; +pub mod ortho; +pub mod pipelines; +pub mod vertex; +pub mod quad; diff --git a/examples/breakout/platform/src/graphics/lowlevel/ortho.rs b/examples/breakout/platform/src/graphics/lowlevel/ortho.rs new file mode 100644 index 0000000000..2f4577871a --- /dev/null +++ b/examples/breakout/platform/src/graphics/lowlevel/ortho.rs @@ -0,0 +1,118 @@ +use cgmath::{Matrix4, Ortho}; +use wgpu::util::DeviceExt; +use wgpu::{ + BindGroup, BindGroupLayout, BindGroupLayoutDescriptor, BindGroupLayoutEntry, Buffer, + ShaderStages, +}; + +// orthographic projection is used to transform pixel coords to the coordinate system used by wgpu + +#[repr(C)] +#[derive(Debug, Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)] +struct Uniforms { + // We can't use cgmath with bytemuck directly so we'll have + // to convert the Matrix4 into a 4x4 f32 array + ortho: [[f32; 4]; 4], +} + +impl Uniforms { + fn new(w: u32, h: u32) -> Self { + let ortho: Matrix4 = Ortho:: { + left: 0.0, + right: w as f32, + bottom: h as f32, + top: 0.0, + near: -1.0, + far: 1.0, + } + .into(); + Self { + ortho: ortho.into(), + } + } +} + +// update orthographic buffer according to new window size +pub fn update_ortho_buffer( + inner_width: u32, + inner_height: u32, + gpu_device: &wgpu::Device, + ortho_buffer: &Buffer, + cmd_queue: &wgpu::Queue, +) { + let new_uniforms = Uniforms::new(inner_width, inner_height); + + let new_ortho_buffer = gpu_device.create_buffer_init(&wgpu::util::BufferInitDescriptor { + label: Some("Ortho uniform buffer"), + contents: bytemuck::cast_slice(&[new_uniforms]), + usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_SRC, + }); + + // get a command encoder for the current frame + let mut encoder = gpu_device.create_command_encoder(&wgpu::CommandEncoderDescriptor { + label: Some("Resize"), + }); + + // overwrite the new buffer over the old one + encoder.copy_buffer_to_buffer( + &new_ortho_buffer, + 0, + ortho_buffer, + 0, + (std::mem::size_of::() * vec![new_uniforms].as_slice().len()) + as wgpu::BufferAddress, + ); + + cmd_queue.submit(Some(encoder.finish())); +} + +#[derive(Debug)] +pub struct OrthoResources { + pub buffer: Buffer, + pub bind_group_layout: BindGroupLayout, + pub bind_group: BindGroup, +} + +pub fn init_ortho( + inner_width: u32, + inner_height: u32, + gpu_device: &wgpu::Device, +) -> OrthoResources { + let uniforms = Uniforms::new(inner_width, inner_height); + + let ortho_buffer = gpu_device.create_buffer_init(&wgpu::util::BufferInitDescriptor { + label: Some("Ortho uniform buffer"), + contents: bytemuck::cast_slice(&[uniforms]), + usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, + }); + + // bind groups consist of extra resources that are provided to the shaders + let ortho_bind_group_layout = gpu_device.create_bind_group_layout(&BindGroupLayoutDescriptor { + entries: &[BindGroupLayoutEntry { + binding: 0, + visibility: ShaderStages::VERTEX, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Uniform, + has_dynamic_offset: false, + min_binding_size: None, + }, + count: None, + }], + label: Some("Ortho bind group layout"), + }); + + let ortho_bind_group = gpu_device.create_bind_group(&wgpu::BindGroupDescriptor { + layout: &ortho_bind_group_layout, + entries: &[wgpu::BindGroupEntry { + binding: 0, + resource: ortho_buffer.as_entire_binding(), + }], + label: Some("Ortho bind group"), + }); + + OrthoResources { + buffer: ortho_buffer, + bind_group_layout: ortho_bind_group_layout, + bind_group: ortho_bind_group, + } +} diff --git a/examples/breakout/platform/src/graphics/lowlevel/pipelines.rs b/examples/breakout/platform/src/graphics/lowlevel/pipelines.rs new file mode 100644 index 0000000000..a0dc7908ec --- /dev/null +++ b/examples/breakout/platform/src/graphics/lowlevel/pipelines.rs @@ -0,0 +1,72 @@ +use super::ortho::{init_ortho, OrthoResources}; +use super::quad::Quad; +use super::vertex::Vertex; +use std::borrow::Cow; + +pub struct RectResources { + pub pipeline: wgpu::RenderPipeline, + pub ortho: OrthoResources, +} + +pub fn make_rect_pipeline( + gpu_device: &wgpu::Device, + surface_config: &wgpu::SurfaceConfiguration, +) -> RectResources { + let ortho = init_ortho(surface_config.width, surface_config.height, gpu_device); + + let pipeline_layout = gpu_device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { + label: None, + bind_group_layouts: &[&ortho.bind_group_layout], + push_constant_ranges: &[], + }); + let pipeline = create_render_pipeline( + gpu_device, + &pipeline_layout, + surface_config.format, + &wgpu::ShaderModuleDescriptor { + label: None, + source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("../shaders/quad.wgsl"))), + }, + ); + + RectResources { pipeline, ortho } +} + +pub fn create_render_pipeline( + device: &wgpu::Device, + layout: &wgpu::PipelineLayout, + color_format: wgpu::TextureFormat, + shader_module_desc: &wgpu::ShaderModuleDescriptor, +) -> wgpu::RenderPipeline { + let shader = device.create_shader_module(shader_module_desc); + + device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { + label: Some("Render pipeline"), + layout: Some(layout), + vertex: wgpu::VertexState { + module: &shader, + entry_point: "vs_main", + buffers: &[Vertex::DESC, Quad::DESC], + }, + fragment: Some(wgpu::FragmentState { + module: &shader, + entry_point: "fs_main", + targets: &[wgpu::ColorTargetState { + format: color_format, + blend: Some(wgpu::BlendState { + color: wgpu::BlendComponent { + operation: wgpu::BlendOperation::Add, + src_factor: wgpu::BlendFactor::SrcAlpha, + dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, + }, + alpha: wgpu::BlendComponent::REPLACE, + }), + write_mask: wgpu::ColorWrites::ALL, + }], + }), + primitive: wgpu::PrimitiveState::default(), + depth_stencil: None, + multisample: wgpu::MultisampleState::default(), + multiview: None, + }) +} diff --git a/examples/breakout/platform/src/graphics/lowlevel/quad.rs b/examples/breakout/platform/src/graphics/lowlevel/quad.rs new file mode 100644 index 0000000000..9c1fd85ae6 --- /dev/null +++ b/examples/breakout/platform/src/graphics/lowlevel/quad.rs @@ -0,0 +1,31 @@ + + +/// A polygon with 4 corners +#[derive(Copy, Clone)] +pub struct Quad { + pub pos: [f32; 2], + pub width: f32, + pub height: f32, + pub color: [f32; 4], + pub border_color: [f32; 4], + pub border_width: f32, +} + +unsafe impl bytemuck::Pod for Quad {} +unsafe impl bytemuck::Zeroable for Quad {} + +impl Quad { + pub const SIZE: wgpu::BufferAddress = std::mem::size_of::() as wgpu::BufferAddress; + pub const DESC: wgpu::VertexBufferLayout<'static> = wgpu::VertexBufferLayout { + array_stride: Self::SIZE, + step_mode: wgpu::VertexStepMode::Instance, + attributes: &wgpu::vertex_attr_array!( + 1 => Float32x2, + 2 => Float32, + 3 => Float32, + 4 => Float32x4, + 5 => Float32x4, + 6 => Float32, + ), + }; +} \ No newline at end of file diff --git a/examples/breakout/platform/src/graphics/lowlevel/vertex.rs b/examples/breakout/platform/src/graphics/lowlevel/vertex.rs new file mode 100644 index 0000000000..aa45bb7fb7 --- /dev/null +++ b/examples/breakout/platform/src/graphics/lowlevel/vertex.rs @@ -0,0 +1,35 @@ +// Inspired by https://github.com/sotrh/learn-wgpu +// by Benjamin Hansen - license information can be found in the LEGAL_DETAILS +// file in the root directory of this distribution. +// +// Thank you, Benjamin! + +// Inspired by https://github.com/iced-rs/iced/blob/adce9e04213803bd775538efddf6e7908d1c605e/wgpu/src/shader/quad.wgsl +// By Héctor Ramón, Iced contributors Licensed under the MIT license. +// The license is included in the LEGAL_DETAILS file in the root directory of this distribution. + +// Thank you Héctor Ramón and Iced contributors! +use bytemuck::{Pod, Zeroable}; + + +#[repr(C)] +#[derive(Copy, Clone, Zeroable, Pod)] +pub struct Vertex { + pub _position: [f32; 2], +} + +impl Vertex { + pub const SIZE: wgpu::BufferAddress = std::mem::size_of::() as wgpu::BufferAddress; + pub const DESC: wgpu::VertexBufferLayout<'static> = wgpu::VertexBufferLayout { + array_stride: Self::SIZE, + step_mode: wgpu::VertexStepMode::Vertex, + attributes: &[ + // position + wgpu::VertexAttribute { + offset: 0, + shader_location: 0, + format: wgpu::VertexFormat::Float32x2, + }, + ], + }; +} diff --git a/examples/breakout/platform/src/graphics/mod.rs b/examples/breakout/platform/src/graphics/mod.rs new file mode 100644 index 0000000000..0eb7fcd6da --- /dev/null +++ b/examples/breakout/platform/src/graphics/mod.rs @@ -0,0 +1,4 @@ +pub mod colors; +pub mod lowlevel; +pub mod primitives; +pub mod style; diff --git a/examples/breakout/platform/src/graphics/primitives/mod.rs b/examples/breakout/platform/src/graphics/primitives/mod.rs new file mode 100644 index 0000000000..a9adb18862 --- /dev/null +++ b/examples/breakout/platform/src/graphics/primitives/mod.rs @@ -0,0 +1,2 @@ +pub mod rect; +pub mod text; diff --git a/examples/breakout/platform/src/graphics/primitives/rect.rs b/examples/breakout/platform/src/graphics/primitives/rect.rs new file mode 100644 index 0000000000..8183fc6f7a --- /dev/null +++ b/examples/breakout/platform/src/graphics/primitives/rect.rs @@ -0,0 +1,27 @@ +use crate::graphics::colors::Rgba; +use cgmath::Vector2; + +#[derive(Debug, Copy, Clone)] +pub struct RectElt { + pub rect: Rect, + pub color: Rgba, + pub border_width: f32, + pub border_color: Rgba, +} + +/// These fields are ordered this way because in Roc, the corresponding stuct is: +/// +/// { top : F32, left : F32, width : F32, height : F32 } +/// +/// alphabetically, that's { height, left, top, width } - which works out to the same as: +/// +/// struct Rect { height: f32, pos: Vector2, width: f32 } +/// +/// ...because Vector2 is a repr(C) struct of { x: f32, y: f32 } +#[derive(Debug, Copy, Clone)] +#[repr(C)] +pub struct Rect { + pub height: f32, + pub pos: Vector2, + pub width: f32, +} diff --git a/examples/breakout/platform/src/graphics/primitives/text.rs b/examples/breakout/platform/src/graphics/primitives/text.rs new file mode 100644 index 0000000000..4ecaa28d9b --- /dev/null +++ b/examples/breakout/platform/src/graphics/primitives/text.rs @@ -0,0 +1,134 @@ +// Adapted from https://github.com/sotrh/learn-wgpu +// by Benjamin Hansen - license information can be found in the COPYRIGHT +// file in the root directory of this distribution. +// +// Thank you, Benjamin! + +use crate::graphics::colors::Rgba; +use crate::graphics::style::DEFAULT_FONT_SIZE; +use ab_glyph::{FontArc, InvalidFont}; +use cgmath::Vector2; +use wgpu_glyph::{ab_glyph, GlyphBrush, GlyphBrushBuilder}; + +#[derive(Debug)] +pub struct Text<'a> { + pub position: Vector2, + pub area_bounds: Vector2, + pub color: Rgba, + pub text: &'a str, + pub size: f32, + pub visible: bool, + pub centered: bool, +} + +impl<'a> Default for Text<'a> { + fn default() -> Self { + Self { + position: (0.0, 0.0).into(), + area_bounds: (std::f32::INFINITY, std::f32::INFINITY).into(), + color: Rgba::WHITE, + text: "", + size: DEFAULT_FONT_SIZE, + visible: true, + centered: false, + } + } +} + +// pub fn layout_from_text(text: &Text) -> wgpu_glyph::Layout { +// wgpu_glyph::Layout::default().h_align(if text.centered { +// wgpu_glyph::HorizontalAlign::Center +// } else { +// wgpu_glyph::HorizontalAlign::Left +// }) +// } + +// fn section_from_text<'a>( +// text: &'a Text, +// layout: wgpu_glyph::Layout, +// ) -> wgpu_glyph::Section<'a> { +// Section { +// screen_position: text.position.into(), +// bounds: text.area_bounds.into(), +// layout, +// ..Section::default() +// } +// .add_text( +// wgpu_glyph::Text::new(text.text) +// .with_color(text.color) +// .with_scale(text.size), +// ) +// } + +// pub fn owned_section_from_text(text: &Text) -> OwnedSection { +// let layout = layout_from_text(text); + +// OwnedSection { +// screen_position: text.position.into(), +// bounds: text.area_bounds.into(), +// layout, +// ..OwnedSection::default() +// } +// .add_text( +// glyph_brush::OwnedText::new(text.text) +// .with_color(Vector4::from(text.color)) +// .with_scale(text.size), +// ) +// } + +// pub fn owned_section_from_glyph_texts( +// text: Vec, +// screen_position: (f32, f32), +// area_bounds: (f32, f32), +// layout: wgpu_glyph::Layout, +// ) -> glyph_brush::OwnedSection { +// glyph_brush::OwnedSection { +// screen_position, +// bounds: area_bounds, +// layout, +// text, +// } +// } + +// pub fn queue_text_draw(text: &Text, glyph_brush: &mut GlyphBrush<()>) { +// let layout = layout_from_text(text); + +// let section = section_from_text(text, layout); + +// glyph_brush.queue(section.clone()); +// } + +// fn glyph_to_rect(glyph: &wgpu_glyph::SectionGlyph) -> Rect { +// let position = glyph.glyph.position; +// let px_scale = glyph.glyph.scale; +// let width = glyph_width(&glyph.glyph); +// let height = px_scale.y; +// let top_y = glyph_top_y(&glyph.glyph); + +// Rect { +// pos: [position.x, top_y].into(), +// width, +// height, +// } +// } + +// pub fn glyph_top_y(glyph: &Glyph) -> f32 { +// let height = glyph.scale.y; + +// glyph.position.y - height * 0.75 +// } + +// pub fn glyph_width(glyph: &Glyph) -> f32 { +// glyph.scale.x * 0.4765 +// } + +pub fn build_glyph_brush( + gpu_device: &wgpu::Device, + render_format: wgpu::TextureFormat, +) -> Result, InvalidFont> { + let inconsolata = FontArc::try_from_slice(include_bytes!( + "../../../../../../editor/Inconsolata-Regular.ttf" + ))?; + + Ok(GlyphBrushBuilder::using_font(inconsolata).build(gpu_device, render_format)) +} diff --git a/examples/breakout/platform/src/graphics/shaders/quad.wgsl b/examples/breakout/platform/src/graphics/shaders/quad.wgsl new file mode 100644 index 0000000000..a561e2fc24 --- /dev/null +++ b/examples/breakout/platform/src/graphics/shaders/quad.wgsl @@ -0,0 +1,60 @@ + + +struct Globals { + ortho: mat4x4; +}; + +@group(0) +@binding(0) +var globals: Globals; + +struct VertexInput { + @location(0) position: vec2; +}; + +struct Quad { + @location(1) pos: vec2; // can't use the name "position" twice for compatibility with metal on MacOS + @location(2) width: f32; + @location(3) height: f32; + @location(4) color: vec4; + @location(5) border_color: vec4; + @location(6) border_width: f32; +}; + +struct VertexOutput { + @builtin(position) position: vec4; + @location(0) color: vec4; + @location(1) border_color: vec4; + @location(2) border_width: f32; +}; + +@stage(vertex) +fn vs_main( + input: VertexInput, + quad: Quad +) -> VertexOutput { + + var transform: mat4x4 = mat4x4( + vec4(quad.width, 0.0, 0.0, 0.0), + vec4(0.0, quad.height, 0.0, 0.0), + vec4(0.0, 0.0, 1.0, 0.0), + vec4(quad.pos, 0.0, 1.0) + ); + + var out: VertexOutput; + + out.position = globals.ortho * transform * vec4(input.position, 0.0, 1.0);; + out.color = quad.color; + out.border_color = quad.border_color; + out.border_width = quad.border_width; + + return out; +} + + +@stage(fragment) +fn fs_main( + input: VertexOutput +) -> @location(0) vec4 { + return input.color; +} diff --git a/examples/breakout/platform/src/graphics/style.rs b/examples/breakout/platform/src/graphics/style.rs new file mode 100644 index 0000000000..11e609075b --- /dev/null +++ b/examples/breakout/platform/src/graphics/style.rs @@ -0,0 +1 @@ +pub const DEFAULT_FONT_SIZE: f32 = 30.0; diff --git a/examples/breakout/platform/src/gui.rs b/examples/breakout/platform/src/gui.rs new file mode 100644 index 0000000000..fca0ad3984 --- /dev/null +++ b/examples/breakout/platform/src/gui.rs @@ -0,0 +1,631 @@ +use crate::{ + graphics::{ + colors::Rgba, + lowlevel::buffer::create_rect_buffers, + lowlevel::{buffer::MAX_QUADS, ortho::update_ortho_buffer}, + lowlevel::{buffer::QUAD_INDICES, pipelines}, + primitives::{ + rect::{Rect, RectElt}, + text::build_glyph_brush, + }, + }, + roc::{self, RocElem, RocElemTag}, +}; +use cgmath::{Vector2, Vector4}; +use glyph_brush::OwnedSection; +use pipelines::RectResources; +use std::error::Error; +use wgpu::{CommandEncoder, LoadOp, RenderPass, TextureView}; +use wgpu_glyph::{GlyphBrush, GlyphCruncher}; +use winit::{ + dpi::PhysicalSize, + event, + event::{Event, ModifiersState}, + event_loop::ControlFlow, + platform::run_return::EventLoopExtRunReturn, +}; + +// Inspired by: +// https://github.com/sotrh/learn-wgpu by Benjamin Hansen, which is licensed under the MIT license +// https://github.com/cloudhead/rgx by Alexis Sellier, which is licensed under the MIT license +// +// See this link to learn wgpu: https://sotrh.github.io/learn-wgpu/ + +pub fn run_event_loop(title: &str, state: roc::State) -> Result<(), Box> { + // Open window and create a surface + let mut event_loop = winit::event_loop::EventLoop::new(); + + let window = winit::window::WindowBuilder::new() + .with_inner_size(PhysicalSize::new(state.width, state.height)) + .with_title(title) + .build(&event_loop) + .unwrap(); + + let mut root = roc::app_render(state); + + let instance = wgpu::Instance::new(wgpu::Backends::all()); + + let surface = unsafe { instance.create_surface(&window) }; + + // Initialize GPU + let (gpu_device, cmd_queue) = futures::executor::block_on(async { + let adapter = instance + .request_adapter(&wgpu::RequestAdapterOptions { + power_preference: wgpu::PowerPreference::HighPerformance, + compatible_surface: Some(&surface), + force_fallback_adapter: false, + }) + .await + .expect(r#"Request adapter + If you're running this from inside nix, follow the instructions here to resolve this: https://github.com/rtfeldman/roc/blob/trunk/BUILDING_FROM_SOURCE.md#editor + "#); + + adapter + .request_device( + &wgpu::DeviceDescriptor { + label: None, + features: wgpu::Features::empty(), + limits: wgpu::Limits::default(), + }, + None, + ) + .await + .expect("Request device") + }); + + // Create staging belt and a local pool + let mut staging_belt = wgpu::util::StagingBelt::new(1024); + let mut local_pool = futures::executor::LocalPool::new(); + let local_spawner = local_pool.spawner(); + + // Prepare swap chain + let render_format = wgpu::TextureFormat::Bgra8Unorm; + let mut size = window.inner_size(); + + let surface_config = wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, + format: render_format, + width: size.width, + height: size.height, + present_mode: wgpu::PresentMode::Mailbox, + }; + + surface.configure(&gpu_device, &surface_config); + + let rect_resources = pipelines::make_rect_pipeline(&gpu_device, &surface_config); + + let mut glyph_brush = build_glyph_brush(&gpu_device, render_format)?; + + let is_animating = true; + + let mut keyboard_modifiers = ModifiersState::empty(); + + // Render loop + window.request_redraw(); + + event_loop.run_return(|event, _, control_flow| { + // TODO dynamically switch this on/off depending on whether any + // animations are running. Should conserve CPU usage and battery life! + if is_animating { + *control_flow = ControlFlow::Poll; + } else { + *control_flow = ControlFlow::Wait; + } + + match event { + //Close + Event::WindowEvent { + event: event::WindowEvent::CloseRequested, + .. + } => *control_flow = ControlFlow::Exit, + //Resize + Event::WindowEvent { + event: event::WindowEvent::Resized(new_size), + .. + } => { + size = new_size; + + surface.configure( + &gpu_device, + &wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, + format: render_format, + width: size.width, + height: size.height, + present_mode: wgpu::PresentMode::Mailbox, + }, + ); + + update_ortho_buffer( + size.width, + size.height, + &gpu_device, + &rect_resources.ortho.buffer, + &cmd_queue, + ); + } + // Keyboard input + Event::WindowEvent { + event: + event::WindowEvent::KeyboardInput { + input: + event::KeyboardInput { + virtual_keycode: Some(keycode), + state: input_state, + .. + }, + .. + }, + .. + } => { + use event::ElementState::*; + use event::VirtualKeyCode::*; + + match keycode { + Left => match input_state { + Pressed => println!("Left pressed!"), + Released => println!("Left released!"), + }, + Right => match input_state { + Pressed => println!("Right pressed!"), + Released => println!("Right released!"), + }, + _ => { + println!("Other!"); + } + }; + + root = roc::app_render(roc::State { + height: 0.0, + width: 0.0, + }); + } + //Modifiers Changed + Event::WindowEvent { + event: event::WindowEvent::ModifiersChanged(modifiers), + .. + } => { + keyboard_modifiers = modifiers; + } + Event::MainEventsCleared => window.request_redraw(), + Event::RedrawRequested { .. } => { + // Get a command cmd_encoder for the current frame + let mut cmd_encoder = + gpu_device.create_command_encoder(&wgpu::CommandEncoderDescriptor { + label: Some("Redraw"), + }); + + let surface_texture = surface + .get_current_texture() + .expect("Failed to acquire next SwapChainTexture"); + + let view = surface_texture + .texture + .create_view(&wgpu::TextureViewDescriptor::default()); + + let focus_ancestry: Vec<(*const RocElem, usize)> = Vec::new(); // TODO test that root node can get focus! + let focused_elem: *const RocElem = match focus_ancestry.first() { + Some((ptr_ref, _)) => *ptr_ref, + None => std::ptr::null(), + }; + + let (_bounds, drawable) = to_drawable( + &root, + focused_elem, + Bounds { + width: size.width as f32, + height: size.height as f32, + }, + &mut glyph_brush, + ); + + process_drawable( + drawable, + &mut staging_belt, + &mut glyph_brush, + &mut cmd_encoder, + &view, + &gpu_device, + &rect_resources, + wgpu::LoadOp::Load, + Bounds { + width: size.width as f32, + height: size.height as f32, + }, + ); + + // for text_section in &rects_and_texts.text_sections_front { + // let borrowed_text = text_section.to_borrowed(); + + // glyph_brush.queue(borrowed_text); + // } + + // draw text + // glyph_brush + // .draw_queued( + // &gpu_device, + // &mut staging_belt, + // &mut cmd_encoder, + // &view, + // size.width, + // size.height, + // ) + // .expect("Failed to draw queued text."); + + staging_belt.finish(); + cmd_queue.submit(Some(cmd_encoder.finish())); + surface_texture.present(); + + // Recall unused staging buffers + use futures::task::SpawnExt; + + local_spawner + .spawn(staging_belt.recall()) + .expect("Recall staging belt"); + + local_pool.run_until_stalled(); + } + _ => { + *control_flow = winit::event_loop::ControlFlow::Wait; + } + } + }); + + Ok(()) +} + +fn draw_rects( + all_rects: &[RectElt], + cmd_encoder: &mut CommandEncoder, + texture_view: &TextureView, + gpu_device: &wgpu::Device, + rect_resources: &RectResources, + load_op: LoadOp, +) { + let rect_buffers = create_rect_buffers(gpu_device, cmd_encoder, all_rects); + + let mut render_pass = begin_render_pass(cmd_encoder, texture_view, load_op); + + render_pass.set_pipeline(&rect_resources.pipeline); + render_pass.set_bind_group(0, &rect_resources.ortho.bind_group, &[]); + + render_pass.set_vertex_buffer(0, rect_buffers.vertex_buffer.slice(..)); + render_pass.set_vertex_buffer(1, rect_buffers.quad_buffer.slice(..)); + + render_pass.set_index_buffer( + rect_buffers.index_buffer.slice(..), + wgpu::IndexFormat::Uint16, + ); + + render_pass.draw_indexed(0..QUAD_INDICES.len() as u32, 0, 0..MAX_QUADS as u32); +} + +fn begin_render_pass<'a>( + cmd_encoder: &'a mut CommandEncoder, + texture_view: &'a TextureView, + load_op: LoadOp, +) -> RenderPass<'a> { + cmd_encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + color_attachments: &[wgpu::RenderPassColorAttachment { + view: texture_view, + resolve_target: None, + ops: wgpu::Operations { + load: load_op, + store: true, + }, + }], + depth_stencil_attachment: None, + label: None, + }) +} + +#[derive(Copy, Clone, Debug, Default)] +struct Bounds { + width: f32, + height: f32, +} + +#[derive(Clone, Debug)] +struct Drawable { + bounds: Bounds, + content: DrawableContent, +} + +#[derive(Clone, Debug)] +enum DrawableContent { + /// This stores an actual Section because an earlier step needs to know the bounds of + /// the text, and making a Section is a convenient way to compute those bounds. + Text(OwnedSection, Vector2), + FillRect { + color: Rgba, + border_width: f32, + border_color: Rgba, + }, + Multi(Vec), + Offset(Vec<(Vector2, Drawable)>), +} + +fn process_drawable( + drawable: Drawable, + staging_belt: &mut wgpu::util::StagingBelt, + glyph_brush: &mut GlyphBrush<()>, + cmd_encoder: &mut CommandEncoder, + texture_view: &TextureView, + gpu_device: &wgpu::Device, + rect_resources: &RectResources, + load_op: LoadOp, + texture_size: Bounds, +) { + // TODO iterate through drawables, + // calculating a pos using offset, + // calling draw and updating bounding boxes + let pos: Vector2 = (0.0, 0.0).into(); + + draw( + drawable.bounds, + drawable.content, + pos, + staging_belt, + glyph_brush, + cmd_encoder, + texture_view, + gpu_device, + rect_resources, + load_op, + texture_size, + ); +} + +fn draw( + bounds: Bounds, + content: DrawableContent, + pos: Vector2, + staging_belt: &mut wgpu::util::StagingBelt, + glyph_brush: &mut GlyphBrush<()>, + cmd_encoder: &mut CommandEncoder, + texture_view: &TextureView, + gpu_device: &wgpu::Device, + rect_resources: &RectResources, + load_op: LoadOp, + texture_size: Bounds, +) { + use DrawableContent::*; + + match content { + Text(section, offset) => { + glyph_brush.queue(section.with_screen_position(pos + offset).to_borrowed()); + + glyph_brush + .draw_queued( + gpu_device, + staging_belt, + cmd_encoder, + texture_view, + texture_size.width as u32, // TODO why do we make these be u32 and then cast to f32 in orthorgraphic_projection? + texture_size.height as u32, + ) + .expect("Failed to draw text element"); + } + FillRect { + color, + border_width, + border_color, + } => { + // TODO store all these colors and things in FillRect + let rect_elt = RectElt { + rect: Rect { + pos, + width: bounds.width, + height: bounds.height, + }, + color, + border_width, + border_color, + }; + + // TODO inline draw_rects into here! + draw_rects( + &[rect_elt], + cmd_encoder, + texture_view, + gpu_device, + rect_resources, + load_op, + ); + } + Offset(children) => { + for (offset, child) in children.into_iter() { + draw( + child.bounds, + child.content, + pos + offset, + staging_belt, + glyph_brush, + cmd_encoder, + texture_view, + gpu_device, + rect_resources, + load_op, + texture_size, + ); + } + } + Multi(children) => { + for child in children.into_iter() { + draw( + child.bounds, + child.content, + pos, + staging_belt, + glyph_brush, + cmd_encoder, + texture_view, + gpu_device, + rect_resources, + load_op, + texture_size, + ); + } + } + } +} + +/// focused_elem is the currently-focused element (or NULL if nothing has the focus) +fn to_drawable( + elem: &RocElem, + focused_elem: *const RocElem, + bounds: Bounds, + glyph_brush: &mut GlyphBrush<()>, +) -> (Bounds, Drawable) { + use RocElemTag::*; + + let is_focused = focused_elem == elem as *const RocElem; + + match elem.tag() { + Button => { + let button = unsafe { &elem.entry().button }; + let styles = button.styles; + let (child_bounds, child_drawable) = + to_drawable(&*button.child, focused_elem, bounds, glyph_brush); + + let button_drawable = Drawable { + bounds: child_bounds, + content: DrawableContent::FillRect { + color: styles.bg_color, + border_width: styles.border_width, + border_color: styles.border_color, + }, + }; + + let drawable = Drawable { + bounds: child_bounds, + content: DrawableContent::Multi(vec![button_drawable, child_drawable]), + }; + + (child_bounds, drawable) + } + Text => { + // TODO let text color and font settings inherit from parent + let text = unsafe { &elem.entry().text }; + let is_centered = true; // TODO don't hardcode this + let layout = wgpu_glyph::Layout::default().h_align(if is_centered { + wgpu_glyph::HorizontalAlign::Center + } else { + wgpu_glyph::HorizontalAlign::Left + }); + + let section = owned_section_from_str(text.as_str(), bounds, layout); + + // Calculate the bounds and offset by measuring glyphs + let text_bounds; + let offset; + + match glyph_brush.glyph_bounds(section.to_borrowed()) { + Some(glyph_bounds) => { + text_bounds = Bounds { + width: glyph_bounds.max.x - glyph_bounds.min.x, + height: glyph_bounds.max.y - glyph_bounds.min.y, + }; + + offset = (-glyph_bounds.min.x, -glyph_bounds.min.y).into(); + } + None => { + text_bounds = Bounds { + width: 0.0, + height: 0.0, + }; + + offset = (0.0, 0.0).into(); + } + } + + let drawable = Drawable { + bounds: text_bounds, + content: DrawableContent::Text(section, offset), + }; + + (text_bounds, drawable) + } + Row => { + let row = unsafe { &elem.entry().row_or_col }; + let mut final_bounds = Bounds::default(); + let mut offset: Vector2 = (0.0, 0.0).into(); + let mut offset_entries = Vec::with_capacity(row.children.len()); + + for child in row.children.as_slice().iter() { + let (child_bounds, child_drawable) = + to_drawable(&child, focused_elem, bounds, glyph_brush); + + offset_entries.push((offset, child_drawable)); + + // Make sure the final height is enough to fit this child + final_bounds.height = final_bounds.height.max(child_bounds.height); + + // Add the child's width to the final width + final_bounds.width = final_bounds.width + child_bounds.width; + + // Offset the next child to make sure it appears after this one. + offset.x += child_bounds.width; + } + + ( + final_bounds, + Drawable { + bounds: final_bounds, + content: DrawableContent::Offset(offset_entries), + }, + ) + } + Col => { + let col = unsafe { &elem.entry().row_or_col }; + let mut final_bounds = Bounds::default(); + let mut offset: Vector2 = (0.0, 0.0).into(); + let mut offset_entries = Vec::with_capacity(col.children.len()); + + for child in col.children.as_slice().iter() { + let (child_bounds, child_drawable) = + to_drawable(&child, focused_elem, bounds, glyph_brush); + + offset_entries.push((offset, child_drawable)); + + // Make sure the final width is enough to fit this child + final_bounds.width = final_bounds.width.max(child_bounds.width); + + // Add the child's height to the final height + final_bounds.height = final_bounds.height + child_bounds.height; + + // Offset the next child to make sure it appears after this one. + offset.y += child_bounds.height; + } + + ( + final_bounds, + Drawable { + bounds: final_bounds, + content: DrawableContent::Offset(offset_entries), + }, + ) + } + } +} + +fn owned_section_from_str( + string: &str, + bounds: Bounds, + layout: wgpu_glyph::Layout, +) -> OwnedSection { + // TODO don't hardcode any of this! + let color = Rgba::WHITE; + let size: f32 = 40.0; + + OwnedSection { + bounds: (bounds.width, bounds.height), + layout, + ..OwnedSection::default() + } + .add_text( + glyph_brush::OwnedText::new(string) + .with_color(Vector4::from(color)) + .with_scale(size), + ) +} diff --git a/examples/breakout/platform/src/lib.rs b/examples/breakout/platform/src/lib.rs new file mode 100644 index 0000000000..fb6877881a --- /dev/null +++ b/examples/breakout/platform/src/lib.rs @@ -0,0 +1,17 @@ +mod focus; +mod graphics; +mod gui; +mod roc; + +#[no_mangle] +pub extern "C" fn rust_main() -> i32 { + let state = roc::State { + width: 1900.0, + height: 1000.0, + }; + + gui::run_event_loop("test title", state).expect("Error running event loop"); + + // Exit code + 0 +} diff --git a/examples/breakout/platform/src/main.rs b/examples/breakout/platform/src/main.rs new file mode 100644 index 0000000000..51175f934b --- /dev/null +++ b/examples/breakout/platform/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + std::process::exit(host::rust_main()); +} diff --git a/examples/breakout/platform/src/roc.rs b/examples/breakout/platform/src/roc.rs new file mode 100644 index 0000000000..9a3ca76439 --- /dev/null +++ b/examples/breakout/platform/src/roc.rs @@ -0,0 +1,400 @@ +use crate::graphics::colors::Rgba; +use core::alloc::Layout; +use core::ffi::c_void; +use core::mem::{self, ManuallyDrop}; +use roc_std::{ReferenceCount, RocList, RocStr}; +use std::ffi::CStr; +use std::fmt::Debug; +use std::os::raw::c_char; + +extern "C" { + #[link_name = "roc__programForHost_1_exposed_generic"] + fn roc_program() -> (); + + #[link_name = "roc__programForHost_1_Render_caller"] + fn call_Render(state: *const State, closure_data: *const u8, output: *mut u8) -> RocElem; + + #[link_name = "roc__programForHost_size"] + fn roc_program_size() -> i64; + + #[allow(dead_code)] + #[link_name = "roc__programForHost_1_Render_size"] + fn size_Render() -> i64; + + #[link_name = "roc__programForHost_1_Render_result_size"] + fn size_Render_result() -> i64; +} + +#[derive(Debug)] +#[repr(C)] +pub struct State { + pub height: f32, + pub width: f32, +} + +#[no_mangle] +pub unsafe extern "C" fn roc_alloc(size: usize, _alignment: u32) -> *mut c_void { + return libc::malloc(size); +} + +#[no_mangle] +pub unsafe extern "C" fn roc_realloc( + c_ptr: *mut c_void, + new_size: usize, + _old_size: usize, + _alignment: u32, +) -> *mut c_void { + return libc::realloc(c_ptr, new_size); +} + +#[no_mangle] +pub unsafe extern "C" fn roc_dealloc(c_ptr: *mut c_void, _alignment: u32) { + return libc::free(c_ptr); +} + +#[no_mangle] +pub unsafe extern "C" fn roc_panic(c_ptr: *mut c_void, tag_id: u32) { + match tag_id { + 0 => { + let slice = CStr::from_ptr(c_ptr as *const c_char); + let string = slice.to_str().unwrap(); + eprintln!("Roc hit a panic: {}", string); + std::process::exit(1); + } + _ => todo!(), + } +} + +#[no_mangle] +pub unsafe extern "C" fn roc_memcpy(dst: *mut c_void, src: *mut c_void, n: usize) -> *mut c_void { + libc::memcpy(dst, src, n) +} + +#[no_mangle] +pub unsafe extern "C" fn roc_memset(dst: *mut c_void, c: i32, n: usize) -> *mut c_void { + libc::memset(dst, c, n) +} + +#[repr(transparent)] +#[cfg(target_pointer_width = "64")] // on a 64-bit system, the tag fits in this pointer's spare 3 bits +#[derive(Copy, Clone, Debug, PartialEq, Eq)] +pub struct ElemId(*const RocElemEntry); + +#[repr(transparent)] +#[cfg(target_pointer_width = "64")] // on a 64-bit system, the tag fits in this pointer's spare 3 bits +pub struct RocElem { + entry: *const RocElemEntry, +} + +impl Debug for RocElem { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + use RocElemTag::*; + + match self.tag() { + Button => unsafe { &*self.entry().button }.fmt(f), + Text => unsafe { &*self.entry().text }.fmt(f), + Row => { + let row_or_col = unsafe { &*self.entry().row_or_col }; + + f.debug_struct("RocRow") + .field("children", &row_or_col.children) + .finish() + } + Col => { + let row_or_col = unsafe { &*self.entry().row_or_col }; + + f.debug_struct("RocCol") + .field("children", &row_or_col.children) + .finish() + } + } + } +} + +impl RocElem { + #[allow(unused)] + pub fn id(&self) -> ElemId { + ElemId(self.entry) + } + + #[cfg(target_pointer_width = "64")] + pub fn tag(&self) -> RocElemTag { + // On a 64-bit system, the last 3 bits of the pointer store the tag + unsafe { mem::transmute::((self.entry as u8) & 0b0000_0111) } + } + + #[allow(unused)] + pub fn entry(&self) -> &RocElemEntry { + unsafe { &*self.entry_ptr() } + } + + pub fn entry_ptr(&self) -> *const RocElemEntry { + // On a 64-bit system, the last 3 bits of the pointer store the tag + let cleared = self.entry as usize & !0b111; + + cleared as *const RocElemEntry + } + + // fn diff(self, other: RocElem, patches: &mut Vec<(usize, Patch)>, index: usize) { + // use RocElemTag::*; + + // let tag = self.tag(); + + // if tag != other.tag() { + // // They were totally different elem types! + + // // TODO should we handle Row -> Col or Col -> Row differently? + // // Elm doesn't: https://github.com/elm/virtual-dom/blob/5a5bcf48720bc7d53461b3cd42a9f19f119c5503/src/Elm/Kernel/VirtualDom.js#L714 + // return; + // } + + // match tag { + // Button => unsafe { + // let button_self = &*self.entry().button; + // let button_other = &*other.entry().button; + + // // TODO compute a diff and patch for the button + // }, + // Text => unsafe { + // let str_self = &*self.entry().text; + // let str_other = &*other.entry().text; + + // if str_self != str_other { + // todo!("fix this"); + // // let roc_str = other.entry().text; + // // let patch = Patch::Text(ManuallyDrop::into_inner(roc_str)); + + // // patches.push((index, patch)); + // } + // }, + // Row => unsafe { + // let children_self = &self.entry().row_or_col.children; + // let children_other = &other.entry().row_or_col.children; + + // // TODO diff children + // }, + // Col => unsafe { + // let children_self = &self.entry().row_or_col.children; + // let children_other = &other.entry().row_or_col.children; + + // // TODO diff children + // }, + // } + // } + + #[allow(unused)] + pub fn is_focusable(&self) -> bool { + use RocElemTag::*; + + match self.tag() { + Button => true, + Text | Row | Col => false, + } + } + + #[allow(unused)] + pub fn row>>(children: T) -> RocElem { + Self::elem_from_tag(Self::row_or_col(children), RocElemTag::Row) + } + + #[allow(unused)] + pub fn col>>(children: T) -> RocElem { + Self::elem_from_tag(Self::row_or_col(children), RocElemTag::Col) + } + + fn row_or_col>>(children: T) -> RocElemEntry { + let row_or_col = RocRowOrCol { + children: children.into(), + }; + RocElemEntry { + row_or_col: ManuallyDrop::new(row_or_col), + } + } + + #[allow(unused)] + pub fn button(styles: ButtonStyles, child: RocElem) -> RocElem { + let button = RocButton { + child: ManuallyDrop::new(child), + styles, + }; + let entry = RocElemEntry { + button: ManuallyDrop::new(button), + }; + + Self::elem_from_tag(entry, RocElemTag::Button) + } + + #[allow(unused)] + pub fn text>(into_roc_str: T) -> RocElem { + let entry = RocElemEntry { + text: ManuallyDrop::new(into_roc_str.into()), + }; + + Self::elem_from_tag(entry, RocElemTag::Text) + } + + fn elem_from_tag(entry: RocElemEntry, tag: RocElemTag) -> Self { + let tagged_ptr = unsafe { + let entry_ptr = roc_alloc( + core::mem::size_of_val(&entry), + core::mem::align_of_val(&entry) as u32, + ) as *mut RocElemEntry; + + *entry_ptr = entry; + + entry_ptr as usize | tag as usize + }; + + Self { + entry: tagged_ptr as *const RocElemEntry, + } + } +} + +#[repr(u8)] +#[allow(unused)] // This is actually used, just via a mem::transmute from u8 +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum RocElemTag { + Button = 0, + Col, + Row, + Text, +} + +#[repr(C)] +#[derive(Debug)] +pub struct RocButton { + pub child: ManuallyDrop, + pub styles: ButtonStyles, +} + +#[repr(C)] +pub struct RocRowOrCol { + pub children: RocList, +} + +unsafe impl ReferenceCount for RocElem { + /// Increment the reference count. + fn increment(&self) { + use RocElemTag::*; + + match self.tag() { + Button => unsafe { &*self.entry().button.child }.increment(), + Text => unsafe { &*self.entry().text }.increment(), + Row | Col => { + let children = unsafe { &self.entry().row_or_col.children }; + + for child in children.as_slice().iter() { + child.increment(); + } + } + } + } + + /// Decrement the reference count. + /// + /// # Safety + /// + /// The caller must ensure that `ptr` points to a value with a non-zero + /// reference count. + unsafe fn decrement(ptr: *const Self) { + use RocElemTag::*; + + let elem = &*ptr; + + match elem.tag() { + Button => ReferenceCount::decrement(&*elem.entry().button.child), + Text => ReferenceCount::decrement(&*elem.entry().text), + Row | Col => { + let children = &elem.entry().row_or_col.children; + + for child in children.as_slice().iter() { + ReferenceCount::decrement(child); + } + } + } + } +} + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default)] +pub struct ButtonStyles { + pub bg_color: Rgba, + pub border_color: Rgba, + pub border_width: f32, + pub text_color: Rgba, +} + +#[repr(C)] +pub union RocElemEntry { + pub button: ManuallyDrop, + pub text: ManuallyDrop, + pub row_or_col: ManuallyDrop, +} + +// enum Patch { +// Text(RocStr), +// } + +#[test] +fn make_text() { + let text = RocElem::text("blah"); + + assert_eq!(text.tag(), RocElemTag::Text); +} + +#[test] +fn make_button() { + let text = RocElem::text("blah"); + let button = RocElem::button(ButtonStyles::default(), text); + + assert_eq!(button.tag(), RocElemTag::Button); +} + +#[test] +fn make_row_with_text() { + let text = RocElem::text(""); + let row = RocElem::row(&[text] as &[_]); + + assert_eq!(row.tag(), RocElemTag::Row); +} + +#[test] +fn make_row_with_button() { + let text = RocElem::text(""); + let button = RocElem::button(ButtonStyles::default(), text); + let row = RocElem::row(&[button] as &[_]); + + assert_eq!(row.tag(), RocElemTag::Row); +} + +pub fn app_render(state: State) -> RocElem { + let size = unsafe { roc_program_size() } as usize; + let layout = Layout::array::(size).unwrap(); + + unsafe { + roc_program(); + + // TODO allocate on the stack if it's under a certain size + let buffer = std::alloc::alloc(layout); + + // Call the program's render function + let result = call_the_closure(state, buffer); + + std::alloc::dealloc(buffer, layout); + + result + } +} + +unsafe fn call_the_closure(state: State, closure_data_ptr: *const u8) -> RocElem { + let size = size_Render_result() as usize; + let layout = Layout::array::(size).unwrap(); + let buffer = std::alloc::alloc(layout) as *mut u8; + + let answer = call_Render(&state, closure_data_ptr as *const u8, buffer as *mut u8); + + std::alloc::dealloc(buffer, layout); + + answer +} From fee7fd795605974a7857ce751d30e41ff9a56602 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 4 Apr 2022 11:26:52 -0400 Subject: [PATCH 058/846] =?UTF-8?q?Breakout:=20Button=20=E2=86=92=20Rect?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/breakout/breakout.roc | 14 +- examples/breakout/platform/Package-Config.roc | 2 +- examples/breakout/platform/src/focus.rs | 172 ------------------ examples/breakout/platform/src/gui.rs | 62 +------ examples/breakout/platform/src/lib.rs | 1 - examples/breakout/platform/src/roc.rs | 92 +--------- 6 files changed, 8 insertions(+), 335 deletions(-) delete mode 100644 examples/breakout/platform/src/focus.rs diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index 8ef081fe5c..32be6ec2ef 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -15,16 +15,4 @@ render = \state -> height = if state.height == 1000 then "correct!" else if state.height == 0 then "zero" else "incorrect" width = if state.width == 1900 then "Correct!" else if state.width == 0 then "zero" else "Incorrect" - Col - [ - Row - [ - Button (Text "Corner ") styles, - Button (Text "Top Mid ") { styles & bgColor: rgba 100 100 50 1 }, - Button (Text "Top Right ") { styles & bgColor: rgba 50 50 150 1 }, - ], - Button (Text "Mid Left ") { styles & bgColor: rgba 150 100 100 1 }, - Button (Text "Bottom Left") { styles & bgColor: rgba 150 50 50 1 }, - Button (Text "height: \(height)") { styles & bgColor: rgba 50 150 50 1 }, - Button (Text "width: \(width)") { styles & bgColor: rgba 50 100 50 1 }, - ] + Rect (Text "Success! ") styles diff --git a/examples/breakout/platform/Package-Config.roc b/examples/breakout/platform/Package-Config.roc index ab31e1fd6b..6d9cac1583 100644 --- a/examples/breakout/platform/Package-Config.roc +++ b/examples/breakout/platform/Package-Config.roc @@ -9,7 +9,7 @@ Rgba : { r : F32, g : F32, b : F32, a : F32 } ButtonStyles : { bgColor : Rgba, borderColor : Rgba, borderWidth : F32, textColor : Rgba } -Elem : [ Button Elem ButtonStyles, Col (List Elem), Row (List Elem), Text Str ] +Elem : [ Rect Elem ButtonStyles, Text Str ] State : { width : F32, height : F32 } diff --git a/examples/breakout/platform/src/focus.rs b/examples/breakout/platform/src/focus.rs deleted file mode 100644 index 71b46b6b1c..0000000000 --- a/examples/breakout/platform/src/focus.rs +++ /dev/null @@ -1,172 +0,0 @@ -use crate::roc::{ElemId, RocElem, RocElemTag}; - -#[derive(Debug, PartialEq, Eq)] -pub struct Focus { - focused: Option, - focused_ancestors: Vec<(ElemId, usize)>, -} - -impl Default for Focus { - fn default() -> Self { - Self { - focused: None, - focused_ancestors: Vec::new(), - } - } -} - -impl Focus { - pub fn focused_elem(&self) -> Option { - self.focused - } - - /// e.g. the user pressed Tab. - /// - /// This is in contrast to next_local, which advances within a button group. - /// For example, if I have three radio buttons in a group, pressing the - /// arrow keys will cycle through them over and over without exiting the group - - /// whereas pressing Tab will cycle through them once and then exit the group. - pub fn next_global(&mut self, root: &RocElem) { - match self.focused { - Some(focused) => { - // while let Some((ancestor_id, index)) = self.focused_ancestors.pop() { - // let ancestor = ancestor_id.elem(); - - // // TODO FIXME - right now this will re-traverse a lot of ground! To prevent this, - // // we should remember past indices searched, and tell the ancestors "hey stop searching when" - // // you reach these indices, because they were already covered previously. - // // One potentially easy way to do this: pass a min_index and max_index, and only look between those! - // // - // // Related idea: instead of doing .pop() here, iterate normally so we can `break;` after storing - // // `new_ancestors = Some(next_ancestors);` - this way, we still have access to the full ancestry, and - // // can maybe even pass it in to make it clear what work has already been done! - // if let Some((new_id, new_ancestors)) = - // Self::next_focusable_sibling(focused, Some(ancestor), Some(index)) - // { - // // We found the next element to focus, so record that. - // self.focused = Some(new_id); - - // // We got a path to the new focusable's ancestor(s), so add them to the path. - // // (This may restore some of the ancestors we've been .pop()-ing as we iterated.) - // self.focused_ancestors.extend(new_ancestors); - - // return; - // } - - // // Need to write a bunch of tests for this, especially tests of focus wrapping around - e.g. - // // what happens if it wraps around to a sibling? What happens if it wraps around to something - // // higher up the tree? Lower down the tree? What if nothing is focusable? - // // A separate question: what if we should have a separate text-to-speech concept separate from focus? - // } - } - None => { - // Nothing was focused in the first place, so try to focus the root. - if root.is_focusable() { - self.focused = Some(root.id()); - self.focused_ancestors = Vec::new(); - } else if let Some((new_id, new_ancestors)) = - Self::next_focusable_sibling(root, None, None) - { - // If the root itself is not focusable, use its next focusable sibling. - self.focused = Some(new_id); - self.focused_ancestors = new_ancestors; - } - - // Regardless of whether we found a focusable Elem, we're done. - return; - } - } - } - - /// Return the next focusable sibling element after this one. - /// If this element has no siblings, or no *next* sibling after the given index - /// (e.g. the given index refers to the last element in a Row element), return None. - fn next_focusable_sibling( - elem: &RocElem, - ancestor: Option<&RocElem>, - opt_index: Option, - ) -> Option<(ElemId, Vec<(ElemId, usize)>)> { - use RocElemTag::*; - - match elem.tag() { - Button | Text => None, - Row | Col => { - let children = unsafe { &elem.entry().row_or_col.children.as_slice() }; - let iter = match opt_index { - Some(focus_index) => children[0..focus_index].iter(), - None => children.iter(), - }; - - for child in iter { - if let Some(focused) = Self::next_focusable_sibling(child, ancestor, None) { - return Some(focused); - } - } - - None - } - } - } -} - -#[test] -fn next_global_button_root() { - use crate::roc::{ButtonStyles, RocElem}; - - let child = RocElem::text(""); - let root = RocElem::button(ButtonStyles::default(), child); - let mut focus = Focus::default(); - - // At first, nothing should be focused. - assert_eq!(focus.focused_elem(), None); - - focus.next_global(&root); - - // Buttons should be focusable, so advancing focus should give the button focus. - assert_eq!(focus.focused_elem(), Some(root.id())); - - // Since the button is at the root, advancing again should maintain focus on it. - focus.next_global(&root); - assert_eq!(focus.focused_elem(), Some(root.id())); -} - -#[test] -fn next_global_text_root() { - let root = RocElem::text(""); - let mut focus = Focus::default(); - - // At first, nothing should be focused. - assert_eq!(focus.focused_elem(), None); - - focus.next_global(&root); - - // Text should not be focusable, so advancing focus should have no effect here. - assert_eq!(focus.focused_elem(), None); - - // Just to double-check, advancing a second time should not change this. - focus.next_global(&root); - assert_eq!(focus.focused_elem(), None); -} - -#[test] -fn next_global_row() { - use crate::roc::{ButtonStyles, RocElem}; - - let child = RocElem::text(""); - let button = RocElem::button(ButtonStyles::default(), child); - let button_id = button.id(); - let root = RocElem::row(&[button] as &[_]); - let mut focus = Focus::default(); - - // At first, nothing should be focused. - assert_eq!(focus.focused_elem(), None); - - focus.next_global(&root); - - // Buttons should be focusable, so advancing focus should give the first button in the row focus. - assert_eq!(focus.focused_elem(), Some(button_id)); - - // Since the button is the only element in the row, advancing again should maintain focus on it. - focus.next_global(&root); - assert_eq!(focus.focused_elem(), Some(button_id)); -} diff --git a/examples/breakout/platform/src/gui.rs b/examples/breakout/platform/src/gui.rs index fca0ad3984..4aaf22e3c4 100644 --- a/examples/breakout/platform/src/gui.rs +++ b/examples/breakout/platform/src/gui.rs @@ -482,7 +482,7 @@ fn to_drawable( let is_focused = focused_elem == elem as *const RocElem; match elem.tag() { - Button => { + Rect => { let button = unsafe { &elem.entry().button }; let styles = button.styles; let (child_bounds, child_drawable) = @@ -546,66 +546,6 @@ fn to_drawable( (text_bounds, drawable) } - Row => { - let row = unsafe { &elem.entry().row_or_col }; - let mut final_bounds = Bounds::default(); - let mut offset: Vector2 = (0.0, 0.0).into(); - let mut offset_entries = Vec::with_capacity(row.children.len()); - - for child in row.children.as_slice().iter() { - let (child_bounds, child_drawable) = - to_drawable(&child, focused_elem, bounds, glyph_brush); - - offset_entries.push((offset, child_drawable)); - - // Make sure the final height is enough to fit this child - final_bounds.height = final_bounds.height.max(child_bounds.height); - - // Add the child's width to the final width - final_bounds.width = final_bounds.width + child_bounds.width; - - // Offset the next child to make sure it appears after this one. - offset.x += child_bounds.width; - } - - ( - final_bounds, - Drawable { - bounds: final_bounds, - content: DrawableContent::Offset(offset_entries), - }, - ) - } - Col => { - let col = unsafe { &elem.entry().row_or_col }; - let mut final_bounds = Bounds::default(); - let mut offset: Vector2 = (0.0, 0.0).into(); - let mut offset_entries = Vec::with_capacity(col.children.len()); - - for child in col.children.as_slice().iter() { - let (child_bounds, child_drawable) = - to_drawable(&child, focused_elem, bounds, glyph_brush); - - offset_entries.push((offset, child_drawable)); - - // Make sure the final width is enough to fit this child - final_bounds.width = final_bounds.width.max(child_bounds.width); - - // Add the child's height to the final height - final_bounds.height = final_bounds.height + child_bounds.height; - - // Offset the next child to make sure it appears after this one. - offset.y += child_bounds.height; - } - - ( - final_bounds, - Drawable { - bounds: final_bounds, - content: DrawableContent::Offset(offset_entries), - }, - ) - } } } diff --git a/examples/breakout/platform/src/lib.rs b/examples/breakout/platform/src/lib.rs index fb6877881a..f403a5a02c 100644 --- a/examples/breakout/platform/src/lib.rs +++ b/examples/breakout/platform/src/lib.rs @@ -1,4 +1,3 @@ -mod focus; mod graphics; mod gui; mod roc; diff --git a/examples/breakout/platform/src/roc.rs b/examples/breakout/platform/src/roc.rs index 9a3ca76439..1e0a390926 100644 --- a/examples/breakout/platform/src/roc.rs +++ b/examples/breakout/platform/src/roc.rs @@ -93,20 +93,6 @@ impl Debug for RocElem { match self.tag() { Button => unsafe { &*self.entry().button }.fmt(f), Text => unsafe { &*self.entry().text }.fmt(f), - Row => { - let row_or_col = unsafe { &*self.entry().row_or_col }; - - f.debug_struct("RocRow") - .field("children", &row_or_col.children) - .finish() - } - Col => { - let row_or_col = unsafe { &*self.entry().row_or_col }; - - f.debug_struct("RocCol") - .field("children", &row_or_col.children) - .finish() - } } } } @@ -182,35 +168,6 @@ impl RocElem { // } // } - #[allow(unused)] - pub fn is_focusable(&self) -> bool { - use RocElemTag::*; - - match self.tag() { - Button => true, - Text | Row | Col => false, - } - } - - #[allow(unused)] - pub fn row>>(children: T) -> RocElem { - Self::elem_from_tag(Self::row_or_col(children), RocElemTag::Row) - } - - #[allow(unused)] - pub fn col>>(children: T) -> RocElem { - Self::elem_from_tag(Self::row_or_col(children), RocElemTag::Col) - } - - fn row_or_col>>(children: T) -> RocElemEntry { - let row_or_col = RocRowOrCol { - children: children.into(), - }; - RocElemEntry { - row_or_col: ManuallyDrop::new(row_or_col), - } - } - #[allow(unused)] pub fn button(styles: ButtonStyles, child: RocElem) -> RocElem { let button = RocButton { @@ -221,7 +178,7 @@ impl RocElem { button: ManuallyDrop::new(button), }; - Self::elem_from_tag(entry, RocElemTag::Button) + Self::elem_from_tag(entry, RocElemTag::Rect) } #[allow(unused)] @@ -255,9 +212,7 @@ impl RocElem { #[allow(unused)] // This is actually used, just via a mem::transmute from u8 #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum RocElemTag { - Button = 0, - Col, - Row, + Rect = 0, Text, } @@ -268,26 +223,14 @@ pub struct RocButton { pub styles: ButtonStyles, } -#[repr(C)] -pub struct RocRowOrCol { - pub children: RocList, -} - unsafe impl ReferenceCount for RocElem { /// Increment the reference count. fn increment(&self) { use RocElemTag::*; match self.tag() { - Button => unsafe { &*self.entry().button.child }.increment(), + Rect => unsafe { &*self.entry().button.child }.increment(), Text => unsafe { &*self.entry().text }.increment(), - Row | Col => { - let children = unsafe { &self.entry().row_or_col.children }; - - for child in children.as_slice().iter() { - child.increment(); - } - } } } @@ -303,15 +246,8 @@ unsafe impl ReferenceCount for RocElem { let elem = &*ptr; match elem.tag() { - Button => ReferenceCount::decrement(&*elem.entry().button.child), + Rect => ReferenceCount::decrement(&*elem.entry().button.child), Text => ReferenceCount::decrement(&*elem.entry().text), - Row | Col => { - let children = &elem.entry().row_or_col.children; - - for child in children.as_slice().iter() { - ReferenceCount::decrement(child); - } - } } } } @@ -329,7 +265,6 @@ pub struct ButtonStyles { pub union RocElemEntry { pub button: ManuallyDrop, pub text: ManuallyDrop, - pub row_or_col: ManuallyDrop, } // enum Patch { @@ -348,24 +283,7 @@ fn make_button() { let text = RocElem::text("blah"); let button = RocElem::button(ButtonStyles::default(), text); - assert_eq!(button.tag(), RocElemTag::Button); -} - -#[test] -fn make_row_with_text() { - let text = RocElem::text(""); - let row = RocElem::row(&[text] as &[_]); - - assert_eq!(row.tag(), RocElemTag::Row); -} - -#[test] -fn make_row_with_button() { - let text = RocElem::text(""); - let button = RocElem::button(ButtonStyles::default(), text); - let row = RocElem::row(&[button] as &[_]); - - assert_eq!(row.tag(), RocElemTag::Row); + assert_eq!(button.tag(), RocElemTag::Rect); } pub fn app_render(state: State) -> RocElem { From 0e187469c208295a3ba53aeef9addf405149604e Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 4 Apr 2022 13:51:33 -0400 Subject: [PATCH 059/846] wip --- examples/breakout/.gitignore | 2 +- examples/breakout/breakout.roc | 8 +- examples/breakout/platform/Package-Config.roc | 4 +- examples/breakout/platform/src/gui.rs | 168 +++++----------- examples/breakout/platform/src/roc.rs | 188 +++++------------- 5 files changed, 109 insertions(+), 261 deletions(-) diff --git a/examples/breakout/.gitignore b/examples/breakout/.gitignore index 8f5562e399..593993d712 100644 --- a/examples/breakout/.gitignore +++ b/examples/breakout/.gitignore @@ -1 +1 @@ -hello-gui +breakout diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index 32be6ec2ef..06935acb4c 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -1,4 +1,4 @@ -app "hello-gui" +app "breakout" packages { pf: "platform" } imports []# [ pf.Action.{ Action }, pf.Elem.{ button, text, row, col } ] provides [ program ] to pf @@ -12,7 +12,5 @@ render = \state -> styles = { bgColor: rgba 100 50 50 1, borderColor: rgba 10 20 30 1, borderWidth: 10, textColor: rgba 220 220 250 1 } - height = if state.height == 1000 then "correct!" else if state.height == 0 then "zero" else "incorrect" - width = if state.width == 1900 then "Correct!" else if state.width == 0 then "zero" else "Incorrect" - - Rect (Text "Success! ") styles + #Text "Hello!" + Rect { r: 1, g: 2, b: 3, a: 4 } diff --git a/examples/breakout/platform/Package-Config.roc b/examples/breakout/platform/Package-Config.roc index 6d9cac1583..31d1d97d81 100644 --- a/examples/breakout/platform/Package-Config.roc +++ b/examples/breakout/platform/Package-Config.roc @@ -9,12 +9,12 @@ Rgba : { r : F32, g : F32, b : F32, a : F32 } ButtonStyles : { bgColor : Rgba, borderColor : Rgba, borderWidth : F32, textColor : Rgba } -Elem : [ Rect Elem ButtonStyles, Text Str ] +Elem : [ Rect Rgba, Text Str ] State : { width : F32, height : F32 } Program state : { render : state -> Elem } -# TODO allow changing the title - maybe via Action.setTitle +# TODO allow changing the window title - maybe via a Task, since that shouldn't happen all the time programForHost : { render : (State -> Elem) as Render } programForHost = program diff --git a/examples/breakout/platform/src/gui.rs b/examples/breakout/platform/src/gui.rs index 4aaf22e3c4..69f5f0786b 100644 --- a/examples/breakout/platform/src/gui.rs +++ b/examples/breakout/platform/src/gui.rs @@ -176,8 +176,8 @@ pub fn run_event_loop(title: &str, state: roc::State) -> Result<(), Box Result<(), Box = Vec::new(); // TODO test that root node can get focus! - let focused_elem: *const RocElem = match focus_ancestry.first() { - Some((ptr_ref, _)) => *ptr_ref, - None => std::ptr::null(), - }; + dbg!(&root.tag()); + dbg!(&root); let (_bounds, drawable) = to_drawable( &root, - focused_elem, Bounds { width: size.width as f32, height: size.height as f32, @@ -234,24 +230,6 @@ pub fn run_event_loop(title: &str, state: roc::State) -> Result<(), Box), - Offset(Vec<(Vector2, Drawable)>), } fn process_drawable( @@ -433,118 +409,80 @@ fn draw( load_op, ); } - Offset(children) => { - for (offset, child) in children.into_iter() { - draw( - child.bounds, - child.content, - pos + offset, - staging_belt, - glyph_brush, - cmd_encoder, - texture_view, - gpu_device, - rect_resources, - load_op, - texture_size, - ); - } - } - Multi(children) => { - for child in children.into_iter() { - draw( - child.bounds, - child.content, - pos, - staging_belt, - glyph_brush, - cmd_encoder, - texture_view, - gpu_device, - rect_resources, - load_op, - texture_size, - ); - } - } } } /// focused_elem is the currently-focused element (or NULL if nothing has the focus) fn to_drawable( elem: &RocElem, - focused_elem: *const RocElem, bounds: Bounds, glyph_brush: &mut GlyphBrush<()>, ) -> (Bounds, Drawable) { use RocElemTag::*; - let is_focused = focused_elem == elem as *const RocElem; - match elem.tag() { Rect => { - let button = unsafe { &elem.entry().button }; - let styles = button.styles; - let (child_bounds, child_drawable) = - to_drawable(&*button.child, focused_elem, bounds, glyph_brush); + todo!("restore RECT") + // let rect = unsafe { &elem.entry().rect }; + // let styles = rect.styles; - let button_drawable = Drawable { - bounds: child_bounds, - content: DrawableContent::FillRect { - color: styles.bg_color, - border_width: styles.border_width, - border_color: styles.border_color, - }, - }; + // let bounds = Bounds { + // width: 500.0, + // height: 300.0, + // }; - let drawable = Drawable { - bounds: child_bounds, - content: DrawableContent::Multi(vec![button_drawable, child_drawable]), - }; + // let drawable = Drawable { + // bounds, + // content: DrawableContent::FillRect { + // color: styles.bg_color, + // border_width: styles.border_width, + // border_color: styles.border_color, + // }, + // }; - (child_bounds, drawable) + // (bounds, drawable) } Text => { - // TODO let text color and font settings inherit from parent - let text = unsafe { &elem.entry().text }; - let is_centered = true; // TODO don't hardcode this - let layout = wgpu_glyph::Layout::default().h_align(if is_centered { - wgpu_glyph::HorizontalAlign::Center - } else { - wgpu_glyph::HorizontalAlign::Left - }); + todo!("restore TEXT") + // let text = unsafe { &elem.entry().text }; + // let is_centered = true; // TODO don't hardcode this + // let layout = wgpu_glyph::Layout::default().h_align(if is_centered { + // wgpu_glyph::HorizontalAlign::Center + // } else { + // wgpu_glyph::HorizontalAlign::Left + // }); - let section = owned_section_from_str(text.as_str(), bounds, layout); + // let section = owned_section_from_str(text.as_str(), bounds, layout); - // Calculate the bounds and offset by measuring glyphs - let text_bounds; - let offset; + // // Calculate the bounds and offset by measuring glyphs + // let text_bounds; + // let offset; - match glyph_brush.glyph_bounds(section.to_borrowed()) { - Some(glyph_bounds) => { - text_bounds = Bounds { - width: glyph_bounds.max.x - glyph_bounds.min.x, - height: glyph_bounds.max.y - glyph_bounds.min.y, - }; + // match glyph_brush.glyph_bounds(section.to_borrowed()) { + // Some(glyph_bounds) => { + // text_bounds = Bounds { + // width: glyph_bounds.max.x - glyph_bounds.min.x, + // height: glyph_bounds.max.y - glyph_bounds.min.y, + // }; - offset = (-glyph_bounds.min.x, -glyph_bounds.min.y).into(); - } - None => { - text_bounds = Bounds { - width: 0.0, - height: 0.0, - }; + // offset = (-glyph_bounds.min.x, -glyph_bounds.min.y).into(); + // } + // None => { + // text_bounds = Bounds { + // width: 0.0, + // height: 0.0, + // }; - offset = (0.0, 0.0).into(); - } - } + // offset = (0.0, 0.0).into(); + // } + // } - let drawable = Drawable { - bounds: text_bounds, - content: DrawableContent::Text(section, offset), - }; + // let drawable = Drawable { + // bounds: text_bounds, + // content: DrawableContent::Text(section, offset), + // }; - (text_bounds, drawable) + // (text_bounds, drawable) } } } diff --git a/examples/breakout/platform/src/roc.rs b/examples/breakout/platform/src/roc.rs index 1e0a390926..ab25cb4512 100644 --- a/examples/breakout/platform/src/roc.rs +++ b/examples/breakout/platform/src/roc.rs @@ -1,10 +1,11 @@ use crate::graphics::colors::Rgba; use core::alloc::Layout; use core::ffi::c_void; -use core::mem::{self, ManuallyDrop}; -use roc_std::{ReferenceCount, RocList, RocStr}; +use core::mem::ManuallyDrop; +use roc_std::{ReferenceCount, RocStr}; use std::ffi::CStr; use std::fmt::Debug; +use std::mem::MaybeUninit; use std::os::raw::c_char; extern "C" { @@ -12,7 +13,7 @@ extern "C" { fn roc_program() -> (); #[link_name = "roc__programForHost_1_Render_caller"] - fn call_Render(state: *const State, closure_data: *const u8, output: *mut u8) -> RocElem; + fn call_Render(state: *const State, closure_data: *const u8, output: *mut RocElem); #[link_name = "roc__programForHost_size"] fn roc_program_size() -> i64; @@ -80,10 +81,24 @@ pub unsafe extern "C" fn roc_memset(dst: *mut c_void, c: i32, n: usize) -> *mut #[derive(Copy, Clone, Debug, PartialEq, Eq)] pub struct ElemId(*const RocElemEntry); -#[repr(transparent)] +#[repr(C)] +pub union RocElemEntry { + pub rect: ManuallyDrop, + pub text: ManuallyDrop, +} + +#[repr(u8)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum RocElemTag { + Rect = 0, + Text = 1, +} + +#[repr(C)] #[cfg(target_pointer_width = "64")] // on a 64-bit system, the tag fits in this pointer's spare 3 bits pub struct RocElem { - entry: *const RocElemEntry, + entry: RocElemEntry, + tag: RocElemTag, } impl Debug for RocElem { @@ -91,135 +106,52 @@ impl Debug for RocElem { use RocElemTag::*; match self.tag() { - Button => unsafe { &*self.entry().button }.fmt(f), + Rect => unsafe { &*self.entry().rect }.fmt(f), Text => unsafe { &*self.entry().text }.fmt(f), } } } impl RocElem { - #[allow(unused)] - pub fn id(&self) -> ElemId { - ElemId(self.entry) - } - #[cfg(target_pointer_width = "64")] pub fn tag(&self) -> RocElemTag { - // On a 64-bit system, the last 3 bits of the pointer store the tag - unsafe { mem::transmute::((self.entry as u8) & 0b0000_0111) } + self.tag } #[allow(unused)] pub fn entry(&self) -> &RocElemEntry { - unsafe { &*self.entry_ptr() } + &self.entry } - pub fn entry_ptr(&self) -> *const RocElemEntry { - // On a 64-bit system, the last 3 bits of the pointer store the tag - let cleared = self.entry as usize & !0b111; - - cleared as *const RocElemEntry - } - - // fn diff(self, other: RocElem, patches: &mut Vec<(usize, Patch)>, index: usize) { - // use RocElemTag::*; - - // let tag = self.tag(); - - // if tag != other.tag() { - // // They were totally different elem types! - - // // TODO should we handle Row -> Col or Col -> Row differently? - // // Elm doesn't: https://github.com/elm/virtual-dom/blob/5a5bcf48720bc7d53461b3cd42a9f19f119c5503/src/Elm/Kernel/VirtualDom.js#L714 - // return; - // } - - // match tag { - // Button => unsafe { - // let button_self = &*self.entry().button; - // let button_other = &*other.entry().button; - - // // TODO compute a diff and patch for the button - // }, - // Text => unsafe { - // let str_self = &*self.entry().text; - // let str_other = &*other.entry().text; - - // if str_self != str_other { - // todo!("fix this"); - // // let roc_str = other.entry().text; - // // let patch = Patch::Text(ManuallyDrop::into_inner(roc_str)); - - // // patches.push((index, patch)); - // } - // }, - // Row => unsafe { - // let children_self = &self.entry().row_or_col.children; - // let children_other = &other.entry().row_or_col.children; - - // // TODO diff children - // }, - // Col => unsafe { - // let children_self = &self.entry().row_or_col.children; - // let children_other = &other.entry().row_or_col.children; - - // // TODO diff children - // }, - // } - // } - #[allow(unused)] - pub fn button(styles: ButtonStyles, child: RocElem) -> RocElem { - let button = RocButton { - child: ManuallyDrop::new(child), - styles, - }; - let entry = RocElemEntry { - button: ManuallyDrop::new(button), - }; + pub fn rect(styles: ButtonStyles) -> RocElem { + todo!("restore rect() method") + // let rect = RocRect { styles }; + // let entry = RocElemEntry { + // rect: ManuallyDrop::new(rect), + // }; - Self::elem_from_tag(entry, RocElemTag::Rect) + // Self::elem_from_tag(entry, RocElemTag::Rect) } #[allow(unused)] pub fn text>(into_roc_str: T) -> RocElem { - let entry = RocElemEntry { - text: ManuallyDrop::new(into_roc_str.into()), - }; + todo!("TODO restore text method") + // let entry = RocElemEntry { + // text: ManuallyDrop::new(into_roc_str.into()), + // }; - Self::elem_from_tag(entry, RocElemTag::Text) + // Self::elem_from_tag(entry, RocElemTag::Text) } fn elem_from_tag(entry: RocElemEntry, tag: RocElemTag) -> Self { - let tagged_ptr = unsafe { - let entry_ptr = roc_alloc( - core::mem::size_of_val(&entry), - core::mem::align_of_val(&entry) as u32, - ) as *mut RocElemEntry; - - *entry_ptr = entry; - - entry_ptr as usize | tag as usize - }; - - Self { - entry: tagged_ptr as *const RocElemEntry, - } + Self { entry, tag } } } -#[repr(u8)] -#[allow(unused)] // This is actually used, just via a mem::transmute from u8 -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum RocElemTag { - Rect = 0, - Text, -} - #[repr(C)] #[derive(Debug)] -pub struct RocButton { - pub child: ManuallyDrop, +pub struct RocRect { pub styles: ButtonStyles, } @@ -229,7 +161,7 @@ unsafe impl ReferenceCount for RocElem { use RocElemTag::*; match self.tag() { - Rect => unsafe { &*self.entry().button.child }.increment(), + Rect => { /* nothing to increment! */ } Text => unsafe { &*self.entry().text }.increment(), } } @@ -246,7 +178,7 @@ unsafe impl ReferenceCount for RocElem { let elem = &*ptr; match elem.tag() { - Rect => ReferenceCount::decrement(&*elem.entry().button.child), + Rect => { /* nothing to decrement! */ } Text => ReferenceCount::decrement(&*elem.entry().text), } } @@ -261,31 +193,6 @@ pub struct ButtonStyles { pub text_color: Rgba, } -#[repr(C)] -pub union RocElemEntry { - pub button: ManuallyDrop, - pub text: ManuallyDrop, -} - -// enum Patch { -// Text(RocStr), -// } - -#[test] -fn make_text() { - let text = RocElem::text("blah"); - - assert_eq!(text.tag(), RocElemTag::Text); -} - -#[test] -fn make_button() { - let text = RocElem::text("blah"); - let button = RocElem::button(ButtonStyles::default(), text); - - assert_eq!(button.tag(), RocElemTag::Rect); -} - pub fn app_render(state: State) -> RocElem { let size = unsafe { roc_program_size() } as usize; let layout = Layout::array::(size).unwrap(); @@ -306,13 +213,18 @@ pub fn app_render(state: State) -> RocElem { } unsafe fn call_the_closure(state: State, closure_data_ptr: *const u8) -> RocElem { - let size = size_Render_result() as usize; - let layout = Layout::array::(size).unwrap(); - let buffer = std::alloc::alloc(layout) as *mut u8; + let mut output = MaybeUninit::uninit(); - let answer = call_Render(&state, closure_data_ptr as *const u8, buffer as *mut u8); + call_Render( + &state, // ({ float, float }* %arg + closure_data_ptr as *const u8, // {}* %arg1 + output.as_mut_ptr(), // { { [6 x i64], [4 x i8] }, i8 }* %arg2) + ); - std::alloc::dealloc(buffer, layout); + let answer = output.assume_init(); - answer + dbg!(answer); + + todo!("explode"); + // answer } From d6858ef15e3f7412243f89c5da7d6a7505ea6f7e Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 6 Apr 2022 09:22:52 -0400 Subject: [PATCH 060/846] Use Rgba over ButtonStyles --- examples/breakout/breakout.roc | 5 +++-- examples/breakout/platform/src/roc.rs | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index 06935acb4c..dfd57cd6dc 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -12,5 +12,6 @@ render = \state -> styles = { bgColor: rgba 100 50 50 1, borderColor: rgba 10 20 30 1, borderWidth: 10, textColor: rgba 220 220 250 1 } - #Text "Hello!" - Rect { r: 1, g: 2, b: 3, a: 4 } + Text "Hello!" + # Rect { r: 1, g: 2, b: 3, a: 4 } + # Rect styles diff --git a/examples/breakout/platform/src/roc.rs b/examples/breakout/platform/src/roc.rs index ab25cb4512..c4c0d16e23 100644 --- a/examples/breakout/platform/src/roc.rs +++ b/examples/breakout/platform/src/roc.rs @@ -83,11 +83,12 @@ pub struct ElemId(*const RocElemEntry); #[repr(C)] pub union RocElemEntry { - pub rect: ManuallyDrop, + pub rect: ManuallyDrop, pub text: ManuallyDrop, } #[repr(u8)] +#[allow(unused)] #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum RocElemTag { Rect = 0, From 7b5bc8e85ff32f481a6af728219cab7d5fc0e78a Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 6 Apr 2022 11:15:08 -0400 Subject: [PATCH 061/846] Use Ayaz's repr(packed) workaround for #2803 --- examples/breakout/breakout.roc | 3 ++- examples/breakout/platform/Package-Config.roc | 2 +- examples/breakout/platform/src/roc.rs | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index dfd57cd6dc..218806f965 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -12,6 +12,7 @@ render = \state -> styles = { bgColor: rgba 100 50 50 1, borderColor: rgba 10 20 30 1, borderWidth: 10, textColor: rgba 220 220 250 1 } - Text "Hello!" + #Text "Hello!" # Rect { r: 1, g: 2, b: 3, a: 4 } # Rect styles + Text "Hello!" diff --git a/examples/breakout/platform/Package-Config.roc b/examples/breakout/platform/Package-Config.roc index 31d1d97d81..aa04462194 100644 --- a/examples/breakout/platform/Package-Config.roc +++ b/examples/breakout/platform/Package-Config.roc @@ -9,7 +9,7 @@ Rgba : { r : F32, g : F32, b : F32, a : F32 } ButtonStyles : { bgColor : Rgba, borderColor : Rgba, borderWidth : F32, textColor : Rgba } -Elem : [ Rect Rgba, Text Str ] +Elem : [ Rect ButtonStyles, Text Str ] State : { width : F32, height : F32 } diff --git a/examples/breakout/platform/src/roc.rs b/examples/breakout/platform/src/roc.rs index c4c0d16e23..7750acb7e3 100644 --- a/examples/breakout/platform/src/roc.rs +++ b/examples/breakout/platform/src/roc.rs @@ -81,7 +81,7 @@ pub unsafe extern "C" fn roc_memset(dst: *mut c_void, c: i32, n: usize) -> *mut #[derive(Copy, Clone, Debug, PartialEq, Eq)] pub struct ElemId(*const RocElemEntry); -#[repr(C)] +#[repr(packed)] // TODO this should be repr(C) but it's repr(packed) to work around https://github.com/rtfeldman/roc/issues/2803 pub union RocElemEntry { pub rect: ManuallyDrop, pub text: ManuallyDrop, From 1e2dcde6c2210c2c0a6edaf7163a09cfe5433e55 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 6 Apr 2022 21:29:09 -0400 Subject: [PATCH 062/846] Use a List of rects, add top and left coordinates --- examples/breakout/breakout.roc | 6 ++++-- examples/breakout/platform/Package-Config.roc | 6 +++--- examples/breakout/platform/src/gui.rs | 8 ++++---- examples/breakout/platform/src/roc.rs | 17 ++++++++++++----- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index 218806f965..41f6190e58 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -14,5 +14,7 @@ render = \state -> #Text "Hello!" # Rect { r: 1, g: 2, b: 3, a: 4 } - # Rect styles - Text "Hello!" + # [ Text "Hello!" ] + [ + Rect { left: 10, top: 20, width: 200, height: 300, borderWidth: 2.0, color: rgba 10 20 30 1 }, + ] diff --git a/examples/breakout/platform/Package-Config.roc b/examples/breakout/platform/Package-Config.roc index aa04462194..25a637e7ca 100644 --- a/examples/breakout/platform/Package-Config.roc +++ b/examples/breakout/platform/Package-Config.roc @@ -7,14 +7,14 @@ platform "gui" Rgba : { r : F32, g : F32, b : F32, a : F32 } -ButtonStyles : { bgColor : Rgba, borderColor : Rgba, borderWidth : F32, textColor : Rgba } +Bounds : { width : F32, height : F32 } -Elem : [ Rect ButtonStyles, Text Str ] +Elem : [ Rect { borderWidth : F32, color : Rgba, left : F32, top : F32, width : F32, height : F32 }, Text Str ] State : { width : F32, height : F32 } Program state : { render : state -> Elem } # TODO allow changing the window title - maybe via a Task, since that shouldn't happen all the time -programForHost : { render : (State -> Elem) as Render } +programForHost : { render : (State -> List Elem) as Render } programForHost = program diff --git a/examples/breakout/platform/src/gui.rs b/examples/breakout/platform/src/gui.rs index 69f5f0786b..5b51a54b2e 100644 --- a/examples/breakout/platform/src/gui.rs +++ b/examples/breakout/platform/src/gui.rs @@ -16,7 +16,7 @@ use glyph_brush::OwnedSection; use pipelines::RectResources; use std::error::Error; use wgpu::{CommandEncoder, LoadOp, RenderPass, TextureView}; -use wgpu_glyph::{GlyphBrush, GlyphCruncher}; +use wgpu_glyph::GlyphBrush; use winit::{ dpi::PhysicalSize, event, @@ -298,9 +298,9 @@ fn begin_render_pass<'a>( } #[derive(Copy, Clone, Debug, Default)] -struct Bounds { - width: f32, - height: f32, +pub struct Bounds { + pub height: f32, + pub width: f32, } #[derive(Clone, Debug)] diff --git a/examples/breakout/platform/src/roc.rs b/examples/breakout/platform/src/roc.rs index 7750acb7e3..d37cc0ed4d 100644 --- a/examples/breakout/platform/src/roc.rs +++ b/examples/breakout/platform/src/roc.rs @@ -2,7 +2,7 @@ use crate::graphics::colors::Rgba; use core::alloc::Layout; use core::ffi::c_void; use core::mem::ManuallyDrop; -use roc_std::{ReferenceCount, RocStr}; +use roc_std::{ReferenceCount, RocList, RocStr}; use std::ffi::CStr; use std::fmt::Debug; use std::mem::MaybeUninit; @@ -13,7 +13,7 @@ extern "C" { fn roc_program() -> (); #[link_name = "roc__programForHost_1_Render_caller"] - fn call_Render(state: *const State, closure_data: *const u8, output: *mut RocElem); + fn call_Render(state: *const State, closure_data: *const u8, output: *mut RocList); #[link_name = "roc__programForHost_size"] fn roc_program_size() -> i64; @@ -81,9 +81,9 @@ pub unsafe extern "C" fn roc_memset(dst: *mut c_void, c: i32, n: usize) -> *mut #[derive(Copy, Clone, Debug, PartialEq, Eq)] pub struct ElemId(*const RocElemEntry); -#[repr(packed)] // TODO this should be repr(C) but it's repr(packed) to work around https://github.com/rtfeldman/roc/issues/2803 +#[repr(C)] pub union RocElemEntry { - pub rect: ManuallyDrop, + pub rect: ManuallyDrop, pub text: ManuallyDrop, } @@ -153,7 +153,14 @@ impl RocElem { #[repr(C)] #[derive(Debug)] pub struct RocRect { - pub styles: ButtonStyles, + pub border_width: f32, + pub color: Rgba, + + // These must be in this order for alphabetization! + pub height: f32, + pub left: f32, + pub top: f32, + pub width: f32, } unsafe impl ReferenceCount for RocElem { From 82a0376666b774c0dc38d8252f107652ea8ae645 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 6 Apr 2022 21:57:03 -0400 Subject: [PATCH 063/846] Drop the borderWidth field to avoid segfault --- examples/breakout/breakout.roc | 3 ++- examples/breakout/platform/Package-Config.roc | 2 +- examples/breakout/platform/src/roc.rs | 1 - 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index 41f6190e58..8645ef733a 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -16,5 +16,6 @@ render = \state -> # Rect { r: 1, g: 2, b: 3, a: 4 } # [ Text "Hello!" ] [ - Rect { left: 10, top: 20, width: 200, height: 300, borderWidth: 2.0, color: rgba 10 20 30 1 }, + Rect { left: 10, top: 20, width: 200, height: 300, color: rgba 10 20 30 1 }, + Rect { left: 10, top: 20, width: 200, height: 300, color: rgba 10 20 30 1 }, ] diff --git a/examples/breakout/platform/Package-Config.roc b/examples/breakout/platform/Package-Config.roc index 25a637e7ca..03b360ee82 100644 --- a/examples/breakout/platform/Package-Config.roc +++ b/examples/breakout/platform/Package-Config.roc @@ -9,7 +9,7 @@ Rgba : { r : F32, g : F32, b : F32, a : F32 } Bounds : { width : F32, height : F32 } -Elem : [ Rect { borderWidth : F32, color : Rgba, left : F32, top : F32, width : F32, height : F32 }, Text Str ] +Elem : [ Rect { color : Rgba, left : F32, top : F32, width : F32, height : F32 }, Text Str ] State : { width : F32, height : F32 } diff --git a/examples/breakout/platform/src/roc.rs b/examples/breakout/platform/src/roc.rs index d37cc0ed4d..2c5fce2dd7 100644 --- a/examples/breakout/platform/src/roc.rs +++ b/examples/breakout/platform/src/roc.rs @@ -153,7 +153,6 @@ impl RocElem { #[repr(C)] #[derive(Debug)] pub struct RocRect { - pub border_width: f32, pub color: Rgba, // These must be in this order for alphabetization! From 3dac45e6f382125eb69cd8e43cc4bf6dd4f09abf Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 6 Apr 2022 22:14:25 -0400 Subject: [PATCH 064/846] Start making breakout blocks --- examples/breakout/breakout.roc | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index 8645ef733a..0d53f67f88 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -12,10 +12,21 @@ render = \state -> styles = { bgColor: rgba 100 50 50 1, borderColor: rgba 10 20 30 1, borderWidth: 10, textColor: rgba 220 220 250 1 } - #Text "Hello!" - # Rect { r: 1, g: 2, b: 3, a: 4 } - # [ Text "Hello!" ] - [ - Rect { left: 10, top: 20, width: 200, height: 300, color: rgba 10 20 30 1 }, - Rect { left: 10, top: 20, width: 200, height: 300, color: rgba 10 20 30 1 }, - ] + numRows = 4 + numCols = 8 + + blocks = List.map (List.range 0 (numRows * numCols)) \index -> + { col: index, row: (index // 5 |> Result.withDefault 0) } + + blockWidth = 100 + blockHeight = 50 + + blockRects = + List.map blocks \{ row, col } -> + left = Num.toF32 (col * blockWidth) + top = Num.toF32 (row * blockHeight) + color = rgba 10 20 30 1 # TODO different colors for each block! + + Rect { left, top, width: blockWidth, height: blockHeight, color } + + blockRects From a12e40a31027f5e335fdb350c322148aa251480b Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 7 Apr 2022 14:03:29 -0400 Subject: [PATCH 065/846] Specialize polymorphic values before binding to pattern Closes #2811 --- compiler/mono/src/ir.rs | 27 +++++++++++++++------ compiler/test_gen/src/gen_str.rs | 16 ++++++++++++ compiler/test_mono/generated/issue_2811.txt | 3 +++ compiler/test_mono/src/tests.rs | 11 +++++++++ 4 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 compiler/test_mono/generated/issue_2811.txt diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 97522dd561..b05fc75072 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -3053,7 +3053,7 @@ fn specialize_naked_symbol<'a>( let opt_fn_var = Some(variable); // if this is a function symbol, ensure that it's properly specialized! - reuse_function_symbol( + specialize_symbol( env, procs, layout_cache, @@ -3558,7 +3558,7 @@ pub fn with_hole<'a>( // this symbol is already defined; nothing to do } Field::Function(symbol, variable) => { - stmt = reuse_function_symbol( + stmt = specialize_symbol( env, procs, layout_cache, @@ -4114,7 +4114,7 @@ pub fn with_hole<'a>( Stmt::Let(*symbol, access_expr, *field_layout, arena.alloc(stmt)); if record_needs_specialization { - stmt = reuse_function_symbol( + stmt = specialize_symbol( env, procs, layout_cache, @@ -4804,8 +4804,7 @@ fn construct_closure_data<'a>( // symbols to be inlined when specializing the closure body elsewhere. for &&(symbol, var) in symbols { if procs.partial_exprs.contains(symbol) { - result = - reuse_function_symbol(env, procs, layout_cache, Some(var), symbol, result, symbol); + result = specialize_symbol(env, procs, layout_cache, Some(var), symbol, result, symbol); } } @@ -6318,6 +6317,20 @@ fn store_pattern_help<'a>( match can_pat { Identifier(symbol) => { + if let Some((_, var)) = procs.partial_exprs.get(outer_symbol) { + // It might be the case that symbol we're storing hasn't been reified to a value + // yet, if it's polymorphic. Do that now. + stmt = specialize_symbol( + env, + procs, + layout_cache, + Some(var), + *symbol, + stmt, + outer_symbol, + ); + } + substitute_in_exprs(env.arena, &mut stmt, *symbol, outer_symbol); } Underscore => { @@ -6771,7 +6784,7 @@ fn let_empty_struct<'a>(assigned: Symbol, hole: &'a Stmt<'a>) -> Stmt<'a> { /// If the symbol is a function, make sure it is properly specialized // TODO: rename this now that we handle polymorphic non-function expressions too -fn reuse_function_symbol<'a>( +fn specialize_symbol<'a>( env: &mut Env<'a, '_>, procs: &mut Procs<'a>, layout_cache: &mut LayoutCache<'a>, @@ -6980,7 +6993,7 @@ fn assign_to_symbol<'a>( match can_reuse_symbol(env, procs, &loc_arg.value) { Imported(original) | LocalFunction(original) | UnspecializedExpr(original) => { // for functions we must make sure they are specialized correctly - reuse_function_symbol( + specialize_symbol( env, procs, layout_cache, diff --git a/compiler/test_gen/src/gen_str.rs b/compiler/test_gen/src/gen_str.rs index d5e5f6da83..de5119e68b 100644 --- a/compiler/test_gen/src/gen_str.rs +++ b/compiler/test_gen/src/gen_str.rs @@ -1587,3 +1587,19 @@ fn str_to_dec() { RocDec ); } + +#[test] +#[cfg(any(feature = "gen-llvm"))] +fn issue_2811() { + assert_evals_to!( + indoc!( + r#" + x = Command { tool: "bash" } + Command c = x + c.tool + "# + ), + RocStr::from("bash"), + RocStr + ); +} diff --git a/compiler/test_mono/generated/issue_2811.txt b/compiler/test_mono/generated/issue_2811.txt new file mode 100644 index 0000000000..ee169bc476 --- /dev/null +++ b/compiler/test_mono/generated/issue_2811.txt @@ -0,0 +1,3 @@ +procedure Test.0 (): + let Test.6 : Str = "bash"; + ret Test.6; diff --git a/compiler/test_mono/src/tests.rs b/compiler/test_mono/src/tests.rs index 64149bd120..ff9b7bfcaa 100644 --- a/compiler/test_mono/src/tests.rs +++ b/compiler/test_mono/src/tests.rs @@ -1282,6 +1282,17 @@ fn issue_2583_specialize_errors_behind_unified_branches() { ) } +#[mono_test] +fn issue_2811() { + indoc!( + r#" + x = Command { tool: "bash" } + Command c = x + c.tool + "# + ) +} + // #[ignore] // #[mono_test] // fn static_str_closure() { From bd623d65bcff72625837a804eee80e1a6552c7c6 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 6 Apr 2022 22:40:06 -0400 Subject: [PATCH 066/846] Formatting whitespace --- compiler/builtins/roc/Num.roc | 12 ++++++------ compiler/solve/tests/solve_expr.rs | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/compiler/builtins/roc/Num.roc b/compiler/builtins/roc/Num.roc index fc337ce9ba..2cd524af6b 100644 --- a/compiler/builtins/roc/Num.roc +++ b/compiler/builtins/roc/Num.roc @@ -1,6 +1,6 @@ interface Num - exposes - [ + exposes + [ Num, Int, Float, @@ -144,8 +144,8 @@ interface Num imports [ ] Num range : [ @Num range ] -Int range : Num (Integer range) -Float range : Num (FloatingPoint range) +Int range : Num (Integer range) +Float range : Num (FloatingPoint range) Signed128 : [ @Signed128 ] Signed64 : [ @Signed64 ] @@ -167,7 +167,7 @@ I128 : Num (Integer Signed128) I64 : Num (Integer Signed64) I32 : Num (Integer Signed32) I16 : Num (Integer Signed16) -I8 : Int Signed8 +I8 : Int Signed8 U128 : Num (Integer Unsigned128) U64 : Num (Integer Unsigned64) @@ -187,7 +187,7 @@ F64 : Num (FloatingPoint Binary64) F32 : Num (FloatingPoint Binary32) Dec : Num (FloatingPoint Decimal) -# ------- Functions +# ------- Functions toStr : Num * -> Str intCast : Int a -> Int b diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index 281bf37528..70a4debb69 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -5359,7 +5359,7 @@ mod solve_expr { condition : Bool v : Id [ Y Str, Z Str ] - v = + v = if condition then $Id (Id 21 (Y "sasha")) else $Id (Id 21 (Z "felix")) From cd00a9863617161513b3d3e60b1fdb0b1b18cf5a Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 6 Apr 2022 22:40:58 -0400 Subject: [PATCH 067/846] Add toF32/64 and checked versions --- compiler/builtins/docs/Num.roc | 20 +++++++++++-------- compiler/builtins/roc/Num.roc | 5 +++++ compiler/builtins/src/std.rs | 30 ++++++++++++++++++++++++++++- compiler/can/src/builtins.rs | 14 ++++++++++++++ compiler/gen_llvm/src/llvm/build.rs | 17 ++++++++++++++++ compiler/gen_wasm/src/low_level.rs | 6 ++++++ compiler/module/src/low_level.rs | 2 ++ compiler/module/src/symbol.rs | 5 ++++- compiler/mono/src/borrow.rs | 4 +++- compiler/mono/src/low_level.rs | 1 + compiler/solve/tests/solve_expr.rs | 15 +++++++++++++++ 11 files changed, 108 insertions(+), 11 deletions(-) diff --git a/compiler/builtins/docs/Num.roc b/compiler/builtins/docs/Num.roc index 766cdd1df4..65f0c94402 100644 --- a/compiler/builtins/docs/Num.roc +++ b/compiler/builtins/docs/Num.roc @@ -628,6 +628,15 @@ toU16 : Int * -> U16 toU32 : Int * -> U32 toU64 : Int * -> U64 toU128 : Int * -> U128 + +## Convert a [Num] to a [F32]. If the given number can't be precisely represented in a [F32], +## there will be a loss of precision. +toF32 : Num * -> F32 + +## Convert a [Num] to a [F64]. If the given number can't be precisely represented in a [F64], +## there will be a loss of precision. +toF64 : Num * -> F64 + ## Convert any [Int] to a specifically-sized [Int], after checking validity. ## These are checked bitwise operations, ## so if the source number is outside the target range, then these will @@ -643,6 +652,9 @@ toU32Checked : Int * -> Result U32 [ OutOfBounds ]* toU64Checked : Int * -> Result U64 [ OutOfBounds ]* toU128Checked : Int * -> Result U128 [ OutOfBounds ]* +toF32Checked : Num * -> Result F32 [ OutOfBounds ] +toF64Checked : Num * -> Result F64 [ OutOfBounds ]* + ## Convert a number to a [Str]. ## ## This is the same as calling `Num.format {}` - so for more details on @@ -765,14 +777,6 @@ toU32 : Int * -> U32 toU64 : Int * -> U64 toU128 : Int * -> U128 -## Convert a #Num to a #F32. If the given number can't be precisely represented in a #F32, -## there will be a loss of precision. -toF32 : Num * -> F32 - -## Convert a #Num to a #F64. If the given number can't be precisely represented in a #F64, -## there will be a loss of precision. -toF64 : Num * -> F64 - ## Convert a #Num to a #Dec. If the given number can't be precisely represented in a #Dec, ## there will be a loss of precision. toDec : Num * -> Dec diff --git a/compiler/builtins/roc/Num.roc b/compiler/builtins/roc/Num.roc index 2cd524af6b..2a30529e3e 100644 --- a/compiler/builtins/roc/Num.roc +++ b/compiler/builtins/roc/Num.roc @@ -336,6 +336,9 @@ toU32 : Int * -> U32 toU64 : Int * -> U64 toU128 : Int * -> U128 +toF32 : Num * -> F32 +toF64 : Num * -> F64 + toI8Checked : Int * -> Result I8 [ OutOfBounds ]* toI16Checked : Int * -> Result I16 [ OutOfBounds ]* toI32Checked : Int * -> Result I32 [ OutOfBounds ]* @@ -346,3 +349,5 @@ toU16Checked : Int * -> Result U16 [ OutOfBounds ]* toU32Checked : Int * -> Result U32 [ OutOfBounds ]* toU64Checked : Int * -> Result U64 [ OutOfBounds ]* toU128Checked : Int * -> Result U128 [ OutOfBounds ]* +toF32Checked : Num * -> Result F32 [ OutOfBounds ]* +toF64Checked : Num * -> Result F64 [ OutOfBounds ]* diff --git a/compiler/builtins/src/std.rs b/compiler/builtins/src/std.rs index ac408f5f56..0dc322ae15 100644 --- a/compiler/builtins/src/std.rs +++ b/compiler/builtins/src/std.rs @@ -615,7 +615,35 @@ pub fn types() -> MutMap { add_top_level_function_type!( Symbol::NUM_TO_NAT_CHECKED, vec![int_type(flex(TVAR1))], - Box::new(result_type(nat_type(), out_of_bounds)), + Box::new(result_type(nat_type(), out_of_bounds.clone())), + ); + + // toF32 : Num * -> F32 + add_top_level_function_type!( + Symbol::NUM_TO_F32, + vec![num_type(flex(TVAR1))], + Box::new(f32_type()), + ); + + // toF32Checked : Num * -> Result F32 [ OutOfBounds ]* + add_top_level_function_type!( + Symbol::NUM_TO_F32_CHECKED, + vec![num_type(flex(TVAR1))], + Box::new(result_type(f32_type(), out_of_bounds.clone())), + ); + + // toF64 : Num * -> F64 + add_top_level_function_type!( + Symbol::NUM_TO_F64, + vec![num_type(flex(TVAR1))], + Box::new(f64_type()), + ); + + // toF64Checked : Num * -> Result F64 [ OutOfBounds ]* + add_top_level_function_type!( + Symbol::NUM_TO_F64_CHECKED, + vec![num_type(flex(TVAR1))], + Box::new(result_type(f64_type(), out_of_bounds)), ); // toStr : Num a -> Str diff --git a/compiler/can/src/builtins.rs b/compiler/can/src/builtins.rs index 496d2aea11..e35094b4ed 100644 --- a/compiler/can/src/builtins.rs +++ b/compiler/can/src/builtins.rs @@ -482,6 +482,18 @@ fn num_to_nat(symbol: Symbol, var_store: &mut VarStore) -> Def { lowlevel_1(symbol, LowLevel::NumIntCast, var_store) } +// Num.toF32 : Num * -> F32 +fn num_to_f32(symbol: Symbol, var_store: &mut VarStore) -> Def { + // Defer to NumToFloatCast + lowlevel_1(symbol, LowLevel::NumToFloatCast, var_store) +} + +// Num.toF64 : Num * -> F64 +fn num_to_f64(symbol: Symbol, var_store: &mut VarStore) -> Def { + // Defer to NumToFloatCast + lowlevel_1(symbol, LowLevel::NumToFloatCast, var_store) +} + fn to_num_checked(symbol: Symbol, var_store: &mut VarStore, lowlevel: LowLevel) -> Def { let bool_var = var_store.fresh(); let num_var_1 = var_store.fresh(); @@ -589,6 +601,8 @@ num_to_checked! { num_to_u64_checked num_to_u128_checked num_to_nat_checked + num_to_f32_checked + num_to_f64_checked } // Num.toStr : Num a -> Str diff --git a/compiler/gen_llvm/src/llvm/build.rs b/compiler/gen_llvm/src/llvm/build.rs index 03ed3d3ec2..5aa4aa7367 100644 --- a/compiler/gen_llvm/src/llvm/build.rs +++ b/compiler/gen_llvm/src/llvm/build.rs @@ -5865,6 +5865,23 @@ fn run_low_level<'a, 'ctx, 'env>( .build_int_cast_sign_flag(arg, to, to_signed, "inc_cast") .into() } + NumToFloatCast => { + debug_assert_eq!(args.len(), 1); + + let arg = load_symbol(scope, &args[0]).into_int_value(); + + todo!("TODO if it's a float, cast; if it's an int, do either signed_int_to_float or unsigned_int_to_float; if it's Dec, panic for now"); + // let to = basic_type_from_layout(env, layout).into_int_type(); + // let to_signed = intwidth_from_layout(*layout).is_signed(); + + // env.builder + // .build_int_cast_sign_flag(arg, to, to_signed, "inc_cast") + // .into() + } + NumToFloatChecked => { + // NOTE: For some reason there's no entry here for NumToIntChecked - why is that? + todo!("implement checked float conversion"); + } Eq => { debug_assert_eq!(args.len(), 2); diff --git a/compiler/gen_wasm/src/low_level.rs b/compiler/gen_wasm/src/low_level.rs index 64d0769d30..b376f613b5 100644 --- a/compiler/gen_wasm/src/low_level.rs +++ b/compiler/gen_wasm/src/low_level.rs @@ -677,9 +677,15 @@ impl<'a> LowLevelCall<'a> { _ => todo!("{:?}: {:?} -> {:?}", self.lowlevel, arg_type, ret_type), } } + NumToFloatCast => { + todo!("implement toF32 and toF64"); + } NumToIntChecked => { todo!() } + NumToFloatChecked => { + todo!("implement toF32Checked and toF64Checked"); + } And => { self.load_args(backend); backend.code_builder.i32_and(); diff --git a/compiler/module/src/low_level.rs b/compiler/module/src/low_level.rs index 1271816043..3876411440 100644 --- a/compiler/module/src/low_level.rs +++ b/compiler/module/src/low_level.rs @@ -111,7 +111,9 @@ pub enum LowLevel { NumShiftRightBy, NumShiftRightZfBy, NumIntCast, + NumToFloatCast, NumToIntChecked, + NumToFloatChecked, NumToStr, Eq, NotEq, diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index db2e02bfdb..86ccb79309 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -1053,6 +1053,10 @@ define_builtins! { 144 NUM_TO_U128_CHECKED: "toU128Checked" 145 NUM_TO_NAT: "toNat" 146 NUM_TO_NAT_CHECKED: "toNatChecked" + 147 NUM_TO_F32: "toF32" + 148 NUM_TO_F32_CHECKED: "toF32Checked" + 149 NUM_TO_F64: "toF64" + 150 NUM_TO_F64_CHECKED: "toF64Checked" } 2 BOOL: "Bool" => { 0 BOOL_BOOL: "Bool" imported // the Bool.Bool type alias @@ -1103,7 +1107,6 @@ define_builtins! { 32 STR_TO_I16: "toI16" 33 STR_TO_U8: "toU8" 34 STR_TO_I8: "toI8" - } 4 LIST: "List" => { 0 LIST_LIST: "List" imported // the List.List type alias diff --git a/compiler/mono/src/borrow.rs b/compiler/mono/src/borrow.rs index 0cbe6a504c..7fd09d0bfc 100644 --- a/compiler/mono/src/borrow.rs +++ b/compiler/mono/src/borrow.rs @@ -1001,7 +1001,9 @@ pub fn lowlevel_borrow_signature(arena: &Bump, op: LowLevel) -> &[bool] { NumToStr | NumAbs | NumNeg | NumSin | NumCos | NumSqrtUnchecked | NumLogUnchecked | NumRound | NumCeiling | NumFloor | NumToFloat | Not | NumIsFinite | NumAtan | NumAcos - | NumAsin | NumIntCast | NumToIntChecked => arena.alloc_slice_copy(&[irrelevant]), + | NumAsin | NumIntCast | NumToIntChecked | NumToFloatCast | NumToFloatChecked => { + arena.alloc_slice_copy(&[irrelevant]) + } NumBytesToU16 => arena.alloc_slice_copy(&[borrowed, irrelevant]), NumBytesToU32 => arena.alloc_slice_copy(&[borrowed, irrelevant]), StrStartsWith | StrEndsWith => arena.alloc_slice_copy(&[owned, borrowed]), diff --git a/compiler/mono/src/low_level.rs b/compiler/mono/src/low_level.rs index 7053ef87ae..03092a25cb 100644 --- a/compiler/mono/src/low_level.rs +++ b/compiler/mono/src/low_level.rs @@ -170,6 +170,7 @@ enum FirstOrder { NumBytesToU32, NumShiftRightZfBy, NumIntCast, + NumFloatCast, Eq, NotEq, And, diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index 70a4debb69..16b39a26d4 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -5271,6 +5271,21 @@ mod solve_expr { ) } + #[test] + fn to_float() { + infer_eq_without_problem( + indoc!( + r#" + { + toF32: Num.toF32, + toF64: Num.toF64, + } + "# + ), + r#"{ toF32 : Num * -> F32, toF64 : Num * -> F64 }"#, + ) + } + #[test] fn opaque_wrap_infer() { infer_eq_without_problem( From 605a8d39e90fdb041b552ee4c0cff3fc307c6d6a Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 7 Apr 2022 14:16:03 -0400 Subject: [PATCH 068/846] Add some REPL tests for toF32/64 --- repl_test/src/tests.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/repl_test/src/tests.rs b/repl_test/src/tests.rs index 84df9024ee..6968a5c639 100644 --- a/repl_test/src/tests.rs +++ b/repl_test/src/tests.rs @@ -1103,3 +1103,17 @@ fn issue_2582_specialize_result_value() { r" : Num *, List Str -> Result Str [ ListWasEmpty ]*", ) } + +#[test] +#[cfg(not(feature = "wasm"))] +fn int_to_float() { + expect_success("Num.toF32 42", "42 : F32"); + expect_success("Num.toF64 123", "123 : F64"); +} + +#[test] +#[cfg(not(feature = "wasm"))] +fn float_to_float() { + expect_success("Num.toF32 123.456", "123.456 : F32"); + expect_success("Num.toF64 123.456", "123.456 : F64"); +} From a4233ad66195d9ac850da3385efd4aed84b69992 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 7 Apr 2022 14:17:04 -0400 Subject: [PATCH 069/846] Add LLVM implementation for toF32/64 --- compiler/can/src/builtins.rs | 4 +++ compiler/gen_llvm/src/llvm/build.rs | 38 +++++++++++++++++++++++------ 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/compiler/can/src/builtins.rs b/compiler/can/src/builtins.rs index e35094b4ed..48bfdf64b2 100644 --- a/compiler/can/src/builtins.rs +++ b/compiler/can/src/builtins.rs @@ -266,6 +266,10 @@ pub fn builtin_defs_map(symbol: Symbol, var_store: &mut VarStore) -> Option NUM_TO_U128_CHECKED => num_to_u128_checked, NUM_TO_NAT => num_to_nat, NUM_TO_NAT_CHECKED => num_to_nat_checked, + NUM_TO_F32 => num_to_f32, + NUM_TO_F32_CHECKED => num_to_f32_checked, + NUM_TO_F64 => num_to_f64, + NUM_TO_F64_CHECKED => num_to_f64_checked, NUM_TO_STR => num_to_str, RESULT_MAP => result_map, RESULT_MAP_ERR => result_map_err, diff --git a/compiler/gen_llvm/src/llvm/build.rs b/compiler/gen_llvm/src/llvm/build.rs index 5aa4aa7367..ab6703ca6e 100644 --- a/compiler/gen_llvm/src/llvm/build.rs +++ b/compiler/gen_llvm/src/llvm/build.rs @@ -5868,15 +5868,39 @@ fn run_low_level<'a, 'ctx, 'env>( NumToFloatCast => { debug_assert_eq!(args.len(), 1); - let arg = load_symbol(scope, &args[0]).into_int_value(); + let (arg, arg_layout) = load_symbol_and_layout(scope, &args[0]); - todo!("TODO if it's a float, cast; if it's an int, do either signed_int_to_float or unsigned_int_to_float; if it's Dec, panic for now"); - // let to = basic_type_from_layout(env, layout).into_int_type(); - // let to_signed = intwidth_from_layout(*layout).is_signed(); + match arg_layout { + Layout::Builtin(Builtin::Int(width)) => { + // Converting from int to float + let int_val = arg.into_int_value(); + let dest = basic_type_from_layout(env, layout).into_float_type(); - // env.builder - // .build_int_cast_sign_flag(arg, to, to_signed, "inc_cast") - // .into() + if width.is_signed() { + env.builder + .build_signed_int_to_float(int_val, dest, "signed_int_to_float") + .into() + } else { + env.builder + .build_unsigned_int_to_float(int_val, dest, "unsigned_int_to_float") + .into() + } + } + Layout::Builtin(Builtin::Float(_)) => { + // Converting from float to float - e.g. F64 to F32, or vice versa + let dest = basic_type_from_layout(env, layout).into_float_type(); + + env.builder + .build_float_cast(arg.into_float_value(), dest, "cast_float_to_float") + .into() + } + Layout::Builtin(Builtin::Decimal) => { + todo!("Support converting Dec values to floats."); + } + other => { + unreachable!("Tried to do a float cast to non-float layout {:?}", other); + } + } } NumToFloatChecked => { // NOTE: For some reason there's no entry here for NumToIntChecked - why is that? From 459e3a0afed7f64aab9bf0c3fc1156d4405e4818 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 7 Apr 2022 15:49:59 -0400 Subject: [PATCH 070/846] Add a bunch of toF32/toF64 repl tests --- repl_test/src/tests.rs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/repl_test/src/tests.rs b/repl_test/src/tests.rs index 6968a5c639..11331e48f8 100644 --- a/repl_test/src/tests.rs +++ b/repl_test/src/tests.rs @@ -1109,11 +1109,35 @@ fn issue_2582_specialize_result_value() { fn int_to_float() { expect_success("Num.toF32 42", "42 : F32"); expect_success("Num.toF64 123", "123 : F64"); + expect_success("Num.toF32 42i8", "42 : F32"); + expect_success("Num.toF64 123i8", "123 : F64"); + expect_success("Num.toF32 42i16", "42 : F32"); + expect_success("Num.toF64 123i16", "123 : F64"); + expect_success("Num.toF32 42i32", "42 : F32"); + expect_success("Num.toF64 123i32", "123 : F64"); + expect_success("Num.toF32 42i64", "42 : F32"); + expect_success("Num.toF64 123i64", "123 : F64"); + expect_success("Num.toF32 42i128", "42 : F32"); + expect_success("Num.toF64 123i128", "123 : F64"); + expect_success("Num.toF32 42u8", "42 : F32"); + expect_success("Num.toF64 123u8", "123 : F64"); + expect_success("Num.toF32 42u16", "42 : F32"); + expect_success("Num.toF64 123u16", "123 : F64"); + expect_success("Num.toF32 42u32", "42 : F32"); + expect_success("Num.toF64 123u32", "123 : F64"); + expect_success("Num.toF32 42u64", "42 : F32"); + expect_success("Num.toF64 123u64", "123 : F64"); + expect_success("Num.toF32 42u128", "42 : F32"); + expect_success("Num.toF64 123u128", "123 : F64"); } #[test] #[cfg(not(feature = "wasm"))] fn float_to_float() { - expect_success("Num.toF32 123.456", "123.456 : F32"); - expect_success("Num.toF64 123.456", "123.456 : F64"); + expect_success("Num.toF32 1.5", "1.5 : F32"); + expect_success("Num.toF64 1.5", "1.5 : F64"); + expect_success("Num.toF32 1.5f32", "1.5 : F32"); + expect_success("Num.toF64 1.5f32", "1.5 : F64"); + expect_success("Num.toF32 1.5f64", "1.5 : F32"); + expect_success("Num.toF64 1.5f64", "1.5 : F64"); } From 4dc7e61f3f8962384b2d9f65ae170d8c0786c146 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 7 Apr 2022 16:27:01 -0400 Subject: [PATCH 071/846] Move conversion tests to test_gen --- compiler/test_gen/src/gen_num.rs | 34 ++++++++++++++++++++++++++-- repl_test/src/tests.rs | 38 -------------------------------- 2 files changed, 32 insertions(+), 40 deletions(-) diff --git a/compiler/test_gen/src/gen_num.rs b/compiler/test_gen/src/gen_num.rs index 870d699f99..0ead1c308d 100644 --- a/compiler/test_gen/src/gen_num.rs +++ b/compiler/test_gen/src/gen_num.rs @@ -2160,7 +2160,7 @@ fn max_u8() { ); } -macro_rules! to_int_tests { +macro_rules! num_conversion_tests { ($($fn:expr, $typ:ty, ($($test_name:ident, $input:expr, $output:expr $(, [ $($support_gen:literal),* ])? )*))*) => {$($( #[test] #[cfg(any(feature = "gen-llvm", $($(feature = $support_gen)*)?))] @@ -2171,7 +2171,7 @@ macro_rules! to_int_tests { )*)*} } -to_int_tests! { +num_conversion_tests! { "Num.toI8", i8, ( to_i8_same_width, "15u8", 15, ["gen-wasm"] to_i8_truncate, "115i32", 115, ["gen-wasm"] @@ -2232,6 +2232,36 @@ to_int_tests! { to_nat_truncate, "115i128", 115 to_nat_truncate_wraps, "10_000_000_000_000_000_000_000i128", 1864712049423024128 ) + "Num.toF32", f32, ( + to_f32_from_i8, "15i8", 15.0 + to_f32_from_i16, "15i16", 15.0 + to_f32_from_i32, "15i32", 15.0 + to_f32_from_i64, "15i64", 15.0 + to_f32_from_i128, "15i128", 15.0 + to_f32_from_u8, "15u8", 15.0 + to_f32_from_u16, "15u16", 15.0 + to_f32_from_u32, "15u32", 15.0 + to_f32_from_u64, "15u64", 15.0 + to_f32_from_u128, "15u128", 15.0 + to_f32_from_nat, "15nat", 15.0 + to_f32_from_f32, "1.5f32", 1.5 + to_f32_from_f64, "1.5f64", 1.5 + ) + "Num.toF64", f64, ( + to_f64_from_i8, "15i8", 15.0 + to_f64_from_i16, "15i16", 15.0 + to_f64_from_i32, "15i32", 15.0 + to_f64_from_i64, "15i64", 15.0 + to_f64_from_i128, "15i128", 15.0 + to_f64_from_u8, "15u8", 15.0 + to_f64_from_u16, "15u16", 15.0 + to_f64_from_u32, "15u32", 15.0 + to_f64_from_u64, "15u64", 15.0 + to_f64_from_u128, "15u128", 15.0 + to_f64_from_nat, "15nat", 15.0 + to_f64_from_f32, "1.5f32", 1.5 + to_f64_from_f64, "1.5f64", 1.5 + ) } macro_rules! to_int_checked_tests { diff --git a/repl_test/src/tests.rs b/repl_test/src/tests.rs index 11331e48f8..84df9024ee 100644 --- a/repl_test/src/tests.rs +++ b/repl_test/src/tests.rs @@ -1103,41 +1103,3 @@ fn issue_2582_specialize_result_value() { r" : Num *, List Str -> Result Str [ ListWasEmpty ]*", ) } - -#[test] -#[cfg(not(feature = "wasm"))] -fn int_to_float() { - expect_success("Num.toF32 42", "42 : F32"); - expect_success("Num.toF64 123", "123 : F64"); - expect_success("Num.toF32 42i8", "42 : F32"); - expect_success("Num.toF64 123i8", "123 : F64"); - expect_success("Num.toF32 42i16", "42 : F32"); - expect_success("Num.toF64 123i16", "123 : F64"); - expect_success("Num.toF32 42i32", "42 : F32"); - expect_success("Num.toF64 123i32", "123 : F64"); - expect_success("Num.toF32 42i64", "42 : F32"); - expect_success("Num.toF64 123i64", "123 : F64"); - expect_success("Num.toF32 42i128", "42 : F32"); - expect_success("Num.toF64 123i128", "123 : F64"); - expect_success("Num.toF32 42u8", "42 : F32"); - expect_success("Num.toF64 123u8", "123 : F64"); - expect_success("Num.toF32 42u16", "42 : F32"); - expect_success("Num.toF64 123u16", "123 : F64"); - expect_success("Num.toF32 42u32", "42 : F32"); - expect_success("Num.toF64 123u32", "123 : F64"); - expect_success("Num.toF32 42u64", "42 : F32"); - expect_success("Num.toF64 123u64", "123 : F64"); - expect_success("Num.toF32 42u128", "42 : F32"); - expect_success("Num.toF64 123u128", "123 : F64"); -} - -#[test] -#[cfg(not(feature = "wasm"))] -fn float_to_float() { - expect_success("Num.toF32 1.5", "1.5 : F32"); - expect_success("Num.toF64 1.5", "1.5 : F64"); - expect_success("Num.toF32 1.5f32", "1.5 : F32"); - expect_success("Num.toF64 1.5f32", "1.5 : F64"); - expect_success("Num.toF32 1.5f64", "1.5 : F32"); - expect_success("Num.toF64 1.5f64", "1.5 : F64"); -} From 6adaf0905e9cbeb4e07b06427180e5e39131262d Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 7 Apr 2022 16:29:17 -0400 Subject: [PATCH 072/846] Fix missing * in type annotation --- compiler/builtins/docs/Num.roc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/builtins/docs/Num.roc b/compiler/builtins/docs/Num.roc index 65f0c94402..2f45e22600 100644 --- a/compiler/builtins/docs/Num.roc +++ b/compiler/builtins/docs/Num.roc @@ -652,7 +652,7 @@ toU32Checked : Int * -> Result U32 [ OutOfBounds ]* toU64Checked : Int * -> Result U64 [ OutOfBounds ]* toU128Checked : Int * -> Result U128 [ OutOfBounds ]* -toF32Checked : Num * -> Result F32 [ OutOfBounds ] +toF32Checked : Num * -> Result F32 [ OutOfBounds ]* toF64Checked : Num * -> Result F64 [ OutOfBounds ]* ## Convert a number to a [Str]. From 66ec1b4a848bc43ec0d0315d1d5c97f01d173645 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 6 Apr 2022 17:20:37 -0400 Subject: [PATCH 073/846] Basic canonicalization and error checking for abilities --- compiler/can/src/abilities.rs | 64 ++++ compiler/can/src/annotation.rs | 164 ++++++++- compiler/can/src/def.rs | 341 ++++++++++++++---- compiler/can/src/lib.rs | 1 + compiler/can/src/scope.rs | 70 +++- compiler/parse/src/expr.rs | 26 +- .../pass/ability_two_in_a_row.expr.result-ast | 100 +++-- compiler/problem/src/can.rs | 24 ++ compiler/types/src/types.rs | 1 + reporting/src/error/canonicalize.rs | 134 +++++++ reporting/tests/test_reporting.rs | 329 +++++++++++++++++ 11 files changed, 1097 insertions(+), 157 deletions(-) create mode 100644 compiler/can/src/abilities.rs diff --git a/compiler/can/src/abilities.rs b/compiler/can/src/abilities.rs new file mode 100644 index 0000000000..07eba0bed5 --- /dev/null +++ b/compiler/can/src/abilities.rs @@ -0,0 +1,64 @@ +use roc_collections::all::{MutMap, MutSet}; +use roc_module::symbol::Symbol; +use roc_types::types::Type; + +use crate::annotation::HasClause; + +/// Stores information about an ability member definition, including the parent ability, the +/// defining type, and what type variables need to be instantiated with instances of the ability. +#[derive(Debug)] +struct AbilityMemberData { + #[allow(unused)] + parent_ability: Symbol, + #[allow(unused)] + signature: Type, + #[allow(unused)] + bound_has_clauses: Vec, +} + +/// Stores information about what abilities exist in a scope, what it means to implement an +/// ability, and what types implement them. +// TODO(abilities): this should probably go on the Scope, I don't put it there for now because we +// are only dealing with inter-module abilities for now. +#[derive(Default, Debug)] +pub struct AbilitiesStore { + /// Maps an ability to the members defining it. + #[allow(unused)] + members_of_ability: MutMap>, + + /// Information about all members composing abilities. + #[allow(unused)] + ability_members: MutMap, + + /// Tuples of (type, member) specifying that `type` declares an implementation of an ability + /// member `member`. + #[allow(unused)] + declared_implementations: MutSet<(Symbol, Symbol)>, +} + +impl AbilitiesStore { + pub fn register_ability( + &mut self, + ability: Symbol, + members: Vec<(Symbol, Type, Vec)>, + ) { + let mut members_vec = Vec::with_capacity(members.len()); + for (member, signature, bound_has_clauses) in members.into_iter() { + members_vec.push(member); + self.ability_members.insert( + member, + AbilityMemberData { + parent_ability: ability, + signature, + bound_has_clauses, + }, + ); + } + self.members_of_ability.insert(ability, members_vec); + } + + pub fn register_implementation(&mut self, implementing_type: Symbol, ability_member: Symbol) { + self.declared_implementations + .insert((implementing_type, ability_member)); + } +} diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index b44641f57a..7cb0fce345 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -1,10 +1,9 @@ use crate::env::Env; use crate::scope::Scope; use roc_collections::all::{ImMap, MutMap, MutSet, SendMap}; -use roc_error_macros::todo_abilities; use roc_module::ident::{Ident, Lowercase, TagName}; use roc_module::symbol::{IdentIds, ModuleId, Symbol}; -use roc_parse::ast::{AssignedField, Pattern, Tag, TypeAnnotation, TypeHeader}; +use roc_parse::ast::{AssignedField, ExtractSpaces, Pattern, Tag, TypeAnnotation, TypeHeader}; use roc_region::all::{Loc, Region}; use roc_types::subs::{VarStore, Variable}; use roc_types::types::{ @@ -104,6 +103,10 @@ impl IntroducedVariables { .find(|nv| nv.variable == var) .map(|nv| &nv.name) } + + pub fn named_var_by_name(&self, name: &Lowercase) -> Option<&NamedVariable> { + self.named.iter().find(|nv| &nv.name == name) + } } fn malformed(env: &mut Env, region: Region, name: &str) { @@ -143,6 +146,78 @@ pub fn canonicalize_annotation( } } +#[derive(Clone, Debug)] +pub struct HasClause { + pub var_name: Lowercase, + pub var: Variable, + pub ability: Symbol, +} + +pub fn canonicalize_annotation_with_possible_clauses( + env: &mut Env, + scope: &mut Scope, + annotation: &TypeAnnotation, + region: Region, + var_store: &mut VarStore, + abilities_in_scope: &[Symbol], +) -> (Annotation, Vec>) { + let mut introduced_variables = IntroducedVariables::default(); + let mut references = MutSet::default(); + let mut aliases = SendMap::default(); + + let (annotation, region, clauses) = match annotation { + TypeAnnotation::Where(annotation, clauses) => { + let mut can_clauses = Vec::with_capacity(clauses.len()); + for clause in clauses.iter() { + match canonicalize_has_clause( + env, + scope, + var_store, + &mut introduced_variables, + clause, + abilities_in_scope, + &mut references, + ) { + Ok(result) => can_clauses.push(Loc::at(clause.region, result)), + Err(err_type) => { + return ( + Annotation { + typ: err_type, + introduced_variables, + references, + aliases, + }, + can_clauses, + ) + } + }; + } + (&annotation.value, annotation.region, can_clauses) + } + annot => (annot, region, vec![]), + }; + + let typ = can_annotation_help( + env, + annotation, + region, + scope, + var_store, + &mut introduced_variables, + &mut aliases, + &mut references, + ); + + let annot = Annotation { + typ, + introduced_variables, + references, + aliases, + }; + + (annot, clauses) +} + fn make_apply_symbol( env: &mut Env, region: Region, @@ -271,7 +346,13 @@ pub fn find_type_def_symbols( SpaceBefore(inner, _) | SpaceAfter(inner, _) => { stack.push(inner); } - Where(..) => todo_abilities!(), + Where(annotation, clauses) => { + stack.push(&annotation.value); + + for has_clause in clauses.iter() { + stack.push(&has_clause.value.ability.value); + } + } Inferred | Wildcard | Malformed(_) => {} } } @@ -685,7 +766,17 @@ fn can_annotation_help( Type::Variable(var) } - Where(..) => todo_abilities!(), + Where(_annotation, clauses) => { + debug_assert!(!clauses.is_empty()); + + // Has clauses are allowed only on the top level of an ability member signature (for + // now), which we handle elsewhere. + env.problem(roc_problem::can::Problem::IllegalHasClause { + region: Region::across_all(clauses.iter().map(|clause| &clause.region)), + }); + + return Type::Erroneous(Problem::CanonicalizationProblem); + } Malformed(string) => { malformed(env, region, string); @@ -698,6 +789,71 @@ fn can_annotation_help( } } +fn canonicalize_has_clause( + env: &mut Env, + scope: &mut Scope, + var_store: &mut VarStore, + introduced_variables: &mut IntroducedVariables, + clause: &Loc>, + abilities_in_scope: &[Symbol], + references: &mut MutSet, +) -> Result { + let Loc { + region, + value: roc_parse::ast::HasClause { var, ability }, + } = clause; + let region = *region; + + let var_name = var.extract_spaces().item; + debug_assert!( + var_name.starts_with(char::is_lowercase), + "Vars should have been parsed as lowercase" + ); + let var_name = Lowercase::from(var_name); + + let ability = match ability.value { + TypeAnnotation::Apply(module_name, ident, _type_arguments) => { + let symbol = make_apply_symbol(env, ability.region, scope, module_name, ident)?; + if !abilities_in_scope.contains(&symbol) { + let region = ability.region; + env.problem(roc_problem::can::Problem::HasClauseIsNotAbility { region }); + return Err(Type::Erroneous(Problem::HasClauseIsNotAbility(region))); + } + symbol + } + _ => { + let region = ability.region; + env.problem(roc_problem::can::Problem::HasClauseIsNotAbility { region }); + return Err(Type::Erroneous(Problem::HasClauseIsNotAbility(region))); + } + }; + + references.insert(ability); + + if let Some(shadowing) = introduced_variables.named_var_by_name(&var_name) { + let var_name_ident = var_name.to_string().into(); + let shadow = Loc::at(region, var_name_ident); + env.problem(roc_problem::can::Problem::ShadowingInAnnotation { + original_region: shadowing.first_seen, + shadow: shadow.clone(), + }); + return Err(Type::Erroneous(Problem::Shadowed( + shadowing.first_seen, + shadow, + ))); + } + + let var = var_store.fresh(); + + introduced_variables.insert_named(var_name.clone(), Loc::at(region, var)); + + Ok(HasClause { + var_name, + var, + ability, + }) +} + #[allow(clippy::too_many_arguments)] fn can_extension_type<'a>( env: &mut Env, diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 9dc3de33d8..a319302906 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1,4 +1,6 @@ +use crate::abilities::AbilitiesStore; use crate::annotation::canonicalize_annotation; +use crate::annotation::canonicalize_annotation_with_possible_clauses; use crate::annotation::IntroducedVariables; use crate::env::Env; use crate::expr::ClosureData; @@ -10,10 +12,11 @@ use crate::scope::create_alias; use crate::scope::Scope; use roc_collections::all::ImSet; use roc_collections::all::{default_hasher, ImEntry, ImMap, MutMap, MutSet, SendMap}; -use roc_error_macros::todo_abilities; use roc_module::ident::Lowercase; use roc_module::symbol::Symbol; use roc_parse::ast; +use roc_parse::ast::AbilityMember; +use roc_parse::ast::ExtractSpaces; use roc_parse::ast::TypeHeader; use roc_parse::pattern::PatternType; use roc_problem::can::{CycleEntry, Problem, RuntimeError}; @@ -86,10 +89,19 @@ enum PendingTypeDef<'a> { kind: AliasKind, }, + Ability { + name: Loc, + members: &'a [ast::AbilityMember<'a>], + }, + /// An invalid alias, that is ignored in the rest of the pipeline /// e.g. a shadowed alias, or a definition like `MyAlias 1 : Int` /// with an incorrect pattern InvalidAlias { kind: AliasKind }, + + /// An invalid ability, that is ignored in the rest of the pipeline. + /// E.g. a shadowed ability, or with a bad definition. + InvalidAbility, } // See github.com/rtfeldman/roc/issues/800 for discussion of the large_enum_variant check. @@ -239,9 +251,19 @@ pub fn canonicalize_defs<'a>( env.home.register_debug_idents(&env.ident_ids); } - let mut aliases = SendMap::default(); + enum TypeDef<'a> { + AliasLike( + Loc, + Vec>, + &'a Loc>, + AliasKind, + ), + Ability(Loc, &'a [AbilityMember<'a>]), + } + + let mut type_defs = MutMap::default(); + let mut abilities_in_scope = Vec::new(); - let mut alias_defs = MutMap::default(); let mut referenced_type_symbols = MutMap::default(); for pending_def in pending_type_defs.into_iter() { @@ -260,93 +282,137 @@ pub fn canonicalize_defs<'a>( referenced_type_symbols.insert(name.value, referenced_symbols); - alias_defs.insert(name.value, (name, vars, ann, kind)); + type_defs.insert(name.value, TypeDef::AliasLike(name, vars, ann, kind)); + } + PendingTypeDef::Ability { name, members } => { + let mut referenced_symbols = Vec::with_capacity(2); + + for member in members.iter() { + // Add the referenced type symbols of each member function. We need to make + // sure those are processed first before we resolve the whole ability + // definition. + referenced_symbols.extend(crate::annotation::find_type_def_symbols( + env.home, + &mut env.ident_ids, + &member.typ.value, + )); + } + + referenced_type_symbols.insert(name.value, referenced_symbols); + type_defs.insert(name.value, TypeDef::Ability(name, members)); + abilities_in_scope.push(name.value); + } + PendingTypeDef::InvalidAlias { .. } | PendingTypeDef::InvalidAbility { .. } => { /* ignore */ } - PendingTypeDef::InvalidAlias { .. } => { /* ignore */ } } } let sorted = sort_type_defs_before_introduction(referenced_type_symbols); + let mut aliases = SendMap::default(); + let mut abilities = MutMap::default(); for type_name in sorted { - let (name, vars, ann, kind) = alias_defs.remove(&type_name).unwrap(); + match type_defs.remove(&type_name).unwrap() { + TypeDef::AliasLike(name, vars, ann, kind) => { + let symbol = name.value; + let can_ann = + canonicalize_annotation(env, &mut scope, &ann.value, ann.region, var_store); - let symbol = name.value; - let can_ann = canonicalize_annotation(env, &mut scope, &ann.value, ann.region, var_store); + // Does this alias reference any abilities? For now, we don't permit that. + let ability_references = can_ann + .references + .iter() + .filter_map(|&ty_ref| abilities_in_scope.iter().find(|&&name| name == ty_ref)) + .collect::>(); - // Record all the annotation's references in output.references.lookups - for symbol in can_ann.references { - output.references.type_lookups.insert(symbol); - output.references.referenced_type_defs.insert(symbol); - } - - let mut can_vars: Vec> = Vec::with_capacity(vars.len()); - let mut is_phantom = false; - - let mut named = can_ann.introduced_variables.named; - for loc_lowercase in vars.iter() { - match named.iter().position(|nv| nv.name == loc_lowercase.value) { - Some(index) => { - // This is a valid lowercase rigid var for the type def. - let named_variable = named.swap_remove(index); - - can_vars.push(Loc { - value: (named_variable.name, named_variable.variable), - region: loc_lowercase.region, + if let Some(one_ability_ref) = ability_references.first() { + env.problem(Problem::AliasUsesAbility { + loc_name: name, + ability: **one_ability_ref, }); } - None => { - is_phantom = true; - env.problems.push(Problem::PhantomTypeArgument { + // Record all the annotation's references in output.references.lookups + for symbol in can_ann.references { + output.references.type_lookups.insert(symbol); + output.references.referenced_type_defs.insert(symbol); + } + + let mut can_vars: Vec> = Vec::with_capacity(vars.len()); + let mut is_phantom = false; + + let mut named = can_ann.introduced_variables.named; + for loc_lowercase in vars.iter() { + match named.iter().position(|nv| nv.name == loc_lowercase.value) { + Some(index) => { + // This is a valid lowercase rigid var for the type def. + let named_variable = named.swap_remove(index); + + can_vars.push(Loc { + value: (named_variable.name, named_variable.variable), + region: loc_lowercase.region, + }); + } + None => { + is_phantom = true; + + env.problems.push(Problem::PhantomTypeArgument { + typ: symbol, + variable_region: loc_lowercase.region, + variable_name: loc_lowercase.value.clone(), + }); + } + } + } + + if is_phantom { + // Bail out + continue; + } + + let IntroducedVariables { + wildcards, + inferred, + .. + } = can_ann.introduced_variables; + let num_unbound = named.len() + wildcards.len() + inferred.len(); + if num_unbound > 0 { + let one_occurrence = named + .iter() + .map(|nv| Loc::at(nv.first_seen, nv.variable)) + .chain(wildcards) + .chain(inferred) + .next() + .unwrap() + .region; + + env.problems.push(Problem::UnboundTypeVariable { typ: symbol, - variable_region: loc_lowercase.region, - variable_name: loc_lowercase.value.clone(), + num_unbound, + one_occurrence, + kind, }); + + // Bail out + continue; } + + let alias = create_alias( + symbol, + name.region, + can_vars.clone(), + can_ann.typ.clone(), + kind, + ); + aliases.insert(symbol, alias.clone()); + } + + TypeDef::Ability(name, members) => { + // For now we enforce that aliases cannot reference abilities, so let's wait to + // resolve ability definitions until aliases are resolved and in scope below. + abilities.insert(name.value, (name, members)); } } - - if is_phantom { - // Bail out - continue; - } - - let IntroducedVariables { - wildcards, - inferred, - .. - } = can_ann.introduced_variables; - let num_unbound = named.len() + wildcards.len() + inferred.len(); - if num_unbound > 0 { - let one_occurrence = named - .iter() - .map(|nv| Loc::at(nv.first_seen, nv.variable)) - .chain(wildcards) - .chain(inferred) - .next() - .unwrap() - .region; - - env.problems.push(Problem::UnboundTypeVariable { - typ: symbol, - num_unbound, - one_occurrence, - kind, - }); - - // Bail out - continue; - } - - let alias = create_alias( - symbol, - name.region, - can_vars.clone(), - can_ann.typ.clone(), - kind, - ); - aliases.insert(symbol, alias.clone()); } // Now that we know the alias dependency graph, we can try to insert recursion variables @@ -362,6 +428,94 @@ pub fn canonicalize_defs<'a>( ); } + // Now we can go through and resolve all pending abilities, to add them to scope. + let mut abilities_store = AbilitiesStore::default(); + for (loc_ability_name, members) in abilities.into_values() { + let mut can_members = Vec::with_capacity(members.len()); + + for member in members { + let (member_annot, clauses) = canonicalize_annotation_with_possible_clauses( + env, + &mut scope, + &member.typ.value, + member.typ.region, + var_store, + &abilities_in_scope, + ); + + // Record all the annotation's references in output.references.lookups + for symbol in member_annot.references { + output.references.type_lookups.insert(symbol); + output.references.referenced_type_defs.insert(symbol); + } + + let member_name = member.name.extract_spaces().item; + + let member_sym = match scope.introduce( + member_name.into(), + &env.exposed_ident_ids, + &mut env.ident_ids, + member.name.region, + ) { + Ok(sym) => sym, + Err((original_region, shadow, _new_symbol)) => { + env.problem(roc_problem::can::Problem::ShadowingInAnnotation { + original_region, + shadow, + }); + // Pretend the member isn't a part of the ability + continue; + } + }; + + // What variables in the annotation are bound to the parent ability, and what variables + // are bound to some other ability? + let (variables_bound_to_ability, variables_bound_to_other_abilities): (Vec<_>, Vec<_>) = + clauses + .into_iter() + .partition(|has_clause| has_clause.value.ability == loc_ability_name.value); + + let mut bad_has_clauses = false; + + if variables_bound_to_ability.is_empty() { + // There are no variables bound to the parent ability - then this member doesn't + // need to be a part of the ability. + env.problem(Problem::AbilityMemberMissingHasClause { + member: member_sym, + ability: loc_ability_name.value, + region: member.name.region, + }); + bad_has_clauses = true; + } + + if !variables_bound_to_other_abilities.is_empty() { + // Disallow variables bound to other abilities, for now. + for bad_clause in variables_bound_to_other_abilities.iter() { + env.problem(Problem::AbilityMemberBindsExternalAbility { + member: member_sym, + ability: loc_ability_name.value, + region: bad_clause.region, + }); + } + bad_has_clauses = true; + } + + if bad_has_clauses { + // Pretend the member isn't a part of the ability + continue; + } + + let has_clauses = variables_bound_to_ability + .into_iter() + .map(|clause| clause.value) + .collect(); + can_members.push((member_sym, member_annot.typ, has_clauses)); + } + + // Store what symbols a type must define implementations for to have this ability. + abilities_store.register_ability(loc_ability_name.value, can_members); + } + // Now that we have the scope completely assembled, and shadowing resolved, // we're ready to canonicalize any body exprs. @@ -1551,7 +1705,46 @@ fn to_pending_type_def<'a>( } } - Ability { .. } => todo_abilities!(), + Ability { + header: TypeHeader { name, vars }, + members, + loc_has: _, + } => { + let name = match scope.introduce_without_shadow_symbol( + name.value.into(), + &env.exposed_ident_ids, + &mut env.ident_ids, + name.region, + ) { + Ok(symbol) => Loc::at(name.region, symbol), + Err((original_region, shadowed_symbol)) => { + env.problem(Problem::ShadowingInAnnotation { + original_region, + shadow: shadowed_symbol, + }); + return Some((Output::default(), PendingTypeDef::InvalidAbility)); + } + }; + + if !vars.is_empty() { + // Disallow ability type arguments, at least for now. + let variables_region = Region::across_all(vars.iter().map(|v| &v.region)); + + env.problem(Problem::AbilityHasTypeVariables { + name: name.value, + variables_region, + }); + return Some((Output::default(), PendingTypeDef::InvalidAbility)); + } + + let pending_ability = PendingTypeDef::Ability { + name, + // We'll handle adding the member symbols later on when we do all value defs. + members, + }; + + Some((Output::default(), pending_ability)) + } } } diff --git a/compiler/can/src/lib.rs b/compiler/can/src/lib.rs index fd813a423f..f22d1a1fe6 100644 --- a/compiler/can/src/lib.rs +++ b/compiler/can/src/lib.rs @@ -1,6 +1,7 @@ #![warn(clippy::dbg_macro)] // See github.com/rtfeldman/roc/issues/800 for discussion of the large_enum_variant check. #![allow(clippy::large_enum_variant)] +pub mod abilities; pub mod annotation; pub mod builtins; pub mod constraint; diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index 34e6369fec..9a6b9219ee 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -19,6 +19,9 @@ pub struct Scope { /// The type aliases currently in scope pub aliases: SendMap, + /// The abilities currently in scope, and their implementors. + pub abilities: SendMap, + /// The current module being processed. This will be used to turn /// unqualified idents into Symbols. home: ModuleId, @@ -62,6 +65,8 @@ impl Scope { idents: Symbol::default_in_scope(), symbols: SendMap::default(), aliases, + // TODO(abilities): default abilities in scope + abilities: SendMap::default(), } } @@ -176,6 +181,11 @@ impl Scope { /// /// Returns Err if this would shadow an existing ident, including the /// Symbol and Region of the ident we already had in scope under that name. + /// + /// If this ident shadows an existing one, a new ident is allocated for the shadow. This is + /// done so that all identifiers have unique symbols, which is important in particular when + /// we generate code for value identifiers. + /// If this behavior is undesirable, use [`Self::introduce_without_shadow_symbol`]. pub fn introduce( &mut self, ident: Ident, @@ -198,25 +208,53 @@ impl Scope { Err((original_region, shadow, symbol)) } - None => { - // If this IdentId was already added previously - // when the value was exposed in the module header, - // use that existing IdentId. Otherwise, create a fresh one. - let ident_id = match exposed_ident_ids.get_id(&ident) { - Some(ident_id) => ident_id, - None => all_ident_ids.add(ident.clone()), - }; - - let symbol = Symbol::new(self.home, ident_id); - - self.symbols.insert(symbol, region); - self.idents.insert(ident, (symbol, region)); - - Ok(symbol) - } + None => Ok(self.commit_introduction(ident, exposed_ident_ids, all_ident_ids, region)), } } + /// Like [Self::introduce], but does not introduce a new symbol for the shadowing symbol. + pub fn introduce_without_shadow_symbol( + &mut self, + ident: Ident, + exposed_ident_ids: &IdentIds, + all_ident_ids: &mut IdentIds, + region: Region, + ) -> Result)> { + match self.idents.get(&ident) { + Some(&(_, original_region)) => { + let shadow = Loc { + value: ident.clone(), + region, + }; + Err((original_region, shadow)) + } + None => Ok(self.commit_introduction(ident, exposed_ident_ids, all_ident_ids, region)), + } + } + + fn commit_introduction( + &mut self, + ident: Ident, + exposed_ident_ids: &IdentIds, + all_ident_ids: &mut IdentIds, + region: Region, + ) -> Symbol { + // If this IdentId was already added previously + // when the value was exposed in the module header, + // use that existing IdentId. Otherwise, create a fresh one. + let ident_id = match exposed_ident_ids.get_id(&ident) { + Some(ident_id) => ident_id, + None => all_ident_ids.add(ident.clone()), + }; + + let symbol = Symbol::new(self.home, ident_id); + + self.symbols.insert(symbol, region); + self.idents.insert(ident, (symbol, region)); + + symbol + } + /// Ignore an identifier. /// /// Used for record guards like { x: Just _ } diff --git a/compiler/parse/src/expr.rs b/compiler/parse/src/expr.rs index 97f81ed416..1c6256bdfe 100644 --- a/compiler/parse/src/expr.rs +++ b/compiler/parse/src/expr.rs @@ -866,24 +866,26 @@ fn parse_defs_end<'a>( } Ok((_, loc_pattern, state)) => { // First let's check whether this is an ability definition. - if let Loc { - value: - Pattern::Apply( - loc_name @ Loc { - value: Pattern::GlobalTag(name), - .. - }, - args, - ), - .. - } = loc_pattern + let opt_tag_and_args: Option<(&str, Region, &[Loc])> = match loc_pattern.value { + Pattern::Apply( + Loc { + value: Pattern::GlobalTag(name), + region, + }, + args, + ) => Some((name, *region, args)), + Pattern::GlobalTag(name) => Some((name, loc_pattern.region, &[])), + _ => None, + }; + + if let Some((name, name_region, args)) = opt_tag_and_args { if let Ok((_, loc_has, state)) = loc_has_parser(min_indent).parse(arena, state.clone()) { let (_, loc_def, state) = finish_parsing_ability_def( start_column, - Loc::at(loc_name.region, name), + Loc::at(name_region, name), args, loc_has, arena, diff --git a/compiler/parse/tests/snapshots/pass/ability_two_in_a_row.expr.result-ast b/compiler/parse/tests/snapshots/pass/ability_two_in_a_row.expr.result-ast index 4bd0831c5c..cba0cace4b 100644 --- a/compiler/parse/tests/snapshots/pass/ability_two_in_a_row.expr.result-ast +++ b/compiler/parse/tests/snapshots/pass/ability_two_in_a_row.expr.result-ast @@ -33,61 +33,59 @@ Defs( }, ], ), - }, - ], - }, - ), - ], - @35-71 SpaceBefore( - Defs( - [ - @35-68 Type( - Ability { - header: TypeHeader { - name: @35-38 "Ab2", - vars: [], - }, - loc_has: @39-42 Has, - members: [ - AbilityMember { - name: @43-46 "ab2", - typ: @54-68 Where( - @54-56 Function( - [ - @49-50 BoundVariable( - "a", - ), - ], - @54-56 Record { - fields: [], - ext: None, - }, - ), - [ - @59-68 HasClause { - var: @59-60 "a", - ability: @65-68 Apply( - "", - "Ab2", - [], - ), - }, - ], + [ + @24-33 HasClause { + var: @24-25 "a", + ability: @30-33 Apply( + "", + "Ab1", + [], ), }, ], - }, - ), + ), + }, ], - @70-71 SpaceBefore( - Num( - "1", - ), - [ - Newline, - Newline, - ], - ), + }, + @35-68 Ability { + header: TypeHeader { + name: @35-38 "Ab2", + vars: [], + }, + loc_has: @39-42 Has, + members: [ + AbilityMember { + name: @43-46 "ab2", + typ: @54-68 Where( + @54-56 Function( + [ + @49-50 BoundVariable( + "a", + ), + ], + @54-56 Record { + fields: [], + ext: None, + }, + ), + [ + @59-68 HasClause { + var: @59-60 "a", + ability: @65-68 Apply( + "", + "Ab2", + [], + ), + }, + ], + ), + }, + ], + }, + ], + @70-71 SpaceBefore( + Num( + "1", ), [ Newline, diff --git a/compiler/problem/src/can.rs b/compiler/problem/src/can.rs index daa20c0778..56756a8508 100644 --- a/compiler/problem/src/can.rs +++ b/compiler/problem/src/can.rs @@ -95,6 +95,30 @@ pub enum Problem { region: Region, kind: ExtensionTypeKind, }, + AbilityHasTypeVariables { + name: Symbol, + variables_region: Region, + }, + HasClauseIsNotAbility { + region: Region, + }, + IllegalHasClause { + region: Region, + }, + AbilityMemberMissingHasClause { + member: Symbol, + ability: Symbol, + region: Region, + }, + AbilityMemberBindsExternalAbility { + member: Symbol, + ability: Symbol, + region: Region, + }, + AliasUsesAbility { + loc_name: Loc, + ability: Symbol, + }, } #[derive(Clone, Debug, PartialEq)] diff --git a/compiler/types/src/types.rs b/compiler/types/src/types.rs index bd8b68199e..6c55d062fa 100644 --- a/compiler/types/src/types.rs +++ b/compiler/types/src/types.rs @@ -1856,6 +1856,7 @@ pub enum Problem { }, InvalidModule, SolvedTypeError, + HasClauseIsNotAbility(Region), } #[derive(PartialEq, Eq, Debug, Clone)] diff --git a/reporting/src/error/canonicalize.rs b/reporting/src/error/canonicalize.rs index 83e35f6ade..24a27f5e9c 100644 --- a/reporting/src/error/canonicalize.rs +++ b/reporting/src/error/canonicalize.rs @@ -38,6 +38,12 @@ const OPAQUE_DECLARED_OUTSIDE_SCOPE: &str = "OPAQUE TYPE DECLARED OUTSIDE SCOPE" const OPAQUE_NOT_APPLIED: &str = "OPAQUE TYPE NOT APPLIED"; const OPAQUE_OVER_APPLIED: &str = "OPAQUE TYPE APPLIED TO TOO MANY ARGS"; const INVALID_EXTENSION_TYPE: &str = "INVALID_EXTENSION_TYPE"; +const ABILITY_HAS_TYPE_VARIABLES: &str = "ABILITY HAS TYPE VARIABLES"; +const HAS_CLAUSE_IS_NOT_AN_ABILITY: &str = "HAS CLAUSE IS NOT AN ABILITY"; +const ALIAS_USES_ABILITY: &str = "ALIAS USES ABILITY"; +const ILLEGAL_HAS_CLAUSE: &str = "ILLEGAL HAS CLAUSE"; +const ABILITY_MEMBER_MISSING_HAS_CLAUSE: &str = "ABILITY MEMBER MISSING HAS CLAUSE"; +const ABILITY_MEMBER_HAS_EXTRANEOUS_HAS_CLAUSE: &str = "ABILITY MEMBER HAS EXTRANEOUS HAS CLAUSE"; pub fn can_problem<'b>( alloc: &'b RocDocAllocator<'b>, @@ -562,6 +568,134 @@ pub fn can_problem<'b>( title = INVALID_EXTENSION_TYPE.to_string(); severity = Severity::RuntimeError; } + + Problem::AbilityHasTypeVariables { + name, + variables_region, + } => { + doc = alloc.stack(vec![ + alloc.concat(vec![ + alloc.reflow("The definition of the "), + alloc.symbol_unqualified(name), + alloc.reflow(" ability includes type variables:"), + ]), + alloc.region(lines.convert_region(variables_region)), + alloc.reflow( + "Abilities cannot depend on type variables, but their member values can!", + ), + ]); + title = ABILITY_HAS_TYPE_VARIABLES.to_string(); + severity = Severity::RuntimeError; + } + + Problem::HasClauseIsNotAbility { + region: clause_region, + } => { + doc = alloc.stack(vec![ + alloc.reflow(r#"The type referenced in this "has" clause is not an ability:"#), + alloc.region(lines.convert_region(clause_region)), + ]); + title = HAS_CLAUSE_IS_NOT_AN_ABILITY.to_string(); + severity = Severity::RuntimeError; + } + + Problem::AliasUsesAbility { + loc_name: Loc { + region, + value: name, + }, + ability, + } => { + doc = alloc.stack(vec![ + alloc.concat(vec![ + alloc.reflow("The definition of the "), + alloc.symbol_unqualified(name), + alloc.reflow(" aliases references the ability "), + alloc.symbol_unqualified(ability), + alloc.reflow(":"), + ]), + alloc.region(lines.convert_region(region)), + ]); + title = ALIAS_USES_ABILITY.to_string(); + severity = Severity::RuntimeError; + } + + Problem::IllegalHasClause { region } => { + doc = alloc.stack(vec![ + alloc.concat(vec![ + alloc.reflow("A "), + alloc.keyword("has"), + alloc.reflow(" clause is not allowed here:"), + ]), + alloc.region(lines.convert_region(region)), + alloc.concat(vec![ + alloc.keyword("has"), + alloc.reflow(" clauses can only be specified on the top-level type annotation of an ability member."), + ]), + ]); + title = ILLEGAL_HAS_CLAUSE.to_string(); + severity = Severity::RuntimeError; + } + + Problem::AbilityMemberMissingHasClause { + member, + ability, + region, + } => { + doc = alloc.stack(vec![ + alloc.concat(vec![ + alloc.reflow("The definition of the ability member "), + alloc.symbol_unqualified(member), + alloc.reflow(" does not include a "), + alloc.keyword("has"), + alloc.reflow(" clause binding a type variable to the ability "), + alloc.symbol_unqualified(ability), + alloc.reflow(":"), + ]), + alloc.region(lines.convert_region(region)), + alloc.concat(vec![ + alloc.reflow("Ability members must include a "), + alloc.keyword("has"), + alloc.reflow(" clause binding a type variable to an ability, like"), + ]), + alloc.type_block(alloc.concat(vec![ + alloc.type_variable("a".into()), + alloc.space(), + alloc.keyword("has"), + alloc.space(), + alloc.symbol_unqualified(ability), + ])), + alloc.concat(vec![alloc.reflow( + "Otherwise, the function does not need to be part of the ability!", + )]), + ]); + title = ABILITY_MEMBER_MISSING_HAS_CLAUSE.to_string(); + severity = Severity::RuntimeError; + } + + Problem::AbilityMemberBindsExternalAbility { + member, + ability, + region, + } => { + doc = alloc.stack(vec![ + alloc.concat(vec![ + alloc.reflow("The definition of the ability member "), + alloc.symbol_unqualified(member), + alloc.reflow(" includes a has clause binding an ability it is not a part of:"), + ]), + alloc.region(lines.convert_region(region)), + alloc.reflow("Currently, ability members can only bind variables to the ability they are a part of."), + alloc.concat(vec![ + alloc.hint(""), + alloc.reflow("Did you mean to bind the "), + alloc.symbol_unqualified(ability), + alloc.reflow(" ability instead?"), + ]), + ]); + title = ABILITY_MEMBER_HAS_EXTRANEOUS_HAS_CLAUSE.to_string(); + severity = Severity::RuntimeError; + } }; Report { diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index d16764eaa2..73b427947a 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -8896,4 +8896,333 @@ I need all branches in an `if` to have the same type! ), ) } + + #[test] + fn bad_type_parameter_in_ability() { + report_problem_as( + indoc!( + r#" + Hash a b c has + hash : a -> U64 | a has Hash + + 1 + "# + ), + indoc!( + r#" + ── ABILITY HAS TYPE VARIABLES ────────────────────────────────────────────────── + + The definition of the `Hash` ability includes type variables: + + 1│ Hash a b c has + ^^^^^ + + Abilities cannot depend on type variables, but their member values + can! + + ── UNUSED DEFINITION ─────────────────────────────────────────────────────────── + + `Hash` is not used anywhere in your code. + + 1│ Hash a b c has + ^^^^ + + If you didn't intend on using `Hash` then remove it so future readers of + your code don't wonder why it is there. + "# + ), + ) + } + + #[test] + fn alias_in_has_clause() { + report_problem_as( + indoc!( + r#" + Hash has hash : a, b -> U64 | a has Hash, b has Bool + + 1 + "# + ), + indoc!( + r#" + ── HAS CLAUSE IS NOT AN ABILITY ──────────────────────────────────────────────── + + The type referenced in this "has" clause is not an ability: + + 1│ Hash has hash : a, b -> U64 | a has Hash, b has Bool + ^^^^ + + ── UNUSED DEFINITION ─────────────────────────────────────────────────────────── + + `hash` is not used anywhere in your code. + + 1│ Hash has hash : a, b -> U64 | a has Hash, b has Bool + ^^^^ + + If you didn't intend on using `hash` then remove it so future readers of + your code don't wonder why it is there. + "# + ), + ) + } + + #[test] + fn shadowed_type_variable_in_has_clause() { + report_problem_as( + indoc!( + r#" + Ab1 has ab1 : a -> {} | a has Ab1, a has Ab1 + + 1 + "# + ), + indoc!( + r#" + ── DUPLICATE NAME ────────────────────────────────────────────────────────────── + + The `a` name is first defined here: + + 1│ Ab1 has ab1 : a -> {} | a has Ab1, a has Ab1 + ^^^^^^^^^ + + But then it's defined a second time here: + + 1│ Ab1 has ab1 : a -> {} | a has Ab1, a has Ab1 + ^^^^^^^^^ + + Since these variables have the same name, it's easy to use the wrong + one on accident. Give one of them a new name. + + ── UNUSED DEFINITION ─────────────────────────────────────────────────────────── + + `ab1` is not used anywhere in your code. + + 1│ Ab1 has ab1 : a -> {} | a has Ab1, a has Ab1 + ^^^ + + If you didn't intend on using `ab1` then remove it so future readers of + your code don't wonder why it is there. + "# + ), + ) + } + + #[test] + fn alias_using_ability() { + report_problem_as( + indoc!( + r#" + Ability has ab : a -> {} | a has Ability + + Alias : Ability + + a : Alias + a + "# + ), + indoc!( + r#" + ── ALIAS USES ABILITY ────────────────────────────────────────────────────────── + + The definition of the `Alias` aliases references the ability `Ability`: + + 3│ Alias : Ability + ^^^^^ + + ── UNUSED DEFINITION ─────────────────────────────────────────────────────────── + + `ab` is not used anywhere in your code. + + 1│ Ability has ab : a -> {} | a has Ability + ^^ + + If you didn't intend on using `ab` then remove it so future readers of + your code don't wonder why it is there. + "# + ), + ) + } + + #[test] + fn ability_shadows_ability() { + report_problem_as( + indoc!( + r#" + Ability has ab : a -> U64 | a has Ability + + Ability has ab1 : a -> U64 | a has Ability + + 1 + "# + ), + indoc!( + r#" + ── DUPLICATE NAME ────────────────────────────────────────────────────────────── + + The `Ability` name is first defined here: + + 1│ Ability has ab : a -> U64 | a has Ability + ^^^^^^^ + + But then it's defined a second time here: + + 3│ Ability has ab1 : a -> U64 | a has Ability + ^^^^^^^ + + Since these variables have the same name, it's easy to use the wrong + one on accident. Give one of them a new name. + + ── UNUSED DEFINITION ─────────────────────────────────────────────────────────── + + `ab` is not used anywhere in your code. + + 1│ Ability has ab : a -> U64 | a has Ability + ^^ + + If you didn't intend on using `ab` then remove it so future readers of + your code don't wonder why it is there. + "# + ), + ) + } + + #[test] + fn ability_member_does_not_bind_ability() { + report_problem_as( + indoc!( + r#" + Ability has ab : {} -> {} + + 1 + "# + ), + indoc!( + r#" + ── ABILITY MEMBER MISSING HAS CLAUSE ─────────────────────────────────────────── + + The definition of the ability member `ab` does not include a `has` clause + binding a type variable to the ability `Ability`: + + 1│ Ability has ab : {} -> {} + ^^ + + Ability members must include a `has` clause binding a type variable to + an ability, like + + a has Ability + + Otherwise, the function does not need to be part of the ability! + + ── UNUSED DEFINITION ─────────────────────────────────────────────────────────── + + `Ability` is not used anywhere in your code. + + 1│ Ability has ab : {} -> {} + ^^^^^^^ + + If you didn't intend on using `Ability` then remove it so future readers + of your code don't wonder why it is there. + + ── UNUSED DEFINITION ─────────────────────────────────────────────────────────── + + `ab` is not used anywhere in your code. + + 1│ Ability has ab : {} -> {} + ^^ + + If you didn't intend on using `ab` then remove it so future readers of + your code don't wonder why it is there. + "# + ), + ) + } + + #[test] + fn ability_member_binds_extra_ability() { + report_problem_as( + indoc!( + r#" + Eq has eq : a, a -> Bool | a has Eq + Hash has hash : a, b -> U64 | a has Eq, b has Hash + + 1 + "# + ), + indoc!( + r#" + ── ABILITY MEMBER HAS EXTRANEOUS HAS CLAUSE ──────────────────────────────────── + + The definition of the ability member `hash` includes a has clause + binding an ability it is not a part of: + + 2│ Hash has hash : a, b -> U64 | a has Eq, b has Hash + ^^^^^^^^ + + Currently, ability members can only bind variables to the ability they + are a part of. + + Hint: Did you mean to bind the `Hash` ability instead? + + ── UNUSED DEFINITION ─────────────────────────────────────────────────────────── + + `eq` is not used anywhere in your code. + + 1│ Eq has eq : a, a -> Bool | a has Eq + ^^ + + If you didn't intend on using `eq` then remove it so future readers of + your code don't wonder why it is there. + + ── UNUSED DEFINITION ─────────────────────────────────────────────────────────── + + `hash` is not used anywhere in your code. + + 2│ Hash has hash : a, b -> U64 | a has Eq, b has Hash + ^^^^ + + If you didn't intend on using `hash` then remove it so future readers of + your code don't wonder why it is there. + "# + ), + ) + } + + #[test] + fn has_clause_outside_of_ability() { + report_problem_as( + indoc!( + r#" + Hash has hash : a -> U64 | a has Hash + + f : a -> U64 | a has Hash + + f + "# + ), + indoc!( + r#" + ── ILLEGAL HAS CLAUSE ────────────────────────────────────────────────────────── + + A `has` clause is not allowed here: + + 3│ f : a -> U64 | a has Hash + ^^^^^^^^^^ + + `has` clauses can only be specified on the top-level type annotation of + an ability member. + + ── UNUSED DEFINITION ─────────────────────────────────────────────────────────── + + `hash` is not used anywhere in your code. + + 1│ Hash has hash : a -> U64 | a has Hash + ^^^^ + + If you didn't intend on using `hash` then remove it so future readers of + your code don't wonder why it is there. + "# + ), + ) + } } From 884d07344e9ab611013cb0a480a0864d61bbbc7c Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 6 Apr 2022 17:26:18 -0400 Subject: [PATCH 074/846] Clippy --- compiler/can/src/annotation.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index 7cb0fce345..4245091e9d 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -775,7 +775,7 @@ fn can_annotation_help( region: Region::across_all(clauses.iter().map(|clause| &clause.region)), }); - return Type::Erroneous(Problem::CanonicalizationProblem); + Type::Erroneous(Problem::CanonicalizationProblem) } Malformed(string) => { malformed(env, region, string); From 73bfff699fc4f5547d4dd84ba92dc913853b4444 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 7 Apr 2022 12:46:05 -0400 Subject: [PATCH 075/846] Handle symbols that shadow ability member definitions Just add the shadowing symbol for now. We'll handle checking that a specialization's type matches the member's type definition in a later pass, during typechecking. --- compiler/can/src/abilities.rs | 23 ++++++++-- compiler/can/src/def.rs | 65 ++++++++++++++------------- compiler/can/src/module.rs | 3 +- compiler/can/src/pattern.rs | 73 ++++++++++++++++++++++++++++++- compiler/can/src/scope.rs | 46 +++++++++++++++++++ compiler/constrain/src/pattern.rs | 15 ++++++- compiler/mono/src/ir.rs | 8 ++++ 7 files changed, 193 insertions(+), 40 deletions(-) diff --git a/compiler/can/src/abilities.rs b/compiler/can/src/abilities.rs index 07eba0bed5..5665b765be 100644 --- a/compiler/can/src/abilities.rs +++ b/compiler/can/src/abilities.rs @@ -34,6 +34,9 @@ pub struct AbilitiesStore { /// member `member`. #[allow(unused)] declared_implementations: MutSet<(Symbol, Symbol)>, + + /// Cache of all ability member names in scope. + ability_member_symbols: MutSet, } impl AbilitiesStore { @@ -45,7 +48,7 @@ impl AbilitiesStore { let mut members_vec = Vec::with_capacity(members.len()); for (member, signature, bound_has_clauses) in members.into_iter() { members_vec.push(member); - self.ability_members.insert( + let old_member = self.ability_members.insert( member, AbilityMemberData { parent_ability: ability, @@ -53,12 +56,26 @@ impl AbilitiesStore { bound_has_clauses, }, ); + debug_assert!(old_member.is_none(), "Replacing existing member definition"); + + let old_member = self.ability_member_symbols.insert(member); + debug_assert!(!old_member, "Replacing existing member entry"); } - self.members_of_ability.insert(ability, members_vec); + let old_ability = self.members_of_ability.insert(ability, members_vec); + debug_assert!( + old_ability.is_none(), + "Replacing existing ability definition" + ); } pub fn register_implementation(&mut self, implementing_type: Symbol, ability_member: Symbol) { - self.declared_implementations + let old_impl = self + .declared_implementations .insert((implementing_type, ability_member)); + debug_assert!(!old_impl, "Replacing existing implementation"); + } + + pub fn is_ability_member_name(&self, name: Symbol) -> bool { + self.ability_member_symbols.contains(&name) } } diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index a319302906..3a0dfde6a7 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -6,7 +6,7 @@ use crate::env::Env; use crate::expr::ClosureData; use crate::expr::Expr::{self, *}; use crate::expr::{canonicalize_expr, local_successors_with_duplicates, Output, Recursive}; -use crate::pattern::{bindings_from_patterns, canonicalize_pattern, Pattern}; +use crate::pattern::{bindings_from_patterns, canonicalize_def_header_pattern, Pattern}; use crate::procedure::References; use crate::scope::create_alias; use crate::scope::Scope; @@ -524,7 +524,14 @@ pub fn canonicalize_defs<'a>( // once we've finished assembling the entire scope. let mut pending_value_defs = Vec::with_capacity(value_defs.len()); for loc_def in value_defs.into_iter() { - match to_pending_value_def(env, var_store, loc_def.value, &mut scope, pattern_type) { + match to_pending_value_def( + env, + var_store, + loc_def.value, + &mut scope, + &abilities_store, + pattern_type, + ) { None => { /* skip */ } Some((new_output, pending_def)) => { // store the top-level defs, used to ensure that closures won't capture them @@ -1011,6 +1018,13 @@ fn pattern_to_vars_by_symbol( vars_by_symbol.insert(*symbol, expr_var); } + AbilityMemberSpecialization { + ident, + specializes: _, + } => { + vars_by_symbol.insert(*ident, expr_var); + } + AppliedTag { arguments, .. } => { for (var, nested) in arguments { pattern_to_vars_by_symbol(vars_by_symbol, &nested.value, *var); @@ -1748,36 +1762,12 @@ fn to_pending_type_def<'a>( } } -fn pending_typed_body<'a>( - env: &mut Env<'a>, - loc_pattern: &'a Loc>, - loc_ann: &'a Loc>, - loc_expr: &'a Loc>, - var_store: &mut VarStore, - scope: &mut Scope, - pattern_type: PatternType, -) -> (Output, PendingValueDef<'a>) { - // This takes care of checking for shadowing and adding idents to scope. - let (output, loc_can_pattern) = canonicalize_pattern( - env, - var_store, - scope, - pattern_type, - &loc_pattern.value, - loc_pattern.region, - ); - - ( - output, - PendingValueDef::TypedBody(loc_pattern, loc_can_pattern, loc_ann, loc_expr), - ) -} - fn to_pending_value_def<'a>( env: &mut Env<'a>, var_store: &mut VarStore, def: &'a ast::ValueDef<'a>, scope: &mut Scope, + abilities_store: &AbilitiesStore, pattern_type: PatternType, ) -> Option<(Output, PendingValueDef<'a>)> { use ast::ValueDef::*; @@ -1785,10 +1775,11 @@ fn to_pending_value_def<'a>( match def { Annotation(loc_pattern, loc_ann) => { // This takes care of checking for shadowing and adding idents to scope. - let (output, loc_can_pattern) = canonicalize_pattern( + let (output, loc_can_pattern) = canonicalize_def_header_pattern( env, var_store, scope, + abilities_store, pattern_type, &loc_pattern.value, loc_pattern.region, @@ -1801,10 +1792,11 @@ fn to_pending_value_def<'a>( } Body(loc_pattern, loc_expr) => { // This takes care of checking for shadowing and adding idents to scope. - let (output, loc_can_pattern) = canonicalize_pattern( + let (output, loc_can_pattern) = canonicalize_def_header_pattern( env, var_store, scope, + abilities_store, pattern_type, &loc_pattern.value, loc_pattern.region, @@ -1829,14 +1821,21 @@ fn to_pending_value_def<'a>( // // { x, y } : { x : Int, y ? Bool }* // { x, y ? False } = rec - Some(pending_typed_body( + // + // This takes care of checking for shadowing and adding idents to scope. + let (output, loc_can_pattern) = canonicalize_def_header_pattern( env, - body_pattern, - ann_type, - body_expr, var_store, scope, + abilities_store, pattern_type, + &body_pattern.value, + body_pattern.region, + ); + + Some(( + output, + PendingValueDef::TypedBody(body_pattern, loc_can_pattern, ann_type, body_expr), )) } else { // the pattern of the annotation does not match the pattern of the body direc diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index 60255ac40d..34ca4faf6a 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -589,7 +589,8 @@ fn fix_values_captured_in_closure_pattern( | Shadowed(..) | MalformedPattern(_, _) | UnsupportedPattern(_) - | OpaqueNotInScope(..) => (), + | OpaqueNotInScope(..) + | AbilityMemberSpecialization { .. } => (), } } diff --git a/compiler/can/src/pattern.rs b/compiler/can/src/pattern.rs index 7dbec77d3e..26353ee2cf 100644 --- a/compiler/can/src/pattern.rs +++ b/compiler/can/src/pattern.rs @@ -1,3 +1,4 @@ +use crate::abilities::AbilitiesStore; use crate::annotation::freshen_opaque_def; use crate::env::Env; use crate::expr::{canonicalize_expr, unescape_char, Expr, IntValue, Output}; @@ -62,6 +63,17 @@ pub enum Pattern { SingleQuote(char), Underscore, + /// An identifier that marks a specialization of an ability member. + /// For example, given an ability member definition `hash : a -> U64 | a has Hash`, + /// there may be the specialization `hash : Bool -> U64`. In this case we generate a + /// new symbol for the specailized "hash" identifier. + AbilityMemberSpecialization { + /// The symbol for this specialization. + ident: Symbol, + /// The ability name being specialized. + specializes: Symbol, + }, + // Runtime Exceptions Shadowed(Region, Loc, Symbol), OpaqueNotInScope(Loc), @@ -101,6 +113,11 @@ pub fn symbols_from_pattern_help(pattern: &Pattern, symbols: &mut Vec) { symbols.push(*symbol); } + AbilityMemberSpecialization { ident, specializes } => { + symbols.push(*ident); + symbols.push(*specializes); + } + AppliedTag { arguments, .. } => { for (_, nested) in arguments { symbols_from_pattern_help(&nested.value, symbols); @@ -136,6 +153,55 @@ pub fn symbols_from_pattern_help(pattern: &Pattern, symbols: &mut Vec) { } } +pub fn canonicalize_def_header_pattern<'a>( + env: &mut Env<'a>, + var_store: &mut VarStore, + scope: &mut Scope, + abilities_store: &AbilitiesStore, + pattern_type: PatternType, + pattern: &ast::Pattern<'a>, + region: Region, +) -> (Output, Loc) { + use roc_parse::ast::Pattern::*; + + let mut output = Output::default(); + match pattern { + // Identifiers that shadow ability members may appear (and may only appear) at the header of a def. + Identifier(name) => match scope.introduce_or_shadow_ability_member( + (*name).into(), + &env.exposed_ident_ids, + &mut env.ident_ids, + region, + abilities_store, + ) { + Ok((symbol, shadowing_ability_member)) => { + output.references.bound_symbols.insert(symbol); + let can_pattern = match shadowing_ability_member { + // A fresh identifier. + None => Pattern::Identifier(symbol), + // Likely a specialization of an ability. + Some(ability_member_name) => Pattern::AbilityMemberSpecialization { + ident: symbol, + specializes: ability_member_name, + }, + }; + (output, Loc::at(region, can_pattern)) + } + Err((original_region, shadow, new_symbol)) => { + env.problem(Problem::RuntimeError(RuntimeError::Shadowing { + original_region, + shadow: shadow.clone(), + })); + output.references.bound_symbols.insert(new_symbol); + + let can_pattern = Pattern::Shadowed(original_region, shadow, new_symbol); + (output, Loc::at(region, can_pattern)) + } + }, + _ => canonicalize_pattern(env, var_store, scope, pattern_type, pattern, region), + } +} + pub fn canonicalize_pattern<'a>( env: &mut Env<'a>, var_store: &mut VarStore, @@ -594,7 +660,12 @@ fn add_bindings_from_patterns( use Pattern::*; match pattern { - Identifier(symbol) | Shadowed(_, _, symbol) => { + Identifier(symbol) + | Shadowed(_, _, symbol) + | AbilityMemberSpecialization { + ident: symbol, + specializes: _, + } => { answer.push((*symbol, *region)); } AppliedTag { diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index 9a6b9219ee..18b1f347dc 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -6,6 +6,8 @@ use roc_region::all::{Loc, Region}; use roc_types::subs::{VarStore, Variable}; use roc_types::types::{Alias, AliasKind, Type}; +use crate::abilities::AbilitiesStore; + #[derive(Clone, Debug, PartialEq)] pub struct Scope { /// All the identifiers in scope, mapped to were they were defined and @@ -232,6 +234,50 @@ impl Scope { } } + /// Like [Self::introduce], but handles the case of when an ident matches an ability member + /// name. In such cases a new symbol is created for the ident (since it's expected to be a + /// specialization of the ability member), but the ident is not added to the ident->symbol map. + /// + /// If the ident does not match an ability name, the behavior of this function is exactly that + /// of `introduce`. + pub fn introduce_or_shadow_ability_member( + &mut self, + ident: Ident, + exposed_ident_ids: &IdentIds, + all_ident_ids: &mut IdentIds, + region: Region, + abilities_store: &AbilitiesStore, + ) -> Result<(Symbol, Option), (Region, Loc, Symbol)> { + match self.idents.get(&ident) { + Some(&(original_symbol, original_region)) => { + let shadow_ident_id = all_ident_ids.add(ident.clone()); + let shadow_symbol = Symbol::new(self.home, shadow_ident_id); + + self.symbols.insert(shadow_symbol, region); + + if abilities_store.is_ability_member_name(original_symbol) { + // Add a symbol for the shadow, but don't re-associate the member name. + Ok((shadow_symbol, Some(original_symbol))) + } else { + // This is an illegal shadow. + let shadow = Loc { + value: ident.clone(), + region, + }; + + self.idents.insert(ident, (shadow_symbol, region)); + + Err((original_region, shadow, shadow_symbol)) + } + } + None => { + let new_symbol = + self.commit_introduction(ident, exposed_ident_ids, all_ident_ids, region); + Ok((new_symbol, None)) + } + } + } + fn commit_introduction( &mut self, ident: Ident, diff --git a/compiler/constrain/src/pattern.rs b/compiler/constrain/src/pattern.rs index 44c5545cec..a66dcb03a5 100644 --- a/compiler/constrain/src/pattern.rs +++ b/compiler/constrain/src/pattern.rs @@ -50,7 +50,13 @@ fn headers_from_annotation_help( headers: &mut SendMap>, ) -> bool { match pattern { - Identifier(symbol) | Shadowed(_, _, symbol) => { + Identifier(symbol) + | Shadowed(_, _, symbol) + // TODO(abilities): handle linking the member def to the specialization ident + | AbilityMemberSpecialization { + ident: symbol, + specializes: _, + } => { let typ = Loc::at(annotation.region, annotation.value.clone()); headers.insert(*symbol, typ); true @@ -182,7 +188,12 @@ pub fn constrain_pattern( // Erroneous patterns don't add any constraints. } - Identifier(symbol) | Shadowed(_, _, symbol) => { + Identifier(symbol) | Shadowed(_, _, symbol) + // TODO(abilities): handle linking the member def to the specialization ident + | AbilityMemberSpecialization { + ident: symbol, + specializes: _, + } => { if could_be_a_tag_union(expected.get_type_ref()) { state .constraints diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 97522dd561..2ef2290aed 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -2088,6 +2088,13 @@ fn pattern_to_when<'a>( // They should have been replaced with `UnsupportedPattern` during canonicalization unreachable!("refutable pattern {:?} where irrefutable pattern is expected. This should never happen!", pattern.value) } + + AbilityMemberSpecialization { .. } => { + unreachable!( + "Ability member specialization {:?} should never appear in a when!", + pattern.value + ) + } } } @@ -7787,6 +7794,7 @@ fn from_can_pattern_help<'a>( match can_pattern { Underscore => Ok(Pattern::Underscore), Identifier(symbol) => Ok(Pattern::Identifier(*symbol)), + AbilityMemberSpecialization { ident, .. } => Ok(Pattern::Identifier(*ident)), IntLiteral(_, precision_var, _, int, _bound) => { match num_argument_to_int_or_float(env.subs, env.target_info, *precision_var, false) { IntOrFloat::Int(precision) => { From 1ca3dad1e230622517affc3af8d8b1c8b1a0e6ac Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 7 Apr 2022 12:55:13 -0400 Subject: [PATCH 076/846] Allow complicated return type --- compiler/can/src/scope.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index 18b1f347dc..179f15bdf0 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -240,6 +240,7 @@ impl Scope { /// /// If the ident does not match an ability name, the behavior of this function is exactly that /// of `introduce`. + #[allow(clippy::type_complexity)] pub fn introduce_or_shadow_ability_member( &mut self, ident: Ident, From 1edbe3225268c53c42c287fc713815042ca01329 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 7 Apr 2022 17:22:05 -0400 Subject: [PATCH 077/846] Fix parse tests --- .../pass/ability_two_in_a_row.expr.result-ast | 86 +++++++++---------- 1 file changed, 39 insertions(+), 47 deletions(-) diff --git a/compiler/parse/tests/snapshots/pass/ability_two_in_a_row.expr.result-ast b/compiler/parse/tests/snapshots/pass/ability_two_in_a_row.expr.result-ast index cba0cace4b..a9a00da02a 100644 --- a/compiler/parse/tests/snapshots/pass/ability_two_in_a_row.expr.result-ast +++ b/compiler/parse/tests/snapshots/pass/ability_two_in_a_row.expr.result-ast @@ -33,55 +33,47 @@ Defs( }, ], ), - [ - @24-33 HasClause { - var: @24-25 "a", - ability: @30-33 Apply( - "", - "Ab1", - [], - ), - }, - ], - ), - }, - ], - }, - @35-68 Ability { - header: TypeHeader { - name: @35-38 "Ab2", - vars: [], + }, + ], }, - loc_has: @39-42 Has, - members: [ - AbilityMember { - name: @43-46 "ab2", - typ: @54-68 Where( - @54-56 Function( - [ - @49-50 BoundVariable( - "a", - ), - ], - @54-56 Record { - fields: [], - ext: None, - }, - ), - [ - @59-68 HasClause { - var: @59-60 "a", - ability: @65-68 Apply( - "", - "Ab2", - [], - ), - }, - ], - ), + ), + @35-68 Type( + Ability { + header: TypeHeader { + name: @35-38 "Ab2", + vars: [], }, - ], - }, + loc_has: @39-42 Has, + members: [ + AbilityMember { + name: @43-46 "ab2", + typ: @54-68 Where( + @54-56 Function( + [ + @49-50 BoundVariable( + "a", + ), + ], + @54-56 Record { + fields: [], + ext: None, + }, + ), + [ + @59-68 HasClause { + var: @59-60 "a", + ability: @65-68 Apply( + "", + "Ab2", + [], + ), + }, + ], + ), + }, + ], + }, + ), ], @70-71 SpaceBefore( Num( From 17b3c7d8ee63c60c65ab33ca5a4a10669fd97762 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 7 Apr 2022 17:49:48 -0400 Subject: [PATCH 078/846] Generate type variables when there are lots Closes #2797 --- compiler/solve/tests/solve_expr.rs | 13 +++++++++++++ compiler/types/src/types.rs | 18 +++++++++--------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index 281bf37528..b85437129a 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -5634,4 +5634,17 @@ mod solve_expr { "Result I64 [ InvalidNumStr, ListWasEmpty ]*", ) } + + #[test] + fn lots_of_type_variables() { + infer_eq_without_problem( + indoc!( + r#" + fun = \a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb -> {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb} + fun + "# + ), + "a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, aa, bb -> { a : a, aa : aa, b : b, bb : bb, c : c, d : d, e : e, f : f, g : g, h : h, i : i, j : j, k : k, l : l, m : m, n : n, o : o, p : p, q : q, r : r, s : s, t : t, u : u, v : v, w : w, x : x, y : y, z : z }", + ) + } } diff --git a/compiler/types/src/types.rs b/compiler/types/src/types.rs index bd8b68199e..e68ad596f8 100644 --- a/compiler/types/src/types.rs +++ b/compiler/types/src/types.rs @@ -2307,15 +2307,15 @@ static THE_LETTER_A: u32 = 'a' as u32; pub fn name_type_var(letters_used: u32, taken: &mut MutSet) -> (Lowercase, u32) { // TODO we should arena-allocate this String, // so all the strings in the entire pass only require ~1 allocation. - let generated_name = if letters_used < 26 { - // This should generate "a", then "b", etc. - std::char::from_u32(THE_LETTER_A + letters_used) - .unwrap_or_else(|| panic!("Tried to convert {} to a char", THE_LETTER_A + letters_used)) - .to_string() - .into() - } else { - panic!("TODO generate aa, ab, ac, ..."); - }; + let mut generated_name = String::with_capacity((letters_used as usize) / 26 + 1); + + let mut remaining = letters_used as i32; + while remaining >= 0 { + generated_name.push(std::char::from_u32(THE_LETTER_A + ((remaining as u32) % 26)).unwrap()); + remaining -= 26; + } + + let generated_name = generated_name.into(); if taken.contains(&generated_name) { // If the generated name is already taken, try again. From bfb7bb3874d50a9df8a4159838d5d4d4b8db880f Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 7 Apr 2022 18:36:33 -0400 Subject: [PATCH 079/846] Update comment --- compiler/gen_llvm/src/llvm/build.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/gen_llvm/src/llvm/build.rs b/compiler/gen_llvm/src/llvm/build.rs index ab6703ca6e..8afb896b6d 100644 --- a/compiler/gen_llvm/src/llvm/build.rs +++ b/compiler/gen_llvm/src/llvm/build.rs @@ -5903,7 +5903,8 @@ fn run_low_level<'a, 'ctx, 'env>( } } NumToFloatChecked => { - // NOTE: For some reason there's no entry here for NumToIntChecked - why is that? + // NOTE: There's a NumToIntChecked implementation above, + // which could be useful to look at when implementing this. todo!("implement checked float conversion"); } Eq => { From 113239d3f41fe66da1957a146f093267a271ea07 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 7 Apr 2022 19:03:06 -0400 Subject: [PATCH 080/846] Reproduce alias_analysis bug --- examples/breakout/breakout.roc | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index 0d53f67f88..b14db97e88 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -6,27 +6,6 @@ app "breakout" program = { render } render = \state -> - div0 = \numerator, denominator -> (numerator / denominator) |> Result.withDefault 0 + x = [] - rgba = \r, g, b, a -> { r: div0 r 255, g: div0 g 255, b: div0 b 255, a } - - styles = { bgColor: rgba 100 50 50 1, borderColor: rgba 10 20 30 1, borderWidth: 10, textColor: rgba 220 220 250 1 } - - numRows = 4 - numCols = 8 - - blocks = List.map (List.range 0 (numRows * numCols)) \index -> - { col: index, row: (index // 5 |> Result.withDefault 0) } - - blockWidth = 100 - blockHeight = 50 - - blockRects = - List.map blocks \{ row, col } -> - left = Num.toF32 (col * blockWidth) - top = Num.toF32 (row * blockHeight) - color = rgba 10 20 30 1 # TODO different colors for each block! - - Rect { left, top, width: blockWidth, height: blockHeight, color } - - blockRects + x From 49a96bcc7200210ad6874ce990223d1f58039192 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 7 Apr 2022 19:03:51 -0400 Subject: [PATCH 081/846] Work around alias analysis bug --- examples/breakout/breakout.roc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index b14db97e88..e77d8eef45 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -6,6 +6,4 @@ app "breakout" program = { render } render = \state -> - x = [] - - x + [] From 304a32ef0ac864428c35806829afe8ec9ecbc025 Mon Sep 17 00:00:00 2001 From: ayazhafiz Date: Thu, 7 Apr 2022 20:51:21 -0400 Subject: [PATCH 082/846] Typo --- compiler/can/src/pattern.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/can/src/pattern.rs b/compiler/can/src/pattern.rs index 26353ee2cf..c8963a045a 100644 --- a/compiler/can/src/pattern.rs +++ b/compiler/can/src/pattern.rs @@ -66,7 +66,7 @@ pub enum Pattern { /// An identifier that marks a specialization of an ability member. /// For example, given an ability member definition `hash : a -> U64 | a has Hash`, /// there may be the specialization `hash : Bool -> U64`. In this case we generate a - /// new symbol for the specailized "hash" identifier. + /// new symbol for the specialized "hash" identifier. AbilityMemberSpecialization { /// The symbol for this specialization. ident: Symbol, From 78feb45d82513135c0aa4a37f15adc649c5dcb07 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 7 Apr 2022 21:17:31 -0400 Subject: [PATCH 083/846] Draw rects --- examples/breakout/breakout.roc | 22 +++- examples/breakout/platform/src/gui.rs | 170 ++++++++++++++------------ examples/breakout/platform/src/roc.rs | 17 +-- 3 files changed, 117 insertions(+), 92 deletions(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index e77d8eef45..c5c7bafd5d 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -6,4 +6,24 @@ app "breakout" program = { render } render = \state -> - [] + div0 = \numerator, denominator -> (numerator / denominator) |> Result.withDefault 0 + + rgba = \r, g, b, a -> { r: div0 r 255, g: div0 g 255, b: div0 b 255, a } + + styles = { bgColor: rgba 100 50 50 1, borderColor: rgba 10 20 30 1, borderWidth: 10, textColor: rgba 220 220 250 1 } + + numRows = 4 + numCols = 8 + + blocks = List.map (List.range 0 (numRows * numCols)) \index -> + { col: index, row: (index // 5 |> Result.withDefault 0) } + + blockWidth = 100 + blockHeight = 50 + + List.map blocks \{ row, col } -> + left = Num.toF32 (col * blockWidth) + top = Num.toF32 (row * blockHeight) + color = rgba 10 20 30 1 # TODO different colors for each block! + + Rect { left, top, width: blockWidth, height: blockHeight, color } diff --git a/examples/breakout/platform/src/gui.rs b/examples/breakout/platform/src/gui.rs index 5b51a54b2e..7e559ecc31 100644 --- a/examples/breakout/platform/src/gui.rs +++ b/examples/breakout/platform/src/gui.rs @@ -12,9 +12,12 @@ use crate::{ roc::{self, RocElem, RocElemTag}, }; use cgmath::{Vector2, Vector4}; -use glyph_brush::OwnedSection; +use glyph_brush::{GlyphCruncher, OwnedSection}; use pipelines::RectResources; -use std::error::Error; +use std::{ + error::Error, + time::{Duration, Instant}, +}; use wgpu::{CommandEncoder, LoadOp, RenderPass, TextureView}; use wgpu_glyph::GlyphBrush; use winit::{ @@ -31,6 +34,8 @@ use winit::{ // // See this link to learn wgpu: https://sotrh.github.io/learn-wgpu/ +const TIME_BETWEEN_RENDERS: Duration = Duration::new(0, 1000 / 60); + pub fn run_event_loop(title: &str, state: roc::State) -> Result<(), Box> { // Open window and create a surface let mut event_loop = winit::event_loop::EventLoop::new(); @@ -41,7 +46,7 @@ pub fn run_event_loop(title: &str, state: roc::State) -> Result<(), Box Result<(), Box Result<(), Box Result<(), Box window.request_redraw(), Event::RedrawRequested { .. } => { + // If we shouldn't draw yet, keep waiting until we should. + let current_time = Instant::now(); + + if next_render_time.saturating_duration_since(current_time) > TIME_BETWEEN_RENDERS { + // Keep waiting until it's time to draw again. + window.request_redraw(); + + return; + } + + next_render_time = current_time + TIME_BETWEEN_RENDERS; + // Get a command cmd_encoder for the current frame let mut cmd_encoder = gpu_device.create_command_encoder(&wgpu::CommandEncoderDescriptor { @@ -203,32 +221,31 @@ pub fn run_event_loop(title: &str, state: roc::State) -> Result<(), Box { - todo!("restore RECT") - // let rect = unsafe { &elem.entry().rect }; - // let styles = rect.styles; + let rect = unsafe { &elem.entry().rect }; - // let bounds = Bounds { - // width: 500.0, - // height: 300.0, - // }; + let bounds = Bounds { + width: rect.width, + height: rect.height, + }; - // let drawable = Drawable { - // bounds, - // content: DrawableContent::FillRect { - // color: styles.bg_color, - // border_width: styles.border_width, - // border_color: styles.border_color, - // }, - // }; + let drawable = Drawable { + bounds, + content: DrawableContent::FillRect { + color: rect.color, + border_width: 1.0, + border_color: rect.color, + }, + }; - // (bounds, drawable) + (bounds, drawable) } Text => { - todo!("restore TEXT") - // let text = unsafe { &elem.entry().text }; - // let is_centered = true; // TODO don't hardcode this - // let layout = wgpu_glyph::Layout::default().h_align(if is_centered { - // wgpu_glyph::HorizontalAlign::Center - // } else { - // wgpu_glyph::HorizontalAlign::Left - // }); + let text = unsafe { &elem.entry().text }; + let is_centered = true; // TODO don't hardcode this + let layout = wgpu_glyph::Layout::default().h_align(if is_centered { + wgpu_glyph::HorizontalAlign::Center + } else { + wgpu_glyph::HorizontalAlign::Left + }); - // let section = owned_section_from_str(text.as_str(), bounds, layout); + let section = owned_section_from_str(text.as_str(), bounds, layout); - // // Calculate the bounds and offset by measuring glyphs - // let text_bounds; - // let offset; + // Calculate the bounds and offset by measuring glyphs + let text_bounds; + let offset; - // match glyph_brush.glyph_bounds(section.to_borrowed()) { - // Some(glyph_bounds) => { - // text_bounds = Bounds { - // width: glyph_bounds.max.x - glyph_bounds.min.x, - // height: glyph_bounds.max.y - glyph_bounds.min.y, - // }; + match glyph_brush.glyph_bounds(section.to_borrowed()) { + Some(glyph_bounds) => { + text_bounds = Bounds { + width: glyph_bounds.max.x - glyph_bounds.min.x, + height: glyph_bounds.max.y - glyph_bounds.min.y, + }; - // offset = (-glyph_bounds.min.x, -glyph_bounds.min.y).into(); - // } - // None => { - // text_bounds = Bounds { - // width: 0.0, - // height: 0.0, - // }; + offset = (-glyph_bounds.min.x, -glyph_bounds.min.y).into(); + } + None => { + text_bounds = Bounds { + width: 0.0, + height: 0.0, + }; - // offset = (0.0, 0.0).into(); - // } - // } + offset = (0.0, 0.0).into(); + } + } - // let drawable = Drawable { - // bounds: text_bounds, - // content: DrawableContent::Text(section, offset), - // }; + let drawable = Drawable { + bounds: text_bounds, + content: DrawableContent::Text(section, offset), + }; - // (text_bounds, drawable) + (text_bounds, drawable) } } } diff --git a/examples/breakout/platform/src/roc.rs b/examples/breakout/platform/src/roc.rs index 2c5fce2dd7..67fe35a075 100644 --- a/examples/breakout/platform/src/roc.rs +++ b/examples/breakout/platform/src/roc.rs @@ -200,7 +200,7 @@ pub struct ButtonStyles { pub text_color: Rgba, } -pub fn app_render(state: State) -> RocElem { +pub fn app_render(state: State) -> RocList { let size = unsafe { roc_program_size() } as usize; let layout = Layout::array::(size).unwrap(); @@ -219,19 +219,10 @@ pub fn app_render(state: State) -> RocElem { } } -unsafe fn call_the_closure(state: State, closure_data_ptr: *const u8) -> RocElem { +unsafe fn call_the_closure(state: State, closure_data_ptr: *const u8) -> RocList { let mut output = MaybeUninit::uninit(); - call_Render( - &state, // ({ float, float }* %arg - closure_data_ptr as *const u8, // {}* %arg1 - output.as_mut_ptr(), // { { [6 x i64], [4 x i8] }, i8 }* %arg2) - ); + call_Render(&state, closure_data_ptr as *const u8, output.as_mut_ptr()); - let answer = output.assume_init(); - - dbg!(answer); - - todo!("explode"); - // answer + output.assume_init() } From cf91390e565d468c4d4d2bd84b1410247a4029d1 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 7 Apr 2022 21:32:57 -0400 Subject: [PATCH 084/846] Avoid unnecessary request_redraw() calls --- examples/breakout/platform/src/gui.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/examples/breakout/platform/src/gui.rs b/examples/breakout/platform/src/gui.rs index 7e559ecc31..c837cda4e7 100644 --- a/examples/breakout/platform/src/gui.rs +++ b/examples/breakout/platform/src/gui.rs @@ -193,15 +193,12 @@ pub fn run_event_loop(title: &str, state: roc::State) -> Result<(), Box { keyboard_modifiers = modifiers; } - Event::MainEventsCleared => window.request_redraw(), Event::RedrawRequested { .. } => { // If we shouldn't draw yet, keep waiting until we should. let current_time = Instant::now(); if next_render_time.saturating_duration_since(current_time) > TIME_BETWEEN_RENDERS { // Keep waiting until it's time to draw again. - window.request_redraw(); - return; } From 02e1a98cac85c64a8ade21c61e4614ed777913a0 Mon Sep 17 00:00:00 2001 From: ayazhafiz Date: Thu, 7 Apr 2022 22:19:30 -0400 Subject: [PATCH 085/846] Remove redundant member --- compiler/can/src/abilities.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/compiler/can/src/abilities.rs b/compiler/can/src/abilities.rs index 5665b765be..5998f9da8e 100644 --- a/compiler/can/src/abilities.rs +++ b/compiler/can/src/abilities.rs @@ -27,16 +27,12 @@ pub struct AbilitiesStore { members_of_ability: MutMap>, /// Information about all members composing abilities. - #[allow(unused)] ability_members: MutMap, /// Tuples of (type, member) specifying that `type` declares an implementation of an ability /// member `member`. #[allow(unused)] declared_implementations: MutSet<(Symbol, Symbol)>, - - /// Cache of all ability member names in scope. - ability_member_symbols: MutSet, } impl AbilitiesStore { @@ -57,9 +53,6 @@ impl AbilitiesStore { }, ); debug_assert!(old_member.is_none(), "Replacing existing member definition"); - - let old_member = self.ability_member_symbols.insert(member); - debug_assert!(!old_member, "Replacing existing member entry"); } let old_ability = self.members_of_ability.insert(ability, members_vec); debug_assert!( @@ -76,6 +69,6 @@ impl AbilitiesStore { } pub fn is_ability_member_name(&self, name: Symbol) -> bool { - self.ability_member_symbols.contains(&name) + self.ability_members.contains_key(&name) } } From 13a17f18589976640a2de3b97ea14c0fe8b91b8d Mon Sep 17 00:00:00 2001 From: ayazhafiz Date: Thu, 7 Apr 2022 22:26:17 -0400 Subject: [PATCH 086/846] Improve error message --- reporting/src/error/canonicalize.rs | 10 ++++++++++ reporting/tests/test_reporting.rs | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/reporting/src/error/canonicalize.rs b/reporting/src/error/canonicalize.rs index 24a27f5e9c..2a806844f5 100644 --- a/reporting/src/error/canonicalize.rs +++ b/reporting/src/error/canonicalize.rs @@ -615,6 +615,16 @@ pub fn can_problem<'b>( alloc.reflow(":"), ]), alloc.region(lines.convert_region(region)), + alloc.concat(vec![ + alloc.reflow("Abilities are not types, but you can add an ability constraint to a type variable "), + alloc.type_variable("a".into()), + alloc.reflow(" by writing"), + ]), + alloc.type_block(alloc.concat(vec![ + alloc.reflow("| a has "), + alloc.symbol_unqualified(ability), + ])), + alloc.reflow(" at the end of the type."), ]); title = ALIAS_USES_ABILITY.to_string(); severity = Severity::RuntimeError; diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 73b427947a..f3377fbfd4 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -9030,6 +9030,13 @@ I need all branches in an `if` to have the same type! 3│ Alias : Ability ^^^^^ + Abilities are not types, but you can add an ability constraint to a + type variable `a` by writing + + | a has Ability + + at the end of the type. + ── UNUSED DEFINITION ─────────────────────────────────────────────────────────── `ab` is not used anywhere in your code. From 94a5cd35590ce4ea4c394a444951de2d4e7b9067 Mon Sep 17 00:00:00 2001 From: ayazhafiz Date: Thu, 7 Apr 2022 22:38:20 -0400 Subject: [PATCH 087/846] Improve shadow errors --- ast/src/lang/core/def/def.rs | 2 +- compiler/can/src/annotation.rs | 7 +++++-- compiler/can/src/def.rs | 17 +++++++++++------ compiler/can/src/pattern.rs | 6 +++++- compiler/mono/src/ir.rs | 4 +++- compiler/problem/src/can.rs | 12 +++++++++++- reporting/src/error/canonicalize.rs | 24 ++++++++++++++++++------ reporting/tests/test_reporting.rs | 6 +++--- 8 files changed, 57 insertions(+), 21 deletions(-) diff --git a/ast/src/lang/core/def/def.rs b/ast/src/lang/core/def/def.rs index 46dc57f072..9747245ce4 100644 --- a/ast/src/lang/core/def/def.rs +++ b/ast/src/lang/core/def/def.rs @@ -251,7 +251,7 @@ fn to_pending_def<'a>( } Err((original_region, loc_shadowed_symbol)) => { - env.problem(Problem::ShadowingInAnnotation { + env.problem(Problem::Shadowing { original_region, shadow: loc_shadowed_symbol, }); diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index 4245091e9d..c8af0d3e0a 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -4,6 +4,7 @@ use roc_collections::all::{ImMap, MutMap, MutSet, SendMap}; use roc_module::ident::{Ident, Lowercase, TagName}; use roc_module::symbol::{IdentIds, ModuleId, Symbol}; use roc_parse::ast::{AssignedField, ExtractSpaces, Pattern, Tag, TypeAnnotation, TypeHeader}; +use roc_problem::can::ShadowKind; use roc_region::all::{Loc, Region}; use roc_types::subs::{VarStore, Variable}; use roc_types::types::{ @@ -530,9 +531,10 @@ fn can_annotation_help( Err((original_region, shadow, _new_symbol)) => { let problem = Problem::Shadowed(original_region, shadow.clone()); - env.problem(roc_problem::can::Problem::ShadowingInAnnotation { + env.problem(roc_problem::can::Problem::Shadowing { original_region, shadow, + kind: ShadowKind::Variable, }); return Type::Erroneous(problem); @@ -833,9 +835,10 @@ fn canonicalize_has_clause( if let Some(shadowing) = introduced_variables.named_var_by_name(&var_name) { let var_name_ident = var_name.to_string().into(); let shadow = Loc::at(region, var_name_ident); - env.problem(roc_problem::can::Problem::ShadowingInAnnotation { + env.problem(roc_problem::can::Problem::Shadowing { original_region: shadowing.first_seen, shadow: shadow.clone(), + kind: ShadowKind::Variable, }); return Err(Type::Erroneous(Problem::Shadowed( shadowing.first_seen, diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 3a0dfde6a7..460b8a5efc 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -19,6 +19,7 @@ use roc_parse::ast::AbilityMember; use roc_parse::ast::ExtractSpaces; use roc_parse::ast::TypeHeader; use roc_parse::pattern::PatternType; +use roc_problem::can::ShadowKind; use roc_problem::can::{CycleEntry, Problem, RuntimeError}; use roc_region::all::{Loc, Region}; use roc_types::subs::{VarStore, Variable}; @@ -459,9 +460,10 @@ pub fn canonicalize_defs<'a>( ) { Ok(sym) => sym, Err((original_region, shadow, _new_symbol)) => { - env.problem(roc_problem::can::Problem::ShadowingInAnnotation { + env.problem(roc_problem::can::Problem::Shadowing { original_region, shadow, + kind: ShadowKind::Variable, }); // Pretend the member isn't a part of the ability continue; @@ -1149,6 +1151,7 @@ fn canonicalize_pending_value_def<'a>( Pattern::Shadowed(region, loc_ident, _new_symbol) => RuntimeError::Shadowing { original_region: *region, shadow: loc_ident.clone(), + kind: ShadowKind::Variable, }, _ => RuntimeError::NoImplementation, }; @@ -1649,10 +1652,10 @@ fn to_pending_type_def<'a>( header: TypeHeader { name, vars }, typ: ann, } => { - let kind = if matches!(def, Alias { .. }) { - AliasKind::Structural + let (kind, shadow_kind) = if matches!(def, Alias { .. }) { + (AliasKind::Structural, ShadowKind::Alias) } else { - AliasKind::Opaque + (AliasKind::Opaque, ShadowKind::Opaque) }; let region = Region::span_across(&name.region, &ann.region); @@ -1709,9 +1712,10 @@ fn to_pending_type_def<'a>( } Err((original_region, loc_shadowed_symbol, _new_symbol)) => { - env.problem(Problem::ShadowingInAnnotation { + env.problem(Problem::Shadowing { original_region, shadow: loc_shadowed_symbol, + kind: shadow_kind, }); Some((Output::default(), PendingTypeDef::InvalidAlias { kind })) @@ -1732,9 +1736,10 @@ fn to_pending_type_def<'a>( ) { Ok(symbol) => Loc::at(name.region, symbol), Err((original_region, shadowed_symbol)) => { - env.problem(Problem::ShadowingInAnnotation { + env.problem(Problem::Shadowing { original_region, shadow: shadowed_symbol, + kind: ShadowKind::Ability, }); return Some((Output::default(), PendingTypeDef::InvalidAbility)); } diff --git a/compiler/can/src/pattern.rs b/compiler/can/src/pattern.rs index c8963a045a..251c889a0c 100644 --- a/compiler/can/src/pattern.rs +++ b/compiler/can/src/pattern.rs @@ -11,7 +11,7 @@ use roc_module::ident::{Ident, Lowercase, TagName}; use roc_module::symbol::Symbol; use roc_parse::ast::{self, StrLiteral, StrSegment}; use roc_parse::pattern::PatternType; -use roc_problem::can::{MalformedPatternProblem, Problem, RuntimeError}; +use roc_problem::can::{MalformedPatternProblem, Problem, RuntimeError, ShadowKind}; use roc_region::all::{Loc, Region}; use roc_types::subs::{VarStore, Variable}; use roc_types::types::{LambdaSet, Type}; @@ -191,6 +191,7 @@ pub fn canonicalize_def_header_pattern<'a>( env.problem(Problem::RuntimeError(RuntimeError::Shadowing { original_region, shadow: shadow.clone(), + kind: ShadowKind::Variable, })); output.references.bound_symbols.insert(new_symbol); @@ -230,6 +231,7 @@ pub fn canonicalize_pattern<'a>( env.problem(Problem::RuntimeError(RuntimeError::Shadowing { original_region, shadow: shadow.clone(), + kind: ShadowKind::Variable, })); output.references.bound_symbols.insert(new_symbol); @@ -478,6 +480,7 @@ pub fn canonicalize_pattern<'a>( env.problem(Problem::RuntimeError(RuntimeError::Shadowing { original_region, shadow: shadow.clone(), + kind: ShadowKind::Variable, })); // No matter what the other patterns @@ -550,6 +553,7 @@ pub fn canonicalize_pattern<'a>( env.problem(Problem::RuntimeError(RuntimeError::Shadowing { original_region, shadow: shadow.clone(), + kind: ShadowKind::Variable, })); // No matter what the other patterns diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 2ef2290aed..30b9fae704 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -13,7 +13,7 @@ use roc_exhaustive::{Ctor, Guard, RenderAs, TagId}; use roc_module::ident::{ForeignSymbol, Lowercase, TagName}; use roc_module::low_level::LowLevel; use roc_module::symbol::{IdentIds, ModuleId, Symbol}; -use roc_problem::can::RuntimeError; +use roc_problem::can::{RuntimeError, ShadowKind}; use roc_region::all::{Loc, Region}; use roc_std::RocDec; use roc_target::TargetInfo; @@ -2037,6 +2037,7 @@ fn pattern_to_when<'a>( let error = roc_problem::can::RuntimeError::Shadowing { original_region: *region, shadow: loc_ident.clone(), + kind: ShadowKind::Variable, }; (*new_symbol, Loc::at_zero(RuntimeError(error))) } @@ -7838,6 +7839,7 @@ fn from_can_pattern_help<'a>( Shadowed(region, ident, _new_symbol) => Err(RuntimeError::Shadowing { original_region: *region, shadow: ident.clone(), + kind: ShadowKind::Variable, }), UnsupportedPattern(region) => Err(RuntimeError::UnsupportedPattern(*region)), MalformedPattern(_problem, region) => { diff --git a/compiler/problem/src/can.rs b/compiler/problem/src/can.rs index 56756a8508..d35d93b307 100644 --- a/compiler/problem/src/can.rs +++ b/compiler/problem/src/can.rs @@ -20,6 +20,14 @@ pub enum BadPattern { Unsupported(PatternType), } +#[derive(Clone, Copy, Debug, PartialEq)] +pub enum ShadowKind { + Variable, + Alias, + Opaque, + Ability, +} + /// Problems that can occur in the course of canonicalization. #[derive(Clone, Debug, PartialEq)] pub enum Problem { @@ -33,9 +41,10 @@ pub enum Problem { PrecedenceProblem(PrecedenceProblem), // Example: (5 = 1 + 2) is an unsupported pattern in an assignment; Int patterns aren't allowed in assignments! UnsupportedPattern(BadPattern, Region), - ShadowingInAnnotation { + Shadowing { original_region: Region, shadow: Loc, + kind: ShadowKind, }, CyclicAlias(Symbol, Region, Vec), BadRecursion(Vec), @@ -181,6 +190,7 @@ pub enum RuntimeError { Shadowing { original_region: Region, shadow: Loc, + kind: ShadowKind, }, InvalidOptionalValue { field_name: Lowercase, diff --git a/reporting/src/error/canonicalize.rs b/reporting/src/error/canonicalize.rs index 2a806844f5..c804905ae2 100644 --- a/reporting/src/error/canonicalize.rs +++ b/reporting/src/error/canonicalize.rs @@ -2,7 +2,7 @@ use roc_collections::all::MutSet; use roc_module::ident::{Ident, Lowercase, ModuleName}; use roc_problem::can::PrecedenceProblem::BothNonAssociative; use roc_problem::can::{ - BadPattern, ExtensionTypeKind, FloatErrorKind, IntErrorKind, Problem, RuntimeError, + BadPattern, ExtensionTypeKind, FloatErrorKind, IntErrorKind, Problem, RuntimeError, ShadowKind, }; use roc_region::all::{LineColumn, LineColumnRegion, LineInfo, Loc, Region}; use roc_types::types::AliasKind; @@ -219,11 +219,12 @@ pub fn can_problem<'b>( title = SYNTAX_PROBLEM.to_string(); severity = Severity::RuntimeError; } - Problem::ShadowingInAnnotation { + Problem::Shadowing { original_region, shadow, + kind, } => { - doc = report_shadowing(alloc, lines, original_region, shadow); + doc = report_shadowing(alloc, lines, original_region, shadow, kind); title = DUPLICATE_NAME.to_string(); severity = Severity::RuntimeError; @@ -1084,8 +1085,14 @@ fn report_shadowing<'b>( lines: &LineInfo, original_region: Region, shadow: Loc, + kind: ShadowKind, ) -> RocDocBuilder<'b> { - let line = r#"Since these variables have the same name, it's easy to use the wrong one on accident. Give one of them a new name."#; + let what = match kind { + ShadowKind::Variable => "variables", + ShadowKind::Alias => "aliases", + ShadowKind::Opaque => "opaques", + ShadowKind::Ability => "abilities", + }; alloc.stack(vec![ alloc @@ -1095,7 +1102,11 @@ fn report_shadowing<'b>( alloc.region(lines.convert_region(original_region)), alloc.reflow("But then it's defined a second time here:"), alloc.region(lines.convert_region(shadow.region)), - alloc.reflow(line), + alloc.concat(vec![ + alloc.reflow("Since these "), + alloc.reflow(what), + alloc.reflow(" have the same name, it's easy to use the wrong one on accident. Give one of them a new name."), + ]), ]) } @@ -1122,8 +1133,9 @@ fn pretty_runtime_error<'b>( RuntimeError::Shadowing { original_region, shadow, + kind, } => { - doc = report_shadowing(alloc, lines, original_region, shadow); + doc = report_shadowing(alloc, lines, original_region, shadow, kind); title = DUPLICATE_NAME; } diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index f3377fbfd4..65525012f1 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -430,8 +430,8 @@ mod test_reporting { 3│ Booly : [ Yes, No, Maybe ] ^^^^^^^^^^^^^^^^^^^^^^^^^^ - Since these variables have the same name, it's easy to use the wrong - one on accident. Give one of them a new name. + Since these aliases have the same name, it's easy to use the wrong one + on accident. Give one of them a new name. ── UNUSED DEFINITION ─────────────────────────────────────────────────────────── @@ -9077,7 +9077,7 @@ I need all branches in an `if` to have the same type! 3│ Ability has ab1 : a -> U64 | a has Ability ^^^^^^^ - Since these variables have the same name, it's easy to use the wrong + Since these abilities have the same name, it's easy to use the wrong one on accident. Give one of them a new name. ── UNUSED DEFINITION ─────────────────────────────────────────────────────────── From 33a5fc65ced29b49269e82aabd135d7f318ee2f4 Mon Sep 17 00:00:00 2001 From: Ayaz <20735482+ayazhafiz@users.noreply.github.com> Date: Fri, 8 Apr 2022 08:50:31 -0400 Subject: [PATCH 088/846] Update comment --- compiler/mono/src/ir.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index b05fc75072..4bf77d3e36 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -6782,8 +6782,7 @@ fn let_empty_struct<'a>(assigned: Symbol, hole: &'a Stmt<'a>) -> Stmt<'a> { Stmt::Let(assigned, Expr::Struct(&[]), Layout::UNIT, hole) } -/// If the symbol is a function, make sure it is properly specialized -// TODO: rename this now that we handle polymorphic non-function expressions too +/// If the symbol is a function or polymorphic value, make sure it is properly specialized fn specialize_symbol<'a>( env: &mut Env<'a, '_>, procs: &mut Procs<'a>, From b3aee4ba7caff095953912a86497774134f84fec Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 8 Apr 2022 08:54:31 -0400 Subject: [PATCH 089/846] Fix typecheck error --- ast/src/lang/core/def/def.rs | 3 ++- ast/src/lang/core/pattern.rs | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ast/src/lang/core/def/def.rs b/ast/src/lang/core/def/def.rs index 9747245ce4..5ade55dcd0 100644 --- a/ast/src/lang/core/def/def.rs +++ b/ast/src/lang/core/def/def.rs @@ -18,7 +18,7 @@ use roc_module::ident::Lowercase; use roc_module::symbol::Symbol; use roc_parse::ast::{self, TypeDef, TypeHeader, ValueDef as AstValueDef}; use roc_parse::pattern::PatternType; -use roc_problem::can::{Problem, RuntimeError}; +use roc_problem::can::{Problem, RuntimeError, ShadowKind}; use roc_region::all::{Loc, Region}; use roc_types::subs::{VarStore, Variable}; use std::collections::HashMap; @@ -254,6 +254,7 @@ fn to_pending_def<'a>( env.problem(Problem::Shadowing { original_region, shadow: loc_shadowed_symbol, + kind: ShadowKind::Variable, }); Some((Output::default(), PendingDef::InvalidAlias)) diff --git a/ast/src/lang/core/pattern.rs b/ast/src/lang/core/pattern.rs index 069f8ae913..13d91a9850 100644 --- a/ast/src/lang/core/pattern.rs +++ b/ast/src/lang/core/pattern.rs @@ -12,7 +12,7 @@ use roc_error_macros::todo_opaques; use roc_module::symbol::{Interns, Symbol}; use roc_parse::ast::{StrLiteral, StrSegment}; use roc_parse::pattern::PatternType; -use roc_problem::can::{MalformedPatternProblem, Problem, RuntimeError}; +use roc_problem::can::{MalformedPatternProblem, Problem, RuntimeError, ShadowKind}; use roc_region::all::Region; use roc_types::subs::Variable; @@ -161,6 +161,7 @@ pub fn to_pattern2<'a>( env.problem(Problem::RuntimeError(RuntimeError::Shadowing { original_region, shadow: shadow.clone(), + kind: ShadowKind::Variable, })); let name: &str = shadow.value.as_ref(); @@ -364,6 +365,7 @@ pub fn to_pattern2<'a>( env.problem(Problem::RuntimeError(RuntimeError::Shadowing { original_region, shadow: shadow.clone(), + kind: ShadowKind::Variable, })); // let shadowed = Pattern2::Shadowed { @@ -443,6 +445,7 @@ pub fn to_pattern2<'a>( env.problem(Problem::RuntimeError(RuntimeError::Shadowing { original_region, shadow: shadow.clone(), + kind: ShadowKind::Variable, })); // No matter what the other patterns From beee95f83c09c4068acc08d247bb79ce700be656 Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 8 Apr 2022 16:02:30 +0200 Subject: [PATCH 090/846] parse the header of builtins too --- compiler/load_internal/src/file.rs | 700 ++++------------------------- 1 file changed, 89 insertions(+), 611 deletions(-) diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index 2180ef4c89..31f99559c4 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -77,8 +77,6 @@ macro_rules! log { ($($arg:tt)*) => (if SHOW_MESSAGE_LOG { println!($($arg)*); } else {}) } -const BUILTIN_MODULES: &[(ModuleId, &[ModuleId])] = &[(ModuleId::RESULT, &[])]; - /// Struct storing various intermediate stages by their ModuleId #[derive(Debug)] struct ModuleCache<'a> { @@ -2436,6 +2434,63 @@ fn load_pkg_config<'a>( } } +fn foo<'a>( + arena: &'a Bump, + filename: &str, + src_bytes: &'a str, +) -> (HeaderInfo<'a>, roc_parse::state::State<'a>) { + let is_root_module = false; + let opt_shorthand = None; + + let filename = PathBuf::from(filename); + + let parse_state = roc_parse::state::State::new(src_bytes.as_bytes()); + let parsed = roc_parse::module::parse_header(arena, parse_state.clone()); + + match parsed { + Ok((ast::Module::Interface { header }, parse_state)) => { + let info = HeaderInfo { + loc_name: Loc { + region: header.name.region, + value: ModuleNameEnum::Interface(header.name.value), + }, + filename, + is_root_module, + opt_shorthand, + packages: &[], + exposes: unspace(arena, header.exposes.items), + imports: unspace(arena, header.imports.items), + extra: HeaderFor::Interface, + }; + + (info, parse_state) + } + Ok(_) => panic!("invalid header format for builtin module"), + Err(e) => todo!(), + } +} + +fn load_builtin_module<'a>( + arena: &'a Bump, + module_ids: Arc>>, + ident_ids_by_module: Arc>>, + module_timing: ModuleTiming, + module_id: ModuleId, + module_name: &str, +) -> (ModuleId, Msg<'a>) { + let src_bytes = module_source(module_id); + + let (info, parse_state) = foo(arena, module_name, src_bytes); + + send_header( + info, + parse_state, + module_ids, + ident_ids_by_module, + module_timing, + ) +} + /// Load a module by its module name, rather than by its filename fn load_module<'a>( arena: &'a Bump, @@ -2457,660 +2512,83 @@ fn load_module<'a>( module_timing.parse_header = parse_header_duration; match module_name.as_inner().as_str() { "Result" => { - let filename = PathBuf::from("Result.roc"); - - const EXPOSES: &[Loc] = &[ - Loc::at_zero(ExposedName::new("Result")), - Loc::at_zero(ExposedName::new("isOk")), - Loc::at_zero(ExposedName::new("isErr")), - Loc::at_zero(ExposedName::new("map")), - Loc::at_zero(ExposedName::new("mapErr")), - Loc::at_zero(ExposedName::new("after")), - Loc::at_zero(ExposedName::new("withDefault")), - ]; - - const IMPORTS: &[Loc] = &[Loc::at_zero(ImportsEntry::Module( - roc_parse::header::ModuleName::new("Bool"), - Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("Bool")))]), - ))]; - - let info = HeaderInfo { - loc_name: Loc { - region: Region::zero(), - value: ModuleNameEnum::Interface(roc_parse::header::ModuleName::new("Result")), - }, - filename, - is_root_module: false, - opt_shorthand: None, - packages: &[], - exposes: EXPOSES, - imports: IMPORTS, - extra: HeaderFor::Builtin { - generates_with: &[], - }, - }; - - let src_bytes = module_source(ModuleId::RESULT); - - let parse_state = roc_parse::state::State::new(src_bytes.as_bytes()); - - return Ok(send_header( - info, - parse_state, + return Ok(load_builtin_module( + arena, module_ids, ident_ids_by_module, module_timing, + ModuleId::RESULT, + "Result.roc", )); } "List" => { - let filename = PathBuf::from("List.roc"); - - const EXPOSES: &[Loc] = &[ - Loc::at_zero(ExposedName::new("isEmpty")), - Loc::at_zero(ExposedName::new("get")), - Loc::at_zero(ExposedName::new("set")), - Loc::at_zero(ExposedName::new("replace")), - Loc::at_zero(ExposedName::new("append")), - Loc::at_zero(ExposedName::new("map")), - Loc::at_zero(ExposedName::new("len")), - Loc::at_zero(ExposedName::new("walkBackwards")), - Loc::at_zero(ExposedName::new("concat")), - Loc::at_zero(ExposedName::new("first")), - Loc::at_zero(ExposedName::new("single")), - Loc::at_zero(ExposedName::new("repeat")), - Loc::at_zero(ExposedName::new("reverse")), - Loc::at_zero(ExposedName::new("prepend")), - Loc::at_zero(ExposedName::new("join")), - Loc::at_zero(ExposedName::new("keepIf")), - Loc::at_zero(ExposedName::new("contains")), - Loc::at_zero(ExposedName::new("sum")), - Loc::at_zero(ExposedName::new("walk")), - Loc::at_zero(ExposedName::new("last")), - Loc::at_zero(ExposedName::new("keepOks")), - Loc::at_zero(ExposedName::new("keepErrs")), - Loc::at_zero(ExposedName::new("mapWithIndex")), - Loc::at_zero(ExposedName::new("map2")), - Loc::at_zero(ExposedName::new("map3")), - Loc::at_zero(ExposedName::new("product")), - Loc::at_zero(ExposedName::new("walkUntil")), - Loc::at_zero(ExposedName::new("range")), - Loc::at_zero(ExposedName::new("sortWith")), - Loc::at_zero(ExposedName::new("drop")), - Loc::at_zero(ExposedName::new("swap")), - Loc::at_zero(ExposedName::new("dropAt")), - Loc::at_zero(ExposedName::new("dropLast")), - Loc::at_zero(ExposedName::new("min")), - Loc::at_zero(ExposedName::new("max")), - Loc::at_zero(ExposedName::new("map4")), - Loc::at_zero(ExposedName::new("dropFirst")), - Loc::at_zero(ExposedName::new("joinMap")), - Loc::at_zero(ExposedName::new("any")), - Loc::at_zero(ExposedName::new("takeFirst")), - Loc::at_zero(ExposedName::new("takeLast")), - Loc::at_zero(ExposedName::new("find")), - Loc::at_zero(ExposedName::new("sublist")), - Loc::at_zero(ExposedName::new("intersperse")), - Loc::at_zero(ExposedName::new("split")), - Loc::at_zero(ExposedName::new("all")), - Loc::at_zero(ExposedName::new("dropIf")), - Loc::at_zero(ExposedName::new("sortAsc")), - Loc::at_zero(ExposedName::new("sortDesc")), - ]; - - const IMPORTS: &[Loc] = &[ - Loc::at_zero(ImportsEntry::Module( - roc_parse::header::ModuleName::new("Result"), - Collection::with_items( - arena.alloc([Loc::at_zero(Spaced::Item(ExposedName::new("Result")))]), - ), - )), - Loc::at_zero(ImportsEntry::Module( - roc_parse::header::ModuleName::new("Bool"), - Collection::with_items( - arena.alloc([Loc::at_zero(Spaced::Item(ExposedName::new("Bool")))]), - ), - )), - Loc::at_zero(ImportsEntry::Module( - roc_parse::header::ModuleName::new("Num"), - Collection::with_items( - arena.alloc([Loc::at_zero(Spaced::Item(ExposedName::new("Nat")))]), - ), - )), - ]; - - const GENERATES_WITH: &[Symbol] = &[]; - - let info = HeaderInfo { - loc_name: Loc { - region: Region::zero(), - value: ModuleNameEnum::Interface(roc_parse::header::ModuleName::new("List")), - }, - filename, - is_root_module: false, - opt_shorthand: None, - packages: &[], - exposes: EXPOSES, - imports: IMPORTS, - extra: HeaderFor::Builtin { - generates_with: GENERATES_WITH, - }, - }; - - let src_bytes = module_source(ModuleId::LIST); - - let parse_state = roc_parse::state::State::new(src_bytes.as_bytes()); - - return Ok(send_header( - info, - parse_state, + return Ok(load_builtin_module( + arena, module_ids, ident_ids_by_module, module_timing, + ModuleId::LIST, + "List.roc", )); } "Str" => { - let filename = PathBuf::from("Str.roc"); - - const EXPOSES: &[Loc] = &[ - Loc::at_zero(ExposedName::new("concat")), - Loc::at_zero(ExposedName::new("Utf8Problem")), - Loc::at_zero(ExposedName::new("Utf8ByteProblem")), - Loc::at_zero(ExposedName::new("isEmpty")), - Loc::at_zero(ExposedName::new("joinWith")), - Loc::at_zero(ExposedName::new("split")), - Loc::at_zero(ExposedName::new("repeat")), - Loc::at_zero(ExposedName::new("countGraphemes")), - Loc::at_zero(ExposedName::new("startsWithCodePt")), - Loc::at_zero(ExposedName::new("toUtf8")), - Loc::at_zero(ExposedName::new("fromUtf8")), - Loc::at_zero(ExposedName::new("fromUtf8Range")), - Loc::at_zero(ExposedName::new("startsWith")), - Loc::at_zero(ExposedName::new("endsWith")), - Loc::at_zero(ExposedName::new("trim")), - Loc::at_zero(ExposedName::new("trimLeft")), - Loc::at_zero(ExposedName::new("trimRight")), - // - Loc::at_zero(ExposedName::new("toDec")), - Loc::at_zero(ExposedName::new("toF64")), - Loc::at_zero(ExposedName::new("toF32")), - Loc::at_zero(ExposedName::new("toNat")), - Loc::at_zero(ExposedName::new("toU128")), - Loc::at_zero(ExposedName::new("toI128")), - Loc::at_zero(ExposedName::new("toU64")), - Loc::at_zero(ExposedName::new("toI64")), - Loc::at_zero(ExposedName::new("toU32")), - Loc::at_zero(ExposedName::new("toI32")), - Loc::at_zero(ExposedName::new("toU16")), - Loc::at_zero(ExposedName::new("toI16")), - Loc::at_zero(ExposedName::new("toU8")), - Loc::at_zero(ExposedName::new("toI8")), - ]; - - const IMPORTS: &[Loc] = &[ - Loc::at_zero(ImportsEntry::Module( - roc_parse::header::ModuleName::new("Result"), - Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new( - "Result", - )))]), - )), - Loc::at_zero(ImportsEntry::Module( - roc_parse::header::ModuleName::new("Bool"), - Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("Bool")))]), - )), - Loc::at_zero(ImportsEntry::Module( - roc_parse::header::ModuleName::new("List"), - Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("List")))]), - )), - Loc::at_zero(ImportsEntry::Module( - roc_parse::header::ModuleName::new("Num"), - Collection::with_items(&[ - Loc::at_zero(Spaced::Item(ExposedName::new("Int"))), // needed because used by the aliases below - Loc::at_zero(Spaced::Item(ExposedName::new("Float"))), // needed because used by the aliases below - Loc::at_zero(Spaced::Item(ExposedName::new("Dec"))), - Loc::at_zero(Spaced::Item(ExposedName::new("F64"))), - Loc::at_zero(Spaced::Item(ExposedName::new("F32"))), - Loc::at_zero(Spaced::Item(ExposedName::new("Nat"))), - Loc::at_zero(Spaced::Item(ExposedName::new("U128"))), - Loc::at_zero(Spaced::Item(ExposedName::new("I128"))), - Loc::at_zero(Spaced::Item(ExposedName::new("U64"))), - Loc::at_zero(Spaced::Item(ExposedName::new("I64"))), - Loc::at_zero(Spaced::Item(ExposedName::new("U32"))), - Loc::at_zero(Spaced::Item(ExposedName::new("I32"))), - Loc::at_zero(Spaced::Item(ExposedName::new("U16"))), - Loc::at_zero(Spaced::Item(ExposedName::new("I16"))), - Loc::at_zero(Spaced::Item(ExposedName::new("U8"))), - Loc::at_zero(Spaced::Item(ExposedName::new("I8"))), - ]), - )), - ]; - - const GENERATES_WITH: &[Symbol] = &[]; - - let info = HeaderInfo { - loc_name: Loc { - region: Region::zero(), - value: ModuleNameEnum::Interface(roc_parse::header::ModuleName::new("Str")), - }, - filename, - is_root_module: false, - opt_shorthand: None, - packages: &[], - exposes: EXPOSES, - imports: IMPORTS, - extra: HeaderFor::Builtin { - generates_with: GENERATES_WITH, - }, - }; - - let src_bytes = module_source(ModuleId::STR); - - let parse_state = roc_parse::state::State::new(src_bytes.as_bytes()); - - return Ok(send_header( - info, - parse_state, + return Ok(load_builtin_module( + arena, module_ids, ident_ids_by_module, module_timing, + ModuleId::STR, + "Str.roc", )); } "Dict" => { - let filename = PathBuf::from("Dict.roc"); - - const EXPOSES: &[Loc] = &[ - Loc::at_zero(ExposedName::new("empty")), - Loc::at_zero(ExposedName::new("single")), - Loc::at_zero(ExposedName::new("get")), - Loc::at_zero(ExposedName::new("walk")), - Loc::at_zero(ExposedName::new("insert")), - Loc::at_zero(ExposedName::new("len")), - Loc::at_zero(ExposedName::new("remove")), - Loc::at_zero(ExposedName::new("contains")), - Loc::at_zero(ExposedName::new("keys")), - Loc::at_zero(ExposedName::new("values")), - Loc::at_zero(ExposedName::new("union")), - Loc::at_zero(ExposedName::new("intersection")), - Loc::at_zero(ExposedName::new("difference")), - ]; - const IMPORTS: &[Loc] = &[ - Loc::at_zero(ImportsEntry::Module( - roc_parse::header::ModuleName::new("Result"), - Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new( - "Result", - )))]), - )), - Loc::at_zero(ImportsEntry::Module( - roc_parse::header::ModuleName::new("Bool"), - Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("Bool")))]), - )), - Loc::at_zero(ImportsEntry::Module( - roc_parse::header::ModuleName::new("List"), - Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("List")))]), - )), - Loc::at_zero(ImportsEntry::Module( - roc_parse::header::ModuleName::new("Num"), - Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("Nat")))]), - )), - ]; - - const GENERATES_WITH: &[Symbol] = &[]; - - let info = HeaderInfo { - loc_name: Loc { - region: Region::zero(), - value: ModuleNameEnum::Interface(roc_parse::header::ModuleName::new("Dict")), - }, - filename, - is_root_module: false, - opt_shorthand: None, - packages: &[], - exposes: EXPOSES, - imports: IMPORTS, - extra: HeaderFor::Builtin { - generates_with: GENERATES_WITH, - }, - }; - - let src_bytes = module_source(ModuleId::DICT); - - let parse_state = roc_parse::state::State::new(src_bytes.as_bytes()); - - return Ok(send_header( - info, - parse_state, + return Ok(load_builtin_module( + arena, module_ids, ident_ids_by_module, module_timing, + ModuleId::DICT, + "Dict.roc", )); } "Set" => { - let filename = PathBuf::from("Set.roc"); - - const EXPOSES: &[Loc] = &[ - Loc::at_zero(ExposedName::new("empty")), - Loc::at_zero(ExposedName::new("single")), - Loc::at_zero(ExposedName::new("walk")), - Loc::at_zero(ExposedName::new("insert")), - Loc::at_zero(ExposedName::new("len")), - Loc::at_zero(ExposedName::new("remove")), - Loc::at_zero(ExposedName::new("contains")), - Loc::at_zero(ExposedName::new("toList")), - Loc::at_zero(ExposedName::new("fromList")), - Loc::at_zero(ExposedName::new("union")), - Loc::at_zero(ExposedName::new("intersection")), - Loc::at_zero(ExposedName::new("difference")), - ]; - const IMPORTS: &[Loc] = &[ - Loc::at_zero(ImportsEntry::Module( - roc_parse::header::ModuleName::new("Result"), - Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new( - "Result", - )))]), - )), - Loc::at_zero(ImportsEntry::Module( - roc_parse::header::ModuleName::new("Bool"), - Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("Bool")))]), - )), - Loc::at_zero(ImportsEntry::Module( - roc_parse::header::ModuleName::new("List"), - Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("List")))]), - )), - Loc::at_zero(ImportsEntry::Module( - roc_parse::header::ModuleName::new("Dict"), - Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("Dict")))]), - )), - Loc::at_zero(ImportsEntry::Module( - roc_parse::header::ModuleName::new("Num"), - Collection::with_items(&[Loc::at_zero(Spaced::Item(ExposedName::new("Nat")))]), - )), - ]; - - const GENERATES_WITH: &[Symbol] = &[]; - - let info = HeaderInfo { - loc_name: Loc { - region: Region::zero(), - value: ModuleNameEnum::Interface(roc_parse::header::ModuleName::new("Set")), - }, - filename, - is_root_module: false, - opt_shorthand: None, - packages: &[], - exposes: EXPOSES, - imports: IMPORTS, - extra: HeaderFor::Builtin { - generates_with: GENERATES_WITH, - }, - }; - - let src_bytes = module_source(ModuleId::SET); - - let parse_state = roc_parse::state::State::new(src_bytes.as_bytes()); - - return Ok(send_header( - info, - parse_state, + return Ok(load_builtin_module( + arena, module_ids, ident_ids_by_module, module_timing, + ModuleId::SET, + "Set.roc", )); } "Num" => { - let filename = PathBuf::from("Num.roc"); - - const EXPOSES: &[Loc] = &[ - Loc::at_zero(ExposedName::new("Num")), - Loc::at_zero(ExposedName::new("Int")), - Loc::at_zero(ExposedName::new("Float")), - // - Loc::at_zero(ExposedName::new("Integer")), - Loc::at_zero(ExposedName::new("FloatingPoint")), - // - Loc::at_zero(ExposedName::new("I128")), - Loc::at_zero(ExposedName::new("I64")), - Loc::at_zero(ExposedName::new("I32")), - Loc::at_zero(ExposedName::new("I16")), - Loc::at_zero(ExposedName::new("I8")), - // - Loc::at_zero(ExposedName::new("U128")), - Loc::at_zero(ExposedName::new("U64")), - Loc::at_zero(ExposedName::new("U32")), - Loc::at_zero(ExposedName::new("U16")), - Loc::at_zero(ExposedName::new("U8")), - // - Loc::at_zero(ExposedName::new("Signed128")), - Loc::at_zero(ExposedName::new("Signed64")), - Loc::at_zero(ExposedName::new("Signed32")), - Loc::at_zero(ExposedName::new("Signed16")), - Loc::at_zero(ExposedName::new("Signed8")), - // - Loc::at_zero(ExposedName::new("Unsigned128")), - Loc::at_zero(ExposedName::new("Unsigned64")), - Loc::at_zero(ExposedName::new("Unsigned32")), - Loc::at_zero(ExposedName::new("Unsigned16")), - Loc::at_zero(ExposedName::new("Unsigned8")), - // - Loc::at_zero(ExposedName::new("Nat")), - Loc::at_zero(ExposedName::new("Dec")), - // - Loc::at_zero(ExposedName::new("F32")), - Loc::at_zero(ExposedName::new("F64")), - // - Loc::at_zero(ExposedName::new("Natural")), - Loc::at_zero(ExposedName::new("Decimal")), - // - Loc::at_zero(ExposedName::new("Binary32")), - Loc::at_zero(ExposedName::new("Binary64")), - // - // Loc::at_zero(ExposedName::new("maxFloat")), - // Loc::at_zero(ExposedName::new("minFloat")), - Loc::at_zero(ExposedName::new("abs")), - Loc::at_zero(ExposedName::new("neg")), - Loc::at_zero(ExposedName::new("add")), - Loc::at_zero(ExposedName::new("sub")), - Loc::at_zero(ExposedName::new("mul")), - Loc::at_zero(ExposedName::new("isLt")), - Loc::at_zero(ExposedName::new("isLte")), - Loc::at_zero(ExposedName::new("isGt")), - Loc::at_zero(ExposedName::new("isGte")), - Loc::at_zero(ExposedName::new("sin")), - Loc::at_zero(ExposedName::new("cos")), - Loc::at_zero(ExposedName::new("tan")), - Loc::at_zero(ExposedName::new("atan")), - Loc::at_zero(ExposedName::new("acos")), - Loc::at_zero(ExposedName::new("asin")), - Loc::at_zero(ExposedName::new("isZero")), - Loc::at_zero(ExposedName::new("isEven")), - Loc::at_zero(ExposedName::new("isOdd")), - Loc::at_zero(ExposedName::new("toFloat")), - Loc::at_zero(ExposedName::new("isPositive")), - Loc::at_zero(ExposedName::new("isNegative")), - Loc::at_zero(ExposedName::new("rem")), - Loc::at_zero(ExposedName::new("div")), - //Loc::at_zero(ExposedName::new("modInt")), - //Loc::at_zero(ExposedName::new("modFloat")), - Loc::at_zero(ExposedName::new("sqrt")), - Loc::at_zero(ExposedName::new("log")), - Loc::at_zero(ExposedName::new("round")), - Loc::at_zero(ExposedName::new("ceiling")), - Loc::at_zero(ExposedName::new("floor")), - Loc::at_zero(ExposedName::new("compare")), - Loc::at_zero(ExposedName::new("pow")), - Loc::at_zero(ExposedName::new("powInt")), - Loc::at_zero(ExposedName::new("addWrap")), - Loc::at_zero(ExposedName::new("addChecked")), - Loc::at_zero(ExposedName::new("addSaturated")), - Loc::at_zero(ExposedName::new("bitwiseAnd")), - Loc::at_zero(ExposedName::new("bitwiseXor")), - Loc::at_zero(ExposedName::new("bitwiseOr")), - Loc::at_zero(ExposedName::new("shiftLeftBy")), - Loc::at_zero(ExposedName::new("shiftRightBy")), - Loc::at_zero(ExposedName::new("shiftRightZfBy")), - Loc::at_zero(ExposedName::new("subWrap")), - Loc::at_zero(ExposedName::new("subChecked")), - Loc::at_zero(ExposedName::new("subSaturated")), - Loc::at_zero(ExposedName::new("mulWrap")), - Loc::at_zero(ExposedName::new("mulChecked")), - Loc::at_zero(ExposedName::new("intCast")), - Loc::at_zero(ExposedName::new("bytesToU16")), - Loc::at_zero(ExposedName::new("bytesToU32")), - Loc::at_zero(ExposedName::new("divCeil")), - Loc::at_zero(ExposedName::new("divFloor")), - Loc::at_zero(ExposedName::new("toStr")), - Loc::at_zero(ExposedName::new("isMultipleOf")), - Loc::at_zero(ExposedName::new("minI8")), - Loc::at_zero(ExposedName::new("maxI8")), - Loc::at_zero(ExposedName::new("minU8")), - Loc::at_zero(ExposedName::new("maxU8")), - Loc::at_zero(ExposedName::new("minI16")), - Loc::at_zero(ExposedName::new("maxI16")), - Loc::at_zero(ExposedName::new("minU16")), - Loc::at_zero(ExposedName::new("maxU16")), - Loc::at_zero(ExposedName::new("minI32")), - Loc::at_zero(ExposedName::new("maxI32")), - Loc::at_zero(ExposedName::new("minU32")), - Loc::at_zero(ExposedName::new("maxU32")), - Loc::at_zero(ExposedName::new("minI64")), - Loc::at_zero(ExposedName::new("maxI64")), - Loc::at_zero(ExposedName::new("minU64")), - Loc::at_zero(ExposedName::new("maxU64")), - Loc::at_zero(ExposedName::new("minI128")), - Loc::at_zero(ExposedName::new("maxI128")), - Loc::at_zero(ExposedName::new("minU128")), - Loc::at_zero(ExposedName::new("maxU128")), - Loc::at_zero(ExposedName::new("toI8")), - Loc::at_zero(ExposedName::new("toI8Checked")), - Loc::at_zero(ExposedName::new("toI16")), - Loc::at_zero(ExposedName::new("toI16Checked")), - Loc::at_zero(ExposedName::new("toI32")), - Loc::at_zero(ExposedName::new("toI32Checked")), - Loc::at_zero(ExposedName::new("toI64")), - Loc::at_zero(ExposedName::new("toI64Checked")), - Loc::at_zero(ExposedName::new("toI128")), - Loc::at_zero(ExposedName::new("toI128Checked")), - Loc::at_zero(ExposedName::new("toU8")), - Loc::at_zero(ExposedName::new("toU8Checked")), - Loc::at_zero(ExposedName::new("toU16")), - Loc::at_zero(ExposedName::new("toU16Checked")), - Loc::at_zero(ExposedName::new("toU32")), - Loc::at_zero(ExposedName::new("toU32Checked")), - Loc::at_zero(ExposedName::new("toU64")), - Loc::at_zero(ExposedName::new("toU64Checked")), - Loc::at_zero(ExposedName::new("toU128")), - Loc::at_zero(ExposedName::new("toU128Checked")), - ]; - const IMPORTS: &[Loc] = &[]; - - const GENERATES_WITH: &[Symbol] = &[]; - - let info = HeaderInfo { - loc_name: Loc { - region: Region::zero(), - value: ModuleNameEnum::Interface(roc_parse::header::ModuleName::new("Num")), - }, - filename, - is_root_module: false, - opt_shorthand: None, - packages: &[], - exposes: EXPOSES, - imports: IMPORTS, - extra: HeaderFor::Builtin { - generates_with: GENERATES_WITH, - }, - }; - - let src_bytes = module_source(ModuleId::NUM); - - let parse_state = roc_parse::state::State::new(src_bytes.as_bytes()); - - return Ok(send_header( - info, - parse_state, + return Ok(load_builtin_module( + arena, module_ids, ident_ids_by_module, module_timing, + ModuleId::NUM, + "Num.roc", )); } "Bool" => { - let filename = PathBuf::from("Bool.roc"); - - const EXPOSES: &[Loc] = &[ - Loc::at_zero(ExposedName::new("and")), - Loc::at_zero(ExposedName::new("or")), - // Loc::at_zero(ExposedName::new("xor")), - Loc::at_zero(ExposedName::new("not")), - Loc::at_zero(ExposedName::new("isEq")), - Loc::at_zero(ExposedName::new("isNotEq")), - ]; - const IMPORTS: &[Loc] = &[]; - - const GENERATES_WITH: &[Symbol] = &[]; - - let info = HeaderInfo { - loc_name: Loc { - region: Region::zero(), - value: ModuleNameEnum::Interface(roc_parse::header::ModuleName::new("Bool")), - }, - filename, - is_root_module: false, - opt_shorthand: None, - packages: &[], - exposes: EXPOSES, - imports: IMPORTS, - extra: HeaderFor::Builtin { - generates_with: GENERATES_WITH, - }, - }; - - let src_bytes = module_source(ModuleId::BOOL); - - let parse_state = roc_parse::state::State::new(src_bytes.as_bytes()); - - return Ok(send_header( - info, - parse_state, + return Ok(load_builtin_module( + arena, module_ids, ident_ids_by_module, module_timing, + ModuleId::BOOL, + "Bool.roc", )); } "Box" => { - let filename = PathBuf::from("Box.roc"); - - const EXPOSES: &[Loc] = &[ - Loc::at_zero(ExposedName::new("box")), - Loc::at_zero(ExposedName::new("unbox")), - ]; - const IMPORTS: &[Loc] = &[]; - - const GENERATES_WITH: &[Symbol] = &[]; - - let info = HeaderInfo { - loc_name: Loc { - region: Region::zero(), - value: ModuleNameEnum::Interface(roc_parse::header::ModuleName::new("Box")), - }, - filename, - is_root_module: false, - opt_shorthand: None, - packages: &[], - exposes: EXPOSES, - imports: IMPORTS, - extra: HeaderFor::Builtin { - generates_with: GENERATES_WITH, - }, - }; - - let src_bytes = module_source(ModuleId::BOX); - - let parse_state = roc_parse::state::State::new(src_bytes.as_bytes()); - - return Ok(send_header( - info, - parse_state, + return Ok(load_builtin_module( + arena, module_ids, ident_ids_by_module, module_timing, + ModuleId::BOX, + "Box.roc", )); } _ => { From d6632981c848de3f7a23de643109c5066e688093 Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 8 Apr 2022 16:46:35 +0200 Subject: [PATCH 091/846] update Num.roc --- compiler/builtins/roc/List.roc | 103 +++++++++++++++++---------------- compiler/builtins/roc/Num.roc | 24 ++++++-- 2 files changed, 74 insertions(+), 53 deletions(-) diff --git a/compiler/builtins/roc/List.roc b/compiler/builtins/roc/List.roc index be58ddd9d2..7f7cea4430 100644 --- a/compiler/builtins/roc/List.roc +++ b/compiler/builtins/roc/List.roc @@ -1,52 +1,57 @@ -isEmpty, -get, -set, -replace, -append, -map, -len, -walkBackwards, -concat, -first, -single, -repeat, -reverse, -prepend, -join, -keepIf, -contains, -sum, -walk, -last, -keepOks, -keepErrs, -mapWithIndex, -map2, -map3, -product, -walkUntil, -range, -sortWith, -drop, -swap, -dropAt, -dropLast, -min, -max, -map4, -dropFirst, -joinMap, -any, -takeFirst, -takeLast, -find, -sublist, -intersperse, -split, -all, -dropIf, -sortAsc, -sortDesc, +interface Num + exposes + [ + isEmpty, + get, + set, + replace, + append, + map, + len, + walkBackwards, + concat, + first, + single, + repeat, + reverse, + prepend, + join, + keepIf, + contains, + sum, + walk, + last, + keepOks, + keepErrs, + mapWithIndex, + map2, + map3, + product, + walkUntil, + range, + sortWith, + drop, + swap, + dropAt, + dropLast, + min, + max, + map4, + dropFirst, + joinMap, + any, + takeFirst, + takeLast, + find, + sublist, + intersperse, + split, + all, + dropIf, + sortAsc, + sortDesc, + ] + imports [ Bool.{ Bool }, Result.{ Result } ] isEmpty : List a -> Bool isEmpty = \list -> diff --git a/compiler/builtins/roc/Num.roc b/compiler/builtins/roc/Num.roc index 2a30529e3e..a1aeb27143 100644 --- a/compiler/builtins/roc/Num.roc +++ b/compiler/builtins/roc/Num.roc @@ -44,8 +44,6 @@ interface Num Binary32, Binary64, - maxFloat, - minFloat, abs, neg, add, @@ -69,8 +67,6 @@ interface Num isNegative, rem, div, - modInt, - modFloat, sqrt, log, round, @@ -120,6 +116,10 @@ interface Num maxI128, minU128, maxU128, + minF32, + maxF32, + minF64, + maxF64, toI8, toI8Checked, toI16, @@ -140,6 +140,10 @@ interface Num toU64Checked, toU128, toU128Checked, + toF32, + toF32Checked, + toF64, + toF64Checked, ] imports [ ] @@ -325,6 +329,18 @@ minU128 = 0 maxU128 : U128 maxU128 = 0340282366920938463463374607431768211455 +minF32 : F32 +minF32 = -3.40282347e38 + +maxF32 : F32 +maxF32 = 3.40282347e38 + +minF64 : F64 +minF64 = -1.7976931348623157e308 + +maxF64 : F64 +maxF64 = 1.7976931348623157e308 + toI8 : Int * -> I8 toI16 : Int * -> I16 toI32 : Int * -> I32 From 1d81dd6c8b9d1b49b9da144019e02646261c848c Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 8 Apr 2022 16:49:38 +0200 Subject: [PATCH 092/846] add import to Str.roc --- compiler/builtins/roc/Str.roc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/builtins/roc/Str.roc b/compiler/builtins/roc/Str.roc index 02f1263924..fae59869c1 100644 --- a/compiler/builtins/roc/Str.roc +++ b/compiler/builtins/roc/Str.roc @@ -34,7 +34,7 @@ interface Str toU8, toI8, ] - imports [ ] + imports [ Bool.{ Bool }, Result.{ Result } ] From ce4f22fd150c327c5bb9619a8bbfcd250998a4c1 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 8 Apr 2022 10:56:34 -0400 Subject: [PATCH 093/846] Use Rect position for drawing --- examples/breakout/platform/src/gui.rs | 10 ++++------ examples/breakout/platform/src/lib.rs | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/examples/breakout/platform/src/gui.rs b/examples/breakout/platform/src/gui.rs index c837cda4e7..febb254d96 100644 --- a/examples/breakout/platform/src/gui.rs +++ b/examples/breakout/platform/src/gui.rs @@ -319,6 +319,7 @@ pub struct Bounds { #[derive(Clone, Debug)] struct Drawable { + pos: Vector2, bounds: Bounds, content: DrawableContent, } @@ -346,15 +347,10 @@ fn process_drawable( load_op: LoadOp, texture_size: Bounds, ) { - // TODO iterate through drawables, - // calculating a pos using offset, - // calling draw and updating bounding boxes - let pos: Vector2 = (0.0, 0.0).into(); - draw( drawable.bounds, drawable.content, - pos, + drawable.pos, staging_belt, glyph_brush, cmd_encoder, @@ -444,6 +440,7 @@ fn to_drawable( }; let drawable = Drawable { + pos: (rect.left, rect.top).into(), bounds, content: DrawableContent::FillRect { color: rect.color, @@ -489,6 +486,7 @@ fn to_drawable( } let drawable = Drawable { + pos: (0.0, 0.0).into(), // TODO store the pos in Text and read it here bounds: text_bounds, content: DrawableContent::Text(section, offset), }; diff --git a/examples/breakout/platform/src/lib.rs b/examples/breakout/platform/src/lib.rs index f403a5a02c..fbb4c75f26 100644 --- a/examples/breakout/platform/src/lib.rs +++ b/examples/breakout/platform/src/lib.rs @@ -9,7 +9,7 @@ pub extern "C" fn rust_main() -> i32 { height: 1000.0, }; - gui::run_event_loop("test title", state).expect("Error running event loop"); + gui::run_event_loop("RocOut!", state).expect("Error running event loop"); // Exit code 0 From 0f6e1bac73b3a462021367c4aef7a2f5c6cf7b02 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 8 Apr 2022 10:56:47 -0400 Subject: [PATCH 094/846] Drop unused functions --- examples/breakout/platform/src/roc.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/examples/breakout/platform/src/roc.rs b/examples/breakout/platform/src/roc.rs index 67fe35a075..3f73d436bd 100644 --- a/examples/breakout/platform/src/roc.rs +++ b/examples/breakout/platform/src/roc.rs @@ -21,9 +21,6 @@ extern "C" { #[allow(dead_code)] #[link_name = "roc__programForHost_1_Render_size"] fn size_Render() -> i64; - - #[link_name = "roc__programForHost_1_Render_result_size"] - fn size_Render_result() -> i64; } #[derive(Debug)] @@ -144,10 +141,6 @@ impl RocElem { // Self::elem_from_tag(entry, RocElemTag::Text) } - - fn elem_from_tag(entry: RocElemEntry, tag: RocElemTag) -> Self { - Self { entry, tag } - } } #[repr(C)] From d40c7ed1d9214a5b670cdec2d35eda9c2e85e025 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 8 Apr 2022 10:56:56 -0400 Subject: [PATCH 095/846] Draw breakout rects differently --- examples/breakout/breakout.roc | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index c5c7bafd5d..30f8e57416 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -7,6 +7,7 @@ program = { render } render = \state -> div0 = \numerator, denominator -> (numerator / denominator) |> Result.withDefault 0 + intDiv0 = \numerator, denominator -> (numerator // denominator) |> Result.withDefault 0 rgba = \r, g, b, a -> { r: div0 r 255, g: div0 g 255, b: div0 b 255, a } @@ -18,12 +19,22 @@ render = \state -> blocks = List.map (List.range 0 (numRows * numCols)) \index -> { col: index, row: (index // 5 |> Result.withDefault 0) } - blockWidth = 100 - blockHeight = 50 + blockWidth = 50 + blockHeight = 20 List.map blocks \{ row, col } -> left = Num.toF32 (col * blockWidth) top = Num.toF32 (row * blockHeight) - color = rgba 10 20 30 1 # TODO different colors for each block! + red = + 250 // col + |> Result.withDefault 0 + |> Num.toF32 + + green = + 250 // row + |> Result.withDefault 0 + |> Num.toF32 + + color = rgba red 120 green 1 Rect { left, top, width: blockWidth, height: blockHeight, color } From 45b5df3a23a1c2b4c8503da23135b58f4a6a6fa9 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 8 Apr 2022 11:52:57 -0400 Subject: [PATCH 096/846] Extract constrain_tag helper function --- compiler/constrain/src/expr.rs | 155 ++++++++++++++++----------------- 1 file changed, 73 insertions(+), 82 deletions(-) diff --git a/compiler/constrain/src/expr.rs b/compiler/constrain/src/expr.rs index f093113971..abcedc7d05 100644 --- a/compiler/constrain/src/expr.rs +++ b/compiler/constrain/src/expr.rs @@ -880,92 +880,31 @@ pub fn constrain_expr( ext_var, name, arguments, - } => { - let mut vars = Vec::with_capacity(arguments.len()); - let mut types = Vec::with_capacity(arguments.len()); - let mut arg_cons = Vec::with_capacity(arguments.len()); - - for (var, loc_expr) in arguments { - let arg_con = constrain_expr( - constraints, - env, - loc_expr.region, - &loc_expr.value, - Expected::NoExpectation(Type::Variable(*var)), - ); - - arg_cons.push(arg_con); - vars.push(*var); - types.push(Type::Variable(*var)); - } - - let union_con = constraints.equal_types_with_storage( - Type::TagUnion( - vec![(name.clone(), types)], - TypeExtension::from_type(Type::Variable(*ext_var)), - ), - expected.clone(), - Category::TagApply { - tag_name: name.clone(), - args_count: arguments.len(), - }, - region, - *variant_var, - ); - - vars.push(*variant_var); - vars.push(*ext_var); - arg_cons.push(union_con); - - constraints.exists_many(vars, arg_cons) - } + } => constrain_tag( + constraints, + env, + expected, + region, + *variant_var, + *ext_var, + name, + arguments, + ), ZeroArgumentTag { variant_var, ext_var, name, - arguments, - closure_name, - } => { - let mut vars = Vec::with_capacity(arguments.len()); - let mut types = Vec::with_capacity(arguments.len()); - let mut arg_cons = Vec::with_capacity(arguments.len()); - - for (var, loc_expr) in arguments { - let arg_con = constrain_expr( - constraints, - env, - loc_expr.region, - &loc_expr.value, - Expected::NoExpectation(Type::Variable(*var)), - ); - - arg_cons.push(arg_con); - vars.push(*var); - types.push(Type::Variable(*var)); - } - - let union_con = constraints.equal_types_with_storage( - Type::FunctionOrTagUnion( - name.clone(), - *closure_name, - TypeExtension::from_type(Type::Variable(*ext_var)), - ), - expected.clone(), - Category::TagApply { - tag_name: name.clone(), - args_count: arguments.len(), - }, - region, - *variant_var, - ); - - vars.push(*variant_var); - vars.push(*ext_var); - arg_cons.push(union_con); - - constraints.exists_many(vars, arg_cons) - } - + closure_name: _, + } => constrain_tag( + constraints, + env, + expected, + region, + *variant_var, + *ext_var, + name, + &[], + ), OpaqueRef { opaque_var, name, @@ -2047,3 +1986,55 @@ fn constrain_field_update( (var, field_type, con) } + +fn constrain_tag( + constraints: &mut Constraints, + env: &Env, + expected: Expected, + region: Region, + variant_var: Variable, + ext_var: Variable, + name: &TagName, + arguments: &[(Variable, Loc)], +) -> Constraint { + // +2 because we push all the arguments, plus variant_var and ext_var + let num_vars = arguments.len() + 2; + + let mut vars = Vec::with_capacity(num_vars); + let mut types = Vec::with_capacity(arguments.len()); + let mut arg_cons = Vec::with_capacity(arguments.len()); + + for (var, loc_expr) in arguments { + let arg_con = constrain_expr( + constraints, + env, + loc_expr.region, + &loc_expr.value, + Expected::NoExpectation(Type::Variable(*var)), + ); + + arg_cons.push(arg_con); + vars.push(*var); + types.push(Type::Variable(*var)); + } + + let union_con = constraints.equal_types_with_storage( + Type::TagUnion( + vec![(name.clone(), types)], + TypeExtension::from_type(Type::Variable(ext_var)), + ), + expected.clone(), + Category::TagApply { + tag_name: name.clone(), + args_count: arguments.len(), + }, + region, + variant_var, + ); + + vars.push(variant_var); + vars.push(ext_var); + arg_cons.push(union_con); + + constraints.exists_many(vars, arg_cons) +} From b777b88e1c2bfa08d05c37ee0adad045cb2e06e1 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 8 Apr 2022 11:53:16 -0400 Subject: [PATCH 097/846] Drop unused `arguments` field from ZeroArgumentTag --- compiler/can/src/expr.rs | 7 +------ compiler/can/src/module.rs | 3 ++- compiler/mono/src/ir.rs | 3 +-- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index 7ac3bf84fd..b021dc2192 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -161,7 +161,6 @@ pub enum Expr { variant_var: Variable, ext_var: Variable, name: TagName, - arguments: Vec<(Variable, Loc)>, }, /// A wrapping of an opaque type, like `$Age 21` @@ -813,7 +812,6 @@ pub fn canonicalize_expr<'a>( ( ZeroArgumentTag { name: TagName::Global((*tag).into()), - arguments: vec![], variant_var, closure_name: symbol, ext_var, @@ -831,7 +829,6 @@ pub fn canonicalize_expr<'a>( ( ZeroArgumentTag { name: TagName::Private(symbol), - arguments: vec![], variant_var, ext_var, closure_name: lambda_set_symbol, @@ -1560,15 +1557,13 @@ pub fn inline_calls(var_store: &mut VarStore, scope: &mut Scope, expr: Expr) -> variant_var, ext_var, name, - arguments, } => { todo!( - "Inlining for ZeroArgumentTag with closure_name {:?}, variant_var {:?}, ext_var {:?}, name {:?}, arguments {:?}", + "Inlining for ZeroArgumentTag with closure_name {:?}, variant_var {:?}, ext_var {:?}, name {:?}", closure_name, variant_var, ext_var, name, - arguments ); } diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index 60255ac40d..da3b79dfa1 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -646,6 +646,7 @@ fn fix_values_captured_in_closure_expr( | Var(_) | EmptyRecord | RuntimeError(_) + | ZeroArgumentTag { .. } | Accessor { .. } => {} List { loc_elems, .. } => { @@ -712,7 +713,7 @@ fn fix_values_captured_in_closure_expr( fix_values_captured_in_closure_expr(&mut loc_expr.value, no_capture_symbols); } - Tag { arguments, .. } | ZeroArgumentTag { arguments, .. } => { + Tag { arguments, .. } => { for (_, loc_arg) in arguments.iter_mut() { fix_values_captured_in_closure_expr(&mut loc_arg.value, no_capture_symbols); } diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 97522dd561..97279ccce7 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -3432,7 +3432,6 @@ pub fn with_hole<'a>( ZeroArgumentTag { variant_var, name: tag_name, - arguments: args, ext_var, closure_name, } => { @@ -3466,7 +3465,7 @@ pub fn with_hole<'a>( tag_name, procs, layout_cache, - args, + std::vec::Vec::new(), arena, ) } From 0ccc5f8105e0e965508816d85f9e7faefe8731a8 Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 8 Apr 2022 18:55:41 +0200 Subject: [PATCH 098/846] fix module names in builtin roc code --- compiler/builtins/roc/List.roc | 2 +- compiler/builtins/roc/Set.roc | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/builtins/roc/List.roc b/compiler/builtins/roc/List.roc index 7f7cea4430..4c8203e4d3 100644 --- a/compiler/builtins/roc/List.roc +++ b/compiler/builtins/roc/List.roc @@ -1,4 +1,4 @@ -interface Num +interface List exposes [ isEmpty, diff --git a/compiler/builtins/roc/Set.roc b/compiler/builtins/roc/Set.roc index 93e0097c40..7f03a9f0e0 100644 --- a/compiler/builtins/roc/Set.roc +++ b/compiler/builtins/roc/Set.roc @@ -1,4 +1,4 @@ -interface Dict +interface Set exposes [ empty, @@ -14,7 +14,7 @@ interface Dict intersection, difference, ] - imports [ ] + imports [ List, Bool.{ Bool } ] empty : Set k single : k -> Set k From b7eacbf120c7ec2552c3cc2c3e089e0fbcdc26ec Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 8 Apr 2022 19:35:26 +0200 Subject: [PATCH 099/846] some tweaks to the builtin roc code --- compiler/builtins/roc/Dict.roc | 9 ++++++--- compiler/builtins/roc/List.roc | 9 ++++++--- compiler/builtins/roc/Num.roc | 5 ++++- compiler/builtins/roc/Result.roc | 2 +- compiler/builtins/roc/Set.roc | 4 ++-- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/compiler/builtins/roc/Dict.roc b/compiler/builtins/roc/Dict.roc index b2d6d9f5ef..aa457cee0e 100644 --- a/compiler/builtins/roc/Dict.roc +++ b/compiler/builtins/roc/Dict.roc @@ -1,6 +1,6 @@ interface Dict - exposes - [ + exposes + [ empty, single, get, @@ -15,7 +15,10 @@ interface Dict intersection, difference, ] - imports [ ] + imports + [ + Bool.{ Bool } + ] empty : Dict k v single : k, v -> Dict k v diff --git a/compiler/builtins/roc/List.roc b/compiler/builtins/roc/List.roc index 4c8203e4d3..18f397d519 100644 --- a/compiler/builtins/roc/List.roc +++ b/compiler/builtins/roc/List.roc @@ -51,7 +51,10 @@ interface List sortAsc, sortDesc, ] - imports [ Bool.{ Bool }, Result.{ Result } ] + imports + [ + Bool.{ Bool } + ] isEmpty : List a -> Bool isEmpty = \list -> @@ -75,11 +78,11 @@ walkBackwards : List elem, state, (state, elem -> state) -> state walkUntil : List elem, state, (state, elem -> [ Continue state, Stop state ]) -> state sum : List (Num a) -> Num a -sum = \list -> +sum = \list -> List.walk list 0 Num.add product : List (Num a) -> Num a -product = \list -> +product = \list -> List.walk list 1 Num.mul any : List a, (a -> Bool) -> Bool diff --git a/compiler/builtins/roc/Num.roc b/compiler/builtins/roc/Num.roc index a1aeb27143..2d2ee09f13 100644 --- a/compiler/builtins/roc/Num.roc +++ b/compiler/builtins/roc/Num.roc @@ -145,7 +145,10 @@ interface Num toF64, toF64Checked, ] - imports [ ] + imports + [ + Bool.{ Bool } + ] Num range : [ @Num range ] Int range : Num (Integer range) diff --git a/compiler/builtins/roc/Result.roc b/compiler/builtins/roc/Result.roc index a32f12d937..a857a6c456 100644 --- a/compiler/builtins/roc/Result.roc +++ b/compiler/builtins/roc/Result.roc @@ -1,6 +1,6 @@ interface Result exposes [ Result, isOk, isErr, map, mapErr, after, withDefault ] - imports [ ] + imports [ Bool.{ Bool } ] Result ok err : [ Ok ok, Err err ] diff --git a/compiler/builtins/roc/Set.roc b/compiler/builtins/roc/Set.roc index 7f03a9f0e0..b004918956 100644 --- a/compiler/builtins/roc/Set.roc +++ b/compiler/builtins/roc/Set.roc @@ -1,6 +1,6 @@ interface Set - exposes - [ + exposes + [ empty, single, walk, From 795e24245c43bd816a17fe5e74f5754a0dc7d2d7 Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 8 Apr 2022 19:50:25 +0200 Subject: [PATCH 100/846] generate all modules on this branch --- compiler/load/build.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/compiler/load/build.rs b/compiler/load/build.rs index dc7b09cca9..fccb69219b 100644 --- a/compiler/load/build.rs +++ b/compiler/load/build.rs @@ -5,13 +5,13 @@ use roc_module::symbol::ModuleId; const MODULES: &[(ModuleId, &str)] = &[ (ModuleId::BOOL, "Bool.roc"), - // (ModuleId::RESULT, "Result.roc"), - // (ModuleId::LIST, "List.roc"), - // (ModuleId::STR, "Str.roc"), - // (ModuleId::DICT, "Dict.roc"), - // (ModuleId::SET, "Set.roc"), - // (ModuleId::BOX, "Box.roc"), - // (ModuleId::NUM, "Num.roc"), + (ModuleId::RESULT, "Result.roc"), + (ModuleId::LIST, "List.roc"), + (ModuleId::STR, "Str.roc"), + (ModuleId::DICT, "Dict.roc"), + (ModuleId::SET, "Set.roc"), + (ModuleId::BOX, "Box.roc"), + (ModuleId::NUM, "Num.roc"), ]; fn main() { From ffd4566c2954332247c66985aa9c6ccb5f3beb4a Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 8 Apr 2022 19:51:05 +0200 Subject: [PATCH 101/846] remove code that saves Subs to a .dat file (it's located elsewhere now) --- compiler/load_internal/src/file.rs | 32 +----------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index 31f99559c4..a778c71021 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -3508,26 +3508,7 @@ fn run_solve_solve( solve_aliases.insert(*name, alias.clone()); } - let (solved_subs, exposed_vars_by_symbol, problems) = if module_id.is_builtin() { - use memmap::MmapOptions; - use std::fs::File; - - let root = get_project_root().unwrap(); - let path = format!("{}/cached_subs/{:?}.dat", root.to_str().unwrap(), module_id); - eprintln!("{:?}: {}", module_id, &path); - let file = File::open(&path).unwrap(); - let mmap = unsafe { MmapOptions::new().map(&file).unwrap() }; - let (subs, vars_by_symbol) = Subs::deserialize(&mmap); - let solved_subs = Solved(subs); - - let exposed_vars_by_symbol: Vec<_> = vars_by_symbol - .iter() - .filter(|(k, _)| exposed_symbols.contains(k)) - .copied() - .collect(); - - (solved_subs, exposed_vars_by_symbol, vec![]) - } else { + let (solved_subs, exposed_vars_by_symbol, problems) = { let (solved_subs, solved_env, problems) = roc_solve::module::run_solve( &constraints, actual_constraint, @@ -3536,15 +3517,6 @@ fn run_solve_solve( solve_aliases, ); - if module_id.is_builtin() { - let mut f = std::fs::File::create(&format!("cached_subs/{:?}.dat", module_id)).unwrap(); - let vars_by_symbol: Vec<(Symbol, Variable)> = solved_env.vars_by_symbol().collect(); - solved_subs - .inner() - .serialize(&vars_by_symbol, &mut f) - .unwrap(); - } - let solved_subs = if true { solved_subs } else { @@ -3556,8 +3528,6 @@ fn run_solve_solve( .unwrap(); let (subs, vbs) = Subs::deserialize(&serialized); - dbg!(vbs); - Solved(subs) }; From 4dafe0854409d0055848cfc55a4a2aa0760fdc8f Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 8 Apr 2022 19:51:20 +0200 Subject: [PATCH 102/846] better debug messages --- compiler/load_internal/src/file.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index a778c71021..8842a1bd50 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -2466,7 +2466,10 @@ fn foo<'a>( (info, parse_state) } Ok(_) => panic!("invalid header format for builtin module"), - Err(e) => todo!(), + Err(e) => panic!( + "Hit a parse error in the header of {:?}:\n{:?}", + filename, e + ), } } @@ -4145,10 +4148,15 @@ fn add_def_to_module<'a>( arguments: loc_args, loc_body, captured_symbols, + name, .. }) => { // this is a top-level definition, it should not capture anything - debug_assert!(captured_symbols.is_empty()); + debug_assert!( + captured_symbols.is_empty(), + "{:?}", + (symbol, name, symbol.module_id(), &captured_symbols) + ); // If this is an exposed symbol, we need to // register it as such. Otherwise, since it From e9f7427c67ac3f5799dc49ef7cbf60dd8893efa6 Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 8 Apr 2022 20:24:17 +0200 Subject: [PATCH 103/846] fix some things in Num --- compiler/builtins/roc/Num.roc | 4 ++++ compiler/can/src/module.rs | 2 +- compiler/load_internal/src/file.rs | 4 +++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/compiler/builtins/roc/Num.roc b/compiler/builtins/roc/Num.roc index 2d2ee09f13..1cbba15026 100644 --- a/compiler/builtins/roc/Num.roc +++ b/compiler/builtins/roc/Num.roc @@ -140,6 +140,8 @@ interface Num toU64Checked, toU128, toU128Checked, + toNat, + toNatChecked, toF32, toF32Checked, toF64, @@ -354,6 +356,7 @@ toU16 : Int * -> U16 toU32 : Int * -> U32 toU64 : Int * -> U64 toU128 : Int * -> U128 +toNat : Int * -> Nat toF32 : Num * -> F32 toF64 : Num * -> F64 @@ -368,5 +371,6 @@ toU16Checked : Int * -> Result U16 [ OutOfBounds ]* toU32Checked : Int * -> Result U32 [ OutOfBounds ]* toU64Checked : Int * -> Result U64 [ OutOfBounds ]* toU128Checked : Int * -> Result U128 [ OutOfBounds ]* +toNatChecked : Int * -> Result Nat [ OutOfBounds ]* toF32Checked : Num * -> Result F32 [ OutOfBounds ]* toF64Checked : Num * -> Result F64 [ OutOfBounds ]* diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index 7f25ba9e5b..63fe59e0de 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -396,7 +396,7 @@ pub fn canonicalize_module_defs<'a>( if has_no_implementation(&def.loc_expr.value) { match generated_info { GeneratedInfo::Builtin { - generated_functions, + generated_functions: _, } => { let symbol = def.pattern_vars.iter().next().unwrap().0; match crate::builtins::builtin_defs_map(*symbol, var_store) { diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index 8842a1bd50..5728e42585 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -2460,7 +2460,9 @@ fn foo<'a>( packages: &[], exposes: unspace(arena, header.exposes.items), imports: unspace(arena, header.imports.items), - extra: HeaderFor::Interface, + extra: HeaderFor::Builtin { + generates_with: &[], + }, }; (info, parse_state) From fa527b18885bc34a07a7ed072e8cbf7959484127 Mon Sep 17 00:00:00 2001 From: Nikita Mounier <36044205+nikitamounier@users.noreply.github.com> Date: Fri, 8 Apr 2022 20:43:58 +0000 Subject: [PATCH 104/846] Specify that in nix-shell's PATH, `usr/bin` needs to come after nix-related components This was the source of quite a head-scratching error when building the compiler, only solved thanks to @ayazhafiz 's insight. Indeed, compilation of `roc_cli` was failing with an obscure error about linking with `cc` and not being able to find `-ltinfo`. Turns out the fix is as trivial as rearranging nix-shell's `PATH` a little. I feel like nix-shell will become the default for many users who prefer delegating the necessary setup to the repo's script, and I definitely wish I had known about this when I was starting out. Is this the right place to mention this or should it be somewhere else in the document? --- BUILDING_FROM_SOURCE.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/BUILDING_FROM_SOURCE.md b/BUILDING_FROM_SOURCE.md index 652f22c06d..99218e2780 100644 --- a/BUILDING_FROM_SOURCE.md +++ b/BUILDING_FROM_SOURCE.md @@ -39,6 +39,8 @@ Use `cargo run help` to see all subcommands. To use the `repl` subcommand, execute `cargo run repl`. Use `cargo build` to build the whole project. +> In the nix-shell, make sure that inside your `PATH` variable `usr/bin` comes after all the nix-related components. Otherwise you might get some nasty rust compilation errors! + #### Extra tips If you plan on using `nix-shell` regularly, check out [direnv](https://direnv.net/) and [lorri](https://github.com/nix-community/lorri). Whenever you `cd` into `roc/`, they will automatically load the Nix dependencies into your current shell, so you never have to run nix-shell directly! From b2ff785a5e5399135377c305a740e4d4f36e54d4 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 8 Apr 2022 19:56:43 -0400 Subject: [PATCH 105/846] Another clip bites the clip --- compiler/constrain/src/expr.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/constrain/src/expr.rs b/compiler/constrain/src/expr.rs index abcedc7d05..893860290b 100644 --- a/compiler/constrain/src/expr.rs +++ b/compiler/constrain/src/expr.rs @@ -1987,6 +1987,7 @@ fn constrain_field_update( (var, field_type, con) } +#[allow(clippy::too_many_arguments)] fn constrain_tag( constraints: &mut Constraints, env: &Env, @@ -2023,7 +2024,7 @@ fn constrain_tag( vec![(name.clone(), types)], TypeExtension::from_type(Type::Variable(ext_var)), ), - expected.clone(), + expected, Category::TagApply { tag_name: name.clone(), args_count: arguments.len(), From dd56fdb61cdb726d5cbeb605dfd8f6540f776fc0 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 8 Apr 2022 21:31:19 -0400 Subject: [PATCH 106/846] Fix regression with ZeroArgumentTag constraint gen Turns out it can't share quite that much code with Tag, because doing so skips the important function-based constraints. --- compiler/constrain/src/expr.rs | 134 +++++++++++++++------------------ 1 file changed, 60 insertions(+), 74 deletions(-) diff --git a/compiler/constrain/src/expr.rs b/compiler/constrain/src/expr.rs index 893860290b..f3932cf06b 100644 --- a/compiler/constrain/src/expr.rs +++ b/compiler/constrain/src/expr.rs @@ -880,31 +880,70 @@ pub fn constrain_expr( ext_var, name, arguments, - } => constrain_tag( - constraints, - env, - expected, - region, - *variant_var, - *ext_var, - name, - arguments, - ), + } => { + // +2 because we push all the arguments, plus variant_var and ext_var + let num_vars = arguments.len() + 2; + let mut vars = Vec::with_capacity(num_vars); + let mut types = Vec::with_capacity(arguments.len()); + let mut arg_cons = Vec::with_capacity(arguments.len()); + + for (var, loc_expr) in arguments { + let arg_con = constrain_expr( + constraints, + env, + loc_expr.region, + &loc_expr.value, + Expected::NoExpectation(Type::Variable(*var)), + ); + + arg_cons.push(arg_con); + vars.push(*var); + types.push(Type::Variable(*var)); + } + + let union_con = constraints.equal_types_with_storage( + Type::TagUnion( + vec![(name.clone(), types)], + TypeExtension::from_type(Type::Variable(*ext_var)), + ), + expected.clone(), + Category::TagApply { + tag_name: name.clone(), + args_count: arguments.len(), + }, + region, + *variant_var, + ); + + vars.push(*variant_var); + vars.push(*ext_var); + arg_cons.push(union_con); + + constraints.exists_many(vars, arg_cons) + } ZeroArgumentTag { variant_var, ext_var, name, - closure_name: _, - } => constrain_tag( - constraints, - env, - expected, - region, - *variant_var, - *ext_var, - name, - &[], - ), + closure_name, + } => { + let union_con = constraints.equal_types_with_storage( + Type::FunctionOrTagUnion( + name.clone(), + *closure_name, + TypeExtension::from_type(Type::Variable(*ext_var)), + ), + expected.clone(), + Category::TagApply { + tag_name: name.clone(), + args_count: 0, + }, + region, + *variant_var, + ); + + constraints.exists_many(vec![*variant_var, *ext_var], vec![union_con]) + } OpaqueRef { opaque_var, name, @@ -1986,56 +2025,3 @@ fn constrain_field_update( (var, field_type, con) } - -#[allow(clippy::too_many_arguments)] -fn constrain_tag( - constraints: &mut Constraints, - env: &Env, - expected: Expected, - region: Region, - variant_var: Variable, - ext_var: Variable, - name: &TagName, - arguments: &[(Variable, Loc)], -) -> Constraint { - // +2 because we push all the arguments, plus variant_var and ext_var - let num_vars = arguments.len() + 2; - - let mut vars = Vec::with_capacity(num_vars); - let mut types = Vec::with_capacity(arguments.len()); - let mut arg_cons = Vec::with_capacity(arguments.len()); - - for (var, loc_expr) in arguments { - let arg_con = constrain_expr( - constraints, - env, - loc_expr.region, - &loc_expr.value, - Expected::NoExpectation(Type::Variable(*var)), - ); - - arg_cons.push(arg_con); - vars.push(*var); - types.push(Type::Variable(*var)); - } - - let union_con = constraints.equal_types_with_storage( - Type::TagUnion( - vec![(name.clone(), types)], - TypeExtension::from_type(Type::Variable(ext_var)), - ), - expected, - Category::TagApply { - tag_name: name.clone(), - args_count: arguments.len(), - }, - region, - variant_var, - ); - - vars.push(variant_var); - vars.push(ext_var); - arg_cons.push(union_con); - - constraints.exists_many(vars, arg_cons) -} From eb99c2c4ec50a134664595cffceeaf7ddca07996 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 8 Apr 2022 23:54:11 -0400 Subject: [PATCH 107/846] Grammar edit Apparently although both "a homage" and "an homage" are considered grammatically acceptable, the latter is more commonly used. --- name-and-logo.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/name-and-logo.md b/name-and-logo.md index 9465fab6bf..f8eb46f3d4 100644 --- a/name-and-logo.md +++ b/name-and-logo.md @@ -4,7 +4,7 @@ The Roc programming language is named after [a mythical bird](https://en.wikipedia.org/wiki/Roc_(mythology)). -That’s why the logo is a bird. It’s specifically an [*origami* bird](https://youtu.be/9gni1t1k1uY) as a homage +That’s why the logo is a bird. It’s specifically an [*origami* bird](https://youtu.be/9gni1t1k1uY) as an homage to [Elm](https://elm-lang.org/)’s tangram logo. Roc is a direct descendant of Elm. The languages are similar, but not the same. From fe77cb3b16131ef0ee0cd70c88fcb2fe1a562eba Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 9 Apr 2022 11:34:24 +0200 Subject: [PATCH 108/846] write functions, that can be written in roc, in roc --- compiler/builtins/roc/List.roc | 48 ++++++++++++++++++++++++++++++++-- compiler/builtins/roc/Set.roc | 4 +-- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/compiler/builtins/roc/List.roc b/compiler/builtins/roc/List.roc index 18f397d519..42de7f03ef 100644 --- a/compiler/builtins/roc/List.roc +++ b/compiler/builtins/roc/List.roc @@ -61,8 +61,12 @@ isEmpty = \list -> List.len list == 0 get : List a, Nat -> Result a [ OutOfBounds ]* -set : List a, Nat, a -> List a replace : List a, Nat, a -> { list : List a, value : a } + +set : List a, Nat, a -> List a +set = \list, index, value -> + (List.replace list index value).list + append : List a, a -> List a prepend : List a, a -> List a len : List a -> Nat @@ -90,6 +94,8 @@ all : List a, (a -> Bool) -> Bool keepIf : List a, (a -> Bool) -> List a dropIf : List a, (a -> Bool) -> List a +dropIf = \list, predicate -> + List.keepIf list (\e -> Bool.not (predicate e)) keepOks : List before, (before -> Result after *) -> List after keepErrs: List before, (before -> Result * after) -> List after @@ -97,7 +103,7 @@ map : List a, (a -> b) -> List b map2 : List a, List b, (a, b -> c) -> List c map3 : List a, List b, List c, (a, b, c -> d) -> List d map4 : List a, List b, List c, List d, (a, b, c, d -> e) -> List e -mapWithIndex : List a, (a -> b) -> List b +mapWithIndex : List a, (a, Nat -> b) -> List b range : Int a, Int a -> List (Int a) sortWith : List a, (a, a -> [ LT, EQ, GT ] ) -> List a sortAsc : List (Num a) -> List (Num a) @@ -120,9 +126,47 @@ drop : List elem, Nat -> List elem dropAt : List elem, Nat -> List elem min : List (Num a) -> Result (Num a) [ ListWasEmpty ]* +min = \list -> + when List.first list is + Ok initial -> + Ok (minHelp list initial) + + Err ListWasEmpty -> + Err ListWasEmpty + + +minHelp : List (Num a), Num a -> Num a +minHelp = \list, initial -> + List.walk list initial \bestSoFar, current -> + if current < bestSoFar then + current + + else + bestSoFar + max : List (Num a) -> Result (Num a) [ ListWasEmpty ]* +max = \list -> + when List.first list is + Ok initial -> + Ok (maxHelp list initial) + + Err ListWasEmpty -> + Err ListWasEmpty + + +maxHelp : List (Num a), Num a -> Num a +maxHelp = \list, initial -> + List.walk list initial \bestSoFar, current -> + if current > bestSoFar then + current + + else + bestSoFar joinMap : List a, (a -> List b) -> List b +joinMap = \list, mapper -> + List.walk list [] (\state, elem -> List.concat state (mapper elem)) + find : List elem, (elem -> Bool) -> Result elem [ NotFound ]* sublist : List elem, { start : Nat, len : Nat } -> List elem intersperse : List elem, elem -> List elem diff --git a/compiler/builtins/roc/Set.roc b/compiler/builtins/roc/Set.roc index b004918956..f19d80eb2d 100644 --- a/compiler/builtins/roc/Set.roc +++ b/compiler/builtins/roc/Set.roc @@ -14,7 +14,7 @@ interface Set intersection, difference, ] - imports [ List, Bool.{ Bool } ] + imports [ List, Bool.{ Bool }, Dict.{ values } ] empty : Set k single : k -> Set k @@ -35,4 +35,4 @@ toDict : Set k -> Dict k {} walk : Set k, state, (state, k -> state) -> state walk = \set, state, step -> - Dict.walk (toDict set) state (\s, k, _ -> step s k) + Dict.walk (Set.toDict set) state (\s, k, _ -> step s k) From c32f85139443a02a81b7eb4c5a46e61a34d6f4f8 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 9 Apr 2022 11:35:06 +0200 Subject: [PATCH 109/846] explicitly import Box --- compiler/test_gen/src/gen_primitives.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/test_gen/src/gen_primitives.rs b/compiler/test_gen/src/gen_primitives.rs index be6ef612a5..ae740a0a45 100644 --- a/compiler/test_gen/src/gen_primitives.rs +++ b/compiler/test_gen/src/gen_primitives.rs @@ -3266,7 +3266,12 @@ fn box_and_unbox_string() { assert_evals_to!( indoc!( r#" - Box.unbox (Box.box (Str.concat "Leverage " "agile frameworks to provide a robust synopsis for high level overviews")) + app "test" imports [ Box ] provides [ main ] to "./platform" + + main = + Str.concat "Leverage " "agile frameworks to provide a robust synopsis for high level overviews" + |> Box.box + |> Box.unbox "# ), RocStr::from( From a7c87af06559a6a4ccfd6ccf42fbc2b4ec816085 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 9 Apr 2022 11:39:57 +0200 Subject: [PATCH 110/846] typo --- compiler/can/src/builtins.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/can/src/builtins.rs b/compiler/can/src/builtins.rs index 06f6ce61f3..19a2896dc6 100644 --- a/compiler/can/src/builtins.rs +++ b/compiler/can/src/builtins.rs @@ -1874,7 +1874,7 @@ fn str_from_utf8(symbol: Symbol, var_store: &mut VarStore) -> Def { ret_var, ) } -/// Str.romUtf8Range : List U8, { start : Nat, count : Nat } -> Result Str [ BadUtf8 { byteIndex : Nat, problem : Utf8Problem } } ]* +/// Str.fromUtf8Range : List U8, { start : Nat, count : Nat } -> Result Str [ BadUtf8 { byteIndex : Nat, problem : Utf8Problem } } ]* fn str_from_utf8_range(symbol: Symbol, var_store: &mut VarStore) -> Def { let bytes_var = var_store.fresh(); let bool_var = var_store.fresh(); From d2756919fd76914ae832cd51b70426a6be8adcb6 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 9 Apr 2022 12:04:12 +0200 Subject: [PATCH 111/846] treat Box.Box as a builtin opaque type --- compiler/can/src/module.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index 63fe59e0de..61e34f8222 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -256,7 +256,7 @@ pub fn canonicalize_module_defs<'a>( Symbol::STR_STR, Symbol::DICT_DICT, Symbol::SET_SET, - // Symbol::BOX_BOX, + Symbol::BOX_BOX_TYPE, ] .contains(&symbol) { From 4d780ec0906f0e471494c9ef1b1e1b96721a1361 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 9 Apr 2022 12:05:35 +0200 Subject: [PATCH 112/846] disable use of cached subs temporarily --- compiler/load/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/load/src/lib.rs b/compiler/load/src/lib.rs index 3b05a22bdf..7989bfd1c6 100644 --- a/compiler/load/src/lib.rs +++ b/compiler/load/src/lib.rs @@ -105,7 +105,7 @@ pub fn load_and_typecheck<'a>( } } -const BOOL: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Bool.dat")) as &[_]; +// const BOOL: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Bool.dat")) as &[_]; // const RESULT: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Result.dat")) as &[_]; // const LIST: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/List.dat")) as &[_]; // const STR: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Str.dat")) as &[_]; @@ -123,7 +123,7 @@ fn deserialize_help(bytes: &[u8]) -> (Subs, Vec<(Symbol, Variable)>) { fn read_cached_subs() -> MutMap)> { let mut output = MutMap::default(); - output.insert(ModuleId::BOOL, deserialize_help(BOOL)); + // output.insert(ModuleId::BOOL, deserialize_help(BOOL)); // output.insert(ModuleId::RESULT, deserialize_help(RESULT)); // output.insert(ModuleId::LIST, deserialize_help(LIST)); // output.insert(ModuleId::STR, deserialize_help(STR)); From 76037de335d11b27eff7117b9651240d8dacf93a Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 9 Apr 2022 12:11:11 +0200 Subject: [PATCH 113/846] ignore test for now --- compiler/test_gen/src/gen_primitives.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/test_gen/src/gen_primitives.rs b/compiler/test_gen/src/gen_primitives.rs index ae740a0a45..48a62f9c69 100644 --- a/compiler/test_gen/src/gen_primitives.rs +++ b/compiler/test_gen/src/gen_primitives.rs @@ -2971,6 +2971,7 @@ fn mix_function_and_closure_level_of_indirection() { } #[test] +#[ignore] #[cfg(any(feature = "gen-llvm"))] fn do_pass_bool_byte_closure_layout() { // see https://github.com/rtfeldman/roc/pull/1706 From 37bb19b0327483c4af5b3c24d00f40251339d6b9 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 9 Apr 2022 12:13:20 +0200 Subject: [PATCH 114/846] for now always generate constraints --- compiler/load_internal/src/file.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index 5728e42585..8c04113125 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -3778,11 +3778,9 @@ fn canonicalize_and_constrain<'a>( let mut constraints = Constraints::new(); - let constraint = if module_id.is_builtin() { - roc_can::constraint::Constraint::True - } else { - constrain_module(&mut constraints, &module_output.declarations, module_id) - }; + // TODO: don't generate constraints for a builtin module if it's cached + let constraint = + constrain_module(&mut constraints, &module_output.declarations, module_id); let after = roc_types::types::get_type_clone_count(); From c93805ea87cf381210f986ef099e1e4ce647a6e3 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 9 Apr 2022 12:23:01 +0200 Subject: [PATCH 115/846] restore effects.roc example --- examples/interactive/effects.roc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/examples/interactive/effects.roc b/examples/interactive/effects.roc index a97ef9df51..a81c87f1ea 100644 --- a/examples/interactive/effects.roc +++ b/examples/interactive/effects.roc @@ -5,4 +5,13 @@ app "effects" main : Effect.Effect {} main = - (Effect.putLine (Str.concat "It is known" "foo")) + Effect.after + (Effect.getLine) + \line -> + Effect.after + (Effect.putLine "You entered: \(line)") + \{ } -> + Effect.after + (Effect.putLine "It is known") + \{ } -> + Effect.always {} From c9b29c773f9d4dde597bb5dc76c05b1d9f8f63d7 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 9 Apr 2022 12:23:18 +0200 Subject: [PATCH 116/846] simplify GeneratedInfo --- compiler/can/src/module.rs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index 61e34f8222..e6dc56b10e 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -75,19 +75,17 @@ fn validate_generate_with<'a>( } #[derive(Debug)] -enum GeneratedInfo<'a> { +enum GeneratedInfo { Hosted { effect_symbol: Symbol, generated_functions: HostedGeneratedFunctions, }, - Builtin { - generated_functions: &'a [Symbol], - }, + Builtin, NotSpecial, } -impl<'a> GeneratedInfo<'a> { - fn from_header_for( +impl GeneratedInfo { + fn from_header_for<'a>( env: &mut Env, scope: &mut Scope, var_store: &mut VarStore, @@ -140,9 +138,10 @@ impl<'a> GeneratedInfo<'a> { generated_functions, } } - HeaderFor::Builtin { generates_with } => GeneratedInfo::Builtin { - generated_functions: generates_with, - }, + HeaderFor::Builtin { generates_with } => { + debug_assert!(generates_with.is_empty()); + GeneratedInfo::Builtin + } _ => GeneratedInfo::NotSpecial, } } @@ -395,9 +394,7 @@ pub fn canonicalize_module_defs<'a>( // we just assume they are hosted functions (meant to be provided by the platform) if has_no_implementation(&def.loc_expr.value) { match generated_info { - GeneratedInfo::Builtin { - generated_functions: _, - } => { + GeneratedInfo::Builtin => { let symbol = def.pattern_vars.iter().next().unwrap().0; match crate::builtins::builtin_defs_map(*symbol, var_store) { None => { From 691e8ee068266c593e7e8dd5cee5257f02e56092 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 9 Apr 2022 12:23:30 +0200 Subject: [PATCH 117/846] remove unused alias code --- compiler/constrain/src/module.rs | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/compiler/constrain/src/module.rs b/compiler/constrain/src/module.rs index 8af7f4c38e..8537932a72 100644 --- a/compiler/constrain/src/module.rs +++ b/compiler/constrain/src/module.rs @@ -147,17 +147,6 @@ pub fn constrain_builtin_imports( } } None => { - let is_valid_alias = stdlib.applies.contains(&symbol) - // This wasn't a builtin value or Apply; maybe it was a builtin alias. - || roc_types::builtin_aliases::aliases().contains_key(&symbol); - - // if !is_valid_alias { - // panic!( - // "Could not find {:?} in builtin types {:?} or builtin aliases", - // symbol, stdlib.types, - // ); - // } - continue; } }; From bdfed2e69903a83099908c2f72973b5d70fcca2b Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 9 Apr 2022 12:23:47 +0200 Subject: [PATCH 118/846] disable usage of cached modules, but do the caching --- compiler/load/src/lib.rs | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/compiler/load/src/lib.rs b/compiler/load/src/lib.rs index 7989bfd1c6..db14d86547 100644 --- a/compiler/load/src/lib.rs +++ b/compiler/load/src/lib.rs @@ -105,14 +105,14 @@ pub fn load_and_typecheck<'a>( } } -// const BOOL: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Bool.dat")) as &[_]; -// const RESULT: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Result.dat")) as &[_]; -// const LIST: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/List.dat")) as &[_]; -// const STR: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Str.dat")) as &[_]; -// const DICT: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Dict.dat")) as &[_]; -// const SET: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Set.dat")) as &[_]; -// const BOX: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Box.dat")) as &[_]; -// const NUM: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Num.dat")) as &[_]; +const BOOL: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Bool.dat")) as &[_]; +const RESULT: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Result.dat")) as &[_]; +const LIST: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/List.dat")) as &[_]; +const STR: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Str.dat")) as &[_]; +const DICT: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Dict.dat")) as &[_]; +const SET: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Set.dat")) as &[_]; +const BOX: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Box.dat")) as &[_]; +const NUM: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Num.dat")) as &[_]; fn deserialize_help(bytes: &[u8]) -> (Subs, Vec<(Symbol, Variable)>) { let (subs, slice) = Subs::deserialize(bytes); @@ -123,14 +123,16 @@ fn deserialize_help(bytes: &[u8]) -> (Subs, Vec<(Symbol, Variable)>) { fn read_cached_subs() -> MutMap)> { let mut output = MutMap::default(); - // output.insert(ModuleId::BOOL, deserialize_help(BOOL)); - // output.insert(ModuleId::RESULT, deserialize_help(RESULT)); - // output.insert(ModuleId::LIST, deserialize_help(LIST)); - // output.insert(ModuleId::STR, deserialize_help(STR)); - // output.insert(ModuleId::DICT, deserialize_help(DICT)); - // output.insert(ModuleId::SET, deserialize_help(SET)); - // output.insert(ModuleId::BOX, deserialize_help(BOX)); - // output.insert(ModuleId::NUM, deserialize_help(NUM)); + if false { + output.insert(ModuleId::BOOL, deserialize_help(BOOL)); + output.insert(ModuleId::RESULT, deserialize_help(RESULT)); + output.insert(ModuleId::LIST, deserialize_help(LIST)); + output.insert(ModuleId::STR, deserialize_help(STR)); + output.insert(ModuleId::DICT, deserialize_help(DICT)); + output.insert(ModuleId::SET, deserialize_help(SET)); + output.insert(ModuleId::BOX, deserialize_help(BOX)); + output.insert(ModuleId::NUM, deserialize_help(NUM)); + } output } From 166c949c3b757fc4551586f041b2704caf4da685 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 9 Apr 2022 12:24:12 +0200 Subject: [PATCH 119/846] clippy --- compiler/load_internal/src/file.rs | 7 +++---- compiler/mono/src/ir.rs | 1 + compiler/types/src/builtin_aliases.rs | 1 - 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index 8c04113125..b36d160bf6 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -25,7 +25,7 @@ use roc_mono::ir::{ UpdateModeIds, }; use roc_mono::layout::{Layout, LayoutCache, LayoutProblem}; -use roc_parse::ast::{self, Collection, ExtractSpaces, Spaced, StrLiteral}; +use roc_parse::ast::{self, ExtractSpaces, Spaced, StrLiteral}; use roc_parse::header::{ExposedName, ImportsEntry, PackageEntry, PlatformHeader, To, TypedIdent}; use roc_parse::header::{HeaderFor, ModuleNameEnum, PackageName}; use roc_parse::ident::UppercaseIdent; @@ -1062,7 +1062,7 @@ pub fn load<'a>( ) -> Result, LoadingProblem<'a>> { // When compiling to wasm, we cannot spawn extra threads // so we have a single-threaded implementation - if true || cfg!(target_family = "wasm") { + if cfg!(target_family = "wasm") { load_single_threaded( arena, load_start, @@ -3488,7 +3488,6 @@ fn run_solve_solve( exposed_symbols, aliases, rigid_variables, - module_id, .. } = module; @@ -3531,7 +3530,7 @@ fn run_solve_solve( .inner() .serialize(&vars_by_symbol, &mut serialized) .unwrap(); - let (subs, vbs) = Subs::deserialize(&serialized); + let (subs, _vbs) = Subs::deserialize(&serialized); Solved(subs) }; diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 768f89ec1f..19f06a44b2 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -7303,6 +7303,7 @@ fn call_by_name_help<'a>( add_needed_external(procs, env, original_fn_var, proc_name); debug_assert_ne!(proc_name.module_id(), ModuleId::ATTR); + if procs.is_imported_module_thunk(proc_name) { force_thunk( env, diff --git a/compiler/types/src/builtin_aliases.rs b/compiler/types/src/builtin_aliases.rs index 16d8512e93..129b12d0c4 100644 --- a/compiler/types/src/builtin_aliases.rs +++ b/compiler/types/src/builtin_aliases.rs @@ -11,7 +11,6 @@ const NUM_BUILTIN_IMPORTS: usize = 8; /// These can be shared between definitions, they will get instantiated when converted to Type const TVAR1: VarId = VarId::from_u32(1); -const TVAR2: VarId = VarId::from_u32(2); pub fn aliases() -> MutMap { let mut aliases = HashMap::with_capacity_and_hasher(NUM_BUILTIN_IMPORTS, default_hasher()); From 9d966d439fd52b7bc0fb7f10917895d0f0075a08 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 9 Apr 2022 12:29:49 +0200 Subject: [PATCH 120/846] fix solve tests --- compiler/solve/tests/solve_expr.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index b99923ba1e..735bbbddcb 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -3251,7 +3251,7 @@ mod solve_expr { Dict.insert "# ), - "Dict k v, k, v -> Dict k v", + "Dict a b, a, b -> Dict a b", ); } @@ -3807,7 +3807,7 @@ mod solve_expr { List.walkBackwards "# ), - "List elem, state, (state, elem -> state) -> state", + "List a, b, (b, a -> b) -> b", ); } @@ -3883,7 +3883,7 @@ mod solve_expr { List.takeLast "# ), - "List elem, Nat -> List elem", + "List a, Nat -> List a", ); } From 94df530a8d21b6084745c1613479107ed5568392 Mon Sep 17 00:00:00 2001 From: Nikita Mounier <36044205+nikitamounier@users.noreply.github.com> Date: Sat, 9 Apr 2022 11:07:00 +0000 Subject: [PATCH 121/846] Change wording using @rtfeldman suggestion. Co-authored-by: Richard Feldman --- BUILDING_FROM_SOURCE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BUILDING_FROM_SOURCE.md b/BUILDING_FROM_SOURCE.md index 99218e2780..bb1e70733c 100644 --- a/BUILDING_FROM_SOURCE.md +++ b/BUILDING_FROM_SOURCE.md @@ -39,7 +39,7 @@ Use `cargo run help` to see all subcommands. To use the `repl` subcommand, execute `cargo run repl`. Use `cargo build` to build the whole project. -> In the nix-shell, make sure that inside your `PATH` variable `usr/bin` comes after all the nix-related components. Otherwise you might get some nasty rust compilation errors! +> When using `nix-shell`, make sure that if you start `nix-shell` and then run `echo "$PATH" | tr ':' '\n'`, you see the `usr/bin` path listed after all the `/nix/…` paths. Otherwise you might get some nasty rust compilation errors! #### Extra tips From a15ff20eec7f1151c31dd58cd5e848124b621993 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 9 Apr 2022 14:11:50 +0200 Subject: [PATCH 122/846] give back the subs of the root module (for the repl) --- compiler/load_internal/src/file.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index b36d160bf6..29554cee67 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -633,6 +633,7 @@ struct PlatformData { #[derive(Debug)] struct State<'a> { pub root_id: ModuleId, + pub root_subs: Option, pub platform_data: Option, pub goal_phase: Phase, pub exposed_types: ExposedByModule, @@ -688,6 +689,7 @@ impl<'a> State<'a> { Self { root_id, + root_subs: None, target_info, platform_data: None, goal_phase, @@ -2153,6 +2155,14 @@ fn update<'a>( existing.push(requested); } + // use the subs of the root module; + // this is used in the repl to find the type of `main` + let subs = if module_id == state.root_id { + subs + } else { + state.root_subs.clone().unwrap() + }; + msg_tx .send(Msg::FinishedAllSpecialization { subs, @@ -2165,6 +2175,12 @@ fn update<'a>( // the originally requested module, we're all done! return Ok(state); } else { + // record the subs of the root module; + // this is used in the repl to find the type of `main` + if module_id == state.root_id { + state.root_subs = Some(subs); + } + state.constrained_ident_ids.insert(module_id, ident_ids); for (module_id, requested) in external_specializations_requested { From 3b2956822193025dc3d759663fa8df249ce4c00e Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 9 Apr 2022 14:12:03 +0200 Subject: [PATCH 123/846] clippy --- repl_eval/src/eval.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/repl_eval/src/eval.rs b/repl_eval/src/eval.rs index edaa0ec06b..bc718a7c6c 100644 --- a/repl_eval/src/eval.rs +++ b/repl_eval/src/eval.rs @@ -64,7 +64,6 @@ pub fn jit_to_ast<'a, A: ReplApp<'a>>( arguments: [], result, } => { - dbg!(content, &result); // this is a thunk jit_to_ast_help(&env, app, main_fn_name, &result, content) } @@ -1204,8 +1203,6 @@ fn num_to_ast<'a>(env: &Env<'a, '_>, num_expr: Expr<'a>, content: &Content) -> E let arena = env.arena; - dbg!(&num_expr, content); - match content { Structure(flat_type) => { match flat_type { From f7ee7c555245ddfc152494a45b37fb84223c61b3 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 9 Apr 2022 14:12:21 +0200 Subject: [PATCH 124/846] ignore box tests in repl (can't import Box) --- repl_test/src/tests.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/repl_test/src/tests.rs b/repl_test/src/tests.rs index 84df9024ee..884c752cde 100644 --- a/repl_test/src/tests.rs +++ b/repl_test/src/tests.rs @@ -1068,6 +1068,7 @@ fn print_i8_issue_2710() { #[cfg(not(feature = "wasm"))] #[test] +#[ignore] fn box_box() { expect_success( indoc!( @@ -1081,6 +1082,7 @@ fn box_box() { #[cfg(not(feature = "wasm"))] #[test] +#[ignore] fn box_box_type_alias() { expect_success( indoc!( From a4c8ebd55e49dd10ceed6b37f1bb598154eaece6 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 9 Apr 2022 14:41:45 +0200 Subject: [PATCH 125/846] fix can tests; qualify imports from num --- compiler/can/tests/helpers/mod.rs | 11 +++++++++- compiler/can/tests/test_can.rs | 36 +++++++++++++++---------------- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/compiler/can/tests/helpers/mod.rs b/compiler/can/tests/helpers/mod.rs index 922ffb6436..f37d6a9190 100644 --- a/compiler/can/tests/helpers/mod.rs +++ b/compiler/can/tests/helpers/mod.rs @@ -7,10 +7,11 @@ use roc_can::expr::{canonicalize_expr, Expr}; use roc_can::operator; use roc_can::scope::Scope; use roc_collections::all::MutMap; -use roc_module::symbol::{IdentIds, Interns, ModuleId, ModuleIds}; +use roc_module::symbol::{IdentIds, Interns, ModuleId, ModuleIds, Symbol}; use roc_problem::can::Problem; use roc_region::all::{Loc, Region}; use roc_types::subs::{VarStore, Variable}; +use roc_types::types::Type; use std::hash::Hash; pub fn test_home() -> ModuleId { @@ -55,6 +56,14 @@ pub fn can_expr_with(arena: &Bump, home: ModuleId, expr_str: &str) -> CanExprOut let loc_expr = operator::desugar_expr(arena, &loc_expr); let mut scope = Scope::new(home, &mut var_store); + scope.add_alias( + Symbol::NUM_INT, + Region::zero(), + vec![Loc::at_zero(("a".into(), Variable::EMPTY_RECORD))], + Type::EmptyRec, + roc_types::types::AliasKind::Structural, + ); + let dep_idents = IdentIds::exposed_builtins(0); let mut env = Env::new(home, &dep_idents, &module_ids, IdentIds::default()); let (loc_expr, output) = canonicalize_expr( diff --git a/compiler/can/tests/test_can.rs b/compiler/can/tests/test_can.rs index a3ee85d6db..83481c882b 100644 --- a/compiler/can/tests/test_can.rs +++ b/compiler/can/tests/test_can.rs @@ -50,7 +50,7 @@ mod test_can { assert_eq!(IntValue::I128(expected), actual); } actual => { - panic!("Expected an Int *, but got: {:?}", actual); + panic!("Expected an Num.Int *, but got: {:?}", actual); } } } @@ -274,7 +274,7 @@ mod test_can { fn correct_annotated_body() { let src = indoc!( r#" - f : Int * -> Int * + f : Num.Int * -> Num.Int * f = \ a -> a f @@ -290,7 +290,7 @@ mod test_can { fn correct_annotated_body_with_comments() { let src = indoc!( r#" - f : Int * -> Int * # comment + f : Num.Int * -> Num.Int * # comment f = \ a -> a f @@ -306,7 +306,7 @@ mod test_can { fn name_mismatch_annotated_body() { let src = indoc!( r#" - f : Int * -> Int * + f : Num.Int * -> Num.Int * g = \ a -> a g @@ -332,7 +332,7 @@ mod test_can { fn name_mismatch_annotated_body_with_comment() { let src = indoc!( r#" - f : Int * -> Int * # comment + f : Num.Int * -> Num.Int * # comment g = \ a -> a g @@ -358,7 +358,7 @@ mod test_can { fn separated_annotated_body() { let src = indoc!( r#" - f : Int * -> Int * + f : Num.Int * -> Num.Int * f = \ a -> a @@ -381,7 +381,7 @@ mod test_can { fn separated_annotated_body_with_comment() { let src = indoc!( r#" - f : Int * -> Int * + f : Num.Int * -> Num.Int * # comment f = \ a -> a @@ -404,9 +404,9 @@ mod test_can { fn shadowed_annotation() { let src = indoc!( r#" - f : Int * -> Int * + f : Num.Int * -> Num.Int * - f : Int * -> Int * + f : Num.Int * -> Num.Int * f "# @@ -428,7 +428,7 @@ mod test_can { fn correct_nested_unannotated_body() { let src = indoc!( r#" - f : Int * + f : Num.Int * f = g = 42 @@ -447,9 +447,9 @@ mod test_can { fn correct_nested_annotated_body() { let src = indoc!( r#" - f : Int * + f : Num.Int * f = - g : Int * + g : Num.Int * g = 42 g + 1 @@ -467,11 +467,11 @@ mod test_can { fn correct_nested_body_annotated_multiple_lines() { let src = indoc!( r#" - f : Int * + f : Num.Int * f = - g : Int * + g : Num.Int * g = 42 - h : Int * + h : Num.Int * h = 5 z = 4 g + h + z @@ -489,10 +489,10 @@ mod test_can { fn correct_nested_body_unannotated_multiple_lines() { let src = indoc!( r#" - f : Int * + f : Num.Int * f = g = 42 - h : Int * + h : Num.Int * h = 5 z = 4 g + h + z @@ -509,7 +509,7 @@ mod test_can { fn correct_double_nested_body() { let src = indoc!( r#" - f : Int * + f : Num.Int * f = g = h = 42 From e9acbe983f1ee81052712b492fe7f96de6b655b8 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sat, 9 Apr 2022 10:09:03 -0400 Subject: [PATCH 126/846] Use array over vec for exists_many --- compiler/constrain/src/expr.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/constrain/src/expr.rs b/compiler/constrain/src/expr.rs index f3932cf06b..9fc45351dc 100644 --- a/compiler/constrain/src/expr.rs +++ b/compiler/constrain/src/expr.rs @@ -942,7 +942,7 @@ pub fn constrain_expr( *variant_var, ); - constraints.exists_many(vec![*variant_var, *ext_var], vec![union_con]) + constraints.exists_many([*variant_var, *ext_var], [union_con]) } OpaqueRef { opaque_var, From ebb03f60dd076dbe6cf7672874969214ec15f234 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sat, 9 Apr 2022 13:23:15 -0400 Subject: [PATCH 127/846] Add Nikita Mounier to AUTHORS --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index c8aad79020..ede51e040a 100644 --- a/AUTHORS +++ b/AUTHORS @@ -72,3 +72,4 @@ Elliot Waite <1767836+elliotwaite@users.noreply.github.com> zimt28 <1764689+zimt28@users.noreply.github.com> Ananda Umamil SylvanSign +Nikita Mounier <36044205+nikitamounier@users.noreply.github.com> From a102a7497e9ade1cf950f6450b8bfee5e50bcd8b Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Sat, 9 Apr 2022 16:21:41 -0400 Subject: [PATCH 128/846] Support box/unbox for types that are typically only on the stack Closes #2786 --- compiler/mono/src/layout.rs | 14 +++++--- compiler/test_gen/src/gen_primitives.rs | 44 +++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/compiler/mono/src/layout.rs b/compiler/mono/src/layout.rs index 325aec6b0e..07cf05ea5e 100644 --- a/compiler/mono/src/layout.rs +++ b/compiler/mono/src/layout.rs @@ -468,7 +468,7 @@ impl<'a> UnionLayout<'a> { pub fn allocation_alignment_bytes(&self, target_info: TargetInfo) -> u32 { let allocation = match self { - UnionLayout::NonRecursive(_) => unreachable!("not heap-allocated"), + UnionLayout::NonRecursive(tags) => Self::tags_alignment_bytes(tags, target_info), UnionLayout::Recursive(tags) => Self::tags_alignment_bytes(tags, target_info), UnionLayout::NonNullableUnwrapped(field_layouts) => { Layout::struct_no_name_order(field_layouts).alignment_bytes(target_info) @@ -1150,9 +1150,11 @@ impl<'a> Layout<'a> { } pub fn allocation_alignment_bytes(&self, target_info: TargetInfo) -> u32 { + let ptr_width = target_info.ptr_width() as u32; + match self { Layout::Builtin(builtin) => builtin.allocation_alignment_bytes(target_info), - Layout::Struct { .. } => unreachable!("not heap-allocated"), + Layout::Struct { .. } => self.alignment_bytes(target_info).max(ptr_width), Layout::Union(union_layout) => union_layout.allocation_alignment_bytes(target_info), Layout::LambdaSet(lambda_set) => lambda_set .runtime_representation() @@ -1545,9 +1547,6 @@ impl<'a> Builtin<'a> { let ptr_width = target_info.ptr_width() as u32; let allocation = match self { - Builtin::Int(_) | Builtin::Float(_) | Builtin::Bool | Builtin::Decimal => { - unreachable!("not heap-allocated") - } Builtin::Str => ptr_width, Builtin::Dict(k, v) => k .alignment_bytes(target_info) @@ -1555,6 +1554,11 @@ impl<'a> Builtin<'a> { .max(ptr_width), Builtin::Set(k) => k.alignment_bytes(target_info).max(ptr_width), Builtin::List(e) => e.alignment_bytes(target_info).max(ptr_width), + // The following are usually not heap-allocated, but they might be when inside a Box. + Builtin::Int(int_width) => int_width.alignment_bytes(target_info).max(ptr_width), + Builtin::Float(float_width) => float_width.alignment_bytes(target_info).max(ptr_width), + Builtin::Bool => (core::mem::align_of::() as u32).max(ptr_width), + Builtin::Decimal => IntWidth::I128.alignment_bytes(target_info).max(ptr_width), }; allocation.max(ptr_width) diff --git a/compiler/test_gen/src/gen_primitives.rs b/compiler/test_gen/src/gen_primitives.rs index be6ef612a5..4c4f020755 100644 --- a/compiler/test_gen/src/gen_primitives.rs +++ b/compiler/test_gen/src/gen_primitives.rs @@ -3275,3 +3275,47 @@ fn box_and_unbox_string() { RocStr ) } + +#[test] +#[cfg(any(feature = "gen-llvm"))] +fn box_and_unbox_num() { + assert_evals_to!( + indoc!( + r#" + Box.unbox (Box.box (123u8)) + "# + ), + 123, + u8 + ) +} + +#[test] +#[cfg(any(feature = "gen-llvm"))] +fn box_and_unbox_record() { + assert_evals_to!( + indoc!( + r#" + Box.unbox (Box.box { a: 15u8, b: 27u8 }) + "# + ), + (15, 27), + (u8, u8) + ) +} + +#[test] +#[cfg(any(feature = "gen-llvm"))] +fn box_and_unbox_tag_union() { + assert_evals_to!( + indoc!( + r#" + v : [ A U8, B U8 ] # usually stack allocated + v = B 27u8 + Box.unbox (Box.box v) + "# + ), + (27, 1), + (u8, u8) + ) +} From 29fe91f95e751f08dd8cb4c633cb8f3c8f7a8a2b Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sat, 9 Apr 2022 20:35:10 -0400 Subject: [PATCH 129/846] Make breakout colors look nicer --- examples/breakout/breakout.roc | 40 +++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index 30f8e57416..8fd1153f3a 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -15,26 +15,32 @@ render = \state -> numRows = 4 numCols = 8 + numBlocks = numRows * numCols - blocks = List.map (List.range 0 (numRows * numCols)) \index -> - { col: index, row: (index // 5 |> Result.withDefault 0) } + blocks = List.map (List.range 0 numBlocks) \index -> + col = + Num.rem index numCols + |> Result.withDefault 0 + |> Num.toF32 - blockWidth = 50 - blockHeight = 20 + row = + index // numCols + |> Result.withDefault 0 + |> Num.toF32 - List.map blocks \{ row, col } -> - left = Num.toF32 (col * blockWidth) + red = (col / Num.toF32 numCols) |> Result.withDefault 0 + green = ((row / Num.toF32 numRows) |> Result.withDefault 0) + blue = (Num.toF32 index / Num.toF32 numBlocks) |> Result.withDefault 0 + + color = { r: red * 0.8, g: 0.2 + green * 0.6, b: 0.2 + blue * 0.8, a: 1 } + + { row, col, color } + + blockWidth = state.width / numCols |> Result.withDefault 0 + blockHeight = 80 + + List.map blocks \{ row, col, color } -> + left = Num.toF32 col * blockWidth top = Num.toF32 (row * blockHeight) - red = - 250 // col - |> Result.withDefault 0 - |> Num.toF32 - - green = - 250 // row - |> Result.withDefault 0 - |> Num.toF32 - - color = rgba red 120 green 1 Rect { left, top, width: blockWidth, height: blockHeight, color } From ee4e7877125e8f004bc7f4ea1e19596135472a74 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sun, 10 Apr 2022 00:52:34 -0400 Subject: [PATCH 130/846] Drop some unused code --- examples/breakout/breakout.roc | 7 ------- examples/breakout/platform/Package-Config.roc | 4 ---- 2 files changed, 11 deletions(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index 8fd1153f3a..0eababd296 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -6,13 +6,6 @@ app "breakout" program = { render } render = \state -> - div0 = \numerator, denominator -> (numerator / denominator) |> Result.withDefault 0 - intDiv0 = \numerator, denominator -> (numerator // denominator) |> Result.withDefault 0 - - rgba = \r, g, b, a -> { r: div0 r 255, g: div0 g 255, b: div0 b 255, a } - - styles = { bgColor: rgba 100 50 50 1, borderColor: rgba 10 20 30 1, borderWidth: 10, textColor: rgba 220 220 250 1 } - numRows = 4 numCols = 8 numBlocks = numRows * numCols diff --git a/examples/breakout/platform/Package-Config.roc b/examples/breakout/platform/Package-Config.roc index 03b360ee82..2efff31ced 100644 --- a/examples/breakout/platform/Package-Config.roc +++ b/examples/breakout/platform/Package-Config.roc @@ -7,14 +7,10 @@ platform "gui" Rgba : { r : F32, g : F32, b : F32, a : F32 } -Bounds : { width : F32, height : F32 } - Elem : [ Rect { color : Rgba, left : F32, top : F32, width : F32, height : F32 }, Text Str ] State : { width : F32, height : F32 } -Program state : { render : state -> Elem } - # TODO allow changing the window title - maybe via a Task, since that shouldn't happen all the time programForHost : { render : (State -> List Elem) as Render } programForHost = program From 6bbc0b5edb7591c3bb202a210eecaf937dce1681 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sun, 10 Apr 2022 00:52:43 -0400 Subject: [PATCH 131/846] Gracefully handle resizing in breakout --- examples/breakout/breakout.roc | 20 ++++++++++++++++---- examples/breakout/platform/src/gui.rs | 7 +++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index 0eababd296..8488b756c8 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -32,8 +32,20 @@ render = \state -> blockWidth = state.width / numCols |> Result.withDefault 0 blockHeight = 80 - List.map blocks \{ row, col, color } -> - left = Num.toF32 col * blockWidth - top = Num.toF32 (row * blockHeight) + rects = + List.map blocks \{ row, col, color } -> + left = Num.toF32 col * blockWidth + top = Num.toF32 (row * blockHeight) - Rect { left, top, width: blockWidth, height: blockHeight, color } + Rect { left, top, width: blockWidth, height: blockHeight, color } + + paddle = + color = { r: 0.8, g: 0.8, b: 0.8, a: 1.0 } + width = state.width * 0.1 + height = state.height * 0.1 + left = state.width - (state.width * 0.1) + top = state.height - (height * 2) + + Rect { left, top, width, height, color } + + List.append rects paddle diff --git a/examples/breakout/platform/src/gui.rs b/examples/breakout/platform/src/gui.rs index febb254d96..23a46d41e3 100644 --- a/examples/breakout/platform/src/gui.rs +++ b/examples/breakout/platform/src/gui.rs @@ -149,6 +149,13 @@ pub fn run_event_loop(title: &str, state: roc::State) -> Result<(), Box Date: Sun, 10 Apr 2022 00:55:18 -0400 Subject: [PATCH 132/846] Horizontally center the paddle, make it bigger --- examples/breakout/breakout.roc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index 8488b756c8..64ce4901e7 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -41,9 +41,9 @@ render = \state -> paddle = color = { r: 0.8, g: 0.8, b: 0.8, a: 1.0 } - width = state.width * 0.1 - height = state.height * 0.1 - left = state.width - (state.width * 0.1) + width = state.width * 0.25 + height = blockHeight + left = (state.width * 0.5) - (width * 0.5) top = state.height - (height * 2) Rect { left, top, width, height, color } From d267bc47f9877977a70e9f729b709f02c7beb1d4 Mon Sep 17 00:00:00 2001 From: C-BJ <62678643+C-BJ@users.noreply.github.com> Date: Sun, 10 Apr 2022 19:06:05 +0800 Subject: [PATCH 133/846] Rename CodeOfConduct.md to CODE_OF_CONDUCT.md --- CodeOfConduct.md => CODE_OF_CONDUCT.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename CodeOfConduct.md => CODE_OF_CONDUCT.md (100%) diff --git a/CodeOfConduct.md b/CODE_OF_CONDUCT.md similarity index 100% rename from CodeOfConduct.md rename to CODE_OF_CONDUCT.md From e0c1d5bcd0ab68e7abb94e933150869e82ac2de0 Mon Sep 17 00:00:00 2001 From: C-BJ <62678643+C-BJ@users.noreply.github.com> Date: Sun, 10 Apr 2022 19:36:41 +0800 Subject: [PATCH 134/846] Update FAQ.md --- FAQ.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/FAQ.md b/FAQ.md index 833c29d0b8..952d930984 100644 --- a/FAQ.md +++ b/FAQ.md @@ -1,5 +1,10 @@ # Frequently Asked Questions +# Why make a new editor instead of making an LSP plugin for VSCode, Vim or Emacs? +The Roc editor is one of the key areas where we want to innovate. Constraining ourselves to a plugin for existing editors would severely limit our possibilities for innovation. + +A key part of our editor will be the use of plugins that are shipped with libraries. Think of a regex visualizer, parser debugger, or color picker. For library authors, it would be most convenient to write these plugins in Roc. Trying to dynamically load library plugins (written in Roc) in for example VSCode seems very difficult. + ## Is there syntax highlighting for Vim/Emacs/VS Code or a LSP? Not currently. Although they will presumably exist someday, while Roc is in the early days there's actually a conscious From e477813be41eed53a8df6e517fbbae8d01088dee Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sun, 10 Apr 2022 09:36:23 -0400 Subject: [PATCH 135/846] Add Cai Bingjun to AUTHORS --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index ede51e040a..cd10ba4f0c 100644 --- a/AUTHORS +++ b/AUTHORS @@ -73,3 +73,4 @@ zimt28 <1764689+zimt28@users.noreply.github.com> Ananda Umamil SylvanSign Nikita Mounier <36044205+nikitamounier@users.noreply.github.com> +Cai Bingjun <62678643+C-BJ@users.noreply.github.com> From 999dbfd9d18b65f45d040a22cdff6cae16db8592 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sun, 10 Apr 2022 10:13:33 -0400 Subject: [PATCH 136/846] Send Event to breakout main --- examples/breakout/breakout.roc | 71 ++++++++-------- examples/breakout/platform/Package-Config.roc | 4 +- examples/breakout/platform/src/gui.rs | 45 +++------- examples/breakout/platform/src/lib.rs | 4 +- examples/breakout/platform/src/roc.rs | 84 +++++++++++++++++-- 5 files changed, 131 insertions(+), 77 deletions(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index 64ce4901e7..70e1c9610d 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -5,47 +5,52 @@ app "breakout" program = { render } -render = \state -> - numRows = 4 - numCols = 8 - numBlocks = numRows * numCols +render = \event -> + when event is + Resize size -> + numRows = 4 + numCols = 8 + numBlocks = numRows * numCols - blocks = List.map (List.range 0 numBlocks) \index -> - col = - Num.rem index numCols - |> Result.withDefault 0 - |> Num.toF32 + blocks = List.map (List.range 0 numBlocks) \index -> + col = + Num.rem index numCols + |> Result.withDefault 0 + |> Num.toF32 - row = - index // numCols - |> Result.withDefault 0 - |> Num.toF32 + row = + index // numCols + |> Result.withDefault 0 + |> Num.toF32 - red = (col / Num.toF32 numCols) |> Result.withDefault 0 - green = ((row / Num.toF32 numRows) |> Result.withDefault 0) - blue = (Num.toF32 index / Num.toF32 numBlocks) |> Result.withDefault 0 + red = (col / Num.toF32 numCols) |> Result.withDefault 0 + green = ((row / Num.toF32 numRows) |> Result.withDefault 0) + blue = (Num.toF32 index / Num.toF32 numBlocks) |> Result.withDefault 0 - color = { r: red * 0.8, g: 0.2 + green * 0.6, b: 0.2 + blue * 0.8, a: 1 } + color = { r: red * 0.8, g: 0.2 + green * 0.6, b: 0.2 + blue * 0.8, a: 1 } - { row, col, color } + { row, col, color } - blockWidth = state.width / numCols |> Result.withDefault 0 - blockHeight = 80 + blockWidth = size.width / numCols |> Result.withDefault 0 + blockHeight = 80 - rects = - List.map blocks \{ row, col, color } -> - left = Num.toF32 col * blockWidth - top = Num.toF32 (row * blockHeight) + rects = + List.map blocks \{ row, col, color } -> + left = Num.toF32 col * blockWidth + top = Num.toF32 (row * blockHeight) - Rect { left, top, width: blockWidth, height: blockHeight, color } + Rect { left, top, width: blockWidth, height: blockHeight, color } - paddle = - color = { r: 0.8, g: 0.8, b: 0.8, a: 1.0 } - width = state.width * 0.25 - height = blockHeight - left = (state.width * 0.5) - (width * 0.5) - top = state.height - (height * 2) + paddle = + color = { r: 0.8, g: 0.8, b: 0.8, a: 1.0 } + width = size.width * 0.25 + height = blockHeight + left = (size.width * 0.5) - (width * 0.5) + top = size.height - (height * 2) - Rect { left, top, width, height, color } + Rect { left, top, width, height, color } - List.append rects paddle + List.append rects paddle + + _ -> + [ Text "TODO handle other events than Resize!" ] diff --git a/examples/breakout/platform/Package-Config.roc b/examples/breakout/platform/Package-Config.roc index 2efff31ced..cee1604c09 100644 --- a/examples/breakout/platform/Package-Config.roc +++ b/examples/breakout/platform/Package-Config.roc @@ -9,8 +9,8 @@ Rgba : { r : F32, g : F32, b : F32, a : F32 } Elem : [ Rect { color : Rgba, left : F32, top : F32, width : F32, height : F32 }, Text Str ] -State : { width : F32, height : F32 } +Event : [ Resize { width : F32, height : F32 }, KeyDown U32, KeyUp U32 ] # TODO allow changing the window title - maybe via a Task, since that shouldn't happen all the time -programForHost : { render : (State -> List Elem) as Render } +programForHost : { render : (Event -> List Elem) as Render } programForHost = program diff --git a/examples/breakout/platform/src/gui.rs b/examples/breakout/platform/src/gui.rs index 23a46d41e3..9f4af16a34 100644 --- a/examples/breakout/platform/src/gui.rs +++ b/examples/breakout/platform/src/gui.rs @@ -9,7 +9,7 @@ use crate::{ text::build_glyph_brush, }, }, - roc::{self, RocElem, RocElemTag}, + roc::{self, Bounds, RocElem, RocElemTag, RocEvent}, }; use cgmath::{Vector2, Vector4}; use glyph_brush::{GlyphCruncher, OwnedSection}; @@ -23,7 +23,7 @@ use wgpu_glyph::GlyphBrush; use winit::{ dpi::PhysicalSize, event, - event::{Event, ModifiersState}, + event::{ElementState, Event, ModifiersState}, event_loop::ControlFlow, platform::run_return::EventLoopExtRunReturn, }; @@ -36,17 +36,17 @@ use winit::{ const TIME_BETWEEN_RENDERS: Duration = Duration::new(0, 1000 / 60); -pub fn run_event_loop(title: &str, state: roc::State) -> Result<(), Box> { +pub fn run_event_loop(title: &str, window_bounds: Bounds) -> Result<(), Box> { // Open window and create a surface let mut event_loop = winit::event_loop::EventLoop::new(); let window = winit::window::WindowBuilder::new() - .with_inner_size(PhysicalSize::new(state.width, state.height)) + .with_inner_size(PhysicalSize::new(window_bounds.width, window_bounds.height)) .with_title(title) .build(&event_loop) .unwrap(); - let mut elems = roc::app_render(state); + let mut elems = roc::app_render(RocEvent::resize(window_bounds)); let instance = wgpu::Instance::new(wgpu::Backends::all()); @@ -150,10 +150,10 @@ pub fn run_event_loop(title: &str, state: roc::State) -> Result<(), Box Result<(), Box { - use event::ElementState::*; - use event::VirtualKeyCode::*; - - match keycode { - Left => match input_state { - Pressed => println!("Left pressed!"), - Released => println!("Left released!"), - }, - Right => match input_state { - Pressed => println!("Right pressed!"), - Released => println!("Right released!"), - }, - _ => { - println!("Other!"); - } + let roc_event = match input_state { + ElementState::Pressed => RocEvent::key_down(keycode), + ElementState::Released => RocEvent::key_up(keycode), }; - elems = roc::app_render(roc::State { - height: size.height as f32, - width: size.width as f32, - }); + elems = roc::app_render(roc_event); + + window.request_redraw(); } //Modifiers Changed Event::WindowEvent { @@ -318,12 +305,6 @@ fn begin_render_pass<'a>( }) } -#[derive(Copy, Clone, Debug, Default)] -pub struct Bounds { - pub height: f32, - pub width: f32, -} - #[derive(Clone, Debug)] struct Drawable { pos: Vector2, diff --git a/examples/breakout/platform/src/lib.rs b/examples/breakout/platform/src/lib.rs index fbb4c75f26..196a65c017 100644 --- a/examples/breakout/platform/src/lib.rs +++ b/examples/breakout/platform/src/lib.rs @@ -4,12 +4,12 @@ mod roc; #[no_mangle] pub extern "C" fn rust_main() -> i32 { - let state = roc::State { + let bounds = roc::Bounds { width: 1900.0, height: 1000.0, }; - gui::run_event_loop("RocOut!", state).expect("Error running event loop"); + gui::run_event_loop("RocOut!", bounds).expect("Error running event loop"); // Exit code 0 diff --git a/examples/breakout/platform/src/roc.rs b/examples/breakout/platform/src/roc.rs index 3f73d436bd..d25ffca628 100644 --- a/examples/breakout/platform/src/roc.rs +++ b/examples/breakout/platform/src/roc.rs @@ -7,13 +7,14 @@ use std::ffi::CStr; use std::fmt::Debug; use std::mem::MaybeUninit; use std::os::raw::c_char; +use winit::event::VirtualKeyCode; extern "C" { #[link_name = "roc__programForHost_1_exposed_generic"] fn roc_program() -> (); #[link_name = "roc__programForHost_1_Render_caller"] - fn call_Render(state: *const State, closure_data: *const u8, output: *mut RocList); + fn call_Render(event: *const RocEvent, closure_data: *const u8, output: *mut RocList); #[link_name = "roc__programForHost_size"] fn roc_program_size() -> i64; @@ -23,11 +24,71 @@ extern "C" { fn size_Render() -> i64; } -#[derive(Debug)] #[repr(C)] -pub struct State { - pub height: f32, - pub width: f32, +pub union RocEventEntry { + pub key_down: winit::event::VirtualKeyCode, + pub key_up: winit::event::VirtualKeyCode, + pub resize: Bounds, +} + +#[repr(u8)] +#[allow(unused)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum RocEventTag { + KeyDown = 0, + KeyUp = 1, + Resize = 2, +} + +#[repr(C)] +#[cfg(target_pointer_width = "64")] // on a 64-bit system, the tag fits in this pointer's spare 3 bits +pub struct RocEvent { + entry: RocEventEntry, + tag: RocEventTag, +} + +impl Debug for RocEvent { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + use RocEventTag::*; + + match self.tag() { + KeyDown => unsafe { self.entry().key_down }.fmt(f), + KeyUp => unsafe { self.entry().key_up }.fmt(f), + Resize => unsafe { self.entry().resize }.fmt(f), + } + } +} + +impl RocEvent { + #[cfg(target_pointer_width = "64")] + pub fn tag(&self) -> RocEventTag { + self.tag + } + + pub fn entry(&self) -> &RocEventEntry { + &self.entry + } + + pub fn resize(size: Bounds) -> Self { + Self { + tag: RocEventTag::Resize, + entry: RocEventEntry { resize: size }, + } + } + + pub fn key_down(keycode: VirtualKeyCode) -> Self { + Self { + tag: RocEventTag::KeyDown, + entry: RocEventEntry { key_down: keycode }, + } + } + + pub fn key_up(keycode: VirtualKeyCode) -> Self { + Self { + tag: RocEventTag::KeyUp, + entry: RocEventEntry { key_up: keycode }, + } + } } #[no_mangle] @@ -193,7 +254,7 @@ pub struct ButtonStyles { pub text_color: Rgba, } -pub fn app_render(state: State) -> RocList { +pub fn app_render(state: RocEvent) -> RocList { let size = unsafe { roc_program_size() } as usize; let layout = Layout::array::(size).unwrap(); @@ -212,10 +273,17 @@ pub fn app_render(state: State) -> RocList { } } -unsafe fn call_the_closure(state: State, closure_data_ptr: *const u8) -> RocList { +unsafe fn call_the_closure(event: RocEvent, closure_data_ptr: *const u8) -> RocList { let mut output = MaybeUninit::uninit(); - call_Render(&state, closure_data_ptr as *const u8, output.as_mut_ptr()); + call_Render(&event, closure_data_ptr as *const u8, output.as_mut_ptr()); output.assume_init() } + +#[derive(Copy, Clone, Debug, Default)] +#[repr(C)] +pub struct Bounds { + pub height: f32, + pub width: f32, +} From 52b58ecdf378b3644bde91cd0f53bc2a15c2562b Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 10 Apr 2022 16:22:35 +0200 Subject: [PATCH 137/846] don't write to (temp) file in solve tests --- compiler/load/src/lib.rs | 25 +++++++++++++++++++++++++ compiler/solve/tests/solve_expr.rs | 9 +++------ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/compiler/load/src/lib.rs b/compiler/load/src/lib.rs index db14d86547..d74caa1a86 100644 --- a/compiler/load/src/lib.rs +++ b/compiler/load/src/lib.rs @@ -105,6 +105,31 @@ pub fn load_and_typecheck<'a>( } } +pub fn load_and_typecheck_str<'a>( + arena: &'a Bump, + filename: PathBuf, + source: &'a str, + src_dir: &Path, + exposed_types: ExposedByModule, + target_info: TargetInfo, +) -> Result> { + use LoadResult::*; + + let load_start = LoadStart::from_str(arena, filename, source)?; + + match load( + arena, + load_start, + src_dir, + exposed_types, + Phase::SolveTypes, + target_info, + )? { + Monomorphized(_) => unreachable!(""), + TypeChecked(module) => Ok(module), + } +} + const BOOL: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Bool.dat")) as &[_]; const RESULT: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/Result.dat")) as &[_]; const LIST: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/List.dat")) as &[_]; diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index 735bbbddcb..9a4257d2f6 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -48,13 +48,10 @@ mod solve_expr { let dir = tempdir()?; let filename = PathBuf::from("Test.roc"); let file_path = dir.path().join(filename); - let full_file_path = file_path.clone(); - let mut file = File::create(file_path)?; - writeln!(file, "{}", module_src)?; - drop(file); - let result = roc_load::load_and_typecheck( + let result = roc_load::load_and_typecheck_str( arena, - full_file_path, + file_path, + module_src, dir.path(), exposed_types, roc_target::TargetInfo::default_x86_64(), From c2b823ce99f6ed170adc13a7a44f5dcd7d1cb5b6 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sun, 10 Apr 2022 10:55:40 -0400 Subject: [PATCH 138/846] Introduce basic TEA for breakout --- examples/breakout/breakout.roc | 77 ++++++++++--------- examples/breakout/platform/Package-Config.roc | 8 +- 2 files changed, 46 insertions(+), 39 deletions(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index 70e1c9610d..7fde7ed7ce 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -3,54 +3,57 @@ app "breakout" imports []# [ pf.Action.{ Action }, pf.Elem.{ button, text, row, col } ] provides [ program ] to pf -program = { render } +program = { init, update, render } -render = \event -> +init = \_ -> { width: 1900, height: 1000 } + +update = \state -> when event is - Resize size -> - numRows = 4 - numCols = 8 - numBlocks = numRows * numCols + Resize size -> size + KeyUp keyCode -> { width: 1900, height: 1000 } + KeyDown keyCode -> { width: 1900, height: 1000 } - blocks = List.map (List.range 0 numBlocks) \index -> - col = - Num.rem index numCols - |> Result.withDefault 0 - |> Num.toF32 +render = \state -> + numRows = 4 + numCols = 8 + numBlocks = numRows * numCols - row = - index // numCols - |> Result.withDefault 0 - |> Num.toF32 + blocks = List.map (List.range 0 numBlocks) \index -> + col = + Num.rem index numCols + |> Result.withDefault 0 + |> Num.toF32 - red = (col / Num.toF32 numCols) |> Result.withDefault 0 - green = ((row / Num.toF32 numRows) |> Result.withDefault 0) - blue = (Num.toF32 index / Num.toF32 numBlocks) |> Result.withDefault 0 + row = + index // numCols + |> Result.withDefault 0 + |> Num.toF32 - color = { r: red * 0.8, g: 0.2 + green * 0.6, b: 0.2 + blue * 0.8, a: 1 } + red = (col / Num.toF32 numCols) |> Result.withDefault 0 + green = ((row / Num.toF32 numRows) |> Result.withDefault 0) + blue = (Num.toF32 index / Num.toF32 numBlocks) |> Result.withDefault 0 - { row, col, color } + color = { r: red * 0.8, g: 0.2 + green * 0.6, b: 0.2 + blue * 0.8, a: 1 } - blockWidth = size.width / numCols |> Result.withDefault 0 - blockHeight = 80 + { row, col, color } - rects = - List.map blocks \{ row, col, color } -> - left = Num.toF32 col * blockWidth - top = Num.toF32 (row * blockHeight) + blockWidth = state.width / numCols |> Result.withDefault 0 + blockHeight = 80 - Rect { left, top, width: blockWidth, height: blockHeight, color } + rects = + List.map blocks \{ row, col, color } -> + left = Num.toF32 col * blockWidth + top = Num.toF32 (row * blockHeight) - paddle = - color = { r: 0.8, g: 0.8, b: 0.8, a: 1.0 } - width = size.width * 0.25 - height = blockHeight - left = (size.width * 0.5) - (width * 0.5) - top = size.height - (height * 2) + Rect { left, top, width: blockWidth, height: blockHeight, color } - Rect { left, top, width, height, color } + paddle = + color = { r: 0.8, g: 0.8, b: 0.8, a: 1.0 } + width = state.width * 0.25 + height = blockHeight + left = (state.width * 0.5) - (width * 0.5) + top = state.height - (height * 2) - List.append rects paddle + Rect { left, top, width, height, color } - _ -> - [ Text "TODO handle other events than Resize!" ] + List.append rects paddle diff --git a/examples/breakout/platform/Package-Config.roc b/examples/breakout/platform/Package-Config.roc index cee1604c09..076ac21f1c 100644 --- a/examples/breakout/platform/Package-Config.roc +++ b/examples/breakout/platform/Package-Config.roc @@ -1,5 +1,5 @@ platform "gui" - requires {} { program : Program State } + requires { Model } { program : _ } exposes [] packages {} imports [] @@ -12,5 +12,9 @@ Elem : [ Rect { color : Rgba, left : F32, top : F32, width : F32, height : F32 } Event : [ Resize { width : F32, height : F32 }, KeyDown U32, KeyUp U32 ] # TODO allow changing the window title - maybe via a Task, since that shouldn't happen all the time -programForHost : { render : (Event -> List Elem) as Render } +programForHost : { + init : ({} -> Model) as Init, + update : (Model, Event -> Model) as Update, + render : (Model -> List Elem) as Render +} programForHost = program From 7deb8dda935e2cf7db6d298ae8b30711065277ab Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sun, 10 Apr 2022 10:56:01 -0400 Subject: [PATCH 139/846] Reproduce identifier interning bug --- compiler/can/src/module.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index 60255ac40d..cd75c6181f 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -190,6 +190,8 @@ pub fn canonicalize_module_defs<'a>( // Here we essentially add those "defs" to "the beginning of the module" // by canonicalizing them right before we canonicalize the actual ast::Def nodes. for (ident, (symbol, region)) in exposed_imports { + dbg!((&ident, symbol)); + let first_char = ident.as_inline_str().as_str().chars().next().unwrap(); if first_char.is_lowercase() { From 0551b564bd6021b3831a29e3f0cab1148065cd98 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 10 Apr 2022 17:09:50 +0200 Subject: [PATCH 140/846] fix num import issues in reporting tests --- reporting/tests/test_reporting.rs | 306 +++++++++++++++--------------- 1 file changed, 156 insertions(+), 150 deletions(-) diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index d16764eaa2..87d35c50f7 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -1114,8 +1114,8 @@ mod test_reporting { r#" bar = { bar : 0x3 } - f : { foo : Int * } -> Bool - f = \_ -> True + f : { foo : Num.Int * } -> [ Yes, No ] + f = \_ -> Yes f bar "# @@ -1152,8 +1152,8 @@ mod test_reporting { report_problem_as( indoc!( r#" - f : [ Red, Green ] -> Bool - f = \_ -> True + f : [ Red, Green ] -> [ Yes, No ] + f = \_ -> Yes f Blue "# @@ -1190,8 +1190,8 @@ mod test_reporting { report_problem_as( indoc!( r#" - f : [ Red (Int *), Green Bool ] -> Bool - f = \_ -> True + f : [ Red (Num.Int *), Green Str ] -> Str + f = \_ -> "yes" f (Blue 3.14) "# @@ -1211,7 +1211,7 @@ mod test_reporting { But `f` needs the 1st argument to be: - [ Green Bool, Red (Int *) ] + [ Green Str, Red (Int *) ] Tip: Seems like a tag typo. Maybe `Blue` should be `Red`? @@ -1228,7 +1228,7 @@ mod test_reporting { report_problem_as( indoc!( r#" - x : Int * + x : Num.Int * x = if True then 3.14 else 4 x @@ -1240,7 +1240,7 @@ mod test_reporting { Something is off with the `then` branch of this `if` expression: - 1│ x : Int * + 1│ x : Num.Int * 2│ x = if True then 3.14 else 4 ^^^^ @@ -1264,7 +1264,7 @@ mod test_reporting { report_problem_as( indoc!( r#" - x : Int * + x : Num.Int * x = when True is _ -> 3.14 @@ -1278,7 +1278,7 @@ mod test_reporting { Something is off with the body of the `x` definition: - 1│ x : Int * + 1│ x : Num.Int * 2│ x = 3│> when True is 4│> _ -> 3.14 @@ -1303,7 +1303,7 @@ mod test_reporting { report_problem_as( indoc!( r#" - x : Int * -> Int * + x : Num.Int * -> Num.Int * x = \_ -> 3.14 x @@ -1315,7 +1315,7 @@ mod test_reporting { Something is off with the body of the `x` definition: - 1│ x : Int * -> Int * + 1│ x : Num.Int * -> Num.Int * 2│ x = \_ -> 3.14 ^^^^ @@ -1339,7 +1339,7 @@ mod test_reporting { report_problem_as( indoc!( r#" - x : I64 + x : Num.I64 x = 42 x 3 @@ -1365,7 +1365,7 @@ mod test_reporting { report_problem_as( indoc!( r#" - f : I64 -> I64 + f : Num.I64 -> Num.I64 f = \_ -> 42 f 1 2 @@ -1391,7 +1391,7 @@ mod test_reporting { report_problem_as( indoc!( r#" - f : I64, I64 -> I64 + f : Num.I64, Num.I64 -> Num.I64 f = \_, _ -> 42 f 1 @@ -1667,7 +1667,7 @@ mod test_reporting { report_problem_as( indoc!( r#" - { x } : { x : Int * } + { x } : { x : Num.Int * } { x } = { x: 4.0 } x @@ -1679,7 +1679,7 @@ mod test_reporting { Something is off with the body of this definition: - 1│ { x } : { x : Int * } + 1│ { x } : { x : Num.Int * } 2│ { x } = { x: 4.0 } ^^^^^^^^^^ @@ -1828,7 +1828,7 @@ mod test_reporting { report_problem_as( indoc!( r#" - x : { a : Int *, b : Float *, c : Bool } + x : { a : Num.Int *, b : Num.Float *, c : Str } x = { b: 4.0 } x @@ -1840,7 +1840,7 @@ mod test_reporting { Something is off with the body of the `x` definition: - 1│ x : { a : Int *, b : Float *, c : Bool } + 1│ x : { a : Num.Int *, b : Num.Float *, c : Str } 2│ x = { b: 4.0 } ^^^^^^^^^^ @@ -1850,7 +1850,7 @@ mod test_reporting { But the type annotation on `x` says it should be: - { a : Int *, b : Float *, c : Bool } + { a : Int *, b : Float *, c : Str } Tip: Looks like the c and a fields are missing. "# @@ -1916,7 +1916,7 @@ mod test_reporting { report_problem_as( indoc!( r#" - f : Bool -> msg + f : Str -> msg f = \_ -> Foo f @@ -1928,7 +1928,7 @@ mod test_reporting { Something is off with the body of the `f` definition: - 1│ f : Bool -> msg + 1│ f : Str -> msg 2│ f = \_ -> Foo ^^^ @@ -1995,7 +1995,7 @@ mod test_reporting { report_problem_as( indoc!( r#" - f : Bool -> [ Ok I64, InvalidFoo ] + f : Str -> [ Ok Num.I64, InvalidFoo ] f = \_ -> ok 4 f @@ -2027,7 +2027,7 @@ mod test_reporting { report_problem_as( indoc!( r#" - f : Bool -> I64 + f : Str -> Num.I64 f = \_ -> ok = 3 @@ -2052,7 +2052,7 @@ mod test_reporting { Something is off with the body of the `f` definition: - 1│ f : Bool -> I64 + 1│ f : Str -> Num.I64 2│ f = \_ -> 3│ ok = 3 4│ @@ -2190,7 +2190,7 @@ mod test_reporting { report_problem_as( indoc!( r#" - f : { fo: I64 }ext -> I64 + f : { fo: Num.I64 }ext -> Num.I64 f = \r -> r2 = { r & foo: r.fo } @@ -2427,12 +2427,12 @@ mod test_reporting { report_problem_as( indoc!( r#" - Either : [ Left I64, Right Bool ] + Either : [ Left {}, Right Str ] x : Either - x = Left 42 + x = Left {} - f : Either -> I64 + f : Either -> {} f = \Left v -> v f x @@ -2464,8 +2464,8 @@ mod test_reporting { report_problem_as( indoc!( r#" - x : [ Left I64, Right Bool ] - x = Left 42 + x : [ Left {}, Right Str ] + x = Left {} (Left y) = x @@ -2484,7 +2484,7 @@ mod test_reporting { This `x` value is a: - [ Left I64, Right Bool ] + [ Left {}, Right Str ] But you are trying to use it as: @@ -2533,11 +2533,11 @@ mod test_reporting { report_problem_as( indoc!( r#" - x : Bool - x = True + x : [ Red, Green ] + x = Green when x is - False -> 3 + Red -> 3 "# ), indoc!( @@ -2547,11 +2547,11 @@ mod test_reporting { This `when` does not cover all the possibilities: 4│> when x is - 5│> False -> 3 + 5│> Red -> 3 Other possibilities include: - True + Green I would have to crash if I saw one of those! Add branches for them! "# @@ -2599,7 +2599,7 @@ mod test_reporting { r#" RemoteData e a : [ NotAsked, Loading, Failure e, Success a ] - x : RemoteData I64 Str + x : RemoteData Num.I64 Str when x is NotAsked -> 3 @@ -2662,7 +2662,7 @@ mod test_reporting { report_problem_as( indoc!( r#" - y : [ Nothing, Just I64 ] + y : [ Nothing, Just Num.I64 ] y = Just 4 x = { a: y, b: 42} @@ -2755,9 +2755,9 @@ mod test_reporting { report_problem_as( indoc!( r#" - Foo a : { x : Int a } + Foo a : { x : Num.Int a } - f : Foo a -> Int a + f : Foo a -> Num.Int a f = \r -> r.x f { y: 3.14 } @@ -3009,8 +3009,8 @@ mod test_reporting { report_problem_as( indoc!( r#" - a : { foo : I64, bar : F64, foo : Str } - a = { bar: 3.0, foo: "foo" } + a : { foo : Num.I64, bar : {}, foo : Str } + a = { bar: {}, foo: "foo" } a "# @@ -3018,17 +3018,17 @@ mod test_reporting { indoc!( r#" ── DUPLICATE FIELD NAME ──────────────────────────────────────────────────────── - + This record type defines the `.foo` field twice! - - 1│ a : { foo : I64, bar : F64, foo : Str } - ^^^^^^^^^ ^^^^^^^^^ - + + 1│ a : { foo : Num.I64, bar : {}, foo : Str } + ^^^^^^^^^^^^^ ^^^^^^^^^ + In the rest of the program, I will only use the latter definition: - - 1│ a : { foo : I64, bar : F64, foo : Str } - ^^^^^^^^^ - + + 1│ a : { foo : Num.I64, bar : {}, foo : Str } + ^^^^^^^^^ + For clarity, remove the previous `.foo` definitions from this record type. "# @@ -3041,7 +3041,7 @@ mod test_reporting { report_problem_as( indoc!( r#" - a : [ Foo I64, Bar F64, Foo Str ] + a : [ Foo Num.I64, Bar {}, Foo Str ] a = Foo "foo" a @@ -3050,17 +3050,17 @@ mod test_reporting { indoc!( r#" ── DUPLICATE TAG NAME ────────────────────────────────────────────────────────── - + This tag union type defines the `Foo` tag twice! - - 1│ a : [ Foo I64, Bar F64, Foo Str ] - ^^^^^^^ ^^^^^^^ - + + 1│ a : [ Foo Num.I64, Bar {}, Foo Str ] + ^^^^^^^^^^^ ^^^^^^^ + In the rest of the program, I will only use the latter definition: - - 1│ a : [ Foo I64, Bar F64, Foo Str ] - ^^^^^^^ - + + 1│ a : [ Foo Num.I64, Bar {}, Foo Str ] + ^^^^^^^ + For clarity, remove the previous `Foo` definitions from this tag union type. "# @@ -3073,7 +3073,7 @@ mod test_reporting { report_problem_as( indoc!( r#" - bar : I64 + bar : Num.I64 foo = \x -> x # NOTE: neither bar or foo are defined at this point @@ -3087,7 +3087,7 @@ mod test_reporting { This annotation does not match the definition immediately following it: - 1│> bar : I64 + 1│> bar : Num.I64 2│> foo = \x -> x Is it a typo? If not, put either a newline or comment between them. @@ -3101,7 +3101,7 @@ mod test_reporting { report_problem_as( indoc!( r#" - bar : I64 + bar : Num.I64 foo = \x -> x @@ -3117,7 +3117,7 @@ mod test_reporting { report_problem_as( indoc!( r#" - MyAlias 1 : I64 + MyAlias 1 : Num.I64 4 "# @@ -3128,7 +3128,7 @@ mod test_reporting { This pattern in the definition of `MyAlias` is not what I expect: - 1│ MyAlias 1 : I64 + 1│ MyAlias 1 : Num.I64 ^ Only type variables like `a` or `value` can occur in this position. @@ -3137,8 +3137,8 @@ mod test_reporting { `MyAlias` is not used anywhere in your code. - 1│ MyAlias 1 : I64 - ^^^^^^^^^^^^^^^ + 1│ MyAlias 1 : Num.I64 + ^^^^^^^^^^^^^^^^^^^ If you didn't intend on using `MyAlias` then remove it so future readers of your code don't wonder why it is there. @@ -3152,7 +3152,7 @@ mod test_reporting { report_problem_as( indoc!( r#" - Age 1 := I64 + Age 1 := Num.I64 a : Age a @@ -3164,7 +3164,7 @@ mod test_reporting { This pattern in the definition of `Age` is not what I expect: - 1│ Age 1 := I64 + 1│ Age 1 := Num.I64 ^ Only type variables like `a` or `value` can occur in this position. @@ -3178,7 +3178,7 @@ mod test_reporting { report_problem_as( indoc!( r#" - a : Num I64 F64 + a : Num.Num Num.I64 Num.F64 a = 3 a @@ -3187,12 +3187,12 @@ mod test_reporting { indoc!( r#" ── TOO MANY TYPE ARGUMENTS ───────────────────────────────────────────────────── - + The `Num` alias expects 1 type argument, but it got 2 instead: - - 1│ a : Num I64 F64 - ^^^^^^^^^^^ - + + 1│ a : Num.Num Num.I64 Num.F64 + ^^^^^^^^^^^^^^^^^^^^^^^ + Are there missing parentheses? "# ), @@ -3204,7 +3204,7 @@ mod test_reporting { report_problem_as( indoc!( r#" - f : Bool -> Num I64 F64 + f : Str -> Num.Num Num.I64 Num.F64 f = \_ -> 3 f @@ -3213,12 +3213,12 @@ mod test_reporting { indoc!( r#" ── TOO MANY TYPE ARGUMENTS ───────────────────────────────────────────────────── - + The `Num` alias expects 1 type argument, but it got 2 instead: - - 1│ f : Bool -> Num I64 F64 - ^^^^^^^^^^^ - + + 1│ f : Str -> Num.Num Num.I64 Num.F64 + ^^^^^^^^^^^^^^^^^^^^^^^ + Are there missing parentheses? "# ), @@ -3232,7 +3232,7 @@ mod test_reporting { r#" Pair a b : [ Pair a b ] - x : Pair I64 + x : Pair Num.I64 x = Pair 2 3 x @@ -3244,8 +3244,8 @@ mod test_reporting { The `Pair` alias expects 2 type arguments, but it got 1 instead: - 3│ x : Pair I64 - ^^^^^^^^ + 3│ x : Pair Num.I64 + ^^^^^^^^^^^^ Are there missing parentheses? "# @@ -3260,7 +3260,7 @@ mod test_reporting { r#" Pair a b : [ Pair a b ] - x : Pair I64 I64 I64 + x : Pair Num.I64 Num.I64 Num.I64 x = 3 x @@ -3272,8 +3272,8 @@ mod test_reporting { The `Pair` alias expects 2 type arguments, but it got 3 instead: - 3│ x : Pair I64 I64 I64 - ^^^^^^^^^^^^^^^^ + 3│ x : Pair Num.I64 Num.I64 Num.I64 + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Are there missing parentheses? "# @@ -3288,7 +3288,7 @@ mod test_reporting { r#" Foo a : [ Foo ] - f : Foo I64 + f : Foo Num.I64 f "# @@ -3378,7 +3378,7 @@ mod test_reporting { AList a b : [ ACons a (BList a b), ANil ] BList a b : [ BCons a (AList a b), BNil ] - x : AList I64 I64 + x : AList Num.I64 Num.I64 x = ACons 0 (BCons 1 (ACons "foo" BNil )) y : BList a a @@ -3395,7 +3395,7 @@ mod test_reporting { Something is off with the body of the `x` definition: - 4│ x : AList I64 I64 + 4│ x : AList Num.I64 Num.I64 5│ x = ACons 0 (BCons 1 (ACons "foo" BNil )) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -3781,7 +3781,7 @@ mod test_reporting { report_problem_as( indoc!( r#" - f : { x : I64, y ? I64 } -> I64 + f : { x : Num.I64, y ? Num.I64 } -> Num.I64 f = \{ x, y ? "foo" } -> (\g, _ -> g) x y f @@ -3814,7 +3814,7 @@ mod test_reporting { indoc!( r#" \rec -> - { x, y } : { x : I64, y ? Bool } + { x, y } : { x : Num.I64, y ? Str } { x, y } = rec { x, y } @@ -3826,16 +3826,16 @@ mod test_reporting { Something is off with the body of this definition: - 2│> { x, y } : { x : I64, y ? Bool } + 2│> { x, y } : { x : Num.I64, y ? Str } 3│> { x, y } = rec The body is a value of type: - { x : I64, y : Bool } + { x : I64, y : Str } But the type annotation says it should be: - { x : I64, y ? Bool } + { x : I64, y ? Str } Tip: To extract the `.y` field it must be non-optional, but the type says this field is optional. Learn more about optional fields at TODO. @@ -3849,7 +3849,7 @@ mod test_reporting { report_problem_as( indoc!( r#" - f : { x : I64, y ? I64 } -> I64 + f : { x : Num.I64, y ? Num.I64 } -> Num.I64 f = \{ x, y } -> x + y f @@ -3884,7 +3884,7 @@ mod test_reporting { report_problem_as( indoc!( r#" - f : { x : I64, y ? I64 } -> I64 + f : { x : Num.I64, y ? Num.I64 } -> Num.I64 f = \r -> when r is { x, y } -> x + y @@ -3921,7 +3921,7 @@ mod test_reporting { report_problem_as( indoc!( r#" - f : { x : I64, y ? I64 } -> I64 + f : { x : Num.I64, y ? Num.I64 } -> Num.I64 f = \r -> r.y f @@ -3956,7 +3956,7 @@ mod test_reporting { report_problem_as( indoc!( r#" - f : { x : I64, y ? I64 } -> I64 + f : { x : Num.I64, y ? Num.I64 } -> Num.I64 f = \r -> .y r f @@ -3991,7 +3991,7 @@ mod test_reporting { report_problem_as( indoc!( r#" - f : { x : I64, y : I64 } -> I64 + f : { x : Num.I64, y : Num.I64 } -> Num.I64 f = \r -> when r is { x, y : "foo" } -> x + 0 @@ -4026,7 +4026,7 @@ mod test_reporting { report_problem_as( indoc!( r#" - f : { x : I64, y ? I64 } -> I64 + f : { x : Num.I64, y ? Num.I64 } -> Num.I64 f = \r -> when r is { x, y ? "foo" } -> (\g, _ -> g) x y @@ -4941,7 +4941,7 @@ mod test_reporting { report_problem_as( indoc!( r#" - f : [ @Foo Bool, @100 I64 ] + f : [ @Foo Str, @100 I64 ] f = 0 f @@ -4953,8 +4953,8 @@ mod test_reporting { I am partway through parsing a tag union type, but I got stuck here: - 1│ f : [ @Foo Bool, @100 I64 ] - ^ + 1│ f : [ @Foo Str, @100 I64 ] + ^ I was expecting to see a private tag name. @@ -4971,7 +4971,7 @@ mod test_reporting { report_problem_as( indoc!( r#" - myDict : Dict I64 Str + myDict : Dict Num.I64 Str myDict = Dict.insert Dict.empty "foo" 42 myDict @@ -4983,7 +4983,7 @@ mod test_reporting { Something is off with the body of the `myDict` definition: - 1│ myDict : Dict I64 Str + 1│ myDict : Dict Num.I64 Str 2│ myDict = Dict.insert Dict.empty "foo" 42 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -6573,7 +6573,7 @@ I need all branches in an `if` to have the same type! report_problem_as( indoc!( r#" - mult : Num *, F64 -> F64 + mult : Num.Num *, Num.F64 -> Num.F64 mult = \a, b -> a * b mult 0 0 @@ -6600,7 +6600,7 @@ I need all branches in an `if` to have the same type! Something is off with the body of the `mult` definition: - 1│ mult : Num *, F64 -> F64 + 1│ mult : Num.Num *, Num.F64 -> Num.F64 2│ mult = \a, b -> a * b ^^^^^ @@ -6621,7 +6621,7 @@ I need all branches in an `if` to have the same type! report_problem_as( indoc!( r#" - mult : Num a, F64 -> F64 + mult : Num.Num a, Num.F64 -> Num.F64 mult = \a, b -> a * b mult 0 0 @@ -6648,7 +6648,7 @@ I need all branches in an `if` to have the same type! Something is off with the body of the `mult` definition: - 1│ mult : Num a, F64 -> F64 + 1│ mult : Num.Num a, Num.F64 -> Num.F64 2│ mult = \a, b -> a * b ^^^^^ @@ -6669,6 +6669,8 @@ I need all branches in an `if` to have the same type! report_problem_as( indoc!( r#" + Result a b : [ Ok a, Err b ] + canIGo : _ -> Result _ canIGo = \color -> when color is @@ -6685,7 +6687,7 @@ I need all branches in an `if` to have the same type! The `Result` alias expects 2 type arguments, but it got 1 instead: - 1│ canIGo : _ -> Result _ + 3│ canIGo : _ -> Result _ ^^^^^^^^ Are there missing parentheses? @@ -6699,6 +6701,8 @@ I need all branches in an `if` to have the same type! report_problem_as( indoc!( r#" + Result a b : [ Ok a, Err b ] + canIGo : _ -> Result _ _ _ canIGo = \color -> when color is @@ -6715,7 +6719,7 @@ I need all branches in an `if` to have the same type! The `Result` alias expects 2 type arguments, but it got 3 instead: - 1│ canIGo : _ -> Result _ _ _ + 3│ canIGo : _ -> Result _ _ _ ^^^^^^^^^^^^ Are there missing parentheses? @@ -6996,7 +7000,7 @@ I need all branches in an `if` to have the same type! C a b : a -> D a b D a b : { a, b } - f : C a Nat -> D a Nat + f : C a Num.Nat -> D a Num.Nat f = \c -> c 6 f "# @@ -7265,7 +7269,7 @@ I need all branches in an `if` to have the same type! report_problem_as( &format!(indoc!( r#" - use : {} -> U8 + use : Num.{} -> Num.U8 use {}{} "# ), bad_type, number, $suffix), @@ -7958,7 +7962,7 @@ I need all branches in an `if` to have the same type! r#" R a : [ Only (R a) ] - v : R U8 + v : R Str v "# ), @@ -7985,7 +7989,7 @@ I need all branches in an `if` to have the same type! r#" R a : [ Only { very: [ Deep (R a) ] } ] - v : R U8 + v : R Str v "# ), @@ -8013,7 +8017,7 @@ I need all branches in an `if` to have the same type! Foo a : [ Thing (Bar a) ] Bar a : [ Stuff (Foo a) ] - v : Bar U8 + v : Bar Str v "# ), @@ -8047,10 +8051,12 @@ I need all branches in an `if` to have the same type! report_problem_as( indoc!( r#" + Result a b : [ Ok a, Err b ] + Foo a : [ Blah (Result (Bar a) []) ] Bar a : Foo a - v : Bar U8 + v : Bar Str v "# ), @@ -8086,7 +8092,7 @@ I need all branches in an `if` to have the same type! report_problem_as( indoc!( r#" - Age : U8 + Age : Num.U8 $Age 21 "# @@ -8102,7 +8108,7 @@ I need all branches in an `if` to have the same type! Note: There is an alias of the same name: - 1│ Age : U8 + 1│ Age : Num.U8 ^^^ Note: It looks like there are no opaque types declared in this scope yet! @@ -8111,8 +8117,8 @@ I need all branches in an `if` to have the same type! `Age` is not used anywhere in your code. - 1│ Age : U8 - ^^^^^^^^ + 1│ Age : Num.U8 + ^^^^^^^^^^^^ If you didn't intend on using `Age` then remove it so future readers of your code don't wonder why it is there. @@ -8163,7 +8169,7 @@ I need all branches in an `if` to have the same type! indoc!( r#" age = - Age := U8 + Age := Num.U8 21u8 $Age age @@ -8178,8 +8184,8 @@ I need all branches in an `if` to have the same type! `Age` is not used anywhere in your code. - 2│ Age := U8 - ^^^^^^^^^ + 2│ Age := Num.U8 + ^^^^^^^^^^^^^ If you didn't intend on using `Age` then remove it so future readers of your code don't wonder why it is there. @@ -8233,7 +8239,7 @@ I need all branches in an `if` to have the same type! report_problem_as( indoc!( r#" - Age := U8 + Age := Num.U8 n : Age n = $Age "" @@ -8342,9 +8348,9 @@ I need all branches in an `if` to have the same type! report_problem_as( indoc!( r#" - Age := U8 + Age := Num.U8 - f : Age -> U8 + f : Age -> Num.U8 f = \Age n -> n f @@ -8453,7 +8459,7 @@ I need all branches in an `if` to have the same type! r#" F n := n - v : F U8 + v : F Num.U8 when v is $F 1 -> "" @@ -8558,7 +8564,7 @@ I need all branches in an `if` to have the same type! report_problem_as( indoc!( r#" - f : { x : Nat }U32 + f : { x : Num.Nat }U32 f "# ), @@ -8568,8 +8574,8 @@ I need all branches in an `if` to have the same type! This record extension type is invalid: - 1│ f : { x : Nat }U32 - ^^^ + 1│ f : { x : Num.Nat }U32 + ^^^ Note: A record extension variable can only contain a type variable or another record. @@ -8770,7 +8776,7 @@ I need all branches in an `if` to have the same type! report_problem_as( indoc!( r#" - I : Int * + I : Num.Int * a : I a "# @@ -8781,8 +8787,8 @@ I need all branches in an `if` to have the same type! The definition of `I` has an unbound type variable: - 1│ I : Int * - ^ + 1│ I : Num.Int * + ^ Tip: Type variables must be bound before the `:`. Perhaps you intended to add a type parameter to this type? @@ -8796,7 +8802,7 @@ I need all branches in an `if` to have the same type! report_problem_as( indoc!( r#" - I := Int * + I := Num.Int * a : I a "# @@ -8807,8 +8813,8 @@ I need all branches in an `if` to have the same type! The definition of `I` has an unbound type variable: - 1│ I := Int * - ^ + 1│ I := Num.Int * + ^ Tip: Type variables must be bound before the `:=`. Perhaps you intended to add a type parameter to this type? @@ -8822,7 +8828,7 @@ I need all branches in an `if` to have the same type! report_problem_as( indoc!( r#" - I : [ A (Int *), B (Int *) ] + I : [ A (Num.Int *), B (Num.Int *) ] a : I a "# @@ -8835,8 +8841,8 @@ I need all branches in an `if` to have the same type! Here is one occurrence: - 1│ I : [ A (Int *), B (Int *) ] - ^ + 1│ I : [ A (Num.Int *), B (Num.Int *) ] + ^ Tip: Type variables must be bound before the `:`. Perhaps you intended to add a type parameter to this type? @@ -8850,7 +8856,7 @@ I need all branches in an `if` to have the same type! report_problem_as( indoc!( r#" - I : Int _ + I : Num.Int _ a : I a "# @@ -8861,8 +8867,8 @@ I need all branches in an `if` to have the same type! The definition of `I` has an unbound type variable: - 1│ I : Int _ - ^ + 1│ I : Num.Int _ + ^ Tip: Type variables must be bound before the `:`. Perhaps you intended to add a type parameter to this type? @@ -8876,7 +8882,7 @@ I need all branches in an `if` to have the same type! report_problem_as( indoc!( r#" - I : Int a + I : Num.Int a a : I a "# @@ -8887,8 +8893,8 @@ I need all branches in an `if` to have the same type! The definition of `I` has an unbound type variable: - 1│ I : Int a - ^ + 1│ I : Num.Int a + ^ Tip: Type variables must be bound before the `:`. Perhaps you intended to add a type parameter to this type? From be1f06f87269df21af01b4b960d0868841102b67 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 10 Apr 2022 17:17:00 +0200 Subject: [PATCH 141/846] fix name suggestions in reporting tests --- reporting/tests/test_reporting.rs | 56 +++++++++++++++---------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 87d35c50f7..5dc8d748cd 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -580,9 +580,9 @@ mod test_reporting { Did you mean one of these? baz - Nat Str Err + main "# ), ) @@ -609,8 +609,8 @@ mod test_reporting { True Str - Num Err + List "# ), ) @@ -772,10 +772,10 @@ mod test_reporting { Did you mean one of these? - Decimal - Dec - Result - Num + Set + List + True + Box "# ), ); @@ -1556,9 +1556,9 @@ mod test_reporting { Did you mean one of these? Box - Bool - U8 - F64 + Set + Str + Ok "# ), ) @@ -2013,9 +2013,9 @@ mod test_reporting { Did you mean one of these? Ok - U8 - Box f + Box + Set "# ), ) @@ -5950,10 +5950,10 @@ I need all branches in an `if` to have the same type! Did you mean one of these? - Nat Str Err - U8 + Box + Set "# ), ) @@ -8564,7 +8564,7 @@ I need all branches in an `if` to have the same type! report_problem_as( indoc!( r#" - f : { x : Num.Nat }U32 + f : { x : Num.Nat }[] f "# ), @@ -8574,8 +8574,8 @@ I need all branches in an `if` to have the same type! This record extension type is invalid: - 1│ f : { x : Num.Nat }U32 - ^^^ + 1│ f : { x : Num.Nat }[] + ^^ Note: A record extension variable can only contain a type variable or another record. @@ -8634,25 +8634,25 @@ I need all branches in an `if` to have the same type! ^^^^^^^^^^^ Did you mean one of these? - + Type - Unsigned8 - Unsigned32 - Unsigned16 - + True + Box + Ok + ── UNRECOGNIZED NAME ─────────────────────────────────────────────────────────── - + I cannot find a `UnknownType` value - + 3│ insertHelper : UnknownType, Type -> Type ^^^^ - + Did you mean one of these? - + Type - Unsigned8 - Unsigned32 - Unsigned16 + True + insertHelper + Box "# ), ) From 823d4678a868dd180428795b208a635ffd38bd07 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 10 Apr 2022 20:12:59 +0200 Subject: [PATCH 142/846] import Box in box tests --- compiler/test_gen/src/gen_primitives.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/compiler/test_gen/src/gen_primitives.rs b/compiler/test_gen/src/gen_primitives.rs index abbba972a6..999d85eb67 100644 --- a/compiler/test_gen/src/gen_primitives.rs +++ b/compiler/test_gen/src/gen_primitives.rs @@ -3288,7 +3288,10 @@ fn box_and_unbox_num() { assert_evals_to!( indoc!( r#" - Box.unbox (Box.box (123u8)) + app "test" imports [ Box ] provides [ main ] to "./platform" + + main = + Box.unbox (Box.box (123u8)) "# ), 123, @@ -3302,7 +3305,10 @@ fn box_and_unbox_record() { assert_evals_to!( indoc!( r#" - Box.unbox (Box.box { a: 15u8, b: 27u8 }) + app "test" imports [ Box ] provides [ main ] to "./platform" + + main = + Box.unbox (Box.box { a: 15u8, b: 27u8 }) "# ), (15, 27), @@ -3316,9 +3322,13 @@ fn box_and_unbox_tag_union() { assert_evals_to!( indoc!( r#" + app "test" imports [ Box ] provides [ main ] to "./platform" + v : [ A U8, B U8 ] # usually stack allocated v = B 27u8 - Box.unbox (Box.box v) + + main = + Box.unbox (Box.box v) "# ), (27, 1), From 78735b6159f5318a1ec91f8d1c2022e430939930 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 10 Apr 2022 21:15:29 +0200 Subject: [PATCH 143/846] remove unused code --- compiler/load_internal/src/file.rs | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index 29554cee67..b0d5e9cafe 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -3641,34 +3641,6 @@ fn run_solve<'a>( } } -/// Get the project root (relative to closest Cargo.lock file) -/// ```rust -/// match project_root::get_project_root() { -/// Ok(p) => println!("Current project root is {:?}", p), -/// Err(e) => println!("Error obtaining project root {:?}", e) -/// }; -/// ``` -pub fn get_project_root() -> io::Result { - use std::fs::read_dir; - use std::io::ErrorKind; - - let path = env::current_dir()?; - let path_ancestors = path.as_path().ancestors(); - - for p in path_ancestors { - let has_cargo = read_dir(p)? - .into_iter() - .any(|p| p.unwrap().file_name() == *"Cargo.lock"); - if has_cargo { - return Ok(PathBuf::from(p)); - } - } - Err(io::Error::new( - ErrorKind::NotFound, - "Ran out of places to find Cargo.toml", - )) -} - fn unspace<'a, T: Copy>(arena: &'a Bump, items: &[Loc>]) -> &'a [Loc] { bumpalo::collections::Vec::from_iter_in( items From 2cb175df1036034ee82b5a758a30c457fbb88b8d Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 10 Apr 2022 21:22:15 +0200 Subject: [PATCH 144/846] use cached subs, run solve tests single-threaded --- compiler/load/src/lib.rs | 45 ++++++++++++++++++++++-------- compiler/load_internal/src/file.rs | 2 +- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/compiler/load/src/lib.rs b/compiler/load/src/lib.rs index d74caa1a86..065e263467 100644 --- a/compiler/load/src/lib.rs +++ b/compiler/load/src/lib.rs @@ -32,6 +32,28 @@ fn load<'a>( ) } +/// Load using only a single thread; used when compiling to webassembly +pub fn load_single_threaded<'a>( + arena: &'a Bump, + load_start: LoadStart<'a>, + src_dir: &Path, + exposed_types: ExposedByModule, + goal_phase: Phase, + target_info: TargetInfo, +) -> Result, LoadingProblem<'a>> { + let cached_subs = read_cached_subs(); + + roc_load_internal::file::load_single_threaded( + arena, + load_start, + src_dir, + exposed_types, + goal_phase, + target_info, + cached_subs, + ) +} + pub fn load_and_monomorphize_from_str<'a>( arena: &'a Bump, filename: PathBuf, @@ -117,7 +139,10 @@ pub fn load_and_typecheck_str<'a>( let load_start = LoadStart::from_str(arena, filename, source)?; - match load( + // NOTE: this function is meant for tests, and so we use single-threaded + // solving so we don't use too many threads per-test. That gives higher + // throughput for the test run overall + match load_single_threaded( arena, load_start, src_dir, @@ -148,16 +173,14 @@ fn deserialize_help(bytes: &[u8]) -> (Subs, Vec<(Symbol, Variable)>) { fn read_cached_subs() -> MutMap)> { let mut output = MutMap::default(); - if false { - output.insert(ModuleId::BOOL, deserialize_help(BOOL)); - output.insert(ModuleId::RESULT, deserialize_help(RESULT)); - output.insert(ModuleId::LIST, deserialize_help(LIST)); - output.insert(ModuleId::STR, deserialize_help(STR)); - output.insert(ModuleId::DICT, deserialize_help(DICT)); - output.insert(ModuleId::SET, deserialize_help(SET)); - output.insert(ModuleId::BOX, deserialize_help(BOX)); - output.insert(ModuleId::NUM, deserialize_help(NUM)); - } + output.insert(ModuleId::BOOL, deserialize_help(BOOL)); + output.insert(ModuleId::RESULT, deserialize_help(RESULT)); + output.insert(ModuleId::LIST, deserialize_help(LIST)); + output.insert(ModuleId::STR, deserialize_help(STR)); + output.insert(ModuleId::DICT, deserialize_help(DICT)); + output.insert(ModuleId::SET, deserialize_help(SET)); + output.insert(ModuleId::BOX, deserialize_help(BOX)); + output.insert(ModuleId::NUM, deserialize_help(NUM)); output } diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index b0d5e9cafe..0ca6a4eda6 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -1089,7 +1089,7 @@ pub fn load<'a>( /// Load using only a single thread; used when compiling to webassembly #[allow(clippy::too_many_arguments)] -fn load_single_threaded<'a>( +pub fn load_single_threaded<'a>( arena: &'a Bump, load_start: LoadStart<'a>, src_dir: &Path, From e281ca7152560e6a0314e1452a1490fea84c7848 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 10 Apr 2022 21:42:39 +0200 Subject: [PATCH 145/846] remove dependency --- Cargo.lock | 11 ----------- compiler/load_internal/Cargo.toml | 1 - 2 files changed, 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0087903628..27c0e7bf0f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2076,16 +2076,6 @@ version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" -[[package]] -name = "memmap" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "memmap2" version = "0.1.0" @@ -3725,7 +3715,6 @@ dependencies = [ "crossbeam", "indoc", "maplit", - "memmap", "morphic_lib", "num_cpus", "parking_lot 0.12.0", diff --git a/compiler/load_internal/Cargo.toml b/compiler/load_internal/Cargo.toml index da06beeec5..5381fc94b9 100644 --- a/compiler/load_internal/Cargo.toml +++ b/compiler/load_internal/Cargo.toml @@ -27,7 +27,6 @@ bumpalo = { version = "3.8.0", features = ["collections"] } parking_lot = "0.12" crossbeam = "0.8.1" num_cpus = "1.13.0" -memmap = "0.7.0" [dev-dependencies] tempfile = "3.2.0" From 4ecf2a8c24a4ee99f8988afcf8f15be38ea3ff78 Mon Sep 17 00:00:00 2001 From: Nikita Mounier Date: Mon, 11 Apr 2022 11:23:33 +0000 Subject: [PATCH 146/846] Modify division behaviour to panic when dividing by 0, and add `divChecked`, divFloorChecked` and `divCeilingChecked` for safe alternatives which return a Result, mimicking the previous behaviour. --- compiler/builtins/bitcode/src/dec.zig | 4 +- compiler/builtins/bitcode/src/num.zig | 2 +- compiler/builtins/roc/Num.roc | 12 +- compiler/builtins/src/std.rs | 25 ++- compiler/can/src/builtins.rs | 24 ++- compiler/module/src/low_level.rs | 6 +- compiler/module/src/symbol.rs | 224 +++++++++++++------------- compiler/solve/tests/solve_expr.rs | 54 ++++++- compiler/test_gen/src/gen_num.rs | 96 ++++++++++- 9 files changed, 318 insertions(+), 129 deletions(-) diff --git a/compiler/builtins/bitcode/src/dec.zig b/compiler/builtins/bitcode/src/dec.zig index 2f0dcb6abe..b9eba9c0cc 100644 --- a/compiler/builtins/bitcode/src/dec.zig +++ b/compiler/builtins/bitcode/src/dec.zig @@ -310,9 +310,7 @@ pub const RocDec = extern struct { // (n / 0) is an error if (denominator_i128 == 0) { - // The compiler frontend does the `denominator == 0` check for us, - // therefore this case is unreachable from roc user code - unreachable; + @panic("TODO runtime exception for dividing by 0!"); } // If they're both negative, or if neither is negative, the final answer diff --git a/compiler/builtins/bitcode/src/num.zig b/compiler/builtins/bitcode/src/num.zig index 41d93df976..54bcf8ff5a 100644 --- a/compiler/builtins/bitcode/src/num.zig +++ b/compiler/builtins/bitcode/src/num.zig @@ -102,7 +102,7 @@ pub fn exportRound(comptime T: type, comptime name: []const u8) void { pub fn exportDivCeil(comptime T: type, comptime name: []const u8) void { comptime var f = struct { fn func(a: T, b: T) callconv(.C) T { - return math.divCeil(T, a, b) catch unreachable; + return math.divCeil(T, a, b) catch @panic("TODO runtime exception for dividing by 0!"); } }.func; @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); diff --git a/compiler/builtins/roc/Num.roc b/compiler/builtins/roc/Num.roc index fc337ce9ba..549e392d84 100644 --- a/compiler/builtins/roc/Num.roc +++ b/compiler/builtins/roc/Num.roc @@ -69,6 +69,7 @@ interface Num isNegative, rem, div, + divChecked, modInt, modFloat, sqrt, @@ -97,7 +98,9 @@ interface Num bytesToU16, bytesToU32, divCeil, + divCeilChecked, divFloor, + divFloorChecked, toStr, isMultipleOf, minI8, @@ -229,10 +232,13 @@ atan : Float a -> Float a sqrt : Float a -> Result (Float a) [ SqrtOfNegative ]* log : Float a -> Result (Float a) [ LogNeedsPositive ]* -div : Float a, Float a -> Result (Float a) [ DivByZero ]* +div : Float a, Float a -> Float a +divChecked : Float a, Float a -> Result (Float a) [ DivByZero ]* -divCeil: Int a, Int a -> Result (Int a) [ DivByZero ]* -divFloor: Int a, Int a -> Result (Int a) [ DivByZero ]* +divCeil : Int a, Int a -> Int a +divCeilChecked : Int a, Int a -> Result (Int a) [ DivByZero ]* +divFloor : Int a, Int a -> Int a +divFloorChecked : Int a, Int a -> Result (Int a) [ DivByZero ]* # mod : Float a, Float a -> Result (Float a) [ DivByZero ]* rem : Int a, Int a -> Result (Int a) [ DivByZero ]* diff --git a/compiler/builtins/src/std.rs b/compiler/builtins/src/std.rs index ac408f5f56..11b11347f9 100644 --- a/compiler/builtins/src/std.rs +++ b/compiler/builtins/src/std.rs @@ -316,17 +316,31 @@ pub fn types() -> MutMap { Box::new(SolvedType::Wildcard), ); - // divInt : Int a, Int a -> Result (Int a) [ DivByZero ]* + // divInt : Int a, Int a -> Int a add_top_level_function_type!( Symbol::NUM_DIV_INT, vec![int_type(flex(TVAR1)), int_type(flex(TVAR1))], + Box::new(int_type(flex(TVAR1))) + ); + + // divIntChecked : Int a, Int a -> Result (Int a) [ DivByZero ]* + add_top_level_function_type!( + Symbol::NUM_DIV_INT_CHECKED, + vec![int_type(flex(TVAR1)), int_type(flex(TVAR1))], Box::new(result_type(int_type(flex(TVAR1)), div_by_zero.clone())), ); - //divCeil: Int a, Int a -> Result (Int a) [ DivByZero ]* + // divCeil : Int a, Int a -> Int a add_top_level_function_type!( Symbol::NUM_DIV_CEIL, vec![int_type(flex(TVAR1)), int_type(flex(TVAR1))], + Box::new(int_type(flex(TVAR1))) + ); + + //divCeilChecked : Int a, Int a -> Result (Int a) [ DivByZero ]* + add_top_level_function_type!( + Symbol::NUM_DIV_CEIL_CHECKED, + vec![int_type(flex(TVAR1)), int_type(flex(TVAR1))], Box::new(result_type(int_type(flex(TVAR1)), div_by_zero.clone())), ); @@ -631,6 +645,13 @@ pub fn types() -> MutMap { add_top_level_function_type!( Symbol::NUM_DIV_FLOAT, vec![float_type(flex(TVAR1)), float_type(flex(TVAR1))], + Box::new(float_type(flex(TVAR1))) + ); + + // divChecked : Float a, Float a -> Result (Float a) [ DivByZero ]* + add_top_level_function_type!( + Symbol::NUM_DIV_FLOAT_CHECKED, + vec![float_type(flex(TVAR1)), float_type(flex(TVAR1))], Box::new(result_type(float_type(flex(TVAR1)), div_by_zero.clone())), ); diff --git a/compiler/can/src/builtins.rs b/compiler/can/src/builtins.rs index 496d2aea11..833851c845 100644 --- a/compiler/can/src/builtins.rs +++ b/compiler/can/src/builtins.rs @@ -195,8 +195,11 @@ pub fn builtin_defs_map(symbol: Symbol, var_store: &mut VarStore) -> Option NUM_COS => num_cos, NUM_TAN => num_tan, NUM_DIV_FLOAT => num_div_float, + NUM_DIV_FLOAT_CHECKED => num_div_float_checked, NUM_DIV_INT => num_div_int, + NUM_DIV_INT_CHECKED => num_div_int_checked, NUM_DIV_CEIL => num_div_ceil, + NUM_DIV_CEIL_CHECKED => num_div_ceil_checked, NUM_ABS => num_abs, NUM_NEG => num_neg, NUM_REM => num_rem, @@ -4277,8 +4280,13 @@ fn num_abs(symbol: Symbol, var_store: &mut VarStore) -> Def { ) } -/// Num.div : Float, Float -> Result Float [ DivByZero ]* +/// Num.div : Float, Float -> Float fn num_div_float(symbol: Symbol, var_store: &mut VarStore) -> Def { + num_binop(symbol, var_store, LowLevel::NumDivUnchecked) +} + +/// Num.divChecked : Float, Float -> Result Float [ DivByZero ]* +fn num_div_float_checked(symbol: Symbol, var_store: &mut VarStore) -> Def { let bool_var = var_store.fresh(); let num_var = var_store.fresh(); let unbound_zero_var = var_store.fresh(); @@ -4343,8 +4351,13 @@ fn num_div_float(symbol: Symbol, var_store: &mut VarStore) -> Def { ) } -/// Num.div : Int a , Int a -> Result (Int a) [ DivByZero ]* +/// Num.div : Int a, Int a -> Int a fn num_div_int(symbol: Symbol, var_store: &mut VarStore) -> Def { + num_binop(symbol, var_store, LowLevel::NumDivUnchecked) +} + +/// Num.divChecked : Int a , Int a -> Result (Int a) [ DivByZero ]* +fn num_div_int_checked(symbol: Symbol, var_store: &mut VarStore) -> Def { let bool_var = var_store.fresh(); let num_var = var_store.fresh(); let unbound_zero_var = var_store.fresh(); @@ -4414,8 +4427,13 @@ fn num_div_int(symbol: Symbol, var_store: &mut VarStore) -> Def { ) } -/// Num.divCeil : Int a , Int a -> Result (Int a) [ DivByZero ]* +/// Num.divCeil : Int a, Int a -> Int a fn num_div_ceil(symbol: Symbol, var_store: &mut VarStore) -> Def { + num_binop(symbol, var_store, LowLevel::NumDivCeilUnchecked) +} + +/// Num.divCeilChecked : Int a , Int a -> Result (Int a) [ DivByZero ]* +fn num_div_ceil_checked(symbol: Symbol, var_store: &mut VarStore) -> Def { let bool_var = var_store.fresh(); let num_var = var_store.fresh(); let unbound_zero_var = var_store.fresh(); diff --git a/compiler/module/src/low_level.rs b/compiler/module/src/low_level.rs index 1271816043..205bfcd1d6 100644 --- a/compiler/module/src/low_level.rs +++ b/compiler/module/src/low_level.rs @@ -287,8 +287,10 @@ impl LowLevelWrapperType { Symbol::NUM_LT => CanBeReplacedBy(NumLt), Symbol::NUM_LTE => CanBeReplacedBy(NumLte), Symbol::NUM_COMPARE => CanBeReplacedBy(NumCompare), - Symbol::NUM_DIV_FLOAT => WrapperIsRequired, - Symbol::NUM_DIV_CEIL => WrapperIsRequired, + Symbol::NUM_DIV_FLOAT => CanBeReplacedBy(NumDivUnchecked), + Symbol::NUM_DIV_FLOAT_CHECKED => WrapperIsRequired, + Symbol::NUM_DIV_CEIL => CanBeReplacedBy(NumDivCeilUnchecked), + Symbol::NUM_DIV_CEIL_CHECKED => WrapperIsRequired, Symbol::NUM_REM => WrapperIsRequired, Symbol::NUM_IS_MULTIPLE_OF => CanBeReplacedBy(NumIsMultipleOf), Symbol::NUM_ABS => CanBeReplacedBy(NumAbs), diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index db2e02bfdb..ea48f28590 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -945,114 +945,122 @@ define_builtins! { 36 NUM_IS_POSITIVE: "isPositive" 37 NUM_IS_NEGATIVE: "isNegative" 38 NUM_REM: "rem" - 39 NUM_DIV_FLOAT: "div" - 40 NUM_DIV_INT: "divFloor" - 41 NUM_MOD_INT: "modInt" - 42 NUM_MOD_FLOAT: "modFloat" - 43 NUM_SQRT: "sqrt" - 44 NUM_LOG: "log" - 45 NUM_ROUND: "round" - 46 NUM_COMPARE: "compare" - 47 NUM_POW: "pow" - 48 NUM_CEILING: "ceiling" - 49 NUM_POW_INT: "powInt" - 50 NUM_FLOOR: "floor" - 51 NUM_ADD_WRAP: "addWrap" - 52 NUM_ADD_CHECKED: "addChecked" - 53 NUM_ADD_SATURATED: "addSaturated" - 54 NUM_ATAN: "atan" - 55 NUM_ACOS: "acos" - 56 NUM_ASIN: "asin" - 57 NUM_AT_SIGNED128: "@Signed128" - 58 NUM_SIGNED128: "Signed128" imported - 59 NUM_AT_SIGNED64: "@Signed64" - 60 NUM_SIGNED64: "Signed64" imported - 61 NUM_AT_SIGNED32: "@Signed32" - 62 NUM_SIGNED32: "Signed32" imported - 63 NUM_AT_SIGNED16: "@Signed16" - 64 NUM_SIGNED16: "Signed16" imported - 65 NUM_AT_SIGNED8: "@Signed8" - 66 NUM_SIGNED8: "Signed8" imported - 67 NUM_AT_UNSIGNED128: "@Unsigned128" - 68 NUM_UNSIGNED128: "Unsigned128" imported - 69 NUM_AT_UNSIGNED64: "@Unsigned64" - 70 NUM_UNSIGNED64: "Unsigned64" imported - 71 NUM_AT_UNSIGNED32: "@Unsigned32" - 72 NUM_UNSIGNED32: "Unsigned32" imported - 73 NUM_AT_UNSIGNED16: "@Unsigned16" - 74 NUM_UNSIGNED16: "Unsigned16" imported - 75 NUM_AT_UNSIGNED8: "@Unsigned8" - 76 NUM_UNSIGNED8: "Unsigned8" imported - 77 NUM_AT_BINARY64: "@Binary64" - 78 NUM_BINARY64: "Binary64" imported - 79 NUM_AT_BINARY32: "@Binary32" - 80 NUM_BINARY32: "Binary32" imported - 81 NUM_BITWISE_AND: "bitwiseAnd" - 82 NUM_BITWISE_XOR: "bitwiseXor" - 83 NUM_BITWISE_OR: "bitwiseOr" - 84 NUM_SHIFT_LEFT: "shiftLeftBy" - 85 NUM_SHIFT_RIGHT: "shiftRightBy" - 86 NUM_SHIFT_RIGHT_ZERO_FILL: "shiftRightZfBy" - 87 NUM_SUB_WRAP: "subWrap" - 88 NUM_SUB_CHECKED: "subChecked" - 89 NUM_SUB_SATURATED: "subSaturated" - 90 NUM_MUL_WRAP: "mulWrap" - 91 NUM_MUL_CHECKED: "mulChecked" - 92 NUM_INT: "Int" imported - 93 NUM_FLOAT: "Float" imported - 94 NUM_AT_NATURAL: "@Natural" - 95 NUM_NATURAL: "Natural" imported - 96 NUM_NAT: "Nat" imported - 97 NUM_INT_CAST: "intCast" - 98 NUM_IS_MULTIPLE_OF: "isMultipleOf" - 99 NUM_AT_DECIMAL: "@Decimal" - 100 NUM_DECIMAL: "Decimal" imported - 101 NUM_DEC: "Dec" imported // the Num.Dectype alias - 102 NUM_BYTES_TO_U16: "bytesToU16" - 103 NUM_BYTES_TO_U32: "bytesToU32" - 104 NUM_CAST_TO_NAT: "#castToNat" - 105 NUM_DIV_CEIL: "divCeil" - 106 NUM_TO_STR: "toStr" - 107 NUM_MIN_I8: "minI8" - 108 NUM_MAX_I8: "maxI8" - 109 NUM_MIN_U8: "minU8" - 110 NUM_MAX_U8: "maxU8" - 111 NUM_MIN_I16: "minI16" - 112 NUM_MAX_I16: "maxI16" - 113 NUM_MIN_U16: "minU16" - 114 NUM_MAX_U16: "maxU16" - 115 NUM_MIN_I32: "minI32" - 116 NUM_MAX_I32: "maxI32" - 117 NUM_MIN_U32: "minU32" - 118 NUM_MAX_U32: "maxU32" - 119 NUM_MIN_I64: "minI64" - 120 NUM_MAX_I64: "maxI64" - 121 NUM_MIN_U64: "minU64" - 122 NUM_MAX_U64: "maxU64" - 123 NUM_MIN_I128: "minI128" - 124 NUM_MAX_I128: "maxI128" - 125 NUM_TO_I8: "toI8" - 126 NUM_TO_I8_CHECKED: "toI8Checked" - 127 NUM_TO_I16: "toI16" - 128 NUM_TO_I16_CHECKED: "toI16Checked" - 129 NUM_TO_I32: "toI32" - 130 NUM_TO_I32_CHECKED: "toI32Checked" - 131 NUM_TO_I64: "toI64" - 132 NUM_TO_I64_CHECKED: "toI64Checked" - 133 NUM_TO_I128: "toI128" - 134 NUM_TO_I128_CHECKED: "toI128Checked" - 135 NUM_TO_U8: "toU8" - 136 NUM_TO_U8_CHECKED: "toU8Checked" - 137 NUM_TO_U16: "toU16" - 138 NUM_TO_U16_CHECKED: "toU16Checked" - 139 NUM_TO_U32: "toU32" - 140 NUM_TO_U32_CHECKED: "toU32Checked" - 141 NUM_TO_U64: "toU64" - 142 NUM_TO_U64_CHECKED: "toU64Checked" - 143 NUM_TO_U128: "toU128" - 144 NUM_TO_U128_CHECKED: "toU128Checked" - 145 NUM_TO_NAT: "toNat" - 146 NUM_TO_NAT_CHECKED: "toNatChecked" + 39 NUM_REM_CHECKED: "remChecked" + 40 NUM_DIV_FLOAT: "div" + 41 NUM_DIV_FLOAT_CHECKED: "divChecked" + 42 NUM_DIV_INT: "divFloor" + 43 NUM_DIV_INT_CHECKED: "divFloorChecked" + 44 NUM_MOD_INT: "modInt" + 45 NUM_MOD_INT_CHECKED: "modIntChecked" + 46 NUM_MOD_FLOAT: "modFloat" + 47 NUM_MOD_FLOAT_CHECKED: "modFloatChecked" + 48 NUM_SQRT: "sqrt" + 49 NUM_SQRT_CHECKED: "sqrtChecked" + 50 NUM_LOG: "log" + 51 NUM_LOG_CHECKED: "logChecked" + 52 NUM_ROUND: "round" + 53 NUM_COMPARE: "compare" + 54 NUM_POW: "pow" + 55 NUM_CEILING: "ceiling" + 56 NUM_POW_INT: "powInt" + 57 NUM_FLOOR: "floor" + 58 NUM_ADD_WRAP: "addWrap" + 59 NUM_ADD_CHECKED: "addChecked" + 60 NUM_ADD_SATURATED: "addSaturated" + 61 NUM_ATAN: "atan" + 62 NUM_ACOS: "acos" + 63 NUM_ASIN: "asin" + 64 NUM_AT_SIGNED128: "@Signed128" + 65 NUM_SIGNED128: "Signed128" imported + 66 NUM_AT_SIGNED64: "@Signed64" + 67 NUM_SIGNED64: "Signed64" imported + 68 NUM_AT_SIGNED32: "@Signed32" + 69 NUM_SIGNED32: "Signed32" imported + 70 NUM_AT_SIGNED16: "@Signed16" + 71 NUM_SIGNED16: "Signed16" imported + 72 NUM_AT_SIGNED8: "@Signed8" + 73 NUM_SIGNED8: "Signed8" imported + 74 NUM_AT_UNSIGNED128: "@Unsigned128" + 75 NUM_UNSIGNED128: "Unsigned128" imported + 76 NUM_AT_UNSIGNED64: "@Unsigned64" + 77 NUM_UNSIGNED64: "Unsigned64" imported + 78 NUM_AT_UNSIGNED32: "@Unsigned32" + 79 NUM_UNSIGNED32: "Unsigned32" imported + 80 NUM_AT_UNSIGNED16: "@Unsigned16" + 81 NUM_UNSIGNED16: "Unsigned16" imported + 82 NUM_AT_UNSIGNED8: "@Unsigned8" + 83 NUM_UNSIGNED8: "Unsigned8" imported + 84 NUM_AT_BINARY64: "@Binary64" + 85 NUM_BINARY64: "Binary64" imported + 86 NUM_AT_BINARY32: "@Binary32" + 87 NUM_BINARY32: "Binary32" imported + 88 NUM_BITWISE_AND: "bitwiseAnd" + 89 NUM_BITWISE_XOR: "bitwiseXor" + 90 NUM_BITWISE_OR: "bitwiseOr" + 91 NUM_SHIFT_LEFT: "shiftLeftBy" + 92 NUM_SHIFT_RIGHT: "shiftRightBy" + 93 NUM_SHIFT_RIGHT_ZERO_FILL: "shiftRightZfBy" + 94 NUM_SUB_WRAP: "subWrap" + 95 NUM_SUB_CHECKED: "subChecked" + 96 NUM_SUB_SATURATED: "subSaturated" + 97 NUM_MUL_WRAP: "mulWrap" + 98 NUM_MUL_CHECKED: "mulChecked" + 99 NUM_INT: "Int" imported + 100 NUM_FLOAT: "Float" imported + 101 NUM_AT_NATURAL: "@Natural" + 102 NUM_NATURAL: "Natural" imported + 103 NUM_NAT: "Nat" imported + 104 NUM_INT_CAST: "intCast" + 105 NUM_IS_MULTIPLE_OF: "isMultipleOf" + 106 NUM_AT_DECIMAL: "@Decimal" + 107 NUM_DECIMAL: "Decimal" imported + 108 NUM_DEC: "Dec" imported // the Num.Dectype alias + 109 NUM_BYTES_TO_U16: "bytesToU16" + 110 NUM_BYTES_TO_U32: "bytesToU32" + 111 NUM_CAST_TO_NAT: "#castToNat" + 112 NUM_DIV_CEIL: "divCeil" + 113 NUM_DIV_CEIL_CHECKED: "divCeilChecked" + 114 NUM_TO_STR: "toStr" + 115 NUM_MIN_I8: "minI8" + 116 NUM_MAX_I8: "maxI8" + 117 NUM_MIN_U8: "minU8" + 118 NUM_MAX_U8: "maxU8" + 119 NUM_MIN_I16: "minI16" + 120 NUM_MAX_I16: "maxI16" + 121 NUM_MIN_U16: "minU16" + 122 NUM_MAX_U16: "maxU16" + 123 NUM_MIN_I32: "minI32" + 124 NUM_MAX_I32: "maxI32" + 125 NUM_MIN_U32: "minU32" + 126 NUM_MAX_U32: "maxU32" + 127 NUM_MIN_I64: "minI64" + 128 NUM_MAX_I64: "maxI64" + 129 NUM_MIN_U64: "minU64" + 130 NUM_MAX_U64: "maxU64" + 131 NUM_MIN_I128: "minI128" + 132 NUM_MAX_I128: "maxI128" + 133 NUM_TO_I8: "toI8" + 134 NUM_TO_I8_CHECKED: "toI8Checked" + 135 NUM_TO_I16: "toI16" + 136 NUM_TO_I16_CHECKED: "toI16Checked" + 137 NUM_TO_I32: "toI32" + 138 NUM_TO_I32_CHECKED: "toI32Checked" + 139 NUM_TO_I64: "toI64" + 140 NUM_TO_I64_CHECKED: "toI64Checked" + 141 NUM_TO_I128: "toI128" + 142 NUM_TO_I128_CHECKED: "toI128Checked" + 143 NUM_TO_U8: "toU8" + 144 NUM_TO_U8_CHECKED: "toU8Checked" + 145 NUM_TO_U16: "toU16" + 146 NUM_TO_U16_CHECKED: "toU16Checked" + 147 NUM_TO_U32: "toU32" + 148 NUM_TO_U32_CHECKED: "toU32Checked" + 149 NUM_TO_U64: "toU64" + 150 NUM_TO_U64_CHECKED: "toU64Checked" + 151 NUM_TO_U128: "toU128" + 152 NUM_TO_U128_CHECKED: "toU128Checked" + 153 NUM_TO_NAT: "toNat" + 154 NUM_TO_NAT_CHECKED: "toNatChecked" } 2 BOOL: "Bool" => { 0 BOOL_BOOL: "Bool" imported // the Bool.Bool type alias diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index 281bf37528..f31cdd5ebc 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -3296,6 +3296,30 @@ mod solve_expr { ); } + #[test] + fn div() { + infer_eq_without_problem( + indoc!( + r#" + Num.div + "# + ), + "Float a, Float a -> Float a" + ) + } + + #[test] + fn div_checked() { + infer_eq_without_problem( + indoc!( + r#" + Num.divChecked + "# + ), + "Float a, Float a -> Result (Float a) [ DivByZero ]*" + ) + } + #[test] fn div_ceil() { infer_eq_without_problem( @@ -3304,22 +3328,46 @@ mod solve_expr { Num.divCeil "# ), - "Int a, Int a -> Result (Int a) [ DivByZero ]*", + "Int a, Int a -> Int a" ); } #[test] - fn pow_int() { + fn div_ceil_checked() { infer_eq_without_problem( indoc!( r#" - Num.powInt + Num.divCeilChecked "# ), "Int a, Int a -> Int a", ); } + #[test] + fn div_floor() { + infer_eq_without_problem( + indoc!( + r#" + Num.divFloor + "# + ), + "Int a, Int a -> Int a" + ); + } + + #[test] + fn div_floor_checked() { + infer_eq_without_problem( + indoc!( + r#" + Num.divFloorChecked + "# + ), + "Int a, Int a -> Result (Int a) [ DivByZer ]*" + ); + } + #[test] fn atan() { infer_eq_without_problem( diff --git a/compiler/test_gen/src/gen_num.rs b/compiler/test_gen/src/gen_num.rs index 870d699f99..b9d6f30e25 100644 --- a/compiler/test_gen/src/gen_num.rs +++ b/compiler/test_gen/src/gen_num.rs @@ -723,6 +723,21 @@ fn gen_wrap_add_nums() { #[test] #[cfg(any(feature = "gen-llvm"))] fn gen_div_f64() { + // FIXME this works with normal types, but fails when checking uniqueness types + assert_evals_to!( + indoc!( + r#" + 48 / 2 + "# + ), + 24.0, + f64 + ); +} + +#[test] +#[cfg(any(feature = "gen-llvm"))] +fn gen_div_checked_f64() { // FIXME this works with normal types, but fails when checking uniqueness types assert_evals_to!( indoc!( @@ -736,6 +751,24 @@ fn gen_div_f64() { f64 ); } + +#[test] +#[cfg(any(feature = "gen-llvm"))] +fn gen_div_checked_by_zero_f64() { + // FIXME this works with normal types, but fails when checking uniqueness types + assert_evals_to!( + indoc!( + r#" + when 48 / 0 is + Ok val -> val + Err _ -> -1 + "# + ), + -1, + f64 + ); +} + #[test] #[cfg(any(feature = "gen-llvm"))] fn gen_div_dec() { @@ -748,7 +781,27 @@ fn gen_div_dec() { y : Dec y = 3 - when x / y is + x / y + "# + ), + RocDec::from_str_to_i128_unsafe("3.333333333333333333"), + i128 + ); +} + +#[test] +#[cfg(any(feature = "gen-llvm"))] +fn gen_div_checked_dec() { + assert_evals_to!( + indoc!( + r#" + x : Dec + x = 10 + + y : Dec + y = 3 + + when Num.divChecked x y is Ok val -> val Err _ -> -1 "# @@ -757,6 +810,27 @@ fn gen_div_dec() { i128 ); } +#[test] +#[cfg(any(feature = "gen-llvm"))] +fn gen_div_checked_by_zero_dec() { + assert_evals_to!( + indoc!( + r#" + x : Dec + x = 10 + + y : Dec + y = 0 + + when Num.divChecked x y is + Ok val -> val + Err _ -> -1 + "# + ), + -1, + i128 + ); +} #[test] #[cfg(any(feature = "gen-llvm", feature = "gen-dev", feature = "gen-wasm"))] @@ -965,7 +1039,21 @@ fn gen_div_i64() { assert_evals_to!( indoc!( r#" - when 1000 // 10 is + 1000 // 10 + "# + ), + 100, + i64 + ); +} + +#[test] +#[cfg(any(feature = "gen-llvm"))] +fn gen_div_checked_i64() { + assert_evals_to!( + indoc!( + r#" + when Num.divFloorChecked 1000 10 is Ok val -> val Err _ -> -1 "# @@ -977,11 +1065,11 @@ fn gen_div_i64() { #[test] #[cfg(any(feature = "gen-llvm"))] -fn gen_div_by_zero_i64() { +fn gen_div_checked_by_zero_i64() { assert_evals_to!( indoc!( r#" - when 1000 // 0 is + when Num.divFloorChecked 1000 0 is Err DivByZero -> 99 _ -> -24 "# From 9182bb5773d41bb2e094cc7c4c30ea4153f3f428 Mon Sep 17 00:00:00 2001 From: Nikita Mounier Date: Mon, 11 Apr 2022 11:35:56 +0000 Subject: [PATCH 147/846] Add toF32/64 checked versions in symbol.rs to avoid conflict. --- compiler/module/src/symbol.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index ea48f28590..f68fb242c4 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -1061,6 +1061,10 @@ define_builtins! { 152 NUM_TO_U128_CHECKED: "toU128Checked" 153 NUM_TO_NAT: "toNat" 154 NUM_TO_NAT_CHECKED: "toNatChecked" + 155 NUM_TO_F32: "toF32" + 156 NUM_TO_F32_CHECKED: "toF32Checked" + 157 NUM_TO_F64: "toF64" + 158 NUM_TO_F64_CHECKED: "toF64Checked" } 2 BOOL: "Bool" => { 0 BOOL_BOOL: "Bool" imported // the Bool.Bool type alias From 1df1b4bc8477f18015c8a524e94377e267de3a02 Mon Sep 17 00:00:00 2001 From: Nikita Mounier Date: Mon, 11 Apr 2022 12:34:23 +0000 Subject: [PATCH 148/846] Fix typo. --- compiler/solve/tests/solve_expr.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index 3e58fdaeb0..0acd1551b2 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -3364,7 +3364,7 @@ mod solve_expr { Num.divFloorChecked "# ), - "Int a, Int a -> Result (Int a) [ DivByZer ]*" + "Int a, Int a -> Result (Int a) [ DivByZero ]*" ); } From 6de8892e882f5acc094b49418503393298407610 Mon Sep 17 00:00:00 2001 From: Brian Carroll Date: Thu, 7 Apr 2022 10:36:44 +0100 Subject: [PATCH 149/846] module: ensure dev backends don't eliminate wrapper functions for higher-order builtins --- compiler/module/src/low_level.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/compiler/module/src/low_level.rs b/compiler/module/src/low_level.rs index 3876411440..dadba6edba 100644 --- a/compiler/module/src/low_level.rs +++ b/compiler/module/src/low_level.rs @@ -243,22 +243,22 @@ impl LowLevelWrapperType { Symbol::LIST_JOIN => CanBeReplacedBy(ListJoin), Symbol::LIST_RANGE => CanBeReplacedBy(ListRange), Symbol::LIST_MAP => WrapperIsRequired, - Symbol::LIST_MAP2 => CanBeReplacedBy(ListMap2), - Symbol::LIST_MAP3 => CanBeReplacedBy(ListMap3), - Symbol::LIST_MAP4 => CanBeReplacedBy(ListMap4), - Symbol::LIST_MAP_WITH_INDEX => CanBeReplacedBy(ListMapWithIndex), - Symbol::LIST_KEEP_IF => CanBeReplacedBy(ListKeepIf), - Symbol::LIST_WALK => CanBeReplacedBy(ListWalk), - Symbol::LIST_WALK_UNTIL => CanBeReplacedBy(ListWalkUntil), - Symbol::LIST_WALK_BACKWARDS => CanBeReplacedBy(ListWalkBackwards), - Symbol::LIST_KEEP_OKS => CanBeReplacedBy(ListKeepOks), - Symbol::LIST_KEEP_ERRS => CanBeReplacedBy(ListKeepErrs), - Symbol::LIST_SORT_WITH => CanBeReplacedBy(ListSortWith), + Symbol::LIST_MAP2 => WrapperIsRequired, + Symbol::LIST_MAP3 => WrapperIsRequired, + Symbol::LIST_MAP4 => WrapperIsRequired, + Symbol::LIST_MAP_WITH_INDEX => WrapperIsRequired, + Symbol::LIST_KEEP_IF => WrapperIsRequired, + Symbol::LIST_WALK => WrapperIsRequired, + Symbol::LIST_WALK_UNTIL => WrapperIsRequired, + Symbol::LIST_WALK_BACKWARDS => WrapperIsRequired, + Symbol::LIST_KEEP_OKS => WrapperIsRequired, + Symbol::LIST_KEEP_ERRS => WrapperIsRequired, + Symbol::LIST_SORT_WITH => WrapperIsRequired, Symbol::LIST_SUBLIST => CanBeReplacedBy(ListSublist), Symbol::LIST_DROP_AT => CanBeReplacedBy(ListDropAt), Symbol::LIST_SWAP => CanBeReplacedBy(ListSwap), - Symbol::LIST_ANY => CanBeReplacedBy(ListAny), - Symbol::LIST_ALL => CanBeReplacedBy(ListAll), + Symbol::LIST_ANY => WrapperIsRequired, + Symbol::LIST_ALL => WrapperIsRequired, Symbol::LIST_FIND => WrapperIsRequired, Symbol::DICT_LEN => CanBeReplacedBy(DictSize), Symbol::DICT_EMPTY => CanBeReplacedBy(DictEmpty), @@ -271,7 +271,7 @@ impl LowLevelWrapperType { Symbol::DICT_UNION => CanBeReplacedBy(DictUnion), Symbol::DICT_INTERSECTION => CanBeReplacedBy(DictIntersection), Symbol::DICT_DIFFERENCE => CanBeReplacedBy(DictDifference), - Symbol::DICT_WALK => CanBeReplacedBy(DictWalk), + Symbol::DICT_WALK => WrapperIsRequired, Symbol::SET_FROM_LIST => CanBeReplacedBy(SetFromList), Symbol::NUM_ADD => CanBeReplacedBy(NumAdd), Symbol::NUM_ADD_WRAP => CanBeReplacedBy(NumAddWrap), From 5cce24bc8fa2a12ccc23de0857cadc86af3f0576 Mon Sep 17 00:00:00 2001 From: Brian Carroll Date: Thu, 7 Apr 2022 11:53:10 +0100 Subject: [PATCH 150/846] wasm: improve debug logging --- compiler/gen_wasm/src/backend.rs | 9 ++++++++- compiler/gen_wasm/src/lib.rs | 2 ++ compiler/gen_wasm/src/wasm_module/code_builder.rs | 12 ++++++------ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/compiler/gen_wasm/src/backend.rs b/compiler/gen_wasm/src/backend.rs index c830876dc3..19b52cef54 100644 --- a/compiler/gen_wasm/src/backend.rs +++ b/compiler/gen_wasm/src/backend.rs @@ -7,7 +7,7 @@ use roc_collections::all::MutMap; use roc_module::ident::Ident; use roc_module::low_level::{LowLevel, LowLevelWrapperType}; use roc_module::symbol::{Interns, Symbol}; -use roc_mono::code_gen_help::{CodeGenHelp, REFCOUNT_MAX}; +use roc_mono::code_gen_help::{CodeGenHelp, HelperOp, REFCOUNT_MAX}; use roc_mono::ir::{ BranchInfo, CallType, Expr, JoinPointId, ListLiteralElement, Literal, ModifyRc, Param, Proc, ProcLayout, Stmt, @@ -270,6 +270,13 @@ impl<'a> WasmBackend<'a> { self.storage.stack_frame_size, self.storage.stack_frame_pointer, ); + + if DEBUG_LOG_SETTINGS.storage_map { + println!("\nStorage:"); + for (sym, storage) in self.storage.symbol_storage_map.iter() { + println!("{:?} => {:?}", sym, storage); + } + } } fn append_proc_debug_name(&mut self, sym: Symbol) { diff --git a/compiler/gen_wasm/src/lib.rs b/compiler/gen_wasm/src/lib.rs index 6689680ac4..7cca526acb 100644 --- a/compiler/gen_wasm/src/lib.rs +++ b/compiler/gen_wasm/src/lib.rs @@ -253,6 +253,7 @@ pub struct WasmDebugLogSettings { helper_procs_ir: bool, let_stmt_ir: bool, instructions: bool, + storage_map: bool, pub keep_test_binary: bool, } @@ -262,5 +263,6 @@ pub const DEBUG_LOG_SETTINGS: WasmDebugLogSettings = WasmDebugLogSettings { helper_procs_ir: false && cfg!(debug_assertions), let_stmt_ir: false && cfg!(debug_assertions), instructions: false && cfg!(debug_assertions), + storage_map: false && cfg!(debug_assertions), keep_test_binary: false && cfg!(debug_assertions), }; diff --git a/compiler/gen_wasm/src/wasm_module/code_builder.rs b/compiler/gen_wasm/src/wasm_module/code_builder.rs index c6d7646a19..30db30702c 100644 --- a/compiler/gen_wasm/src/wasm_module/code_builder.rs +++ b/compiler/gen_wasm/src/wasm_module/code_builder.rs @@ -62,7 +62,7 @@ struct VmBlock<'a> { impl std::fmt::Debug for VmBlock<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_fmt(format_args!("{:?}", self.opcode)) + f.write_fmt(format_args!("{:?} {:?}", self.opcode, self.value_stack)) } } @@ -608,7 +608,7 @@ impl<'a> CodeBuilder<'a> { log_instruction!( "{:10}\t\t{:?}", format!("{:?}", opcode), - self.current_stack() + self.vm_block_stack ); } @@ -635,7 +635,7 @@ impl<'a> CodeBuilder<'a> { "{:10}\t{}\t{:?}", format!("{:?}", opcode), immediate, - self.current_stack() + self.vm_block_stack ); } @@ -648,7 +648,7 @@ impl<'a> CodeBuilder<'a> { format!("{:?}", opcode), align, offset, - self.current_stack() + self.vm_block_stack ); } @@ -752,7 +752,7 @@ impl<'a> CodeBuilder<'a> { "{:10}\t{}\t{:?}", format!("{:?}", CALL), function_index, - self.current_stack() + self.vm_block_stack ); } @@ -823,7 +823,7 @@ impl<'a> CodeBuilder<'a> { "{:10}\t{}\t{:?}", format!("{:?}", opcode), x, - self.current_stack() + self.vm_block_stack ); } pub fn i32_const(&mut self, x: i32) { From 7b96e953ba3d7f381bc874e2cca2532400abff13 Mon Sep 17 00:00:00 2001 From: Brian Carroll Date: Thu, 7 Apr 2022 12:05:53 +0100 Subject: [PATCH 151/846] wasm: Get List.map2 working --- compiler/gen_wasm/src/backend.rs | 10 +-- compiler/gen_wasm/src/low_level.rs | 79 ++++++++++++++++++--- compiler/mono/src/code_gen_help/mod.rs | 8 +-- compiler/mono/src/code_gen_help/refcount.rs | 4 +- compiler/test_gen/src/gen_list.rs | 6 +- 5 files changed, 86 insertions(+), 21 deletions(-) diff --git a/compiler/gen_wasm/src/backend.rs b/compiler/gen_wasm/src/backend.rs index 19b52cef54..0ad99742cb 100644 --- a/compiler/gen_wasm/src/backend.rs +++ b/compiler/gen_wasm/src/backend.rs @@ -1616,8 +1616,9 @@ impl<'a> WasmBackend<'a> { ); } - /// Generate a refcount increment procedure and return its Wasm function index - pub fn gen_refcount_inc_for_zig(&mut self, layout: Layout<'a>) -> u32 { + /// Generate a refcount helper procedure and return a pointer (table index) to it + /// This allows it to be indirectly called from Zig code + pub fn get_refcount_fn_ptr(&mut self, layout: Layout<'a>, op: HelperOp) -> i32 { let ident_ids = self .interns .all_ident_ids @@ -1626,7 +1627,7 @@ impl<'a> WasmBackend<'a> { let (proc_symbol, new_specializations) = self .helper_proc_gen - .gen_refcount_inc_proc(ident_ids, layout); + .gen_refcount_proc(ident_ids, layout, op); // If any new specializations were created, register their symbol data for (spec_sym, spec_layout) in new_specializations.into_iter() { @@ -1639,6 +1640,7 @@ impl<'a> WasmBackend<'a> { .position(|lookup| lookup.name == proc_symbol && lookup.layout.arguments[0] == layout) .unwrap(); - self.fn_index_offset + proc_index as u32 + let wasm_fn_index = self.fn_index_offset + proc_index as u32; + self.get_fn_table_index(wasm_fn_index) } } diff --git a/compiler/gen_wasm/src/low_level.rs b/compiler/gen_wasm/src/low_level.rs index b376f613b5..b396a83adc 100644 --- a/compiler/gen_wasm/src/low_level.rs +++ b/compiler/gen_wasm/src/low_level.rs @@ -3,6 +3,7 @@ use roc_builtins::bitcode::{self, FloatWidth, IntWidth}; use roc_error_macros::internal_error; use roc_module::low_level::LowLevel; use roc_module::symbol::Symbol; +use roc_mono::code_gen_help::HelperOp; use roc_mono::ir::{HigherOrderLowLevel, PassedFunction, ProcLayout}; use roc_mono::layout::{Builtin, Layout, UnionLayout}; use roc_mono::low_level::HigherOrder; @@ -1014,22 +1015,20 @@ pub fn call_higher_order_lowlevel<'a>( }; let wrapper_fn_idx = backend.register_helper_proc(wrapper_sym, wrapper_layout, source); - let inc_fn_idx = backend.gen_refcount_inc_for_zig(closure_data_layout); - let wrapper_fn_ptr = backend.get_fn_table_index(wrapper_fn_idx); - let inc_fn_ptr = backend.get_fn_table_index(inc_fn_idx); + let inc_fn_ptr = backend.get_refcount_fn_ptr(closure_data_layout, HelperOp::Inc); match op { // List.map : List elem_x, (elem_x -> elem_ret) -> List elem_ret ListMap { xs } => { - let list_layout_in = backend.storage.symbol_layouts[xs]; + let list_x = backend.storage.symbol_layouts[xs]; - let (elem_x, elem_ret) = match (list_layout_in, return_layout) { + let (elem_x, elem_ret) = match (list_x, return_layout) { ( Layout::Builtin(Builtin::List(elem_x)), Layout::Builtin(Builtin::List(elem_ret)), ) => (elem_x, elem_ret), - _ => unreachable!("invalid layout for List.map arguments"), + _ => unreachable!("invalid arguments layout for {:?}", op), }; let elem_x_size = elem_x.stack_size(TARGET_INFO); let (elem_ret_size, elem_ret_align) = elem_ret.stack_size_and_alignment(TARGET_INFO); @@ -1039,7 +1038,7 @@ pub fn call_higher_order_lowlevel<'a>( // Load return pointer & argument values // Wasm signature: (i32, i64, i64, i32, i32, i32, i32, i32, i32, i32) -> nil backend.storage.load_symbols(cb, &[return_sym]); - backend.storage.load_symbol_zig(cb, *xs); // list with capacity = 2 x i64 args + backend.storage.load_symbol_zig(cb, *xs); // 2 x i64 cb.i32_const(wrapper_fn_ptr); if closure_data_exists { backend.storage.load_symbols(cb, &[*captured_environment]); @@ -1062,8 +1061,70 @@ pub fn call_higher_order_lowlevel<'a>( ); } - ListMap2 { .. } - | ListMap3 { .. } + ListMap2 { xs, ys } => { + let list_x = backend.storage.symbol_layouts[xs]; + let list_y = backend.storage.symbol_layouts[ys]; + + let (elem_x, elem_y, elem_ret) = match (list_x, list_y, return_layout) { + ( + Layout::Builtin(Builtin::List(x)), + Layout::Builtin(Builtin::List(y)), + Layout::Builtin(Builtin::List(ret)), + ) => (x, y, ret), + _ => unreachable!("invalid arguments layout for {:?}", op), + }; + let elem_x_size = elem_x.stack_size(TARGET_INFO); + let elem_y_size = elem_y.stack_size(TARGET_INFO); + let (elem_ret_size, elem_ret_align) = elem_ret.stack_size_and_alignment(TARGET_INFO); + + let dec_x_fn_ptr = backend.get_refcount_fn_ptr(*elem_x, HelperOp::Dec); + let dec_y_fn_ptr = backend.get_refcount_fn_ptr(*elem_y, HelperOp::Dec); + + let cb = &mut backend.code_builder; + + /* Load Wasm arguments + return ptr: RocList, // i32 + list1: RocList, // i64, i64 + list2: RocList, // i64, i64 + caller: Caller2, // i32 + data: Opaque, // i32 + inc_n_data: IncN, // i32 + data_is_owned: bool, // i32 + alignment: u32, // i32 + a_width: usize, // i32 + b_width: usize, // i32 + c_width: usize, // i32 + dec_a: Dec, // i32 + dec_b: Dec, // i32 + */ + backend.storage.load_symbols(cb, &[return_sym]); + backend.storage.load_symbol_zig(cb, *xs); + backend.storage.load_symbol_zig(cb, *ys); + cb.i32_const(wrapper_fn_ptr); + if closure_data_exists { + backend.storage.load_symbols(cb, &[*captured_environment]); + } else { + cb.i32_const(0); // null pointer + } + cb.i32_const(inc_fn_ptr); + cb.i32_const(*owns_captured_environment as i32); + cb.i32_const(elem_ret_align as i32); + cb.i32_const(elem_x_size as i32); + cb.i32_const(elem_y_size as i32); + cb.i32_const(elem_ret_size as i32); + cb.i32_const(dec_x_fn_ptr); + cb.i32_const(dec_y_fn_ptr); + + let num_wasm_args = 15; + let has_return_val = false; + backend.call_zig_builtin_after_loading_args( + bitcode::LIST_MAP2, + num_wasm_args, + has_return_val, + ); + } + + ListMap3 { .. } | ListMap4 { .. } | ListMapWithIndex { .. } | ListKeepIf { .. } diff --git a/compiler/mono/src/code_gen_help/mod.rs b/compiler/mono/src/code_gen_help/mod.rs index 2ffdd2494d..3244e04fbb 100644 --- a/compiler/mono/src/code_gen_help/mod.rs +++ b/compiler/mono/src/code_gen_help/mod.rs @@ -25,7 +25,7 @@ const ARG_2: Symbol = Symbol::ARG_2; pub const REFCOUNT_MAX: usize = 0; #[derive(Clone, Copy, Debug, PartialEq, Eq)] -enum HelperOp { +pub enum HelperOp { Inc, Dec, DecRef(JoinPointId), @@ -185,16 +185,16 @@ impl<'a> CodeGenHelp<'a> { /// Generate a refcount increment procedure, *without* a Call expression. /// *This method should be rarely used* - only when the proc is to be called from Zig. /// Otherwise you want to generate the Proc and the Call together, using another method. - /// This only supports the 'inc' operation, as it's the only real use case we have. - pub fn gen_refcount_inc_proc( + pub fn gen_refcount_proc( &mut self, ident_ids: &mut IdentIds, layout: Layout<'a>, + op: HelperOp, ) -> (Symbol, Vec<'a, (Symbol, ProcLayout<'a>)>) { let mut ctx = Context { new_linker_data: Vec::new_in(self.arena), recursive_union: None, - op: HelperOp::Inc, + op, }; let proc_name = self.find_or_create_proc(ident_ids, &mut ctx, layout); diff --git a/compiler/mono/src/code_gen_help/refcount.rs b/compiler/mono/src/code_gen_help/refcount.rs index ef46ad8564..176f875d41 100644 --- a/compiler/mono/src/code_gen_help/refcount.rs +++ b/compiler/mono/src/code_gen_help/refcount.rs @@ -107,7 +107,9 @@ pub fn refcount_generic<'a>( match layout { Layout::Builtin(Builtin::Int(_) | Builtin::Float(_) | Builtin::Bool | Builtin::Decimal) => { - unreachable!("Not refcounted: {:?}", layout) + // Generate a dummy function that immediately returns Unit + // Some higher-order Zig builtins *always* call an RC function on List elements. + rc_return_stmt(root, ident_ids, ctx) } Layout::Builtin(Builtin::Str) => refcount_str(root, ident_ids, ctx), Layout::Builtin(Builtin::List(elem_layout)) => { diff --git a/compiler/test_gen/src/gen_list.rs b/compiler/test_gen/src/gen_list.rs index cb46f2de49..92ab071fa2 100644 --- a/compiler/test_gen/src/gen_list.rs +++ b/compiler/test_gen/src/gen_list.rs @@ -1169,7 +1169,7 @@ fn list_map3_different_length() { } #[test] -#[cfg(any(feature = "gen-llvm"))] +#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] fn list_map2_pair() { assert_evals_to!( indoc!( @@ -1184,13 +1184,13 @@ fn list_map2_pair() { } #[test] -#[cfg(any(feature = "gen-llvm"))] +#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] fn list_map2_different_lengths() { assert_evals_to!( indoc!( r#" List.map2 - ["a", "b", "lllllllllllllongnggg" ] + ["a", "b", "lllllllllllllooooooooongnggg" ] ["b"] (\a, b -> Str.concat a b) "# From a7a84019cda2d9ea4285bc232395710d0b1e10c4 Mon Sep 17 00:00:00 2001 From: Brian Carroll Date: Thu, 7 Apr 2022 15:15:53 +0100 Subject: [PATCH 152/846] wasm: Get List.map3 working --- compiler/gen_wasm/src/lib.rs | 2 +- compiler/gen_wasm/src/low_level.rs | 80 ++++++++++++++++++++++++++++-- compiler/test_gen/src/gen_list.rs | 4 +- 3 files changed, 79 insertions(+), 7 deletions(-) diff --git a/compiler/gen_wasm/src/lib.rs b/compiler/gen_wasm/src/lib.rs index 7cca526acb..50f1e81350 100644 --- a/compiler/gen_wasm/src/lib.rs +++ b/compiler/gen_wasm/src/lib.rs @@ -264,5 +264,5 @@ pub const DEBUG_LOG_SETTINGS: WasmDebugLogSettings = WasmDebugLogSettings { let_stmt_ir: false && cfg!(debug_assertions), instructions: false && cfg!(debug_assertions), storage_map: false && cfg!(debug_assertions), - keep_test_binary: false && cfg!(debug_assertions), + keep_test_binary: true && cfg!(debug_assertions), }; diff --git a/compiler/gen_wasm/src/low_level.rs b/compiler/gen_wasm/src/low_level.rs index b396a83adc..281e1d204d 100644 --- a/compiler/gen_wasm/src/low_level.rs +++ b/compiler/gen_wasm/src/low_level.rs @@ -1028,7 +1028,7 @@ pub fn call_higher_order_lowlevel<'a>( Layout::Builtin(Builtin::List(elem_x)), Layout::Builtin(Builtin::List(elem_ret)), ) => (elem_x, elem_ret), - _ => unreachable!("invalid arguments layout for {:?}", op), + _ => internal_error!("invalid arguments layout for {:?}", op), }; let elem_x_size = elem_x.stack_size(TARGET_INFO); let (elem_ret_size, elem_ret_align) = elem_ret.stack_size_and_alignment(TARGET_INFO); @@ -1071,7 +1071,7 @@ pub fn call_higher_order_lowlevel<'a>( Layout::Builtin(Builtin::List(y)), Layout::Builtin(Builtin::List(ret)), ) => (x, y, ret), - _ => unreachable!("invalid arguments layout for {:?}", op), + _ => internal_error!("invalid arguments layout for {:?}", op), }; let elem_x_size = elem_x.stack_size(TARGET_INFO); let elem_y_size = elem_y.stack_size(TARGET_INFO); @@ -1124,8 +1124,80 @@ pub fn call_higher_order_lowlevel<'a>( ); } - ListMap3 { .. } - | ListMap4 { .. } + ListMap3 { xs, ys, zs } => { + let list_x = backend.storage.symbol_layouts[xs]; + let list_y = backend.storage.symbol_layouts[ys]; + let list_z = backend.storage.symbol_layouts[zs]; + + let (elem_x, elem_y, elem_z, elem_ret) = match (list_x, list_y, list_z, return_layout) { + ( + Layout::Builtin(Builtin::List(x)), + Layout::Builtin(Builtin::List(y)), + Layout::Builtin(Builtin::List(z)), + Layout::Builtin(Builtin::List(ret)), + ) => (x, y, z, ret), + e => internal_error!("invalid arguments layout for {:?}\n{:?}", op, e), + }; + let elem_x_size = elem_x.stack_size(TARGET_INFO); + let elem_y_size = elem_y.stack_size(TARGET_INFO); + let elem_z_size = elem_y.stack_size(TARGET_INFO); + let (elem_ret_size, elem_ret_align) = elem_ret.stack_size_and_alignment(TARGET_INFO); + + let dec_x_fn_ptr = backend.get_refcount_fn_ptr(*elem_x, HelperOp::Dec); + let dec_y_fn_ptr = backend.get_refcount_fn_ptr(*elem_y, HelperOp::Dec); + let dec_z_fn_ptr = backend.get_refcount_fn_ptr(*elem_z, HelperOp::Dec); + + let cb = &mut backend.code_builder; + + /* Load Wasm arguments + return ptr i32 + list1: RocList, i64, i64 + list2: RocList, i64, i64 + list3: RocList, i64, i64 + caller: Caller3, i32 + data: Opaque, i32 + inc_n_data: IncN, i32 + data_is_owned: bool, i32 + alignment: u32, i32 + a_width: usize, i32 + b_width: usize, i32 + c_width: usize, i32 + d_width: usize, i32 + dec_a: Dec, i32 + dec_b: Dec, i32 + dec_c: Dec, i32 + */ + backend.storage.load_symbols(cb, &[return_sym]); + backend.storage.load_symbol_zig(cb, *xs); + backend.storage.load_symbol_zig(cb, *ys); + backend.storage.load_symbol_zig(cb, *zs); + cb.i32_const(wrapper_fn_ptr); + if closure_data_exists { + backend.storage.load_symbols(cb, &[*captured_environment]); + } else { + cb.i32_const(0); // null pointer + } + cb.i32_const(inc_fn_ptr); + cb.i32_const(*owns_captured_environment as i32); + cb.i32_const(elem_ret_align as i32); + cb.i32_const(elem_x_size as i32); + cb.i32_const(elem_y_size as i32); + cb.i32_const(elem_z_size as i32); + cb.i32_const(elem_ret_size as i32); + cb.i32_const(dec_x_fn_ptr); + cb.i32_const(dec_y_fn_ptr); + cb.i32_const(dec_z_fn_ptr); + + let num_wasm_args = 19; + let has_return_val = false; + backend.call_zig_builtin_after_loading_args( + bitcode::LIST_MAP3, + num_wasm_args, + has_return_val, + ); + } + + ListMap4 { .. } | ListMapWithIndex { .. } | ListKeepIf { .. } | ListWalk { .. } diff --git a/compiler/test_gen/src/gen_list.rs b/compiler/test_gen/src/gen_list.rs index 92ab071fa2..74ad1281b2 100644 --- a/compiler/test_gen/src/gen_list.rs +++ b/compiler/test_gen/src/gen_list.rs @@ -1137,7 +1137,7 @@ fn list_map4_different_length() { } #[test] -#[cfg(any(feature = "gen-llvm"))] +#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] fn list_map3_group() { assert_evals_to!( indoc!( @@ -1151,7 +1151,7 @@ fn list_map3_group() { } #[test] -#[cfg(any(feature = "gen-llvm"))] +#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] fn list_map3_different_length() { assert_evals_to!( indoc!( From d81228df8059ea34c4fb4a39369779f11eeba96d Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 11 Apr 2022 13:17:46 -0400 Subject: [PATCH 153/846] cargo fmt --- compiler/builtins/src/std.rs | 2 +- compiler/solve/tests/solve_expr.rs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/compiler/builtins/src/std.rs b/compiler/builtins/src/std.rs index 322607b7a1..dabc694835 100644 --- a/compiler/builtins/src/std.rs +++ b/compiler/builtins/src/std.rs @@ -675,7 +675,7 @@ pub fn types() -> MutMap { vec![float_type(flex(TVAR1)), float_type(flex(TVAR1))], Box::new(float_type(flex(TVAR1))) ); - + // divChecked : Float a, Float a -> Result (Float a) [ DivByZero ]* add_top_level_function_type!( Symbol::NUM_DIV_FLOAT_CHECKED, diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index 0acd1551b2..7250fb4d80 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -3304,7 +3304,7 @@ mod solve_expr { Num.div "# ), - "Float a, Float a -> Float a" + "Float a, Float a -> Float a", ) } @@ -3316,7 +3316,7 @@ mod solve_expr { Num.divChecked "# ), - "Float a, Float a -> Result (Float a) [ DivByZero ]*" + "Float a, Float a -> Result (Float a) [ DivByZero ]*", ) } @@ -3328,7 +3328,7 @@ mod solve_expr { Num.divCeil "# ), - "Int a, Int a -> Int a" + "Int a, Int a -> Int a", ); } @@ -3352,7 +3352,7 @@ mod solve_expr { Num.divFloor "# ), - "Int a, Int a -> Int a" + "Int a, Int a -> Int a", ); } @@ -3364,7 +3364,7 @@ mod solve_expr { Num.divFloorChecked "# ), - "Int a, Int a -> Result (Int a) [ DivByZero ]*" + "Int a, Int a -> Result (Int a) [ DivByZero ]*", ); } From 1d5ab1d79c0dd4d8dc7c6a863a9f9334048175fb Mon Sep 17 00:00:00 2001 From: Nikita Mounier Date: Mon, 11 Apr 2022 17:51:38 +0000 Subject: [PATCH 154/846] Merge remote-tracking branch 'origin/trunk' into div-no-result --- compiler/test_gen/src/gen_num.rs | 38 ++++---------------------------- 1 file changed, 4 insertions(+), 34 deletions(-) diff --git a/compiler/test_gen/src/gen_num.rs b/compiler/test_gen/src/gen_num.rs index 445751893f..a975cceee8 100644 --- a/compiler/test_gen/src/gen_num.rs +++ b/compiler/test_gen/src/gen_num.rs @@ -742,7 +742,7 @@ fn gen_div_checked_f64() { assert_evals_to!( indoc!( r#" - when 48 / 2 is + when Num.divChecked 48 2 is Ok val -> val Err _ -> -1 "# @@ -759,7 +759,7 @@ fn gen_div_checked_by_zero_f64() { assert_evals_to!( indoc!( r#" - when 48 / 0 is + when Num.divChecked 48 0 is Ok val -> val Err _ -> -1 "# @@ -2248,7 +2248,7 @@ fn max_u8() { ); } -macro_rules! num_conversion_tests { +macro_rules! to_int_tests { ($($fn:expr, $typ:ty, ($($test_name:ident, $input:expr, $output:expr $(, [ $($support_gen:literal),* ])? )*))*) => {$($( #[test] #[cfg(any(feature = "gen-llvm", $($(feature = $support_gen)*)?))] @@ -2259,7 +2259,7 @@ macro_rules! num_conversion_tests { )*)*} } -num_conversion_tests! { +to_int_tests! { "Num.toI8", i8, ( to_i8_same_width, "15u8", 15, ["gen-wasm"] to_i8_truncate, "115i32", 115, ["gen-wasm"] @@ -2320,36 +2320,6 @@ num_conversion_tests! { to_nat_truncate, "115i128", 115 to_nat_truncate_wraps, "10_000_000_000_000_000_000_000i128", 1864712049423024128 ) - "Num.toF32", f32, ( - to_f32_from_i8, "15i8", 15.0 - to_f32_from_i16, "15i16", 15.0 - to_f32_from_i32, "15i32", 15.0 - to_f32_from_i64, "15i64", 15.0 - to_f32_from_i128, "15i128", 15.0 - to_f32_from_u8, "15u8", 15.0 - to_f32_from_u16, "15u16", 15.0 - to_f32_from_u32, "15u32", 15.0 - to_f32_from_u64, "15u64", 15.0 - to_f32_from_u128, "15u128", 15.0 - to_f32_from_nat, "15nat", 15.0 - to_f32_from_f32, "1.5f32", 1.5 - to_f32_from_f64, "1.5f64", 1.5 - ) - "Num.toF64", f64, ( - to_f64_from_i8, "15i8", 15.0 - to_f64_from_i16, "15i16", 15.0 - to_f64_from_i32, "15i32", 15.0 - to_f64_from_i64, "15i64", 15.0 - to_f64_from_i128, "15i128", 15.0 - to_f64_from_u8, "15u8", 15.0 - to_f64_from_u16, "15u16", 15.0 - to_f64_from_u32, "15u32", 15.0 - to_f64_from_u64, "15u64", 15.0 - to_f64_from_u128, "15u128", 15.0 - to_f64_from_nat, "15nat", 15.0 - to_f64_from_f32, "1.5f32", 1.5 - to_f64_from_f64, "1.5f64", 1.5 - ) } macro_rules! to_int_checked_tests { From 799c05f183ddd80dee1d8355925e0f8433a89af1 Mon Sep 17 00:00:00 2001 From: Nikita Mounier Date: Mon, 11 Apr 2022 17:56:43 +0000 Subject: [PATCH 155/846] Fix test. --- compiler/test_gen/src/gen_num.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/test_gen/src/gen_num.rs b/compiler/test_gen/src/gen_num.rs index a975cceee8..6fafd43fb9 100644 --- a/compiler/test_gen/src/gen_num.rs +++ b/compiler/test_gen/src/gen_num.rs @@ -759,7 +759,7 @@ fn gen_div_checked_by_zero_f64() { assert_evals_to!( indoc!( r#" - when Num.divChecked 48 0 is + when Num.divChecked 47 0 is Ok val -> val Err _ -> -1 "# From 20b9f6377c5b2d63bb6cbe775080197268e54fbf Mon Sep 17 00:00:00 2001 From: Nikita Mounier Date: Mon, 11 Apr 2022 19:43:21 +0000 Subject: [PATCH 156/846] Fix f64 ambiguity in test. --- compiler/test_gen/src/gen_num.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/test_gen/src/gen_num.rs b/compiler/test_gen/src/gen_num.rs index 6fafd43fb9..a46b8d01c0 100644 --- a/compiler/test_gen/src/gen_num.rs +++ b/compiler/test_gen/src/gen_num.rs @@ -764,7 +764,7 @@ fn gen_div_checked_by_zero_f64() { Err _ -> -1 "# ), - -1, + -1.0, f64 ); } From 6c78a971894dc5580e617fd88123514d62d8ab17 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 11 Apr 2022 16:18:17 -0400 Subject: [PATCH 157/846] Revert "Reproduce identifier interning bug" This reverts commit 7deb8dda935e2cf7db6d298ae8b30711065277ab. --- compiler/can/src/module.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index 97372be1f0..c0b01b8888 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -190,8 +190,6 @@ pub fn canonicalize_module_defs<'a>( // Here we essentially add those "defs" to "the beginning of the module" // by canonicalizing them right before we canonicalize the actual ast::Def nodes. for (ident, (symbol, region)) in exposed_imports { - dbg!((&ident, symbol)); - let first_char = ident.as_inline_str().as_str().chars().next().unwrap(); if first_char.is_lowercase() { From cd3f084c60d4be0def4b37117e36e21b58a4d4de Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 11 Apr 2022 16:18:27 -0400 Subject: [PATCH 158/846] Fix missing `provides` in breakout.roc --- examples/breakout/breakout.roc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index 7fde7ed7ce..682c5b1c4d 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -1,13 +1,15 @@ app "breakout" packages { pf: "platform" } imports []# [ pf.Action.{ Action }, pf.Elem.{ button, text, row, col } ] - provides [ program ] to pf + provides [ program ] { Model } to pf + +Model : { height : F32, width : F32 } program = { init, update, render } init = \_ -> { width: 1900, height: 1000 } -update = \state -> +update = \state, event -> when event is Resize size -> size KeyUp keyCode -> { width: 1900, height: 1000 } From dbb91639e92398b21080abfa6ad6846eed602978 Mon Sep 17 00:00:00 2001 From: Nikita Mounier Date: Mon, 11 Apr 2022 21:33:22 +0000 Subject: [PATCH 159/846] Revert weird changes in tests. --- compiler/test_gen/src/gen_num.rs | 34 ++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/compiler/test_gen/src/gen_num.rs b/compiler/test_gen/src/gen_num.rs index a46b8d01c0..f82b96ba36 100644 --- a/compiler/test_gen/src/gen_num.rs +++ b/compiler/test_gen/src/gen_num.rs @@ -2248,7 +2248,7 @@ fn max_u8() { ); } -macro_rules! to_int_tests { +macro_rules! num_conversion_tests { ($($fn:expr, $typ:ty, ($($test_name:ident, $input:expr, $output:expr $(, [ $($support_gen:literal),* ])? )*))*) => {$($( #[test] #[cfg(any(feature = "gen-llvm", $($(feature = $support_gen)*)?))] @@ -2259,7 +2259,7 @@ macro_rules! to_int_tests { )*)*} } -to_int_tests! { +num_conversion_tests! { "Num.toI8", i8, ( to_i8_same_width, "15u8", 15, ["gen-wasm"] to_i8_truncate, "115i32", 115, ["gen-wasm"] @@ -2320,6 +2320,36 @@ to_int_tests! { to_nat_truncate, "115i128", 115 to_nat_truncate_wraps, "10_000_000_000_000_000_000_000i128", 1864712049423024128 ) + "Num.toF32", f32, ( + to_f32_from_i8, "15i8", 15.0 + to_f32_from_i16, "15i16", 15.0 + to_f32_from_i32, "15i32", 15.0 + to_f32_from_i64, "15i64", 15.0 + to_f32_from_i128, "15i128", 15.0 + to_f32_from_u8, "15u8", 15.0 + to_f32_from_u16, "15u16", 15.0 + to_f32_from_u32, "15u32", 15.0 + to_f32_from_u64, "15u64", 15.0 + to_f32_from_u128, "15u128", 15.0 + to_f32_from_nat, "15nat", 15.0 + to_f32_from_f32, "1.5f32", 1.5 + to_f32_from_f64, "1.5f64", 1.5 + ) + "Num.toF64", f64, ( + to_f64_from_i8, "15i8", 15.0 + to_f64_from_i16, "15i16", 15.0 + to_f64_from_i32, "15i32", 15.0 + to_f64_from_i64, "15i64", 15.0 + to_f64_from_i128, "15i128", 15.0 + to_f64_from_u8, "15u8", 15.0 + to_f64_from_u16, "15u16", 15.0 + to_f64_from_u32, "15u32", 15.0 + to_f64_from_u64, "15u64", 15.0 + to_f64_from_u128, "15u128", 15.0 + to_f64_from_nat, "15nat", 15.0 + to_f64_from_f32, "1.5f32", 1.5 + to_f64_from_f64, "1.5f64", 1.5 + ) } macro_rules! to_int_checked_tests { From 82a01c876e15dcb354a9eb5fecb96e4e4da35bcf Mon Sep 17 00:00:00 2001 From: Nikita Mounier Date: Mon, 11 Apr 2022 23:28:50 +0000 Subject: [PATCH 160/846] Update REPL tests --- repl_test/src/tests.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/repl_test/src/tests.rs b/repl_test/src/tests.rs index 84df9024ee..b88e6ba1bc 100644 --- a/repl_test/src/tests.rs +++ b/repl_test/src/tests.rs @@ -61,23 +61,35 @@ fn num_rem() { #[cfg(not(feature = "wasm"))] #[test] -fn num_floor_division_success() { - expect_success("Num.divFloor 4 3", "Ok 1 : Result (Int *) [ DivByZero ]*"); +fn num_floor_division() { + expect_success("Num.divFloor 4 3", "1 : Int *"); } #[cfg(not(feature = "wasm"))] #[test] -fn num_floor_division_divby_zero() { +fn num_floor_checked_division_success() { + expect_success("Num.divFloorChecked 4 3", "Ok 1 : Result (Int *) [ DivByZero ]*"); +} + +#[cfg(not(feature = "wasm"))] +#[test] +fn num_floor_checked_division_divby_zero() { expect_success( - "Num.divFloor 4 0", + "Num.divFloorChecked 4 0", "Err DivByZero : Result (Int *) [ DivByZero ]*", ); } #[cfg(not(feature = "wasm"))] #[test] -fn num_ceil_division_success() { - expect_success("Num.divCeil 4 3", "Ok 2 : Result (Int *) [ DivByZero ]*") +fn num_ceil_division() { + expect_success("Num.divCeil 4 3", "2 : Int *") +} + +#[cfg(not(feature = "wasm"))] +#[test] +fn num_ceil_checked_division_success() { + expect_success("Num.divCeilChecked 4 3", "Ok 2 : Result (Int *) [ DivByZero ]*") } #[test] From e2cccbc7b517a2937344606b15662b5e33e910cb Mon Sep 17 00:00:00 2001 From: Nikita Mounier Date: Mon, 11 Apr 2022 23:32:34 +0000 Subject: [PATCH 161/846] Format previous change. --- repl_test/src/tests.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/repl_test/src/tests.rs b/repl_test/src/tests.rs index b88e6ba1bc..0e54fec311 100644 --- a/repl_test/src/tests.rs +++ b/repl_test/src/tests.rs @@ -68,7 +68,10 @@ fn num_floor_division() { #[cfg(not(feature = "wasm"))] #[test] fn num_floor_checked_division_success() { - expect_success("Num.divFloorChecked 4 3", "Ok 1 : Result (Int *) [ DivByZero ]*"); + expect_success( + "Num.divFloorChecked 4 3", + "Ok 1 : Result (Int *) [ DivByZero ]*", + ); } #[cfg(not(feature = "wasm"))] @@ -89,7 +92,10 @@ fn num_ceil_division() { #[cfg(not(feature = "wasm"))] #[test] fn num_ceil_checked_division_success() { - expect_success("Num.divCeilChecked 4 3", "Ok 2 : Result (Int *) [ DivByZero ]*") + expect_success( + "Num.divCeilChecked 4 3", + "Ok 2 : Result (Int *) [ DivByZero ]*", + ) } #[test] From 6b2d1a7af67ea434c34da9ed437335f0b261d72f Mon Sep 17 00:00:00 2001 From: Nikita Mounier Date: Mon, 11 Apr 2022 23:36:30 +0000 Subject: [PATCH 162/846] Remove outdated comments. --- compiler/test_gen/src/gen_num.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/compiler/test_gen/src/gen_num.rs b/compiler/test_gen/src/gen_num.rs index f82b96ba36..0b72191ca9 100644 --- a/compiler/test_gen/src/gen_num.rs +++ b/compiler/test_gen/src/gen_num.rs @@ -723,7 +723,6 @@ fn gen_wrap_add_nums() { #[test] #[cfg(any(feature = "gen-llvm"))] fn gen_div_f64() { - // FIXME this works with normal types, but fails when checking uniqueness types assert_evals_to!( indoc!( r#" @@ -738,7 +737,6 @@ fn gen_div_f64() { #[test] #[cfg(any(feature = "gen-llvm"))] fn gen_div_checked_f64() { - // FIXME this works with normal types, but fails when checking uniqueness types assert_evals_to!( indoc!( r#" @@ -755,7 +753,6 @@ fn gen_div_checked_f64() { #[test] #[cfg(any(feature = "gen-llvm"))] fn gen_div_checked_by_zero_f64() { - // FIXME this works with normal types, but fails when checking uniqueness types assert_evals_to!( indoc!( r#" From bb8b8fd0c09bc36558c64bd82ecfb860e6c8a5e8 Mon Sep 17 00:00:00 2001 From: Nikita Mounier Date: Tue, 12 Apr 2022 00:07:53 +0000 Subject: [PATCH 163/846] Update examples / benchmarks. --- examples/benchmarks/Deriv.roc | 2 +- examples/false-interpreter/False.roc | 2 +- examples/gui/Hello.roc | 4 +--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/examples/benchmarks/Deriv.roc b/examples/benchmarks/Deriv.roc index 2cad781765..1b1458e915 100644 --- a/examples/benchmarks/Deriv.roc +++ b/examples/benchmarks/Deriv.roc @@ -42,7 +42,7 @@ Expr : [ Val I64, Var Str, Add Expr Expr, Mul Expr Expr, Pow Expr Expr, Ln Expr divmod : I64, I64 -> Result { div : I64, mod : I64 } [ DivByZero ]* divmod = \l, r -> when Pair (l // r) (l % r) is - Pair (Ok div) (Ok mod) -> + Pair (div) (Ok mod) -> Ok { div, mod } _ -> diff --git a/examples/false-interpreter/False.roc b/examples/false-interpreter/False.roc index d7e0ac0c4f..f8306e7d8d 100644 --- a/examples/false-interpreter/False.roc +++ b/examples/false-interpreter/False.roc @@ -434,7 +434,7 @@ stepExecCtx = \ctx, char -> ( (T popCtx1 numR) <- Result.after (popNumber ctx) (T popCtx2 numL) <- Result.after (popNumber popCtx1) - res <- Result.after (Num.divFloor numL numR) + res <- Result.after (Num.divFloorChecked numL numR) Ok (Context.pushStack popCtx2 (Number res)) ) diff --git a/examples/gui/Hello.roc b/examples/gui/Hello.roc index c15f5bd21a..653ccbd8e1 100644 --- a/examples/gui/Hello.roc +++ b/examples/gui/Hello.roc @@ -4,9 +4,7 @@ app "hello-gui" provides [ render ] to pf render = - div0 = \numerator, denominator -> (numerator / denominator) |> Result.withDefault 0 - - rgba = \r, g, b, a -> { r: div0 r 255, g: div0 g 255, b: div0 b 255, a } + rgba = \r, g, b, a -> { r: r / 255, g: g / 255, b: b / 255, a } styles = { bgColor: rgba 100 50 50 1, borderColor: rgba 10 20 30 1, borderWidth: 10, textColor: rgba 220 220 250 1 } From d32e77819bcd37c86bef3362aa3ff468ee022168 Mon Sep 17 00:00:00 2001 From: Nikita Mounier Date: Tue, 12 Apr 2022 00:19:09 +0000 Subject: [PATCH 164/846] Update benchmark. --- examples/benchmarks/RBTreeDel.roc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/benchmarks/RBTreeDel.roc b/examples/benchmarks/RBTreeDel.roc index 24419ef84a..43fd309e5d 100644 --- a/examples/benchmarks/RBTreeDel.roc +++ b/examples/benchmarks/RBTreeDel.roc @@ -47,7 +47,7 @@ makeMapHelp = \total, n, m -> isFrequency = n |> Num.isMultipleOf 4 - key = n1 + ((total - n1) // 5 |> resultWithDefault 0) + key = n1 + ((total - n1) // 5) t2 = if isFrequency then delete t1 key else t1 makeMapHelp total n1 t2 From 2ba9566c03cdb1e486626143fbe0897d208561c8 Mon Sep 17 00:00:00 2001 From: Nikita Mounier Date: Tue, 12 Apr 2022 00:41:14 +0000 Subject: [PATCH 165/846] Remove parenthesis from Pair --- examples/benchmarks/Deriv.roc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/benchmarks/Deriv.roc b/examples/benchmarks/Deriv.roc index 1b1458e915..caf08906a6 100644 --- a/examples/benchmarks/Deriv.roc +++ b/examples/benchmarks/Deriv.roc @@ -42,7 +42,7 @@ Expr : [ Val I64, Var Str, Add Expr Expr, Mul Expr Expr, Pow Expr Expr, Ln Expr divmod : I64, I64 -> Result { div : I64, mod : I64 } [ DivByZero ]* divmod = \l, r -> when Pair (l // r) (l % r) is - Pair (div) (Ok mod) -> + Pair div (Ok mod) -> Ok { div, mod } _ -> From 1c3700e22e5980dd47ef8adeaaa87bd0f6291733 Mon Sep 17 00:00:00 2001 From: Kevin Gillette Date: Mon, 11 Apr 2022 19:11:37 -0600 Subject: [PATCH 166/846] Minor typo/formatting fixes --- BUILDING_FROM_SOURCE.md | 2 +- compiler/builtins/README.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/BUILDING_FROM_SOURCE.md b/BUILDING_FROM_SOURCE.md index bb1e70733c..4182939e77 100644 --- a/BUILDING_FROM_SOURCE.md +++ b/BUILDING_FROM_SOURCE.md @@ -109,7 +109,7 @@ Alternatively, you can use `cargo test --no-fail-fast` or `cargo test -p specifi For debugging LLVM IR, we use [DebugIR](https://github.com/vaivaswatha/debugir). This dependency is only required to build with the `--debug` flag, and for normal developtment you should be fine without it. -### libcxb libraries +### libxcb libraries You may see an error like this during builds: diff --git a/compiler/builtins/README.md b/compiler/builtins/README.md index ceaf3007e3..2ab95cd260 100644 --- a/compiler/builtins/README.md +++ b/compiler/builtins/README.md @@ -60,7 +60,7 @@ Its one thing to actually write these functions, its _another_ thing to let the ## Specifying how we pass args to the function ### builtins/mono/src/borrow.rs -After we have all of this, we need to specify if the arguments we're passing are owned, borrowed or irrelevant. Towards the bottom of this file, add a new case for you builtin and specify each arg. Be sure to read the comment, as it explains this in more detail. +After we have all of this, we need to specify if the arguments we're passing are owned, borrowed or irrelevant. Towards the bottom of this file, add a new case for your builtin and specify each arg. Be sure to read the comment, as it explains this in more detail. ## Testing it ### solve/tests/solve_expr.rs @@ -87,7 +87,7 @@ In this directory, there are a couple files like `gen_num.rs`, `gen_str.rs`, etc fn atan() { assert_evals_to!("Num.atan 10", 1.4711276743037347, f64); } - ``` +``` But replace `Num.atan`, the return value, and the return type with your new builtin. # Mistakes that are easy to make!! From 895ba92239b158224f2b9f4521e61b22466a3605 Mon Sep 17 00:00:00 2001 From: Nikita Mounier Date: Tue, 12 Apr 2022 01:21:24 +0000 Subject: [PATCH 167/846] Change expected types in test_load. --- compiler/load_internal/tests/test_load.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/load_internal/tests/test_load.rs b/compiler/load_internal/tests/test_load.rs index f78802553c..d97db1c0c6 100644 --- a/compiler/load_internal/tests/test_load.rs +++ b/compiler/load_internal/tests/test_load.rs @@ -426,12 +426,12 @@ mod test_load { loaded_module, hashmap! { "floatTest" => "Float *", - "divisionFn" => "Float a, Float a -> Result (Float a) [ DivByZero ]*", - "divisionTest" => "Result (Float *) [ DivByZero ]*", + "divisionFn" => "Float a, Float a -> Float a", + "divisionTest" => "Float a", "intTest" => "I64", "x" => "Float *", "constantNum" => "Num *", - "divDep1ByDep2" => "Result (Float *) [ DivByZero ]*", + "divDep1ByDep2" => "Float *", "fromDep2" => "Float *", }, ); From 2a56463b74039c02eddd37c2dfd40b23d284154d Mon Sep 17 00:00:00 2001 From: Nikita Mounier Date: Tue, 12 Apr 2022 01:23:49 +0000 Subject: [PATCH 168/846] Fix typo in test_load. --- compiler/load_internal/tests/test_load.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/load_internal/tests/test_load.rs b/compiler/load_internal/tests/test_load.rs index d97db1c0c6..8f0223d483 100644 --- a/compiler/load_internal/tests/test_load.rs +++ b/compiler/load_internal/tests/test_load.rs @@ -427,7 +427,7 @@ mod test_load { hashmap! { "floatTest" => "Float *", "divisionFn" => "Float a, Float a -> Float a", - "divisionTest" => "Float a", + "divisionTest" => "Float *", "intTest" => "I64", "x" => "Float *", "constantNum" => "Num *", From 0f0e9bdf14acaeee444e3dec8ed8763fe462d2ae Mon Sep 17 00:00:00 2001 From: Nikita Mounier Date: Tue, 12 Apr 2022 12:12:29 +0000 Subject: [PATCH 169/846] Fix test in solve_expr.rs --- compiler/solve/tests/solve_expr.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index 7250fb4d80..7e3e2e8215 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -3340,7 +3340,7 @@ mod solve_expr { Num.divCeilChecked "# ), - "Int a, Int a -> Int a", + "Int a, Int a -> Result (Int a) [ DivByZero ]*", ); } From dfba77bd0419036d47825fe99d43dda9611d883d Mon Sep 17 00:00:00 2001 From: Nikita Mounier Date: Tue, 12 Apr 2022 16:41:29 +0000 Subject: [PATCH 170/846] Explicit i128 in test. --- compiler/test_gen/src/gen_num.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/test_gen/src/gen_num.rs b/compiler/test_gen/src/gen_num.rs index 0b72191ca9..88480c6310 100644 --- a/compiler/test_gen/src/gen_num.rs +++ b/compiler/test_gen/src/gen_num.rs @@ -824,7 +824,7 @@ fn gen_div_checked_by_zero_dec() { Err _ -> -1 "# ), - -1, + RocDec::from_str_to_i128_unsafe("-1"), i128 ); } From c035900d64b8f579210d442d391d04c66bcfc468 Mon Sep 17 00:00:00 2001 From: Nikita Mounier Date: Tue, 12 Apr 2022 18:15:19 +0000 Subject: [PATCH 171/846] Update test_mono test. --- compiler/test_mono/src/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/test_mono/src/tests.rs b/compiler/test_mono/src/tests.rs index ff9b7bfcaa..777a790d52 100644 --- a/compiler/test_mono/src/tests.rs +++ b/compiler/test_mono/src/tests.rs @@ -274,7 +274,7 @@ fn ir_round() { #[mono_test] fn ir_when_idiv() { r#" - when 1000 // 10 is + when Num.divFloorChecked 1000 10 is Ok val -> val Err _ -> -1 "# From 7536d48a2295f3bda0d4d09d72ba507e7ed16f03 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Mon, 11 Apr 2022 16:12:01 -0400 Subject: [PATCH 172/846] Remove unused function --- compiler/can/src/annotation.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index c8af0d3e0a..52e4f34103 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -98,13 +98,6 @@ impl IntroducedVariables { .map(|nv| &nv.variable) } - pub fn name_by_var(&self, var: Variable) -> Option<&Lowercase> { - self.named - .iter() - .find(|nv| nv.variable == var) - .map(|nv| &nv.name) - } - pub fn named_var_by_name(&self, name: &Lowercase) -> Option<&NamedVariable> { self.named.iter().find(|nv| &nv.name == name) } From 913d97cab117392d92fd070e75eae79a7395abb8 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 12 Apr 2022 15:36:36 -0400 Subject: [PATCH 173/846] Add needed imports --- Cargo.lock | 6 ++++++ compiler/load/Cargo.toml | 2 ++ compiler/solve/Cargo.toml | 2 ++ compiler/unify/Cargo.toml | 3 +++ reporting/Cargo.toml | 2 ++ 5 files changed, 15 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 27c0e7bf0f..dc9e364812 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3703,6 +3703,7 @@ dependencies = [ "roc_constrain", "roc_load_internal", "roc_module", + "roc_reporting", "roc_target", "roc_types", ] @@ -3893,6 +3894,7 @@ dependencies = [ "roc_collections", "roc_constrain", "roc_exhaustive", + "roc_load", "roc_module", "roc_mono", "roc_parse", @@ -3902,6 +3904,7 @@ dependencies = [ "roc_target", "roc_test_utils", "roc_types", + "tempfile", "ven_pretty", ] @@ -3916,11 +3919,13 @@ dependencies = [ "roc_builtins", "roc_can", "roc_collections", + "roc_error_macros", "roc_load", "roc_module", "roc_parse", "roc_problem", "roc_region", + "roc_reporting", "roc_solve", "roc_target", "roc_types", @@ -3968,6 +3973,7 @@ version = "0.1.0" dependencies = [ "bitflags", "roc_collections", + "roc_error_macros", "roc_module", "roc_types", ] diff --git a/compiler/load/Cargo.toml b/compiler/load/Cargo.toml index 4f7632fb60..f3d1d4c30f 100644 --- a/compiler/load/Cargo.toml +++ b/compiler/load/Cargo.toml @@ -13,10 +13,12 @@ roc_constrain= { path = "../constrain" } roc_types = { path = "../types" } roc_module = { path = "../module" } roc_collections = { path = "../collections" } +roc_reporting = { path = "../../reporting" } [build-dependencies] roc_load_internal = { path = "../load_internal" } roc_builtins = { path = "../builtins" } roc_module = { path = "../module" } +roc_reporting = { path = "../../reporting" } roc_target = { path = "../roc_target" } bumpalo = { version = "3.8.0", features = ["collections"] } diff --git a/compiler/solve/Cargo.toml b/compiler/solve/Cargo.toml index ebb9e4a615..b78faa8421 100644 --- a/compiler/solve/Cargo.toml +++ b/compiler/solve/Cargo.toml @@ -7,6 +7,7 @@ edition = "2018" [dependencies] roc_collections = { path = "../collections" } +roc_error_macros = { path = "../../error_macros" } roc_region = { path = "../region" } roc_module = { path = "../module" } roc_types = { path = "../types" } @@ -22,6 +23,7 @@ roc_problem = { path = "../problem" } roc_parse = { path = "../parse" } roc_solve = { path = "../solve" } roc_target = { path = "../roc_target" } +roc_reporting = { path = "../../reporting" } pretty_assertions = "1.0.0" indoc = "1.0.3" tempfile = "3.2.0" diff --git a/compiler/unify/Cargo.toml b/compiler/unify/Cargo.toml index e15626603c..d8622ed928 100644 --- a/compiler/unify/Cargo.toml +++ b/compiler/unify/Cargo.toml @@ -11,6 +11,9 @@ bitflags = "1.3.2" [dependencies.roc_collections] path = "../collections" +[dependencies.roc_error_macros] +path = "../../error_macros" + [dependencies.roc_module] path = "../module" diff --git a/reporting/Cargo.toml b/reporting/Cargo.toml index f2f9bf1c57..63e16ad7c3 100644 --- a/reporting/Cargo.toml +++ b/reporting/Cargo.toml @@ -23,9 +23,11 @@ bumpalo = { version = "3.8.0", features = ["collections"] } [dev-dependencies] roc_constrain = { path = "../compiler/constrain" } roc_builtins = { path = "../compiler/builtins" } +roc_load = { path = "../compiler/load" } roc_problem = { path = "../compiler/problem" } roc_parse = { path = "../compiler/parse" } roc_target = { path = "../compiler/roc_target" } roc_test_utils = { path = "../test_utils" } pretty_assertions = "1.0.0" indoc = "1.0.3" +tempfile = "3.2.0" From 15a040ec870cb6aa7473f5d9ba5e72a2ab34f29f Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 12 Apr 2022 15:37:16 -0400 Subject: [PATCH 174/846] Basic type inference and solving for abilities Note that is still pretty limited. We only permit opaque types to implement abilities, abilities cannot have type arguments, and also no other functions may depend on abilities --- compiler/can/src/abilities.rs | 101 +++++-- compiler/can/src/annotation.rs | 156 ++++++---- compiler/can/src/def.rs | 55 ++-- compiler/can/src/expr.rs | 1 + compiler/can/src/module.rs | 14 + compiler/can/src/pattern.rs | 5 +- compiler/can/src/scope.rs | 14 +- compiler/constrain/src/module.rs | 19 +- compiler/constrain/src/pattern.rs | 20 +- compiler/load/build.rs | 1 + compiler/load/src/lib.rs | 13 +- compiler/load_internal/src/file.rs | 110 ++++++- compiler/mono/src/layout.rs | 4 + compiler/mono/src/layout_soa.rs | 18 +- compiler/solve/src/module.rs | 16 +- compiler/solve/src/solve.rs | 179 +++++++++-- compiler/solve/tests/solve_expr.rs | 154 +++++++++- compiler/types/src/pretty_print.rs | 136 ++++++--- compiler/types/src/subs.rs | 151 +++++++++- compiler/types/src/types.rs | 31 +- compiler/unify/src/unify.rs | 465 +++++++++++++++++++++-------- reporting/src/error/type.rs | 175 ++++++++--- reporting/src/report.rs | 19 ++ reporting/tests/helpers/mod.rs | 12 +- reporting/tests/test_reporting.rs | 416 ++++++++++++++++++++------ 25 files changed, 1808 insertions(+), 477 deletions(-) diff --git a/compiler/can/src/abilities.rs b/compiler/can/src/abilities.rs index 5998f9da8e..71be29a706 100644 --- a/compiler/can/src/abilities.rs +++ b/compiler/can/src/abilities.rs @@ -1,55 +1,62 @@ use roc_collections::all::{MutMap, MutSet}; use roc_module::symbol::Symbol; -use roc_types::types::Type; - -use crate::annotation::HasClause; +use roc_region::all::Region; +use roc_types::{subs::Variable, types::Type}; /// Stores information about an ability member definition, including the parent ability, the /// defining type, and what type variables need to be instantiated with instances of the ability. -#[derive(Debug)] -struct AbilityMemberData { - #[allow(unused)] - parent_ability: Symbol, - #[allow(unused)] - signature: Type, - #[allow(unused)] - bound_has_clauses: Vec, +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct AbilityMemberData { + pub parent_ability: Symbol, + pub signature_var: Variable, + pub signature: Type, + pub region: Region, } /// Stores information about what abilities exist in a scope, what it means to implement an /// ability, and what types implement them. // TODO(abilities): this should probably go on the Scope, I don't put it there for now because we // are only dealing with inter-module abilities for now. -#[derive(Default, Debug)] +#[derive(Default, Debug, Clone, PartialEq, Eq)] pub struct AbilitiesStore { /// Maps an ability to the members defining it. - #[allow(unused)] members_of_ability: MutMap>, /// Information about all members composing abilities. ability_members: MutMap, + /// Map of symbols that specialize an ability member to the root ability symbol name. + /// For example, for the program + /// Hash has hash : a -> U64 | a has Hash + /// ^^^^ gets the symbol "#hash" + /// hash = \@Id n -> n + /// ^^^^ gets the symbol "#hash1" + /// + /// We keep the mapping #hash1->#hash + specialization_to_root: MutMap, + /// Tuples of (type, member) specifying that `type` declares an implementation of an ability /// member `member`. - #[allow(unused)] - declared_implementations: MutSet<(Symbol, Symbol)>, + declared_specializations: MutSet<(Symbol, Symbol)>, } impl AbilitiesStore { + /// Records the definition of an ability, including its members. pub fn register_ability( &mut self, ability: Symbol, - members: Vec<(Symbol, Type, Vec)>, + members: Vec<(Symbol, Region, Variable, Type)>, ) { let mut members_vec = Vec::with_capacity(members.len()); - for (member, signature, bound_has_clauses) in members.into_iter() { + for (member, region, signature_var, signature) in members.into_iter() { members_vec.push(member); let old_member = self.ability_members.insert( member, AbilityMemberData { parent_ability: ability, + signature_var, signature, - bound_has_clauses, + region, }, ); debug_assert!(old_member.is_none(), "Replacing existing member definition"); @@ -61,14 +68,64 @@ impl AbilitiesStore { ); } - pub fn register_implementation(&mut self, implementing_type: Symbol, ability_member: Symbol) { - let old_impl = self - .declared_implementations + /// Records a specialization of `ability_member` with specialized type `implementing_type`. + pub fn register_specialization_for_type( + &mut self, + implementing_type: Symbol, + ability_member: Symbol, + ) { + let is_new_insert = self + .declared_specializations .insert((implementing_type, ability_member)); - debug_assert!(!old_impl, "Replacing existing implementation"); + debug_assert!(is_new_insert, "Replacing existing implementation"); } + /// Checks if `name` is a root ability member symbol name. + /// Note that this will return `false` for specializations of an ability member, which have + /// different symbols from the root. pub fn is_ability_member_name(&self, name: Symbol) -> bool { self.ability_members.contains_key(&name) } + + /// Returns information about all known ability members and their root symbols. + pub fn root_ability_members(&self) -> &MutMap { + &self.ability_members + } + + /// Records that the symbol `specializing_symbol` claims to specialize `ability_member`; for + /// example the symbol of `hash : Id -> U64` specializing `hash : a -> U64 | a has Hash`. + pub fn register_specializing_symbol( + &mut self, + specializing_symbol: Symbol, + ability_member: Symbol, + ) { + self.specialization_to_root + .insert(specializing_symbol, ability_member); + } + + /// Returns whether a symbol is declared to specialize an ability member. + pub fn is_specialization_name(&self, symbol: Symbol) -> bool { + self.specialization_to_root.contains_key(&symbol) + } + + /// Finds the symbol name and ability member definition for a symbol specializing the ability + /// member, if it specializes any. + /// For example, suppose `hash : Id -> U64` has symbol #hash1 and specializes + /// `hash : a -> U64 | a has Hash` with symbol #hash. Calling this with #hash1 would retrieve + /// the ability member data for #hash. + pub fn root_name_and_def( + &self, + specializing_symbol: Symbol, + ) -> Option<(Symbol, &AbilityMemberData)> { + let root_symbol = self.specialization_to_root.get(&specializing_symbol)?; + debug_assert!(self.ability_members.contains_key(&root_symbol)); + let root_data = self.ability_members.get(&root_symbol).unwrap(); + Some((*root_symbol, root_data)) + } + + /// Returns pairs of (type, ability member) specifying that "ability member" has a + /// specialization with type "type". + pub fn get_known_specializations(&self) -> &MutSet<(Symbol, Symbol)> { + &self.declared_specializations + } } diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index 52e4f34103..ddc5292dcd 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -19,6 +19,22 @@ pub struct Annotation { pub aliases: SendMap, } +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] +pub enum NamedOrAbleVariable<'a> { + Named(&'a NamedVariable), + Able(&'a AbleVariable), +} + +impl<'a> NamedOrAbleVariable<'a> { + pub fn first_seen(&self) -> Region { + match self { + NamedOrAbleVariable::Named(nv) => nv.first_seen, + NamedOrAbleVariable::Able(av) => av.first_seen, + } + } +} + +/// A named type variable, not bound to an ability. #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] pub struct NamedVariable { pub variable: Variable, @@ -27,21 +43,40 @@ pub struct NamedVariable { pub first_seen: Region, } +/// A type variable bound to an ability, like "a has Hash". +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] +pub struct AbleVariable { + pub variable: Variable, + pub name: Lowercase, + pub ability: Symbol, + // NB: there may be multiple occurrences of a variable + pub first_seen: Region, +} + #[derive(Clone, Debug, PartialEq, Default)] pub struct IntroducedVariables { pub wildcards: Vec>, pub lambda_sets: Vec, pub inferred: Vec>, pub named: Vec, + pub able: Vec, pub host_exposed_aliases: MutMap, } impl IntroducedVariables { + #[inline(always)] + fn debug_assert_not_already_present(&self, var: Variable) { + debug_assert!((self.wildcards.iter().map(|v| &v.value)) + .chain(self.lambda_sets.iter()) + .chain(self.inferred.iter().map(|v| &v.value)) + .chain(self.named.iter().map(|nv| &nv.variable)) + .chain(self.able.iter().map(|av| &av.variable)) + .chain(self.host_exposed_aliases.values()) + .all(|&v| v != var)); + } + pub fn insert_named(&mut self, name: Lowercase, var: Loc) { - debug_assert!(!self - .named - .iter() - .any(|nv| nv.name == name || nv.variable == var.value)); + self.debug_assert_not_already_present(var.value); let named_variable = NamedVariable { name, @@ -52,19 +87,36 @@ impl IntroducedVariables { self.named.push(named_variable); } + pub fn insert_able(&mut self, name: Lowercase, var: Loc, ability: Symbol) { + self.debug_assert_not_already_present(var.value); + + let able_variable = AbleVariable { + name, + ability, + variable: var.value, + first_seen: var.region, + }; + + self.able.push(able_variable); + } + pub fn insert_wildcard(&mut self, var: Loc) { + self.debug_assert_not_already_present(var.value); self.wildcards.push(var); } pub fn insert_inferred(&mut self, var: Loc) { + self.debug_assert_not_already_present(var.value); self.inferred.push(var); } fn insert_lambda_set(&mut self, var: Variable) { + self.debug_assert_not_already_present(var); self.lambda_sets.push(var); } pub fn insert_host_exposed_alias(&mut self, symbol: Symbol, var: Variable) { + self.debug_assert_not_already_present(var); self.host_exposed_aliases.insert(symbol, var); } @@ -78,6 +130,10 @@ impl IntroducedVariables { self.named.extend(other.named.iter().cloned()); self.named.sort(); self.named.dedup(); + + self.able.extend(other.able.iter().cloned()); + self.able.sort(); + self.able.dedup(); } pub fn union_owned(&mut self, other: Self) { @@ -91,15 +147,26 @@ impl IntroducedVariables { self.named.dedup(); } - pub fn var_by_name(&self, name: &Lowercase) -> Option<&Variable> { - self.named - .iter() - .find(|nv| &nv.name == name) - .map(|nv| &nv.variable) + pub fn var_by_name(&self, name: &Lowercase) -> Option { + (self.named.iter().map(|nv| (&nv.name, nv.variable))) + .chain(self.able.iter().map(|av| (&av.name, av.variable))) + .find(|(cand, _)| cand == &name) + .map(|(_, var)| var) } - pub fn named_var_by_name(&self, name: &Lowercase) -> Option<&NamedVariable> { - self.named.iter().find(|nv| &nv.name == name) + pub fn named_var_by_name(&self, name: &Lowercase) -> Option { + if let Some(nav) = self + .named + .iter() + .find(|nv| &nv.name == name) + .map(|nv| NamedOrAbleVariable::Named(nv)) + { + return Some(nav); + } + self.able + .iter() + .find(|av| &av.name == name) + .map(|av| NamedOrAbleVariable::Able(av)) } } @@ -140,13 +207,6 @@ pub fn canonicalize_annotation( } } -#[derive(Clone, Debug)] -pub struct HasClause { - pub var_name: Lowercase, - pub var: Variable, - pub ability: Symbol, -} - pub fn canonicalize_annotation_with_possible_clauses( env: &mut Env, scope: &mut Scope, @@ -154,16 +214,17 @@ pub fn canonicalize_annotation_with_possible_clauses( region: Region, var_store: &mut VarStore, abilities_in_scope: &[Symbol], -) -> (Annotation, Vec>) { +) -> Annotation { let mut introduced_variables = IntroducedVariables::default(); let mut references = MutSet::default(); let mut aliases = SendMap::default(); - let (annotation, region, clauses) = match annotation { + let (annotation, region) = match annotation { TypeAnnotation::Where(annotation, clauses) => { - let mut can_clauses = Vec::with_capacity(clauses.len()); + // Add each "has" clause. The association of a variable to an ability will be saved on + // `introduced_variables`, which we'll process later. for clause in clauses.iter() { - match canonicalize_has_clause( + let opt_err = canonicalize_has_clause( env, scope, var_store, @@ -171,24 +232,19 @@ pub fn canonicalize_annotation_with_possible_clauses( clause, abilities_in_scope, &mut references, - ) { - Ok(result) => can_clauses.push(Loc::at(clause.region, result)), - Err(err_type) => { - return ( - Annotation { - typ: err_type, - introduced_variables, - references, - aliases, - }, - can_clauses, - ) - } - }; + ); + if let Err(err_type) = opt_err { + return Annotation { + typ: err_type, + introduced_variables, + references, + aliases, + }; + } } - (&annotation.value, annotation.region, can_clauses) + (&annotation.value, annotation.region) } - annot => (annot, region, vec![]), + annot => (annot, region), }; let typ = can_annotation_help( @@ -209,7 +265,7 @@ pub fn canonicalize_annotation_with_possible_clauses( aliases, }; - (annot, clauses) + annot } fn make_apply_symbol( @@ -495,7 +551,7 @@ fn can_annotation_help( let name = Lowercase::from(*v); match introduced_variables.var_by_name(&name) { - Some(var) => Type::Variable(*var), + Some(var) => Type::Variable(var), None => { let var = var_store.fresh(); @@ -559,8 +615,8 @@ fn can_annotation_help( let var_name = Lowercase::from(var); if let Some(var) = introduced_variables.var_by_name(&var_name) { - vars.push((var_name.clone(), Type::Variable(*var))); - lowercase_vars.push(Loc::at(loc_var.region, (var_name, *var))); + vars.push((var_name.clone(), Type::Variable(var))); + lowercase_vars.push(Loc::at(loc_var.region, (var_name, var))); } else { let var = var_store.fresh(); @@ -792,7 +848,7 @@ fn canonicalize_has_clause( clause: &Loc>, abilities_in_scope: &[Symbol], references: &mut MutSet, -) -> Result { +) -> Result<(), Type> { let Loc { region, value: roc_parse::ast::HasClause { var, ability }, @@ -829,25 +885,21 @@ fn canonicalize_has_clause( let var_name_ident = var_name.to_string().into(); let shadow = Loc::at(region, var_name_ident); env.problem(roc_problem::can::Problem::Shadowing { - original_region: shadowing.first_seen, + original_region: shadowing.first_seen(), shadow: shadow.clone(), kind: ShadowKind::Variable, }); return Err(Type::Erroneous(Problem::Shadowed( - shadowing.first_seen, + shadowing.first_seen(), shadow, ))); } let var = var_store.fresh(); - introduced_variables.insert_named(var_name.clone(), Loc::at(region, var)); + introduced_variables.insert_able(var_name.clone(), Loc::at(region, var), ability); - Ok(HasClause { - var_name, - var, - ability, - }) + Ok(()) } #[allow(clippy::too_many_arguments)] @@ -1098,7 +1150,7 @@ fn can_assigned_fields<'a>( let field_name = Lowercase::from(loc_field_name.value); let field_type = { if let Some(var) = introduced_variables.var_by_name(&field_name) { - Type::Variable(*var) + Type::Variable(var) } else { let field_var = var_store.fresh(); introduced_variables.insert_named( diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 460b8a5efc..75d17270af 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1,4 +1,3 @@ -use crate::abilities::AbilitiesStore; use crate::annotation::canonicalize_annotation; use crate::annotation::canonicalize_annotation_with_possible_clauses; use crate::annotation::IntroducedVariables; @@ -430,12 +429,11 @@ pub fn canonicalize_defs<'a>( } // Now we can go through and resolve all pending abilities, to add them to scope. - let mut abilities_store = AbilitiesStore::default(); for (loc_ability_name, members) in abilities.into_values() { let mut can_members = Vec::with_capacity(members.len()); for member in members { - let (member_annot, clauses) = canonicalize_annotation_with_possible_clauses( + let member_annot = canonicalize_annotation_with_possible_clauses( env, &mut scope, &member.typ.value, @@ -450,13 +448,14 @@ pub fn canonicalize_defs<'a>( output.references.referenced_type_defs.insert(symbol); } + let name_region = member.name.region; let member_name = member.name.extract_spaces().item; let member_sym = match scope.introduce( member_name.into(), &env.exposed_ident_ids, &mut env.ident_ids, - member.name.region, + name_region, ) { Ok(sym) => sym, Err((original_region, shadow, _new_symbol)) => { @@ -473,9 +472,11 @@ pub fn canonicalize_defs<'a>( // What variables in the annotation are bound to the parent ability, and what variables // are bound to some other ability? let (variables_bound_to_ability, variables_bound_to_other_abilities): (Vec<_>, Vec<_>) = - clauses - .into_iter() - .partition(|has_clause| has_clause.value.ability == loc_ability_name.value); + member_annot + .introduced_variables + .able + .iter() + .partition(|av| av.ability == loc_ability_name.value); let mut bad_has_clauses = false; @@ -485,18 +486,18 @@ pub fn canonicalize_defs<'a>( env.problem(Problem::AbilityMemberMissingHasClause { member: member_sym, ability: loc_ability_name.value, - region: member.name.region, + region: name_region, }); bad_has_clauses = true; } if !variables_bound_to_other_abilities.is_empty() { // Disallow variables bound to other abilities, for now. - for bad_clause in variables_bound_to_other_abilities.iter() { + for bad_variable in variables_bound_to_other_abilities.iter() { env.problem(Problem::AbilityMemberBindsExternalAbility { member: member_sym, ability: loc_ability_name.value, - region: bad_clause.region, + region: bad_variable.first_seen, }); } bad_has_clauses = true; @@ -507,17 +508,22 @@ pub fn canonicalize_defs<'a>( continue; } - let has_clauses = variables_bound_to_ability - .into_iter() - .map(|clause| clause.value) - .collect(); - can_members.push((member_sym, member_annot.typ, has_clauses)); + // The introduced variables are good; add them to the output. + output + .introduced_variables + .union(&member_annot.introduced_variables); + + can_members.push((member_sym, name_region, var_store.fresh(), member_annot.typ)); } // Store what symbols a type must define implementations for to have this ability. - abilities_store.register_ability(loc_ability_name.value, can_members); + scope + .abilities_store + .register_ability(loc_ability_name.value, can_members); } + dbg!(&scope.abilities_store, pattern_type); + // Now that we have the scope completely assembled, and shadowing resolved, // we're ready to canonicalize any body exprs. @@ -526,14 +532,7 @@ pub fn canonicalize_defs<'a>( // once we've finished assembling the entire scope. let mut pending_value_defs = Vec::with_capacity(value_defs.len()); for loc_def in value_defs.into_iter() { - match to_pending_value_def( - env, - var_store, - loc_def.value, - &mut scope, - &abilities_store, - pattern_type, - ) { + match to_pending_value_def(env, var_store, loc_def.value, &mut scope, pattern_type) { None => { /* skip */ } Some((new_output, pending_def)) => { // store the top-level defs, used to ensure that closures won't capture them @@ -1561,7 +1560,9 @@ pub fn can_defs_with_return<'a>( // Now that we've collected all the references, check to see if any of the new idents // we defined went unused by the return expression. If any were unused, report it. for (symbol, region) in symbols_introduced { - if !output.references.has_value_lookup(symbol) && !output.references.has_type_lookup(symbol) + if !output.references.has_value_lookup(symbol) + && !output.references.has_type_lookup(symbol) + && !scope.abilities_store.is_specialization_name(symbol) { env.problem(Problem::UnusedDef(symbol, region)); } @@ -1772,7 +1773,6 @@ fn to_pending_value_def<'a>( var_store: &mut VarStore, def: &'a ast::ValueDef<'a>, scope: &mut Scope, - abilities_store: &AbilitiesStore, pattern_type: PatternType, ) -> Option<(Output, PendingValueDef<'a>)> { use ast::ValueDef::*; @@ -1784,7 +1784,6 @@ fn to_pending_value_def<'a>( env, var_store, scope, - abilities_store, pattern_type, &loc_pattern.value, loc_pattern.region, @@ -1801,7 +1800,6 @@ fn to_pending_value_def<'a>( env, var_store, scope, - abilities_store, pattern_type, &loc_pattern.value, loc_pattern.region, @@ -1832,7 +1830,6 @@ fn to_pending_value_def<'a>( env, var_store, scope, - abilities_store, pattern_type, &body_pattern.value, body_pattern.region, diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index b021dc2192..d9262ceab1 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -1083,6 +1083,7 @@ fn canonicalize_when_branch<'a>( && !branch_output.references.has_value_lookup(symbol) && !branch_output.references.has_type_lookup(symbol) && !original_scope.contains_symbol(symbol) + && !scope.abilities_store.is_specialization_name(symbol) { env.problem(Problem::UnusedDef(symbol, *region)); } diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index c0b01b8888..01e6664d14 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -1,3 +1,4 @@ +use crate::abilities::AbilitiesStore; use crate::def::{canonicalize_defs, sort_can_defs, Declaration, Def}; use crate::effect_module::HostedGeneratedFunctions; use crate::env::Env; @@ -28,11 +29,13 @@ pub struct Module { /// all aliases. `bool` indicates whether it is exposed pub aliases: MutMap, pub rigid_variables: RigidVariables, + pub abilities_store: AbilitiesStore, } #[derive(Debug, Default)] pub struct RigidVariables { pub named: MutMap, + pub able: MutMap, pub wildcards: MutSet, } @@ -250,6 +253,7 @@ pub fn canonicalize_module_defs<'a>( if !output.references.has_value_lookup(symbol) && !output.references.has_type_lookup(symbol) && !exposed_symbols.contains(&symbol) + && !scope.abilities_store.is_specialization_name(symbol) { env.problem(Problem::UnusedDef(symbol, region)); } @@ -259,6 +263,12 @@ pub fn canonicalize_module_defs<'a>( rigid_variables.named.insert(named.variable, named.name); } + for able in output.introduced_variables.able { + rigid_variables + .able + .insert(able.variable, (able.name, able.ability)); + } + for var in output.introduced_variables.wildcards { rigid_variables.wildcards.insert(var.value); } @@ -444,6 +454,10 @@ pub fn canonicalize_module_defs<'a>( aliases.insert(symbol, alias); } + for member in scope.abilities_store.root_ability_members().keys() { + exposed_but_not_defined.remove(member); + } + // By this point, all exposed symbols should have been removed from // exposed_symbols and added to exposed_vars_by_symbol. If any were // not, that means they were declared as exposed but there was diff --git a/compiler/can/src/pattern.rs b/compiler/can/src/pattern.rs index 251c889a0c..9df8cd7312 100644 --- a/compiler/can/src/pattern.rs +++ b/compiler/can/src/pattern.rs @@ -1,4 +1,3 @@ -use crate::abilities::AbilitiesStore; use crate::annotation::freshen_opaque_def; use crate::env::Env; use crate::expr::{canonicalize_expr, unescape_char, Expr, IntValue, Output}; @@ -157,7 +156,6 @@ pub fn canonicalize_def_header_pattern<'a>( env: &mut Env<'a>, var_store: &mut VarStore, scope: &mut Scope, - abilities_store: &AbilitiesStore, pattern_type: PatternType, pattern: &ast::Pattern<'a>, region: Region, @@ -168,11 +166,10 @@ pub fn canonicalize_def_header_pattern<'a>( match pattern { // Identifiers that shadow ability members may appear (and may only appear) at the header of a def. Identifier(name) => match scope.introduce_or_shadow_ability_member( - (*name).into(), + dbg!((*name).into()), &env.exposed_ident_ids, &mut env.ident_ids, region, - abilities_store, ) { Ok((symbol, shadowing_ability_member)) => { output.references.bound_symbols.insert(symbol); diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index 179f15bdf0..f08ba453a8 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -22,7 +22,7 @@ pub struct Scope { pub aliases: SendMap, /// The abilities currently in scope, and their implementors. - pub abilities: SendMap, + pub abilities_store: AbilitiesStore, /// The current module being processed. This will be used to turn /// unqualified idents into Symbols. @@ -68,7 +68,7 @@ impl Scope { symbols: SendMap::default(), aliases, // TODO(abilities): default abilities in scope - abilities: SendMap::default(), + abilities_store: AbilitiesStore::default(), } } @@ -247,16 +247,20 @@ impl Scope { exposed_ident_ids: &IdentIds, all_ident_ids: &mut IdentIds, region: Region, - abilities_store: &AbilitiesStore, ) -> Result<(Symbol, Option), (Region, Loc, Symbol)> { - match self.idents.get(&ident) { + match dbg!(self.idents.get(&ident)) { Some(&(original_symbol, original_region)) => { let shadow_ident_id = all_ident_ids.add(ident.clone()); let shadow_symbol = Symbol::new(self.home, shadow_ident_id); self.symbols.insert(shadow_symbol, region); - if abilities_store.is_ability_member_name(original_symbol) { + if self + .abilities_store + .is_ability_member_name(dbg!(original_symbol)) + { + self.abilities_store + .register_specializing_symbol(shadow_symbol, original_symbol); // Add a symbol for the shadow, but don't re-associate the member name. Ok((shadow_symbol, Some(original_symbol))) } else { diff --git a/compiler/constrain/src/module.rs b/compiler/constrain/src/module.rs index e9b622cbee..566b15cd88 100644 --- a/compiler/constrain/src/module.rs +++ b/compiler/constrain/src/module.rs @@ -1,4 +1,5 @@ use roc_builtins::std::StdLib; +use roc_can::abilities::AbilitiesStore; use roc_can::constraint::{Constraint, Constraints}; use roc_can::def::Declaration; use roc_collections::all::MutMap; @@ -100,10 +101,26 @@ pub enum ExposedModuleTypes { pub fn constrain_module( constraints: &mut Constraints, + abilities_store: &AbilitiesStore, declarations: &[Declaration], home: ModuleId, ) -> Constraint { - crate::expr::constrain_decls(constraints, home, declarations) + let mut constraint = crate::expr::constrain_decls(constraints, home, declarations); + + for (member_name, member_data) in abilities_store.root_ability_members().iter() { + constraint = constraints.let_constraint( + [], + [], + [(*member_name, Loc::at_zero(member_data.signature.clone()))], + Constraint::True, + constraint, + ); + } + + // The module constraint should always save the environment at the end. + debug_assert!(constraints.contains_save_the_environment(&constraint)); + + constraint } #[derive(Debug, Clone)] diff --git a/compiler/constrain/src/pattern.rs b/compiler/constrain/src/pattern.rs index a66dcb03a5..2672602b7b 100644 --- a/compiler/constrain/src/pattern.rs +++ b/compiler/constrain/src/pattern.rs @@ -188,9 +188,23 @@ pub fn constrain_pattern( // Erroneous patterns don't add any constraints. } - Identifier(symbol) | Shadowed(_, _, symbol) - // TODO(abilities): handle linking the member def to the specialization ident - | AbilityMemberSpecialization { + Identifier(symbol) | Shadowed(_, _, symbol) => { + if could_be_a_tag_union(expected.get_type_ref()) { + state + .constraints + .push(constraints.is_open_type(expected.get_type_ref().clone())); + } + + state.headers.insert( + *symbol, + Loc { + region, + value: expected.get_type(), + }, + ); + } + + AbilityMemberSpecialization { ident: symbol, specializes: _, } => { diff --git a/compiler/load/build.rs b/compiler/load/build.rs index dc7b09cca9..3484b412d1 100644 --- a/compiler/load/build.rs +++ b/compiler/load/build.rs @@ -36,6 +36,7 @@ fn write_subs_for_module(module_id: ModuleId, filename: &str) { &src_dir, Default::default(), target_info, + roc_reporting::report::RenderTarget::ColorTerminal, ); let module = res_module.unwrap(); diff --git a/compiler/load/src/lib.rs b/compiler/load/src/lib.rs index 3b05a22bdf..b867228cca 100644 --- a/compiler/load/src/lib.rs +++ b/compiler/load/src/lib.rs @@ -2,6 +2,7 @@ use bumpalo::Bump; use roc_collections::all::MutMap; use roc_constrain::module::ExposedByModule; use roc_module::symbol::{ModuleId, Symbol}; +use roc_reporting::report::RenderTarget; use roc_target::TargetInfo; use roc_types::subs::{Subs, Variable}; use std::path::{Path, PathBuf}; @@ -18,6 +19,7 @@ fn load<'a>( exposed_types: ExposedByModule, goal_phase: Phase, target_info: TargetInfo, + render: RenderTarget, ) -> Result, LoadingProblem<'a>> { let cached_subs = read_cached_subs(); @@ -29,6 +31,7 @@ fn load<'a>( goal_phase, target_info, cached_subs, + render, ) } @@ -39,6 +42,7 @@ pub fn load_and_monomorphize_from_str<'a>( src_dir: &Path, exposed_types: ExposedByModule, target_info: TargetInfo, + render: RenderTarget, ) -> Result, LoadingProblem<'a>> { use LoadResult::*; @@ -51,6 +55,7 @@ pub fn load_and_monomorphize_from_str<'a>( exposed_types, Phase::MakeSpecializations, target_info, + render, )? { Monomorphized(module) => Ok(module), TypeChecked(_) => unreachable!(""), @@ -63,10 +68,11 @@ pub fn load_and_monomorphize<'a>( src_dir: &Path, exposed_types: ExposedByModule, target_info: TargetInfo, + render: RenderTarget, ) -> Result, LoadingProblem<'a>> { use LoadResult::*; - let load_start = LoadStart::from_path(arena, filename)?; + let load_start = LoadStart::from_path(arena, filename, render)?; match load( arena, @@ -75,6 +81,7 @@ pub fn load_and_monomorphize<'a>( exposed_types, Phase::MakeSpecializations, target_info, + render, )? { Monomorphized(module) => Ok(module), TypeChecked(_) => unreachable!(""), @@ -87,10 +94,11 @@ pub fn load_and_typecheck<'a>( src_dir: &Path, exposed_types: ExposedByModule, target_info: TargetInfo, + render: RenderTarget, ) -> Result> { use LoadResult::*; - let load_start = LoadStart::from_path(arena, filename)?; + let load_start = LoadStart::from_path(arena, filename, render)?; match load( arena, @@ -99,6 +107,7 @@ pub fn load_and_typecheck<'a>( exposed_types, Phase::SolveTypes, target_info, + render, )? { Monomorphized(_) => unreachable!(""), TypeChecked(module) => Ok(module), diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index 27f8cb8c76..ae1a70d631 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -5,6 +5,7 @@ use crossbeam::deque::{Injector, Stealer, Worker}; use crossbeam::thread; use parking_lot::Mutex; use roc_builtins::std::borrow_stdlib; +use roc_can::abilities::AbilitiesStore; use roc_can::constraint::{Constraint as ConstraintSoa, Constraints}; use roc_can::def::Declaration; use roc_can::module::{canonicalize_module_defs, Module}; @@ -31,6 +32,7 @@ use roc_parse::ident::UppercaseIdent; use roc_parse::module::module_defs; use roc_parse::parser::{FileError, Parser, SyntaxError}; use roc_region::all::{LineInfo, Loc, Region}; +use roc_reporting::report::RenderTarget; use roc_solve::module::SolvedModule; use roc_solve::solve; use roc_target::TargetInfo; @@ -347,6 +349,7 @@ pub struct LoadedModule { pub sources: MutMap)>, pub timings: MutMap, pub documentation: MutMap, + pub abilities_store: AbilitiesStore, } impl LoadedModule { @@ -508,6 +511,7 @@ enum Msg<'a> { decls: Vec, dep_idents: MutMap, module_timing: ModuleTiming, + abilities_store: AbilitiesStore, }, FinishedAllTypeChecking { solved_subs: Solved, @@ -515,6 +519,7 @@ enum Msg<'a> { exposed_aliases_by_symbol: MutMap, dep_idents: MutMap, documentation: MutMap, + abilities_store: AbilitiesStore, }, FoundSpecializations { module_id: ModuleId, @@ -604,6 +609,8 @@ struct State<'a> { // (Granted, this has not been attempted or measured!) pub layout_caches: std::vec::Vec>, + pub render: RenderTarget, + // cached subs (used for builtin modules, could include packages in the future too) cached_subs: CachedSubs, } @@ -619,6 +626,7 @@ impl<'a> State<'a> { arc_modules: Arc>>, ident_ids_by_module: Arc>>, cached_subs: MutMap)>, + render: RenderTarget, ) -> Self { let arc_shorthands = Arc::new(Mutex::new(MutMap::default())); @@ -643,6 +651,7 @@ impl<'a> State<'a> { timings: MutMap::default(), layout_caches: std::vec::Vec::with_capacity(num_cpus::get()), cached_subs: Arc::new(Mutex::new(cached_subs)), + render, } } } @@ -824,6 +833,7 @@ pub fn load_and_typecheck_str<'a>( src_dir: &Path, exposed_types: ExposedByModule, target_info: TargetInfo, + render: RenderTarget, ) -> Result> { use LoadResult::*; @@ -841,12 +851,19 @@ pub fn load_and_typecheck_str<'a>( Phase::SolveTypes, target_info, cached_subs, + render, )? { Monomorphized(_) => unreachable!(""), TypeChecked(module) => Ok(module), } } +#[derive(Clone, Copy)] +pub enum PrintTarget { + ColorTerminal, + Generic, +} + pub struct LoadStart<'a> { arc_modules: Arc>>, ident_ids_by_module: Arc>>, @@ -855,7 +872,11 @@ pub struct LoadStart<'a> { } impl<'a> LoadStart<'a> { - pub fn from_path(arena: &'a Bump, filename: PathBuf) -> Result> { + pub fn from_path( + arena: &'a Bump, + filename: PathBuf, + render: RenderTarget, + ) -> Result> { let arc_modules = Arc::new(Mutex::new(PackageModuleIds::default())); let root_exposed_ident_ids = IdentIds::exposed_builtins(0); let ident_ids_by_module = Arc::new(Mutex::new(root_exposed_ident_ids)); @@ -887,7 +908,12 @@ impl<'a> LoadStart<'a> { // if parsing failed, this module did not add any identifiers let root_exposed_ident_ids = IdentIds::exposed_builtins(0); - let buf = to_parse_problem_report(problem, module_ids, root_exposed_ident_ids); + let buf = to_parse_problem_report( + problem, + module_ids, + root_exposed_ident_ids, + render, + ); return Err(LoadingProblem::FormattedReport(buf)); } Err(LoadingProblem::FileProblem { filename, error }) => { @@ -995,6 +1021,7 @@ pub fn load<'a>( goal_phase: Phase, target_info: TargetInfo, cached_subs: MutMap)>, + render: RenderTarget, ) -> Result, LoadingProblem<'a>> { // When compiling to wasm, we cannot spawn extra threads // so we have a single-threaded implementation @@ -1007,6 +1034,7 @@ pub fn load<'a>( goal_phase, target_info, cached_subs, + render, ) } else { load_multi_threaded( @@ -1017,6 +1045,7 @@ pub fn load<'a>( goal_phase, target_info, cached_subs, + render, ) } } @@ -1031,12 +1060,14 @@ fn load_single_threaded<'a>( goal_phase: Phase, target_info: TargetInfo, cached_subs: MutMap)>, + render: RenderTarget, ) -> Result, LoadingProblem<'a>> { let LoadStart { arc_modules, ident_ids_by_module, root_id, root_msg, + .. } = load_start; let (msg_tx, msg_rx) = bounded(1024); @@ -1053,6 +1084,7 @@ fn load_single_threaded<'a>( arc_modules, ident_ids_by_module, cached_subs, + render, ); // We'll add tasks to this, and then worker threads will take tasks from it. @@ -1115,6 +1147,7 @@ fn state_thread_step<'a>( exposed_aliases_by_symbol, dep_idents, documentation, + abilities_store, } => { // We're done! There should be no more messages pending. debug_assert!(msg_rx.is_empty()); @@ -1131,6 +1164,7 @@ fn state_thread_step<'a>( exposed_vars_by_symbol, dep_idents, documentation, + abilities_store, ); Ok(ControlFlow::Break(LoadResult::TypeChecked(typechecked))) @@ -1153,8 +1187,12 @@ fn state_thread_step<'a>( Msg::FailedToParse(problem) => { let module_ids = (*state.arc_modules).lock().clone().into_module_ids(); - let buf = - to_parse_problem_report(problem, module_ids, state.constrained_ident_ids); + let buf = to_parse_problem_report( + problem, + module_ids, + state.constrained_ident_ids, + state.render, + ); Err(LoadingProblem::FormattedReport(buf)) } msg => { @@ -1164,6 +1202,8 @@ fn state_thread_step<'a>( let constrained_ident_ids = state.constrained_ident_ids.clone(); let arc_modules = state.arc_modules.clone(); + let render = state.render; + let res_state = update( state, msg, @@ -1185,8 +1225,12 @@ fn state_thread_step<'a>( .into_inner() .into_module_ids(); - let buf = - to_parse_problem_report(problem, module_ids, constrained_ident_ids); + let buf = to_parse_problem_report( + problem, + module_ids, + constrained_ident_ids, + render, + ); Err(LoadingProblem::FormattedReport(buf)) } Err(e) => Err(e), @@ -1210,12 +1254,14 @@ fn load_multi_threaded<'a>( goal_phase: Phase, target_info: TargetInfo, cached_subs: MutMap)>, + render: RenderTarget, ) -> Result, LoadingProblem<'a>> { let LoadStart { arc_modules, ident_ids_by_module, root_id, root_msg, + .. } = load_start; let mut state = State::new( @@ -1226,6 +1272,7 @@ fn load_multi_threaded<'a>( arc_modules, ident_ids_by_module, cached_subs, + render, ); let (msg_tx, msg_rx) = bounded(1024); @@ -1746,6 +1793,7 @@ fn update<'a>( decls, dep_idents, mut module_timing, + abilities_store, } => { log!("solved types for {:?}", module_id); module_timing.end_time = SystemTime::now(); @@ -1798,6 +1846,7 @@ fn update<'a>( exposed_aliases_by_symbol: solved_module.aliases, dep_idents, documentation, + abilities_store, }) .map_err(|_| LoadingProblem::MsgChannelDied)?; @@ -2126,6 +2175,7 @@ fn finish( exposed_vars_by_symbol: Vec<(Symbol, Variable)>, dep_idents: MutMap, documentation: MutMap, + abilities_store: AbilitiesStore, ) -> LoadedModule { let module_ids = Arc::try_unwrap(state.arc_modules) .unwrap_or_else(|_| panic!("There were still outstanding Arc references to module_ids")) @@ -2160,6 +2210,7 @@ fn finish( sources, timings: state.timings, documentation, + abilities_store, } } @@ -3102,6 +3153,10 @@ fn add_imports( rigid_vars.extend(copied_import.rigid); rigid_vars.extend(copied_import.flex); + // Rigid vars bound to abilities are also treated like rigids. + rigid_vars.extend(copied_import.rigid_able); + rigid_vars.extend(copied_import.flex_able); + import_variables.extend(copied_import.registered); def_types.push(( @@ -3126,11 +3181,17 @@ fn run_solve_solve( constraint: ConstraintSoa, mut var_store: VarStore, module: Module, -) -> (Solved, Vec<(Symbol, Variable)>, Vec) { +) -> ( + Solved, + Vec<(Symbol, Variable)>, + Vec, + AbilitiesStore, +) { let Module { exposed_symbols, aliases, rigid_variables, + abilities_store, .. } = module; @@ -3155,12 +3216,13 @@ fn run_solve_solve( solve_aliases.insert(*name, alias.clone()); } - let (solved_subs, solved_env, problems) = roc_solve::module::run_solve( + let (solved_subs, solved_env, problems, abilities_store) = roc_solve::module::run_solve( &constraints, actual_constraint, rigid_variables, subs, solve_aliases, + abilities_store, ); let solved_subs = if true { @@ -3179,7 +3241,12 @@ fn run_solve_solve( .filter(|(k, _)| exposed_symbols.contains(k)) .collect(); - (solved_subs, exposed_vars_by_symbol, problems) + ( + solved_subs, + exposed_vars_by_symbol, + problems, + abilities_store, + ) } #[allow(clippy::too_many_arguments)] @@ -3203,7 +3270,7 @@ fn run_solve<'a>( // TODO remove when we write builtins in roc let aliases = module.aliases.clone(); - let (solved_subs, exposed_vars_by_symbol, problems) = { + let (solved_subs, exposed_vars_by_symbol, problems, abilities_store) = { if module_id.is_builtin() { match cached_subs.lock().remove(&module_id) { None => { @@ -3217,9 +3284,13 @@ fn run_solve<'a>( module, ) } - Some((subs, exposed_vars_by_symbol)) => { - (Solved(subs), exposed_vars_by_symbol.to_vec(), vec![]) - } + Some((subs, exposed_vars_by_symbol)) => ( + Solved(subs), + exposed_vars_by_symbol.to_vec(), + vec![], + // TODO(abilities) replace when we have abilities for builtins + AbilitiesStore::default(), + ), } } else { run_solve_solve( @@ -3258,6 +3329,7 @@ fn run_solve<'a>( dep_idents, solved_module, module_timing, + abilities_store, } } @@ -3385,8 +3457,12 @@ fn canonicalize_and_constrain<'a>( let mut constraints = Constraints::new(); - let constraint = - constrain_module(&mut constraints, &module_output.declarations, module_id); + let constraint = constrain_module( + &mut constraints, + &module_output.scope.abilities_store, + &module_output.declarations, + module_id, + ); let after = roc_types::types::get_type_clone_count(); @@ -3426,6 +3502,7 @@ fn canonicalize_and_constrain<'a>( referenced_types: module_output.referenced_types, aliases, rigid_variables: module_output.rigid_variables, + abilities_store: module_output.scope.abilities_store, }; let constrained_module = ConstrainedModule { @@ -4068,6 +4145,7 @@ fn to_parse_problem_report<'a>( problem: FileError<'a, SyntaxError<'a>>, mut module_ids: ModuleIds, all_ident_ids: MutMap, + render: RenderTarget, ) -> String { use roc_reporting::report::{parse_problem, RocDocAllocator, DEFAULT_PALETTE}; @@ -4102,7 +4180,7 @@ fn to_parse_problem_report<'a>( let mut buf = String::new(); let palette = DEFAULT_PALETTE; - report.render_color_terminal(&mut buf, &alloc, &palette); + report.render(render, &mut buf, &alloc, &palette); buf } diff --git a/compiler/mono/src/layout.rs b/compiler/mono/src/layout.rs index 07cf05ea5e..2b7548c3bb 100644 --- a/compiler/mono/src/layout.rs +++ b/compiler/mono/src/layout.rs @@ -3,6 +3,7 @@ use bumpalo::collections::Vec; use bumpalo::Bump; use roc_builtins::bitcode::{FloatWidth, IntWidth}; use roc_collections::all::{default_hasher, MutMap}; +use roc_error_macros::todo_abilities; use roc_module::ident::{Lowercase, TagName}; use roc_module::symbol::{Interns, Symbol}; use roc_problem::can::RuntimeError; @@ -72,6 +73,7 @@ impl<'a> RawFunctionLayout<'a> { use roc_types::subs::Content::*; match content { FlexVar(_) | RigidVar(_) => Err(LayoutProblem::UnresolvedTypeVar(var)), + FlexAbleVar(_, _) | RigidAbleVar(_, _) => todo_abilities!("Not reachable yet"), RecursionVar { structure, .. } => { let structure_content = env.subs.get_content_without_compacting(structure); Self::new_help(env, structure, *structure_content) @@ -952,6 +954,7 @@ impl<'a> Layout<'a> { use roc_types::subs::Content::*; match content { FlexVar(_) | RigidVar(_) => Err(LayoutProblem::UnresolvedTypeVar(var)), + FlexAbleVar(_, _) | RigidAbleVar(_, _) => todo_abilities!("Not reachable yet"), RecursionVar { structure, .. } => { let structure_content = env.subs.get_content_without_compacting(structure); Self::new_help(env, structure, *structure_content) @@ -2657,6 +2660,7 @@ fn layout_from_num_content<'a>( // (e.g. for (5 + 5) assume both 5s are 64-bit integers.) Ok(Layout::default_integer()) } + FlexAbleVar(_, _) | RigidAbleVar(_, _) => todo_abilities!("Not reachable yet"), Structure(Apply(symbol, args)) => match *symbol { // Ints Symbol::NUM_NAT => Ok(Layout::usize(target_info)), diff --git a/compiler/mono/src/layout_soa.rs b/compiler/mono/src/layout_soa.rs index b4f9bd1a72..ed813d0c0a 100644 --- a/compiler/mono/src/layout_soa.rs +++ b/compiler/mono/src/layout_soa.rs @@ -137,8 +137,10 @@ impl FunctionLayout { use LayoutError::*; match content { - Content::FlexVar(_) => Err(UnresolvedVariable(var)), - Content::RigidVar(_) => Err(UnresolvedVariable(var)), + Content::FlexVar(_) + | Content::RigidVar(_) + | Content::FlexAbleVar(_, _) + | Content::RigidAbleVar(_, _) => Err(UnresolvedVariable(var)), Content::RecursionVar { .. } => Err(TypeError(())), Content::Structure(flat_type) => Self::from_flat_type(layouts, subs, flat_type), Content::Alias(_, _, actual, _) => Self::from_var_help(layouts, subs, *actual), @@ -243,8 +245,10 @@ impl LambdaSet { use LayoutError::*; match content { - Content::FlexVar(_) => Err(UnresolvedVariable(var)), - Content::RigidVar(_) => Err(UnresolvedVariable(var)), + Content::FlexVar(_) + | Content::RigidVar(_) + | Content::FlexAbleVar(_, _) + | Content::RigidAbleVar(_, _) => Err(UnresolvedVariable(var)), Content::RecursionVar { .. } => { unreachable!("lambda sets cannot currently be recursive") } @@ -627,8 +631,10 @@ impl Layout { use LayoutError::*; match content { - Content::FlexVar(_) => Err(UnresolvedVariable(var)), - Content::RigidVar(_) => Err(UnresolvedVariable(var)), + Content::FlexVar(_) + | Content::RigidVar(_) + | Content::FlexAbleVar(_, _) + | Content::RigidAbleVar(_, _) => Err(UnresolvedVariable(var)), Content::RecursionVar { structure, opt_name: _, diff --git a/compiler/solve/src/module.rs b/compiler/solve/src/module.rs index c6197065a8..c0f5f7ef94 100644 --- a/compiler/solve/src/module.rs +++ b/compiler/solve/src/module.rs @@ -1,4 +1,5 @@ use crate::solve::{self, Aliases}; +use roc_can::abilities::AbilitiesStore; use roc_can::constraint::{Constraint as ConstraintSoa, Constraints}; use roc_can::module::RigidVariables; use roc_collections::all::MutMap; @@ -32,13 +33,23 @@ pub fn run_solve( rigid_variables: RigidVariables, mut subs: Subs, mut aliases: Aliases, -) -> (Solved, solve::Env, Vec) { + mut abilities_store: AbilitiesStore, +) -> ( + Solved, + solve::Env, + Vec, + AbilitiesStore, +) { let env = solve::Env::default(); for (var, name) in rigid_variables.named { subs.rigid_var(var, name); } + for (var, (name, ability)) in rigid_variables.able { + subs.rigid_able_var(var, name, ability); + } + for var in rigid_variables.wildcards { subs.rigid_var(var, "*".into()); } @@ -55,9 +66,10 @@ pub fn run_solve( subs, &mut aliases, &constraint, + &mut abilities_store, ); - (solved_subs, solved_env, problems) + (solved_subs, solved_env, problems, abilities_store) } pub fn exposed_types_storage_subs( diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index e546730f70..8399b8cba2 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -1,4 +1,5 @@ use bumpalo::Bump; +use roc_can::abilities::AbilitiesStore; use roc_can::constraint::Constraint::{self, *}; use roc_can::constraint::{Constraints, LetConstraint}; use roc_can::expected::{Expected, PExpected}; @@ -14,9 +15,9 @@ use roc_types::subs::{ use roc_types::types::Type::{self, *}; use roc_types::types::{ gather_fields_unsorted_iter, AliasCommon, AliasKind, Category, ErrorType, PatternCategory, - TypeExtension, + Reason, TypeExtension, }; -use roc_unify::unify::{unify, Mode, Unified::*}; +use roc_unify::unify::{unify, Mode, MustImplementAbility, Unified::*}; // Type checking system adapted from Elm by Evan Czaplicki, BSD-3-Clause Licensed // https://github.com/elm/compiler @@ -515,8 +516,17 @@ pub fn run( mut subs: Subs, aliases: &mut Aliases, constraint: &Constraint, + abilities_store: &mut AbilitiesStore, ) -> (Solved, Env) { - let env = run_in_place(constraints, env, problems, &mut subs, aliases, constraint); + let env = run_in_place( + constraints, + env, + problems, + &mut subs, + aliases, + constraint, + abilities_store, + ); (Solved(subs), env) } @@ -529,6 +539,7 @@ pub fn run_in_place( subs: &mut Subs, aliases: &mut Aliases, constraint: &Constraint, + abilities_store: &mut AbilitiesStore, ) -> Env { let mut pools = Pools::default(); @@ -540,6 +551,8 @@ pub fn run_in_place( let arena = Bump::new(); + let mut deferred_must_implement_abilities = Vec::new(); + let state = solve( &arena, constraints, @@ -551,8 +564,12 @@ pub fn run_in_place( aliases, subs, constraint, + abilities_store, + &mut deferred_must_implement_abilities, ); + // TODO run through and check that all abilities are properly implemented + state.env } @@ -604,6 +621,8 @@ fn solve( aliases: &mut Aliases, subs: &mut Subs, constraint: &Constraint, + abilities_store: &mut AbilitiesStore, + deferred_must_implement_abilities: &mut Vec, ) -> State { let initial = Work::Constraint { env, @@ -752,6 +771,18 @@ fn solve( let mut new_env = env.clone(); for (symbol, loc_var) in local_def_vars.iter() { + check_ability_specialization( + subs, + &new_env, + pools, + rank, + abilities_store, + problems, + deferred_must_implement_abilities, + *symbol, + *loc_var, + ); + new_env.insert_symbol_var_if_vacant(*symbol, loc_var.value); } @@ -796,12 +827,15 @@ fn solve( let expected = type_to_var(subs, rank, pools, aliases, expectation.get_type_ref()); match unify(subs, actual, expected, Mode::EQ) { - Success(vars) => { + Success { + vars, + must_implement_ability: _, + } => { introduce(subs, rank, pools, &vars); state } - Failure(vars, actual_type, expected_type) => { + Failure(vars, actual_type, expected_type, _bad_impls) => { introduce(subs, rank, pools, &vars); let problem = TypeError::BadExpr( @@ -838,12 +872,15 @@ fn solve( let target = *target; match unify(subs, actual, target, Mode::EQ) { - Success(vars) => { + Success { + vars, + must_implement_ability: _, + } => { introduce(subs, rank, pools, &vars); state } - Failure(vars, _actual_type, _expected_type) => { + Failure(vars, _actual_type, _expected_type, _bad_impls) => { introduce(subs, rank, pools, &vars); // ERROR NOT REPORTED @@ -890,13 +927,16 @@ fn solve( type_to_var(subs, rank, pools, aliases, expectation.get_type_ref()); match unify(subs, actual, expected, Mode::EQ) { - Success(vars) => { + Success { + vars, + must_implement_ability: _, + } => { introduce(subs, rank, pools, &vars); state } - Failure(vars, actual_type, expected_type) => { + Failure(vars, actual_type, expected_type, _bad_impls) => { introduce(subs, rank, pools, &vars); let problem = TypeError::BadExpr( @@ -954,12 +994,15 @@ fn solve( }; match unify(subs, actual, expected, mode) { - Success(vars) => { + Success { + vars, + must_implement_ability: _, + } => { introduce(subs, rank, pools, &vars); state } - Failure(vars, actual_type, expected_type) => { + Failure(vars, actual_type, expected_type, _bad_impls) => { introduce(subs, rank, pools, &vars); let problem = TypeError::BadPattern( @@ -1123,12 +1166,15 @@ fn solve( let includes = type_to_var(subs, rank, pools, aliases, &tag_ty); match unify(subs, actual, includes, Mode::PRESENT) { - Success(vars) => { + Success { + vars, + must_implement_ability: _, + } => { introduce(subs, rank, pools, &vars); state } - Failure(vars, actual_type, expected_to_include_type) => { + Failure(vars, actual_type, expected_to_include_type, _bad_impls) => { introduce(subs, rank, pools, &vars); let problem = TypeError::BadPattern( @@ -1156,6 +1202,92 @@ fn solve( state } +/// If a symbol claims to specialize an ability member, check that its solved type in fact +/// does specialize the ability, and record the specialization. +fn check_ability_specialization( + subs: &mut Subs, + env: &Env, + pools: &mut Pools, + rank: Rank, + abilities_store: &mut AbilitiesStore, + problems: &mut Vec, + deferred_must_implement_abilities: &mut Vec, + symbol: Symbol, + symbol_loc_var: Loc, +) { + // If the symbol specializes an ability member, we need to make sure that the + // inferred type for the specialization actually aligns with the expected + // implementation. + if let Some((root_symbol, root_data)) = abilities_store.root_name_and_def(symbol) { + let root_signature_var = env + .get_var_by_symbol(&root_symbol) + .expect("Ability should be registered in env by now!"); + + // Check if they unify - if they don't, that's a type error! + let snapshot = subs.snapshot(); + let unified = unify(subs, symbol_loc_var.value, root_signature_var, Mode::EQ); + + match unified { + Success { + vars: _, + must_implement_ability, + } => { + // We don't actually care about storing the unified type since the checked type for the + // specialization is what we want for code generation. + subs.rollback_to(snapshot); + + if must_implement_ability.is_empty() { + // This is an error.. but what kind? + } + + // First, figure out and register for what type does this symbol specialize + // the ability member. + let mut ability_implementations_for_specialization = must_implement_ability + .iter() + .filter(|mia| mia.ability == root_data.parent_ability) + .collect::>(); + ability_implementations_for_specialization.dedup(); + debug_assert_eq!( + ability_implementations_for_specialization.len(), 1, + "If there's more than one, the definition is ambiguous - this should be an error" + ); + + let specialization_type = ability_implementations_for_specialization[0].typ; + abilities_store.register_specialization_for_type(specialization_type, root_symbol); + + // Store the checks for what abilities must be implemented to be checked after the + // whole module is complete. + deferred_must_implement_abilities.extend(must_implement_ability); + } + Failure(vars, actual_type, expected_type, unimplemented_abilities) => { + subs.commit_snapshot(snapshot); + introduce(subs, rank, pools, &vars); + + let reason = Reason::InvalidAbilityMemberSpecialization { + member_name: root_symbol, + def_region: root_data.region, + unimplemented_abilities, + }; + + let problem = TypeError::BadExpr( + symbol_loc_var.region, + Category::AbilityMemberSpecialization(root_symbol), + actual_type, + Expected::ForReason(reason, expected_type, symbol_loc_var.region), + ); + + problems.push(problem); + } + BadType(vars, problem) => { + subs.commit_snapshot(snapshot); + introduce(subs, rank, pools, &vars); + + problems.push(TypeError::BadType(problem)); + } + } + } +} + #[derive(Debug)] enum LocalDefVarsVec { Stack(arrayvec::ArrayVec), @@ -1288,7 +1420,7 @@ impl RegisterVariable { use RegisterVariable::*; match typ { - Variable(var) => Direct(*var), + Type::Variable(var) => Direct(*var), EmptyRec => Direct(Variable::EMPTY_RECORD), EmptyTagUnion => Direct(Variable::EMPTY_TAG_UNION), Type::DelayedAlias(AliasCommon { symbol, .. }) => { @@ -2180,7 +2312,7 @@ fn adjust_rank_content( use roc_types::subs::FlatType::*; match content { - FlexVar(_) | RigidVar(_) | Error => group_rank, + FlexVar(_) | RigidVar(_) | FlexAbleVar(_, _) | RigidAbleVar(_, _) | Error => group_rank, RecursionVar { .. } => group_rank, @@ -2396,7 +2528,14 @@ fn instantiate_rigids_help(subs: &mut Subs, max_rank: Rank, initial: Variable) { desc.mark = Mark::NONE; desc.copy = OptVariable::NONE; } - FlexVar(_) | Error => (), + &RigidAbleVar(name, ability) => { + // Same as `RigidVar` above + desc.content = FlexAbleVar(Some(name), ability); + desc.rank = max_rank; + desc.mark = Mark::NONE; + desc.copy = OptVariable::NONE; + } + FlexVar(_) | FlexAbleVar(_, _) | Error => (), RecursionVar { structure, .. } => { stack.push(*structure); @@ -2684,7 +2823,7 @@ fn deep_copy_var_help( copy } - FlexVar(_) | Error => copy, + FlexVar(_) | FlexAbleVar(_, _) | Error => copy, RecursionVar { opt_name, @@ -2709,6 +2848,12 @@ fn deep_copy_var_help( copy } + RigidAbleVar(name, ability) => { + subs.set(copy, make_descriptor(FlexAbleVar(Some(name), ability))); + + copy + } + Alias(symbol, arguments, real_type_var, kind) => { let new_variables = SubsSlice::reserve_into_subs(subs, arguments.all_variables_len as _); diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index 7e3e2e8215..6a0205be68 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -10,20 +10,12 @@ mod helpers; #[cfg(test)] mod solve_expr { use crate::helpers::with_larger_debug_stack; + use roc_load::LoadedModule; use roc_types::pretty_print::{content_to_string, name_all_type_vars}; // HELPERS - fn infer_eq_help( - src: &str, - ) -> Result< - ( - Vec, - Vec, - String, - ), - std::io::Error, - > { + fn run_load_and_infer(src: &str) -> Result { use bumpalo::Bump; use std::fs::File; use std::io::Write; @@ -58,6 +50,7 @@ mod solve_expr { dir.path(), exposed_types, roc_target::TargetInfo::default_x86_64(), + roc_reporting::report::RenderTarget::Generic, ); dir.close()?; @@ -66,8 +59,19 @@ mod solve_expr { }; let loaded = loaded.expect("failed to load module"); + Ok(loaded) + } - use roc_load::LoadedModule; + fn infer_eq_help( + src: &str, + ) -> Result< + ( + Vec, + Vec, + String, + ), + std::io::Error, + > { let LoadedModule { module_id: home, mut can_problems, @@ -76,7 +80,7 @@ mod solve_expr { mut solved, exposed_to_host, .. - } = loaded; + } = run_load_and_infer(src)?; let mut can_problems = can_problems.remove(&home).unwrap_or_default(); let type_problems = type_problems.remove(&home).unwrap_or_default(); @@ -155,6 +159,51 @@ mod solve_expr { assert_eq!(actual, expected.to_string()); } + fn check_inferred_abilities<'a, I>(src: &'a str, expected_specializations: I) + where + I: IntoIterator, + { + let LoadedModule { + module_id: home, + mut can_problems, + mut type_problems, + interns, + abilities_store, + .. + } = run_load_and_infer(src).unwrap(); + + let can_problems = can_problems.remove(&home).unwrap_or_default(); + let type_problems = type_problems.remove(&home).unwrap_or_default(); + + assert_eq!(can_problems, Vec::new(), "Canonicalization problems: "); + + if !type_problems.is_empty() { + eprintln!("{:?}", type_problems); + panic!(); + } + + let known_specializations = abilities_store.get_known_specializations(); + use std::collections::HashSet; + let pretty_specializations = known_specializations + .into_iter() + .map(|(typ, member)| { + ( + typ.ident_str(&interns).as_str(), + member.ident_str(&interns).as_str(), + ) + }) + .collect::>(); + + for expected_spec in expected_specializations.into_iter() { + assert!( + pretty_specializations.contains(&expected_spec), + "{:#?} not in {:#?}", + expected_spec, + pretty_specializations, + ); + } + } + #[test] fn int_literal() { infer_eq("5", "Num *"); @@ -5710,4 +5759,85 @@ mod solve_expr { "a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, aa, bb -> { a : a, aa : aa, b : b, bb : bb, c : c, d : d, e : e, f : f, g : g, h : h, i : i, j : j, k : k, l : l, m : m, n : n, o : o, p : p, q : q, r : r, s : s, t : t, u : u, v : v, w : w, x : x, y : y, z : z }", ) } + + #[test] + fn exposed_ability_name() { + infer_eq_without_problem( + indoc!( + r#" + app "test" provides [ hash ] to "./platform" + + Hash has hash : a -> U64 | a has Hash + "# + ), + "a -> U64 | a has Hash", + ) + } + + #[test] + fn single_ability_single_member_specializations() { + check_inferred_abilities( + indoc!( + r#" + app "test" provides [ hash ] to "./platform" + + Hash has hash : a -> U64 | a has Hash + + Id := U64 + + hash = \$Id n -> n + "# + ), + [("Id", "hash")], + ) + } + + #[test] + fn single_ability_multiple_members_specializations() { + check_inferred_abilities( + indoc!( + r#" + app "test" provides [ hash, hash32 ] to "./platform" + + Hash has + hash : a -> U64 | a has Hash + hash32 : a -> U32 | a has Hash + + Id := U64 + + hash = \$Id n -> n + hash32 = \$Id n -> Num.toU32 n + "# + ), + [("Id", "hash"), ("Id", "hash32")], + ) + } + + #[test] + fn multiple_abilities_multiple_members_specializations() { + check_inferred_abilities( + indoc!( + r#" + app "test" provides [ hash, hash32, eq, le ] to "./platform" + + Hash has + hash : a -> U64 | a has Hash + hash32 : a -> U32 | a has Hash + + Ord has + eq : a, a -> Bool | a has Ord + le : a, a -> Bool | a has Ord + + Id := U64 + + hash = \$Id n -> n + hash32 = \$Id n -> Num.toU32 n + + eq = \$Id m, $Id n -> m == n + le = \$Id m, $Id n -> m < n + "# + ), + [("Id", "hash"), ("Id", "hash32"), ("Id", "eq"), ("Id", "le")], + ) + } } diff --git a/compiler/types/src/pretty_print.rs b/compiler/types/src/pretty_print.rs index ce6b338282..e4e8456fe3 100644 --- a/compiler/types/src/pretty_print.rs +++ b/compiler/types/src/pretty_print.rs @@ -116,7 +116,7 @@ fn find_names_needed( } match &subs.get_content_without_compacting(variable).clone() { - RecursionVar { opt_name: None, .. } | FlexVar(None) => { + RecursionVar { opt_name: None, .. } | FlexVar(None) | FlexAbleVar(None, _) => { let root = subs.get_root_key_without_compacting(variable); // If this var is *not* its own root, then the @@ -139,7 +139,8 @@ fn find_names_needed( opt_name: Some(name_index), .. } - | FlexVar(Some(name_index)) => { + | FlexVar(Some(name_index)) + | FlexAbleVar(Some(name_index), _) => { // This root already has a name. Nothing more to do here! // User-defined names are already taken. @@ -147,7 +148,7 @@ fn find_names_needed( let name = subs.field_names[name_index.index as usize].clone(); names_taken.insert(name); } - RigidVar(name_index) => { + RigidVar(name_index) | RigidAbleVar(name_index, _) => { // User-defined names are already taken. // We must not accidentally generate names that collide with them! let name = subs.field_names[name_index.index as usize].clone(); @@ -289,6 +290,11 @@ fn set_root_name(root: Variable, name: Lowercase, subs: &mut Subs) { } } +#[derive(Default)] +struct Context<'a> { + able_variables: Vec<(&'a str, Symbol)>, +} + pub fn content_to_string( content: &Content, subs: &Subs, @@ -297,8 +303,16 @@ pub fn content_to_string( ) -> String { let mut buf = String::new(); let env = Env { home, interns }; + let mut ctx = Context::default(); - write_content(&env, content, subs, &mut buf, Parens::Unnecessary); + write_content(&env, &mut ctx, content, subs, &mut buf, Parens::Unnecessary); + + for (i, (var, ability)) in ctx.able_variables.into_iter().enumerate() { + buf.push_str(if i == 0 { " | " } else { ", " }); + buf.push_str(var); + buf.push_str(" has "); + write_symbol(&env, ability, &mut buf); + } buf } @@ -314,7 +328,14 @@ pub fn get_single_arg<'a>(subs: &'a Subs, args: &'a AliasVariables) -> &'a Conte subs.get_content_without_compacting(arg_var) } -fn write_content(env: &Env, content: &Content, subs: &Subs, buf: &mut String, parens: Parens) { +fn write_content<'a>( + env: &Env, + ctx: &mut Context<'a>, + content: &Content, + subs: &'a Subs, + buf: &mut String, + parens: Parens, +) { use crate::subs::Content::*; match content { @@ -327,6 +348,18 @@ fn write_content(env: &Env, content: &Content, subs: &Subs, buf: &mut String, pa let name = &subs.field_names[name_index.index as usize]; buf.push_str(name.as_str()) } + FlexAbleVar(opt_name_index, ability) => { + let name = opt_name_index + .map(|name_index| subs.field_names[name_index.index as usize].as_str()) + .unwrap_or(WILDCARD); + ctx.able_variables.push((name, *ability)); + buf.push_str(name); + } + RigidAbleVar(name_index, ability) => { + let name = subs.field_names[name_index.index as usize].as_str(); + ctx.able_variables.push((name, *ability)); + buf.push_str(name); + } RecursionVar { opt_name, .. } => match opt_name { Some(name_index) => { let name = &subs.field_names[name_index.index as usize]; @@ -334,7 +367,7 @@ fn write_content(env: &Env, content: &Content, subs: &Subs, buf: &mut String, pa } None => buf.push_str(WILDCARD), }, - Structure(flat_type) => write_flat_type(env, flat_type, subs, buf, parens), + Structure(flat_type) => write_flat_type(env, ctx, flat_type, subs, buf, parens), Alias(symbol, args, _actual, _kind) => { let write_parens = parens == Parens::InTypeParam && !args.is_empty(); @@ -346,6 +379,7 @@ fn write_content(env: &Env, content: &Content, subs: &Subs, buf: &mut String, pa Symbol::NUM_INTEGER => { write_integer( env, + ctx, get_single_arg(subs, &args), subs, buf, @@ -357,13 +391,13 @@ fn write_content(env: &Env, content: &Content, subs: &Subs, buf: &mut String, pa _ => write_parens!(write_parens, buf, { buf.push_str("Num "); - write_content(env, content, subs, buf, parens); + write_content(env, ctx, content, subs, buf, parens); }), }, _ => write_parens!(write_parens, buf, { buf.push_str("Num "); - write_content(env, content, subs, buf, parens); + write_content(env, ctx, content, subs, buf, parens); }), } } @@ -371,7 +405,7 @@ fn write_content(env: &Env, content: &Content, subs: &Subs, buf: &mut String, pa Symbol::NUM_INT => { let content = get_single_arg(subs, args); - write_integer(env, content, subs, buf, parens, write_parens) + write_integer(env, ctx, content, subs, buf, parens, write_parens) } Symbol::NUM_FLOAT => { @@ -390,7 +424,7 @@ fn write_content(env: &Env, content: &Content, subs: &Subs, buf: &mut String, pa Alias(Symbol::NUM_DECIMAL, _, _, _) => buf.push_str("Dec"), _ => write_parens!(write_parens, buf, { buf.push_str("Float "); - write_content(env, content, subs, buf, parens); + write_content(env, ctx, content, subs, buf, parens); }), } } @@ -403,6 +437,7 @@ fn write_content(env: &Env, content: &Content, subs: &Subs, buf: &mut String, pa buf.push(' '); write_content( env, + ctx, subs.get_content_without_compacting(var), subs, buf, @@ -414,7 +449,7 @@ fn write_content(env: &Env, content: &Content, subs: &Subs, buf: &mut String, pa if false { buf.push_str("[[ but really "); let content = subs.get_content_without_compacting(*_actual); - write_content(env, content, subs, buf, parens); + write_content(env, ctx, content, subs, buf, parens); buf.push_str("]]"); } }), @@ -422,6 +457,7 @@ fn write_content(env: &Env, content: &Content, subs: &Subs, buf: &mut String, pa } RangedNumber(typ, _range_vars) => write_content( env, + ctx, subs.get_content_without_compacting(*typ), subs, buf, @@ -431,10 +467,11 @@ fn write_content(env: &Env, content: &Content, subs: &Subs, buf: &mut String, pa } } -fn write_integer( +fn write_integer<'a>( env: &Env, + ctx: &mut Context<'a>, content: &Content, - subs: &Subs, + subs: &'a Subs, buf: &mut String, parens: Parens, write_parens: bool, @@ -454,7 +491,7 @@ fn write_integer( )* actual => { buf.push_str("Int "); - write_content(env, actual, subs, buf, parens); + write_content(env, ctx, actual, subs, buf, parens); } } ) @@ -497,6 +534,7 @@ impl<'a> ExtContent<'a> { fn write_ext_content<'a>( env: &Env, + ctx: &mut Context<'a>, subs: &'a Subs, buf: &mut String, ext_content: ExtContent<'a>, @@ -508,12 +546,13 @@ fn write_ext_content<'a>( // // e.g. the "*" at the end of `{ x: I64 }*` // or the "r" at the end of `{ x: I64 }r` - write_content(env, content, subs, buf, parens) + write_content(env, ctx, content, subs, buf, parens) } } fn write_sorted_tags2<'a>( env: &Env, + ctx: &mut Context<'a>, subs: &'a Subs, buf: &mut String, tags: &UnionTags, @@ -546,6 +585,7 @@ fn write_sorted_tags2<'a>( buf.push(' '); write_content( env, + ctx, subs.get_content_without_compacting(*var), subs, buf, @@ -559,6 +599,7 @@ fn write_sorted_tags2<'a>( fn write_sorted_tags<'a>( env: &Env, + ctx: &mut Context<'a>, subs: &'a Subs, buf: &mut String, tags: &MutMap>, @@ -603,6 +644,7 @@ fn write_sorted_tags<'a>( buf.push(' '); write_content( env, + ctx, subs.get_content_without_compacting(*var), subs, buf, @@ -614,18 +656,37 @@ fn write_sorted_tags<'a>( ExtContent::from_var(subs, ext_var) } -fn write_flat_type(env: &Env, flat_type: &FlatType, subs: &Subs, buf: &mut String, parens: Parens) { +fn write_flat_type<'a>( + env: &Env, + ctx: &mut Context<'a>, + flat_type: &FlatType, + subs: &'a Subs, + buf: &mut String, + parens: Parens, +) { use crate::subs::FlatType::*; match flat_type { - Apply(symbol, args) => { - write_apply(env, *symbol, subs.get_subs_slice(*args), subs, buf, parens) - } + Apply(symbol, args) => write_apply( + env, + ctx, + *symbol, + subs.get_subs_slice(*args), + subs, + buf, + parens, + ), EmptyRecord => buf.push_str(EMPTY_RECORD), EmptyTagUnion => buf.push_str(EMPTY_TAG_UNION), - Func(args, _closure, ret) => { - write_fn(env, subs.get_subs_slice(*args), *ret, subs, buf, parens) - } + Func(args, _closure, ret) => write_fn( + env, + ctx, + subs.get_subs_slice(*args), + *ret, + subs, + buf, + parens, + ), Record(fields, ext_var) => { use crate::types::{gather_fields, RecordStructure}; @@ -664,6 +725,7 @@ fn write_flat_type(env: &Env, flat_type: &FlatType, subs: &Subs, buf: &mut Strin write_content( env, + ctx, subs.get_content_without_compacting(var), subs, buf, @@ -684,18 +746,18 @@ fn write_flat_type(env: &Env, flat_type: &FlatType, subs: &Subs, buf: &mut Strin // // e.g. the "*" at the end of `{ x: I64 }*` // or the "r" at the end of `{ x: I64 }r` - write_content(env, content, subs, buf, parens) + write_content(env, ctx, content, subs, buf, parens) } } } TagUnion(tags, ext_var) => { buf.push_str("[ "); - let ext_content = write_sorted_tags2(env, subs, buf, tags, *ext_var); + let ext_content = write_sorted_tags2(env, ctx, subs, buf, tags, *ext_var); buf.push_str(" ]"); - write_ext_content(env, subs, buf, ext_content, parens) + write_ext_content(env, ctx, subs, buf, ext_content, parens) } FunctionOrTagUnion(tag_name, _, ext_var) => { @@ -703,25 +765,26 @@ fn write_flat_type(env: &Env, flat_type: &FlatType, subs: &Subs, buf: &mut Strin let mut tags: MutMap = MutMap::default(); tags.insert(subs[*tag_name].clone(), vec![]); - let ext_content = write_sorted_tags(env, subs, buf, &tags, *ext_var); + let ext_content = write_sorted_tags(env, ctx, subs, buf, &tags, *ext_var); buf.push_str(" ]"); - write_ext_content(env, subs, buf, ext_content, parens) + write_ext_content(env, ctx, subs, buf, ext_content, parens) } RecursiveTagUnion(rec_var, tags, ext_var) => { buf.push_str("[ "); - let ext_content = write_sorted_tags2(env, subs, buf, tags, *ext_var); + let ext_content = write_sorted_tags2(env, ctx, subs, buf, tags, *ext_var); buf.push_str(" ]"); - write_ext_content(env, subs, buf, ext_content, parens); + write_ext_content(env, ctx, subs, buf, ext_content, parens); buf.push_str(" as "); write_content( env, + ctx, subs.get_content_without_compacting(*rec_var), subs, buf, @@ -777,11 +840,12 @@ pub fn chase_ext_tag_union<'a>( } } -fn write_apply( +fn write_apply<'a>( env: &Env, + ctx: &mut Context<'a>, symbol: Symbol, args: &[Variable], - subs: &Subs, + subs: &'a Subs, buf: &mut String, parens: Parens, ) { @@ -805,7 +869,7 @@ fn write_apply( buf.push('('); } - write_content(env, content, subs, &mut arg_param, Parens::InTypeParam); + write_content(env, ctx, content, subs, &mut arg_param, Parens::InTypeParam); buf.push_str("Num "); buf.push_str(&arg_param); @@ -838,6 +902,7 @@ fn write_apply( buf.push(' '); write_content( env, + ctx, subs.get_content_without_compacting(*arg), subs, buf, @@ -852,11 +917,12 @@ fn write_apply( } } -fn write_fn( +fn write_fn<'a>( env: &Env, + ctx: &mut Context<'a>, args: &[Variable], ret: Variable, - subs: &Subs, + subs: &'a Subs, buf: &mut String, parens: Parens, ) { @@ -876,6 +942,7 @@ fn write_fn( write_content( env, + ctx, subs.get_content_without_compacting(*arg), subs, buf, @@ -886,6 +953,7 @@ fn write_fn( buf.push_str(" -> "); write_content( env, + ctx, subs.get_content_without_compacting(ret), subs, buf, diff --git a/compiler/types/src/subs.rs b/compiler/types/src/subs.rs index 36f0ac811d..8d10405afd 100644 --- a/compiler/types/src/subs.rs +++ b/compiler/types/src/subs.rs @@ -754,7 +754,9 @@ impl<'a> fmt::Debug for SubsFmtContent<'a> { fn subs_fmt_content(this: &Content, subs: &Subs, f: &mut fmt::Formatter) -> fmt::Result { match this { Content::FlexVar(name) => write!(f, "Flex({:?})", name), + Content::FlexAbleVar(name, symbol) => write!(f, "FlexAble({:?}, {:?})", name, symbol), Content::RigidVar(name) => write!(f, "Rigid({:?})", name), + Content::RigidAbleVar(name, symbol) => write!(f, "RigidAble({:?}, {:?})", name, symbol), Content::RecursionVar { structure, opt_name, @@ -794,7 +796,19 @@ fn subs_fmt_flat_type(this: &FlatType, subs: &Subs, f: &mut fmt::Formatter) -> f } FlatType::Func(arguments, lambda_set, result) => { let slice = subs.get_subs_slice(*arguments); - write!(f, "Func({:?}, {:?}, {:?})", slice, lambda_set, result) + write!(f, "Func([")?; + for var in slice { + let content = subs.get_content_without_compacting(*var); + write!(f, "<{:?}>{:?},", *var, SubsFmtContent(content, subs))?; + } + let result_content = subs.get_content_without_compacting(*result); + write!( + f, + "], {:?}, <{:?}>{:?})", + lambda_set, + *result, + SubsFmtContent(result_content, subs) + ) } FlatType::Record(fields, ext) => { write!(f, "{{ ")?; @@ -1737,6 +1751,14 @@ impl Subs { self.set(var, desc); } + pub fn rigid_able_var(&mut self, var: Variable, name: Lowercase, ability: Symbol) { + let name_index = SubsIndex::push_new(&mut self.field_names, name); + let content = Content::RigidAbleVar(name_index, ability); + let desc = Descriptor::from(content); + + self.set(var, desc); + } + /// Unions two keys without the possibility of failure. pub fn union(&mut self, left: Variable, right: Variable, desc: Descriptor) { let l_root = self.utable.inlined_get_root_key(left); @@ -2118,6 +2140,12 @@ pub enum Content { FlexVar(Option>), /// name given in a user-written annotation RigidVar(SubsIndex), + /// Like a [Self::FlexVar], but is also bound to an ability. + /// This can only happen when unified with a [Self::RigidAbleVar]. + FlexAbleVar(Option>, Symbol), + /// Like a [Self::RigidVar], but is also bound to an ability. + /// For example, "a has Hash". + RigidAbleVar(SubsIndex, Symbol), /// name given to a recursion variable RecursionVar { structure: Variable, @@ -2838,7 +2866,12 @@ fn occurs( Err((root_var, vec![])) } else { match subs.get_content_without_compacting(root_var) { - FlexVar(_) | RigidVar(_) | RecursionVar { .. } | Error => Ok(()), + FlexVar(_) + | RigidVar(_) + | FlexAbleVar(_, _) + | RigidAbleVar(_, _) + | RecursionVar { .. } + | Error => Ok(()), Structure(flat_type) => { let mut new_seen = seen.to_owned(); @@ -2966,7 +2999,12 @@ fn explicit_substitute( to } else { match subs.get(in_var).content { - FlexVar(_) | RigidVar(_) | RecursionVar { .. } | Error => in_var, + FlexVar(_) + | RigidVar(_) + | FlexAbleVar(_, _) + | RigidAbleVar(_, _) + | RecursionVar { .. } + | Error => in_var, Structure(flat_type) => { match flat_type { @@ -3134,9 +3172,9 @@ fn get_var_names( subs.set_mark(var, Mark::GET_VAR_NAMES); match desc.content { - Error | FlexVar(None) => taken_names, + Error | FlexVar(None) | FlexAbleVar(None, _) => taken_names, - FlexVar(Some(name_index)) => add_name( + FlexVar(Some(name_index)) | FlexAbleVar(Some(name_index), _) => add_name( subs, 0, name_index, @@ -3163,7 +3201,9 @@ fn get_var_names( None => taken_names, }, - RigidVar(name_index) => add_name(subs, 0, name_index, var, RigidVar, taken_names), + RigidVar(name_index) | RigidAbleVar(name_index, _) => { + add_name(subs, 0, name_index, var, RigidVar, taken_names) + } Alias(_, args, _, _) => args.into_iter().fold(taken_names, |answer, arg_var| { get_var_names(subs, subs[arg_var], answer) @@ -3329,11 +3369,6 @@ fn content_to_err_type( match content { Structure(flat_type) => flat_type_to_err_type(subs, state, flat_type), - FlexVar(Some(name_index)) => { - let name = subs.field_names[name_index.index as usize].clone(); - ErrorType::FlexVar(name) - } - FlexVar(opt_name) => { let name = match opt_name { Some(name_index) => subs.field_names[name_index.index as usize].clone(), @@ -3356,6 +3391,28 @@ fn content_to_err_type( ErrorType::RigidVar(name) } + FlexAbleVar(opt_name, ability) => { + let name = match opt_name { + Some(name_index) => subs.field_names[name_index.index as usize].clone(), + None => { + // set the name so when this variable occurs elsewhere in the type it gets the same name + let name = get_fresh_var_name(state); + let name_index = SubsIndex::push_new(&mut subs.field_names, name.clone()); + + subs.set_content(var, FlexVar(Some(name_index))); + + name + } + }; + + ErrorType::FlexAbleVar(name, ability) + } + + RigidAbleVar(name_index, ability) => { + let name = subs.field_names[name_index.index as usize].clone(); + ErrorType::RigidAbleVar(name, ability) + } + RecursionVar { opt_name, .. } => { let name = match opt_name { Some(name_index) => subs.field_names[name_index.index as usize].clone(), @@ -3628,7 +3685,7 @@ fn restore_help(subs: &mut Subs, initial: Variable) { use FlatType::*; match &desc.content { - FlexVar(_) | RigidVar(_) | Error => (), + FlexVar(_) | RigidVar(_) | FlexAbleVar(_, _) | RigidAbleVar(_, _) | Error => (), RecursionVar { structure, .. } => { stack.push(*structure); @@ -3857,6 +3914,8 @@ impl StorageSubs { match content { FlexVar(opt_name) => FlexVar(*opt_name), RigidVar(name) => RigidVar(*name), + FlexAbleVar(opt_name, ability) => FlexAbleVar(*opt_name, *ability), + RigidAbleVar(name, ability) => RigidAbleVar(*name, *ability), RecursionVar { structure, opt_name, @@ -4253,6 +4312,29 @@ fn deep_copy_var_to_help(env: &mut DeepCopyVarToEnv<'_>, var: Variable) -> Varia copy } + FlexAbleVar(opt_name_index, ability) => { + let new_name_index = opt_name_index.map(|name_index| { + let name = env.source.field_names[name_index.index as usize].clone(); + SubsIndex::push_new(&mut env.target.field_names, name) + }); + + let content = FlexAbleVar(new_name_index, ability); + env.target.set_content(copy, content); + + copy + } + + RigidAbleVar(name_index, ability) => { + let name = env.source.field_names[name_index.index as usize].clone(); + let new_name_index = SubsIndex::push_new(&mut env.target.field_names, name); + env.target.set( + copy, + make_descriptor(FlexAbleVar(Some(new_name_index), ability)), + ); + + copy + } + Alias(symbol, arguments, real_type_var, kind) => { let new_variables = SubsSlice::reserve_into_subs(env.target, arguments.all_variables_len as _); @@ -4312,6 +4394,8 @@ pub struct CopiedImport { pub variable: Variable, pub flex: Vec, pub rigid: Vec, + pub flex_able: Vec, + pub rigid_able: Vec, pub translations: Vec<(Variable, Variable)>, pub registered: Vec, } @@ -4322,6 +4406,8 @@ struct CopyImportEnv<'a> { target: &'a mut Subs, flex: Vec, rigid: Vec, + flex_able: Vec, + rigid_able: Vec, translations: Vec<(Variable, Variable)>, registered: Vec, } @@ -4343,6 +4429,8 @@ pub fn copy_import_to( target, flex: Vec::new(), rigid: Vec::new(), + flex_able: Vec::new(), + rigid_able: Vec::new(), translations: Vec::new(), registered: Vec::new(), }; @@ -4354,6 +4442,8 @@ pub fn copy_import_to( source, flex, rigid, + flex_able, + rigid_able, translations, registered, target: _, @@ -4376,6 +4466,8 @@ pub fn copy_import_to( variable: copy, flex, rigid, + flex_able, + rigid_able, translations, registered, } @@ -4393,7 +4485,10 @@ pub fn copy_import_to( /// standard variables fn is_registered(content: &Content) -> bool { match content { - Content::FlexVar(_) | Content::RigidVar(_) => false, + Content::FlexVar(_) + | Content::RigidVar(_) + | Content::FlexAbleVar(..) + | Content::RigidAbleVar(..) => false, Content::Structure(FlatType::EmptyRecord | FlatType::EmptyTagUnion) => false, Content::Structure(_) @@ -4631,6 +4726,20 @@ fn copy_import_to_help(env: &mut CopyImportEnv<'_>, max_rank: Rank, var: Variabl copy } + FlexAbleVar(opt_name_index, ability) => { + if let Some(name_index) = opt_name_index { + let name = env.source.field_names[name_index.index as usize].clone(); + let new_name_index = SubsIndex::push_new(&mut env.target.field_names, name); + + let content = FlexAbleVar(Some(new_name_index), ability); + env.target.set_content(copy, content); + } + + env.flex_able.push(copy); + + copy + } + Error => { // Open question: should this return Error, or a Flex var? @@ -4653,6 +4762,20 @@ fn copy_import_to_help(env: &mut CopyImportEnv<'_>, max_rank: Rank, var: Variabl copy } + RigidAbleVar(name_index, ability) => { + let name = env.source.field_names[name_index.index as usize].clone(); + let new_name_index = SubsIndex::push_new(&mut env.target.field_names, name); + + env.target + .set(copy, make_descriptor(RigidAbleVar(new_name_index, ability))); + + env.rigid_able.push(copy); + + env.translations.push((var, copy)); + + copy + } + RecursionVar { opt_name, structure, @@ -4746,7 +4869,7 @@ where use Content::*; use FlatType::*; match content { - FlexVar(_) | RigidVar(_) => {} + FlexVar(_) | RigidVar(_) | FlexAbleVar(_, _) | RigidAbleVar(_, _) => {} RecursionVar { structure, opt_name: _, diff --git a/compiler/types/src/types.rs b/compiler/types/src/types.rs index eca1b3bc66..846ef8817d 100644 --- a/compiler/types/src/types.rs +++ b/compiler/types/src/types.rs @@ -1744,6 +1744,11 @@ pub enum Reason { RecordUpdateKeys(Symbol, SendMap), RecordDefaultField(Lowercase), NumericLiteralSuffix, + InvalidAbilityMemberSpecialization { + member_name: Symbol, + def_region: Region, + unimplemented_abilities: DoesNotImplementAbility, + }, } #[derive(PartialEq, Debug, Clone)] @@ -1783,6 +1788,8 @@ pub enum Category { Accessor(Lowercase), Access(Lowercase), DefaultValue(Lowercase), // for setting optional fields + + AbilityMemberSpecialization(Symbol), } #[derive(Debug, Clone, PartialEq, Eq)] @@ -1867,14 +1874,19 @@ pub enum Mismatch { InconsistentWhenBranches, CanonicalizationProblem, TypeNotInRange, + DoesNotImplementAbiity(Variable, Symbol), } +pub type DoesNotImplementAbility = Vec<(ErrorType, Symbol)>; + #[derive(PartialEq, Eq, Clone, Hash)] pub enum ErrorType { Infinite, Type(Symbol, Vec), FlexVar(Lowercase), RigidVar(Lowercase), + FlexAbleVar(Lowercase, Symbol), + RigidAbleVar(Lowercase, Symbol), Record(SendMap>, TypeExt), TagUnion(SendMap>, TypeExt), RecursiveTagUnion(Box, SendMap>, TypeExt), @@ -1905,10 +1917,7 @@ impl ErrorType { match self { Infinite => {} Type(_, ts) => ts.iter().for_each(|t| t.add_names(taken)), - FlexVar(v) => { - taken.insert(v.clone()); - } - RigidVar(v) => { + FlexVar(v) | RigidVar(v) | FlexAbleVar(v, _) | RigidAbleVar(v, _) => { taken.insert(v.clone()); } Record(fields, ext) => { @@ -2087,8 +2096,18 @@ fn write_debug_error_type_help(error_type: ErrorType, buf: &mut String, parens: match error_type { Infinite => buf.push('∞'), Error => buf.push('?'), - FlexVar(name) => buf.push_str(name.as_str()), - RigidVar(name) => buf.push_str(name.as_str()), + FlexVar(name) | RigidVar(name) => buf.push_str(name.as_str()), + FlexAbleVar(name, symbol) | RigidAbleVar(name, symbol) => { + let write_parens = parens == Parens::InTypeParam; + if write_parens { + buf.push('('); + } + buf.push_str(name.as_str()); + buf.push_str(&format!(" has {:?}", symbol)); + if write_parens { + buf.push(')'); + } + } Type(symbol, arguments) => { let write_parens = parens == Parens::InTypeParam && !arguments.is_empty(); diff --git a/compiler/unify/src/unify.rs b/compiler/unify/src/unify.rs index 82a96045b5..a586cdaed7 100644 --- a/compiler/unify/src/unify.rs +++ b/compiler/unify/src/unify.rs @@ -1,4 +1,5 @@ use bitflags::bitflags; +use roc_error_macros::todo_abilities; use roc_module::ident::{Lowercase, TagName}; use roc_module::symbol::Symbol; use roc_types::subs::Content::{self, *}; @@ -6,7 +7,7 @@ use roc_types::subs::{ AliasVariables, Descriptor, ErrorTypeContext, FlatType, GetSubsSlice, Mark, OptVariable, RecordFields, Subs, SubsIndex, SubsSlice, UnionTags, Variable, VariableSubsSlice, }; -use roc_types::types::{AliasKind, ErrorType, Mismatch, RecordField}; +use roc_types::types::{AliasKind, DoesNotImplementAbility, ErrorType, Mismatch, RecordField}; macro_rules! mismatch { () => {{ @@ -19,7 +20,10 @@ macro_rules! mismatch { ); } - vec![Mismatch::TypeMismatch] + Outcome { + mismatches: vec![Mismatch::TypeMismatch], + ..Outcome::default() + } }}; ($msg:expr) => {{ if cfg!(debug_assertions) && std::env::var("ROC_PRINT_MISMATCHES").is_ok() { @@ -34,7 +38,10 @@ macro_rules! mismatch { } - vec![Mismatch::TypeMismatch] + Outcome { + mismatches: vec![Mismatch::TypeMismatch], + ..Outcome::default() + } }}; ($msg:expr,) => {{ mismatch!($msg) @@ -51,8 +58,28 @@ macro_rules! mismatch { println!(""); } - vec![Mismatch::TypeMismatch] + Outcome { + mismatches: vec![Mismatch::TypeMismatch], + ..Outcome::default() + } }}; + (%not_able, $var:expr, $ability:expr, $msg:expr, $($arg:tt)*) => {{ + if cfg!(debug_assertions) && std::env::var("ROC_PRINT_MISMATCHES").is_ok() { + println!( + "Mismatch in {} Line {} Column {}", + file!(), + line!(), + column!() + ); + println!($msg, $($arg)*); + println!(""); + } + + Outcome { + mismatches: vec![Mismatch::TypeMismatch, Mismatch::DoesNotImplementAbiity($var, $ability)], + ..Outcome::default() + } + }} } type Pool = Vec; @@ -105,20 +132,52 @@ pub struct Context { #[derive(Debug)] pub enum Unified { - Success(Pool), - Failure(Pool, ErrorType, ErrorType), + Success { + vars: Pool, + must_implement_ability: Vec, + }, + Failure(Pool, ErrorType, ErrorType, DoesNotImplementAbility), BadType(Pool, roc_types::types::Problem), } -type Outcome = Vec; +/// Specifies that `type` must implement the ability `ability`. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct MustImplementAbility { + // This only points to opaque type names currently. + // TODO(abilities) support structural types in general + pub typ: Symbol, + pub ability: Symbol, +} + +#[derive(Debug, Default)] +pub struct Outcome { + mismatches: Vec, + /// We defer these checks until the end of a solving phase. + /// NOTE: this vector is almost always empty! + must_implement_ability: Vec, +} + +impl Outcome { + fn union(&mut self, other: Self) { + self.mismatches.extend(other.mismatches); + self.must_implement_ability + .extend(other.must_implement_ability); + } +} #[inline(always)] pub fn unify(subs: &mut Subs, var1: Variable, var2: Variable, mode: Mode) -> Unified { let mut vars = Vec::new(); - let mismatches = unify_pool(subs, &mut vars, var1, var2, mode); + let Outcome { + mismatches, + must_implement_ability, + } = unify_pool(subs, &mut vars, var1, var2, mode); if mismatches.is_empty() { - Unified::Success(vars) + Unified::Success { + vars, + must_implement_ability, + } } else { let error_context = if mismatches.contains(&Mismatch::TypeNotInRange) { ErrorTypeContext::ExpandRanges @@ -136,7 +195,19 @@ pub fn unify(subs: &mut Subs, var1: Variable, var2: Variable, mode: Mode) -> Uni if !problems.is_empty() { Unified::BadType(vars, problems.remove(0)) } else { - Unified::Failure(vars, type1, type2) + let do_not_implement_ability = mismatches + .into_iter() + .filter_map(|mismatch| match mismatch { + Mismatch::DoesNotImplementAbiity(var, ab) => { + let (err_type, _new_problems) = + subs.var_to_error_type_contextual(var, error_context); + Some((err_type, ab)) + } + _ => None, + }) + .collect(); + + Unified::Failure(vars, type1, type2, do_not_implement_ability) } } } @@ -150,7 +221,7 @@ pub fn unify_pool( mode: Mode, ) -> Outcome { if subs.equivalent(var1, var2) { - Vec::new() + Outcome::default() } else { let ctx = Context { first: var1, @@ -191,7 +262,14 @@ fn unify_context(subs: &mut Subs, pool: &mut Pool, ctx: Context) -> Outcome { ); } match &ctx.first_desc.content { - FlexVar(opt_name) => unify_flex(subs, &ctx, opt_name, &ctx.second_desc.content), + FlexVar(opt_name) => unify_flex(subs, &ctx, opt_name, None, &ctx.second_desc.content), + FlexAbleVar(opt_name, ability) => unify_flex( + subs, + &ctx, + opt_name, + Some(*ability), + &ctx.second_desc.content, + ), RecursionVar { opt_name, structure, @@ -203,7 +281,10 @@ fn unify_context(subs: &mut Subs, pool: &mut Pool, ctx: Context) -> Outcome { *structure, &ctx.second_desc.content, ), - RigidVar(name) => unify_rigid(subs, &ctx, name, &ctx.second_desc.content), + RigidVar(name) => unify_rigid(subs, &ctx, name, None, &ctx.second_desc.content), + RigidAbleVar(name, ability) => { + unify_rigid(subs, &ctx, name, Some(*ability), &ctx.second_desc.content) + } Structure(flat_type) => { unify_structure(subs, pool, &ctx, flat_type, &ctx.second_desc.content) } @@ -238,7 +319,7 @@ fn unify_ranged_number( } &RangedNumber(other_real_var, other_range_vars) => { let outcome = unify_pool(subs, pool, real_var, other_real_var, ctx.mode); - if outcome.is_empty() { + if outcome.mismatches.is_empty() { check_valid_range(subs, pool, ctx.first, other_range_vars, ctx.mode) } else { outcome @@ -246,9 +327,12 @@ fn unify_ranged_number( // TODO: We should probably check that "range_vars" and "other_range_vars" intersect } Error => merge(subs, ctx, Error), + FlexAbleVar(..) | RigidAbleVar(..) => { + todo_abilities!("I don't think this can be reached yet") + } }; - if !outcome.is_empty() { + if !outcome.mismatches.is_empty() { return outcome; } @@ -269,11 +353,11 @@ fn check_valid_range( let snapshot = subs.snapshot(); let old_pool = pool.clone(); let outcome = unify_pool(subs, pool, var, possible_var, mode | Mode::RIGID_AS_FLEX); - if outcome.is_empty() { + if outcome.mismatches.is_empty() { // Okay, we matched some type in the range. subs.rollback_to(snapshot); *pool = old_pool; - return vec![]; + return Outcome::default(); } else if it.peek().is_some() { // We failed to match something in the range, but there are still things we can try. subs.rollback_to(snapshot); @@ -283,7 +367,10 @@ fn check_valid_range( } } - return vec![Mismatch::TypeNotInRange]; + Outcome { + mismatches: vec![Mismatch::TypeNotInRange], + ..Outcome::default() + } } #[inline(always)] @@ -310,13 +397,19 @@ fn unify_alias( unify_pool(subs, pool, real_var, *structure, ctx.mode) } RigidVar(_) => unify_pool(subs, pool, real_var, ctx.second, ctx.mode), + RigidAbleVar (_, ability) | FlexAbleVar(_, ability) if kind == AliasKind::Opaque && args.is_empty() => { + // Opaque type wins + let mut outcome = merge(subs, ctx, Alias(symbol, args, real_var, kind)); + outcome.must_implement_ability.push(MustImplementAbility { typ: symbol, ability: *ability }); + outcome + } Alias(other_symbol, other_args, other_real_var, _) // Opaques types are only equal if the opaque symbols are equal! if !either_is_opaque || symbol == *other_symbol => { if symbol == *other_symbol { if args.len() == other_args.len() { - let mut problems = Vec::new(); + let mut outcome = Outcome::default(); let it = args .all_variables() .into_iter() @@ -327,23 +420,23 @@ fn unify_alias( for (l, r) in it { let l_var = subs[l]; let r_var = subs[r]; - problems.extend(unify_pool(subs, pool, l_var, r_var, ctx.mode)); + outcome.union(unify_pool(subs, pool, l_var, r_var, ctx.mode)); } - if problems.is_empty() { - problems.extend(merge(subs, ctx, *other_content)); + if outcome.mismatches.is_empty() { + outcome.union(merge(subs, ctx, *other_content)); } let args_unification_had_changes = !subs.vars_since_snapshot(&args_unification_snapshot).is_empty(); subs.commit_snapshot(args_unification_snapshot); - if !args.is_empty() && args_unification_had_changes && problems.is_empty() { + if !args.is_empty() && args_unification_had_changes && outcome.mismatches.is_empty() { // We need to unify the real vars because unification of type variables // may have made them larger, which then needs to be reflected in the `real_var`. - problems.extend(unify_pool(subs, pool, real_var, *other_real_var, ctx.mode)); + outcome.union(unify_pool(subs, pool, real_var, *other_real_var, ctx.mode)); } - problems + outcome } else { dbg!(args.len(), other_args.len()); mismatch!("{:?}", symbol) @@ -355,7 +448,7 @@ fn unify_alias( Structure(_) if !either_is_opaque => unify_pool(subs, pool, real_var, ctx.second, ctx.mode), RangedNumber(other_real_var, other_range_vars) if !either_is_opaque => { let outcome = unify_pool(subs, pool, real_var, *other_real_var, ctx.mode); - if outcome.is_empty() { + if outcome.mismatches.is_empty() { check_valid_range(subs, pool, real_var, *other_range_vars, ctx.mode) } else { outcome @@ -448,13 +541,31 @@ fn unify_structure( }, RangedNumber(other_real_var, other_range_vars) => { let outcome = unify_pool(subs, pool, ctx.first, *other_real_var, ctx.mode); - if outcome.is_empty() { + if outcome.mismatches.is_empty() { check_valid_range(subs, pool, ctx.first, *other_range_vars, ctx.mode) } else { outcome } } Error => merge(subs, ctx, Error), + + FlexAbleVar(_, ability) => { + // TODO(abilities) support structural types in ability bounds + mismatch!( + %not_able, ctx.first, *ability, + "trying to unify {:?} with FlexAble {:?}", + &flat_type, + &other + ) + } + RigidAbleVar(_, ability) => { + mismatch!( + %not_able, ctx.first, *ability, + "trying to unify {:?} with RigidAble {:?}", + &flat_type, + &other + ) + } } } @@ -474,29 +585,29 @@ fn unify_record( if separate.only_in_1.is_empty() { if separate.only_in_2.is_empty() { // these variable will be the empty record, but we must still unify them - let ext_problems = unify_pool(subs, pool, ext1, ext2, ctx.mode); + let ext_outcome = unify_pool(subs, pool, ext1, ext2, ctx.mode); - if !ext_problems.is_empty() { - return ext_problems; + if !ext_outcome.mismatches.is_empty() { + return ext_outcome; } - let mut field_problems = + let mut field_outcome = unify_shared_fields(subs, pool, ctx, shared_fields, OtherFields::None, ext1); - field_problems.extend(ext_problems); + field_outcome.union(ext_outcome); - field_problems + field_outcome } else { let only_in_2 = RecordFields::insert_into_subs(subs, separate.only_in_2); let flat_type = FlatType::Record(only_in_2, ext2); let sub_record = fresh(subs, pool, ctx, Structure(flat_type)); - let ext_problems = unify_pool(subs, pool, ext1, sub_record, ctx.mode); + let ext_outcome = unify_pool(subs, pool, ext1, sub_record, ctx.mode); - if !ext_problems.is_empty() { - return ext_problems; + if !ext_outcome.mismatches.is_empty() { + return ext_outcome; } - let mut field_problems = unify_shared_fields( + let mut field_outcome = unify_shared_fields( subs, pool, ctx, @@ -505,21 +616,21 @@ fn unify_record( sub_record, ); - field_problems.extend(ext_problems); + field_outcome.union(ext_outcome); - field_problems + field_outcome } } else if separate.only_in_2.is_empty() { let only_in_1 = RecordFields::insert_into_subs(subs, separate.only_in_1); let flat_type = FlatType::Record(only_in_1, ext1); let sub_record = fresh(subs, pool, ctx, Structure(flat_type)); - let ext_problems = unify_pool(subs, pool, sub_record, ext2, ctx.mode); + let ext_outcome = unify_pool(subs, pool, sub_record, ext2, ctx.mode); - if !ext_problems.is_empty() { - return ext_problems; + if !ext_outcome.mismatches.is_empty() { + return ext_outcome; } - let mut field_problems = unify_shared_fields( + let mut field_outcome = unify_shared_fields( subs, pool, ctx, @@ -528,9 +639,9 @@ fn unify_record( sub_record, ); - field_problems.extend(ext_problems); + field_outcome.union(ext_outcome); - field_problems + field_outcome } else { let only_in_1 = RecordFields::insert_into_subs(subs, separate.only_in_1); let only_in_2 = RecordFields::insert_into_subs(subs, separate.only_in_2); @@ -544,24 +655,26 @@ fn unify_record( let sub1 = fresh(subs, pool, ctx, Structure(flat_type1)); let sub2 = fresh(subs, pool, ctx, Structure(flat_type2)); - let rec1_problems = unify_pool(subs, pool, ext1, sub2, ctx.mode); - if !rec1_problems.is_empty() { - return rec1_problems; + let rec1_outcome = unify_pool(subs, pool, ext1, sub2, ctx.mode); + if !rec1_outcome.mismatches.is_empty() { + return rec1_outcome; } - let rec2_problems = unify_pool(subs, pool, sub1, ext2, ctx.mode); - if !rec2_problems.is_empty() { - return rec2_problems; + let rec2_outcome = unify_pool(subs, pool, sub1, ext2, ctx.mode); + if !rec2_outcome.mismatches.is_empty() { + return rec2_outcome; } - let mut field_problems = + let mut field_outcome = unify_shared_fields(subs, pool, ctx, shared_fields, other_fields, ext); - field_problems.reserve(rec1_problems.len() + rec2_problems.len()); - field_problems.extend(rec1_problems); - field_problems.extend(rec2_problems); + field_outcome + .mismatches + .reserve(rec1_outcome.mismatches.len() + rec2_outcome.mismatches.len()); + field_outcome.union(rec1_outcome); + field_outcome.union(rec2_outcome); - field_problems + field_outcome } } @@ -584,7 +697,7 @@ fn unify_shared_fields( let num_shared_fields = shared_fields.len(); for (name, (actual, expected)) in shared_fields { - let local_problems = unify_pool( + let local_outcome = unify_pool( subs, pool, actual.into_inner(), @@ -592,7 +705,7 @@ fn unify_shared_fields( ctx.mode, ); - if local_problems.is_empty() { + if local_outcome.mismatches.is_empty() { use RecordField::*; // Unification of optional fields @@ -856,18 +969,18 @@ fn unify_tag_union_new( if separate.only_in_1.is_empty() { if separate.only_in_2.is_empty() { - let ext_problems = if ctx.mode.is_eq() { + let ext_outcome = if ctx.mode.is_eq() { unify_pool(subs, pool, ext1, ext2, ctx.mode) } else { // In a presence context, we don't care about ext2 being equal to ext1 - vec![] + Outcome::default() }; - if !ext_problems.is_empty() { - return ext_problems; + if !ext_outcome.mismatches.is_empty() { + return ext_outcome; } - let mut tag_problems = unify_shared_tags_new( + let mut shared_tags_outcome = unify_shared_tags_new( subs, pool, ctx, @@ -877,20 +990,20 @@ fn unify_tag_union_new( recursion_var, ); - tag_problems.extend(ext_problems); + shared_tags_outcome.union(ext_outcome); - tag_problems + shared_tags_outcome } else { let unique_tags2 = UnionTags::insert_slices_into_subs(subs, separate.only_in_2); let flat_type = FlatType::TagUnion(unique_tags2, ext2); let sub_record = fresh(subs, pool, ctx, Structure(flat_type)); - let ext_problems = unify_pool(subs, pool, ext1, sub_record, ctx.mode); + let ext_outcome = unify_pool(subs, pool, ext1, sub_record, ctx.mode); - if !ext_problems.is_empty() { - return ext_problems; + if !ext_outcome.mismatches.is_empty() { + return ext_outcome; } - let mut tag_problems = unify_shared_tags_new( + let mut shared_tags_outcome = unify_shared_tags_new( subs, pool, ctx, @@ -900,9 +1013,9 @@ fn unify_tag_union_new( recursion_var, ); - tag_problems.extend(ext_problems); + shared_tags_outcome.union(ext_outcome); - tag_problems + shared_tags_outcome } } else if separate.only_in_2.is_empty() { let unique_tags1 = UnionTags::insert_slices_into_subs(subs, separate.only_in_1); @@ -911,10 +1024,10 @@ fn unify_tag_union_new( // In a presence context, we don't care about ext2 being equal to tags1 if ctx.mode.is_eq() { - let ext_problems = unify_pool(subs, pool, sub_record, ext2, ctx.mode); + let ext_outcome = unify_pool(subs, pool, sub_record, ext2, ctx.mode); - if !ext_problems.is_empty() { - return ext_problems; + if !ext_outcome.mismatches.is_empty() { + return ext_outcome; } } @@ -961,17 +1074,17 @@ fn unify_tag_union_new( let snapshot = subs.snapshot(); - let ext1_problems = unify_pool(subs, pool, ext1, sub2, ctx.mode); - if !ext1_problems.is_empty() { + let ext1_outcome = unify_pool(subs, pool, ext1, sub2, ctx.mode); + if !ext1_outcome.mismatches.is_empty() { subs.rollback_to(snapshot); - return ext1_problems; + return ext1_outcome; } if ctx.mode.is_eq() { - let ext2_problems = unify_pool(subs, pool, sub1, ext2, ctx.mode); - if !ext2_problems.is_empty() { + let ext2_outcome = unify_pool(subs, pool, sub1, ext2, ctx.mode); + if !ext2_outcome.mismatches.is_empty() { subs.rollback_to(snapshot); - return ext2_problems; + return ext2_outcome; } } @@ -1063,17 +1176,17 @@ fn unify_shared_tags_new( maybe_mark_tag_union_recursive(subs, actual); maybe_mark_tag_union_recursive(subs, expected); - let mut problems = Vec::new(); + let mut outcome = Outcome::default(); - problems.extend(unify_pool(subs, pool, actual, expected, ctx.mode)); + outcome.union(unify_pool(subs, pool, actual, expected, ctx.mode)); // clearly, this is very suspicious: these variables have just been unified. And yet, // not doing this leads to stack overflows if let Rec::Right(_) = recursion_var { - if problems.is_empty() { + if outcome.mismatches.is_empty() { matching_vars.push(expected); } - } else if problems.is_empty() { + } else if outcome.mismatches.is_empty() { matching_vars.push(actual); } } @@ -1215,39 +1328,43 @@ fn unify_flat_type( debug_assert!(is_recursion_var(subs, *rec2)); let rec = Rec::Both(*rec1, *rec2); - let mut problems = + let mut outcome = unify_tag_union_new(subs, pool, ctx, *tags1, *ext1, *tags2, *ext2, rec); - problems.extend(unify_pool(subs, pool, *rec1, *rec2, ctx.mode)); + outcome.union(unify_pool(subs, pool, *rec1, *rec2, ctx.mode)); - problems + outcome } (Apply(l_symbol, l_args), Apply(r_symbol, r_args)) if l_symbol == r_symbol => { - let problems = unify_zip_slices(subs, pool, *l_args, *r_args); + let mut outcome = unify_zip_slices(subs, pool, *l_args, *r_args); - if problems.is_empty() { - merge(subs, ctx, Structure(Apply(*r_symbol, *r_args))) - } else { - problems + if outcome.mismatches.is_empty() { + outcome.union(merge(subs, ctx, Structure(Apply(*r_symbol, *r_args)))); } + + outcome } (Func(l_args, l_closure, l_ret), Func(r_args, r_closure, r_ret)) if l_args.len() == r_args.len() => { - let arg_problems = unify_zip_slices(subs, pool, *l_args, *r_args); - let ret_problems = unify_pool(subs, pool, *l_ret, *r_ret, ctx.mode); - let closure_problems = unify_pool(subs, pool, *l_closure, *r_closure, ctx.mode); + let arg_outcome = unify_zip_slices(subs, pool, *l_args, *r_args); + let ret_outcome = unify_pool(subs, pool, *l_ret, *r_ret, ctx.mode); + let closure_outcome = unify_pool(subs, pool, *l_closure, *r_closure, ctx.mode); - if arg_problems.is_empty() && closure_problems.is_empty() && ret_problems.is_empty() { - merge(subs, ctx, Structure(Func(*r_args, *r_closure, *r_ret))) - } else { - let mut problems = ret_problems; + let mut outcome = ret_outcome; - problems.extend(closure_problems); - problems.extend(arg_problems); + outcome.union(closure_outcome); + outcome.union(arg_outcome); - problems + if outcome.mismatches.is_empty() { + outcome.union(merge( + subs, + ctx, + Structure(Func(*r_args, *r_closure, *r_ret)), + )); } + + outcome } (FunctionOrTagUnion(tag_name, tag_symbol, ext), Func(args, closure, ret)) => { unify_function_or_tag_union_and_func( @@ -1282,12 +1399,12 @@ fn unify_flat_type( let tag_name_2_ref = &subs[*tag_name_2]; if tag_name_1_ref == tag_name_2_ref { - let problems = unify_pool(subs, pool, *ext1, *ext2, ctx.mode); - if problems.is_empty() { + let outcome = unify_pool(subs, pool, *ext1, *ext2, ctx.mode); + if outcome.mismatches.is_empty() { let content = *subs.get_content_without_compacting(ctx.second); merge(subs, ctx, content) } else { - problems + outcome } } else { let tags1 = UnionTags::from_tag_name_index(*tag_name_1); @@ -1343,7 +1460,7 @@ fn unify_zip_slices( left: SubsSlice, right: SubsSlice, ) -> Outcome { - let mut problems = Vec::new(); + let mut outcome = Outcome::default(); let it = left.into_iter().zip(right.into_iter()); @@ -1351,10 +1468,10 @@ fn unify_zip_slices( let l_var = subs[l_index]; let r_var = subs[r_index]; - problems.extend(unify_pool(subs, pool, l_var, r_var, Mode::EQ)); + outcome.union(unify_pool(subs, pool, l_var, r_var, Mode::EQ)); } - problems + outcome } #[inline(always)] @@ -1362,6 +1479,7 @@ fn unify_rigid( subs: &mut Subs, ctx: &Context, name: &SubsIndex, + opt_able_bound: Option, other: &Content, ) -> Outcome { match other { @@ -1369,16 +1487,76 @@ fn unify_rigid( // If the other is flex, rigid wins! merge(subs, ctx, RigidVar(*name)) } - RigidVar(_) | RecursionVar { .. } | Structure(_) | Alias(_, _, _, _) | RangedNumber(..) => { - if !ctx.mode.contains(Mode::RIGID_AS_FLEX) { - // Type mismatch! Rigid can only unify with flex, even if the - // rigid names are the same. - mismatch!("Rigid {:?} with {:?}", ctx.first, &other) - } else { - // We are treating rigid vars as flex vars; admit this - merge(subs, ctx, *other) + FlexAbleVar(_, other_ability) => { + match opt_able_bound { + Some(ability) => { + if ability == *other_ability { + // The ability bounds are the same, so rigid wins! + merge(subs, ctx, RigidAbleVar(*name, ability)) + } else { + // Mismatch for now. + // TODO check ability hierarchies. + mismatch!( + %not_able, ctx.second, ability, + "RigidAble {:?} with ability {:?} not compatible with ability {:?}", + ctx.first, + ability, + other_ability + ) + } + } + None => { + // Mismatch - Rigid can unify with FlexAble only when the Rigid has an ability + // bound as well, otherwise the user failed to correctly annotate the bound. + mismatch!( + %not_able, ctx.first, *other_ability, + "Rigid {:?} with FlexAble {:?}", ctx.first, other + ) + } } } + + RigidVar(_) | RecursionVar { .. } | Structure(_) | Alias(_, _, _, _) | RangedNumber(..) + if ctx.mode.contains(Mode::RIGID_AS_FLEX) => + { + // Usually rigids can only unify with flex, but the mode indicates we are treating + // rigid vars as flex, so admit this. + match (opt_able_bound, other) { + (None, other) => merge(subs, ctx, *other), + (Some(ability), Alias(opaque_name, vars, _real_var, AliasKind::Opaque)) + if vars.is_empty() => + { + let mut output = merge(subs, ctx, *other); + let must_implement_ability = MustImplementAbility { + typ: *opaque_name, + ability, + }; + output.must_implement_ability.push(must_implement_ability); + output + } + (Some(ability), other) => { + // For now, only allow opaque types with no type variables to implement abilities. + mismatch!( + %not_able, ctx.second, ability, + "RigidAble {:?} with non-opaque or opaque with type variables {:?}", + ctx.first, + &other + ) + } + } + } + + RigidVar(_) + | RigidAbleVar(..) + | RecursionVar { .. } + | Structure(_) + | Alias(..) + | RangedNumber(..) => { + // Type mismatch! Rigid can only unify with flex, even if the + // rigid names are the same. + mismatch!("Rigid {:?} with {:?}", ctx.first, &other) + } + Error => { // Error propagates. merge(subs, ctx, Error) @@ -1391,16 +1569,49 @@ fn unify_flex( subs: &mut Subs, ctx: &Context, opt_name: &Option>, + opt_able_bound: Option, other: &Content, ) -> Outcome { match other { FlexVar(None) => { // If both are flex, and only left has a name, keep the name around. - merge(subs, ctx, FlexVar(*opt_name)) + match opt_able_bound { + Some(ability) => merge(subs, ctx, FlexAbleVar(*opt_name, ability)), + None => merge(subs, ctx, FlexVar(*opt_name)), + } + } + + FlexAbleVar(opt_other_name, other_ability) => { + // Prefer the right's name when possible. + let opt_name = (opt_other_name).or(*opt_name); + + match opt_able_bound { + Some(ability) => { + if ability == *other_ability { + // The ability bounds are the same! Keep the name around if it exists. + merge(subs, ctx, FlexAbleVar(opt_name, ability)) + } else { + // Ability names differ; mismatch for now. + // TODO check ability hierarchies. + mismatch!( + %not_able, ctx.second, ability, + "FlexAble {:?} with ability {:?} not compatible with ability {:?}", + ctx.first, + ability, + other_ability + ) + } + } + None => { + // Right has an ability bound, but left might have the name. Combine them. + merge(subs, ctx, FlexAbleVar(opt_name, *other_ability)) + } + } } FlexVar(Some(_)) | RigidVar(_) + | RigidAbleVar(_, _) | RecursionVar { .. } | Structure(_) | Alias(_, _, _, _) @@ -1446,7 +1657,13 @@ fn unify_recursion( // unify the structure variable with this Structure unify_pool(subs, pool, structure, ctx.second, ctx.mode) } - RigidVar(_) => mismatch!("RecursionVar {:?} with rigid {:?}", ctx.first, &other), + RigidVar(_) => { + mismatch!("RecursionVar {:?} with rigid {:?}", ctx.first, &other) + } + + FlexAbleVar(..) | RigidAbleVar(..) => { + mismatch!("RecursionVar {:?} with able var {:?}", ctx.first, &other) + } FlexVar(_) => merge( subs, @@ -1492,7 +1709,7 @@ pub fn merge(subs: &mut Subs, ctx: &Context, content: Content) -> Outcome { subs.union(ctx.first, ctx.second, desc); - Vec::new() + Outcome::default() } fn register(subs: &mut Subs, desc: Descriptor, pool: &mut Pool) -> Variable { @@ -1543,7 +1760,7 @@ fn unify_function_or_tag_union_and_func( let new_tag_union_var = fresh(subs, pool, ctx, content); - let mut problems = if left { + let mut outcome = if left { unify_pool(subs, pool, new_tag_union_var, function_return, ctx.mode) } else { unify_pool(subs, pool, function_return, new_tag_union_var, ctx.mode) @@ -1567,16 +1784,16 @@ fn unify_function_or_tag_union_and_func( pool, ); - let closure_problems = if left { + let closure_outcome = if left { unify_pool(subs, pool, tag_lambda_set, function_lambda_set, ctx.mode) } else { unify_pool(subs, pool, function_lambda_set, tag_lambda_set, ctx.mode) }; - problems.extend(closure_problems); + outcome.union(closure_outcome); } - if problems.is_empty() { + if outcome.mismatches.is_empty() { let desc = if left { subs.get(ctx.second) } else { @@ -1586,5 +1803,5 @@ fn unify_function_or_tag_union_and_func( subs.union(ctx.first, ctx.second, desc); } - problems + outcome } diff --git a/reporting/src/error/type.rs b/reporting/src/error/type.rs index 21ec179d6f..848c510651 100644 --- a/reporting/src/error/type.rs +++ b/reporting/src/error/type.rs @@ -950,6 +950,62 @@ fn to_expr_report<'b>( None, ), + Reason::InvalidAbilityMemberSpecialization { + member_name, + def_region: _, + unimplemented_abilities, + } => { + let problem = alloc.concat(vec![ + alloc.reflow("Something is off with this specialization of "), + alloc.symbol_unqualified(member_name), + alloc.reflow(":"), + ]); + let this_is = alloc.reflow("This value is"); + let instead_of = alloc.concat(vec![ + alloc.reflow("But the type annotation on "), + alloc.symbol_unqualified(member_name), + alloc.reflow(" says it must match:"), + ]); + + let hint = if unimplemented_abilities.is_empty() { + None + } else { + let mut stack = Vec::with_capacity(unimplemented_abilities.len()); + for (err_type, ability) in unimplemented_abilities.into_iter() { + stack.push(alloc.concat(vec![ + to_doc(alloc, Parens::Unnecessary, err_type).0, + alloc.reflow(" does not implement "), + alloc.symbol_unqualified(ability), + ])); + } + + let hint = alloc.stack(vec![ + alloc.concat(vec![ + alloc.note(""), + alloc.reflow("Some types in this specialization don't implement the abilities they are expected to. I found the following missing implementations:"), + ]), + alloc.type_block(alloc.stack(stack)), + ]); + + Some(hint) + }; + + report_mismatch( + alloc, + lines, + filename, + &category, + found, + expected_type, + region, + Some(expr_region), + problem, + this_is, + instead_of, + hint, + ) + } + Reason::LowLevelOpArg { op, arg_index } => { panic!( "Compiler bug: argument #{} to low-level operation {:?} was the wrong type!", @@ -1281,6 +1337,10 @@ fn format_category<'b>( alloc.concat(vec![this_is, alloc.text(" a default field")]), alloc.text(" of type:"), ), + AbilityMemberSpecialization(_ability_member) => ( + alloc.concat(vec![this_is, alloc.text(" a declared specialization")]), + alloc.text(" of type:"), + ), } } @@ -1526,7 +1586,7 @@ fn to_circular_report<'b>( You will see ∞ for parts of the type that repeat \ something already printed out infinitely.", ), - alloc.type_block(to_doc(alloc, Parens::Unnecessary, overall_type)), + alloc.type_block(to_doc(alloc, Parens::Unnecessary, overall_type).0), ]), ]) }, @@ -1683,6 +1743,7 @@ pub struct Diff { left: T, right: T, status: Status, + // TODO: include able variables } fn ext_to_doc<'b>(alloc: &'b RocDocAllocator<'b>, ext: TypeExt) -> Option> { @@ -1694,10 +1755,30 @@ fn ext_to_doc<'b>(alloc: &'b RocDocAllocator<'b>, ext: TypeExt) -> Option; + +#[derive(Default)] +struct Context { + able_variables: AbleVariables, +} + pub fn to_doc<'b>( alloc: &'b RocDocAllocator<'b>, parens: Parens, tipe: ErrorType, +) -> (RocDocBuilder<'b>, AbleVariables) { + let mut ctx = Context::default(); + + let doc = to_doc_help(&mut ctx, alloc, parens, dbg!(tipe)); + + (doc, ctx.able_variables) +} + +fn to_doc_help<'b>( + ctx: &mut Context, + alloc: &'b RocDocAllocator<'b>, + parens: Parens, + tipe: ErrorType, ) -> RocDocBuilder<'b> { use ErrorType::*; @@ -1706,22 +1787,32 @@ pub fn to_doc<'b>( alloc, parens, args.into_iter() - .map(|arg| to_doc(alloc, Parens::InFn, arg)) + .map(|arg| to_doc_help(ctx, alloc, Parens::InFn, arg)) .collect(), - to_doc(alloc, Parens::InFn, *ret), + to_doc_help(ctx, alloc, Parens::InFn, *ret), ), Infinite => alloc.text("∞"), Error => alloc.text("?"), - FlexVar(lowercase) => alloc.type_variable(lowercase), - RigidVar(lowercase) => alloc.type_variable(lowercase), + FlexVar(lowercase) | RigidVar(lowercase) => alloc.type_variable(lowercase), + FlexAbleVar(lowercase, ability) | RigidAbleVar(lowercase, ability) => { + // TODO we should be putting able variables on the toplevel of the type, not here + ctx.able_variables.push((lowercase.clone(), ability)); + alloc.concat(vec![ + alloc.type_variable(lowercase), + alloc.space(), + alloc.keyword("has"), + alloc.space(), + alloc.symbol_foreign_qualified(ability), + ]) + } Type(symbol, args) => report_text::apply( alloc, parens, alloc.symbol_foreign_qualified(symbol), args.into_iter() - .map(|arg| to_doc(alloc, Parens::InTypeParam, arg)) + .map(|arg| to_doc_help(ctx, alloc, Parens::InTypeParam, arg)) .collect(), ), @@ -1730,7 +1821,7 @@ pub fn to_doc<'b>( parens, alloc.symbol_foreign_qualified(symbol), args.into_iter() - .map(|arg| to_doc(alloc, Parens::InTypeParam, arg)) + .map(|arg| to_doc_help(ctx, alloc, Parens::InTypeParam, arg)) .collect(), ), @@ -1746,15 +1837,24 @@ pub fn to_doc<'b>( ( alloc.string(k.as_str().to_string()), match value { - RecordField::Optional(v) => { - RecordField::Optional(to_doc(alloc, Parens::Unnecessary, v)) - } - RecordField::Required(v) => { - RecordField::Required(to_doc(alloc, Parens::Unnecessary, v)) - } - RecordField::Demanded(v) => { - RecordField::Demanded(to_doc(alloc, Parens::Unnecessary, v)) - } + RecordField::Optional(v) => RecordField::Optional(to_doc_help( + ctx, + alloc, + Parens::Unnecessary, + v, + )), + RecordField::Required(v) => RecordField::Required(to_doc_help( + ctx, + alloc, + Parens::Unnecessary, + v, + )), + RecordField::Demanded(v) => RecordField::Demanded(to_doc_help( + ctx, + alloc, + Parens::Unnecessary, + v, + )), }, ) }) @@ -1770,7 +1870,7 @@ pub fn to_doc<'b>( ( name, args.into_iter() - .map(|arg| to_doc(alloc, Parens::InTypeParam, arg)) + .map(|arg| to_doc_help(ctx, alloc, Parens::InTypeParam, arg)) .collect::>(), ) }) @@ -1793,7 +1893,7 @@ pub fn to_doc<'b>( ( name, args.into_iter() - .map(|arg| to_doc(alloc, Parens::InTypeParam, arg)) + .map(|arg| to_doc_help(ctx, alloc, Parens::InTypeParam, arg)) .collect::>(), ) }) @@ -1802,7 +1902,7 @@ pub fn to_doc<'b>( report_text::recursive_tag_union( alloc, - to_doc(alloc, Parens::Unnecessary, *rec_var), + to_doc_help(ctx, alloc, Parens::Unnecessary, *rec_var), tags.into_iter() .map(|(k, v)| (alloc.tag_name(k), v)) .collect(), @@ -1811,10 +1911,10 @@ pub fn to_doc<'b>( } Range(typ, range_types) => { - let typ = to_doc(alloc, parens, *typ); + let typ = to_doc_help(ctx, alloc, parens, *typ); let range_types = range_types .into_iter() - .map(|arg| to_doc(alloc, Parens::Unnecessary, arg)) + .map(|arg| to_doc_help(ctx, alloc, Parens::Unnecessary, arg)) .collect(); report_text::range(alloc, typ, range_types) } @@ -1826,7 +1926,7 @@ fn same<'b>( parens: Parens, tipe: ErrorType, ) -> Diff> { - let doc = to_doc(alloc, parens, tipe); + let doc = to_doc(alloc, parens, tipe).0; Diff { left: doc.clone(), @@ -1870,8 +1970,8 @@ fn to_diff<'b>( status, } } else { - let left = to_doc(alloc, Parens::InFn, type1); - let right = to_doc(alloc, Parens::InFn, type2); + let left = to_doc(alloc, Parens::InFn, type1).0; + let right = to_doc(alloc, Parens::InFn, type2).0; Diff { left, @@ -1928,8 +2028,8 @@ fn to_diff<'b>( } (Alias(_, _, _, AliasKind::Opaque), _) | (_, Alias(_, _, _, AliasKind::Opaque)) => { - let left = to_doc(alloc, Parens::InFn, type1); - let right = to_doc(alloc, Parens::InFn, type2); + let left = to_doc(alloc, Parens::InFn, type1).0; + let right = to_doc(alloc, Parens::InFn, type2).0; Diff { left, @@ -1961,8 +2061,8 @@ fn to_diff<'b>( (RecursiveTagUnion(_rec1, _tags1, _ext1), RecursiveTagUnion(_rec2, _tags2, _ext2)) => { // TODO do a better job here - let left = to_doc(alloc, Parens::Unnecessary, type1); - let right = to_doc(alloc, Parens::Unnecessary, type2); + let left = to_doc(alloc, Parens::Unnecessary, type1).0; + let right = to_doc(alloc, Parens::Unnecessary, type2).0; Diff { left, @@ -1973,8 +2073,8 @@ fn to_diff<'b>( pair => { // We hit none of the specific cases where we give more detailed information - let left = to_doc(alloc, parens, type1); - let right = to_doc(alloc, parens, type2); + let left = to_doc(alloc, parens, type1).0; + let right = to_doc(alloc, parens, type2).0; let is_int = |t: &ErrorType| match t { ErrorType::Type(Symbol::NUM_INT, _) => true, @@ -2135,7 +2235,7 @@ fn diff_record<'b>( ( field.clone(), alloc.string(field.as_str().to_string()), - tipe.map(|t| to_doc(alloc, Parens::Unnecessary, t.clone())), + tipe.map(|t| to_doc(alloc, Parens::Unnecessary, t.clone()).0), ) }; let shared_keys = fields1 @@ -2261,7 +2361,7 @@ fn diff_tag_union<'b>( alloc.tag_name(field.clone()), // TODO add spaces between args args.iter() - .map(|arg| to_doc(alloc, Parens::InTypeParam, arg.clone())) + .map(|arg| to_doc(alloc, Parens::InTypeParam, arg.clone()).0) .collect(), ) }; @@ -2518,7 +2618,7 @@ mod report_text { let entry_to_doc = |(name, tipe): (Lowercase, RecordField)| { ( alloc.string(name.as_str().to_string()), - to_doc(alloc, Parens::Unnecessary, tipe.into_inner()), + to_doc(alloc, Parens::Unnecessary, tipe.into_inner()).0, ) }; @@ -2863,7 +2963,14 @@ fn type_problem_to_pretty<'b>( match tipe { Infinite | Error | FlexVar(_) => alloc.nil(), - RigidVar(y) => bad_double_rigid(x, y), + FlexAbleVar(_, ability) => bad_rigid_var( + x, + alloc.concat(vec![ + alloc.reflow("an instance of the ability "), + alloc.symbol_unqualified(ability), + ]), + ), + RigidVar(y) | RigidAbleVar(y, _) => bad_double_rigid(x, y), Function(_, _, _) => bad_rigid_var(x, alloc.reflow("a function value")), Record(_, _) => bad_rigid_var(x, alloc.reflow("a record value")), TagUnion(_, _) | RecursiveTagUnion(_, _, _) => { diff --git a/reporting/src/report.rs b/reporting/src/report.rs index 4dc7c46d3e..fb6de7f29b 100644 --- a/reporting/src/report.rs +++ b/reporting/src/report.rs @@ -72,6 +72,12 @@ pub enum Severity { Warning, } +#[derive(Clone, Copy, Debug)] +pub enum RenderTarget { + ColorTerminal, + Generic, +} + /// A textual report. pub struct Report<'b> { pub title: String, @@ -81,6 +87,19 @@ pub struct Report<'b> { } impl<'b> Report<'b> { + pub fn render( + self, + target: RenderTarget, + buf: &'b mut String, + alloc: &'b RocDocAllocator<'b>, + palette: &'b Palette, + ) { + match target { + RenderTarget::Generic => self.render_ci(buf, alloc), + RenderTarget::ColorTerminal => self.render_color_terminal(buf, alloc, palette), + } + } + /// Render to CI console output, where no colors are available. pub fn render_ci(self, buf: &'b mut String, alloc: &'b RocDocAllocator<'b>) { let err_msg = ""; diff --git a/reporting/tests/helpers/mod.rs b/reporting/tests/helpers/mod.rs index eda767542e..34aa95bf8f 100644 --- a/reporting/tests/helpers/mod.rs +++ b/reporting/tests/helpers/mod.rs @@ -1,6 +1,7 @@ extern crate bumpalo; use self::bumpalo::Bump; +use roc_can::abilities::AbilitiesStore; use roc_can::constraint::{Constraint, Constraints}; use roc_can::env::Env; use roc_can::expected::Expected; @@ -31,10 +32,19 @@ pub fn infer_expr( constraints: &Constraints, constraint: &Constraint, aliases: &mut Aliases, + abilities_store: &mut AbilitiesStore, expr_var: Variable, ) -> (Content, Subs) { let env = solve::Env::default(); - let (solved, _) = solve::run(constraints, &env, problems, subs, aliases, constraint); + let (solved, _) = solve::run( + constraints, + &env, + problems, + subs, + aliases, + constraint, + abilities_store, + ); let content = *solved.inner().get_content_without_compacting(expr_var); diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 65525012f1..675a259de0 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -8,17 +8,20 @@ mod helpers; #[cfg(test)] mod test_reporting { - use crate::helpers::test_home; - use crate::helpers::{can_expr, infer_expr, CanExprOut, ParseErrOut}; + use crate::helpers::{can_expr, infer_expr, test_home, CanExprOut, ParseErrOut}; use bumpalo::Bump; use indoc::indoc; + use roc_can::abilities::AbilitiesStore; + use roc_can::def::Declaration; + use roc_can::pattern::Pattern; + use roc_load::{self, LoadedModule, LoadingProblem}; use roc_module::symbol::{Interns, ModuleId}; use roc_mono::ir::{Procs, Stmt, UpdateModeIds}; use roc_mono::layout::LayoutCache; use roc_region::all::LineInfo; use roc_reporting::report::{ - can_problem, mono_problem, parse_problem, type_problem, Report, Severity, ANSI_STYLE_CODES, - DEFAULT_PALETTE, + can_problem, mono_problem, parse_problem, type_problem, RenderTarget, Report, Severity, + ANSI_STYLE_CODES, DEFAULT_PALETTE, }; use roc_reporting::report::{RocDocAllocator, RocDocBuilder}; use roc_solve::solve; @@ -43,6 +46,214 @@ mod test_reporting { } } + fn promote_expr_to_module(src: &str) -> String { + let mut buffer = + String::from("app \"test\" provides [ main ] to \"./platform\"\n\nmain =\n"); + + for line in src.lines() { + // indent the body! + buffer.push_str(" "); + buffer.push_str(line); + buffer.push('\n'); + } + + buffer + } + + fn run_load_and_infer<'a>( + arena: &'a Bump, + src: &'a str, + ) -> (String, Result>) { + use std::fs::File; + use std::io::Write; + use tempfile::tempdir; + + let module_src = if src.starts_with("app") { + // this is already a module + src.to_string() + } else { + // this is an expression, promote it to a module + promote_expr_to_module(src) + }; + + let exposed_types = Default::default(); + let loaded = { + let dir = tempdir().unwrap(); + let filename = PathBuf::from("Test.roc"); + let file_path = dir.path().join(filename); + let full_file_path = file_path.clone(); + let mut file = File::create(file_path).unwrap(); + writeln!(file, "{}", module_src).unwrap(); + let result = roc_load::load_and_typecheck( + arena, + full_file_path, + dir.path(), + exposed_types, + roc_target::TargetInfo::default_x86_64(), + RenderTarget::Generic, + ); + drop(file); + + dir.close().unwrap(); + + result + }; + + (module_src, loaded) + } + + fn infer_expr_help_new<'a>( + arena: &'a Bump, + expr_src: &'a str, + ) -> Result< + ( + String, + Vec, + Vec, + Vec, + ModuleId, + Interns, + ), + LoadingProblem<'a>, + > { + let (module_src, result) = run_load_and_infer(arena, expr_src); + let LoadedModule { + module_id: home, + mut can_problems, + mut type_problems, + interns, + mut solved, + exposed_to_host, + mut declarations_by_id, + .. + } = result?; + + let can_problems = can_problems.remove(&home).unwrap_or_default(); + let type_problems = type_problems.remove(&home).unwrap_or_default(); + + let subs = solved.inner_mut(); + + for var in exposed_to_host.values() { + name_all_type_vars(*var, subs); + } + + let mut mono_problems = Vec::new(); + + // MONO + + if type_problems.is_empty() && can_problems.is_empty() { + let arena = Bump::new(); + + assert!(exposed_to_host.len() == 1); + let (sym, _var) = exposed_to_host.into_iter().next().unwrap(); + + let home_decls = declarations_by_id.remove(&home).unwrap(); + let (loc_expr, var) = home_decls + .into_iter() + .find_map(|decl| match decl { + Declaration::Declare(def) => match def.loc_pattern.value { + Pattern::Identifier(s) if s == sym => Some((def.loc_expr, def.expr_var)), + _ => None, + }, + _ => None, + }) + .expect("No expression to monomorphize found!"); + + // Compile and add all the Procs before adding main + let mut procs = Procs::new_in(&arena); + let mut ident_ids = interns.all_ident_ids.get(&home).unwrap().clone(); + let mut update_mode_ids = UpdateModeIds::new(); + + // Populate Procs and Subs, and get the low-level Expr from the canonical Expr + let target_info = roc_target::TargetInfo::default_x86_64(); + let mut layout_cache = LayoutCache::new(target_info); + let mut mono_env = roc_mono::ir::Env { + arena: &arena, + subs, + problems: &mut mono_problems, + home, + ident_ids: &mut ident_ids, + update_mode_ids: &mut update_mode_ids, + target_info, + // call_specialization_counter=0 is reserved + call_specialization_counter: 1, + }; + let _mono_expr = Stmt::new( + &mut mono_env, + loc_expr.value, + var, + &mut procs, + &mut layout_cache, + ); + } + + Ok(( + module_src, + type_problems, + can_problems, + mono_problems, + home, + interns, + )) + } + + fn list_reports_new(arena: &Bump, src: &str, finalize_render: F) -> String + where + F: FnOnce(RocDocBuilder<'_>, &mut String), + { + use ven_pretty::DocAllocator; + + let filename = filename_from_string(r"\code\proj\Main.roc"); + + let mut buf = String::new(); + + match infer_expr_help_new(arena, src) { + Err(LoadingProblem::FormattedReport(fail)) => fail, + Ok((module_src, type_problems, can_problems, mono_problems, home, interns)) => { + let lines = LineInfo::new(&module_src); + let src_lines: Vec<&str> = module_src.split('\n').collect(); + let mut reports = Vec::new(); + + let alloc = RocDocAllocator::new(&src_lines, home, &interns); + + for problem in can_problems { + let report = can_problem(&alloc, &lines, filename.clone(), problem.clone()); + reports.push(report); + } + + for problem in type_problems { + if let Some(report) = + type_problem(&alloc, &lines, filename.clone(), problem.clone()) + { + reports.push(report); + } + } + + for problem in mono_problems { + let report = mono_problem(&alloc, &lines, filename.clone(), problem.clone()); + reports.push(report); + } + + let has_reports = !reports.is_empty(); + + let doc = alloc + .stack(reports.into_iter().map(|v| v.pretty(&alloc))) + .append(if has_reports { + alloc.line() + } else { + alloc.nil() + }); + + finalize_render(doc, &mut buf); + buf + } + Err(other) => { + assert!(false, "failed to load: {:?}", other); + unreachable!() + } + } + } + fn infer_expr_help<'a>( arena: &'a Bump, expr_src: &'a str, @@ -85,12 +296,14 @@ mod test_reporting { } let mut unify_problems = Vec::new(); + let mut abilities_store = AbilitiesStore::default(); let (_content, mut subs) = infer_expr( subs, &mut unify_problems, &constraints, &constraint, &mut solve_aliases, + &mut abilities_store, var, ); @@ -298,6 +511,27 @@ mod test_reporting { assert_eq!(readable, expected_rendering); } + fn new_report_problem_as(src: &str, expected_rendering: &str) { + let arena = Bump::new(); + + let finalize_render = |doc: RocDocBuilder<'_>, buf: &mut String| { + doc.1 + .render_raw(70, &mut roc_reporting::report::CiWrite::new(buf)) + .expect("list_reports") + }; + + let buf = list_reports_new(&arena, src, finalize_render); + + // convenient to copy-paste the generated message + if true && buf != expected_rendering { + for line in buf.split('\n') { + println!(" {}", line); + } + } + + assert_multiline_str_eq!(expected_rendering, buf.as_str()); + } + fn human_readable(str: &str) -> String { str.replace(ANSI_STYLE_CODES.red, "") .replace(ANSI_STYLE_CODES.white, "") @@ -8682,7 +8916,7 @@ I need all branches in an `if` to have the same type! #[test] fn ability_demands_not_indented_with_first() { - report_problem_as( + new_report_problem_as( indoc!( r#" Eq has @@ -8699,19 +8933,18 @@ I need all branches in an `if` to have the same type! I was partway through parsing an ability definition, but I got stuck here: - 2│ eq : a, a -> U64 | a has Eq - 3│ neq : a, a -> U64 | a has Eq - ^ + 5│ eq : a, a -> U64 | a has Eq + 6│ neq : a, a -> U64 | a has Eq + ^ - I suspect this line is indented too much (by 4 spaces) - "# + I suspect this line is indented too much (by 4 spaces)"# ), ) } #[test] fn ability_demand_value_has_args() { - report_problem_as( + new_report_problem_as( indoc!( r#" Eq has @@ -8727,12 +8960,11 @@ I need all branches in an `if` to have the same type! I was partway through parsing an ability definition, but I got stuck here: - 2│ eq b c : a, a -> U64 | a has Eq - ^ + 5│ eq b c : a, a -> U64 | a has Eq + ^ I was expecting to see a : annotating the signature of this value - next. - "# + next."# ), ) } @@ -8898,8 +9130,8 @@ I need all branches in an `if` to have the same type! } #[test] - fn bad_type_parameter_in_ability() { - report_problem_as( + fn ability_bad_type_parameter() { + new_report_problem_as( indoc!( r#" Hash a b c has @@ -8914,8 +9146,8 @@ I need all branches in an `if` to have the same type! The definition of the `Hash` ability includes type variables: - 1│ Hash a b c has - ^^^^^ + 4│ Hash a b c has + ^^^^^ Abilities cannot depend on type variables, but their member values can! @@ -8924,8 +9156,8 @@ I need all branches in an `if` to have the same type! `Hash` is not used anywhere in your code. - 1│ Hash a b c has - ^^^^ + 4│ Hash a b c has + ^^^^ If you didn't intend on using `Hash` then remove it so future readers of your code don't wonder why it is there. @@ -8936,12 +9168,12 @@ I need all branches in an `if` to have the same type! #[test] fn alias_in_has_clause() { - report_problem_as( + new_report_problem_as( indoc!( r#" - Hash has hash : a, b -> U64 | a has Hash, b has Bool + app "test" provides [ hash ] to "./platform" - 1 + Hash has hash : a, b -> U64 | a has Hash, b has Bool "# ), indoc!( @@ -8950,18 +9182,8 @@ I need all branches in an `if` to have the same type! The type referenced in this "has" clause is not an ability: - 1│ Hash has hash : a, b -> U64 | a has Hash, b has Bool + 3│ Hash has hash : a, b -> U64 | a has Hash, b has Bool ^^^^ - - ── UNUSED DEFINITION ─────────────────────────────────────────────────────────── - - `hash` is not used anywhere in your code. - - 1│ Hash has hash : a, b -> U64 | a has Hash, b has Bool - ^^^^ - - If you didn't intend on using `hash` then remove it so future readers of - your code don't wonder why it is there. "# ), ) @@ -8969,12 +9191,12 @@ I need all branches in an `if` to have the same type! #[test] fn shadowed_type_variable_in_has_clause() { - report_problem_as( + new_report_problem_as( indoc!( r#" - Ab1 has ab1 : a -> {} | a has Ab1, a has Ab1 + app "test" provides [ ab1 ] to "./platform" - 1 + Ab1 has ab1 : a -> {} | a has Ab1, a has Ab1 "# ), indoc!( @@ -8983,26 +9205,16 @@ I need all branches in an `if` to have the same type! The `a` name is first defined here: - 1│ Ab1 has ab1 : a -> {} | a has Ab1, a has Ab1 + 3│ Ab1 has ab1 : a -> {} | a has Ab1, a has Ab1 ^^^^^^^^^ But then it's defined a second time here: - 1│ Ab1 has ab1 : a -> {} | a has Ab1, a has Ab1 + 3│ Ab1 has ab1 : a -> {} | a has Ab1, a has Ab1 ^^^^^^^^^ Since these variables have the same name, it's easy to use the wrong one on accident. Give one of them a new name. - - ── UNUSED DEFINITION ─────────────────────────────────────────────────────────── - - `ab1` is not used anywhere in your code. - - 1│ Ab1 has ab1 : a -> {} | a has Ab1, a has Ab1 - ^^^ - - If you didn't intend on using `ab1` then remove it so future readers of - your code don't wonder why it is there. "# ), ) @@ -9010,7 +9222,7 @@ I need all branches in an `if` to have the same type! #[test] fn alias_using_ability() { - report_problem_as( + new_report_problem_as( indoc!( r#" Ability has ab : a -> {} | a has Ability @@ -9027,8 +9239,8 @@ I need all branches in an `if` to have the same type! The definition of the `Alias` aliases references the ability `Ability`: - 3│ Alias : Ability - ^^^^^ + 6│ Alias : Ability + ^^^^^ Abilities are not types, but you can add an ability constraint to a type variable `a` by writing @@ -9041,8 +9253,8 @@ I need all branches in an `if` to have the same type! `ab` is not used anywhere in your code. - 1│ Ability has ab : a -> {} | a has Ability - ^^ + 4│ Ability has ab : a -> {} | a has Ability + ^^ If you didn't intend on using `ab` then remove it so future readers of your code don't wonder why it is there. @@ -9053,7 +9265,7 @@ I need all branches in an `if` to have the same type! #[test] fn ability_shadows_ability() { - report_problem_as( + new_report_problem_as( indoc!( r#" Ability has ab : a -> U64 | a has Ability @@ -9069,13 +9281,13 @@ I need all branches in an `if` to have the same type! The `Ability` name is first defined here: - 1│ Ability has ab : a -> U64 | a has Ability - ^^^^^^^ + 4│ Ability has ab : a -> U64 | a has Ability + ^^^^^^^ But then it's defined a second time here: - 3│ Ability has ab1 : a -> U64 | a has Ability - ^^^^^^^ + 6│ Ability has ab1 : a -> U64 | a has Ability + ^^^^^^^ Since these abilities have the same name, it's easy to use the wrong one on accident. Give one of them a new name. @@ -9084,8 +9296,8 @@ I need all branches in an `if` to have the same type! `ab` is not used anywhere in your code. - 1│ Ability has ab : a -> U64 | a has Ability - ^^ + 4│ Ability has ab : a -> U64 | a has Ability + ^^ If you didn't intend on using `ab` then remove it so future readers of your code don't wonder why it is there. @@ -9096,12 +9308,12 @@ I need all branches in an `if` to have the same type! #[test] fn ability_member_does_not_bind_ability() { - report_problem_as( + new_report_problem_as( indoc!( r#" - Ability has ab : {} -> {} + app "test" provides [ ] to "./platform" - 1 + Ability has ab : {} -> {} "# ), indoc!( @@ -9111,7 +9323,7 @@ I need all branches in an `if` to have the same type! The definition of the ability member `ab` does not include a `has` clause binding a type variable to the ability `Ability`: - 1│ Ability has ab : {} -> {} + 3│ Ability has ab : {} -> {} ^^ Ability members must include a `has` clause binding a type variable to @@ -9125,7 +9337,7 @@ I need all branches in an `if` to have the same type! `Ability` is not used anywhere in your code. - 1│ Ability has ab : {} -> {} + 3│ Ability has ab : {} -> {} ^^^^^^^ If you didn't intend on using `Ability` then remove it so future readers @@ -9135,7 +9347,7 @@ I need all branches in an `if` to have the same type! `ab` is not used anywhere in your code. - 1│ Ability has ab : {} -> {} + 3│ Ability has ab : {} -> {} ^^ If you didn't intend on using `ab` then remove it so future readers of @@ -9147,13 +9359,13 @@ I need all branches in an `if` to have the same type! #[test] fn ability_member_binds_extra_ability() { - report_problem_as( + new_report_problem_as( indoc!( r#" + app "test" provides [ eq ] to "./platform" + Eq has eq : a, a -> Bool | a has Eq Hash has hash : a, b -> U64 | a has Eq, b has Hash - - 1 "# ), indoc!( @@ -9163,7 +9375,7 @@ I need all branches in an `if` to have the same type! The definition of the ability member `hash` includes a has clause binding an ability it is not a part of: - 2│ Hash has hash : a, b -> U64 | a has Eq, b has Hash + 4│ Hash has hash : a, b -> U64 | a has Eq, b has Hash ^^^^^^^^ Currently, ability members can only bind variables to the ability they @@ -9173,19 +9385,9 @@ I need all branches in an `if` to have the same type! ── UNUSED DEFINITION ─────────────────────────────────────────────────────────── - `eq` is not used anywhere in your code. - - 1│ Eq has eq : a, a -> Bool | a has Eq - ^^ - - If you didn't intend on using `eq` then remove it so future readers of - your code don't wonder why it is there. - - ── UNUSED DEFINITION ─────────────────────────────────────────────────────────── - `hash` is not used anywhere in your code. - 2│ Hash has hash : a, b -> U64 | a has Eq, b has Hash + 4│ Hash has hash : a, b -> U64 | a has Eq, b has Hash ^^^^ If you didn't intend on using `hash` then remove it so future readers of @@ -9197,14 +9399,14 @@ I need all branches in an `if` to have the same type! #[test] fn has_clause_outside_of_ability() { - report_problem_as( + new_report_problem_as( indoc!( r#" + app "test" provides [ hash, f ] to "./platform" + Hash has hash : a -> U64 | a has Hash f : a -> U64 | a has Hash - - f "# ), indoc!( @@ -9213,21 +9415,49 @@ I need all branches in an `if` to have the same type! A `has` clause is not allowed here: - 3│ f : a -> U64 | a has Hash + 5│ f : a -> U64 | a has Hash ^^^^^^^^^^ `has` clauses can only be specified on the top-level type annotation of an ability member. + "# + ), + ) + } - ── UNUSED DEFINITION ─────────────────────────────────────────────────────────── + #[test] + fn ability_specialization_with_non_implementing_type() { + new_report_problem_as( + indoc!( + r#" + app "test" provides [ hash ] to "./platform" - `hash` is not used anywhere in your code. + Hash has hash : a -> U64 | a has Hash - 1│ Hash has hash : a -> U64 | a has Hash - ^^^^ + hash = \{} -> 0u64 + "# + ), + indoc!( + r#" + ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── - If you didn't intend on using `hash` then remove it so future readers of - your code don't wonder why it is there. + Something is off with this specialization of `hash`: + + 5│ hash = \{} -> 0u64 + ^^^^ + + This value is a declared specialization of type: + + {}a -> U64 + + But the type annotation on `hash` says it must match: + + a has Hash -> U64 + + Note: Some types in this specialization don't implement the abilities + they are expected to. I found the following missing implementations: + + {}a does not implement Hash "# ), ) From ce7c61eb09aac7fa54c128938238d97e37146a1b Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 12 Apr 2022 15:45:42 -0400 Subject: [PATCH 175/846] Propogate render target forward --- Cargo.lock | 2 ++ ast/Cargo.toml | 1 + ast/src/module.rs | 1 + ast/src/solve_type.rs | 51 +++++++++++++++++++++++++++++++++---------- cli/src/build.rs | 5 +++++ docs/Cargo.toml | 1 + docs/src/lib.rs | 1 + repl_eval/src/gen.rs | 1 + 8 files changed, 51 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dc9e364812..d2babf3e7b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3351,6 +3351,7 @@ dependencies = [ "roc_parse", "roc_problem", "roc_region", + "roc_reporting", "roc_target", "roc_types", "roc_unify", @@ -3519,6 +3520,7 @@ dependencies = [ "roc_module", "roc_parse", "roc_region", + "roc_reporting", "roc_target", "roc_types", "snafu", diff --git a/ast/Cargo.toml b/ast/Cargo.toml index 86d203cee4..d1384b96ee 100644 --- a/ast/Cargo.toml +++ b/ast/Cargo.toml @@ -19,6 +19,7 @@ roc_unify = { path = "../compiler/unify"} roc_load = { path = "../compiler/load" } roc_target = { path = "../compiler/roc_target" } roc_error_macros = { path = "../error_macros" } +roc_reporting = { path = "../reporting" } arrayvec = "0.7.2" bumpalo = { version = "3.8.0", features = ["collections"] } page_size = "0.4.2" diff --git a/ast/src/module.rs b/ast/src/module.rs index 55b324b35d..769df5d162 100644 --- a/ast/src/module.rs +++ b/ast/src/module.rs @@ -19,6 +19,7 @@ pub fn load_module(src_file: &Path) -> LoadedModule { }), subs_by_module, TargetInfo::default_x86_64(), + roc_reporting::report::RenderTarget::ColorTerminal, ); match loaded { diff --git a/ast/src/solve_type.rs b/ast/src/solve_type.rs index dc2e53f3a8..f15b128827 100644 --- a/ast/src/solve_type.rs +++ b/ast/src/solve_type.rs @@ -227,12 +227,16 @@ fn solve<'a>( ); match unify(subs, actual, expected, Mode::EQ) { - Success(vars) => { + Success { + vars, + must_implement_ability: _, + } => { + // TODO(abilities) record deferred ability checks introduce(subs, rank, pools, &vars); state } - Failure(vars, actual_type, expected_type) => { + Failure(vars, actual_type, expected_type, _bad_impl) => { introduce(subs, rank, pools, &vars); let problem = TypeError::BadExpr( @@ -267,7 +271,7 @@ fn solve<'a>( // // state // } - // Failure(vars, _actual_type, _expected_type) => { + // Failure(vars, _actual_type, _expected_type, _bad_impl) => { // introduce(subs, rank, pools, &vars); // // // ERROR NOT REPORTED @@ -320,13 +324,17 @@ fn solve<'a>( ); match unify(subs, actual, expected, Mode::EQ) { - Success(vars) => { + Success { + vars, + must_implement_ability: _, + } => { + // TODO(abilities) record deferred ability checks introduce(subs, rank, pools, &vars); state } - Failure(vars, actual_type, expected_type) => { + Failure(vars, actual_type, expected_type, _bad_impl) => { introduce(subs, rank, pools, &vars); let problem = TypeError::BadExpr( @@ -391,12 +399,16 @@ fn solve<'a>( // TODO(ayazhafiz): presence constraints for Expr2/Type2 match unify(subs, actual, expected, Mode::EQ) { - Success(vars) => { + Success { + vars, + must_implement_ability: _, + } => { + // TODO(abilities) record deferred ability checks introduce(subs, rank, pools, &vars); state } - Failure(vars, actual_type, expected_type) => { + Failure(vars, actual_type, expected_type, _bad_impl) => { introduce(subs, rank, pools, &vars); let problem = TypeError::BadPattern( @@ -699,12 +711,16 @@ fn solve<'a>( let includes = type_to_var(arena, mempool, subs, rank, pools, cached_aliases, &tag_ty); match unify(subs, actual, includes, Mode::PRESENT) { - Success(vars) => { + Success { + vars, + must_implement_ability: _, + } => { + // TODO(abilities) record deferred ability checks introduce(subs, rank, pools, &vars); state } - Failure(vars, actual_type, expected_type) => { + Failure(vars, actual_type, expected_type, _bad_impl) => { introduce(subs, rank, pools, &vars); // TODO: do we need a better error type here? @@ -1281,7 +1297,7 @@ fn adjust_rank_content( use roc_types::subs::FlatType::*; match content { - FlexVar(_) | RigidVar(_) | Error => group_rank, + FlexVar(_) | RigidVar(_) | FlexAbleVar(..) | RigidAbleVar(..) | Error => group_rank, RecursionVar { .. } => group_rank, @@ -1536,7 +1552,7 @@ fn instantiate_rigids_help( }; } - FlexVar(_) | Error => {} + FlexVar(_) | FlexAbleVar(_, _) | Error => {} RecursionVar { structure, .. } => { instantiate_rigids_help(subs, max_rank, pools, structure); @@ -1547,6 +1563,11 @@ fn instantiate_rigids_help( subs.set(copy, make_descriptor(FlexVar(Some(name)))); } + RigidAbleVar(name, ability) => { + // what it's all about: convert the rigid var into a flex var + subs.set(copy, make_descriptor(FlexAbleVar(Some(name), ability))); + } + Alias(_, args, real_type_var, _) => { for var_index in args.all_variables() { let var = subs[var_index]; @@ -1772,7 +1793,7 @@ fn deep_copy_var_help( copy } - FlexVar(_) | Error => copy, + FlexVar(_) | FlexAbleVar(_, _) | Error => copy, RecursionVar { opt_name, @@ -1797,6 +1818,12 @@ fn deep_copy_var_help( copy } + RigidAbleVar(name, ability) => { + subs.set(copy, make_descriptor(FlexAbleVar(Some(name), ability))); + + copy + } + Alias(symbol, mut args, real_type_var, kind) => { let mut new_args = Vec::with_capacity(args.all_variables().len()); diff --git a/cli/src/build.rs b/cli/src/build.rs index ab3d7d0c42..c39b55f043 100644 --- a/cli/src/build.rs +++ b/cli/src/build.rs @@ -6,6 +6,7 @@ use roc_build::{ use roc_builtins::bitcode; use roc_load::LoadingProblem; use roc_mono::ir::OptLevel; +use roc_reporting::report::RenderTarget; use roc_target::TargetInfo; use std::path::PathBuf; use std::time::{Duration, SystemTime}; @@ -68,6 +69,8 @@ pub fn build_file<'a>( src_dir.as_path(), subs_by_module, target_info, + // TODO: expose this from CLI? + RenderTarget::ColorTerminal, )?; use target_lexicon::Architecture; @@ -374,6 +377,8 @@ pub fn check_file( src_dir.as_path(), subs_by_module, target_info, + // TODO: expose this from CLI? + RenderTarget::ColorTerminal, )?; let buf = &mut String::with_capacity(1024); diff --git a/docs/Cargo.toml b/docs/Cargo.toml index d377031ac9..1fe3c231e2 100644 --- a/docs/Cargo.toml +++ b/docs/Cargo.toml @@ -21,6 +21,7 @@ roc_parse = { path = "../compiler/parse" } roc_target = { path = "../compiler/roc_target" } roc_collections = { path = "../compiler/collections" } roc_highlight = { path = "../highlight"} +roc_reporting = { path = "../reporting"} bumpalo = { version = "3.8.0", features = ["collections"] } snafu = { version = "0.6.10", features = ["backtraces"] } peg = "0.8.0" diff --git a/docs/src/lib.rs b/docs/src/lib.rs index 7a4a05f0c9..d09134d98d 100644 --- a/docs/src/lib.rs +++ b/docs/src/lib.rs @@ -424,6 +424,7 @@ pub fn load_modules_for_files(filenames: Vec) -> Vec { src_dir.as_path(), Default::default(), roc_target::TargetInfo::default_x86_64(), // This is just type-checking for docs, so "target" doesn't matter + roc_reporting::report::RenderTarget::ColorTerminal, ) { Ok(loaded) => modules.push(loaded), Err(LoadingProblem::FormattedReport(report)) => { diff --git a/repl_eval/src/gen.rs b/repl_eval/src/gen.rs index a5e1fa6dbd..4e8f698c29 100644 --- a/repl_eval/src/gen.rs +++ b/repl_eval/src/gen.rs @@ -60,6 +60,7 @@ pub fn compile_to_mono<'a>( src_dir, exposed_types, target_info, + roc_reporting::report::RenderTarget::ColorTerminal, ); let mut loaded = match loaded { From 64b559073d90be0cc79752f26c7f8b9e55a562d2 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 12 Apr 2022 15:48:26 -0400 Subject: [PATCH 176/846] Clippy --- compiler/can/src/abilities.rs | 4 ++-- compiler/can/src/annotation.rs | 12 +++++------- compiler/load_internal/src/file.rs | 2 ++ compiler/solve/src/solve.rs | 1 + 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/compiler/can/src/abilities.rs b/compiler/can/src/abilities.rs index 71be29a706..16c90273e2 100644 --- a/compiler/can/src/abilities.rs +++ b/compiler/can/src/abilities.rs @@ -118,8 +118,8 @@ impl AbilitiesStore { specializing_symbol: Symbol, ) -> Option<(Symbol, &AbilityMemberData)> { let root_symbol = self.specialization_to_root.get(&specializing_symbol)?; - debug_assert!(self.ability_members.contains_key(&root_symbol)); - let root_data = self.ability_members.get(&root_symbol).unwrap(); + debug_assert!(self.ability_members.contains_key(root_symbol)); + let root_data = self.ability_members.get(root_symbol).unwrap(); Some((*root_symbol, root_data)) } diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index ddc5292dcd..c5d1ea3f23 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -159,14 +159,14 @@ impl IntroducedVariables { .named .iter() .find(|nv| &nv.name == name) - .map(|nv| NamedOrAbleVariable::Named(nv)) + .map(NamedOrAbleVariable::Named) { return Some(nav); } self.able .iter() .find(|av| &av.name == name) - .map(|av| NamedOrAbleVariable::Able(av)) + .map(NamedOrAbleVariable::Able) } } @@ -258,14 +258,12 @@ pub fn canonicalize_annotation_with_possible_clauses( &mut references, ); - let annot = Annotation { + Annotation { typ, introduced_variables, references, aliases, - }; - - annot + } } fn make_apply_symbol( @@ -897,7 +895,7 @@ fn canonicalize_has_clause( let var = var_store.fresh(); - introduced_variables.insert_able(var_name.clone(), Loc::at(region, var), ability); + introduced_variables.insert_able(var_name, Loc::at(region, var), ability); Ok(()) } diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index ae1a70d631..5585d32da3 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -618,6 +618,7 @@ struct State<'a> { type CachedSubs = Arc)>>>; impl<'a> State<'a> { + #[allow(clippy::too_many_arguments)] fn new( root_id: ModuleId, target_info: TargetInfo, @@ -3174,6 +3175,7 @@ fn add_imports( import_variables } +#[allow(clippy::complexity)] fn run_solve_solve( imported_builtins: Vec, exposed_for_module: ExposedForModule, diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index 8399b8cba2..12adce566f 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -1204,6 +1204,7 @@ fn solve( /// If a symbol claims to specialize an ability member, check that its solved type in fact /// does specialize the ability, and record the specialization. +#[allow(clippy::too_many_arguments)] fn check_ability_specialization( subs: &mut Subs, env: &Env, From cbbbb8c8554ddd98b046bb4ebc3b57cbcd9629ac Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 12 Apr 2022 16:32:50 -0400 Subject: [PATCH 177/846] Remove stray `dbg`s --- compiler/can/src/def.rs | 2 -- compiler/can/src/pattern.rs | 2 +- compiler/can/src/scope.rs | 7 ++----- reporting/src/error/type.rs | 2 +- 4 files changed, 4 insertions(+), 9 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 75d17270af..514d43d8e6 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -522,8 +522,6 @@ pub fn canonicalize_defs<'a>( .register_ability(loc_ability_name.value, can_members); } - dbg!(&scope.abilities_store, pattern_type); - // Now that we have the scope completely assembled, and shadowing resolved, // we're ready to canonicalize any body exprs. diff --git a/compiler/can/src/pattern.rs b/compiler/can/src/pattern.rs index 9df8cd7312..e620f41f00 100644 --- a/compiler/can/src/pattern.rs +++ b/compiler/can/src/pattern.rs @@ -166,7 +166,7 @@ pub fn canonicalize_def_header_pattern<'a>( match pattern { // Identifiers that shadow ability members may appear (and may only appear) at the header of a def. Identifier(name) => match scope.introduce_or_shadow_ability_member( - dbg!((*name).into()), + (*name).into(), &env.exposed_ident_ids, &mut env.ident_ids, region, diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index f08ba453a8..f4cb75e1be 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -248,17 +248,14 @@ impl Scope { all_ident_ids: &mut IdentIds, region: Region, ) -> Result<(Symbol, Option), (Region, Loc, Symbol)> { - match dbg!(self.idents.get(&ident)) { + match self.idents.get(&ident) { Some(&(original_symbol, original_region)) => { let shadow_ident_id = all_ident_ids.add(ident.clone()); let shadow_symbol = Symbol::new(self.home, shadow_ident_id); self.symbols.insert(shadow_symbol, region); - if self - .abilities_store - .is_ability_member_name(dbg!(original_symbol)) - { + if self.abilities_store.is_ability_member_name(original_symbol) { self.abilities_store .register_specializing_symbol(shadow_symbol, original_symbol); // Add a symbol for the shadow, but don't re-associate the member name. diff --git a/reporting/src/error/type.rs b/reporting/src/error/type.rs index 848c510651..823f87c47d 100644 --- a/reporting/src/error/type.rs +++ b/reporting/src/error/type.rs @@ -1769,7 +1769,7 @@ pub fn to_doc<'b>( ) -> (RocDocBuilder<'b>, AbleVariables) { let mut ctx = Context::default(); - let doc = to_doc_help(&mut ctx, alloc, parens, dbg!(tipe)); + let doc = to_doc_help(&mut ctx, alloc, parens, tipe); (doc, ctx.able_variables) } From 865c1f15d7d56d245eaef7014165fcb1dfd3de7a Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 12 Apr 2022 16:42:51 -0400 Subject: [PATCH 178/846] Fix test compile errors, and simply load_internal tests --- Cargo.lock | 2 +- compiler/load_internal/Cargo.toml | 1 - compiler/load_internal/tests/test_load.rs | 24 ++++++++++------------ compiler/test_gen/src/helpers/llvm.rs | 2 ++ compiler/test_mono/Cargo.toml | 1 + compiler/test_mono/src/tests.rs | 1 + reporting/tests/test_reporting.rs | 25 +++++++++++++++++++++++ 7 files changed, 41 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d2babf3e7b..71b9a3e355 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3737,7 +3737,6 @@ dependencies = [ "roc_target", "roc_types", "roc_unify", - "strip-ansi-escapes", "tempfile", "ven_pretty", ] @@ -4526,6 +4525,7 @@ dependencies = [ "roc_load", "roc_module", "roc_mono", + "roc_reporting", "roc_target", "test_mono_macros", ] diff --git a/compiler/load_internal/Cargo.toml b/compiler/load_internal/Cargo.toml index 5381fc94b9..3d876623f5 100644 --- a/compiler/load_internal/Cargo.toml +++ b/compiler/load_internal/Cargo.toml @@ -33,4 +33,3 @@ tempfile = "3.2.0" pretty_assertions = "1.0.0" maplit = "1.0.2" indoc = "1.0.3" -strip-ansi-escapes = "0.1.1" diff --git a/compiler/load_internal/tests/test_load.rs b/compiler/load_internal/tests/test_load.rs index 8f0223d483..9cc4a46721 100644 --- a/compiler/load_internal/tests/test_load.rs +++ b/compiler/load_internal/tests/test_load.rs @@ -25,6 +25,7 @@ mod test_load { use roc_problem::can::Problem; use roc_region::all::LineInfo; use roc_reporting::report::can_problem; + use roc_reporting::report::RenderTarget; use roc_reporting::report::RocDocAllocator; use roc_target::TargetInfo; use roc_types::pretty_print::{content_to_string, name_all_type_vars}; @@ -41,7 +42,7 @@ mod test_load { ) -> Result> { use LoadResult::*; - let load_start = LoadStart::from_path(arena, filename)?; + let load_start = LoadStart::from_path(arena, filename, RenderTarget::Generic)?; match roc_load_internal::file::load( arena, @@ -51,6 +52,7 @@ mod test_load { Phase::SolveTypes, target_info, Default::default(), // these tests will re-compile the builtins + RenderTarget::Generic, )? { Monomorphized(_) => unreachable!(""), TypeChecked(module) => Ok(module), @@ -88,8 +90,6 @@ mod test_load { } fn multiple_modules(files: Vec<(&str, &str)>) -> Result { - use roc_load_internal::file::LoadingProblem; - let arena = Bump::new(); let arena = &arena; @@ -589,18 +589,18 @@ mod test_load { report, indoc!( " - \u{1b}[36m── UNFINISHED LIST ─────────────────────────────────────────────────────────────\u{1b}[0m + ── UNFINISHED LIST ───────────────────────────────────────────────────────────── - I cannot find the end of this list: + I cannot find the end of this list: - \u{1b}[36m3\u{1b}[0m\u{1b}[36m│\u{1b}[0m \u{1b}[37mmain = [\u{1b}[0m - \u{1b}[31m^\u{1b}[0m + 3│ main = [ + ^ - You could change it to something like \u{1b}[33m[ 1, 2, 3 ]\u{1b}[0m or even just \u{1b}[33m[]\u{1b}[0m. - Anything where there is an open and a close square bracket, and where - the elements of the list are separated by commas. + You could change it to something like [ 1, 2, 3 ] or even just []. + Anything where there is an open and a close square bracket, and where + the elements of the list are separated by commas. - \u{1b}[4mNote\u{1b}[0m: I may be confused by indentation" + Note: I may be confused by indentation" ) ), Ok(_) => unreachable!("we expect failure here"), @@ -769,8 +769,6 @@ mod test_load { ]; let err = multiple_modules(modules).unwrap_err(); - let err = strip_ansi_escapes::strip(err).unwrap(); - let err = String::from_utf8(err).unwrap(); assert_eq!( err, indoc!( diff --git a/compiler/test_gen/src/helpers/llvm.rs b/compiler/test_gen/src/helpers/llvm.rs index f6660f977b..03bc6b7a1e 100644 --- a/compiler/test_gen/src/helpers/llvm.rs +++ b/compiler/test_gen/src/helpers/llvm.rs @@ -7,6 +7,7 @@ use roc_collections::all::MutSet; use roc_gen_llvm::llvm::externs::add_default_roc_externs; use roc_mono::ir::OptLevel; use roc_region::all::LineInfo; +use roc_reporting::report::RenderTarget; use target_lexicon::Triple; fn promote_expr_to_module(src: &str) -> String { @@ -57,6 +58,7 @@ fn create_llvm_module<'a>( src_dir, Default::default(), target_info, + RenderTarget::ColorTerminal, ); let mut loaded = match loaded { diff --git a/compiler/test_mono/Cargo.toml b/compiler/test_mono/Cargo.toml index 2f56668cb1..9f336dbe73 100644 --- a/compiler/test_mono/Cargo.toml +++ b/compiler/test_mono/Cargo.toml @@ -17,6 +17,7 @@ roc_load = { path = "../load" } roc_can = { path = "../can" } roc_mono = { path = "../mono" } roc_target = { path = "../roc_target" } +roc_reporting = { path = "../../reporting" } test_mono_macros = { path = "../test_mono_macros" } pretty_assertions = "1.0.0" bumpalo = { version = "3.8.0", features = ["collections"] } diff --git a/compiler/test_mono/src/tests.rs b/compiler/test_mono/src/tests.rs index 777a790d52..74e17f9a15 100644 --- a/compiler/test_mono/src/tests.rs +++ b/compiler/test_mono/src/tests.rs @@ -101,6 +101,7 @@ fn compiles_to_ir(test_name: &str, src: &str) { src_dir, Default::default(), TARGET_INFO, + roc_reporting::report::RenderTarget::Generic, ); let mut loaded = match loaded { diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 675a259de0..84e0509b5d 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -9462,4 +9462,29 @@ I need all branches in an `if` to have the same type! ), ) } + + #[test] + fn ability_specialization_is_incomplete() { + new_report_problem_as( + indoc!( + r#" + app "test" provides [ eq, le ] to "./platform" + + Eq has + eq : a, a -> Bool | a has Eq + le : a, a -> Bool | a has Eq + + Id := U64 + + eq = \$Id m, $Id n -> m == n + + le = \$Id m, $Id n -> m < n + "# + ), + indoc!( + r#" + "# + ), + ) + } } From a73c8a85c21907c0ceae1b11f5a0d5457528711b Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 12 Apr 2022 17:10:44 -0400 Subject: [PATCH 179/846] Remove stray test for now --- reporting/tests/test_reporting.rs | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 84e0509b5d..675a259de0 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -9462,29 +9462,4 @@ I need all branches in an `if` to have the same type! ), ) } - - #[test] - fn ability_specialization_is_incomplete() { - new_report_problem_as( - indoc!( - r#" - app "test" provides [ eq, le ] to "./platform" - - Eq has - eq : a, a -> Bool | a has Eq - le : a, a -> Bool | a has Eq - - Id := U64 - - eq = \$Id m, $Id n -> m == n - - le = \$Id m, $Id n -> m < n - "# - ), - indoc!( - r#" - "# - ), - ) - } } From 5171e3964d85a9b9f6e0a47cd7e611dd0d7710ab Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 12 Apr 2022 17:19:27 -0400 Subject: [PATCH 180/846] Lift able variables to the top of a reported error type --- reporting/src/error/type.rs | 141 ++++++++++++++++++++++++------ reporting/tests/test_reporting.rs | 2 +- 2 files changed, 113 insertions(+), 30 deletions(-) diff --git a/reporting/src/error/type.rs b/reporting/src/error/type.rs index 823f87c47d..737ea2be40 100644 --- a/reporting/src/error/type.rs +++ b/reporting/src/error/type.rs @@ -1687,10 +1687,12 @@ fn to_comparison<'b>( expected: ErrorType, ) -> Comparison<'b> { let diff = to_diff(alloc, Parens::Unnecessary, actual, expected); + let actual = type_with_able_vars(alloc, diff.left, diff.left_able); + let expected = type_with_able_vars(alloc, diff.right, diff.right_able); Comparison { - actual: alloc.type_block(diff.left), - expected: alloc.type_block(diff.right), + actual: alloc.type_block(actual), + expected: alloc.type_block(expected), problems: match diff.status { Status::Similar => vec![], Status::Different(problems) => problems, @@ -1743,7 +1745,9 @@ pub struct Diff { left: T, right: T, status: Status, - // TODO: include able variables + // idea: lift "able" type variables so they are shown at the top of a type. + left_able: AbleVariables, + right_able: AbleVariables, } fn ext_to_doc<'b>(alloc: &'b RocDocAllocator<'b>, ext: TypeExt) -> Option> { @@ -1798,13 +1802,7 @@ fn to_doc_help<'b>( FlexAbleVar(lowercase, ability) | RigidAbleVar(lowercase, ability) => { // TODO we should be putting able variables on the toplevel of the type, not here ctx.able_variables.push((lowercase.clone(), ability)); - alloc.concat(vec![ - alloc.type_variable(lowercase), - alloc.space(), - alloc.keyword("has"), - alloc.space(), - alloc.symbol_foreign_qualified(ability), - ]) + alloc.type_variable(lowercase) } Type(symbol, args) => report_text::apply( @@ -1926,15 +1924,42 @@ fn same<'b>( parens: Parens, tipe: ErrorType, ) -> Diff> { - let doc = to_doc(alloc, parens, tipe).0; + let (doc, able) = to_doc(alloc, parens, tipe); Diff { left: doc.clone(), right: doc, status: Status::Similar, + left_able: able.clone(), + right_able: able, } } +fn type_with_able_vars<'b>( + alloc: &'b RocDocAllocator<'b>, + typ: RocDocBuilder<'b>, + able: AbleVariables, +) -> RocDocBuilder<'b> { + if able.is_empty() { + // fast path: taken the vast majority of the time + return typ; + } + + let mut doc = Vec::with_capacity(1 + 6 * able.len()); + doc.push(typ); + + for (i, (var, ability)) in able.into_iter().enumerate() { + doc.push(alloc.string(if i == 0 { " | " } else { ", " }.to_string())); + doc.push(alloc.type_variable(var)); + doc.push(alloc.space()); + doc.push(alloc.keyword("has")); + doc.push(alloc.space()); + doc.push(alloc.symbol_foreign_qualified(ability)); + } + + alloc.concat(doc) +} + fn to_diff<'b>( alloc: &'b RocDocAllocator<'b>, parens: Parens, @@ -1963,15 +1988,21 @@ fn to_diff<'b>( let left = report_text::function(alloc, parens, arg_diff.left, ret_diff.left); let right = report_text::function(alloc, parens, arg_diff.right, ret_diff.right); + let mut left_able = arg_diff.left_able; + left_able.extend(ret_diff.left_able); + let mut right_able = arg_diff.right_able; + right_able.extend(ret_diff.right_able); Diff { left, right, status, + left_able, + right_able, } } else { - let left = to_doc(alloc, Parens::InFn, type1).0; - let right = to_doc(alloc, Parens::InFn, type2).0; + let (left, left_able) = to_doc(alloc, Parens::InFn, type1); + let (right, right_able) = to_doc(alloc, Parens::InFn, type2); Diff { left, @@ -1980,6 +2011,8 @@ fn to_diff<'b>( args1.len(), args2.len(), )]), + left_able, + right_able, } } } @@ -2002,6 +2035,8 @@ fn to_diff<'b>( left, right, status: args_diff.status, + left_able: args_diff.left_able, + right_able: args_diff.right_able, } } @@ -2024,17 +2059,21 @@ fn to_diff<'b>( left, right, status: args_diff.status, + left_able: args_diff.left_able, + right_able: args_diff.right_able, } } (Alias(_, _, _, AliasKind::Opaque), _) | (_, Alias(_, _, _, AliasKind::Opaque)) => { - let left = to_doc(alloc, Parens::InFn, type1).0; - let right = to_doc(alloc, Parens::InFn, type2).0; + let (left, left_able) = to_doc(alloc, Parens::InFn, type1); + let (right, right_able) = to_doc(alloc, Parens::InFn, type2); Diff { left, right, status: Status::Different(vec![Problem::OpaqueComparedToNonOpaque]), + left_able, + right_able, } } @@ -2061,20 +2100,22 @@ fn to_diff<'b>( (RecursiveTagUnion(_rec1, _tags1, _ext1), RecursiveTagUnion(_rec2, _tags2, _ext2)) => { // TODO do a better job here - let left = to_doc(alloc, Parens::Unnecessary, type1).0; - let right = to_doc(alloc, Parens::Unnecessary, type2).0; + let (left, left_able) = to_doc(alloc, Parens::Unnecessary, type1); + let (right, right_able) = to_doc(alloc, Parens::Unnecessary, type2); Diff { left, right, status: Status::Similar, + left_able, + right_able, } } pair => { // We hit none of the specific cases where we give more detailed information - let left = to_doc(alloc, parens, type1).0; - let right = to_doc(alloc, parens, type2).0; + let (left, left_able) = to_doc(alloc, parens, type1); + let (right, right_able) = to_doc(alloc, parens, type2); let is_int = |t: &ErrorType| match t { ErrorType::Type(Symbol::NUM_INT, _) => true, @@ -2130,6 +2171,8 @@ fn to_diff<'b>( left, right, status: Status::Different(problems), + left_able, + right_able, } } } @@ -2149,6 +2192,8 @@ where // TODO use ExactSizeIterator to pre-allocate here let mut left = Vec::new(); let mut right = Vec::new(); + let mut left_able = Vec::new(); + let mut right_able = Vec::new(); for (arg1, arg2) in args1.into_iter().zip(args2.into_iter()) { let diff = to_diff(alloc, parens, arg1, arg2); @@ -2156,12 +2201,16 @@ where left.push(diff.left); right.push(diff.right); status.merge(diff.status); + left_able.extend(diff.left_able); + right_able.extend(diff.right_able); } Diff { left, right, status, + left_able, + right_able, } } @@ -2228,6 +2277,8 @@ fn diff_record<'b>( _ => diff.status, } }, + left_able: diff.left_able, + right_able: diff.right_able, } }; @@ -2293,12 +2344,16 @@ fn diff_record<'b>( left: vec![], right: vec![], status: Status::Similar, + left_able: vec![], + right_able: vec![], }; for diff in both { fields_diff.left.push(diff.left); fields_diff.right.push(diff.right); fields_diff.status.merge(diff.status); + fields_diff.left_able.extend(diff.left_able); + fields_diff.right_able.extend(diff.right_able); } if !all_fields_shared { @@ -2336,6 +2391,8 @@ fn diff_record<'b>( left: doc1, right: doc2, status: fields_diff.status, + left_able: fields_diff.left_able, + right_able: fields_diff.right_able, } } @@ -2353,16 +2410,26 @@ fn diff_tag_union<'b>( left: (field.clone(), alloc.tag_name(field.clone()), diff.left), right: (field.clone(), alloc.tag_name(field), diff.right), status: diff.status, + left_able: diff.left_able, + right_able: diff.right_able, } }; - let to_unknown_docs = |(field, args): (&TagName, &Vec)| { + let to_unknown_docs = |(field, args): (&TagName, &Vec)| -> ( + TagName, + RocDocBuilder<'b>, + Vec>, + AbleVariables, + ) { + let (args, able): (_, Vec) = + // TODO add spaces between args + args.iter() + .map(|arg| to_doc(alloc, Parens::InTypeParam, arg.clone())) + .unzip(); ( field.clone(), alloc.tag_name(field.clone()), - // TODO add spaces between args - args.iter() - .map(|arg| to_doc(alloc, Parens::InTypeParam, arg.clone()).0) - .collect(), + args, + able.into_iter().flatten().collect(), ) }; let shared_keys = fields1 @@ -2380,7 +2447,7 @@ fn diff_tag_union<'b>( let status = match (ext_has_fixed_fields(&ext1), ext_has_fixed_fields(&ext2)) { (true, true) => match left.peek() { - Some((f, _, _)) => Status::Different(vec![Problem::TagTypo( + Some((f, _, _, _)) => Status::Different(vec![Problem::TagTypo( f.clone(), fields2.keys().cloned().collect(), )]), @@ -2397,14 +2464,14 @@ fn diff_tag_union<'b>( } }, (false, true) => match left.peek() { - Some((f, _, _)) => Status::Different(vec![Problem::TagTypo( + Some((f, _, _, _)) => Status::Different(vec![Problem::TagTypo( f.clone(), fields2.keys().cloned().collect(), )]), None => Status::Similar, }, (true, false) => match right.peek() { - Some((f, _, _)) => Status::Different(vec![Problem::TagTypo( + Some((f, _, _, _)) => Status::Different(vec![Problem::TagTypo( f.clone(), fields1.keys().cloned().collect(), )]), @@ -2419,17 +2486,27 @@ fn diff_tag_union<'b>( left: vec![], right: vec![], status: Status::Similar, + left_able: vec![], + right_able: vec![], }; for diff in both { fields_diff.left.push(diff.left); fields_diff.right.push(diff.right); fields_diff.status.merge(diff.status); + fields_diff.left_able.extend(diff.left_able); + fields_diff.right_able.extend(diff.right_able); } if !all_fields_shared { - fields_diff.left.extend(left); - fields_diff.right.extend(right); + for (tag, tag_doc, args, able) in left { + fields_diff.left.push((tag, tag_doc, args)); + fields_diff.left_able.extend(able); + } + for (tag, tag_doc, args, able) in right { + fields_diff.right.push((tag, tag_doc, args)); + fields_diff.right_able.extend(able); + } fields_diff.status.merge(Status::Different(vec![])); } @@ -2456,6 +2533,8 @@ fn diff_tag_union<'b>( left: doc1, right: doc2, status: fields_diff.status, + left_able: fields_diff.left_able, + right_able: fields_diff.right_able, } } @@ -2473,12 +2552,16 @@ fn ext_to_diff<'b>( left: ext_doc_1, right: ext_doc_2, status, + left_able: vec![], + right_able: vec![], }, Status::Different(_) => Diff { // NOTE elm colors these differently at this point left: ext_doc_1, right: ext_doc_2, status, + left_able: vec![], + right_able: vec![], }, } } diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 675a259de0..8a1fe1d0b9 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -9452,7 +9452,7 @@ I need all branches in an `if` to have the same type! But the type annotation on `hash` says it must match: - a has Hash -> U64 + a -> U64 | a has Hash Note: Some types in this specialization don't implement the abilities they are expected to. I found the following missing implementations: From 462f443956733b4a9770f6aced49197a11b1969e Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 12 Apr 2022 17:23:03 -0400 Subject: [PATCH 181/846] Comment --- compiler/solve/src/solve.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index 12adce566f..b0042086c4 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -1224,7 +1224,8 @@ fn check_ability_specialization( .get_var_by_symbol(&root_symbol) .expect("Ability should be registered in env by now!"); - // Check if they unify - if they don't, that's a type error! + // Check if they unify - if they don't, then the claimed specialization isn't really one, + // and that's a type error! let snapshot = subs.snapshot(); let unified = unify(subs, symbol_loc_var.value, root_signature_var, Mode::EQ); From 154a36398d2582963ea1276fbd7f65b0cc07d0e5 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Tue, 12 Apr 2022 17:28:07 -0400 Subject: [PATCH 182/846] Simplify app_render --- examples/breakout/platform/src/roc.rs | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/examples/breakout/platform/src/roc.rs b/examples/breakout/platform/src/roc.rs index d25ffca628..3ae0f189e6 100644 --- a/examples/breakout/platform/src/roc.rs +++ b/examples/breakout/platform/src/roc.rs @@ -19,9 +19,8 @@ extern "C" { #[link_name = "roc__programForHost_size"] fn roc_program_size() -> i64; - #[allow(dead_code)] #[link_name = "roc__programForHost_1_Render_size"] - fn size_Render() -> i64; + fn roc_render_size() -> i64; } #[repr(C)] @@ -254,33 +253,24 @@ pub struct ButtonStyles { pub text_color: Rgba, } -pub fn app_render(state: RocEvent) -> RocList { - let size = unsafe { roc_program_size() } as usize; - let layout = Layout::array::(size).unwrap(); +pub fn app_render(event: RocEvent) -> RocList { + let mut output = MaybeUninit::uninit(); + // Call the program's render function unsafe { - roc_program(); + let layout = Layout::array::(roc_render_size() as usize).unwrap(); // TODO allocate on the stack if it's under a certain size let buffer = std::alloc::alloc(layout); - // Call the program's render function - let result = call_the_closure(state, buffer); + call_Render(&event, buffer, output.as_mut_ptr()); std::alloc::dealloc(buffer, layout); - result + output.assume_init() } } -unsafe fn call_the_closure(event: RocEvent, closure_data_ptr: *const u8) -> RocList { - let mut output = MaybeUninit::uninit(); - - call_Render(&event, closure_data_ptr as *const u8, output.as_mut_ptr()); - - output.assume_init() -} - #[derive(Copy, Clone, Debug, Default)] #[repr(C)] pub struct Bounds { From b86bf94d9279f0f6b8e15530f4b2a008363727cc Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 12 Apr 2022 17:35:00 -0400 Subject: [PATCH 183/846] Dev, wasm test bugs --- compiler/test_gen/src/helpers/dev.rs | 1 + compiler/test_gen/src/helpers/wasm.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/compiler/test_gen/src/helpers/dev.rs b/compiler/test_gen/src/helpers/dev.rs index 2adcaadb90..0ecd1bb37c 100644 --- a/compiler/test_gen/src/helpers/dev.rs +++ b/compiler/test_gen/src/helpers/dev.rs @@ -54,6 +54,7 @@ pub fn helper( src_dir, Default::default(), roc_target::TargetInfo::default_x86_64(), + roc_reporting::report::RenderTarget::ColorTerminal, ); let mut loaded = loaded.expect("failed to load module"); diff --git a/compiler/test_gen/src/helpers/wasm.rs b/compiler/test_gen/src/helpers/wasm.rs index 6460cb1139..0c59df3cf5 100644 --- a/compiler/test_gen/src/helpers/wasm.rs +++ b/compiler/test_gen/src/helpers/wasm.rs @@ -91,6 +91,7 @@ fn compile_roc_to_wasm_bytes<'a, T: Wasm32Result>( src_dir, Default::default(), roc_target::TargetInfo::default_wasm32(), + roc_reporting::report::RenderTarget::ColorTerminal, ); let loaded = loaded.expect("failed to load module"); From 127d435ff2b25e89968a8cff4ecedab7c7531588 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 12 Apr 2022 18:24:10 -0400 Subject: [PATCH 184/846] Report incomplete ability implementations --- compiler/can/src/abilities.rs | 48 +++++++++++++++++++++++------- compiler/solve/src/solve.rs | 49 +++++++++++++++++++++++++++++-- reporting/src/error/type.rs | 47 +++++++++++++++++++++++++++++ reporting/tests/test_reporting.rs | 39 ++++++++++++++++++++++++ 4 files changed, 170 insertions(+), 13 deletions(-) diff --git a/compiler/can/src/abilities.rs b/compiler/can/src/abilities.rs index 16c90273e2..453cded77f 100644 --- a/compiler/can/src/abilities.rs +++ b/compiler/can/src/abilities.rs @@ -1,4 +1,4 @@ -use roc_collections::all::{MutMap, MutSet}; +use roc_collections::all::MutMap; use roc_module::symbol::Symbol; use roc_region::all::Region; use roc_types::{subs::Variable, types::Type}; @@ -13,6 +13,13 @@ pub struct AbilityMemberData { pub region: Region, } +/// A particular specialization of an ability member. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct MemberSpecialization { + pub symbol: Symbol, + pub region: Region, +} + /// Stores information about what abilities exist in a scope, what it means to implement an /// ability, and what types implement them. // TODO(abilities): this should probably go on the Scope, I don't put it there for now because we @@ -35,9 +42,9 @@ pub struct AbilitiesStore { /// We keep the mapping #hash1->#hash specialization_to_root: MutMap, - /// Tuples of (type, member) specifying that `type` declares an implementation of an ability - /// member `member`. - declared_specializations: MutSet<(Symbol, Symbol)>, + /// Maps a tuple (member, type) specifying that `type` declares an implementation of an ability + /// member `member`, to the exact symbol that implements the ability. + declared_specializations: MutMap<(Symbol, Symbol), MemberSpecialization>, } impl AbilitiesStore { @@ -69,15 +76,18 @@ impl AbilitiesStore { } /// Records a specialization of `ability_member` with specialized type `implementing_type`. + /// Entries via this function are considered a source of truth. It must be ensured that a + /// specialization is validated before being registered here. pub fn register_specialization_for_type( &mut self, - implementing_type: Symbol, ability_member: Symbol, + implementing_type: Symbol, + specialization: MemberSpecialization, ) { - let is_new_insert = self + let old_spec = self .declared_specializations - .insert((implementing_type, ability_member)); - debug_assert!(is_new_insert, "Replacing existing implementation"); + .insert((ability_member, implementing_type), specialization); + debug_assert!(old_spec.is_none(), "Replacing existing specialization"); } /// Checks if `name` is a root ability member symbol name. @@ -123,9 +133,27 @@ impl AbilitiesStore { Some((*root_symbol, root_data)) } + /// Finds the ability member definition for a member name. + pub fn member_def(&self, member: Symbol) -> Option<&AbilityMemberData> { + self.ability_members.get(&member) + } + + /// Returns an iterator over pairs (ability member, type) specifying that + /// "ability member" has a specialization with type "type". + pub fn get_known_specializations<'lifetime_for_copied>( + &'lifetime_for_copied self, + ) -> impl Iterator + 'lifetime_for_copied { + self.declared_specializations.keys().copied() + } + + /// Retrieves the specialization of `member` for `typ`, if it exists. + pub fn get_specialization(&self, member: Symbol, typ: Symbol) -> Option { + self.declared_specializations.get(&(member, typ)).copied() + } + /// Returns pairs of (type, ability member) specifying that "ability member" has a /// specialization with type "type". - pub fn get_known_specializations(&self) -> &MutSet<(Symbol, Symbol)> { - &self.declared_specializations + pub fn members_of_ability(&self, ability: Symbol) -> Option<&[Symbol]> { + self.members_of_ability.get(&ability).map(|v| v.as_ref()) } } diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index b0042086c4..b5e83160f9 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -1,5 +1,5 @@ use bumpalo::Bump; -use roc_can::abilities::AbilitiesStore; +use roc_can::abilities::{AbilitiesStore, MemberSpecialization}; use roc_can::constraint::Constraint::{self, *}; use roc_can::constraint::{Constraints, LetConstraint}; use roc_can::expected::{Expected, PExpected}; @@ -76,6 +76,13 @@ pub enum TypeError { CircularType(Region, Symbol, ErrorType), BadType(roc_types::types::Problem), UnexposedLookup(Symbol), + IncompleteAbilityImplementation { + // TODO(abilities): have general types here, not just opaques + typ: Symbol, + ability: Symbol, + specialized_members: Vec>, + missing_members: Vec>, + }, } use roc_types::types::Alias; @@ -568,7 +575,34 @@ pub fn run_in_place( &mut deferred_must_implement_abilities, ); - // TODO run through and check that all abilities are properly implemented + // Now that the module has been solved, we can run through and check all + // types claimed to implement abilities. + deferred_must_implement_abilities.dedup(); + for MustImplementAbility { typ, ability } in deferred_must_implement_abilities.into_iter() { + let members_of_ability = abilities_store.members_of_ability(ability).unwrap(); + let mut specialized_members = Vec::with_capacity(members_of_ability.len()); + let mut missing_members = Vec::with_capacity(members_of_ability.len()); + for &member in members_of_ability { + match abilities_store.get_specialization(member, typ) { + None => { + let root_data = abilities_store.member_def(member).unwrap(); + missing_members.push(Loc::at(root_data.region, member)); + } + Some(specialization) => { + specialized_members.push(Loc::at(specialization.region, member)); + } + } + } + + if !missing_members.is_empty() { + problems.push(TypeError::IncompleteAbilityImplementation { + typ, + ability, + specialized_members, + missing_members, + }); + } + } state.env } @@ -1254,8 +1288,17 @@ fn check_ability_specialization( "If there's more than one, the definition is ambiguous - this should be an error" ); + // This is a valid specialization! Record it. let specialization_type = ability_implementations_for_specialization[0].typ; - abilities_store.register_specialization_for_type(specialization_type, root_symbol); + let specialization = MemberSpecialization { + symbol, + region: symbol_loc_var.region, + }; + abilities_store.register_specialization_for_type( + root_symbol, + specialization_type, + specialization, + ); // Store the checks for what abilities must be implemented to be checked after the // whole module is complete. diff --git a/reporting/src/error/type.rs b/reporting/src/error/type.rs index 737ea2be40..c98d125e3d 100644 --- a/reporting/src/error/type.rs +++ b/reporting/src/error/type.rs @@ -118,6 +118,53 @@ pub fn type_problem<'b>( other => panic!("unhandled bad type: {:?}", other), } } + IncompleteAbilityImplementation { + typ, + ability, + specialized_members, + missing_members, + } => { + let title = "INCOMPLETE ABILITY IMPLEMENTATION".to_string(); + + let mut stack = vec![alloc.concat(vec![ + alloc.reflow("The type "), + alloc.symbol_unqualified(typ), + alloc.reflow(" does not fully implement the ability "), + alloc.symbol_unqualified(ability), + alloc.reflow(". The following specializations are missing:"), + ])]; + + for member in missing_members.into_iter() { + stack.push(alloc.concat(vec![ + alloc.reflow("A specialization for "), + alloc.symbol_unqualified(member.value), + alloc.reflow(", which is defined here:"), + ])); + stack.push(alloc.region(lines.convert_region(member.region))); + } + + debug_assert!(!specialized_members.is_empty()); + + stack.push(alloc.concat(vec![ + alloc.note(""), + alloc.symbol_unqualified(typ), + alloc.reflow(" specializes the following members of "), + alloc.symbol_unqualified(ability), + alloc.reflow(":"), + ])); + + for spec in specialized_members { + stack.push(alloc.concat(vec![ + alloc.symbol_unqualified(spec.value), + alloc.reflow(", specialized here:"), + ])); + stack.push(alloc.region(lines.convert_region(spec.region))); + } + + let doc = alloc.stack(stack); + + report(title, doc, filename) + } } } diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 8a1fe1d0b9..2b285c334f 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -9462,4 +9462,43 @@ I need all branches in an `if` to have the same type! ), ) } + + #[test] + fn ability_specialization_is_incomplete() { + new_report_problem_as( + indoc!( + r#" + app "test" provides [ eq, le ] to "./platform" + + Eq has + eq : a, a -> Bool | a has Eq + le : a, a -> Bool | a has Eq + + Id := U64 + + eq = \$Id m, $Id n -> m == n + "# + ), + indoc!( + r#" + ── INCOMPLETE ABILITY IMPLEMENTATION ─────────────────────────────────────────── + + The type `Id` does not fully implement the ability `Eq`. The following + specializations are missing: + + A specialization for `le`, which is defined here: + + 5│ le : a, a -> Bool | a has Eq + ^^ + + Note: `Id` specializes the following members of `Eq`: + + `eq`, specialized here: + + 9│ eq = \$Id m, $Id n -> m == n + ^^ + "# + ), + ) + } } From 16d00608246b605ac30b3185128aceec26465b54 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 12 Apr 2022 18:41:20 -0400 Subject: [PATCH 185/846] Report errors for type errors in specializations outside of ability impl --- compiler/solve/src/solve.rs | 16 +++++++------- reporting/tests/test_reporting.rs | 35 +++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index b5e83160f9..596b511af0 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -806,6 +806,7 @@ fn solve( let mut new_env = env.clone(); for (symbol, loc_var) in local_def_vars.iter() { check_ability_specialization( + arena, subs, &new_env, pools, @@ -1240,6 +1241,7 @@ fn solve( /// does specialize the ability, and record the specialization. #[allow(clippy::too_many_arguments)] fn check_ability_specialization( + arena: &Bump, subs: &mut Subs, env: &Env, pools: &mut Pools, @@ -1260,7 +1262,13 @@ fn check_ability_specialization( // Check if they unify - if they don't, then the claimed specialization isn't really one, // and that's a type error! - let snapshot = subs.snapshot(); + // This also fixes any latent type variables that need to be specialized to exactly what + // the ability signature expects. + + // We need to freshly instantiate the root signature so that all unifications are reflected + // in the specialization type, but not the original signature type. + let root_signature_var = + deep_copy_var_in(subs, Rank::toplevel(), pools, root_signature_var, arena); let unified = unify(subs, symbol_loc_var.value, root_signature_var, Mode::EQ); match unified { @@ -1268,10 +1276,6 @@ fn check_ability_specialization( vars: _, must_implement_ability, } => { - // We don't actually care about storing the unified type since the checked type for the - // specialization is what we want for code generation. - subs.rollback_to(snapshot); - if must_implement_ability.is_empty() { // This is an error.. but what kind? } @@ -1305,7 +1309,6 @@ fn check_ability_specialization( deferred_must_implement_abilities.extend(must_implement_ability); } Failure(vars, actual_type, expected_type, unimplemented_abilities) => { - subs.commit_snapshot(snapshot); introduce(subs, rank, pools, &vars); let reason = Reason::InvalidAbilityMemberSpecialization { @@ -1324,7 +1327,6 @@ fn check_ability_specialization( problems.push(problem); } BadType(vars, problem) => { - subs.commit_snapshot(snapshot); introduce(subs, rank, pools, &vars); problems.push(TypeError::BadType(problem)); diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 2b285c334f..e579b03db0 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -9463,6 +9463,41 @@ I need all branches in an `if` to have the same type! ) } + #[test] + fn ability_specialization_does_not_match_type() { + new_report_problem_as( + indoc!( + r#" + app "test" provides [ hash ] to "./platform" + + Hash has hash : a -> U64 | a has Hash + + Id := U32 + + hash = \$Id n -> n + "# + ), + indoc!( + r#" + ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + + Something is off with this specialization of `hash`: + + 7│ hash = \$Id n -> n + ^^^^ + + This value is a declared specialization of type: + + Id -> U32 + + But the type annotation on `hash` says it must match: + + Id -> U64 + "# + ), + ) + } + #[test] fn ability_specialization_is_incomplete() { new_report_problem_as( From d94556d807625947c742989dee3c71be6a73e26f Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 12 Apr 2022 18:52:49 -0400 Subject: [PATCH 186/846] Report overly general specializations --- compiler/solve/src/solve.rs | 40 +++++++++++++++++++++++++++--- compiler/types/src/types.rs | 4 +++ reporting/src/error/type.rs | 40 ++++++++++++++++++++++++++++++ reporting/tests/test_reporting.rs | 41 +++++++++++++++++++++++++++++++ 4 files changed, 122 insertions(+), 3 deletions(-) diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index 596b511af0..4a57c10378 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -1269,16 +1269,48 @@ fn check_ability_specialization( // in the specialization type, but not the original signature type. let root_signature_var = deep_copy_var_in(subs, Rank::toplevel(), pools, root_signature_var, arena); + let snapshot = subs.snapshot(); let unified = unify(subs, symbol_loc_var.value, root_signature_var, Mode::EQ); match unified { Success { vars: _, must_implement_ability, + } if must_implement_ability.is_empty() => { + // This can happen when every ability constriant on a type variable went + // through only another type variable. That means this def is not specialized + // for one type - for now, we won't admit this. + + // Rollback the snapshot so we unlink the root signature with the specialization, + // so we can have two separate error types. + subs.rollback_to(snapshot); + + let (expected_type, _problems) = subs.var_to_error_type(root_signature_var); + let (actual_type, _problems) = subs.var_to_error_type(symbol_loc_var.value); + + let reason = Reason::GeneralizedAbilityMemberSpecialization { + member_name: root_symbol, + def_region: root_data.region, + }; + + let problem = TypeError::BadExpr( + symbol_loc_var.region, + Category::AbilityMemberSpecialization(root_symbol), + actual_type, + Expected::ForReason(reason, expected_type, symbol_loc_var.region), + ); + + problems.push(problem); + + return; + } + + Success { + vars, + must_implement_ability, } => { - if must_implement_ability.is_empty() { - // This is an error.. but what kind? - } + subs.commit_snapshot(snapshot); + introduce(subs, rank, pools, &vars); // First, figure out and register for what type does this symbol specialize // the ability member. @@ -1309,6 +1341,7 @@ fn check_ability_specialization( deferred_must_implement_abilities.extend(must_implement_ability); } Failure(vars, actual_type, expected_type, unimplemented_abilities) => { + subs.commit_snapshot(snapshot); introduce(subs, rank, pools, &vars); let reason = Reason::InvalidAbilityMemberSpecialization { @@ -1327,6 +1360,7 @@ fn check_ability_specialization( problems.push(problem); } BadType(vars, problem) => { + subs.commit_snapshot(snapshot); introduce(subs, rank, pools, &vars); problems.push(TypeError::BadType(problem)); diff --git a/compiler/types/src/types.rs b/compiler/types/src/types.rs index 846ef8817d..8f5f68636e 100644 --- a/compiler/types/src/types.rs +++ b/compiler/types/src/types.rs @@ -1749,6 +1749,10 @@ pub enum Reason { def_region: Region, unimplemented_abilities: DoesNotImplementAbility, }, + GeneralizedAbilityMemberSpecialization { + member_name: Symbol, + def_region: Region, + }, } #[derive(PartialEq, Debug, Clone)] diff --git a/reporting/src/error/type.rs b/reporting/src/error/type.rs index c98d125e3d..b1d6334d77 100644 --- a/reporting/src/error/type.rs +++ b/reporting/src/error/type.rs @@ -1053,6 +1053,46 @@ fn to_expr_report<'b>( ) } + Reason::GeneralizedAbilityMemberSpecialization { + member_name, + def_region: _, + } => { + let problem = alloc.concat(vec![ + alloc.reflow("This specialization of "), + alloc.symbol_unqualified(member_name), + alloc.reflow(" is overly general:"), + ]); + let this_is = alloc.reflow("This value is"); + let instead_of = alloc.concat(vec![ + alloc.reflow("But the type annotation on "), + alloc.symbol_unqualified(member_name), + alloc.reflow(" says it must match:"), + ]); + + let note = alloc.stack(vec![ + alloc.concat(vec![ + alloc.note(""), + alloc.reflow("The specialized type is too general, and does not provide a concrete type where a type variable is bound to an ability."), + ]), + alloc.reflow("Specializations can only be made for concrete types. If you have a generic implementation for this value, perhaps you don't need an ability?"), + ]); + + report_mismatch( + alloc, + lines, + filename, + &category, + found, + expected_type, + region, + Some(expr_region), + problem, + this_is, + instead_of, + Some(note), + ) + } + Reason::LowLevelOpArg { op, arg_index } => { panic!( "Compiler bug: argument #{} to low-level operation {:?} was the wrong type!", diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index e579b03db0..d544e1cb64 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -9536,4 +9536,45 @@ I need all branches in an `if` to have the same type! ), ) } + + #[test] + fn ability_specialization_overly_generalized() { + new_report_problem_as( + indoc!( + r#" + app "test" provides [ hash ] to "./platform" + + Hash has + hash : a -> U64 | a has Hash + + hash = \_ -> 0u64 + "# + ), + indoc!( + r#" + ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + + This specialization of `hash` is overly general: + + 6│ hash = \_ -> 0u64 + ^^^^ + + This value is a declared specialization of type: + + a -> U64 + + But the type annotation on `hash` says it must match: + + a -> U64 | a has Hash + + Note: The specialized type is too general, and does not provide a + concrete type where a type variable is bound to an ability. + + Specializations can only be made for concrete types. If you have a + generic implementation for this value, perhaps you don't need an + ability? + "# + ), + ) + } } From cf1a6691dda7b8540ba4340bf93f87d082e7f72b Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 12 Apr 2022 18:54:12 -0400 Subject: [PATCH 187/846] Fix solve tests --- compiler/solve/tests/solve_expr.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index 6a0205be68..fd2f854633 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -5788,7 +5788,7 @@ mod solve_expr { hash = \$Id n -> n "# ), - [("Id", "hash")], + [("hash", "Id")], ) } @@ -5809,7 +5809,7 @@ mod solve_expr { hash32 = \$Id n -> Num.toU32 n "# ), - [("Id", "hash"), ("Id", "hash32")], + [("hash", "Id"), ("hash32", "Id")], ) } @@ -5837,7 +5837,7 @@ mod solve_expr { le = \$Id m, $Id n -> m < n "# ), - [("Id", "hash"), ("Id", "hash32"), ("Id", "eq"), ("Id", "le")], + [("hash", "Id"), ("hash32", "Id"), ("eq", "Id"), ("le", "Id")], ) } } From 67b5ab7fe7ff015a889fce2b1e386f252e7bebf8 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 12 Apr 2022 19:01:36 -0400 Subject: [PATCH 188/846] Add test for when specialization types conflict --- compiler/solve/src/solve.rs | 6 ++--- reporting/tests/test_reporting.rs | 42 +++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index 4a57c10378..7179caac90 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -1319,10 +1319,8 @@ fn check_ability_specialization( .filter(|mia| mia.ability == root_data.parent_ability) .collect::>(); ability_implementations_for_specialization.dedup(); - debug_assert_eq!( - ability_implementations_for_specialization.len(), 1, - "If there's more than one, the definition is ambiguous - this should be an error" - ); + + debug_assert!(ability_implementations_for_specialization.len() == 1, "Multiple variables bound to an ability - this is ambiguous and should have been caught in canonicalization"); // This is a valid specialization! Record it. let specialization_type = ability_implementations_for_specialization[0].typ; diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index d544e1cb64..a8d1b8a32a 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -9577,4 +9577,46 @@ I need all branches in an `if` to have the same type! ), ) } + + #[test] + fn ability_specialization_conflicting_specialization_types() { + new_report_problem_as( + indoc!( + r#" + app "test" provides [ eq ] to "./platform" + + Eq has + eq : a, a -> Bool | a has Eq + + You := {} + AndI := {} + + eq = \$You {}, $AndI {} -> False + "# + ), + indoc!( + r#" + ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + + Something is off with this specialization of `eq`: + + 9│ eq = \$You {}, $AndI {} -> False + ^^ + + This value is a declared specialization of type: + + You, AndI -> [ False, True ] + + But the type annotation on `eq` says it must match: + + You, You -> Bool + + Tip: Type comparisons between an opaque type are only ever equal if + both types are the same opaque type. Did you mean to create an opaque + type by wrapping it? If I have an opaque type Age := U32 I can create + an instance of this opaque type by doing @Age 23. + "# + ), + ) + } } From 0336b6ad27c996d779f8b07acc7c34ba7dc04132 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 12 Apr 2022 19:02:58 -0400 Subject: [PATCH 189/846] Clippy --- compiler/can/src/abilities.rs | 4 +--- compiler/solve/src/solve.rs | 2 -- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/compiler/can/src/abilities.rs b/compiler/can/src/abilities.rs index 453cded77f..558f73441d 100644 --- a/compiler/can/src/abilities.rs +++ b/compiler/can/src/abilities.rs @@ -140,9 +140,7 @@ impl AbilitiesStore { /// Returns an iterator over pairs (ability member, type) specifying that /// "ability member" has a specialization with type "type". - pub fn get_known_specializations<'lifetime_for_copied>( - &'lifetime_for_copied self, - ) -> impl Iterator + 'lifetime_for_copied { + pub fn get_known_specializations(&self) -> impl Iterator + '_ { self.declared_specializations.keys().copied() } diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index 7179caac90..aab17659f2 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -1301,8 +1301,6 @@ fn check_ability_specialization( ); problems.push(problem); - - return; } Success { From e7a298e7b9fe8a0b016567d24cd9f3b0dd9f812f Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Tue, 12 Apr 2022 17:34:33 -0400 Subject: [PATCH 190/846] Incorporate TEA into breakout --- examples/breakout/platform/src/roc.rs | 55 +++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/examples/breakout/platform/src/roc.rs b/examples/breakout/platform/src/roc.rs index 3ae0f189e6..5d4d1052fd 100644 --- a/examples/breakout/platform/src/roc.rs +++ b/examples/breakout/platform/src/roc.rs @@ -10,15 +10,41 @@ use std::os::raw::c_char; use winit::event::VirtualKeyCode; extern "C" { + // program + #[link_name = "roc__programForHost_1_exposed_generic"] fn roc_program() -> (); - #[link_name = "roc__programForHost_1_Render_caller"] - fn call_Render(event: *const RocEvent, closure_data: *const u8, output: *mut RocList); - #[link_name = "roc__programForHost_size"] fn roc_program_size() -> i64; + // init + + #[link_name = "roc__programForHost_1_Init_caller"] + fn call_init(size: *const Bounds, closure_data: *const u8, output: Model); + + #[link_name = "roc__programForHost_1_Init_size"] + fn init_size() -> i64; + + #[link_name = "roc__mainForHost_1_Init_result_size"] + fn init_result_size() -> i64; + + // update + + #[link_name = "roc__programForHost_1_Update_caller"] + fn call_update(model: Model, event: *const RocEvent, closure_data: *const u8, output: Model); + + #[link_name = "roc__programForHost_1_Update_size"] + fn update_size() -> i64; + + #[link_name = "roc__mainForHost_1_Update_result_size"] + fn update_result_size() -> i64; + + // render + + #[link_name = "roc__programForHost_1_Render_caller"] + fn call_render(model: ConstModel, closure_data: *const u8, output: *mut RocList); + #[link_name = "roc__programForHost_1_Render_size"] fn roc_render_size() -> i64; } @@ -263,7 +289,7 @@ pub fn app_render(event: RocEvent) -> RocList { // TODO allocate on the stack if it's under a certain size let buffer = std::alloc::alloc(layout); - call_Render(&event, buffer, output.as_mut_ptr()); + call_render(&event, buffer, output.as_mut_ptr()); std::alloc::dealloc(buffer, layout); @@ -277,3 +303,24 @@ pub struct Bounds { pub height: f32, pub width: f32, } + +struct Model(*mut c_void); + +impl Model { + fn new() -> Self { + const size = init_size(); + const raw_output = allocator.allocAdvanced(u8, @alignOf(u64), @intCast(usize, size), .at_least) catch unreachable; + + Self(raw_output as *mut c_void) + } +} + +fn init(bounds: Bounds) -> Model { + const closure: [*]u8 = undefined; + const output = allocate_model(allocator); + + roc__mainForHost_1_Init_caller(closure, closure, output); + fn call_init(&bounds, closure_data, output); + + return output; +} From 566e7f9a79b6b611396c17028993b36e3316a556 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Tue, 12 Apr 2022 22:14:31 -0400 Subject: [PATCH 191/846] Call init and render on app startup --- examples/breakout/platform/src/gui.rs | 4 +- examples/breakout/platform/src/roc.rs | 61 ++++++++++++++++++--------- 2 files changed, 43 insertions(+), 22 deletions(-) diff --git a/examples/breakout/platform/src/gui.rs b/examples/breakout/platform/src/gui.rs index 9f4af16a34..16ddee84b4 100644 --- a/examples/breakout/platform/src/gui.rs +++ b/examples/breakout/platform/src/gui.rs @@ -37,6 +37,8 @@ use winit::{ const TIME_BETWEEN_RENDERS: Duration = Duration::new(0, 1000 / 60); pub fn run_event_loop(title: &str, window_bounds: Bounds) -> Result<(), Box> { + let mut elems = roc::init(window_bounds); + // Open window and create a surface let mut event_loop = winit::event_loop::EventLoop::new(); @@ -46,8 +48,6 @@ pub fn run_event_loop(title: &str, window_bounds: Bounds) -> Result<(), Box i64; @@ -32,7 +32,12 @@ extern "C" { // update #[link_name = "roc__programForHost_1_Update_caller"] - fn call_update(model: Model, event: *const RocEvent, closure_data: *const u8, output: Model); + fn call_update( + model: *const Model, + event: *const RocEvent, + closure_data: *const u8, + output: *mut Model, + ); #[link_name = "roc__programForHost_1_Update_size"] fn update_size() -> i64; @@ -43,7 +48,7 @@ extern "C" { // render #[link_name = "roc__programForHost_1_Render_caller"] - fn call_render(model: ConstModel, closure_data: *const u8, output: *mut RocList); + fn call_render(model: *const Model, closure_data: *const u8, output: *mut RocList); #[link_name = "roc__programForHost_1_Render_size"] fn roc_render_size() -> i64; @@ -279,7 +284,7 @@ pub struct ButtonStyles { pub text_color: Rgba, } -pub fn app_render(event: RocEvent) -> RocList { +pub fn render(event: RocEvent) -> RocList { let mut output = MaybeUninit::uninit(); // Call the program's render function @@ -304,23 +309,39 @@ pub struct Bounds { pub width: f32, } -struct Model(*mut c_void); +type Model = c_void; -impl Model { - fn new() -> Self { - const size = init_size(); - const raw_output = allocator.allocAdvanced(u8, @alignOf(u64), @intCast(usize, size), .at_least) catch unreachable; +/// Call the app's init function +pub fn init(bounds: Bounds) -> RocList { + let closure_data_buf; + let layout; - Self(raw_output as *mut c_void) + // Call init to get the initial model + let model = unsafe { + let mut ret_val = MaybeUninit::uninit(); + + layout = Layout::array::(init_size() as usize).unwrap(); + + // TODO allocate on the stack if it's under a certain size + closure_data_buf = std::alloc::alloc(layout); + + call_init(&bounds, closure_data_buf, ret_val.as_mut_ptr()); + + ret_val.assume_init() + }; + + // Call render passing the model to get the initial Elem + unsafe { + let mut ret_val = MaybeUninit::uninit(); + + // Reuse the buffer from the previous closure if possible + let closure_data_buf = + std::alloc::realloc(closure_data_buf, layout, roc_render_size() as usize); + + call_render(&model, closure_data_buf, ret_val.as_mut_ptr()); + + std::alloc::dealloc(closure_data_buf, layout); + + ret_val.assume_init() } } - -fn init(bounds: Bounds) -> Model { - const closure: [*]u8 = undefined; - const output = allocate_model(allocator); - - roc__mainForHost_1_Init_caller(closure, closure, output); - fn call_init(&bounds, closure_data, output); - - return output; -} From 82b55ae4c9b6d5851ebd6c4de1366347bfa7a174 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Tue, 12 Apr 2022 22:34:16 -0400 Subject: [PATCH 192/846] Initialize both model and elems at once --- examples/breakout/platform/Package-Config.roc | 4 +++- examples/breakout/platform/src/gui.rs | 2 +- examples/breakout/platform/src/roc.rs | 9 ++++++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/examples/breakout/platform/Package-Config.roc b/examples/breakout/platform/Package-Config.roc index 076ac21f1c..7a9f031e64 100644 --- a/examples/breakout/platform/Package-Config.roc +++ b/examples/breakout/platform/Package-Config.roc @@ -7,13 +7,15 @@ platform "gui" Rgba : { r : F32, g : F32, b : F32, a : F32 } +Bounds : { height : F32, width: F32 } + Elem : [ Rect { color : Rgba, left : F32, top : F32, width : F32, height : F32 }, Text Str ] Event : [ Resize { width : F32, height : F32 }, KeyDown U32, KeyUp U32 ] # TODO allow changing the window title - maybe via a Task, since that shouldn't happen all the time programForHost : { - init : ({} -> Model) as Init, + init : (Bounds -> Model) as Init, update : (Model, Event -> Model) as Update, render : (Model -> List Elem) as Render } diff --git a/examples/breakout/platform/src/gui.rs b/examples/breakout/platform/src/gui.rs index 16ddee84b4..4f461f58e6 100644 --- a/examples/breakout/platform/src/gui.rs +++ b/examples/breakout/platform/src/gui.rs @@ -37,7 +37,7 @@ use winit::{ const TIME_BETWEEN_RENDERS: Duration = Duration::new(0, 1000 / 60); pub fn run_event_loop(title: &str, window_bounds: Bounds) -> Result<(), Box> { - let mut elems = roc::init(window_bounds); + let (model, mut elems) = roc::init_and_render(window_bounds); // Open window and create a surface let mut event_loop = winit::event_loop::EventLoop::new(); diff --git a/examples/breakout/platform/src/roc.rs b/examples/breakout/platform/src/roc.rs index 24c0566ecb..a61be8eed5 100644 --- a/examples/breakout/platform/src/roc.rs +++ b/examples/breakout/platform/src/roc.rs @@ -312,7 +312,7 @@ pub struct Bounds { type Model = c_void; /// Call the app's init function -pub fn init(bounds: Bounds) -> RocList { +pub fn init_and_render(bounds: Bounds) -> (*const Model, RocList) { let closure_data_buf; let layout; @@ -330,8 +330,9 @@ pub fn init(bounds: Bounds) -> RocList { ret_val.assume_init() }; - // Call render passing the model to get the initial Elem unsafe { + // Call render passing the model to get the initial Elems + let elems = unsafe { let mut ret_val = MaybeUninit::uninit(); // Reuse the buffer from the previous closure if possible @@ -343,5 +344,7 @@ pub fn init(bounds: Bounds) -> RocList { std::alloc::dealloc(closure_data_buf, layout); ret_val.assume_init() - } + }; + + (&model, elems) } From 105730fc1b6302e06db1564564f9d924427dd5f1 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Tue, 12 Apr 2022 22:35:32 -0400 Subject: [PATCH 193/846] Reproduce init returning wrong floats --- examples/breakout/breakout.roc | 3 ++- examples/breakout/platform/src/gui.rs | 2 ++ examples/breakout/platform/src/roc.rs | 11 ++++++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index 682c5b1c4d..191c652934 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -58,4 +58,5 @@ render = \state -> Rect { left, top, width, height, color } - List.append rects paddle + # List.append rects paddle + [ Rect { left: 1, top: 2, width: state.width, height: state.height, color: { r: 0.8, g: 0.8, b: 0.8, a: 1.0 } } ] diff --git a/examples/breakout/platform/src/gui.rs b/examples/breakout/platform/src/gui.rs index 4f461f58e6..f94e760a1b 100644 --- a/examples/breakout/platform/src/gui.rs +++ b/examples/breakout/platform/src/gui.rs @@ -39,6 +39,8 @@ const TIME_BETWEEN_RENDERS: Duration = Duration::new(0, 1000 / 60); pub fn run_event_loop(title: &str, window_bounds: Bounds) -> Result<(), Box> { let (model, mut elems) = roc::init_and_render(window_bounds); + dbg!(&elems); + // Open window and create a surface let mut event_loop = winit::event_loop::EventLoop::new(); diff --git a/examples/breakout/platform/src/roc.rs b/examples/breakout/platform/src/roc.rs index a61be8eed5..746552f3f1 100644 --- a/examples/breakout/platform/src/roc.rs +++ b/examples/breakout/platform/src/roc.rs @@ -294,7 +294,10 @@ pub fn render(event: RocEvent) -> RocList { // TODO allocate on the stack if it's under a certain size let buffer = std::alloc::alloc(layout); - call_render(&event, buffer, output.as_mut_ptr()); + if true { + todo!("call render here"); + // call_render(&event, buffer, output.as_mut_ptr()); + } std::alloc::dealloc(buffer, layout); @@ -325,12 +328,18 @@ pub fn init_and_render(bounds: Bounds) -> (*const Model, RocList) { // TODO allocate on the stack if it's under a certain size closure_data_buf = std::alloc::alloc(layout); + dbg!(&bounds); + call_init(&bounds, closure_data_buf, ret_val.as_mut_ptr()); ret_val.assume_init() }; unsafe { + let model_returned_by_init: Bounds = *std::mem::transmute::<&c_void, *const Bounds>(&model); + dbg!(model_returned_by_init); + } + // Call render passing the model to get the initial Elems let elems = unsafe { let mut ret_val = MaybeUninit::uninit(); From 76e98f7add2a168b9f3ee99d472612e3fb57d700 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 13 Apr 2022 00:09:36 -0400 Subject: [PATCH 194/846] Add Into for Target --- cli/src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 7d82ed074c..32b041b783 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -568,6 +568,12 @@ impl Target { } } +impl From<&Target> for Triple { + fn from(target: &Target) -> Self { + target.to_triple() + } +} + impl std::fmt::Display for Target { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", self.as_str()) From 2e1b384bdc2ca2c8fb4f50cb53c2da69cea787ee Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 13 Apr 2022 00:09:42 -0400 Subject: [PATCH 195/846] Drop unused import --- compiler/load_internal/tests/test_load.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/compiler/load_internal/tests/test_load.rs b/compiler/load_internal/tests/test_load.rs index 8f0223d483..032492dc2c 100644 --- a/compiler/load_internal/tests/test_load.rs +++ b/compiler/load_internal/tests/test_load.rs @@ -88,8 +88,6 @@ mod test_load { } fn multiple_modules(files: Vec<(&str, &str)>) -> Result { - use roc_load_internal::file::LoadingProblem; - let arena = Bump::new(); let arena = &arena; From 746fb6ce883fdc0f654e32d7af3efbd307e4c03c Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 13 Apr 2022 00:10:02 -0400 Subject: [PATCH 196/846] Make --target flags be linux32 and linux64 --- cli/src/lib.rs | 72 ++++++++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 32b041b783..185b3eedb0 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -15,7 +15,9 @@ use std::path::PathBuf; use std::process; use std::process::Command; use target_lexicon::BinaryFormat; -use target_lexicon::{Architecture, OperatingSystem, Triple, X86_32Architecture}; +use target_lexicon::{ + Architecture, Environment, OperatingSystem, Triple, Vendor, X86_32Architecture, +}; pub mod build; mod format; @@ -509,8 +511,8 @@ fn run_with_wasmer(_wasm_path: &std::path::Path, _args: &[String]) { enum Target { Host, - X86_32, - X86_64, + Linux32, + Linux64, Wasm32, } @@ -522,48 +524,50 @@ impl Default for Target { impl Target { const fn as_str(&self) -> &'static str { + use Target::*; + match self { - Target::Host => "host", - Target::X86_32 => "x86_32", - Target::X86_64 => "x86_64", - Target::Wasm32 => "wasm32", + Host => "host", + Linux32 => "linux32", + Linux64 => "linux64", + Wasm32 => "wasm32", } } /// NOTE keep up to date! const OPTIONS: &'static [&'static str] = &[ Target::Host.as_str(), - Target::X86_32.as_str(), - Target::X86_64.as_str(), + Target::Linux32.as_str(), + Target::Linux64.as_str(), Target::Wasm32.as_str(), ]; fn to_triple(&self) -> Triple { - let mut triple = Triple::unknown(); + use Target::*; match self { - Target::Host => Triple::host(), - Target::X86_32 => { - triple.architecture = Architecture::X86_32(X86_32Architecture::I386); - triple.binary_format = BinaryFormat::Elf; - - // TODO make this user-specified? - triple.operating_system = OperatingSystem::Linux; - - triple - } - Target::X86_64 => { - triple.architecture = Architecture::X86_64; - triple.binary_format = BinaryFormat::Elf; - - triple - } - Target::Wasm32 => { - triple.architecture = Architecture::Wasm32; - triple.binary_format = BinaryFormat::Wasm; - - triple - } + Host => Triple::host(), + Linux32 => Triple { + architecture: Architecture::X86_32(X86_32Architecture::I386), + vendor: Vendor::Unknown, + operating_system: OperatingSystem::Linux, + environment: Environment::Unknown, + binary_format: BinaryFormat::Elf, + }, + Linux64 => Triple { + architecture: Architecture::X86_64, + vendor: Vendor::Unknown, + operating_system: OperatingSystem::Linux, + environment: Environment::Unknown, + binary_format: BinaryFormat::Elf, + }, + Wasm32 => Triple { + architecture: Architecture::Wasm32, + vendor: Vendor::Unknown, + operating_system: OperatingSystem::Unknown, + environment: Environment::Unknown, + binary_format: BinaryFormat::Wasm, + }, } } } @@ -586,8 +590,8 @@ impl std::str::FromStr for Target { fn from_str(s: &str) -> Result { match s { "host" => Ok(Target::Host), - "x86_32" => Ok(Target::X86_32), - "x86_64" => Ok(Target::X86_64), + "linux32" => Ok(Target::Linux32), + "linux64" => Ok(Target::Linux64), "wasm32" => Ok(Target::Wasm32), _ => Err(()), } From 9f8be769fbb5686372d2b1137ce903bc580964e9 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 13 Apr 2022 00:33:12 -0400 Subject: [PATCH 197/846] Specify environments on linux targets --- cli/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 185b3eedb0..36d89a5a9e 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -551,14 +551,14 @@ impl Target { architecture: Architecture::X86_32(X86_32Architecture::I386), vendor: Vendor::Unknown, operating_system: OperatingSystem::Linux, - environment: Environment::Unknown, + environment: Environment::Musl, binary_format: BinaryFormat::Elf, }, Linux64 => Triple { architecture: Architecture::X86_64, vendor: Vendor::Unknown, operating_system: OperatingSystem::Linux, - environment: Environment::Unknown, + environment: Environment::Gnu, binary_format: BinaryFormat::Elf, }, Wasm32 => Triple { From c7f5beb0ad4a366f1e057ba7d05002a0117ac2e4 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 13 Apr 2022 00:35:59 -0400 Subject: [PATCH 198/846] Rename generated .bc files to have target triples --- compiler/builtins/bitcode/build.zig | 14 +++++++------- compiler/builtins/build.rs | 6 +++--- compiler/gen_llvm/src/llvm/build.rs | 6 +++--- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/compiler/builtins/bitcode/build.zig b/compiler/builtins/bitcode/build.zig index 377f975018..2b2d7793fa 100644 --- a/compiler/builtins/bitcode/build.zig +++ b/compiler/builtins/bitcode/build.zig @@ -28,17 +28,17 @@ pub fn build(b: *Builder) void { // TODO allow for native target for maximum speed }, }); - const i386_target = makeI386Target(); + const linux32_target = makeLinux32Target(); const wasm32_target = makeWasm32Target(); // LLVM IR - generateLlvmIrFile(b, mode, host_target, main_path, "ir", "builtins-host"); - generateLlvmIrFile(b, mode, i386_target, main_path, "ir-i386", "builtins-i386"); - generateLlvmIrFile(b, mode, wasm32_target, main_path, "ir-wasm32", "builtins-wasm32"); + generateLlvmIrFile(b, mode, host_target, main_path, "ir", "host"); + generateLlvmIrFile(b, mode, linux32_target, main_path, "ir-i386", "i386-unknown-linux-musl"); + generateLlvmIrFile(b, mode, wasm32_target, main_path, "ir-wasm32", "wasm32-unknown-unknown"); // Generate Object Files - generateObjectFile(b, mode, host_target, main_path, "object", "builtins-host"); - generateObjectFile(b, mode, wasm32_target, main_path, "wasm32-object", "builtins-wasm32"); + generateObjectFile(b, mode, host_target, main_path, "object", "host"); + generateObjectFile(b, mode, wasm32_target, main_path, "wasm32-object", "wasm32"); removeInstallSteps(b); } @@ -87,7 +87,7 @@ fn generateObjectFile( obj_step.dependOn(&obj.step); } -fn makeI386Target() CrossTarget { +fn makeLinux32Target() CrossTarget { var target = CrossTarget.parse(.{}) catch unreachable; target.cpu_arch = std.Target.Cpu.Arch.i386; diff --git a/compiler/builtins/build.rs b/compiler/builtins/build.rs index ca1ce3678c..4fea8e5373 100644 --- a/compiler/builtins/build.rs +++ b/compiler/builtins/build.rs @@ -36,14 +36,14 @@ fn main() { // LLVM .bc FILES - generate_bc_file(&bitcode_path, &build_script_dir_path, "ir", "builtins-host"); + generate_bc_file(&bitcode_path, &build_script_dir_path, "ir", "host"); if !DEBUG { generate_bc_file( &bitcode_path, &build_script_dir_path, "ir-wasm32", - "builtins-wasm32", + "wasm32-unknown-unknown", ); } @@ -51,7 +51,7 @@ fn main() { &bitcode_path, &build_script_dir_path, "ir-i386", - "builtins-i386", + "i386-unknown-linux-musl", ); // OBJECT FILES diff --git a/compiler/gen_llvm/src/llvm/build.rs b/compiler/gen_llvm/src/llvm/build.rs index 8afb896b6d..f11f0f83d2 100644 --- a/compiler/gen_llvm/src/llvm/build.rs +++ b/compiler/gen_llvm/src/llvm/build.rs @@ -411,21 +411,21 @@ pub fn module_from_builtins<'ctx>( // In the build script for the builtins module, we compile the builtins into LLVM bitcode let bitcode_bytes: &[u8] = if target == &target_lexicon::Triple::host() { - include_bytes!("../../../builtins/bitcode/builtins-host.bc") + include_bytes!("../../../builtins/bitcode/host.bc") } else { match target { Triple { architecture: Architecture::Wasm32, .. } => { - include_bytes!("../../../builtins/bitcode/builtins-wasm32.bc") + include_bytes!("../../../builtins/bitcode/wasm32-unknown-unknown.bc") } Triple { architecture: Architecture::X86_32(_), operating_system: OperatingSystem::Linux, .. } => { - include_bytes!("../../../builtins/bitcode/builtins-i386.bc") + include_bytes!("../../../builtins/bitcode/i386-unknown-linux-musl.bc") } _ => panic!( "The zig builtins are not currently built for this target: {:?}", From e1a88f190cee1daf2fb69b5c68293ea5ab7955ba Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 13 Apr 2022 00:45:22 -0400 Subject: [PATCH 199/846] Add a target triple for 32-bit musl linux --- cli/src/lib.rs | 2 +- compiler/build/src/target.rs | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 36d89a5a9e..1b1fdeec80 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -558,7 +558,7 @@ impl Target { architecture: Architecture::X86_64, vendor: Vendor::Unknown, operating_system: OperatingSystem::Linux, - environment: Environment::Gnu, + environment: Environment::Musl, binary_format: BinaryFormat::Elf, }, Wasm32 => Triple { diff --git a/compiler/build/src/target.rs b/compiler/build/src/target.rs index cf79283410..398eec6316 100644 --- a/compiler/build/src/target.rs +++ b/compiler/build/src/target.rs @@ -5,7 +5,7 @@ use inkwell::{ }; #[cfg(feature = "llvm")] use roc_mono::ir::OptLevel; -use target_lexicon::{Architecture, OperatingSystem, Triple}; +use target_lexicon::{Architecture, Environment, OperatingSystem, Triple}; pub fn target_triple_str(target: &Triple) -> &'static str { // Best guide I've found on how to determine these magic strings: @@ -62,6 +62,12 @@ pub fn target_zig_str(target: &Triple) -> &'static str { operating_system: OperatingSystem::Linux, .. } => "x86_64-linux-gnu", + Triple { + architecture: Architecture::X86_32(target_lexicon::X86_32Architecture::I386), + operating_system: OperatingSystem::Linux, + environment: Environment::Musl, + .. + } => "i386-linux-musl", Triple { architecture: Architecture::X86_32(target_lexicon::X86_32Architecture::I386), operating_system: OperatingSystem::Linux, From 412eb763bb224f83e44444e93a5b5e9369d33d79 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 13 Apr 2022 00:45:28 -0400 Subject: [PATCH 200/846] Add support for x64 linux --- compiler/build/src/target.rs | 6 ++++++ compiler/builtins/bitcode/build.zig | 12 ++++++++++++ compiler/builtins/build.rs | 7 +++++++ compiler/gen_llvm/src/llvm/build.rs | 7 +++++++ 4 files changed, 32 insertions(+) diff --git a/compiler/build/src/target.rs b/compiler/build/src/target.rs index 398eec6316..6beee37300 100644 --- a/compiler/build/src/target.rs +++ b/compiler/build/src/target.rs @@ -57,6 +57,12 @@ pub fn target_zig_str(target: &Triple) -> &'static str { // and an open proposal to unify them with the more typical "target triples": // https://github.com/ziglang/zig/issues/4911 match target { + Triple { + architecture: Architecture::X86_64, + operating_system: OperatingSystem::Linux, + environment: Environment::Musl, + .. + } => "x86_64-linux-musl", Triple { architecture: Architecture::X86_64, operating_system: OperatingSystem::Linux, diff --git a/compiler/builtins/bitcode/build.zig b/compiler/builtins/bitcode/build.zig index 2b2d7793fa..6522f76bc2 100644 --- a/compiler/builtins/bitcode/build.zig +++ b/compiler/builtins/bitcode/build.zig @@ -29,11 +29,13 @@ pub fn build(b: *Builder) void { }, }); const linux32_target = makeLinux32Target(); + const linux64_target = makeLinux64Target(); const wasm32_target = makeWasm32Target(); // LLVM IR generateLlvmIrFile(b, mode, host_target, main_path, "ir", "host"); generateLlvmIrFile(b, mode, linux32_target, main_path, "ir-i386", "i386-unknown-linux-musl"); + generateLlvmIrFile(b, mode, linux64_target, main_path, "ir-x86_64", "x86_64-unknown-linux-musl"); generateLlvmIrFile(b, mode, wasm32_target, main_path, "ir-wasm32", "wasm32-unknown-unknown"); // Generate Object Files @@ -97,6 +99,16 @@ fn makeLinux32Target() CrossTarget { return target; } +fn makeLinux64Target() CrossTarget { + var target = CrossTarget.parse(.{}) catch unreachable; + + target.cpu_arch = std.Target.Cpu.Arch.x86_64; + target.os_tag = std.Target.Os.Tag.linux; + target.abi = std.Target.Abi.musl; + + return target; +} + fn makeWasm32Target() CrossTarget { var target = CrossTarget.parse(.{}) catch unreachable; diff --git a/compiler/builtins/build.rs b/compiler/builtins/build.rs index 4fea8e5373..00bd61028c 100644 --- a/compiler/builtins/build.rs +++ b/compiler/builtins/build.rs @@ -54,6 +54,13 @@ fn main() { "i386-unknown-linux-musl", ); + generate_bc_file( + &bitcode_path, + &build_script_dir_path, + "ir-x86_64", + "x86_64-unknown-linux-musl", + ); + // OBJECT FILES #[cfg(windows)] const BUILTINS_HOST_FILE: &str = "builtins-host.obj"; diff --git a/compiler/gen_llvm/src/llvm/build.rs b/compiler/gen_llvm/src/llvm/build.rs index f11f0f83d2..d406abecf5 100644 --- a/compiler/gen_llvm/src/llvm/build.rs +++ b/compiler/gen_llvm/src/llvm/build.rs @@ -427,6 +427,13 @@ pub fn module_from_builtins<'ctx>( } => { include_bytes!("../../../builtins/bitcode/i386-unknown-linux-musl.bc") } + Triple { + architecture: Architecture::X86_64, + operating_system: OperatingSystem::Linux, + .. + } => { + include_bytes!("../../../builtins/bitcode/x86_64-unknown-linux-musl.bc") + } _ => panic!( "The zig builtins are not currently built for this target: {:?}", target From e9d4a4134a957bd9d410efa26f458adfdeee8ee6 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 13 Apr 2022 01:26:10 -0400 Subject: [PATCH 201/846] Give more info when copying obj files fails --- compiler/builtins/build.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/builtins/build.rs b/compiler/builtins/build.rs index 00bd61028c..ff0d260941 100644 --- a/compiler/builtins/build.rs +++ b/compiler/builtins/build.rs @@ -122,7 +122,12 @@ fn generate_object_file( println!("Moving zig object `{}` to: {}", zig_object, dest_obj); // we store this .o file in rust's `target` folder (for wasm we need to leave a copy here too) - fs::copy(src_obj, dest_obj).expect("Failed to copy object file."); + fs::copy(src_obj, dest_obj).unwrap_or_else(|err| { + panic!( + "Failed to copy object file {} to {}: {:?}", + src_obj, dest_obj, err + ); + }); } } From 2c4a83788c100889b037f3756cb665462a1caed4 Mon Sep 17 00:00:00 2001 From: Kevin Gillette Date: Wed, 13 Apr 2022 00:17:38 -0600 Subject: [PATCH 202/846] Rename internal NUM_DIV_INT references to NUM_DIV_FLOOR. This balances with NUM_DIV_CEIL (which is another form of integer division). --- compiler/builtins/src/std.rs | 10 +++++----- compiler/can/src/builtins.rs | 12 ++++++------ compiler/module/src/symbol.rs | 4 ++-- roc-for-elm-programmers.md | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/compiler/builtins/src/std.rs b/compiler/builtins/src/std.rs index dabc694835..cc0fd16ef0 100644 --- a/compiler/builtins/src/std.rs +++ b/compiler/builtins/src/std.rs @@ -316,16 +316,16 @@ pub fn types() -> MutMap { Box::new(SolvedType::Wildcard), ); - // divInt : Int a, Int a -> Int a + // divFloor : Int a, Int a -> Int a add_top_level_function_type!( - Symbol::NUM_DIV_INT, + Symbol::NUM_DIV_FLOOR, vec![int_type(flex(TVAR1)), int_type(flex(TVAR1))], Box::new(int_type(flex(TVAR1))) ); - // divIntChecked : Int a, Int a -> Result (Int a) [ DivByZero ]* + // divFloorChecked : Int a, Int a -> Result (Int a) [ DivByZero ]* add_top_level_function_type!( - Symbol::NUM_DIV_INT_CHECKED, + Symbol::NUM_DIV_FLOOR_CHECKED, vec![int_type(flex(TVAR1)), int_type(flex(TVAR1))], Box::new(result_type(int_type(flex(TVAR1)), div_by_zero.clone())), ); @@ -337,7 +337,7 @@ pub fn types() -> MutMap { Box::new(int_type(flex(TVAR1))) ); - //divCeilChecked : Int a, Int a -> Result (Int a) [ DivByZero ]* + // divCeilChecked : Int a, Int a -> Result (Int a) [ DivByZero ]* add_top_level_function_type!( Symbol::NUM_DIV_CEIL_CHECKED, vec![int_type(flex(TVAR1)), int_type(flex(TVAR1))], diff --git a/compiler/can/src/builtins.rs b/compiler/can/src/builtins.rs index 66f931aa31..d194966b8b 100644 --- a/compiler/can/src/builtins.rs +++ b/compiler/can/src/builtins.rs @@ -196,8 +196,8 @@ pub fn builtin_defs_map(symbol: Symbol, var_store: &mut VarStore) -> Option NUM_TAN => num_tan, NUM_DIV_FLOAT => num_div_float, NUM_DIV_FLOAT_CHECKED => num_div_float_checked, - NUM_DIV_INT => num_div_int, - NUM_DIV_INT_CHECKED => num_div_int_checked, + NUM_DIV_FLOOR => num_div_floor, + NUM_DIV_FLOOR_CHECKED => num_div_floor_checked, NUM_DIV_CEIL => num_div_ceil, NUM_DIV_CEIL_CHECKED => num_div_ceil_checked, NUM_ABS => num_abs, @@ -4369,13 +4369,13 @@ fn num_div_float_checked(symbol: Symbol, var_store: &mut VarStore) -> Def { ) } -/// Num.div : Int a, Int a -> Int a -fn num_div_int(symbol: Symbol, var_store: &mut VarStore) -> Def { +/// Num.divFloor : Int a, Int a -> Int a +fn num_div_floor(symbol: Symbol, var_store: &mut VarStore) -> Def { num_binop(symbol, var_store, LowLevel::NumDivUnchecked) } -/// Num.divChecked : Int a , Int a -> Result (Int a) [ DivByZero ]* -fn num_div_int_checked(symbol: Symbol, var_store: &mut VarStore) -> Def { +/// Num.divFloorChecked : Int a , Int a -> Result (Int a) [ DivByZero ]* +fn num_div_floor_checked(symbol: Symbol, var_store: &mut VarStore) -> Def { let bool_var = var_store.fresh(); let num_var = var_store.fresh(); let unbound_zero_var = var_store.fresh(); diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index 30f6e71a7a..5be160e1d8 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -948,8 +948,8 @@ define_builtins! { 39 NUM_REM_CHECKED: "remChecked" 40 NUM_DIV_FLOAT: "div" 41 NUM_DIV_FLOAT_CHECKED: "divChecked" - 42 NUM_DIV_INT: "divFloor" - 43 NUM_DIV_INT_CHECKED: "divFloorChecked" + 42 NUM_DIV_FLOOR: "divFloor" + 43 NUM_DIV_FLOOR_CHECKED: "divFloorChecked" 44 NUM_MOD_INT: "modInt" 45 NUM_MOD_INT_CHECKED: "modIntChecked" 46 NUM_MOD_FLOAT: "modFloat" diff --git a/roc-for-elm-programmers.md b/roc-for-elm-programmers.md index f932b10ed4..204ad125a9 100644 --- a/roc-for-elm-programmers.md +++ b/roc-for-elm-programmers.md @@ -1130,7 +1130,7 @@ so calculations involving them take longer. Roc does not let floating point calculations result in `Infinity`, `-Infinity`, or `NaN`. Any operation which would result in one of these -(such as `sqrt` or `/`) will return a `Result`. +(such as `sqrt` or `/`) will panic. Similarly to how there are different sizes of floating point numbers, there are also different sizes of integer to choose from: From 7c583b5e79fb7c0d44b26180b798863dd6a0a8e1 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 13 Apr 2022 14:09:22 +0200 Subject: [PATCH 203/846] disable caching just for CI --- compiler/load/src/lib.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/compiler/load/src/lib.rs b/compiler/load/src/lib.rs index 065e263467..6cfd01465e 100644 --- a/compiler/load/src/lib.rs +++ b/compiler/load/src/lib.rs @@ -173,14 +173,16 @@ fn deserialize_help(bytes: &[u8]) -> (Subs, Vec<(Symbol, Variable)>) { fn read_cached_subs() -> MutMap)> { let mut output = MutMap::default(); - output.insert(ModuleId::BOOL, deserialize_help(BOOL)); - output.insert(ModuleId::RESULT, deserialize_help(RESULT)); - output.insert(ModuleId::LIST, deserialize_help(LIST)); - output.insert(ModuleId::STR, deserialize_help(STR)); - output.insert(ModuleId::DICT, deserialize_help(DICT)); - output.insert(ModuleId::SET, deserialize_help(SET)); - output.insert(ModuleId::BOX, deserialize_help(BOX)); - output.insert(ModuleId::NUM, deserialize_help(NUM)); + if false { + output.insert(ModuleId::BOOL, deserialize_help(BOOL)); + output.insert(ModuleId::RESULT, deserialize_help(RESULT)); + output.insert(ModuleId::LIST, deserialize_help(LIST)); + output.insert(ModuleId::STR, deserialize_help(STR)); + output.insert(ModuleId::DICT, deserialize_help(DICT)); + output.insert(ModuleId::SET, deserialize_help(SET)); + output.insert(ModuleId::BOX, deserialize_help(BOX)); + output.insert(ModuleId::NUM, deserialize_help(NUM)); + } output } From 03d4d81f8d4521e08ed1f4d451d33dceb319f5ce Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 13 Apr 2022 08:41:45 -0400 Subject: [PATCH 204/846] Remove unnecessary condition --- reporting/tests/test_reporting.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index a8d1b8a32a..140926a53a 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -523,7 +523,7 @@ mod test_reporting { let buf = list_reports_new(&arena, src, finalize_render); // convenient to copy-paste the generated message - if true && buf != expected_rendering { + if buf != expected_rendering { for line in buf.split('\n') { println!(" {}", line); } From a1c1dc1a9f8759a0a007be821afc5f9c3b5bef07 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 13 Apr 2022 08:49:27 -0400 Subject: [PATCH 205/846] Ask rustc to please always inline --- compiler/solve/src/solve.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index aab17659f2..649c1e28ed 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -1240,6 +1240,8 @@ fn solve( /// If a symbol claims to specialize an ability member, check that its solved type in fact /// does specialize the ability, and record the specialization. #[allow(clippy::too_many_arguments)] +// Aggressive but necessary - there aren't many usages. +#[inline(always)] fn check_ability_specialization( arena: &Bump, subs: &mut Subs, From 5e1ab8225ef2bc46129a14f8b753edb256323417 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 13 Apr 2022 10:11:24 -0400 Subject: [PATCH 206/846] Report when ability member binds >1 variable to parent --- compiler/can/src/def.rs | 20 +++++++++++++++ compiler/problem/src/can.rs | 7 +++++ reporting/src/error/canonicalize.rs | 29 +++++++++++++++++++++ reporting/tests/test_reporting.rs | 40 +++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 514d43d8e6..83fff31fbc 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -491,6 +491,26 @@ pub fn canonicalize_defs<'a>( bad_has_clauses = true; } + if variables_bound_to_ability.len() > 1 { + // There is more than one variable bound to the member signature, so something like + // Eq has eq : a, b -> Bool | a has Eq, b has Eq + // We have no way of telling what type implements a particular instance of Eq in + // this case (a or b?), so disallow it. + let span_has_clauses = + Region::across_all(variables_bound_to_ability.iter().map(|v| &v.first_seen)); + let bound_var_names = variables_bound_to_ability + .iter() + .map(|v| v.name.clone()) + .collect(); + env.problem(Problem::AbilityMemberMultipleBoundVars { + member: member_sym, + ability: loc_ability_name.value, + span_has_clauses, + bound_var_names, + }); + bad_has_clauses = true; + } + if !variables_bound_to_other_abilities.is_empty() { // Disallow variables bound to other abilities, for now. for bad_variable in variables_bound_to_other_abilities.iter() { diff --git a/compiler/problem/src/can.rs b/compiler/problem/src/can.rs index d35d93b307..f8d1684418 100644 --- a/compiler/problem/src/can.rs +++ b/compiler/problem/src/can.rs @@ -119,6 +119,13 @@ pub enum Problem { ability: Symbol, region: Region, }, + AbilityMemberMultipleBoundVars { + member: Symbol, + ability: Symbol, + span_has_clauses: Region, + bound_var_names: Vec, + }, + // TODO(abilities): remove me when ability hierarchies are supported AbilityMemberBindsExternalAbility { member: Symbol, ability: Symbol, diff --git a/reporting/src/error/canonicalize.rs b/reporting/src/error/canonicalize.rs index c804905ae2..d366baf6f2 100644 --- a/reporting/src/error/canonicalize.rs +++ b/reporting/src/error/canonicalize.rs @@ -44,6 +44,7 @@ const ALIAS_USES_ABILITY: &str = "ALIAS USES ABILITY"; const ILLEGAL_HAS_CLAUSE: &str = "ILLEGAL HAS CLAUSE"; const ABILITY_MEMBER_MISSING_HAS_CLAUSE: &str = "ABILITY MEMBER MISSING HAS CLAUSE"; const ABILITY_MEMBER_HAS_EXTRANEOUS_HAS_CLAUSE: &str = "ABILITY MEMBER HAS EXTRANEOUS HAS CLAUSE"; +const ABILITY_MEMBER_BINDS_MULTIPLE_VARIABLES: &str = "ABILITY MEMBER BINDS MULTIPLE VARIABLES"; pub fn can_problem<'b>( alloc: &'b RocDocAllocator<'b>, @@ -684,6 +685,34 @@ pub fn can_problem<'b>( severity = Severity::RuntimeError; } + Problem::AbilityMemberMultipleBoundVars { + member, + ability, + span_has_clauses, + mut bound_var_names, + } => { + doc = alloc.stack(vec![ + alloc.concat(vec![ + alloc.reflow("The definition of the ability member "), + alloc.symbol_unqualified(member), + alloc.reflow(" includes multiple variables bound to the "), + alloc.symbol_unqualified(ability), + alloc.keyword(" ability:"), + ]), + alloc.region(lines.convert_region(span_has_clauses)), + alloc.reflow("Ability members can only bind one type variable to their parent ability. Otherwise, I wouldn't know what type implements an ability by looking at specializations!"), + alloc.concat(vec![ + alloc.hint("Did you mean to only bind "), + alloc.type_variable(bound_var_names.swap_remove(0)), + alloc.reflow(" to "), + alloc.symbol_unqualified(ability), + alloc.reflow("?"), + ]) + ]); + title = ABILITY_MEMBER_BINDS_MULTIPLE_VARIABLES.to_string(); + severity = Severity::RuntimeError; + } + Problem::AbilityMemberBindsExternalAbility { member, ability, diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 140926a53a..6585008ab9 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -9397,6 +9397,46 @@ I need all branches in an `if` to have the same type! ) } + #[test] + fn ability_member_binds_parent_twice() { + new_report_problem_as( + indoc!( + r#" + app "test" provides [ ] to "./platform" + + Eq has eq : a, b -> Bool | a has Eq, b has Eq + "# + ), + indoc!( + r#" + ── ABILITY MEMBER BINDS MULTIPLE VARIABLES ───────────────────────────────────── + + The definition of the ability member `eq` includes multiple variables + bound to the `Eq`` ability:` + + 3│ Eq has eq : a, b -> Bool | a has Eq, b has Eq + ^^^^^^^^^^^^^^^^^^ + + Ability members can only bind one type variable to their parent + ability. Otherwise, I wouldn't know what type implements an ability by + looking at specializations! + + Hint: Did you mean to only bind `a` to `Eq`? + + ── UNUSED DEFINITION ─────────────────────────────────────────────────────────── + + `eq` is not used anywhere in your code. + + 3│ Eq has eq : a, b -> Bool | a has Eq, b has Eq + ^^ + + If you didn't intend on using `eq` then remove it so future readers of + your code don't wonder why it is there. + "# + ), + ) + } + #[test] fn has_clause_outside_of_ability() { new_report_problem_as( From 389c46edcf1540234e66d8dc56944cf0b6c7387d Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 13 Apr 2022 10:12:45 -0400 Subject: [PATCH 207/846] Remove unneeded var --- compiler/can/src/abilities.rs | 12 +++--------- compiler/can/src/def.rs | 2 +- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/compiler/can/src/abilities.rs b/compiler/can/src/abilities.rs index 558f73441d..4132456a21 100644 --- a/compiler/can/src/abilities.rs +++ b/compiler/can/src/abilities.rs @@ -1,14 +1,13 @@ use roc_collections::all::MutMap; use roc_module::symbol::Symbol; use roc_region::all::Region; -use roc_types::{subs::Variable, types::Type}; +use roc_types::types::Type; /// Stores information about an ability member definition, including the parent ability, the /// defining type, and what type variables need to be instantiated with instances of the ability. #[derive(Debug, Clone, PartialEq, Eq)] pub struct AbilityMemberData { pub parent_ability: Symbol, - pub signature_var: Variable, pub signature: Type, pub region: Region, } @@ -49,19 +48,14 @@ pub struct AbilitiesStore { impl AbilitiesStore { /// Records the definition of an ability, including its members. - pub fn register_ability( - &mut self, - ability: Symbol, - members: Vec<(Symbol, Region, Variable, Type)>, - ) { + pub fn register_ability(&mut self, ability: Symbol, members: Vec<(Symbol, Region, Type)>) { let mut members_vec = Vec::with_capacity(members.len()); - for (member, region, signature_var, signature) in members.into_iter() { + for (member, region, signature) in members.into_iter() { members_vec.push(member); let old_member = self.ability_members.insert( member, AbilityMemberData { parent_ability: ability, - signature_var, signature, region, }, diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 83fff31fbc..2a8a6d1880 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -533,7 +533,7 @@ pub fn canonicalize_defs<'a>( .introduced_variables .union(&member_annot.introduced_variables); - can_members.push((member_sym, name_region, var_store.fresh(), member_annot.typ)); + can_members.push((member_sym, name_region, member_annot.typ)); } // Store what symbols a type must define implementations for to have this ability. From 3746161c42576bc5b172e347ed330c62831cbe7e Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 13 Apr 2022 10:39:32 -0400 Subject: [PATCH 208/846] Fix init returning the wrong model --- examples/breakout/breakout.roc | 3 +-- examples/breakout/platform/src/gui.rs | 2 -- examples/breakout/platform/src/roc.rs | 37 ++++++++++++--------------- 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index 191c652934..682c5b1c4d 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -58,5 +58,4 @@ render = \state -> Rect { left, top, width, height, color } - # List.append rects paddle - [ Rect { left: 1, top: 2, width: state.width, height: state.height, color: { r: 0.8, g: 0.8, b: 0.8, a: 1.0 } } ] + List.append rects paddle diff --git a/examples/breakout/platform/src/gui.rs b/examples/breakout/platform/src/gui.rs index f94e760a1b..4f461f58e6 100644 --- a/examples/breakout/platform/src/gui.rs +++ b/examples/breakout/platform/src/gui.rs @@ -39,8 +39,6 @@ const TIME_BETWEEN_RENDERS: Duration = Duration::new(0, 1000 / 60); pub fn run_event_loop(title: &str, window_bounds: Bounds) -> Result<(), Box> { let (model, mut elems) = roc::init_and_render(window_bounds); - dbg!(&elems); - // Open window and create a surface let mut event_loop = winit::event_loop::EventLoop::new(); diff --git a/examples/breakout/platform/src/roc.rs b/examples/breakout/platform/src/roc.rs index 746552f3f1..f6b61fe03f 100644 --- a/examples/breakout/platform/src/roc.rs +++ b/examples/breakout/platform/src/roc.rs @@ -26,7 +26,7 @@ extern "C" { #[link_name = "roc__programForHost_1_Init_size"] fn init_size() -> i64; - #[link_name = "roc__mainForHost_1_Init_result_size"] + #[link_name = "roc__programForHost_1_Init_result_size"] fn init_result_size() -> i64; // update @@ -42,7 +42,7 @@ extern "C" { #[link_name = "roc__programForHost_1_Update_size"] fn update_size() -> i64; - #[link_name = "roc__mainForHost_1_Update_result_size"] + #[link_name = "roc__programForHost_1_Update_result_size"] fn update_result_size() -> i64; // render @@ -317,43 +317,40 @@ type Model = c_void; /// Call the app's init function pub fn init_and_render(bounds: Bounds) -> (*const Model, RocList) { let closure_data_buf; - let layout; + let closure_layout; // Call init to get the initial model let model = unsafe { - let mut ret_val = MaybeUninit::uninit(); - - layout = Layout::array::(init_size() as usize).unwrap(); + let ret_val_layout = Layout::array::(init_result_size() as usize).unwrap(); + let mut ret_val: MaybeUninit = MaybeUninit::uninit(); // TODO allocate on the stack if it's under a certain size - closure_data_buf = std::alloc::alloc(layout); + let ret_val_buf = std::alloc::alloc(ret_val_layout) as *mut Model; - dbg!(&bounds); + closure_layout = Layout::array::(init_size() as usize).unwrap(); - call_init(&bounds, closure_data_buf, ret_val.as_mut_ptr()); + // TODO allocate on the stack if it's under a certain size + closure_data_buf = std::alloc::alloc(closure_layout); - ret_val.assume_init() + call_init(&bounds, closure_data_buf, ret_val_buf); + + ret_val_buf }; - unsafe { - let model_returned_by_init: Bounds = *std::mem::transmute::<&c_void, *const Bounds>(&model); - dbg!(model_returned_by_init); - } - // Call render passing the model to get the initial Elems let elems = unsafe { - let mut ret_val = MaybeUninit::uninit(); + let mut ret_val: MaybeUninit> = MaybeUninit::uninit(); // Reuse the buffer from the previous closure if possible let closure_data_buf = - std::alloc::realloc(closure_data_buf, layout, roc_render_size() as usize); + std::alloc::realloc(closure_data_buf, closure_layout, roc_render_size() as usize); - call_render(&model, closure_data_buf, ret_val.as_mut_ptr()); + call_render(model, closure_data_buf, ret_val.as_mut_ptr()); - std::alloc::dealloc(closure_data_buf, layout); + std::alloc::dealloc(closure_data_buf, closure_layout); ret_val.assume_init() }; - (&model, elems) + (model, elems) } From 25b3aa7ca7aad9e4a5c9979630e9ff4132b8bfce Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 13 Apr 2022 10:42:46 -0400 Subject: [PATCH 209/846] Typed body specializations solve --- compiler/can/src/def.rs | 4 +++- compiler/solve/src/solve.rs | 13 +++++++++++++ compiler/solve/tests/solve_expr.rs | 20 ++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 2a8a6d1880..f5417708fa 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1306,7 +1306,9 @@ fn canonicalize_pending_value_def<'a>( // which also implies it's not a self tail call! // // Only defs of the form (foo = ...) can be closure declarations or self tail calls. - if let Pattern::Identifier(symbol) = loc_can_pattern.value { + if let Pattern::Identifier(symbol) + | Pattern::AbilityMemberSpecialization { ident: symbol, .. } = loc_can_pattern.value + { if let Closure(ClosureData { function_type, closure_type, diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index 649c1e28ed..e5aed79134 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -709,6 +709,19 @@ fn solve( let mut new_env = env.clone(); for (symbol, loc_var) in local_def_vars.iter() { + check_ability_specialization( + arena, + subs, + &new_env, + pools, + rank, + abilities_store, + problems, + deferred_must_implement_abilities, + *symbol, + *loc_var, + ); + new_env.insert_symbol_var_if_vacant(*symbol, loc_var.value); } diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index fd2f854633..b926ebf467 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -5840,4 +5840,24 @@ mod solve_expr { [("hash", "Id"), ("hash32", "Id"), ("eq", "Id"), ("le", "Id")], ) } + + #[test] + fn ability_checked_specialization_with_typed_body() { + check_inferred_abilities( + indoc!( + r#" + app "test" provides [ hash ] to "./platform" + + Hash has + hash : a -> U64 | a has Hash + + Id := U64 + + hash : Id -> U64 + hash = \$Id n -> n + "# + ), + [("hash", "Id")], + ) + } } From d110fbde6c6b775ec9e7f41455c28e51da1810ef Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 13 Apr 2022 10:44:34 -0400 Subject: [PATCH 210/846] Annotation specializes ability --- compiler/can/src/def.rs | 4 +++- compiler/solve/tests/solve_expr.rs | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index f5417708fa..54c64f8c92 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1218,7 +1218,9 @@ fn canonicalize_pending_value_def<'a>( } }; - if let Pattern::Identifier(symbol) = loc_can_pattern.value { + if let Pattern::Identifier(symbol) + | Pattern::AbilityMemberSpecialization { ident: symbol, .. } = loc_can_pattern.value + { let def = single_can_def( loc_can_pattern, loc_can_expr, diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index b926ebf467..c781854cfa 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -5860,4 +5860,23 @@ mod solve_expr { [("hash", "Id")], ) } + + #[test] + fn ability_checked_specialization_with_annotation_only() { + check_inferred_abilities( + indoc!( + r#" + app "test" provides [ hash ] to "./platform" + + Hash has + hash : a -> U64 | a has Hash + + Id := U64 + + hash : Id -> U64 + "# + ), + [("hash", "Id")], + ) + } } From de9d97c5d1759fb979488d13d7e99465e59c663e Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 13 Apr 2022 10:46:41 -0400 Subject: [PATCH 211/846] Ability specialization checks against annotation --- reporting/tests/test_reporting.rs | 53 +++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 6585008ab9..2152850a0c 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -9659,4 +9659,57 @@ I need all branches in an `if` to have the same type! ), ) } + + #[test] + fn ability_specialization_checked_against_annotation() { + new_report_problem_as( + indoc!( + r#" + app "test" provides [ hash ] to "./platform" + + Hash has + hash : a -> U64 | a has Hash + + Id := U64 + + hash : Id -> U32 + hash = \$Id n -> n + "# + ), + indoc!( + r#" + ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + + Something is off with the body of this definition: + + 8│ hash : Id -> U32 + 9│ hash = \$Id n -> n + ^ + + This `n` value is a: + + U64 + + But the type annotation says it should be: + + U32 + + ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + + Something is off with this specialization of `hash`: + + 9│ hash = \$Id n -> n + ^^^^ + + This value is a declared specialization of type: + + Id -> U32 + + But the type annotation on `hash` says it must match: + + Id -> U64 + "# + ), + ) + } } From ee7c5ad2e10489257eeadd896117b5a4bfc10746 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 13 Apr 2022 10:48:11 -0400 Subject: [PATCH 212/846] Wire up update in breakout --- examples/breakout/breakout.roc | 4 +-- examples/breakout/platform/src/gui.rs | 14 +++++++-- examples/breakout/platform/src/roc.rs | 43 +++++++++++++++++++++++++-- 3 files changed, 54 insertions(+), 7 deletions(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index 682c5b1c4d..154144cbdb 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -12,8 +12,8 @@ init = \_ -> { width: 1900, height: 1000 } update = \state, event -> when event is Resize size -> size - KeyUp keyCode -> { width: 1900, height: 1000 } - KeyDown keyCode -> { width: 1900, height: 1000 } + KeyUp keyCode -> { width: 200, height: 200 } + KeyDown keyCode -> { width: 200, height: 200 } render = \state -> numRows = 4 diff --git a/examples/breakout/platform/src/gui.rs b/examples/breakout/platform/src/gui.rs index 4f461f58e6..25c44af7c7 100644 --- a/examples/breakout/platform/src/gui.rs +++ b/examples/breakout/platform/src/gui.rs @@ -37,7 +37,7 @@ use winit::{ const TIME_BETWEEN_RENDERS: Duration = Duration::new(0, 1000 / 60); pub fn run_event_loop(title: &str, window_bounds: Bounds) -> Result<(), Box> { - let (model, mut elems) = roc::init_and_render(window_bounds); + let (mut model, mut elems) = roc::init_and_render(window_bounds); // Open window and create a surface let mut event_loop = winit::event_loop::EventLoop::new(); @@ -150,11 +150,15 @@ pub fn run_event_loop(title: &str, window_bounds: Bounds) -> Result<(), Box Result<(), Box RocEvent::key_up(keycode), }; - elems = roc::app_render(roc_event); + // TODO use (model, elems) = ... once we've upgraded rust versions + let pair = roc::update_and_render(model, roc_event); + + model = pair.0; + elems = pair.1; window.request_redraw(); } diff --git a/examples/breakout/platform/src/roc.rs b/examples/breakout/platform/src/roc.rs index f6b61fe03f..3699a23e5d 100644 --- a/examples/breakout/platform/src/roc.rs +++ b/examples/breakout/platform/src/roc.rs @@ -314,7 +314,7 @@ pub struct Bounds { type Model = c_void; -/// Call the app's init function +/// Call the app's init function, then render and return that result pub fn init_and_render(bounds: Bounds) -> (*const Model, RocList) { let closure_data_buf; let closure_layout; @@ -322,7 +322,6 @@ pub fn init_and_render(bounds: Bounds) -> (*const Model, RocList) { // Call init to get the initial model let model = unsafe { let ret_val_layout = Layout::array::(init_result_size() as usize).unwrap(); - let mut ret_val: MaybeUninit = MaybeUninit::uninit(); // TODO allocate on the stack if it's under a certain size let ret_val_buf = std::alloc::alloc(ret_val_layout) as *mut Model; @@ -354,3 +353,43 @@ pub fn init_and_render(bounds: Bounds) -> (*const Model, RocList) { (model, elems) } + +/// Call the app's update function, then render and return that result +pub fn update_and_render(model: *const Model, event: RocEvent) -> (*const Model, RocList) { + let closure_data_buf; + let closure_layout; + + // Call update to get the new model + let model = unsafe { + let ret_val_layout = Layout::array::(update_result_size() as usize).unwrap(); + + // TODO allocate on the stack if it's under a certain size + let ret_val_buf = std::alloc::alloc(ret_val_layout) as *mut Model; + + closure_layout = Layout::array::(update_size() as usize).unwrap(); + + // TODO allocate on the stack if it's under a certain size + closure_data_buf = std::alloc::alloc(closure_layout); + + call_update(model, &event, closure_data_buf, ret_val_buf); + + ret_val_buf + }; + + // Call render passing the model to get the initial Elems + let elems = unsafe { + let mut ret_val: MaybeUninit> = MaybeUninit::uninit(); + + // Reuse the buffer from the previous closure if possible + let closure_data_buf = + std::alloc::realloc(closure_data_buf, closure_layout, roc_render_size() as usize); + + call_render(model, closure_data_buf, ret_val.as_mut_ptr()); + + std::alloc::dealloc(closure_data_buf, closure_layout); + + ret_val.assume_init() + }; + + (model, elems) +} From dfec98c0683b093c38d286bbf9a71394bcee3e3b Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 13 Apr 2022 10:53:32 -0400 Subject: [PATCH 213/846] Moving the paddle in one direction --- examples/breakout/breakout.roc | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index 154144cbdb..e48ec96e0b 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -3,19 +3,22 @@ app "breakout" imports []# [ pf.Action.{ Action }, pf.Elem.{ button, text, row, col } ] provides [ program ] { Model } to pf -Model : { height : F32, width : F32 } +Model : { height : F32, width : F32, pos : F32 } program = { init, update, render } -init = \_ -> { width: 1900, height: 1000 } +#init : { height : F32, width : F32 } -> Model +init = \_ -> { width: 1900, height: 1000, pos: 100 } -update = \state, event -> +#update : Model, Event -> Model +update = \model, event -> when event is - Resize size -> size - KeyUp keyCode -> { width: 200, height: 200 } - KeyDown keyCode -> { width: 200, height: 200 } + Resize size -> { model & width: size.width, height: size.height } + KeyUp keyCode -> model + KeyDown keyCode -> { model & pos: model.pos + 50 } -render = \state -> +#render : Model -> List Elem +render = \model -> numRows = 4 numCols = 8 numBlocks = numRows * numCols @@ -39,7 +42,7 @@ render = \state -> { row, col, color } - blockWidth = state.width / numCols |> Result.withDefault 0 + blockWidth = model.width / numCols |> Result.withDefault 0 blockHeight = 80 rects = @@ -51,10 +54,10 @@ render = \state -> paddle = color = { r: 0.8, g: 0.8, b: 0.8, a: 1.0 } - width = state.width * 0.25 + width = model.width * 0.25 height = blockHeight - left = (state.width * 0.5) - (width * 0.5) - top = state.height - (height * 2) + left = (model.width * 0.5) - (width * 0.5) + model.pos + top = model.height - (height * 2) Rect { left, top, width, height, color } From 0792ccbbe868c000aa834bf194f8e28ec5013ddd Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 13 Apr 2022 11:49:33 -0400 Subject: [PATCH 214/846] Calling ability with non-specialized type is an error --- compiler/can/src/abilities.rs | 20 ++++++++++++--- compiler/can/src/annotation.rs | 16 ++++++++++++ compiler/can/src/def.rs | 11 +++++++- compiler/constrain/src/module.rs | 10 ++++++-- compiler/solve/tests/solve_expr.rs | 21 +++++++++++++++ reporting/tests/test_reporting.rs | 41 ++++++++++++++++++++++++++++++ 6 files changed, 113 insertions(+), 6 deletions(-) diff --git a/compiler/can/src/abilities.rs b/compiler/can/src/abilities.rs index 4132456a21..2879de8e0c 100644 --- a/compiler/can/src/abilities.rs +++ b/compiler/can/src/abilities.rs @@ -1,14 +1,23 @@ use roc_collections::all::MutMap; use roc_module::symbol::Symbol; use roc_region::all::Region; -use roc_types::types::Type; +use roc_types::{subs::Variable, types::Type}; + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct MemberVariables { + pub able_vars: Vec, + pub rigid_vars: Vec, + pub flex_vars: Vec, +} /// Stores information about an ability member definition, including the parent ability, the /// defining type, and what type variables need to be instantiated with instances of the ability. +// TODO: SoA and put me in an arena #[derive(Debug, Clone, PartialEq, Eq)] pub struct AbilityMemberData { pub parent_ability: Symbol, pub signature: Type, + pub variables: MemberVariables, pub region: Region, } @@ -48,9 +57,13 @@ pub struct AbilitiesStore { impl AbilitiesStore { /// Records the definition of an ability, including its members. - pub fn register_ability(&mut self, ability: Symbol, members: Vec<(Symbol, Region, Type)>) { + pub fn register_ability( + &mut self, + ability: Symbol, + members: Vec<(Symbol, Region, Type, MemberVariables)>, + ) { let mut members_vec = Vec::with_capacity(members.len()); - for (member, region, signature) in members.into_iter() { + for (member, region, signature, variables) in members.into_iter() { members_vec.push(member); let old_member = self.ability_members.insert( member, @@ -58,6 +71,7 @@ impl AbilitiesStore { parent_ability: ability, signature, region, + variables, }, ); debug_assert!(old_member.is_none(), "Replacing existing member definition"); diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index c5d1ea3f23..087cc9d9b8 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -168,6 +168,22 @@ impl IntroducedVariables { .find(|av| &av.name == name) .map(NamedOrAbleVariable::Able) } + + pub fn collect_able(&self) -> Vec { + self.able.iter().map(|av| av.variable).collect() + } + + pub fn collect_rigid(&self) -> Vec { + (self.named.iter().map(|nv| nv.variable)) + .chain(self.wildcards.iter().map(|wc| wc.value)) + // For our purposes, lambda set vars are treated like rigids + .chain(self.lambda_sets.iter().copied()) + .collect() + } + + pub fn collect_flex(&self) -> Vec { + self.inferred.iter().map(|iv| iv.value).collect() + } } fn malformed(env: &mut Env, region: Region, name: &str) { diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 54c64f8c92..571568592a 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1,3 +1,4 @@ +use crate::abilities::MemberVariables; use crate::annotation::canonicalize_annotation; use crate::annotation::canonicalize_annotation_with_possible_clauses; use crate::annotation::IntroducedVariables; @@ -533,7 +534,15 @@ pub fn canonicalize_defs<'a>( .introduced_variables .union(&member_annot.introduced_variables); - can_members.push((member_sym, name_region, member_annot.typ)); + let iv = member_annot.introduced_variables; + + let variables = MemberVariables { + able_vars: iv.collect_able(), + rigid_vars: iv.collect_rigid(), + flex_vars: iv.collect_flex(), + }; + + can_members.push((member_sym, name_region, member_annot.typ, variables)); } // Store what symbols a type must define implementations for to have this ability. diff --git a/compiler/constrain/src/module.rs b/compiler/constrain/src/module.rs index 566b15cd88..e47fe1130a 100644 --- a/compiler/constrain/src/module.rs +++ b/compiler/constrain/src/module.rs @@ -108,9 +108,15 @@ pub fn constrain_module( let mut constraint = crate::expr::constrain_decls(constraints, home, declarations); for (member_name, member_data) in abilities_store.root_ability_members().iter() { + let vars = &member_data.variables; + let rigids = (vars.rigid_vars.iter()) + // For our purposes, in the let constraint, able vars are treated like rigids. + .chain(vars.able_vars.iter()) + .copied(); + let flex = vars.flex_vars.iter().copied(); constraint = constraints.let_constraint( - [], - [], + rigids, + flex, [(*member_name, Loc::at_zero(member_data.signature.clone()))], Constraint::True, constraint, diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index c781854cfa..36a1220d9e 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -5879,4 +5879,25 @@ mod solve_expr { [("hash", "Id")], ) } + + #[test] + fn ability_specialization_called() { + infer_eq_without_problem( + indoc!( + r#" + app "test" provides [ zero ] to "./platform" + + Hash has + hash : a -> U64 | a has Hash + + Id := U64 + + hash = \$Id n -> n + + zero = hash ($Id 0) + "# + ), + "U64", + ) + } } diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 2152850a0c..ee04904c1d 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -9712,4 +9712,45 @@ I need all branches in an `if` to have the same type! ), ) } + + #[test] + fn ability_specialization_called_with_non_specializing() { + new_report_problem_as( + indoc!( + r#" + app "test" provides [ noGoodVeryBadTerrible ] to "./platform" + + Hash has + hash : a -> U64 | a has Hash + + Id := U64 + + hash = \$Id n -> n + + noGoodVeryBadTerrible = + { + notYet: hash (A 1), + } + "# + ), + indoc!( + r#" + ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + + The 1st argument to `hash` is not what I expect: + + 12│ notYet: hash (A 1), + ^^^ + + This `A` global tag application has the type: + + [ A (Num a) ]b + + But `hash` needs the 1st argument to be: + + a | a has Hash + "# + ), + ) + } } From 8eec930260aecd019a40216048222953ba6ebc30 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 13 Apr 2022 15:25:19 -0400 Subject: [PATCH 215/846] More and smarter checking and error reporting for abilities --- compiler/can/src/expected.rs | 9 ++ compiler/solve/src/ability.rs | 156 ++++++++++++++++++++++++ compiler/solve/src/lib.rs | 1 + compiler/solve/src/solve.rs | 109 ++++++++++------- reporting/src/error/type.rs | 196 ++++++++++++++++++++++-------- reporting/tests/test_reporting.rs | 29 ++++- 6 files changed, 409 insertions(+), 91 deletions(-) create mode 100644 compiler/solve/src/ability.rs diff --git a/compiler/can/src/expected.rs b/compiler/can/src/expected.rs index 50af7f0d20..aad8bd42b4 100644 --- a/compiler/can/src/expected.rs +++ b/compiler/can/src/expected.rs @@ -44,6 +44,15 @@ impl PExpected { PExpected::ForReason(reason, _val, region) => PExpected::ForReason(reason, new, region), } } + + pub fn replace_ref(&self, new: U) -> PExpected { + match self { + PExpected::NoExpectation(_val) => PExpected::NoExpectation(new), + PExpected::ForReason(reason, _val, region) => { + PExpected::ForReason(reason.clone(), new, *region) + } + } + } } impl Expected { diff --git a/compiler/solve/src/ability.rs b/compiler/solve/src/ability.rs new file mode 100644 index 0000000000..3aaf27d32d --- /dev/null +++ b/compiler/solve/src/ability.rs @@ -0,0 +1,156 @@ +use roc_can::abilities::AbilitiesStore; +use roc_region::all::{Loc, Region}; +use roc_types::subs::Subs; +use roc_types::subs::Variable; +use roc_types::types::{Category, PatternCategory}; +use roc_unify::unify::MustImplementAbility; + +use crate::solve::{IncompleteAbilityImplementation, TypeError}; + +#[derive(Debug, Clone)] +pub enum AbilityImplError { + /// Promote this to an error that the type does not fully implement an ability + IncompleteAbility, + /// Promote this error to a `TypeError::BadExpr` from elsewhere + BadExpr(Region, Category, Variable), + /// Promote this error to a `TypeError::BadPattern` from elsewhere + BadPattern(Region, PatternCategory, Variable), +} + +#[derive(Default)] +pub struct DeferredMustImplementAbility(Vec<(Vec, AbilityImplError)>); + +impl DeferredMustImplementAbility { + pub fn add(&mut self, must_implement: Vec, on_error: AbilityImplError) { + self.0.push((must_implement, on_error)); + } + + pub fn check(self, subs: &mut Subs, abilities_store: &AbilitiesStore) -> Vec { + // Two passes here. First up let's build up records of what types fully implement + // abilities, and what specializations are available/missing for the ones that don't. + // Use a vec since these lists should usually be pretty small. + let mut good = vec![]; + let mut bad = vec![]; + + macro_rules! is_good { + ($e:expr) => { + good.contains($e) + }; + } + macro_rules! get_bad { + ($e:expr) => { + bad.iter() + .find(|(cand, _)| $e == *cand) + .map(|(_, incomplete)| incomplete) + }; + } + + for (mias, _) in self.0.iter() { + for &mia @ MustImplementAbility { typ, ability } in mias { + if is_good!(&mia) || get_bad!(mia).is_some() { + continue; + } + + let members_of_ability = abilities_store.members_of_ability(ability).unwrap(); + let mut specialized_members = Vec::with_capacity(members_of_ability.len()); + let mut missing_members = Vec::with_capacity(members_of_ability.len()); + for &member in members_of_ability { + match abilities_store.get_specialization(member, typ) { + None => { + let root_data = abilities_store.member_def(member).unwrap(); + missing_members.push(Loc::at(root_data.region, member)); + } + Some(specialization) => { + specialized_members.push(Loc::at(specialization.region, member)); + } + } + } + + if missing_members.is_empty() { + good.push(mia); + } else { + bad.push(( + mia, + IncompleteAbilityImplementation { + typ, + ability, + specialized_members, + missing_members, + }, + )); + } + } + } + + // Now figure out what errors we need to report. + let mut problems = vec![]; + + // Keep track of which types that have an incomplete ability were reported as part of + // another type error (from an expression or pattern). If we reported an error for a type + // that doesn't implement an ability in that context, we don't want to repeat the error + // message. + let mut reported_in_context = vec![]; + let mut incomplete_not_in_context = vec![]; + + for (must_implement, on_error) in self.0.into_iter() { + use AbilityImplError::*; + match on_error { + IncompleteAbility => { + incomplete_not_in_context.extend(must_implement); + } + BadExpr(region, category, var) => { + let incomplete_types = must_implement + .iter() + .filter_map(|e| get_bad!(*e)) + .cloned() + .collect::>(); + if !incomplete_types.is_empty() { + // Demote the bad variable that exposed this problem to an error, both so + // that we have an ErrorType to report and so that codegen knows to deal + // with the error later. + let (error_type, _moar_ghosts_n_stuff) = subs.var_to_error_type(var); + problems.push(TypeError::BadExprMissingAbility( + region, + category, + error_type, + incomplete_types, + )); + reported_in_context.extend(must_implement); + } + } + BadPattern(region, category, var) => { + let incomplete_types = must_implement + .iter() + .filter_map(|e| get_bad!(*e)) + .cloned() + .collect::>(); + if !incomplete_types.is_empty() { + // Demote the bad variable that exposed this problem to an error, both so + // that we have an ErrorType to report and so that codegen knows to deal + // with the error later. + let (error_type, _moar_ghosts_n_stuff) = subs.var_to_error_type(var); + problems.push(TypeError::BadPatternMissingAbility( + region, + category, + error_type, + incomplete_types, + )); + reported_in_context.extend(must_implement); + } + } + }; + } + + for mia in incomplete_not_in_context.into_iter() { + if let Some(must_implement) = get_bad!(mia) { + if !reported_in_context.contains(&mia) { + problems.push(TypeError::IncompleteAbilityImplementation( + must_implement.clone(), + )); + } + } + } + + problems + } +} diff --git a/compiler/solve/src/lib.rs b/compiler/solve/src/lib.rs index 3706c9d5dd..06f9e2fd5c 100644 --- a/compiler/solve/src/lib.rs +++ b/compiler/solve/src/lib.rs @@ -2,5 +2,6 @@ // See github.com/rtfeldman/roc/issues/800 for discussion of the large_enum_variant check. #![allow(clippy::large_enum_variant)] +mod ability; pub mod module; pub mod solve; diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index e5aed79134..c0d10cd841 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -1,3 +1,4 @@ +use crate::ability::{AbilityImplError, DeferredMustImplementAbility}; use bumpalo::Bump; use roc_can::abilities::{AbilitiesStore, MemberSpecialization}; use roc_can::constraint::Constraint::{self, *}; @@ -17,7 +18,7 @@ use roc_types::types::{ gather_fields_unsorted_iter, AliasCommon, AliasKind, Category, ErrorType, PatternCategory, Reason, TypeExtension, }; -use roc_unify::unify::{unify, Mode, MustImplementAbility, Unified::*}; +use roc_unify::unify::{unify, Mode, Unified::*}; // Type checking system adapted from Elm by Evan Czaplicki, BSD-3-Clause Licensed // https://github.com/elm/compiler @@ -69,6 +70,15 @@ use roc_unify::unify::{unify, Mode, MustImplementAbility, Unified::*}; // Ranks are used to limit the number of type variables considered for generalization. Only those inside // of the let (so those used in inferring the type of `\x -> x`) are considered. +#[derive(PartialEq, Debug, Clone)] +pub struct IncompleteAbilityImplementation { + // TODO(abilities): have general types here, not just opaques + pub typ: Symbol, + pub ability: Symbol, + pub specialized_members: Vec>, + pub missing_members: Vec>, +} + #[derive(PartialEq, Debug, Clone)] pub enum TypeError { BadExpr(Region, Category, ErrorType, Expected), @@ -76,13 +86,19 @@ pub enum TypeError { CircularType(Region, Symbol, ErrorType), BadType(roc_types::types::Problem), UnexposedLookup(Symbol), - IncompleteAbilityImplementation { - // TODO(abilities): have general types here, not just opaques - typ: Symbol, - ability: Symbol, - specialized_members: Vec>, - missing_members: Vec>, - }, + IncompleteAbilityImplementation(IncompleteAbilityImplementation), + BadExprMissingAbility( + Region, + Category, + ErrorType, + Vec, + ), + BadPatternMissingAbility( + Region, + PatternCategory, + ErrorType, + Vec, + ), } use roc_types::types::Alias; @@ -558,7 +574,7 @@ pub fn run_in_place( let arena = Bump::new(); - let mut deferred_must_implement_abilities = Vec::new(); + let mut deferred_must_implement_abilities = DeferredMustImplementAbility::default(); let state = solve( &arena, @@ -577,32 +593,7 @@ pub fn run_in_place( // Now that the module has been solved, we can run through and check all // types claimed to implement abilities. - deferred_must_implement_abilities.dedup(); - for MustImplementAbility { typ, ability } in deferred_must_implement_abilities.into_iter() { - let members_of_ability = abilities_store.members_of_ability(ability).unwrap(); - let mut specialized_members = Vec::with_capacity(members_of_ability.len()); - let mut missing_members = Vec::with_capacity(members_of_ability.len()); - for &member in members_of_ability { - match abilities_store.get_specialization(member, typ) { - None => { - let root_data = abilities_store.member_def(member).unwrap(); - missing_members.push(Loc::at(root_data.region, member)); - } - Some(specialization) => { - specialized_members.push(Loc::at(specialization.region, member)); - } - } - } - - if !missing_members.is_empty() { - problems.push(TypeError::IncompleteAbilityImplementation { - typ, - ability, - specialized_members, - missing_members, - }); - } - } + problems.extend(deferred_must_implement_abilities.check(subs, &abilities_store)); state.env } @@ -656,7 +647,7 @@ fn solve( subs: &mut Subs, constraint: &Constraint, abilities_store: &mut AbilitiesStore, - deferred_must_implement_abilities: &mut Vec, + deferred_must_implement_abilities: &mut DeferredMustImplementAbility, ) -> State { let initial = Work::Constraint { env, @@ -877,9 +868,15 @@ fn solve( match unify(subs, actual, expected, Mode::EQ) { Success { vars, - must_implement_ability: _, + must_implement_ability, } => { introduce(subs, rank, pools, &vars); + if !must_implement_ability.is_empty() { + deferred_must_implement_abilities.add( + must_implement_ability, + AbilityImplError::BadExpr(*region, category.clone(), actual), + ); + } state } @@ -922,6 +919,7 @@ fn solve( match unify(subs, actual, target, Mode::EQ) { Success { vars, + // ERROR NOT REPORTED must_implement_ability: _, } => { introduce(subs, rank, pools, &vars); @@ -977,9 +975,19 @@ fn solve( match unify(subs, actual, expected, Mode::EQ) { Success { vars, - must_implement_ability: _, + must_implement_ability, } => { introduce(subs, rank, pools, &vars); + if !must_implement_ability.is_empty() { + deferred_must_implement_abilities.add( + must_implement_ability, + AbilityImplError::BadExpr( + *region, + Category::Lookup(*symbol), + actual, + ), + ); + } state } @@ -1044,9 +1052,15 @@ fn solve( match unify(subs, actual, expected, mode) { Success { vars, - must_implement_ability: _, + must_implement_ability, } => { introduce(subs, rank, pools, &vars); + if !must_implement_ability.is_empty() { + deferred_must_implement_abilities.add( + must_implement_ability, + AbilityImplError::BadPattern(*region, category.clone(), actual), + ); + } state } @@ -1216,9 +1230,19 @@ fn solve( match unify(subs, actual, includes, Mode::PRESENT) { Success { vars, - must_implement_ability: _, + must_implement_ability, } => { introduce(subs, rank, pools, &vars); + if !must_implement_ability.is_empty() { + deferred_must_implement_abilities.add( + must_implement_ability, + AbilityImplError::BadPattern( + *region, + pattern_category.clone(), + actual, + ), + ); + } state } @@ -1263,7 +1287,7 @@ fn check_ability_specialization( rank: Rank, abilities_store: &mut AbilitiesStore, problems: &mut Vec, - deferred_must_implement_abilities: &mut Vec, + deferred_must_implement_abilities: &mut DeferredMustImplementAbility, symbol: Symbol, symbol_loc_var: Loc, ) { @@ -1349,7 +1373,8 @@ fn check_ability_specialization( // Store the checks for what abilities must be implemented to be checked after the // whole module is complete. - deferred_must_implement_abilities.extend(must_implement_ability); + deferred_must_implement_abilities + .add(must_implement_ability, AbilityImplError::IncompleteAbility); } Failure(vars, actual_type, expected_type, unimplemented_abilities) => { subs.commit_snapshot(snapshot); diff --git a/reporting/src/error/type.rs b/reporting/src/error/type.rs index b1d6334d77..1735b01607 100644 --- a/reporting/src/error/type.rs +++ b/reporting/src/error/type.rs @@ -4,7 +4,7 @@ use roc_module::called_via::{BinOp, CalledVia}; use roc_module::ident::{Ident, IdentStr, Lowercase, TagName}; use roc_module::symbol::Symbol; use roc_region::all::{LineInfo, Loc, Region}; -use roc_solve::solve; +use roc_solve::solve::{self, IncompleteAbilityImplementation}; use roc_types::pretty_print::{Parens, WILDCARD}; use roc_types::types::{ AliasKind, Category, ErrorType, PatternCategory, Reason, RecordField, TypeExt, @@ -118,56 +118,136 @@ pub fn type_problem<'b>( other => panic!("unhandled bad type: {:?}", other), } } - IncompleteAbilityImplementation { - typ, - ability, - specialized_members, - missing_members, - } => { + IncompleteAbilityImplementation(incomplete) => { let title = "INCOMPLETE ABILITY IMPLEMENTATION".to_string(); - let mut stack = vec![alloc.concat(vec![ - alloc.reflow("The type "), - alloc.symbol_unqualified(typ), - alloc.reflow(" does not fully implement the ability "), - alloc.symbol_unqualified(ability), - alloc.reflow(". The following specializations are missing:"), - ])]; - - for member in missing_members.into_iter() { - stack.push(alloc.concat(vec![ - alloc.reflow("A specialization for "), - alloc.symbol_unqualified(member.value), - alloc.reflow(", which is defined here:"), - ])); - stack.push(alloc.region(lines.convert_region(member.region))); - } - - debug_assert!(!specialized_members.is_empty()); - - stack.push(alloc.concat(vec![ - alloc.note(""), - alloc.symbol_unqualified(typ), - alloc.reflow(" specializes the following members of "), - alloc.symbol_unqualified(ability), - alloc.reflow(":"), - ])); - - for spec in specialized_members { - stack.push(alloc.concat(vec![ - alloc.symbol_unqualified(spec.value), - alloc.reflow(", specialized here:"), - ])); - stack.push(alloc.region(lines.convert_region(spec.region))); - } - - let doc = alloc.stack(stack); + let doc = report_incomplete_ability(alloc, lines, incomplete); report(title, doc, filename) } + BadExprMissingAbility(region, category, found, incomplete) => { + let note = alloc.stack(vec![ + alloc.reflow("The ways this expression is used requires that the following types implement the following abilities, which they do not:"), + alloc.type_block(alloc.stack(incomplete.iter().map(|incomplete| { + symbol_does_not_implement(alloc, incomplete.typ, incomplete.ability) + }))), + ]); + let snippet = alloc.region(lines.convert_region(region)); + let mut stack = vec![ + alloc.text( + "This expression has a type does not implement the abilities it's expected to:", + ), + snippet, + lone_type( + alloc, + found.clone(), + found, + ExpectationContext::Arbitrary, + add_category(alloc, alloc.text("Right now it's"), &category), + note, + ), + ]; + incomplete.into_iter().for_each(|incomplete| { + stack.push(report_incomplete_ability(alloc, lines, incomplete)) + }); + + let report = Report { + title: "TYPE MISMATCH".to_string(), + filename, + doc: alloc.stack(stack), + severity: Severity::RuntimeError, + }; + Some(report) + } + BadPatternMissingAbility(region, category, found, incomplete) => { + let note = alloc.stack(vec![ + alloc.reflow("The ways this expression is used requires that the following types implement the following abilities, which they do not:"), + alloc.type_block(alloc.stack(incomplete.iter().map(|incomplete| { + symbol_does_not_implement(alloc, incomplete.typ, incomplete.ability) + }))), + ]); + let snippet = alloc.region(lines.convert_region(region)); + let mut stack = vec![ + alloc.text( + "This expression has a type does not implement the abilities it's expected to:", + ), + snippet, + lone_type( + alloc, + found.clone(), + found, + ExpectationContext::Arbitrary, + add_pattern_category(alloc, alloc.text("Right now it's"), &category), + note, + ), + ]; + incomplete.into_iter().for_each(|incomplete| { + stack.push(report_incomplete_ability(alloc, lines, incomplete)) + }); + + let report = Report { + title: "TYPE MISMATCH".to_string(), + filename, + doc: alloc.stack(stack), + severity: Severity::RuntimeError, + }; + Some(report) + } } } +fn report_incomplete_ability<'a>( + alloc: &'a RocDocAllocator<'a>, + lines: &LineInfo, + incomplete: IncompleteAbilityImplementation, +) -> RocDocBuilder<'a> { + let IncompleteAbilityImplementation { + typ, + ability, + specialized_members, + missing_members, + } = incomplete; + + debug_assert!(!missing_members.is_empty()); + + let mut stack = vec![alloc.concat(vec![ + alloc.reflow("The type "), + alloc.symbol_unqualified(typ), + alloc.reflow(" does not fully implement the ability "), + alloc.symbol_unqualified(ability), + alloc.reflow(". The following specializations are missing:"), + ])]; + + for member in missing_members.into_iter() { + stack.push(alloc.concat(vec![ + alloc.reflow("A specialization for "), + alloc.symbol_unqualified(member.value), + alloc.reflow(", which is defined here:"), + ])); + stack.push(alloc.region(lines.convert_region(member.region))); + } + + if !specialized_members.is_empty() { + stack.push(alloc.concat(vec![ + alloc.note(""), + alloc.symbol_unqualified(typ), + alloc.reflow(" specializes the following members of "), + alloc.symbol_unqualified(ability), + alloc.reflow(":"), + ])); + + for spec in specialized_members { + stack.push(alloc.concat(vec![ + alloc.symbol_unqualified(spec.value), + alloc.reflow(", specialized here:"), + ])); + stack.push(alloc.region(lines.convert_region(spec.region))); + } + } + + alloc.stack(stack) +} + fn report_shadowing<'b>( alloc: &'b RocDocAllocator<'b>, lines: &LineInfo, @@ -1019,11 +1099,7 @@ fn to_expr_report<'b>( } else { let mut stack = Vec::with_capacity(unimplemented_abilities.len()); for (err_type, ability) in unimplemented_abilities.into_iter() { - stack.push(alloc.concat(vec![ - to_doc(alloc, Parens::Unnecessary, err_type).0, - alloc.reflow(" does not implement "), - alloc.symbol_unqualified(ability), - ])); + stack.push(does_not_implement(alloc, err_type, ability)); } let hint = alloc.stack(vec![ @@ -1126,6 +1202,30 @@ fn to_expr_report<'b>( } } +fn does_not_implement<'a>( + alloc: &'a RocDocAllocator<'a>, + err_type: ErrorType, + ability: Symbol, +) -> RocDocBuilder<'a> { + alloc.concat(vec![ + to_doc(alloc, Parens::Unnecessary, err_type).0, + alloc.reflow(" does not implement "), + alloc.symbol_unqualified(ability), + ]) +} + +fn symbol_does_not_implement<'a>( + alloc: &'a RocDocAllocator<'a>, + symbol: Symbol, + ability: Symbol, +) -> RocDocBuilder<'a> { + alloc.concat(vec![ + alloc.symbol_unqualified(symbol), + alloc.reflow(" does not implement "), + alloc.symbol_unqualified(ability), + ]) +} + fn count_arguments(tipe: &ErrorType) -> usize { use ErrorType::*; diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index ee04904c1d..99cbc3d710 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -9727,8 +9727,11 @@ I need all branches in an `if` to have the same type! hash = \$Id n -> n + User := {} + noGoodVeryBadTerrible = { + nope: hash ($User {}), notYet: hash (A 1), } "# @@ -9739,7 +9742,7 @@ I need all branches in an `if` to have the same type! The 1st argument to `hash` is not what I expect: - 12│ notYet: hash (A 1), + 15│ notYet: hash (A 1), ^^^ This `A` global tag application has the type: @@ -9749,6 +9752,30 @@ I need all branches in an `if` to have the same type! But `hash` needs the 1st argument to be: a | a has Hash + + ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + + This expression has a type does not implement the abilities it's expected to: + + 14│ nope: hash ($User {}), + ^^^^^^^^ + + This User opaque wrapping has the type: + + User + + The ways this expression is used requires that the following types + implement the following abilities, which they do not: + + User does not implement Hash + + The type `User` does not fully implement the ability `Hash`. The following + specializations are missing: + + A specialization for `hash`, which is defined here: + + 4│ hash : a -> U64 | a has Hash + ^^^^ "# ), ) From d630562d997dd40650475438c27812d1a0cc7f76 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 13 Apr 2022 15:30:02 -0400 Subject: [PATCH 216/846] forgive me clippy --- compiler/solve/src/solve.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index c0d10cd841..2902eaefda 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -593,7 +593,7 @@ pub fn run_in_place( // Now that the module has been solved, we can run through and check all // types claimed to implement abilities. - problems.extend(deferred_must_implement_abilities.check(subs, &abilities_store)); + problems.extend(deferred_must_implement_abilities.check(subs, abilities_store)); state.env } From 493a96d85b817b74cd37bed53a518ebf20360c00 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 13 Apr 2022 21:40:08 +0200 Subject: [PATCH 217/846] mark the builtin files as such so builtin function implementations are inserted --- compiler/load/build.rs | 2 +- compiler/load/src/lib.rs | 18 ++++++++---------- compiler/load_internal/src/file.rs | 12 ++++++++++++ 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/compiler/load/build.rs b/compiler/load/build.rs index fccb69219b..e16e3a58ca 100644 --- a/compiler/load/build.rs +++ b/compiler/load/build.rs @@ -6,12 +6,12 @@ use roc_module::symbol::ModuleId; const MODULES: &[(ModuleId, &str)] = &[ (ModuleId::BOOL, "Bool.roc"), (ModuleId::RESULT, "Result.roc"), + (ModuleId::NUM, "Num.roc"), (ModuleId::LIST, "List.roc"), (ModuleId::STR, "Str.roc"), (ModuleId::DICT, "Dict.roc"), (ModuleId::SET, "Set.roc"), (ModuleId::BOX, "Box.roc"), - (ModuleId::NUM, "Num.roc"), ]; fn main() { diff --git a/compiler/load/src/lib.rs b/compiler/load/src/lib.rs index 6cfd01465e..065e263467 100644 --- a/compiler/load/src/lib.rs +++ b/compiler/load/src/lib.rs @@ -173,16 +173,14 @@ fn deserialize_help(bytes: &[u8]) -> (Subs, Vec<(Symbol, Variable)>) { fn read_cached_subs() -> MutMap)> { let mut output = MutMap::default(); - if false { - output.insert(ModuleId::BOOL, deserialize_help(BOOL)); - output.insert(ModuleId::RESULT, deserialize_help(RESULT)); - output.insert(ModuleId::LIST, deserialize_help(LIST)); - output.insert(ModuleId::STR, deserialize_help(STR)); - output.insert(ModuleId::DICT, deserialize_help(DICT)); - output.insert(ModuleId::SET, deserialize_help(SET)); - output.insert(ModuleId::BOX, deserialize_help(BOX)); - output.insert(ModuleId::NUM, deserialize_help(NUM)); - } + output.insert(ModuleId::BOOL, deserialize_help(BOOL)); + output.insert(ModuleId::RESULT, deserialize_help(RESULT)); + output.insert(ModuleId::LIST, deserialize_help(LIST)); + output.insert(ModuleId::STR, deserialize_help(STR)); + output.insert(ModuleId::DICT, deserialize_help(DICT)); + output.insert(ModuleId::SET, deserialize_help(SET)); + output.insert(ModuleId::BOX, deserialize_help(BOX)); + output.insert(ModuleId::NUM, deserialize_help(NUM)); output } diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index 0ca6a4eda6..380099174a 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -3128,6 +3128,18 @@ fn send_header<'a>( } } + // make sure when we run the bulitin modules in /compiler/builtins/roc that we + // mark these modules as Builtin. Otherwise the builtin functions are not instantiated + // and we just have a bunch of definitions with runtime errors in their bodies + let extra = { + match extra { + HeaderFor::Interface if home.is_builtin() => HeaderFor::Builtin { + generates_with: &[], + }, + _ => extra, + } + }; + ( home, Msg::Header(ModuleHeader { From 6343382af515dbd0d570d242a4579447ed884d33 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 13 Apr 2022 16:23:13 -0400 Subject: [PATCH 218/846] Propogate errors in record fields to layout error Closes #2812 Unfortunately we don't have a great way to test this without scaffolding a host since this happens while processing a variable exposed to the host. In tests the root cause just yields a type error first and codegen works, just bails during the runtime. But this works. --- compiler/mono/src/layout.rs | 8 ++++++-- compiler/types/src/subs.rs | 12 +++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/compiler/mono/src/layout.rs b/compiler/mono/src/layout.rs index 07cf05ea5e..88efc05517 100644 --- a/compiler/mono/src/layout.rs +++ b/compiler/mono/src/layout.rs @@ -10,7 +10,7 @@ use roc_target::{PtrWidth, TargetInfo}; use roc_types::subs::{ Content, FlatType, RecordFields, Subs, UnionTags, UnsortedUnionTags, Variable, }; -use roc_types::types::{gather_fields_unsorted_iter, RecordField}; +use roc_types::types::{gather_fields_unsorted_iter, RecordField, RecordFieldsError}; use std::collections::hash_map::{DefaultHasher, Entry}; use std::collections::HashMap; use std::hash::{Hash, Hasher}; @@ -1683,7 +1683,11 @@ fn layout_from_flat_type<'a>( // extract any values from the ext_var let mut pairs = Vec::with_capacity_in(fields.len(), arena); - for (label, field) in fields.unsorted_iterator(subs, ext_var) { + let it = match fields.unsorted_iterator(subs, ext_var) { + Ok(it) => it, + Err(RecordFieldsError) => return Err(LayoutProblem::Erroneous), + }; + for (label, field) in it { // drop optional fields let var = match field { RecordField::Optional(_) => continue, diff --git a/compiler/types/src/subs.rs b/compiler/types/src/subs.rs index 36f0ac811d..048824a436 100644 --- a/compiler/types/src/subs.rs +++ b/compiler/types/src/subs.rs @@ -1,5 +1,7 @@ #![deny(unsafe_op_in_unsafe_fn)] -use crate::types::{name_type_var, AliasKind, ErrorType, Problem, RecordField, TypeExt}; +use crate::types::{ + name_type_var, AliasKind, ErrorType, Problem, RecordField, RecordFieldsError, TypeExt, +}; use roc_collections::all::{ImMap, ImSet, MutSet, SendMap}; use roc_module::ident::{Lowercase, TagName, Uppercase}; use roc_module::symbol::Symbol; @@ -2713,11 +2715,11 @@ impl RecordFields { &'a self, subs: &'a Subs, ext: Variable, - ) -> impl Iterator)> + 'a { - let (it, _) = crate::types::gather_fields_unsorted_iter(subs, *self, ext) - .expect("Something weird ended up in a record type"); + ) -> Result)> + 'a, RecordFieldsError> + { + let (it, _) = crate::types::gather_fields_unsorted_iter(subs, *self, ext)?; - it + Ok(it) } #[inline(always)] From bdad1a5161c72cf5c261cc090d1c413bad780046 Mon Sep 17 00:00:00 2001 From: Brian Carroll Date: Fri, 8 Apr 2022 14:45:47 +0100 Subject: [PATCH 219/846] wasm: Extract List.mapN logic into a helper function --- compiler/gen_wasm/src/lib.rs | 2 +- compiler/gen_wasm/src/low_level.rs | 280 ++++++++++++----------------- compiler/test_gen/src/gen_list.rs | 8 +- 3 files changed, 123 insertions(+), 167 deletions(-) diff --git a/compiler/gen_wasm/src/lib.rs b/compiler/gen_wasm/src/lib.rs index 50f1e81350..7cca526acb 100644 --- a/compiler/gen_wasm/src/lib.rs +++ b/compiler/gen_wasm/src/lib.rs @@ -264,5 +264,5 @@ pub const DEBUG_LOG_SETTINGS: WasmDebugLogSettings = WasmDebugLogSettings { let_stmt_ir: false && cfg!(debug_assertions), instructions: false && cfg!(debug_assertions), storage_map: false && cfg!(debug_assertions), - keep_test_binary: true && cfg!(debug_assertions), + keep_test_binary: false && cfg!(debug_assertions), }; diff --git a/compiler/gen_wasm/src/low_level.rs b/compiler/gen_wasm/src/low_level.rs index 281e1d204d..6745c92e23 100644 --- a/compiler/gen_wasm/src/low_level.rs +++ b/compiler/gen_wasm/src/low_level.rs @@ -1033,172 +1033,60 @@ pub fn call_higher_order_lowlevel<'a>( let elem_x_size = elem_x.stack_size(TARGET_INFO); let (elem_ret_size, elem_ret_align) = elem_ret.stack_size_and_alignment(TARGET_INFO); - let cb = &mut backend.code_builder; + match op { + ListMap { xs } => list_map_n( + bitcode::LIST_MAP, + backend, + &[*xs], + return_sym, + *return_layout, + wrapper_fn_ptr, + inc_fn_ptr, + closure_data_exists, + *captured_environment, + *owns_captured_environment, + ), - // Load return pointer & argument values - // Wasm signature: (i32, i64, i64, i32, i32, i32, i32, i32, i32, i32) -> nil - backend.storage.load_symbols(cb, &[return_sym]); - backend.storage.load_symbol_zig(cb, *xs); // 2 x i64 - cb.i32_const(wrapper_fn_ptr); - if closure_data_exists { - backend.storage.load_symbols(cb, &[*captured_environment]); - } else { - // Normally, a zero-size arg would be eliminated in code gen, but Zig expects one! - cb.i32_const(0); // null pointer - } - cb.i32_const(inc_fn_ptr); - cb.i32_const(*owns_captured_environment as i32); - cb.i32_const(elem_ret_align as i32); // used for allocating the new list - cb.i32_const(elem_x_size as i32); - cb.i32_const(elem_ret_size as i32); + ListMap2 { xs, ys } => list_map_n( + bitcode::LIST_MAP2, + backend, + &[*xs, *ys], + return_sym, + *return_layout, + wrapper_fn_ptr, + inc_fn_ptr, + closure_data_exists, + *captured_environment, + *owns_captured_environment, + ), - let num_wasm_args = 10; // 1 return pointer + 8 Zig args + list 2nd i64 - let has_return_val = false; - backend.call_zig_builtin_after_loading_args( - bitcode::LIST_MAP, - num_wasm_args, - has_return_val, - ); - } + ListMap3 { xs, ys, zs } => list_map_n( + bitcode::LIST_MAP3, + backend, + &[*xs, *ys, *zs], + return_sym, + *return_layout, + wrapper_fn_ptr, + inc_fn_ptr, + closure_data_exists, + *captured_environment, + *owns_captured_environment, + ), - ListMap2 { xs, ys } => { - let list_x = backend.storage.symbol_layouts[xs]; - let list_y = backend.storage.symbol_layouts[ys]; + ListMap4 { xs, ys, zs, ws } => list_map_n( + bitcode::LIST_MAP4, + backend, + &[*xs, *ys, *zs, *ws], + return_sym, + *return_layout, + wrapper_fn_ptr, + inc_fn_ptr, + closure_data_exists, + *captured_environment, + *owns_captured_environment, + ), - let (elem_x, elem_y, elem_ret) = match (list_x, list_y, return_layout) { - ( - Layout::Builtin(Builtin::List(x)), - Layout::Builtin(Builtin::List(y)), - Layout::Builtin(Builtin::List(ret)), - ) => (x, y, ret), - _ => internal_error!("invalid arguments layout for {:?}", op), - }; - let elem_x_size = elem_x.stack_size(TARGET_INFO); - let elem_y_size = elem_y.stack_size(TARGET_INFO); - let (elem_ret_size, elem_ret_align) = elem_ret.stack_size_and_alignment(TARGET_INFO); - - let dec_x_fn_ptr = backend.get_refcount_fn_ptr(*elem_x, HelperOp::Dec); - let dec_y_fn_ptr = backend.get_refcount_fn_ptr(*elem_y, HelperOp::Dec); - - let cb = &mut backend.code_builder; - - /* Load Wasm arguments - return ptr: RocList, // i32 - list1: RocList, // i64, i64 - list2: RocList, // i64, i64 - caller: Caller2, // i32 - data: Opaque, // i32 - inc_n_data: IncN, // i32 - data_is_owned: bool, // i32 - alignment: u32, // i32 - a_width: usize, // i32 - b_width: usize, // i32 - c_width: usize, // i32 - dec_a: Dec, // i32 - dec_b: Dec, // i32 - */ - backend.storage.load_symbols(cb, &[return_sym]); - backend.storage.load_symbol_zig(cb, *xs); - backend.storage.load_symbol_zig(cb, *ys); - cb.i32_const(wrapper_fn_ptr); - if closure_data_exists { - backend.storage.load_symbols(cb, &[*captured_environment]); - } else { - cb.i32_const(0); // null pointer - } - cb.i32_const(inc_fn_ptr); - cb.i32_const(*owns_captured_environment as i32); - cb.i32_const(elem_ret_align as i32); - cb.i32_const(elem_x_size as i32); - cb.i32_const(elem_y_size as i32); - cb.i32_const(elem_ret_size as i32); - cb.i32_const(dec_x_fn_ptr); - cb.i32_const(dec_y_fn_ptr); - - let num_wasm_args = 15; - let has_return_val = false; - backend.call_zig_builtin_after_loading_args( - bitcode::LIST_MAP2, - num_wasm_args, - has_return_val, - ); - } - - ListMap3 { xs, ys, zs } => { - let list_x = backend.storage.symbol_layouts[xs]; - let list_y = backend.storage.symbol_layouts[ys]; - let list_z = backend.storage.symbol_layouts[zs]; - - let (elem_x, elem_y, elem_z, elem_ret) = match (list_x, list_y, list_z, return_layout) { - ( - Layout::Builtin(Builtin::List(x)), - Layout::Builtin(Builtin::List(y)), - Layout::Builtin(Builtin::List(z)), - Layout::Builtin(Builtin::List(ret)), - ) => (x, y, z, ret), - e => internal_error!("invalid arguments layout for {:?}\n{:?}", op, e), - }; - let elem_x_size = elem_x.stack_size(TARGET_INFO); - let elem_y_size = elem_y.stack_size(TARGET_INFO); - let elem_z_size = elem_y.stack_size(TARGET_INFO); - let (elem_ret_size, elem_ret_align) = elem_ret.stack_size_and_alignment(TARGET_INFO); - - let dec_x_fn_ptr = backend.get_refcount_fn_ptr(*elem_x, HelperOp::Dec); - let dec_y_fn_ptr = backend.get_refcount_fn_ptr(*elem_y, HelperOp::Dec); - let dec_z_fn_ptr = backend.get_refcount_fn_ptr(*elem_z, HelperOp::Dec); - - let cb = &mut backend.code_builder; - - /* Load Wasm arguments - return ptr i32 - list1: RocList, i64, i64 - list2: RocList, i64, i64 - list3: RocList, i64, i64 - caller: Caller3, i32 - data: Opaque, i32 - inc_n_data: IncN, i32 - data_is_owned: bool, i32 - alignment: u32, i32 - a_width: usize, i32 - b_width: usize, i32 - c_width: usize, i32 - d_width: usize, i32 - dec_a: Dec, i32 - dec_b: Dec, i32 - dec_c: Dec, i32 - */ - backend.storage.load_symbols(cb, &[return_sym]); - backend.storage.load_symbol_zig(cb, *xs); - backend.storage.load_symbol_zig(cb, *ys); - backend.storage.load_symbol_zig(cb, *zs); - cb.i32_const(wrapper_fn_ptr); - if closure_data_exists { - backend.storage.load_symbols(cb, &[*captured_environment]); - } else { - cb.i32_const(0); // null pointer - } - cb.i32_const(inc_fn_ptr); - cb.i32_const(*owns_captured_environment as i32); - cb.i32_const(elem_ret_align as i32); - cb.i32_const(elem_x_size as i32); - cb.i32_const(elem_y_size as i32); - cb.i32_const(elem_z_size as i32); - cb.i32_const(elem_ret_size as i32); - cb.i32_const(dec_x_fn_ptr); - cb.i32_const(dec_y_fn_ptr); - cb.i32_const(dec_z_fn_ptr); - - let num_wasm_args = 19; - let has_return_val = false; - backend.call_zig_builtin_after_loading_args( - bitcode::LIST_MAP3, - num_wasm_args, - has_return_val, - ); - } - - ListMap4 { .. } - | ListMapWithIndex { .. } + ListMapWithIndex { .. } | ListKeepIf { .. } | ListWalk { .. } | ListWalkUntil { .. } @@ -1212,3 +1100,71 @@ pub fn call_higher_order_lowlevel<'a>( | DictWalk { .. } => todo!("{:?}", op), } } + +fn unwrap_list_elem_layout(list_layout: Layout<'_>) -> &Layout<'_> { + match list_layout { + Layout::Builtin(Builtin::List(x)) => x, + e => internal_error!("expected List layout, got {:?}", e), + } +} + +#[allow(clippy::too_many_arguments)] +fn list_map_n<'a>( + zig_fn_name: &'static str, + backend: &mut WasmBackend<'a>, + arg_symbols: &[Symbol], + return_sym: Symbol, + return_layout: Layout<'a>, + wrapper_fn_ptr: i32, + inc_fn_ptr: i32, + closure_data_exists: bool, + captured_environment: Symbol, + owns_captured_environment: bool, +) { + let arg_elem_layouts = Vec::from_iter_in( + arg_symbols + .iter() + .map(|sym| *unwrap_list_elem_layout(backend.storage.symbol_layouts[sym])), + backend.env.arena, + ); + + let elem_ret = unwrap_list_elem_layout(return_layout); + let (elem_ret_size, elem_ret_align) = elem_ret.stack_size_and_alignment(TARGET_INFO); + + let cb = &mut backend.code_builder; + + backend.storage.load_symbols(cb, &[return_sym]); + + for s in arg_symbols { + backend.storage.load_symbol_zig(cb, *s); + } + cb.i32_const(wrapper_fn_ptr); + if closure_data_exists { + backend.storage.load_symbols(cb, &[captured_environment]); + } else { + // load_symbols assumes that a zero-size arg should be eliminated in code gen, + // but that's a specialization that our Zig code doesn't have! Pass a null pointer. + cb.i32_const(0); + } + cb.i32_const(inc_fn_ptr); + cb.i32_const(owns_captured_environment as i32); + cb.i32_const(elem_ret_align as i32); + for el in arg_elem_layouts.iter() { + cb.i32_const(el.stack_size(TARGET_INFO) as i32); + } + cb.i32_const(elem_ret_size as i32); + + // If we have lists of different lengths, we may need to decrement + let num_wasm_args = if arg_elem_layouts.len() > 1 { + for el in arg_elem_layouts.iter() { + let ptr = backend.get_refcount_fn_ptr(*el, HelperOp::Dec); + backend.code_builder.i32_const(ptr); + } + 7 + arg_elem_layouts.len() * 4 + } else { + 7 + arg_elem_layouts.len() * 3 + }; + + let has_return_val = false; + backend.call_zig_builtin_after_loading_args(zig_fn_name, num_wasm_args, has_return_val); +} diff --git a/compiler/test_gen/src/gen_list.rs b/compiler/test_gen/src/gen_list.rs index 74ad1281b2..1ad158a473 100644 --- a/compiler/test_gen/src/gen_list.rs +++ b/compiler/test_gen/src/gen_list.rs @@ -1104,7 +1104,7 @@ fn list_map_closure() { } #[test] -#[cfg(any(feature = "gen-llvm"))] +#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] fn list_map4_group() { assert_evals_to!( indoc!( @@ -1112,13 +1112,13 @@ fn list_map4_group() { List.map4 [1,2,3] [3,2,1] [2,1,3] [3,1,2] (\a, b, c, d -> Group a b c d) "# ), - RocList::from_slice(&[(1, 3, 2, 3), (2, 2, 1, 1), (3, 1, 3, 2)]), - RocList<(i64, i64, i64, i64)> + RocList::from_slice(&[[1, 3, 2, 3], [2, 2, 1, 1], [3, 1, 3, 2]]), + RocList<[i64; 4]> ); } #[test] -#[cfg(any(feature = "gen-llvm"))] +#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] fn list_map4_different_length() { assert_evals_to!( indoc!( From ae05e870af86ff203e2a167ab24acbc2e691f702 Mon Sep 17 00:00:00 2001 From: Brian Carroll Date: Wed, 13 Apr 2022 21:54:29 +0100 Subject: [PATCH 220/846] wasm: Fix Wasm type mismatch for empty closure data in List.mapN --- compiler/gen_wasm/src/low_level.rs | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/compiler/gen_wasm/src/low_level.rs b/compiler/gen_wasm/src/low_level.rs index 6745c92e23..c766e164bd 100644 --- a/compiler/gen_wasm/src/low_level.rs +++ b/compiler/gen_wasm/src/low_level.rs @@ -1016,22 +1016,17 @@ pub fn call_higher_order_lowlevel<'a>( let wrapper_fn_idx = backend.register_helper_proc(wrapper_sym, wrapper_layout, source); let wrapper_fn_ptr = backend.get_fn_table_index(wrapper_fn_idx); - let inc_fn_ptr = backend.get_refcount_fn_ptr(closure_data_layout, HelperOp::Inc); - - match op { - // List.map : List elem_x, (elem_x -> elem_ret) -> List elem_ret - ListMap { xs } => { - let list_x = backend.storage.symbol_layouts[xs]; - - let (elem_x, elem_ret) = match (list_x, return_layout) { - ( - Layout::Builtin(Builtin::List(elem_x)), - Layout::Builtin(Builtin::List(elem_ret)), - ) => (elem_x, elem_ret), - _ => internal_error!("invalid arguments layout for {:?}", op), - }; - let elem_x_size = elem_x.stack_size(TARGET_INFO); - let (elem_ret_size, elem_ret_align) = elem_ret.stack_size_and_alignment(TARGET_INFO); + let inc_fn_ptr = match closure_data_layout { + Layout::Struct { + field_layouts: &[], .. + } => { + // Our code gen would ignore the Unit arg, but the Zig builtin passes a pointer for it! + // That results in an exception (type signature mismatch in indirect call). + // The workaround is to use I32 layout, treating the (ignored) pointer as an integer. + backend.get_refcount_fn_ptr(Layout::Builtin(Builtin::Int(IntWidth::I32)), HelperOp::Inc) + } + _ => backend.get_refcount_fn_ptr(closure_data_layout, HelperOp::Inc), + }; match op { ListMap { xs } => list_map_n( From 41dd7d0b4df037ee781272b59d1a13682e780181 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 13 Apr 2022 18:35:50 -0400 Subject: [PATCH 221/846] Specialize bodies with body var, not function var I'm surprised code generation worked so well without this, before... Closes #2818 --- compiler/load_internal/src/file.rs | 1 + compiler/mono/src/ir.rs | 7 ++++++- repl_test/src/tests.rs | 17 +++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index 27f8cb8c76..5db29560e8 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -3859,6 +3859,7 @@ fn add_def_to_module<'a>( // This is a top-level definition, so it cannot capture anything captured_symbols: CapturedSymbols::None, body, + body_var: def.expr_var, // This is a 0-arity thunk, so it cannot be recursive is_self_recursive: false, }; diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 4ab5b2c841..8409b19b01 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -195,6 +195,7 @@ pub struct PartialProc<'a> { pub pattern_symbols: &'a [Symbol], pub captured_symbols: CapturedSymbols<'a>, pub body: roc_can::expr::Expr, + pub body_var: Variable, pub is_self_recursive: bool, } @@ -224,6 +225,7 @@ impl<'a> PartialProc<'a> { pattern_symbols, captured_symbols, body: body.value, + body_var: ret_var, is_self_recursive, } } @@ -240,6 +242,7 @@ impl<'a> PartialProc<'a> { pattern_symbols: pattern_symbols.into_bump_slice(), captured_symbols: CapturedSymbols::None, body: roc_can::expr::Expr::RuntimeError(error.value), + body_var: ret_var, is_self_recursive: false, } } @@ -902,6 +905,7 @@ impl<'a> Procs<'a> { pattern_symbols, captured_symbols, body: body.value, + body_var: ret_var, is_self_recursive, }; @@ -939,6 +943,7 @@ impl<'a> Procs<'a> { pattern_symbols, captured_symbols, body: body.value, + body_var: ret_var, is_self_recursive, }; @@ -2476,7 +2481,7 @@ fn specialize_external<'a>( }; let body = partial_proc.body.clone(); - let mut specialized_body = from_can(env, fn_var, body, procs, layout_cache); + let mut specialized_body = from_can(env, partial_proc.body_var, body, procs, layout_cache); match specialized { SpecializedLayout::FunctionPointerBody { diff --git a/repl_test/src/tests.rs b/repl_test/src/tests.rs index 0e54fec311..9f46137f38 100644 --- a/repl_test/src/tests.rs +++ b/repl_test/src/tests.rs @@ -1121,3 +1121,20 @@ fn issue_2582_specialize_result_value() { r" : Num *, List Str -> Result Str [ ListWasEmpty ]*", ) } + +#[test] +#[cfg(not(feature = "wasm"))] +fn issue_2818() { + expect_success( + indoc!( + r#" + f : {} -> List Str + f = \_ -> + x = [] + x + f + "# + ), + r" : {} -> List Str", + ) +} From 17e5ec85aa91b31172e58d30af7f0ec0538668b1 Mon Sep 17 00:00:00 2001 From: Jared Cone Date: Wed, 13 Apr 2022 23:18:00 -0700 Subject: [PATCH 222/846] Num.toStr unit tests --- compiler/test_gen/src/gen_num.rs | 124 +++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) diff --git a/compiler/test_gen/src/gen_num.rs b/compiler/test_gen/src/gen_num.rs index 88480c6310..11ae54b991 100644 --- a/compiler/test_gen/src/gen_num.rs +++ b/compiler/test_gen/src/gen_num.rs @@ -2745,6 +2745,130 @@ fn num_to_str() { ); } +#[test] +#[cfg(any(feature = "gen-llvm"))] +fn num_to_str_u8() { + use roc_std::RocStr; + + assert_evals_to!(r#"Num.toStr 0u8"#, RocStr::from("0"), RocStr); + assert_evals_to!(r#"Num.toStr 1u8"#, RocStr::from("1"), RocStr); + assert_evals_to!(r#"Num.toStr 10u8"#, RocStr::from("10"), RocStr); + + let max = format!("{}", u8::MAX); + assert_evals_to!(r#"Num.toStr Num.maxU8"#, RocStr::from(max.as_str()), RocStr); +} + +#[test] +#[cfg(any(feature = "gen-llvm"))] +fn num_to_str_u16() { + use roc_std::RocStr; + + assert_evals_to!(r#"Num.toStr 0u16"#, RocStr::from("0"), RocStr); + assert_evals_to!(r#"Num.toStr 1u16"#, RocStr::from("1"), RocStr); + assert_evals_to!(r#"Num.toStr 10u16"#, RocStr::from("10"), RocStr); + + let max = format!("{}", u16::MAX); + assert_evals_to!(r#"Num.toStr Num.maxU16"#, RocStr::from(max.as_str()), RocStr); +} + +#[test] +#[cfg(any(feature = "gen-llvm"))] +fn num_to_str_u32() { + use roc_std::RocStr; + + assert_evals_to!(r#"Num.toStr 0u32"#, RocStr::from("0"), RocStr); + assert_evals_to!(r#"Num.toStr 1u32"#, RocStr::from("1"), RocStr); + assert_evals_to!(r#"Num.toStr 10u32"#, RocStr::from("10"), RocStr); + + let max = format!("{}", u32::MAX); + assert_evals_to!(r#"Num.toStr Num.maxU32"#, RocStr::from(max.as_str()), RocStr); +} + +#[test] +#[cfg(any(feature = "gen-llvm"))] +fn num_to_str_u64() { + use roc_std::RocStr; + + assert_evals_to!(r#"Num.toStr 0u64"#, RocStr::from("0"), RocStr); + assert_evals_to!(r#"Num.toStr 1u64"#, RocStr::from("1"), RocStr); + assert_evals_to!(r#"Num.toStr 10u64"#, RocStr::from("10"), RocStr); + + let max = format!("{}", u64::MAX); + assert_evals_to!(r#"Num.toStr Num.maxU64"#, RocStr::from(max.as_str()), RocStr); +} + +#[test] +#[cfg(any(feature = "gen-llvm"))] +fn num_to_str_i8() { + use roc_std::RocStr; + + assert_evals_to!(r#"Num.toStr -10i8"#, RocStr::from("-10"), RocStr); + assert_evals_to!(r#"Num.toStr -1i8"#, RocStr::from("-1"), RocStr); + assert_evals_to!(r#"Num.toStr 0i8"#, RocStr::from("0"), RocStr); + assert_evals_to!(r#"Num.toStr 1i8"#, RocStr::from("1"), RocStr); + assert_evals_to!(r#"Num.toStr 10i8"#, RocStr::from("10"), RocStr); + + let max = format!("{}", i8::MAX); + assert_evals_to!(r#"Num.toStr Num.maxI8"#, RocStr::from(max.as_str()), RocStr); + + let max = format!("{}", i8::MIN); + assert_evals_to!(r#"Num.toStr Num.minI8"#, RocStr::from(max.as_str()), RocStr); +} + +#[test] +#[cfg(any(feature = "gen-llvm"))] +fn num_to_str_i16() { + use roc_std::RocStr; + + assert_evals_to!(r#"Num.toStr -10i16"#, RocStr::from("-10"), RocStr); + assert_evals_to!(r#"Num.toStr -1i16"#, RocStr::from("-1"), RocStr); + assert_evals_to!(r#"Num.toStr 0i16"#, RocStr::from("0"), RocStr); + assert_evals_to!(r#"Num.toStr 1i16"#, RocStr::from("1"), RocStr); + assert_evals_to!(r#"Num.toStr 10i16"#, RocStr::from("10"), RocStr); + + let max = format!("{}", i16::MAX); + assert_evals_to!(r#"Num.toStr Num.maxI16"#, RocStr::from(max.as_str()), RocStr); + + let max = format!("{}", i16::MIN); + assert_evals_to!(r#"Num.toStr Num.minI16"#, RocStr::from(max.as_str()), RocStr); +} + +#[test] +#[cfg(any(feature = "gen-llvm"))] +fn num_to_str_i32() { + use roc_std::RocStr; + + assert_evals_to!(r#"Num.toStr -10i32"#, RocStr::from("-10"), RocStr); + assert_evals_to!(r#"Num.toStr -1i32"#, RocStr::from("-1"), RocStr); + assert_evals_to!(r#"Num.toStr 0i32"#, RocStr::from("0"), RocStr); + assert_evals_to!(r#"Num.toStr 1i32"#, RocStr::from("1"), RocStr); + assert_evals_to!(r#"Num.toStr 10i32"#, RocStr::from("10"), RocStr); + + let max = format!("{}", i32::MAX); + assert_evals_to!(r#"Num.toStr Num.maxI32"#, RocStr::from(max.as_str()), RocStr); + + let max = format!("{}", i32::MIN); + assert_evals_to!(r#"Num.toStr Num.minI32"#, RocStr::from(max.as_str()), RocStr); +} + +#[test] +#[cfg(any(feature = "gen-llvm"))] +fn num_to_str_i64() { + use roc_std::RocStr; + + assert_evals_to!(r#"Num.toStr -10i64"#, RocStr::from("-10"), RocStr); + assert_evals_to!(r#"Num.toStr -1i64"#, RocStr::from("-1"), RocStr); + assert_evals_to!(r#"Num.toStr 0i64"#, RocStr::from("0"), RocStr); + assert_evals_to!(r#"Num.toStr 1i64"#, RocStr::from("1"), RocStr); + assert_evals_to!(r#"Num.toStr 10i64"#, RocStr::from("10"), RocStr); + + let max = format!("{}", i64::MAX); + assert_evals_to!(r#"Num.toStr Num.maxI64"#, RocStr::from(max.as_str()), RocStr); + + let max = format!("{}", i64::MIN); + assert_evals_to!(r#"Num.toStr Num.minI64"#, RocStr::from(max.as_str()), RocStr); +} + #[test] #[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] fn u8_addition_greater_than_i8() { From cb3ea8641c7589bbde8a37af6784d2be08162f53 Mon Sep 17 00:00:00 2001 From: Jared Cone Date: Wed, 13 Apr 2022 23:20:09 -0700 Subject: [PATCH 223/846] Fixed strFromIntHelp. std.math.minInt is 0 for unsigned types, so buffer size was being set to only 1. --- compiler/builtins/bitcode/src/str.zig | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/compiler/builtins/bitcode/src/str.zig b/compiler/builtins/bitcode/src/str.zig index 0628c38ae6..03657bbec3 100644 --- a/compiler/builtins/bitcode/src/str.zig +++ b/compiler/builtins/bitcode/src/str.zig @@ -468,8 +468,10 @@ fn strFromIntHelp(comptime T: type, int: T) RocStr { const size = comptime blk: { // the string representation of the minimum i128 value uses at most 40 characters var buf: [40]u8 = undefined; - var result = std.fmt.bufPrint(&buf, "{}", .{std.math.minInt(T)}) catch unreachable; - break :blk result.len; + var resultMin = std.fmt.bufPrint(&buf, "{}", .{std.math.minInt(T)}) catch unreachable; + var resultMax = std.fmt.bufPrint(&buf, "{}", .{std.math.maxInt(T)}) catch unreachable; + var result = if (resultMin.len > resultMax.len) resultMin.len else resultMax.len; + break :blk result; }; var buf: [size]u8 = undefined; From b35debee70fcc944fc0709d2cf2bb9c200c5b4f5 Mon Sep 17 00:00:00 2001 From: Jared Cone Date: Wed, 13 Apr 2022 23:36:00 -0700 Subject: [PATCH 224/846] fixed formatting --- compiler/test_gen/src/gen_num.rs | 54 ++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/compiler/test_gen/src/gen_num.rs b/compiler/test_gen/src/gen_num.rs index 11ae54b991..62f9f21eb4 100644 --- a/compiler/test_gen/src/gen_num.rs +++ b/compiler/test_gen/src/gen_num.rs @@ -2768,7 +2768,11 @@ fn num_to_str_u16() { assert_evals_to!(r#"Num.toStr 10u16"#, RocStr::from("10"), RocStr); let max = format!("{}", u16::MAX); - assert_evals_to!(r#"Num.toStr Num.maxU16"#, RocStr::from(max.as_str()), RocStr); + assert_evals_to!( + r#"Num.toStr Num.maxU16"#, + RocStr::from(max.as_str()), + RocStr + ); } #[test] @@ -2781,7 +2785,11 @@ fn num_to_str_u32() { assert_evals_to!(r#"Num.toStr 10u32"#, RocStr::from("10"), RocStr); let max = format!("{}", u32::MAX); - assert_evals_to!(r#"Num.toStr Num.maxU32"#, RocStr::from(max.as_str()), RocStr); + assert_evals_to!( + r#"Num.toStr Num.maxU32"#, + RocStr::from(max.as_str()), + RocStr + ); } #[test] @@ -2794,7 +2802,11 @@ fn num_to_str_u64() { assert_evals_to!(r#"Num.toStr 10u64"#, RocStr::from("10"), RocStr); let max = format!("{}", u64::MAX); - assert_evals_to!(r#"Num.toStr Num.maxU64"#, RocStr::from(max.as_str()), RocStr); + assert_evals_to!( + r#"Num.toStr Num.maxU64"#, + RocStr::from(max.as_str()), + RocStr + ); } #[test] @@ -2827,10 +2839,18 @@ fn num_to_str_i16() { assert_evals_to!(r#"Num.toStr 10i16"#, RocStr::from("10"), RocStr); let max = format!("{}", i16::MAX); - assert_evals_to!(r#"Num.toStr Num.maxI16"#, RocStr::from(max.as_str()), RocStr); + assert_evals_to!( + r#"Num.toStr Num.maxI16"#, + RocStr::from(max.as_str()), + RocStr + ); let max = format!("{}", i16::MIN); - assert_evals_to!(r#"Num.toStr Num.minI16"#, RocStr::from(max.as_str()), RocStr); + assert_evals_to!( + r#"Num.toStr Num.minI16"#, + RocStr::from(max.as_str()), + RocStr + ); } #[test] @@ -2845,10 +2865,18 @@ fn num_to_str_i32() { assert_evals_to!(r#"Num.toStr 10i32"#, RocStr::from("10"), RocStr); let max = format!("{}", i32::MAX); - assert_evals_to!(r#"Num.toStr Num.maxI32"#, RocStr::from(max.as_str()), RocStr); + assert_evals_to!( + r#"Num.toStr Num.maxI32"#, + RocStr::from(max.as_str()), + RocStr + ); let max = format!("{}", i32::MIN); - assert_evals_to!(r#"Num.toStr Num.minI32"#, RocStr::from(max.as_str()), RocStr); + assert_evals_to!( + r#"Num.toStr Num.minI32"#, + RocStr::from(max.as_str()), + RocStr + ); } #[test] @@ -2863,10 +2891,18 @@ fn num_to_str_i64() { assert_evals_to!(r#"Num.toStr 10i64"#, RocStr::from("10"), RocStr); let max = format!("{}", i64::MAX); - assert_evals_to!(r#"Num.toStr Num.maxI64"#, RocStr::from(max.as_str()), RocStr); + assert_evals_to!( + r#"Num.toStr Num.maxI64"#, + RocStr::from(max.as_str()), + RocStr + ); let max = format!("{}", i64::MIN); - assert_evals_to!(r#"Num.toStr Num.minI64"#, RocStr::from(max.as_str()), RocStr); + assert_evals_to!( + r#"Num.toStr Num.minI64"#, + RocStr::from(max.as_str()), + RocStr + ); } #[test] From 84ff4ec1edd98ae4c3f8efc32c91894adb79a176 Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Thu, 14 Apr 2022 13:15:57 +0200 Subject: [PATCH 225/846] fix editor freeze --- editor/src/editor/main.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/editor/src/editor/main.rs b/editor/src/editor/main.rs index 3455724465..e1076dbe11 100644 --- a/editor/src/editor/main.rs +++ b/editor/src/editor/main.rs @@ -267,6 +267,7 @@ fn run_event_loop(project_dir_path_opt: Option<&Path>) -> Result<(), Box { keyboard_modifiers = modifiers; } + Event::MainEventsCleared => window.request_redraw(), Event::RedrawRequested { .. } => { // Get a command encoder for the current frame let mut encoder = From e4fa11184b486931cf1885e5ca645f478fe3e604 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 13 Apr 2022 13:53:20 -0400 Subject: [PATCH 226/846] Drop Result types from division in breakout example --- examples/breakout/breakout.roc | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index e48ec96e0b..e8ff4a9c0d 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -1,23 +1,23 @@ app "breakout" packages { pf: "platform" } - imports []# [ pf.Action.{ Action }, pf.Elem.{ button, text, row, col } ] + imports [] provides [ program ] { Model } to pf Model : { height : F32, width : F32, pos : F32 } program = { init, update, render } -#init : { height : F32, width : F32 } -> Model +# init : { height : F32, width : F32 } -> Model init = \_ -> { width: 1900, height: 1000, pos: 100 } -#update : Model, Event -> Model +# update : Model, Event -> Model update = \model, event -> when event is Resize size -> { model & width: size.width, height: size.height } - KeyUp keyCode -> model + KeyUp _ -> model KeyDown keyCode -> { model & pos: model.pos + 50 } -#render : Model -> List Elem +# render : Model -> List Elem render = \model -> numRows = 4 numCols = 8 @@ -31,18 +31,17 @@ render = \model -> row = index // numCols - |> Result.withDefault 0 |> Num.toF32 - red = (col / Num.toF32 numCols) |> Result.withDefault 0 - green = ((row / Num.toF32 numRows) |> Result.withDefault 0) - blue = (Num.toF32 index / Num.toF32 numBlocks) |> Result.withDefault 0 + red = col / Num.toF32 numCols + green = row / Num.toF32 numRows + blue = Num.toF32 index / Num.toF32 numBlocks color = { r: red * 0.8, g: 0.2 + green * 0.6, b: 0.2 + blue * 0.8, a: 1 } { row, col, color } - blockWidth = model.width / numCols |> Result.withDefault 0 + blockWidth = model.width / numCols blockHeight = 80 rects = From 698603aae7854d3125a248f785067b65c1040a57 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 14 Apr 2022 08:13:17 -0400 Subject: [PATCH 227/846] Restore examples/gui to `trunk` version --- examples/gui/Hello.roc | 15 +- examples/gui/platform/Cargo.toml | 1 + examples/gui/platform/Package-Config.roc | 13 +- examples/gui/platform/build.rs | 4 + examples/gui/platform/src/graphics/colors.rs | 2 +- .../platform/src/graphics/primitives/text.rs | 157 +++++------ examples/gui/platform/src/gui.rs | 97 +++---- examples/gui/platform/src/lib.rs | 16 +- examples/gui/platform/src/rects_and_texts.rs | 70 +++++ examples/gui/platform/src/roc.rs | 256 +----------------- 10 files changed, 220 insertions(+), 411 deletions(-) create mode 100644 examples/gui/platform/build.rs create mode 100644 examples/gui/platform/src/rects_and_texts.rs diff --git a/examples/gui/Hello.roc b/examples/gui/Hello.roc index 8ef081fe5c..653ccbd8e1 100644 --- a/examples/gui/Hello.roc +++ b/examples/gui/Hello.roc @@ -1,20 +1,13 @@ app "hello-gui" packages { pf: "platform" } imports []# [ pf.Action.{ Action }, pf.Elem.{ button, text, row, col } ] - provides [ program ] to pf + provides [ render ] to pf -program = { render } - -render = \state -> - div0 = \numerator, denominator -> (numerator / denominator) |> Result.withDefault 0 - - rgba = \r, g, b, a -> { r: div0 r 255, g: div0 g 255, b: div0 b 255, a } +render = + rgba = \r, g, b, a -> { r: r / 255, g: g / 255, b: b / 255, a } styles = { bgColor: rgba 100 50 50 1, borderColor: rgba 10 20 30 1, borderWidth: 10, textColor: rgba 220 220 250 1 } - height = if state.height == 1000 then "correct!" else if state.height == 0 then "zero" else "incorrect" - width = if state.width == 1900 then "Correct!" else if state.width == 0 then "zero" else "Incorrect" - Col [ Row @@ -25,6 +18,4 @@ render = \state -> ], Button (Text "Mid Left ") { styles & bgColor: rgba 150 100 100 1 }, Button (Text "Bottom Left") { styles & bgColor: rgba 150 50 50 1 }, - Button (Text "height: \(height)") { styles & bgColor: rgba 50 150 50 1 }, - Button (Text "width: \(width)") { styles & bgColor: rgba 50 100 50 1 }, ] diff --git a/examples/gui/platform/Cargo.toml b/examples/gui/platform/Cargo.toml index dee9bee179..b82712e562 100644 --- a/examples/gui/platform/Cargo.toml +++ b/examples/gui/platform/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" authors = ["The Roc Contributors"] license = "UPL-1.0" edition = "2018" +links = "app" # Needed to be able to run on non-Windows systems for some reason. Without this, cargo panics with: # diff --git a/examples/gui/platform/Package-Config.roc b/examples/gui/platform/Package-Config.roc index ab31e1fd6b..8099b4ded7 100644 --- a/examples/gui/platform/Package-Config.roc +++ b/examples/gui/platform/Package-Config.roc @@ -1,9 +1,9 @@ platform "gui" - requires {} { program : Program State } + requires {} { render : Elem } exposes [] packages {} imports [] - provides [ programForHost ] + provides [ renderForHost ] Rgba : { r : F32, g : F32, b : F32, a : F32 } @@ -11,10 +11,5 @@ ButtonStyles : { bgColor : Rgba, borderColor : Rgba, borderWidth : F32, textColo Elem : [ Button Elem ButtonStyles, Col (List Elem), Row (List Elem), Text Str ] -State : { width : F32, height : F32 } - -Program state : { render : state -> Elem } - -# TODO allow changing the title - maybe via Action.setTitle -programForHost : { render : (State -> Elem) as Render } -programForHost = program +renderForHost : Elem +renderForHost = render diff --git a/examples/gui/platform/build.rs b/examples/gui/platform/build.rs new file mode 100644 index 0000000000..73159e387c --- /dev/null +++ b/examples/gui/platform/build.rs @@ -0,0 +1,4 @@ +fn main() { + println!("cargo:rustc-link-lib=dylib=app"); + println!("cargo:rustc-link-search=."); +} diff --git a/examples/gui/platform/src/graphics/colors.rs b/examples/gui/platform/src/graphics/colors.rs index 3ec448413f..e0932a1d69 100644 --- a/examples/gui/platform/src/graphics/colors.rs +++ b/examples/gui/platform/src/graphics/colors.rs @@ -3,7 +3,7 @@ use palette::{FromColor, Hsv, Srgb}; /// This order is optimized for what Roc will send #[repr(C)] -#[derive(Copy, Clone, Debug, PartialEq, Default)] +#[derive(Copy, Clone, Debug, PartialEq)] pub struct Rgba { a: f32, b: f32, diff --git a/examples/gui/platform/src/graphics/primitives/text.rs b/examples/gui/platform/src/graphics/primitives/text.rs index 4ecaa28d9b..f002d506e7 100644 --- a/examples/gui/platform/src/graphics/primitives/text.rs +++ b/examples/gui/platform/src/graphics/primitives/text.rs @@ -6,9 +6,12 @@ use crate::graphics::colors::Rgba; use crate::graphics::style::DEFAULT_FONT_SIZE; -use ab_glyph::{FontArc, InvalidFont}; -use cgmath::Vector2; -use wgpu_glyph::{ab_glyph, GlyphBrush, GlyphBrushBuilder}; +use ab_glyph::{FontArc, Glyph, InvalidFont}; +use cgmath::{Vector2, Vector4}; +use glyph_brush::OwnedSection; +use wgpu_glyph::{ab_glyph, GlyphBrush, GlyphBrushBuilder, Section}; + +use super::rect::Rect; #[derive(Debug)] pub struct Text<'a> { @@ -35,92 +38,92 @@ impl<'a> Default for Text<'a> { } } -// pub fn layout_from_text(text: &Text) -> wgpu_glyph::Layout { -// wgpu_glyph::Layout::default().h_align(if text.centered { -// wgpu_glyph::HorizontalAlign::Center -// } else { -// wgpu_glyph::HorizontalAlign::Left -// }) -// } +pub fn layout_from_text(text: &Text) -> wgpu_glyph::Layout { + wgpu_glyph::Layout::default().h_align(if text.centered { + wgpu_glyph::HorizontalAlign::Center + } else { + wgpu_glyph::HorizontalAlign::Left + }) +} -// fn section_from_text<'a>( -// text: &'a Text, -// layout: wgpu_glyph::Layout, -// ) -> wgpu_glyph::Section<'a> { -// Section { -// screen_position: text.position.into(), -// bounds: text.area_bounds.into(), -// layout, -// ..Section::default() -// } -// .add_text( -// wgpu_glyph::Text::new(text.text) -// .with_color(text.color) -// .with_scale(text.size), -// ) -// } +fn section_from_text<'a>( + text: &'a Text, + layout: wgpu_glyph::Layout, +) -> wgpu_glyph::Section<'a> { + Section { + screen_position: text.position.into(), + bounds: text.area_bounds.into(), + layout, + ..Section::default() + } + .add_text( + wgpu_glyph::Text::new(text.text) + .with_color(text.color) + .with_scale(text.size), + ) +} -// pub fn owned_section_from_text(text: &Text) -> OwnedSection { -// let layout = layout_from_text(text); +pub fn owned_section_from_text(text: &Text) -> OwnedSection { + let layout = layout_from_text(text); -// OwnedSection { -// screen_position: text.position.into(), -// bounds: text.area_bounds.into(), -// layout, -// ..OwnedSection::default() -// } -// .add_text( -// glyph_brush::OwnedText::new(text.text) -// .with_color(Vector4::from(text.color)) -// .with_scale(text.size), -// ) -// } + OwnedSection { + screen_position: text.position.into(), + bounds: text.area_bounds.into(), + layout, + ..OwnedSection::default() + } + .add_text( + glyph_brush::OwnedText::new(text.text) + .with_color(Vector4::from(text.color)) + .with_scale(text.size), + ) +} -// pub fn owned_section_from_glyph_texts( -// text: Vec, -// screen_position: (f32, f32), -// area_bounds: (f32, f32), -// layout: wgpu_glyph::Layout, -// ) -> glyph_brush::OwnedSection { -// glyph_brush::OwnedSection { -// screen_position, -// bounds: area_bounds, -// layout, -// text, -// } -// } +pub fn owned_section_from_glyph_texts( + text: Vec, + screen_position: (f32, f32), + area_bounds: (f32, f32), + layout: wgpu_glyph::Layout, +) -> glyph_brush::OwnedSection { + glyph_brush::OwnedSection { + screen_position, + bounds: area_bounds, + layout, + text, + } +} -// pub fn queue_text_draw(text: &Text, glyph_brush: &mut GlyphBrush<()>) { -// let layout = layout_from_text(text); +pub fn queue_text_draw(text: &Text, glyph_brush: &mut GlyphBrush<()>) { + let layout = layout_from_text(text); -// let section = section_from_text(text, layout); + let section = section_from_text(text, layout); -// glyph_brush.queue(section.clone()); -// } + glyph_brush.queue(section.clone()); +} -// fn glyph_to_rect(glyph: &wgpu_glyph::SectionGlyph) -> Rect { -// let position = glyph.glyph.position; -// let px_scale = glyph.glyph.scale; -// let width = glyph_width(&glyph.glyph); -// let height = px_scale.y; -// let top_y = glyph_top_y(&glyph.glyph); +fn glyph_to_rect(glyph: &wgpu_glyph::SectionGlyph) -> Rect { + let position = glyph.glyph.position; + let px_scale = glyph.glyph.scale; + let width = glyph_width(&glyph.glyph); + let height = px_scale.y; + let top_y = glyph_top_y(&glyph.glyph); -// Rect { -// pos: [position.x, top_y].into(), -// width, -// height, -// } -// } + Rect { + pos: [position.x, top_y].into(), + width, + height, + } +} -// pub fn glyph_top_y(glyph: &Glyph) -> f32 { -// let height = glyph.scale.y; +pub fn glyph_top_y(glyph: &Glyph) -> f32 { + let height = glyph.scale.y; -// glyph.position.y - height * 0.75 -// } + glyph.position.y - height * 0.75 +} -// pub fn glyph_width(glyph: &Glyph) -> f32 { -// glyph.scale.x * 0.4765 -// } +pub fn glyph_width(glyph: &Glyph) -> f32 { + glyph.scale.x * 0.4765 +} pub fn build_glyph_brush( gpu_device: &wgpu::Device, diff --git a/examples/gui/platform/src/gui.rs b/examples/gui/platform/src/gui.rs index d99b1ba3c8..755fa40ae8 100644 --- a/examples/gui/platform/src/gui.rs +++ b/examples/gui/platform/src/gui.rs @@ -9,11 +9,12 @@ use crate::{ text::build_glyph_brush, }, }, - roc::{self, RocElem, RocElemTag}, + roc::{RocElem, RocElemTag}, }; use cgmath::{Vector2, Vector4}; use glyph_brush::OwnedSection; use pipelines::RectResources; +use roc_std::RocStr; use std::error::Error; use wgpu::{CommandEncoder, LoadOp, RenderPass, TextureView}; use wgpu_glyph::{GlyphBrush, GlyphCruncher}; @@ -31,18 +32,16 @@ use winit::{ // // See this link to learn wgpu: https://sotrh.github.io/learn-wgpu/ -pub fn run_event_loop(title: &str, state: roc::State) -> Result<(), Box> { +fn run_event_loop(title: &str, root: RocElem) -> Result<(), Box> { // Open window and create a surface let mut event_loop = winit::event_loop::EventLoop::new(); let window = winit::window::WindowBuilder::new() - .with_inner_size(PhysicalSize::new(state.width, state.height)) + .with_inner_size(PhysicalSize::new(1900.0, 1000.0)) .with_title(title) .build(&event_loop) .unwrap(); - let mut root = roc::app_render(state); - let instance = wgpu::Instance::new(wgpu::Backends::all()); let surface = unsafe { instance.create_surface(&window) }; @@ -144,41 +143,42 @@ pub fn run_event_loop(title: &str, state: roc::State) -> Result<(), Box { - use event::ElementState::*; - use event::VirtualKeyCode::*; + // let input_outcome_res = + // app_update::handle_new_char(&ch, &mut app_model, keyboard_modifiers); + // if let Err(e) = input_outcome_res { + // print_err(&e) + // } else if let Ok(InputOutcome::Ignored) = input_outcome_res { + // println!("Input '{}' ignored!", ch); + // } + todo!("TODO handle character input"); + } + //Keyboard Input + Event::WindowEvent { + event: event::WindowEvent::KeyboardInput { input: _, .. }, + .. + } => { + // if let Some(virtual_keycode) = input.virtual_keycode { + // if let Some(ref mut ed_model) = app_model.ed_model_opt { + // if ed_model.has_focus { + // let keydown_res = keyboard_input::handle_keydown( + // input.state, + // virtual_keycode, + // keyboard_modifiers, + // &mut app_model, + // ); - match keycode { - Left => match input_state { - Pressed => println!("Left pressed!"), - Released => println!("Left released!"), - }, - Right => match input_state { - Pressed => println!("Right pressed!"), - Released => println!("Right released!"), - }, - _ => { - println!("Other!"); - } - }; - - root = roc::app_render(roc::State { - height: 0.0, - width: 0.0, - }); + // if let Err(e) = keydown_res { + // print_err(&e) + // } + // } + // } + // } + // TODO todo!("TODO handle keyboard input"); } //Modifiers Changed Event::WindowEvent { @@ -230,15 +230,9 @@ pub fn run_event_loop(title: &str, state: roc::State) -> Result<(), Box = Vec::new(); // TODO test that root node can get focus! - let focused_elem: *const RocElem = match focus_ancestry.first() { - Some((ptr_ref, _)) => *ptr_ref, - None => std::ptr::null(), - }; - + // TODO use with_capacity based on some heuristic let (_bounds, drawable) = to_drawable( &root, - focused_elem, Bounds { width: size.width as f32, height: size.height as f32, @@ -346,6 +340,10 @@ fn begin_render_pass<'a>( }) } +pub fn render(title: RocStr, root: RocElem) { + run_event_loop(title.as_str(), root).expect("Error running event loop"); +} + #[derive(Copy, Clone, Debug, Default)] struct Bounds { width: f32, @@ -497,23 +495,18 @@ fn draw( } } -/// focused_elem is the currently-focused element (or NULL if nothing has the focus) fn to_drawable( elem: &RocElem, - focused_elem: *const RocElem, bounds: Bounds, glyph_brush: &mut GlyphBrush<()>, ) -> (Bounds, Drawable) { use RocElemTag::*; - let is_focused = focused_elem == elem as *const RocElem; - match elem.tag() { Button => { let button = unsafe { &elem.entry().button }; let styles = button.styles; - let (child_bounds, child_drawable) = - to_drawable(&*button.child, focused_elem, bounds, glyph_brush); + let (child_bounds, child_drawable) = to_drawable(&*button.child, bounds, glyph_brush); let button_drawable = Drawable { bounds: child_bounds, @@ -580,8 +573,7 @@ fn to_drawable( let mut offset_entries = Vec::with_capacity(row.children.len()); for child in row.children.as_slice().iter() { - let (child_bounds, child_drawable) = - to_drawable(&child, focused_elem, bounds, glyph_brush); + let (child_bounds, child_drawable) = to_drawable(&child, bounds, glyph_brush); offset_entries.push((offset, child_drawable)); @@ -610,8 +602,7 @@ fn to_drawable( let mut offset_entries = Vec::with_capacity(col.children.len()); for child in col.children.as_slice().iter() { - let (child_bounds, child_drawable) = - to_drawable(&child, focused_elem, bounds, glyph_brush); + let (child_bounds, child_drawable) = to_drawable(&child, bounds, glyph_brush); offset_entries.push((offset, child_drawable)); diff --git a/examples/gui/platform/src/lib.rs b/examples/gui/platform/src/lib.rs index fb6877881a..17fa0b4d4a 100644 --- a/examples/gui/platform/src/lib.rs +++ b/examples/gui/platform/src/lib.rs @@ -1,16 +1,20 @@ -mod focus; mod graphics; mod gui; +mod rects_and_texts; mod roc; +use crate::roc::RocElem; + +extern "C" { + #[link_name = "roc__renderForHost_1_exposed"] + fn roc_render() -> RocElem; +} + #[no_mangle] pub extern "C" fn rust_main() -> i32 { - let state = roc::State { - width: 1900.0, - height: 1000.0, - }; + let root_elem = unsafe { roc_render() }; - gui::run_event_loop("test title", state).expect("Error running event loop"); + gui::render("test title".into(), root_elem); // Exit code 0 diff --git a/examples/gui/platform/src/rects_and_texts.rs b/examples/gui/platform/src/rects_and_texts.rs new file mode 100644 index 0000000000..3eed8654ac --- /dev/null +++ b/examples/gui/platform/src/rects_and_texts.rs @@ -0,0 +1,70 @@ +use crate::graphics::primitives::rect::RectElt; +use crate::graphics::primitives::text::{owned_section_from_text, Text}; + +#[derive(Debug)] +pub struct RectsAndTexts { + pub text_sections_behind: Vec, // displayed in front of rect_behind, behind everything else + pub text_sections_front: Vec, // displayed in front of everything + pub rects_behind: Vec, // displayed at lowest depth + pub rects_front: Vec, // displayed in front of text_sections_behind, behind text_sections_front +} + +impl RectsAndTexts { + pub fn new() -> Self { + Self { + text_sections_behind: Vec::new(), + text_sections_front: Vec::new(), + rects_behind: Vec::new(), + rects_front: Vec::new(), + } + } + + pub fn init( + rects_behind: Vec, + texts_behind: Vec, + rects_front: Vec, + texts_front: Vec, + ) -> Self { + Self { + text_sections_behind: texts_behind + .iter() + .map(|txt| owned_section_from_text(txt)) + .collect(), + text_sections_front: texts_front + .iter() + .map(|txt| owned_section_from_text(txt)) + .collect(), + rects_behind, + rects_front, + } + } + + pub fn add_text_behind(&mut self, new_text_section: glyph_brush::OwnedSection) { + self.text_sections_behind.push(new_text_section); + } + + pub fn add_text_front(&mut self, new_text_section: glyph_brush::OwnedSection) { + self.text_sections_front.push(new_text_section); + } + + pub fn add_rect_behind(&mut self, new_rect: RectElt) { + self.rects_behind.push(new_rect); + } + + pub fn add_rects_behind(&mut self, new_rects: Vec) { + self.rects_behind.extend(new_rects); + } + + pub fn add_rect_front(&mut self, new_rect: RectElt) { + self.rects_front.push(new_rect); + } + + pub fn extend(&mut self, rects_and_texts: RectsAndTexts) { + self.text_sections_behind + .extend(rects_and_texts.text_sections_behind); + self.text_sections_front + .extend(rects_and_texts.text_sections_front); + self.rects_behind.extend(rects_and_texts.rects_behind); + self.rects_front.extend(rects_and_texts.rects_front); + } +} diff --git a/examples/gui/platform/src/roc.rs b/examples/gui/platform/src/roc.rs index 9a3ca76439..034181deed 100644 --- a/examples/gui/platform/src/roc.rs +++ b/examples/gui/platform/src/roc.rs @@ -1,37 +1,10 @@ use crate::graphics::colors::Rgba; -use core::alloc::Layout; use core::ffi::c_void; use core::mem::{self, ManuallyDrop}; use roc_std::{ReferenceCount, RocList, RocStr}; use std::ffi::CStr; -use std::fmt::Debug; use std::os::raw::c_char; -extern "C" { - #[link_name = "roc__programForHost_1_exposed_generic"] - fn roc_program() -> (); - - #[link_name = "roc__programForHost_1_Render_caller"] - fn call_Render(state: *const State, closure_data: *const u8, output: *mut u8) -> RocElem; - - #[link_name = "roc__programForHost_size"] - fn roc_program_size() -> i64; - - #[allow(dead_code)] - #[link_name = "roc__programForHost_1_Render_size"] - fn size_Render() -> i64; - - #[link_name = "roc__programForHost_1_Render_result_size"] - fn size_Render_result() -> i64; -} - -#[derive(Debug)] -#[repr(C)] -pub struct State { - pub height: f32, - pub width: f32, -} - #[no_mangle] pub unsafe extern "C" fn roc_alloc(size: usize, _alignment: u32) -> *mut c_void { return libc::malloc(size); @@ -75,185 +48,30 @@ pub unsafe extern "C" fn roc_memset(dst: *mut c_void, c: i32, n: usize) -> *mut libc::memset(dst, c, n) } -#[repr(transparent)] -#[cfg(target_pointer_width = "64")] // on a 64-bit system, the tag fits in this pointer's spare 3 bits -#[derive(Copy, Clone, Debug, PartialEq, Eq)] -pub struct ElemId(*const RocElemEntry); - #[repr(transparent)] #[cfg(target_pointer_width = "64")] // on a 64-bit system, the tag fits in this pointer's spare 3 bits pub struct RocElem { entry: *const RocElemEntry, } -impl Debug for RocElem { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - use RocElemTag::*; - - match self.tag() { - Button => unsafe { &*self.entry().button }.fmt(f), - Text => unsafe { &*self.entry().text }.fmt(f), - Row => { - let row_or_col = unsafe { &*self.entry().row_or_col }; - - f.debug_struct("RocRow") - .field("children", &row_or_col.children) - .finish() - } - Col => { - let row_or_col = unsafe { &*self.entry().row_or_col }; - - f.debug_struct("RocCol") - .field("children", &row_or_col.children) - .finish() - } - } - } -} - impl RocElem { - #[allow(unused)] - pub fn id(&self) -> ElemId { - ElemId(self.entry) - } - #[cfg(target_pointer_width = "64")] pub fn tag(&self) -> RocElemTag { // On a 64-bit system, the last 3 bits of the pointer store the tag unsafe { mem::transmute::((self.entry as u8) & 0b0000_0111) } } - #[allow(unused)] pub fn entry(&self) -> &RocElemEntry { - unsafe { &*self.entry_ptr() } - } - - pub fn entry_ptr(&self) -> *const RocElemEntry { // On a 64-bit system, the last 3 bits of the pointer store the tag let cleared = self.entry as usize & !0b111; - cleared as *const RocElemEntry - } - - // fn diff(self, other: RocElem, patches: &mut Vec<(usize, Patch)>, index: usize) { - // use RocElemTag::*; - - // let tag = self.tag(); - - // if tag != other.tag() { - // // They were totally different elem types! - - // // TODO should we handle Row -> Col or Col -> Row differently? - // // Elm doesn't: https://github.com/elm/virtual-dom/blob/5a5bcf48720bc7d53461b3cd42a9f19f119c5503/src/Elm/Kernel/VirtualDom.js#L714 - // return; - // } - - // match tag { - // Button => unsafe { - // let button_self = &*self.entry().button; - // let button_other = &*other.entry().button; - - // // TODO compute a diff and patch for the button - // }, - // Text => unsafe { - // let str_self = &*self.entry().text; - // let str_other = &*other.entry().text; - - // if str_self != str_other { - // todo!("fix this"); - // // let roc_str = other.entry().text; - // // let patch = Patch::Text(ManuallyDrop::into_inner(roc_str)); - - // // patches.push((index, patch)); - // } - // }, - // Row => unsafe { - // let children_self = &self.entry().row_or_col.children; - // let children_other = &other.entry().row_or_col.children; - - // // TODO diff children - // }, - // Col => unsafe { - // let children_self = &self.entry().row_or_col.children; - // let children_other = &other.entry().row_or_col.children; - - // // TODO diff children - // }, - // } - // } - - #[allow(unused)] - pub fn is_focusable(&self) -> bool { - use RocElemTag::*; - - match self.tag() { - Button => true, - Text | Row | Col => false, - } - } - - #[allow(unused)] - pub fn row>>(children: T) -> RocElem { - Self::elem_from_tag(Self::row_or_col(children), RocElemTag::Row) - } - - #[allow(unused)] - pub fn col>>(children: T) -> RocElem { - Self::elem_from_tag(Self::row_or_col(children), RocElemTag::Col) - } - - fn row_or_col>>(children: T) -> RocElemEntry { - let row_or_col = RocRowOrCol { - children: children.into(), - }; - RocElemEntry { - row_or_col: ManuallyDrop::new(row_or_col), - } - } - - #[allow(unused)] - pub fn button(styles: ButtonStyles, child: RocElem) -> RocElem { - let button = RocButton { - child: ManuallyDrop::new(child), - styles, - }; - let entry = RocElemEntry { - button: ManuallyDrop::new(button), - }; - - Self::elem_from_tag(entry, RocElemTag::Button) - } - - #[allow(unused)] - pub fn text>(into_roc_str: T) -> RocElem { - let entry = RocElemEntry { - text: ManuallyDrop::new(into_roc_str.into()), - }; - - Self::elem_from_tag(entry, RocElemTag::Text) - } - - fn elem_from_tag(entry: RocElemEntry, tag: RocElemTag) -> Self { - let tagged_ptr = unsafe { - let entry_ptr = roc_alloc( - core::mem::size_of_val(&entry), - core::mem::align_of_val(&entry) as u32, - ) as *mut RocElemEntry; - - *entry_ptr = entry; - - entry_ptr as usize | tag as usize - }; - - Self { - entry: tagged_ptr as *const RocElemEntry, - } + unsafe { &*(cleared as *const RocElemEntry) } } } #[repr(u8)] #[allow(unused)] // This is actually used, just via a mem::transmute from u8 -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy)] pub enum RocElemTag { Button = 0, Col, @@ -262,7 +80,6 @@ pub enum RocElemTag { } #[repr(C)] -#[derive(Debug)] pub struct RocButton { pub child: ManuallyDrop, pub styles: ButtonStyles, @@ -317,7 +134,7 @@ unsafe impl ReferenceCount for RocElem { } #[repr(C)] -#[derive(Copy, Clone, Debug, Default)] +#[derive(Copy, Clone, Debug)] pub struct ButtonStyles { pub bg_color: Rgba, pub border_color: Rgba, @@ -331,70 +148,3 @@ pub union RocElemEntry { pub text: ManuallyDrop, pub row_or_col: ManuallyDrop, } - -// enum Patch { -// Text(RocStr), -// } - -#[test] -fn make_text() { - let text = RocElem::text("blah"); - - assert_eq!(text.tag(), RocElemTag::Text); -} - -#[test] -fn make_button() { - let text = RocElem::text("blah"); - let button = RocElem::button(ButtonStyles::default(), text); - - assert_eq!(button.tag(), RocElemTag::Button); -} - -#[test] -fn make_row_with_text() { - let text = RocElem::text(""); - let row = RocElem::row(&[text] as &[_]); - - assert_eq!(row.tag(), RocElemTag::Row); -} - -#[test] -fn make_row_with_button() { - let text = RocElem::text(""); - let button = RocElem::button(ButtonStyles::default(), text); - let row = RocElem::row(&[button] as &[_]); - - assert_eq!(row.tag(), RocElemTag::Row); -} - -pub fn app_render(state: State) -> RocElem { - let size = unsafe { roc_program_size() } as usize; - let layout = Layout::array::(size).unwrap(); - - unsafe { - roc_program(); - - // TODO allocate on the stack if it's under a certain size - let buffer = std::alloc::alloc(layout); - - // Call the program's render function - let result = call_the_closure(state, buffer); - - std::alloc::dealloc(buffer, layout); - - result - } -} - -unsafe fn call_the_closure(state: State, closure_data_ptr: *const u8) -> RocElem { - let size = size_Render_result() as usize; - let layout = Layout::array::(size).unwrap(); - let buffer = std::alloc::alloc(layout) as *mut u8; - - let answer = call_Render(&state, closure_data_ptr as *const u8, buffer as *mut u8); - - std::alloc::dealloc(buffer, layout); - - answer -} From 6f635cf4f3f5f1e0c772f9277db98375035c98e4 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 14 Apr 2022 08:21:51 -0400 Subject: [PATCH 228/846] Give breakout a build.rs --- examples/breakout/platform/build.rs | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 examples/breakout/platform/build.rs diff --git a/examples/breakout/platform/build.rs b/examples/breakout/platform/build.rs new file mode 100644 index 0000000000..73159e387c --- /dev/null +++ b/examples/breakout/platform/build.rs @@ -0,0 +1,4 @@ +fn main() { + println!("cargo:rustc-link-lib=dylib=app"); + println!("cargo:rustc-link-search=."); +} From 8f906826fcfac66734bdc47412ac2c2b532f179a Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 14 Apr 2022 08:57:32 -0400 Subject: [PATCH 229/846] Include parent ability in specialization tests --- compiler/solve/tests/solve_expr.rs | 33 +++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index 36a1220d9e..cf822538a2 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -186,19 +186,27 @@ mod solve_expr { use std::collections::HashSet; let pretty_specializations = known_specializations .into_iter() - .map(|(typ, member)| { + .map(|(member, typ)| { + let member_data = abilities_store.member_def(member).unwrap(); + let member_str = member.ident_str(&interns).as_str(); + let ability_str = member_data.parent_ability.ident_str(&interns).as_str(); ( + format!("{}:{}", ability_str, member_str), typ.ident_str(&interns).as_str(), - member.ident_str(&interns).as_str(), ) }) .collect::>(); - for expected_spec in expected_specializations.into_iter() { + for (parent, specialization) in expected_specializations.into_iter() { + let has_the_one = pretty_specializations + .iter() + // references are annoying so we do this + .find(|(p, s)| p == parent && s == &specialization) + .is_some(); assert!( - pretty_specializations.contains(&expected_spec), + has_the_one, "{:#?} not in {:#?}", - expected_spec, + (parent, specialization), pretty_specializations, ); } @@ -5788,7 +5796,7 @@ mod solve_expr { hash = \$Id n -> n "# ), - [("hash", "Id")], + [("Hash:hash", "Id")], ) } @@ -5809,7 +5817,7 @@ mod solve_expr { hash32 = \$Id n -> Num.toU32 n "# ), - [("hash", "Id"), ("hash32", "Id")], + [("Hash:hash", "Id"), ("Hash:hash32", "Id")], ) } @@ -5837,7 +5845,12 @@ mod solve_expr { le = \$Id m, $Id n -> m < n "# ), - [("hash", "Id"), ("hash32", "Id"), ("eq", "Id"), ("le", "Id")], + [ + ("Hash:hash", "Id"), + ("Hash:hash32", "Id"), + ("Ord:eq", "Id"), + ("Ord:le", "Id"), + ], ) } @@ -5857,7 +5870,7 @@ mod solve_expr { hash = \$Id n -> n "# ), - [("hash", "Id")], + [("Hash:hash", "Id")], ) } @@ -5876,7 +5889,7 @@ mod solve_expr { hash : Id -> U64 "# ), - [("hash", "Id")], + [("Hash:hash", "Id")], ) } From ff3f54b3eb8a7491a24d0bc6b66ef3a0bddd36c4 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 14 Apr 2022 08:59:41 -0400 Subject: [PATCH 230/846] Bugfix report message --- reporting/src/error/type.rs | 2 +- reporting/tests/test_reporting.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/reporting/src/error/type.rs b/reporting/src/error/type.rs index 1735b01607..e4723a0de2 100644 --- a/reporting/src/error/type.rs +++ b/reporting/src/error/type.rs @@ -135,7 +135,7 @@ pub fn type_problem<'b>( let snippet = alloc.region(lines.convert_region(region)); let mut stack = vec![ alloc.text( - "This expression has a type does not implement the abilities it's expected to:", + "This expression has a type that does not implement the abilities it's expected to:", ), snippet, lone_type( diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 99cbc3d710..6b7d822835 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -9755,7 +9755,7 @@ I need all branches in an `if` to have the same type! ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── - This expression has a type does not implement the abilities it's expected to: + This expression has a type that does not implement the abilities it's expected to: 14│ nope: hash ($User {}), ^^^^^^^^ From 3c03b7004cc3e2ee6539eceb06951808d6c26c49 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 14 Apr 2022 09:31:26 -0400 Subject: [PATCH 231/846] Test for outdented list parse --- .../pass/outdented_list.expr.result-ast | 43 +++++++++++++++++++ .../snapshots/pass/outdented_list.expr.roc | 4 ++ 2 files changed, 47 insertions(+) create mode 100644 compiler/parse/tests/snapshots/pass/outdented_list.expr.result-ast create mode 100644 compiler/parse/tests/snapshots/pass/outdented_list.expr.roc diff --git a/compiler/parse/tests/snapshots/pass/outdented_list.expr.result-ast b/compiler/parse/tests/snapshots/pass/outdented_list.expr.result-ast new file mode 100644 index 0000000000..d7db49650a --- /dev/null +++ b/compiler/parse/tests/snapshots/pass/outdented_list.expr.result-ast @@ -0,0 +1,43 @@ +Defs( + [ + @0-17 Value( + Body( + @0-1 Identifier( + "a", + ), + @4-17 List( + Collection { + items: [ + @8-9 SpaceBefore( + Num( + "1", + ), + [ + Newline, + ], + ), + @11-12 Num( + "2", + ), + @14-15 Num( + "3", + ), + ], + final_comments: [ + Newline, + ], + }, + ), + ), + ), + ], + @18-19 SpaceBefore( + Var { + module_name: "", + ident: "a", + }, + [ + Newline, + ], + ), +) diff --git a/compiler/parse/tests/snapshots/pass/outdented_list.expr.roc b/compiler/parse/tests/snapshots/pass/outdented_list.expr.roc new file mode 100644 index 0000000000..d5ae4d79bc --- /dev/null +++ b/compiler/parse/tests/snapshots/pass/outdented_list.expr.roc @@ -0,0 +1,4 @@ +a = [ + 1, 2, 3 +] +a From 0c21821b044dc3d2fc0ac3b5e77d97890b6d9276 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 14 Apr 2022 09:31:55 -0400 Subject: [PATCH 232/846] Make sure outdented records parse --- compiler/parse/src/expr.rs | 9 ++-- .../pass/outdented_record.expr.result-ast | 51 +++++++++++++++++++ .../snapshots/pass/outdented_record.expr.roc | 4 ++ compiler/parse/tests/test_parse.rs | 2 + 4 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 compiler/parse/tests/snapshots/pass/outdented_record.expr.result-ast create mode 100644 compiler/parse/tests/snapshots/pass/outdented_record.expr.roc diff --git a/compiler/parse/src/expr.rs b/compiler/parse/src/expr.rs index 1c6256bdfe..4d0654b31f 100644 --- a/compiler/parse/src/expr.rs +++ b/compiler/parse/src/expr.rs @@ -2,7 +2,9 @@ use crate::ast::{ AssignedField, Collection, CommentOrNewline, Def, Expr, ExtractSpaces, Has, Pattern, Spaceable, TypeAnnotation, TypeDef, TypeHeader, ValueDef, }; -use crate::blankspace::{space0_after_e, space0_around_ee, space0_before_e, space0_e}; +use crate::blankspace::{ + space0_after_e, space0_around_ee, space0_before_e, space0_before_optional_after, space0_e, +}; use crate::ident::{lowercase_ident, parse_ident, Ident}; use crate::keyword; use crate::parser::{ @@ -2591,14 +2593,15 @@ fn record_help<'a>( and!( trailing_sep_by0( word1(b',', ERecord::End), - space0_around_ee( + space0_before_optional_after( loc!(record_field_help(min_indent)), min_indent, ERecord::IndentEnd, ERecord::IndentEnd ), ), - space0_e(min_indent, ERecord::IndentEnd) + // Allow outdented closing braces + space0_e(0, ERecord::IndentEnd) ), word1(b'}', ERecord::End) ) diff --git a/compiler/parse/tests/snapshots/pass/outdented_record.expr.result-ast b/compiler/parse/tests/snapshots/pass/outdented_record.expr.result-ast new file mode 100644 index 0000000000..119d0dc5be --- /dev/null +++ b/compiler/parse/tests/snapshots/pass/outdented_record.expr.result-ast @@ -0,0 +1,51 @@ +Defs( + [ + @0-23 Value( + Body( + @0-1 Identifier( + "x", + ), + @4-23 Apply( + @4-7 Var { + module_name: "", + ident: "foo", + }, + [ + @8-23 Record( + Collection { + items: [ + @12-21 SpaceBefore( + RequiredValue( + @12-15 "bar", + [], + @17-21 Var { + module_name: "", + ident: "blah", + }, + ), + [ + Newline, + ], + ), + ], + final_comments: [ + Newline, + ], + }, + ), + ], + Space, + ), + ), + ), + ], + @24-25 SpaceBefore( + Var { + module_name: "", + ident: "x", + }, + [ + Newline, + ], + ), +) diff --git a/compiler/parse/tests/snapshots/pass/outdented_record.expr.roc b/compiler/parse/tests/snapshots/pass/outdented_record.expr.roc new file mode 100644 index 0000000000..b344f9df89 --- /dev/null +++ b/compiler/parse/tests/snapshots/pass/outdented_record.expr.roc @@ -0,0 +1,4 @@ +x = foo { + bar: blah +} +x diff --git a/compiler/parse/tests/test_parse.rs b/compiler/parse/tests/test_parse.rs index 522c89c7c6..7b78187826 100644 --- a/compiler/parse/tests/test_parse.rs +++ b/compiler/parse/tests/test_parse.rs @@ -218,6 +218,8 @@ mod test_parse { pass/opaque_reference_pattern.expr, pass/opaque_reference_pattern_with_arguments.expr, pass/ops_with_newlines.expr, + pass/outdented_list.expr, + pass/outdented_record.expr, pass/packed_singleton_list.expr, pass/parenthetical_apply.expr, pass/parenthetical_basic_field.expr, From 362ca1d914bc0cba5750009e2c3149f2f63993ae Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 14 Apr 2022 10:44:07 -0400 Subject: [PATCH 233/846] Fix parse tests --- .../outdented_app_with_record.expr.result-ast | 62 +++++++++++++++++++ .../pass/outdented_app_with_record.expr.roc | 4 ++ compiler/parse/tests/test_parse.rs | 1 + 3 files changed, 67 insertions(+) create mode 100644 compiler/parse/tests/snapshots/pass/outdented_app_with_record.expr.result-ast create mode 100644 compiler/parse/tests/snapshots/pass/outdented_app_with_record.expr.roc diff --git a/compiler/parse/tests/snapshots/pass/outdented_app_with_record.expr.result-ast b/compiler/parse/tests/snapshots/pass/outdented_app_with_record.expr.result-ast new file mode 100644 index 0000000000..4df43e0d86 --- /dev/null +++ b/compiler/parse/tests/snapshots/pass/outdented_app_with_record.expr.result-ast @@ -0,0 +1,62 @@ +Defs( + [ + @0-29 Value( + Body( + @0-1 Identifier( + "x", + ), + @4-29 Apply( + @4-7 Var { + module_name: "", + ident: "foo", + }, + [ + @9-28 ParensAround( + Apply( + @9-12 Var { + module_name: "", + ident: "baz", + }, + [ + @13-28 Record( + Collection { + items: [ + @17-26 SpaceBefore( + RequiredValue( + @17-20 "bar", + [], + @22-26 Var { + module_name: "", + ident: "blah", + }, + ), + [ + Newline, + ], + ), + ], + final_comments: [ + Newline, + ], + }, + ), + ], + Space, + ), + ), + ], + Space, + ), + ), + ), + ], + @30-31 SpaceBefore( + Var { + module_name: "", + ident: "x", + }, + [ + Newline, + ], + ), +) diff --git a/compiler/parse/tests/snapshots/pass/outdented_app_with_record.expr.roc b/compiler/parse/tests/snapshots/pass/outdented_app_with_record.expr.roc new file mode 100644 index 0000000000..2f87899d3e --- /dev/null +++ b/compiler/parse/tests/snapshots/pass/outdented_app_with_record.expr.roc @@ -0,0 +1,4 @@ +x = foo (baz { + bar: blah +}) +x diff --git a/compiler/parse/tests/test_parse.rs b/compiler/parse/tests/test_parse.rs index 7b78187826..759276523c 100644 --- a/compiler/parse/tests/test_parse.rs +++ b/compiler/parse/tests/test_parse.rs @@ -220,6 +220,7 @@ mod test_parse { pass/ops_with_newlines.expr, pass/outdented_list.expr, pass/outdented_record.expr, + pass/outdented_app_with_record.expr, pass/packed_singleton_list.expr, pass/parenthetical_apply.expr, pass/parenthetical_basic_field.expr, From dc2d9ceeac1dda2ee9bae9e84b72b41ae51ffc4a Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 14 Apr 2022 10:43:53 -0400 Subject: [PATCH 234/846] Detect outdents too far --- compiler/parse/src/expr.rs | 84 ++++++++++++++++++++------- compiler/parse/src/module.rs | 26 +++++++++ compiler/parse/src/parser.rs | 18 ++++-- compiler/parse/src/pattern.rs | 2 + compiler/parse/src/type_annotation.rs | 4 ++ reporting/src/error/parse.rs | 84 ++++++++++++++++++++++----- reporting/tests/test_reporting.rs | 61 +++++++++++++++++++ 7 files changed, 238 insertions(+), 41 deletions(-) diff --git a/compiler/parse/src/expr.rs b/compiler/parse/src/expr.rs index 4d0654b31f..fbc57d27f8 100644 --- a/compiler/parse/src/expr.rs +++ b/compiler/parse/src/expr.rs @@ -190,6 +190,7 @@ fn record_field_access<'a>() -> impl Parser<'a, &'a str, EExpr<'a>> { /// pattern later fn parse_loc_term_or_underscore<'a>( min_indent: u32, + outdent_col: u32, options: ExprParseOptions, arena: &'a Bump, state: State<'a>, @@ -201,8 +202,11 @@ fn parse_loc_term_or_underscore<'a>( loc!(specialize(EExpr::Number, positive_number_literal_help())), loc!(specialize(EExpr::Lambda, closure_help(min_indent, options))), loc!(underscore_expression()), - loc!(record_literal_help(min_indent)), - loc!(specialize(EExpr::List, list_literal_help(min_indent))), + loc!(record_literal_help(min_indent, outdent_col)), + loc!(specialize( + EExpr::List, + list_literal_help(min_indent, outdent_col) + )), loc!(map_with_arena!( assign_or_destructure_identifier(), ident_to_expr @@ -213,6 +217,7 @@ fn parse_loc_term_or_underscore<'a>( fn parse_loc_term<'a>( min_indent: u32, + outdent_col: u32, options: ExprParseOptions, arena: &'a Bump, state: State<'a>, @@ -223,8 +228,11 @@ fn parse_loc_term<'a>( loc!(specialize(EExpr::SingleQuote, single_quote_literal_help())), loc!(specialize(EExpr::Number, positive_number_literal_help())), loc!(specialize(EExpr::Lambda, closure_help(min_indent, options))), - loc!(record_literal_help(min_indent)), - loc!(specialize(EExpr::List, list_literal_help(min_indent))), + loc!(record_literal_help(min_indent, outdent_col)), + loc!(specialize( + EExpr::List, + list_literal_help(min_indent, outdent_col) + )), loc!(map_with_arena!( assign_or_destructure_identifier(), ident_to_expr @@ -252,6 +260,7 @@ fn underscore_expression<'a>() -> impl Parser<'a, Expr<'a>, EExpr<'a>> { fn loc_possibly_negative_or_negated_term<'a>( min_indent: u32, + outdent_col: u32, options: ExprParseOptions, ) -> impl Parser<'a, Loc>, EExpr<'a>> { one_of![ @@ -259,7 +268,11 @@ fn loc_possibly_negative_or_negated_term<'a>( let initial = state.clone(); let (_, (loc_op, loc_expr), state) = and!(loc!(unary_negate()), |a, s| parse_loc_term( - min_indent, options, a, s + min_indent, + outdent_col, + options, + a, + s )) .parse(arena, state)?; @@ -271,13 +284,15 @@ fn loc_possibly_negative_or_negated_term<'a>( loc!(specialize(EExpr::Number, number_literal_help())), loc!(map_with_arena!( and!(loc!(word1(b'!', EExpr::Start)), |a, s| { - parse_loc_term(min_indent, options, a, s) + parse_loc_term(min_indent, outdent_col, options, a, s) }), |arena: &'a Bump, (loc_op, loc_expr): (Loc<_>, _)| { Expr::UnaryOp(arena.alloc(loc_expr), Loc::at(loc_op.region, UnaryOp::Not)) } )), - |arena, state| { parse_loc_term_or_underscore(min_indent, options, arena, state) } + |arena, state| { + parse_loc_term_or_underscore(min_indent, outdent_col, options, arena, state) + } ] } @@ -336,8 +351,8 @@ fn parse_expr_operator_chain<'a>( arena: &'a Bump, state: State<'a>, ) -> ParseResult<'a, Expr<'a>, EExpr<'a>> { - let (_, expr, state) = - loc_possibly_negative_or_negated_term(min_indent, options).parse(arena, state)?; + let (_, expr, state) = loc_possibly_negative_or_negated_term(min_indent, start_column, options) + .parse(arena, state)?; let initial = state.clone(); let end = state.pos(); @@ -1333,7 +1348,8 @@ fn parse_expr_operator<'a>( BinOp::Minus if expr_state.end != op_start && op_end == new_start => { // negative terms - let (_, negated_expr, state) = parse_loc_term(min_indent, options, arena, state)?; + let (_, negated_expr, state) = + parse_loc_term(min_indent, start_column, options, arena, state)?; let new_end = state.pos(); let arg = numeric_negate_expression( @@ -1467,7 +1483,9 @@ fn parse_expr_operator<'a>( _ => unreachable!(), }, ), - _ => match loc_possibly_negative_or_negated_term(min_indent, options).parse(arena, state) { + _ => match loc_possibly_negative_or_negated_term(min_indent, start_column, options) + .parse(arena, state) + { Err((MadeProgress, f, s)) => Err((MadeProgress, f, s)), Ok((_, mut new_expr, state)) => { let new_end = state.pos(); @@ -1526,7 +1544,7 @@ fn parse_expr_end<'a>( ) -> ParseResult<'a, Expr<'a>, EExpr<'a>> { let parser = skip_first!( crate::blankspace::check_indent(min_indent, EExpr::IndentEnd), - move |a, s| parse_loc_term(min_indent, options, a, s) + move |a, s| parse_loc_term(min_indent, start_column, options, a, s) ); match parser.parse(arena, state.clone()) { @@ -2467,7 +2485,10 @@ fn ident_to_expr<'a>(arena: &'a Bump, src: Ident<'a>) -> Expr<'a> { } } -fn list_literal_help<'a>(min_indent: u32) -> impl Parser<'a, Expr<'a>, EList<'a>> { +fn list_literal_help<'a>( + min_indent: u32, + outdent_col: u32, +) -> impl Parser<'a, Expr<'a>, EList<'a>> { move |arena, state| { let (_, elements, state) = collection_trailing_sep_e!( word1(b'[', EList::Open), @@ -2478,8 +2499,10 @@ fn list_literal_help<'a>(min_indent: u32) -> impl Parser<'a, Expr<'a>, EList<'a> word1(b',', EList::End), word1(b']', EList::End), min_indent, + outdent_col, EList::Open, EList::IndentEnd, + EList::OutdentEnd, Expr::SpaceBefore ) .parse(arena, state)?; @@ -2555,6 +2578,7 @@ fn record_updateable_identifier<'a>() -> impl Parser<'a, Expr<'a>, ERecord<'a>> fn record_help<'a>( min_indent: u32, + outdent_col: u32, ) -> impl Parser< 'a, ( @@ -2589,8 +2613,8 @@ fn record_help<'a>( // `{ }` can be successfully parsed as an empty record, and then // changed by the formatter back into `{}`. zero_or_more!(word1(b' ', ERecord::End)), - skip_second!( - and!( + |arena, state| { + let (_, (parsed_elems, comments), state) = and!( trailing_sep_by0( word1(b',', ERecord::End), space0_before_optional_after( @@ -2600,19 +2624,35 @@ fn record_help<'a>( ERecord::IndentEnd ), ), - // Allow outdented closing braces - space0_e(0, ERecord::IndentEnd) - ), - word1(b'}', ERecord::End) - ) + space0_e(0, ERecord::OutdentEnd) + ) + .parse(arena, state)?; + + let closing_brace_col = state.column(); + let closing_brace_pos = state.pos(); + + let (_, _, state) = word1(b'}', ERecord::End).parse(arena, state)?; + + if closing_brace_col < outdent_col { + return Err((MadeProgress, ERecord::OutdentEnd(closing_brace_pos), state)); + } + + Ok((MadeProgress, (parsed_elems, comments), state)) + } )) ) ) } -fn record_literal_help<'a>(min_indent: u32) -> impl Parser<'a, Expr<'a>, EExpr<'a>> { +fn record_literal_help<'a>( + min_indent: u32, + outdent_col: u32, +) -> impl Parser<'a, Expr<'a>, EExpr<'a>> { then( - loc!(specialize(EExpr::Record, record_help(min_indent))), + loc!(specialize( + EExpr::Record, + record_help(min_indent, outdent_col) + )), move |arena, state, _, loc_record| { let (opt_update, loc_assigned_fields_with_comments) = loc_record.value; diff --git a/compiler/parse/src/module.rs b/compiler/parse/src/module.rs index b1e43773f5..c2a6366dd3 100644 --- a/compiler/parse/src/module.rs +++ b/compiler/parse/src/module.rs @@ -416,6 +416,7 @@ fn provides_without_to<'a>() -> impl Parser< EProvides<'a>, > { let min_indent = 1; + let outdent_col = 0; and!( spaces_around_keyword( min_indent, @@ -431,8 +432,10 @@ fn provides_without_to<'a>() -> impl Parser< word1(b',', EProvides::ListEnd), word1(b']', EProvides::ListEnd), min_indent, + outdent_col, EProvides::Open, EProvides::IndentListEnd, + EProvides::IndentListEnd, Spaced::SpaceBefore ), // Optionally @@ -445,6 +448,7 @@ fn provides_without_to<'a>() -> impl Parser< fn provides_types<'a>( ) -> impl Parser<'a, Collection<'a, Loc>>>, EProvides<'a>> { let min_indent = 1; + let outdent_col = 0; skip_first!( // We only support spaces here, not newlines, because this is not intended @@ -464,8 +468,10 @@ fn provides_types<'a>( word1(b',', EProvides::ListEnd), word1(b'}', EProvides::ListEnd), min_indent, + outdent_col, EProvides::Open, EProvides::IndentListEnd, + EProvides::IndentListEnd, Spaced::SpaceBefore ) ) @@ -545,8 +551,10 @@ fn requires_rigids<'a>( word1(b',', ERequires::ListEnd), word1(b'}', ERequires::ListEnd), min_indent, + 0, ERequires::Open, ERequires::IndentListEnd, + ERequires::IndentListEnd, Spaced::SpaceBefore ) } @@ -577,6 +585,7 @@ fn exposes_values<'a>() -> impl Parser< EExposes, > { let min_indent = 1; + let outdent_col = 0; and!( spaces_around_keyword( @@ -592,8 +601,10 @@ fn exposes_values<'a>() -> impl Parser< word1(b',', EExposes::ListEnd), word1(b']', EExposes::ListEnd), min_indent, + outdent_col, EExposes::Open, EExposes::IndentListEnd, + EExposes::IndentListEnd, Spaced::SpaceBefore ) ) @@ -628,6 +639,7 @@ fn exposes_modules<'a>() -> impl Parser< EExposes, > { let min_indent = 1; + let outdent_col = 0; and!( spaces_around_keyword( @@ -643,8 +655,10 @@ fn exposes_modules<'a>() -> impl Parser< word1(b',', EExposes::ListEnd), word1(b']', EExposes::ListEnd), min_indent, + outdent_col, EExposes::Open, EExposes::IndentListEnd, + EExposes::IndentListEnd, Spaced::SpaceBefore ) ) @@ -674,6 +688,7 @@ struct Packages<'a> { #[inline(always)] fn packages<'a>() -> impl Parser<'a, Packages<'a>, EPackages<'a>> { let min_indent = 1; + let outdent_col = 0; map!( and!( @@ -690,8 +705,10 @@ fn packages<'a>() -> impl Parser<'a, Packages<'a>, EPackages<'a>> { word1(b',', EPackages::ListEnd), word1(b'}', EPackages::ListEnd), min_indent, + outdent_col, EPackages::Open, EPackages::IndentListEnd, + EPackages::IndentListEnd, Spaced::SpaceBefore ) ), @@ -741,6 +758,7 @@ fn generates_with<'a>() -> impl Parser< EGeneratesWith, > { let min_indent = 1; + let outdent_col = 0; and!( spaces_around_keyword( @@ -756,8 +774,10 @@ fn generates_with<'a>() -> impl Parser< word1(b',', EGeneratesWith::ListEnd), word1(b']', EGeneratesWith::ListEnd), min_indent, + outdent_col, EGeneratesWith::Open, EGeneratesWith::IndentListEnd, + EGeneratesWith::IndentListEnd, Spaced::SpaceBefore ) ) @@ -773,6 +793,7 @@ fn imports<'a>() -> impl Parser< EImports, > { let min_indent = 1; + let outdent_col = 0; and!( spaces_around_keyword( @@ -788,8 +809,10 @@ fn imports<'a>() -> impl Parser< word1(b',', EImports::ListEnd), word1(b']', EImports::ListEnd), min_indent, + outdent_col, EImports::Open, EImports::IndentListEnd, + EImports::IndentListEnd, Spaced::SpaceBefore ) ) @@ -849,6 +872,7 @@ where #[inline(always)] fn imports_entry<'a>() -> impl Parser<'a, Spaced<'a, ImportsEntry<'a>>, EImports> { let min_indent = 1; + let outdent_col = 0; type Temp<'a> = ( (Option<&'a str>, ModuleName<'a>), @@ -875,8 +899,10 @@ fn imports_entry<'a>() -> impl Parser<'a, Spaced<'a, ImportsEntry<'a>>, EImports word1(b',', EImports::SetEnd), word1(b'}', EImports::SetEnd), min_indent, + outdent_col, EImports::Open, EImports::IndentSetEnd, + EImports::IndentSetEnd, Spaced::SpaceBefore ) )) diff --git a/compiler/parse/src/parser.rs b/compiler/parse/src/parser.rs index 3c25922ba9..6edeaa3cdd 100644 --- a/compiler/parse/src/parser.rs +++ b/compiler/parse/src/parser.rs @@ -407,6 +407,7 @@ pub enum ERecord<'a> { IndentBar(Position), IndentAmpersand(Position), IndentEnd(Position), + OutdentEnd(Position), } #[derive(Debug, Clone, PartialEq, Eq)] @@ -448,6 +449,7 @@ pub enum EList<'a> { IndentOpen(Position), IndentEnd(Position), + OutdentEnd(Position), } #[derive(Debug, Clone, PartialEq, Eq)] @@ -1211,7 +1213,7 @@ macro_rules! collection { #[macro_export] macro_rules! collection_trailing_sep_e { - ($opening_brace:expr, $elem:expr, $delimiter:expr, $closing_brace:expr, $min_indent:expr, $open_problem:expr, $indent_problem:expr, $space_before:expr) => { + ($opening_brace:expr, $elem:expr, $delimiter:expr, $closing_brace:expr, $min_indent:expr, $outdent_col:expr, $open_problem:expr, $indent_problem:expr, $outdent_problem:expr, $space_before:expr) => { skip_first!( $opening_brace, |arena, state| { @@ -1230,12 +1232,13 @@ macro_rules! collection_trailing_sep_e { ) ), $crate::blankspace::space0_e( - // we use min_indent=0 because we want to parse incorrectly indented closing braces - // and later fix these up in the formatter. - 0 /* min_indent */, + 0, $indent_problem) ).parse(arena, state)?; + let closing_brace_col = state.column(); + let closing_brace_pos = state.pos(); + let (_,_, state) = if parsed_elems.is_empty() { one_of_with_error![$open_problem; $closing_brace].parse(arena, state)? @@ -1243,6 +1246,13 @@ macro_rules! collection_trailing_sep_e { $closing_brace.parse(arena, state)? }; + #[allow(unused_comparisons)] // sometimes $outdent_col is 0 + if closing_brace_col < $outdent_col { + // We successfully parsed the collection but the closing brace was outdented + // further than expected. + return Err((MadeProgress, $outdent_problem(closing_brace_pos), state)); + } + if !spaces.is_empty() { if let Some(first) = parsed_elems.first_mut() { first.value = $space_before(arena.alloc(first.value), spaces) diff --git a/compiler/parse/src/pattern.rs b/compiler/parse/src/pattern.rs index 09e676075f..c2ec96fcf1 100644 --- a/compiler/parse/src/pattern.rs +++ b/compiler/parse/src/pattern.rs @@ -365,8 +365,10 @@ fn record_pattern_help<'a>(min_indent: u32) -> impl Parser<'a, Pattern<'a>, PRec // word1_check_indent!(b'}', PRecord::End, min_indent, PRecord::IndentEnd), word1(b'}', PRecord::End), min_indent, + 0, PRecord::Open, PRecord::IndentEnd, + PRecord::IndentEnd, Pattern::SpaceBefore ) .parse(arena, state)?; diff --git a/compiler/parse/src/type_annotation.rs b/compiler/parse/src/type_annotation.rs index 45b34b7157..02e52f774c 100644 --- a/compiler/parse/src/type_annotation.rs +++ b/compiler/parse/src/type_annotation.rs @@ -31,8 +31,10 @@ fn tag_union_type<'a>(min_indent: u32) -> impl Parser<'a, TypeAnnotation<'a>, ET word1(b',', ETypeTagUnion::End), word1(b']', ETypeTagUnion::End), min_indent, + 0, ETypeTagUnion::Open, ETypeTagUnion::IndentEnd, + ETypeTagUnion::IndentEnd, Tag::SpaceBefore ) .parse(arena, state)?; @@ -323,8 +325,10 @@ fn record_type<'a>(min_indent: u32) -> impl Parser<'a, TypeAnnotation<'a>, EType // word1_check_indent!(b'}', TRecord::End, min_indent, TRecord::IndentEnd), word1(b'}', ETypeRecord::End), min_indent, + 0, ETypeRecord::Open, ETypeRecord::IndentEnd, + ETypeRecord::IndentEnd, AssignedField::SpaceBefore ) .parse(arena, state)?; diff --git a/reporting/src/error/parse.rs b/reporting/src/error/parse.rs index 83b878a6c0..cb5a3e0b47 100644 --- a/reporting/src/error/parse.rs +++ b/reporting/src/error/parse.rs @@ -1,4 +1,4 @@ -use roc_parse::parser::{ENumber, FileError, SyntaxError}; +use roc_parse::parser::{ENumber, ERecord, FileError, SyntaxError}; use roc_region::all::{LineColumn, LineColumnRegion, LineInfo, Position, Region}; use std::path::PathBuf; @@ -516,23 +516,42 @@ fn to_expr_report<'a>( } } - EExpr::Record(_erecord, pos) => { - let surroundings = Region::new(start, *pos); - let region = LineColumnRegion::from_pos(lines.convert_pos(*pos)); + EExpr::Record(erecord, pos) => match erecord { + &ERecord::OutdentEnd(pos) => { + let surroundings = Region::new(start, pos); + let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ - alloc.reflow(r"I am partway through parsing an record, but I got stuck here:"), - alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![alloc.reflow("TODO provide more context.")]), - ]); + let doc = alloc.stack(vec![ + alloc.reflow(r"I found the end of this record, but it's outdented too far:"), + alloc.region_with_subregion(lines.convert_region(surroundings), region), + alloc.reflow(r"Did you mean to indent it further?"), + ]); - Report { - filename, - doc, - title: "RECORD PARSE PROBLEM".to_string(), - severity: Severity::RuntimeError, + Report { + filename, + doc, + title: "RECORD END OUDENTED TOO FAR".to_string(), + severity: Severity::RuntimeError, + } } - } + _ => { + let surroundings = Region::new(start, *pos); + let region = LineColumnRegion::from_pos(lines.convert_pos(*pos)); + + let doc = alloc.stack(vec![ + alloc.reflow(r"I am partway through parsing an record, but I got stuck here:"), + alloc.region_with_subregion(lines.convert_region(surroundings), region), + alloc.concat(vec![alloc.reflow("TODO provide more context.")]), + ]); + + Report { + filename, + doc, + title: "RECORD PARSE PROBLEM".to_string(), + severity: Severity::RuntimeError, + } + } + }, EExpr::Space(error, pos) => to_space_report(alloc, lines, filename, error, *pos), @@ -542,6 +561,23 @@ fn to_expr_report<'a>( EExpr::Ability(err, pos) => to_ability_def_report(alloc, lines, filename, err, *pos), + EExpr::IndentEnd(pos) => { + let surroundings = Region::new(start, *pos); + let region = LineColumnRegion::from_pos(lines.convert_pos(*pos)); + + let doc = alloc.stack(vec![ + alloc.reflow("Indentation unexpectedly ended here:"), + alloc.region_with_subregion(lines.convert_region(surroundings), region), + ]); + + Report { + filename, + doc, + title: "INDENTATION ENDED EARLY".to_string(), + // In an ideal world, this is recoverable and we keep parsing. + severity: Severity::Warning, + } + } _ => todo!("unhandled parse error: {:?}", parse_problem), } } @@ -1116,6 +1152,24 @@ fn to_list_report<'a>( severity: Severity::RuntimeError, } } + + EList::OutdentEnd(pos) => { + let surroundings = Region::new(start, pos); + let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); + + let doc = alloc.stack(vec![ + alloc.reflow(r"I found the end of this list, but it's outdented too far:"), + alloc.region_with_subregion(lines.convert_region(surroundings), region), + alloc.reflow(r"Did you mean to indent it further?"), + ]); + + Report { + filename, + doc, + title: "LIST END OUDENTED TOO FAR".to_string(), + severity: Severity::RuntimeError, + } + } } } diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 99cbc3d710..8eb035dea2 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -9780,4 +9780,65 @@ I need all branches in an `if` to have the same type! ), ) } + + #[test] + fn list_outdented_too_far() { + report_problem_as( + indoc!( + r#" + w = + a = [ + 1, 2, 3 + ] + a + w + "# + ), + indoc!( + r#" + ── LIST END OUDENTED TOO FAR ─────────────────────────────────────────────────── + + I found the end of this list, but it's outdented too far: + + 2│ a = [ + 3│ 1, 2, 3 + 4│ ] + ^ + + Did you mean to indent it further? + "# + ), + ) + } + + #[test] + fn record_outdented_too_far() { + report_problem_as( + indoc!( + r#" + w = + r = { + sweet: "disposition" + } + r + w + "# + ), + indoc!( + r#" + ── RECORD END OUDENTED TOO FAR ───────────────────────────────────────────────── + + I found the end of this record, but it's outdented too far: + + 1│ w = + 2│ r = { + 3│ sweet: "disposition" + 4│ } + ^ + + Did you mean to indent it further? + "# + ), + ) + } } From 233ea239793f6577ac3849bf4bf149e495a4c399 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 14 Apr 2022 10:45:12 -0400 Subject: [PATCH 235/846] Revert "Detect outdents too far" This reverts commit 1c2ca2e3f5ae12d114cc72970035caf937d6e413. --- compiler/parse/src/expr.rs | 84 +++++++-------------------- compiler/parse/src/module.rs | 26 --------- compiler/parse/src/parser.rs | 18 ++---- compiler/parse/src/pattern.rs | 2 - compiler/parse/src/type_annotation.rs | 4 -- compiler/parse/tests/test_parse.rs | 1 - reporting/src/error/parse.rs | 84 +++++---------------------- reporting/tests/test_reporting.rs | 61 ------------------- 8 files changed, 41 insertions(+), 239 deletions(-) diff --git a/compiler/parse/src/expr.rs b/compiler/parse/src/expr.rs index fbc57d27f8..4d0654b31f 100644 --- a/compiler/parse/src/expr.rs +++ b/compiler/parse/src/expr.rs @@ -190,7 +190,6 @@ fn record_field_access<'a>() -> impl Parser<'a, &'a str, EExpr<'a>> { /// pattern later fn parse_loc_term_or_underscore<'a>( min_indent: u32, - outdent_col: u32, options: ExprParseOptions, arena: &'a Bump, state: State<'a>, @@ -202,11 +201,8 @@ fn parse_loc_term_or_underscore<'a>( loc!(specialize(EExpr::Number, positive_number_literal_help())), loc!(specialize(EExpr::Lambda, closure_help(min_indent, options))), loc!(underscore_expression()), - loc!(record_literal_help(min_indent, outdent_col)), - loc!(specialize( - EExpr::List, - list_literal_help(min_indent, outdent_col) - )), + loc!(record_literal_help(min_indent)), + loc!(specialize(EExpr::List, list_literal_help(min_indent))), loc!(map_with_arena!( assign_or_destructure_identifier(), ident_to_expr @@ -217,7 +213,6 @@ fn parse_loc_term_or_underscore<'a>( fn parse_loc_term<'a>( min_indent: u32, - outdent_col: u32, options: ExprParseOptions, arena: &'a Bump, state: State<'a>, @@ -228,11 +223,8 @@ fn parse_loc_term<'a>( loc!(specialize(EExpr::SingleQuote, single_quote_literal_help())), loc!(specialize(EExpr::Number, positive_number_literal_help())), loc!(specialize(EExpr::Lambda, closure_help(min_indent, options))), - loc!(record_literal_help(min_indent, outdent_col)), - loc!(specialize( - EExpr::List, - list_literal_help(min_indent, outdent_col) - )), + loc!(record_literal_help(min_indent)), + loc!(specialize(EExpr::List, list_literal_help(min_indent))), loc!(map_with_arena!( assign_or_destructure_identifier(), ident_to_expr @@ -260,7 +252,6 @@ fn underscore_expression<'a>() -> impl Parser<'a, Expr<'a>, EExpr<'a>> { fn loc_possibly_negative_or_negated_term<'a>( min_indent: u32, - outdent_col: u32, options: ExprParseOptions, ) -> impl Parser<'a, Loc>, EExpr<'a>> { one_of![ @@ -268,11 +259,7 @@ fn loc_possibly_negative_or_negated_term<'a>( let initial = state.clone(); let (_, (loc_op, loc_expr), state) = and!(loc!(unary_negate()), |a, s| parse_loc_term( - min_indent, - outdent_col, - options, - a, - s + min_indent, options, a, s )) .parse(arena, state)?; @@ -284,15 +271,13 @@ fn loc_possibly_negative_or_negated_term<'a>( loc!(specialize(EExpr::Number, number_literal_help())), loc!(map_with_arena!( and!(loc!(word1(b'!', EExpr::Start)), |a, s| { - parse_loc_term(min_indent, outdent_col, options, a, s) + parse_loc_term(min_indent, options, a, s) }), |arena: &'a Bump, (loc_op, loc_expr): (Loc<_>, _)| { Expr::UnaryOp(arena.alloc(loc_expr), Loc::at(loc_op.region, UnaryOp::Not)) } )), - |arena, state| { - parse_loc_term_or_underscore(min_indent, outdent_col, options, arena, state) - } + |arena, state| { parse_loc_term_or_underscore(min_indent, options, arena, state) } ] } @@ -351,8 +336,8 @@ fn parse_expr_operator_chain<'a>( arena: &'a Bump, state: State<'a>, ) -> ParseResult<'a, Expr<'a>, EExpr<'a>> { - let (_, expr, state) = loc_possibly_negative_or_negated_term(min_indent, start_column, options) - .parse(arena, state)?; + let (_, expr, state) = + loc_possibly_negative_or_negated_term(min_indent, options).parse(arena, state)?; let initial = state.clone(); let end = state.pos(); @@ -1348,8 +1333,7 @@ fn parse_expr_operator<'a>( BinOp::Minus if expr_state.end != op_start && op_end == new_start => { // negative terms - let (_, negated_expr, state) = - parse_loc_term(min_indent, start_column, options, arena, state)?; + let (_, negated_expr, state) = parse_loc_term(min_indent, options, arena, state)?; let new_end = state.pos(); let arg = numeric_negate_expression( @@ -1483,9 +1467,7 @@ fn parse_expr_operator<'a>( _ => unreachable!(), }, ), - _ => match loc_possibly_negative_or_negated_term(min_indent, start_column, options) - .parse(arena, state) - { + _ => match loc_possibly_negative_or_negated_term(min_indent, options).parse(arena, state) { Err((MadeProgress, f, s)) => Err((MadeProgress, f, s)), Ok((_, mut new_expr, state)) => { let new_end = state.pos(); @@ -1544,7 +1526,7 @@ fn parse_expr_end<'a>( ) -> ParseResult<'a, Expr<'a>, EExpr<'a>> { let parser = skip_first!( crate::blankspace::check_indent(min_indent, EExpr::IndentEnd), - move |a, s| parse_loc_term(min_indent, start_column, options, a, s) + move |a, s| parse_loc_term(min_indent, options, a, s) ); match parser.parse(arena, state.clone()) { @@ -2485,10 +2467,7 @@ fn ident_to_expr<'a>(arena: &'a Bump, src: Ident<'a>) -> Expr<'a> { } } -fn list_literal_help<'a>( - min_indent: u32, - outdent_col: u32, -) -> impl Parser<'a, Expr<'a>, EList<'a>> { +fn list_literal_help<'a>(min_indent: u32) -> impl Parser<'a, Expr<'a>, EList<'a>> { move |arena, state| { let (_, elements, state) = collection_trailing_sep_e!( word1(b'[', EList::Open), @@ -2499,10 +2478,8 @@ fn list_literal_help<'a>( word1(b',', EList::End), word1(b']', EList::End), min_indent, - outdent_col, EList::Open, EList::IndentEnd, - EList::OutdentEnd, Expr::SpaceBefore ) .parse(arena, state)?; @@ -2578,7 +2555,6 @@ fn record_updateable_identifier<'a>() -> impl Parser<'a, Expr<'a>, ERecord<'a>> fn record_help<'a>( min_indent: u32, - outdent_col: u32, ) -> impl Parser< 'a, ( @@ -2613,8 +2589,8 @@ fn record_help<'a>( // `{ }` can be successfully parsed as an empty record, and then // changed by the formatter back into `{}`. zero_or_more!(word1(b' ', ERecord::End)), - |arena, state| { - let (_, (parsed_elems, comments), state) = and!( + skip_second!( + and!( trailing_sep_by0( word1(b',', ERecord::End), space0_before_optional_after( @@ -2624,35 +2600,19 @@ fn record_help<'a>( ERecord::IndentEnd ), ), - space0_e(0, ERecord::OutdentEnd) - ) - .parse(arena, state)?; - - let closing_brace_col = state.column(); - let closing_brace_pos = state.pos(); - - let (_, _, state) = word1(b'}', ERecord::End).parse(arena, state)?; - - if closing_brace_col < outdent_col { - return Err((MadeProgress, ERecord::OutdentEnd(closing_brace_pos), state)); - } - - Ok((MadeProgress, (parsed_elems, comments), state)) - } + // Allow outdented closing braces + space0_e(0, ERecord::IndentEnd) + ), + word1(b'}', ERecord::End) + ) )) ) ) } -fn record_literal_help<'a>( - min_indent: u32, - outdent_col: u32, -) -> impl Parser<'a, Expr<'a>, EExpr<'a>> { +fn record_literal_help<'a>(min_indent: u32) -> impl Parser<'a, Expr<'a>, EExpr<'a>> { then( - loc!(specialize( - EExpr::Record, - record_help(min_indent, outdent_col) - )), + loc!(specialize(EExpr::Record, record_help(min_indent))), move |arena, state, _, loc_record| { let (opt_update, loc_assigned_fields_with_comments) = loc_record.value; diff --git a/compiler/parse/src/module.rs b/compiler/parse/src/module.rs index c2a6366dd3..b1e43773f5 100644 --- a/compiler/parse/src/module.rs +++ b/compiler/parse/src/module.rs @@ -416,7 +416,6 @@ fn provides_without_to<'a>() -> impl Parser< EProvides<'a>, > { let min_indent = 1; - let outdent_col = 0; and!( spaces_around_keyword( min_indent, @@ -432,10 +431,8 @@ fn provides_without_to<'a>() -> impl Parser< word1(b',', EProvides::ListEnd), word1(b']', EProvides::ListEnd), min_indent, - outdent_col, EProvides::Open, EProvides::IndentListEnd, - EProvides::IndentListEnd, Spaced::SpaceBefore ), // Optionally @@ -448,7 +445,6 @@ fn provides_without_to<'a>() -> impl Parser< fn provides_types<'a>( ) -> impl Parser<'a, Collection<'a, Loc>>>, EProvides<'a>> { let min_indent = 1; - let outdent_col = 0; skip_first!( // We only support spaces here, not newlines, because this is not intended @@ -468,10 +464,8 @@ fn provides_types<'a>( word1(b',', EProvides::ListEnd), word1(b'}', EProvides::ListEnd), min_indent, - outdent_col, EProvides::Open, EProvides::IndentListEnd, - EProvides::IndentListEnd, Spaced::SpaceBefore ) ) @@ -551,10 +545,8 @@ fn requires_rigids<'a>( word1(b',', ERequires::ListEnd), word1(b'}', ERequires::ListEnd), min_indent, - 0, ERequires::Open, ERequires::IndentListEnd, - ERequires::IndentListEnd, Spaced::SpaceBefore ) } @@ -585,7 +577,6 @@ fn exposes_values<'a>() -> impl Parser< EExposes, > { let min_indent = 1; - let outdent_col = 0; and!( spaces_around_keyword( @@ -601,10 +592,8 @@ fn exposes_values<'a>() -> impl Parser< word1(b',', EExposes::ListEnd), word1(b']', EExposes::ListEnd), min_indent, - outdent_col, EExposes::Open, EExposes::IndentListEnd, - EExposes::IndentListEnd, Spaced::SpaceBefore ) ) @@ -639,7 +628,6 @@ fn exposes_modules<'a>() -> impl Parser< EExposes, > { let min_indent = 1; - let outdent_col = 0; and!( spaces_around_keyword( @@ -655,10 +643,8 @@ fn exposes_modules<'a>() -> impl Parser< word1(b',', EExposes::ListEnd), word1(b']', EExposes::ListEnd), min_indent, - outdent_col, EExposes::Open, EExposes::IndentListEnd, - EExposes::IndentListEnd, Spaced::SpaceBefore ) ) @@ -688,7 +674,6 @@ struct Packages<'a> { #[inline(always)] fn packages<'a>() -> impl Parser<'a, Packages<'a>, EPackages<'a>> { let min_indent = 1; - let outdent_col = 0; map!( and!( @@ -705,10 +690,8 @@ fn packages<'a>() -> impl Parser<'a, Packages<'a>, EPackages<'a>> { word1(b',', EPackages::ListEnd), word1(b'}', EPackages::ListEnd), min_indent, - outdent_col, EPackages::Open, EPackages::IndentListEnd, - EPackages::IndentListEnd, Spaced::SpaceBefore ) ), @@ -758,7 +741,6 @@ fn generates_with<'a>() -> impl Parser< EGeneratesWith, > { let min_indent = 1; - let outdent_col = 0; and!( spaces_around_keyword( @@ -774,10 +756,8 @@ fn generates_with<'a>() -> impl Parser< word1(b',', EGeneratesWith::ListEnd), word1(b']', EGeneratesWith::ListEnd), min_indent, - outdent_col, EGeneratesWith::Open, EGeneratesWith::IndentListEnd, - EGeneratesWith::IndentListEnd, Spaced::SpaceBefore ) ) @@ -793,7 +773,6 @@ fn imports<'a>() -> impl Parser< EImports, > { let min_indent = 1; - let outdent_col = 0; and!( spaces_around_keyword( @@ -809,10 +788,8 @@ fn imports<'a>() -> impl Parser< word1(b',', EImports::ListEnd), word1(b']', EImports::ListEnd), min_indent, - outdent_col, EImports::Open, EImports::IndentListEnd, - EImports::IndentListEnd, Spaced::SpaceBefore ) ) @@ -872,7 +849,6 @@ where #[inline(always)] fn imports_entry<'a>() -> impl Parser<'a, Spaced<'a, ImportsEntry<'a>>, EImports> { let min_indent = 1; - let outdent_col = 0; type Temp<'a> = ( (Option<&'a str>, ModuleName<'a>), @@ -899,10 +875,8 @@ fn imports_entry<'a>() -> impl Parser<'a, Spaced<'a, ImportsEntry<'a>>, EImports word1(b',', EImports::SetEnd), word1(b'}', EImports::SetEnd), min_indent, - outdent_col, EImports::Open, EImports::IndentSetEnd, - EImports::IndentSetEnd, Spaced::SpaceBefore ) )) diff --git a/compiler/parse/src/parser.rs b/compiler/parse/src/parser.rs index 6edeaa3cdd..3c25922ba9 100644 --- a/compiler/parse/src/parser.rs +++ b/compiler/parse/src/parser.rs @@ -407,7 +407,6 @@ pub enum ERecord<'a> { IndentBar(Position), IndentAmpersand(Position), IndentEnd(Position), - OutdentEnd(Position), } #[derive(Debug, Clone, PartialEq, Eq)] @@ -449,7 +448,6 @@ pub enum EList<'a> { IndentOpen(Position), IndentEnd(Position), - OutdentEnd(Position), } #[derive(Debug, Clone, PartialEq, Eq)] @@ -1213,7 +1211,7 @@ macro_rules! collection { #[macro_export] macro_rules! collection_trailing_sep_e { - ($opening_brace:expr, $elem:expr, $delimiter:expr, $closing_brace:expr, $min_indent:expr, $outdent_col:expr, $open_problem:expr, $indent_problem:expr, $outdent_problem:expr, $space_before:expr) => { + ($opening_brace:expr, $elem:expr, $delimiter:expr, $closing_brace:expr, $min_indent:expr, $open_problem:expr, $indent_problem:expr, $space_before:expr) => { skip_first!( $opening_brace, |arena, state| { @@ -1232,13 +1230,12 @@ macro_rules! collection_trailing_sep_e { ) ), $crate::blankspace::space0_e( - 0, + // we use min_indent=0 because we want to parse incorrectly indented closing braces + // and later fix these up in the formatter. + 0 /* min_indent */, $indent_problem) ).parse(arena, state)?; - let closing_brace_col = state.column(); - let closing_brace_pos = state.pos(); - let (_,_, state) = if parsed_elems.is_empty() { one_of_with_error![$open_problem; $closing_brace].parse(arena, state)? @@ -1246,13 +1243,6 @@ macro_rules! collection_trailing_sep_e { $closing_brace.parse(arena, state)? }; - #[allow(unused_comparisons)] // sometimes $outdent_col is 0 - if closing_brace_col < $outdent_col { - // We successfully parsed the collection but the closing brace was outdented - // further than expected. - return Err((MadeProgress, $outdent_problem(closing_brace_pos), state)); - } - if !spaces.is_empty() { if let Some(first) = parsed_elems.first_mut() { first.value = $space_before(arena.alloc(first.value), spaces) diff --git a/compiler/parse/src/pattern.rs b/compiler/parse/src/pattern.rs index c2ec96fcf1..09e676075f 100644 --- a/compiler/parse/src/pattern.rs +++ b/compiler/parse/src/pattern.rs @@ -365,10 +365,8 @@ fn record_pattern_help<'a>(min_indent: u32) -> impl Parser<'a, Pattern<'a>, PRec // word1_check_indent!(b'}', PRecord::End, min_indent, PRecord::IndentEnd), word1(b'}', PRecord::End), min_indent, - 0, PRecord::Open, PRecord::IndentEnd, - PRecord::IndentEnd, Pattern::SpaceBefore ) .parse(arena, state)?; diff --git a/compiler/parse/src/type_annotation.rs b/compiler/parse/src/type_annotation.rs index 02e52f774c..45b34b7157 100644 --- a/compiler/parse/src/type_annotation.rs +++ b/compiler/parse/src/type_annotation.rs @@ -31,10 +31,8 @@ fn tag_union_type<'a>(min_indent: u32) -> impl Parser<'a, TypeAnnotation<'a>, ET word1(b',', ETypeTagUnion::End), word1(b']', ETypeTagUnion::End), min_indent, - 0, ETypeTagUnion::Open, ETypeTagUnion::IndentEnd, - ETypeTagUnion::IndentEnd, Tag::SpaceBefore ) .parse(arena, state)?; @@ -325,10 +323,8 @@ fn record_type<'a>(min_indent: u32) -> impl Parser<'a, TypeAnnotation<'a>, EType // word1_check_indent!(b'}', TRecord::End, min_indent, TRecord::IndentEnd), word1(b'}', ETypeRecord::End), min_indent, - 0, ETypeRecord::Open, ETypeRecord::IndentEnd, - ETypeRecord::IndentEnd, AssignedField::SpaceBefore ) .parse(arena, state)?; diff --git a/compiler/parse/tests/test_parse.rs b/compiler/parse/tests/test_parse.rs index 759276523c..7b78187826 100644 --- a/compiler/parse/tests/test_parse.rs +++ b/compiler/parse/tests/test_parse.rs @@ -220,7 +220,6 @@ mod test_parse { pass/ops_with_newlines.expr, pass/outdented_list.expr, pass/outdented_record.expr, - pass/outdented_app_with_record.expr, pass/packed_singleton_list.expr, pass/parenthetical_apply.expr, pass/parenthetical_basic_field.expr, diff --git a/reporting/src/error/parse.rs b/reporting/src/error/parse.rs index cb5a3e0b47..83b878a6c0 100644 --- a/reporting/src/error/parse.rs +++ b/reporting/src/error/parse.rs @@ -1,4 +1,4 @@ -use roc_parse::parser::{ENumber, ERecord, FileError, SyntaxError}; +use roc_parse::parser::{ENumber, FileError, SyntaxError}; use roc_region::all::{LineColumn, LineColumnRegion, LineInfo, Position, Region}; use std::path::PathBuf; @@ -516,42 +516,23 @@ fn to_expr_report<'a>( } } - EExpr::Record(erecord, pos) => match erecord { - &ERecord::OutdentEnd(pos) => { - let surroundings = Region::new(start, pos); - let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); + EExpr::Record(_erecord, pos) => { + let surroundings = Region::new(start, *pos); + let region = LineColumnRegion::from_pos(lines.convert_pos(*pos)); - let doc = alloc.stack(vec![ - alloc.reflow(r"I found the end of this record, but it's outdented too far:"), - alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.reflow(r"Did you mean to indent it further?"), - ]); + let doc = alloc.stack(vec![ + alloc.reflow(r"I am partway through parsing an record, but I got stuck here:"), + alloc.region_with_subregion(lines.convert_region(surroundings), region), + alloc.concat(vec![alloc.reflow("TODO provide more context.")]), + ]); - Report { - filename, - doc, - title: "RECORD END OUDENTED TOO FAR".to_string(), - severity: Severity::RuntimeError, - } + Report { + filename, + doc, + title: "RECORD PARSE PROBLEM".to_string(), + severity: Severity::RuntimeError, } - _ => { - let surroundings = Region::new(start, *pos); - let region = LineColumnRegion::from_pos(lines.convert_pos(*pos)); - - let doc = alloc.stack(vec![ - alloc.reflow(r"I am partway through parsing an record, but I got stuck here:"), - alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![alloc.reflow("TODO provide more context.")]), - ]); - - Report { - filename, - doc, - title: "RECORD PARSE PROBLEM".to_string(), - severity: Severity::RuntimeError, - } - } - }, + } EExpr::Space(error, pos) => to_space_report(alloc, lines, filename, error, *pos), @@ -561,23 +542,6 @@ fn to_expr_report<'a>( EExpr::Ability(err, pos) => to_ability_def_report(alloc, lines, filename, err, *pos), - EExpr::IndentEnd(pos) => { - let surroundings = Region::new(start, *pos); - let region = LineColumnRegion::from_pos(lines.convert_pos(*pos)); - - let doc = alloc.stack(vec![ - alloc.reflow("Indentation unexpectedly ended here:"), - alloc.region_with_subregion(lines.convert_region(surroundings), region), - ]); - - Report { - filename, - doc, - title: "INDENTATION ENDED EARLY".to_string(), - // In an ideal world, this is recoverable and we keep parsing. - severity: Severity::Warning, - } - } _ => todo!("unhandled parse error: {:?}", parse_problem), } } @@ -1152,24 +1116,6 @@ fn to_list_report<'a>( severity: Severity::RuntimeError, } } - - EList::OutdentEnd(pos) => { - let surroundings = Region::new(start, pos); - let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - - let doc = alloc.stack(vec![ - alloc.reflow(r"I found the end of this list, but it's outdented too far:"), - alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.reflow(r"Did you mean to indent it further?"), - ]); - - Report { - filename, - doc, - title: "LIST END OUDENTED TOO FAR".to_string(), - severity: Severity::RuntimeError, - } - } } } diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 8eb035dea2..99cbc3d710 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -9780,65 +9780,4 @@ I need all branches in an `if` to have the same type! ), ) } - - #[test] - fn list_outdented_too_far() { - report_problem_as( - indoc!( - r#" - w = - a = [ - 1, 2, 3 - ] - a - w - "# - ), - indoc!( - r#" - ── LIST END OUDENTED TOO FAR ─────────────────────────────────────────────────── - - I found the end of this list, but it's outdented too far: - - 2│ a = [ - 3│ 1, 2, 3 - 4│ ] - ^ - - Did you mean to indent it further? - "# - ), - ) - } - - #[test] - fn record_outdented_too_far() { - report_problem_as( - indoc!( - r#" - w = - r = { - sweet: "disposition" - } - r - w - "# - ), - indoc!( - r#" - ── RECORD END OUDENTED TOO FAR ───────────────────────────────────────────────── - - I found the end of this record, but it's outdented too far: - - 1│ w = - 2│ r = { - 3│ sweet: "disposition" - 4│ } - ^ - - Did you mean to indent it further? - "# - ), - ) - } } From dca2fedbd473b64020492a175113cf0b04d7eaae Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 13 Apr 2022 20:58:56 -0400 Subject: [PATCH 236/846] Give more information when surgical linking fails --- cli/src/build.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cli/src/build.rs b/cli/src/build.rs index ab3d7d0c42..938ed23935 100644 --- a/cli/src/build.rs +++ b/cli/src/build.rs @@ -242,8 +242,11 @@ pub fn build_file<'a>( let link_start = SystemTime::now(); let outcome = if surgically_link { roc_linker::link_preprocessed_host(target, &host_input_path, app_o_file, &binary_path) - .map_err(|_| { - todo!("gracefully handle failing to surgically link"); + .map_err(|err| { + todo!( + "gracefully handle failing to surgically link with error: {:?}", + err + ); })?; BuildOutcome::NoProblems } else if matches!(link_type, LinkType::None) { From be725d64214dcf9600d816b5cfc88f40e8ffb105 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 13 Apr 2022 13:54:57 -0400 Subject: [PATCH 237/846] Revert changes to IR filenames --- compiler/builtins/bitcode/build.zig | 12 ++++++------ compiler/builtins/build.rs | 8 ++++---- compiler/gen_llvm/src/llvm/build.rs | 8 ++++---- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/compiler/builtins/bitcode/build.zig b/compiler/builtins/bitcode/build.zig index 6522f76bc2..8a194dad50 100644 --- a/compiler/builtins/bitcode/build.zig +++ b/compiler/builtins/bitcode/build.zig @@ -33,14 +33,14 @@ pub fn build(b: *Builder) void { const wasm32_target = makeWasm32Target(); // LLVM IR - generateLlvmIrFile(b, mode, host_target, main_path, "ir", "host"); - generateLlvmIrFile(b, mode, linux32_target, main_path, "ir-i386", "i386-unknown-linux-musl"); - generateLlvmIrFile(b, mode, linux64_target, main_path, "ir-x86_64", "x86_64-unknown-linux-musl"); - generateLlvmIrFile(b, mode, wasm32_target, main_path, "ir-wasm32", "wasm32-unknown-unknown"); + generateLlvmIrFile(b, mode, host_target, main_path, "ir", "builtins-host"); + generateLlvmIrFile(b, mode, linux32_target, main_path, "ir-i386", "builtins-i386"); + generateLlvmIrFile(b, mode, linux64_target, main_path, "ir-x86_64", "builtins-x86_64"); + generateLlvmIrFile(b, mode, wasm32_target, main_path, "ir-wasm32", "wasm32"); // Generate Object Files - generateObjectFile(b, mode, host_target, main_path, "object", "host"); - generateObjectFile(b, mode, wasm32_target, main_path, "wasm32-object", "wasm32"); + generateObjectFile(b, mode, host_target, main_path, "object", "builtins-host"); + generateObjectFile(b, mode, wasm32_target, main_path, "wasm32-object", "builtins-wasm32"); removeInstallSteps(b); } diff --git a/compiler/builtins/build.rs b/compiler/builtins/build.rs index ff0d260941..ff2a83e609 100644 --- a/compiler/builtins/build.rs +++ b/compiler/builtins/build.rs @@ -36,14 +36,14 @@ fn main() { // LLVM .bc FILES - generate_bc_file(&bitcode_path, &build_script_dir_path, "ir", "host"); + generate_bc_file(&bitcode_path, &build_script_dir_path, "ir", "builtins-host"); if !DEBUG { generate_bc_file( &bitcode_path, &build_script_dir_path, "ir-wasm32", - "wasm32-unknown-unknown", + "builtins-wasm32", ); } @@ -51,14 +51,14 @@ fn main() { &bitcode_path, &build_script_dir_path, "ir-i386", - "i386-unknown-linux-musl", + "builtins-i386", ); generate_bc_file( &bitcode_path, &build_script_dir_path, "ir-x86_64", - "x86_64-unknown-linux-musl", + "builtins-x86_64", ); // OBJECT FILES diff --git a/compiler/gen_llvm/src/llvm/build.rs b/compiler/gen_llvm/src/llvm/build.rs index d406abecf5..d80b48dfea 100644 --- a/compiler/gen_llvm/src/llvm/build.rs +++ b/compiler/gen_llvm/src/llvm/build.rs @@ -411,28 +411,28 @@ pub fn module_from_builtins<'ctx>( // In the build script for the builtins module, we compile the builtins into LLVM bitcode let bitcode_bytes: &[u8] = if target == &target_lexicon::Triple::host() { - include_bytes!("../../../builtins/bitcode/host.bc") + include_bytes!("../../../builtins/bitcode/builtins-host.bc") } else { match target { Triple { architecture: Architecture::Wasm32, .. } => { - include_bytes!("../../../builtins/bitcode/wasm32-unknown-unknown.bc") + include_bytes!("../../../builtins/bitcode/builtins-wasm32.bc") } Triple { architecture: Architecture::X86_32(_), operating_system: OperatingSystem::Linux, .. } => { - include_bytes!("../../../builtins/bitcode/i386-unknown-linux-musl.bc") + include_bytes!("../../../builtins/bitcode/builtins-i386.bc") } Triple { architecture: Architecture::X86_64, operating_system: OperatingSystem::Linux, .. } => { - include_bytes!("../../../builtins/bitcode/x86_64-unknown-linux-musl.bc") + include_bytes!("../../../builtins/bitcode/builtins-x86_64.bc") } _ => panic!( "The zig builtins are not currently built for this target: {:?}", From 3fc777a7be8fd961dadf157b34349cd5b15ef063 Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Thu, 14 Apr 2022 18:15:35 +0200 Subject: [PATCH 238/846] made changes to keep performance and not freeze --- editor/src/editor/main.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/editor/src/editor/main.rs b/editor/src/editor/main.rs index e1076dbe11..5dbfac12f7 100644 --- a/editor/src/editor/main.rs +++ b/editor/src/editor/main.rs @@ -236,6 +236,8 @@ fn run_event_loop(project_dir_path_opt: Option<&Path>) -> Result<(), Box) -> Result<(), Box) -> Result<(), Box { keyboard_modifiers = modifiers; } - Event::MainEventsCleared => window.request_redraw(), Event::RedrawRequested { .. } => { // Get a command encoder for the current frame let mut encoder = From 5652e72f994832766b7a9029a5c0c8d05ecbd019 Mon Sep 17 00:00:00 2001 From: Ayaz <20735482+ayazhafiz@users.noreply.github.com> Date: Thu, 14 Apr 2022 12:50:28 -0400 Subject: [PATCH 239/846] Missing test --- compiler/parse/tests/test_parse.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/parse/tests/test_parse.rs b/compiler/parse/tests/test_parse.rs index 7b78187826..759276523c 100644 --- a/compiler/parse/tests/test_parse.rs +++ b/compiler/parse/tests/test_parse.rs @@ -220,6 +220,7 @@ mod test_parse { pass/ops_with_newlines.expr, pass/outdented_list.expr, pass/outdented_record.expr, + pass/outdented_app_with_record.expr, pass/packed_singleton_list.expr, pass/parenthetical_apply.expr, pass/parenthetical_basic_field.expr, From 629d17c3ae5913f87654b7b61430895b05bf34e4 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 14 Apr 2022 13:21:24 -0400 Subject: [PATCH 240/846] Restore old IR name for wasm32 --- compiler/builtins/bitcode/build.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/builtins/bitcode/build.zig b/compiler/builtins/bitcode/build.zig index 8a194dad50..3f724041fe 100644 --- a/compiler/builtins/bitcode/build.zig +++ b/compiler/builtins/bitcode/build.zig @@ -36,7 +36,7 @@ pub fn build(b: *Builder) void { generateLlvmIrFile(b, mode, host_target, main_path, "ir", "builtins-host"); generateLlvmIrFile(b, mode, linux32_target, main_path, "ir-i386", "builtins-i386"); generateLlvmIrFile(b, mode, linux64_target, main_path, "ir-x86_64", "builtins-x86_64"); - generateLlvmIrFile(b, mode, wasm32_target, main_path, "ir-wasm32", "wasm32"); + generateLlvmIrFile(b, mode, wasm32_target, main_path, "ir-wasm32", "builtins-wasm32"); // Generate Object Files generateObjectFile(b, mode, host_target, main_path, "object", "builtins-host"); From eb81c68bcbdb7a354abd382fab46185cc3b567ec Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 14 Apr 2022 16:02:37 -0400 Subject: [PATCH 241/846] Pass abilities store to mono --- compiler/load_internal/src/file.rs | 27 ++++++++++++++++++++++++++- compiler/mono/src/ir.rs | 2 ++ reporting/tests/test_reporting.rs | 3 +++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index 5287d7721c..6c52590996 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -271,6 +271,7 @@ fn start_phase<'a>( solved_subs, decls, ident_ids, + abilities_store, } = typechecked; let mut imported_module_thunks = bumpalo::collections::Vec::new_in(arena); @@ -294,6 +295,7 @@ fn start_phase<'a>( decls, ident_ids, exposed_to_host: state.exposed_to_host.clone(), + abilities_store, } } Phase::MakeSpecializations => { @@ -316,6 +318,7 @@ fn start_phase<'a>( procs_base, layout_cache, module_timing, + abilities_store, } = found_specializations; BuildTask::MakeSpecializations { @@ -326,6 +329,7 @@ fn start_phase<'a>( layout_cache, specializations_we_must_make, module_timing, + abilities_store, } } } @@ -419,6 +423,7 @@ pub struct TypeCheckedModule<'a> { pub solved_subs: Solved, pub decls: Vec, pub ident_ids: IdentIds, + pub abilities_store: AbilitiesStore, } #[derive(Debug)] @@ -429,6 +434,7 @@ struct FoundSpecializationsModule<'a> { procs_base: ProcsBase<'a>, subs: Subs, module_timing: ModuleTiming, + abilities_store: AbilitiesStore, } #[derive(Debug)] @@ -529,6 +535,7 @@ enum Msg<'a> { problems: Vec, solved_subs: Solved, module_timing: ModuleTiming, + abilities_store: AbilitiesStore, }, MadeSpecializations { module_id: ModuleId, @@ -767,6 +774,7 @@ enum BuildTask<'a> { ident_ids: IdentIds, decls: Vec, exposed_to_host: ExposedToHost, + abilities_store: AbilitiesStore, }, MakeSpecializations { module_id: ModuleId, @@ -776,6 +784,7 @@ enum BuildTask<'a> { layout_cache: LayoutCache<'a>, specializations_we_must_make: Vec, module_timing: ModuleTiming, + abilities_store: AbilitiesStore, }, } @@ -1880,6 +1889,7 @@ fn update<'a>( solved_subs, decls, ident_ids, + abilities_store, }; state @@ -1904,6 +1914,7 @@ fn update<'a>( layout_cache, problems, module_timing, + abilities_store, } => { log!("found specializations for {:?}", module_id); @@ -1925,6 +1936,7 @@ fn update<'a>( procs_base, subs, module_timing, + abilities_store, }; state @@ -3642,6 +3654,7 @@ fn make_specializations<'a>( specializations_we_must_make: Vec, mut module_timing: ModuleTiming, target_info: TargetInfo, + abilities_store: AbilitiesStore, ) -> Msg<'a> { let make_specializations_start = SystemTime::now(); let mut mono_problems = Vec::new(); @@ -3657,6 +3670,7 @@ fn make_specializations<'a>( update_mode_ids: &mut update_mode_ids, // call_specialization_counter=0 is reserved call_specialization_counter: 1, + abilities_store: &abilities_store, }; let mut procs = Procs::new_in(arena); @@ -3727,6 +3741,7 @@ fn build_pending_specializations<'a>( target_info: TargetInfo, // TODO remove exposed_to_host: ExposedToHost, + abilities_store: AbilitiesStore, ) -> Msg<'a> { let find_specializations_start = SystemTime::now(); @@ -3753,6 +3768,7 @@ fn build_pending_specializations<'a>( update_mode_ids: &mut update_mode_ids, // call_specialization_counter=0 is reserved call_specialization_counter: 1, + abilities_store: &abilities_store, }; // Add modules' decls to Procs @@ -3806,6 +3822,7 @@ fn build_pending_specializations<'a>( procs_base, problems, module_timing, + abilities_store, } } @@ -3823,7 +3840,11 @@ fn add_def_to_module<'a>( use roc_can::pattern::Pattern::*; match def.loc_pattern.value { - Identifier(symbol) => { + Identifier(symbol) + | AbilityMemberSpecialization { + ident: symbol, + specializes: _, + } => { let is_host_exposed = exposed_to_host.contains_key(&symbol); match def.loc_expr.value { @@ -4026,6 +4047,7 @@ fn run_task<'a>( solved_subs, imported_module_thunks, exposed_to_host, + abilities_store, } => Ok(build_pending_specializations( arena, solved_subs, @@ -4037,6 +4059,7 @@ fn run_task<'a>( layout_cache, target_info, exposed_to_host, + abilities_store, )), MakeSpecializations { module_id, @@ -4046,6 +4069,7 @@ fn run_task<'a>( layout_cache, specializations_we_must_make, module_timing, + abilities_store, } => Ok(make_specializations( arena, module_id, @@ -4056,6 +4080,7 @@ fn run_task<'a>( specializations_we_must_make, module_timing, target_info, + abilities_store, )), }?; diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 8409b19b01..8e5c5a5a1e 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -7,6 +7,7 @@ use crate::layout::{ use bumpalo::collections::Vec; use bumpalo::Bump; use roc_builtins::bitcode::{FloatWidth, IntWidth}; +use roc_can::abilities::AbilitiesStore; use roc_can::expr::{ClosureData, IntValue}; use roc_collections::all::{default_hasher, BumpMap, BumpMapDefault, MutMap}; use roc_exhaustive::{Ctor, Guard, RenderAs, TagId}; @@ -1119,6 +1120,7 @@ pub struct Env<'a, 'i> { pub target_info: TargetInfo, pub update_mode_ids: &'i mut UpdateModeIds, pub call_specialization_counter: u32, + pub abilities_store: &'i AbilitiesStore, } impl<'a, 'i> Env<'a, 'i> { diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 99cbc3d710..5d0cf6b884 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -125,6 +125,7 @@ mod test_reporting { mut solved, exposed_to_host, mut declarations_by_id, + abilities_store, .. } = result?; @@ -177,6 +178,7 @@ mod test_reporting { target_info, // call_specialization_counter=0 is reserved call_specialization_counter: 1, + abilities_store: &abilities_store, }; let _mono_expr = Stmt::new( &mut mono_env, @@ -334,6 +336,7 @@ mod test_reporting { target_info, // call_specialization_counter=0 is reserved call_specialization_counter: 1, + abilities_store: &abilities_store, }; let _mono_expr = Stmt::new( &mut mono_env, From 6b4294307f682452b41317cfa7c2432beba5271e Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 14 Apr 2022 16:22:54 -0400 Subject: [PATCH 242/846] Start saving ability signature on designated variable again --- compiler/can/src/abilities.rs | 6 +++-- compiler/can/src/def.rs | 8 +++++- compiler/constrain/src/module.rs | 44 ++++++++++++++++++++++++++------ compiler/solve/src/solve.rs | 7 +---- 4 files changed, 48 insertions(+), 17 deletions(-) diff --git a/compiler/can/src/abilities.rs b/compiler/can/src/abilities.rs index 2879de8e0c..b162a1355f 100644 --- a/compiler/can/src/abilities.rs +++ b/compiler/can/src/abilities.rs @@ -16,6 +16,7 @@ pub struct MemberVariables { #[derive(Debug, Clone, PartialEq, Eq)] pub struct AbilityMemberData { pub parent_ability: Symbol, + pub signature_var: Variable, pub signature: Type, pub variables: MemberVariables, pub region: Region, @@ -60,15 +61,16 @@ impl AbilitiesStore { pub fn register_ability( &mut self, ability: Symbol, - members: Vec<(Symbol, Region, Type, MemberVariables)>, + members: Vec<(Symbol, Region, Variable, Type, MemberVariables)>, ) { let mut members_vec = Vec::with_capacity(members.len()); - for (member, region, signature, variables) in members.into_iter() { + for (member, region, signature_var, signature, variables) in members.into_iter() { members_vec.push(member); let old_member = self.ability_members.insert( member, AbilityMemberData { parent_ability: ability, + signature_var, signature, region, variables, diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 571568592a..33473cd886 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -542,7 +542,13 @@ pub fn canonicalize_defs<'a>( flex_vars: iv.collect_flex(), }; - can_members.push((member_sym, name_region, member_annot.typ, variables)); + can_members.push(( + member_sym, + name_region, + var_store.fresh(), + member_annot.typ, + variables, + )); } // Store what symbols a type must define implementations for to have this ability. diff --git a/compiler/constrain/src/module.rs b/compiler/constrain/src/module.rs index e47fe1130a..244958b75b 100644 --- a/compiler/constrain/src/module.rs +++ b/compiler/constrain/src/module.rs @@ -2,12 +2,14 @@ use roc_builtins::std::StdLib; use roc_can::abilities::AbilitiesStore; use roc_can::constraint::{Constraint, Constraints}; use roc_can::def::Declaration; +use roc_can::expected::Expected; use roc_collections::all::MutMap; use roc_error_macros::internal_error; use roc_module::symbol::{ModuleId, Symbol}; -use roc_region::all::Loc; +use roc_region::all::{Loc, Region}; use roc_types::solved_types::{FreeVars, SolvedType}; use roc_types::subs::{VarStore, Variable}; +use roc_types::types::{Category, Type}; /// The types of all exposed values/functions of a collection of modules #[derive(Clone, Debug, Default)] @@ -105,27 +107,53 @@ pub fn constrain_module( declarations: &[Declaration], home: ModuleId, ) -> Constraint { - let mut constraint = crate::expr::constrain_decls(constraints, home, declarations); + let constraint = crate::expr::constrain_decls(constraints, home, declarations); + let constraint = frontload_ability_constraints(constraints, abilities_store, constraint); + + // The module constraint should always save the environment at the end. + debug_assert!(constraints.contains_save_the_environment(&constraint)); + + constraint +} + +pub fn frontload_ability_constraints( + constraints: &mut Constraints, + abilities_store: &AbilitiesStore, + mut constraint: Constraint, +) -> Constraint { for (member_name, member_data) in abilities_store.root_ability_members().iter() { + // 1. Attach the type of member signature to the reserved signature_var. This is + // infallible. + let unify_with_signature_var = constraints.equal_types_var( + member_data.signature_var, + Expected::NoExpectation(member_data.signature.clone()), + Category::Storage(std::file!(), std::column!()), + Region::zero(), + ); + + // 2. Store the member signature on the member symbol. This makes sure we generalize it on + // the toplevel, as appropriate. let vars = &member_data.variables; let rigids = (vars.rigid_vars.iter()) // For our purposes, in the let constraint, able vars are treated like rigids. .chain(vars.able_vars.iter()) .copied(); let flex = vars.flex_vars.iter().copied(); - constraint = constraints.let_constraint( + + let let_constr = constraints.let_constraint( rigids, flex, - [(*member_name, Loc::at_zero(member_data.signature.clone()))], + [( + *member_name, + Loc::at_zero(Type::Variable(member_data.signature_var)), + )], Constraint::True, constraint, ); + + constraint = constraints.and_constraint([unify_with_signature_var, let_constr]); } - - // The module constraint should always save the environment at the end. - debug_assert!(constraints.contains_save_the_environment(&constraint)); - constraint } diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index 2902eaefda..a466c99f8c 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -703,7 +703,6 @@ fn solve( check_ability_specialization( arena, subs, - &new_env, pools, rank, abilities_store, @@ -812,7 +811,6 @@ fn solve( check_ability_specialization( arena, subs, - &new_env, pools, rank, abilities_store, @@ -1282,7 +1280,6 @@ fn solve( fn check_ability_specialization( arena: &Bump, subs: &mut Subs, - env: &Env, pools: &mut Pools, rank: Rank, abilities_store: &mut AbilitiesStore, @@ -1295,9 +1292,7 @@ fn check_ability_specialization( // inferred type for the specialization actually aligns with the expected // implementation. if let Some((root_symbol, root_data)) = abilities_store.root_name_and_def(symbol) { - let root_signature_var = env - .get_var_by_symbol(&root_symbol) - .expect("Ability should be registered in env by now!"); + let root_signature_var = root_data.signature_var; // Check if they unify - if they don't, then the claimed specialization isn't really one, // and that's a type error! From b79b351136d9c95f9f4706f8b33e47423b61d642 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 14 Apr 2022 16:50:41 -0400 Subject: [PATCH 243/846] The first ability... compiles --- compiler/mono/src/ir.rs | 41 +++++++++++++++++++ compiler/solve/src/ability.rs | 21 ++++++++++ compiler/solve/src/lib.rs | 2 +- compiler/solve/src/solve.rs | 14 ++----- .../generated/specialize_ability_call.txt | 7 ++++ compiler/test_mono/src/tests.rs | 19 +++++++++ compiler/unify/src/unify.rs | 12 ++++++ 7 files changed, 104 insertions(+), 12 deletions(-) create mode 100644 compiler/test_mono/generated/specialize_ability_call.txt diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 8e5c5a5a1e..baf8576c49 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -4220,10 +4220,14 @@ pub fn with_hole<'a>( // a proc in this module, or an imported symbol procs.partial_procs.contains_key(key) || (env.is_imported_symbol(key) && !procs.is_imported_module_thunk(key)) + || env.abilities_store.is_ability_member_name(key) }; match loc_expr.value { roc_can::expr::Expr::Var(proc_name) if is_known(proc_name) => { + // This might be an ability member - if so, use the appropriate specialization. + let proc_name = repoint_to_specialization(env, fn_var, proc_name); + // a call by a known name call_by_name( env, @@ -4707,6 +4711,43 @@ pub fn with_hole<'a>( } } +#[inline(always)] +fn repoint_to_specialization<'a>( + env: &mut Env<'a, '_>, + symbol_var: Variable, + symbol: Symbol, +) -> Symbol { + use roc_solve::ability::type_implementing_member; + use roc_unify::unify::unify; + + match env.abilities_store.member_def(symbol) { + None => { + // This is not an ability member, it doesn't need specialization. + symbol + } + Some(member) => { + let snapshot = env.subs.snapshot(); + let (_, must_implement_ability) = unify( + env.subs, + symbol_var, + member.signature_var, + roc_unify::unify::Mode::EQ, + ) + .expect_success("This typechecked previously"); + env.subs.rollback_to(snapshot); + let specializing_type = + type_implementing_member(&must_implement_ability, member.parent_ability); + + let specialization = env + .abilities_store + .get_specialization(symbol, specializing_type) + .expect("No specialization is recorded - I thought there would only be a type error here."); + + specialization.symbol + } + } +} + #[allow(clippy::too_many_arguments)] fn construct_closure_data<'a>( env: &mut Env<'a, '_>, diff --git a/compiler/solve/src/ability.rs b/compiler/solve/src/ability.rs index 3aaf27d32d..edbbd54bec 100644 --- a/compiler/solve/src/ability.rs +++ b/compiler/solve/src/ability.rs @@ -1,4 +1,5 @@ use roc_can::abilities::AbilitiesStore; +use roc_module::symbol::Symbol; use roc_region::all::{Loc, Region}; use roc_types::subs::Subs; use roc_types::subs::Variable; @@ -154,3 +155,23 @@ impl DeferredMustImplementAbility { problems } } + +/// Determines what type implements an ability member of a specialized signature, given the +/// [MustImplementAbility] constraints of the signature. +pub fn type_implementing_member( + specialization_must_implement_constraints: &[MustImplementAbility], + ability: Symbol, +) -> Symbol { + let mut ability_implementations_for_specialization = specialization_must_implement_constraints + .iter() + .filter(|mia| mia.ability == ability) + .collect::>(); + ability_implementations_for_specialization.dedup(); + + debug_assert!(ability_implementations_for_specialization.len() == 1, "Multiple variables bound to an ability - this is ambiguous and should have been caught in canonicalization"); + + ability_implementations_for_specialization + .pop() + .unwrap() + .typ +} diff --git a/compiler/solve/src/lib.rs b/compiler/solve/src/lib.rs index 06f9e2fd5c..d0e42eaf42 100644 --- a/compiler/solve/src/lib.rs +++ b/compiler/solve/src/lib.rs @@ -2,6 +2,6 @@ // See github.com/rtfeldman/roc/issues/800 for discussion of the large_enum_variant check. #![allow(clippy::large_enum_variant)] -mod ability; +pub mod ability; pub mod module; pub mod solve; diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index a466c99f8c..61814b7282 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -1,4 +1,4 @@ -use crate::ability::{AbilityImplError, DeferredMustImplementAbility}; +use crate::ability::{type_implementing_member, AbilityImplError, DeferredMustImplementAbility}; use bumpalo::Bump; use roc_can::abilities::{AbilitiesStore, MemberSpecialization}; use roc_can::constraint::Constraint::{self, *}; @@ -1346,16 +1346,8 @@ fn check_ability_specialization( // First, figure out and register for what type does this symbol specialize // the ability member. - let mut ability_implementations_for_specialization = must_implement_ability - .iter() - .filter(|mia| mia.ability == root_data.parent_ability) - .collect::>(); - ability_implementations_for_specialization.dedup(); - - debug_assert!(ability_implementations_for_specialization.len() == 1, "Multiple variables bound to an ability - this is ambiguous and should have been caught in canonicalization"); - - // This is a valid specialization! Record it. - let specialization_type = ability_implementations_for_specialization[0].typ; + let specialization_type = + type_implementing_member(&must_implement_ability, root_data.parent_ability); let specialization = MemberSpecialization { symbol, region: symbol_loc_var.region, diff --git a/compiler/test_mono/generated/specialize_ability_call.txt b/compiler/test_mono/generated/specialize_ability_call.txt new file mode 100644 index 0000000000..9e3179be06 --- /dev/null +++ b/compiler/test_mono/generated/specialize_ability_call.txt @@ -0,0 +1,7 @@ +procedure Test.5 (Test.8): + ret Test.8; + +procedure Test.0 (): + let Test.10 : U64 = 1234i64; + let Test.9 : U64 = CallByName Test.5 Test.10; + ret Test.9; diff --git a/compiler/test_mono/src/tests.rs b/compiler/test_mono/src/tests.rs index 74e17f9a15..bba051e6b6 100644 --- a/compiler/test_mono/src/tests.rs +++ b/compiler/test_mono/src/tests.rs @@ -1294,6 +1294,25 @@ fn issue_2811() { ) } +#[mono_test] +fn specialize_ability_call() { + indoc!( + r#" + app "test" provides [ main ] to "./platform" + + Hash has + hash : a -> U64 | a has Hash + + Id := U64 + + hash : Id -> U64 + hash = \$Id n -> n + + main = hash ($Id 1234) + "# + ) +} + // #[ignore] // #[mono_test] // fn static_str_closure() { diff --git a/compiler/unify/src/unify.rs b/compiler/unify/src/unify.rs index a586cdaed7..35685d8a4c 100644 --- a/compiler/unify/src/unify.rs +++ b/compiler/unify/src/unify.rs @@ -140,6 +140,18 @@ pub enum Unified { BadType(Pool, roc_types::types::Problem), } +impl Unified { + pub fn expect_success(self, err_msg: &'static str) -> (Pool, Vec) { + match self { + Unified::Success { + vars, + must_implement_ability, + } => (vars, must_implement_ability), + _ => panic!("{}", err_msg), + } + } +} + /// Specifies that `type` must implement the ability `ability`. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct MustImplementAbility { From 8694ea9d3300667311e727ea80568a1f80db6e28 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 14 Apr 2022 17:06:19 -0400 Subject: [PATCH 244/846] Add first ability gen tests --- compiler/test_gen/src/gen_abilities.rs | 61 ++++++++++++++++++++++++++ compiler/test_gen/src/tests.rs | 1 + 2 files changed, 62 insertions(+) create mode 100644 compiler/test_gen/src/gen_abilities.rs diff --git a/compiler/test_gen/src/gen_abilities.rs b/compiler/test_gen/src/gen_abilities.rs new file mode 100644 index 0000000000..6522440dc7 --- /dev/null +++ b/compiler/test_gen/src/gen_abilities.rs @@ -0,0 +1,61 @@ +#[cfg(feature = "gen-llvm")] +use crate::helpers::llvm::assert_evals_to; + +#[cfg(feature = "gen-dev")] +use crate::helpers::dev::assert_evals_to; + +#[cfg(feature = "gen-wasm")] +use crate::helpers::wasm::assert_evals_to; + +#[cfg(test)] +use indoc::indoc; + +#[test] +#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] +fn hash_specialization() { + assert_evals_to!( + indoc!( + r#" + app "test" provides [ main ] to "./platform" + + Hash has + hash : a -> U64 | a has Hash + + Id := U64 + + hash = \$Id n -> n + + main = hash ($Id 1234) + "# + ), + 1234, + u64 + ); +} + +#[test] +#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] +fn hash_specialization_multiple_add() { + assert_evals_to!( + indoc!( + r#" + app "test" provides [ main ] to "./platform" + + Hash has + hash : a -> U64 | a has Hash + + Id := U64 + + hash = \$Id n -> n + + One := {} + + hash = \$One _ -> 1 + + main = hash ($Id 1234) + hash ($One {}) + "# + ), + 1235, + u64 + ); +} diff --git a/compiler/test_gen/src/tests.rs b/compiler/test_gen/src/tests.rs index 41923811a5..d17c610bc4 100644 --- a/compiler/test_gen/src/tests.rs +++ b/compiler/test_gen/src/tests.rs @@ -4,6 +4,7 @@ // we actually want to compare against the literal float bits #![allow(clippy::float_cmp)] +pub mod gen_abilities; pub mod gen_compare; pub mod gen_dict; pub mod gen_list; From 8f335c32787f969566efefde6a4bd57bd7c0caec Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 14 Apr 2022 17:25:44 -0400 Subject: [PATCH 245/846] Add solve test for aliasing ability --- compiler/solve/src/ability.rs | 5 ++++- compiler/solve/tests/solve_expr.rs | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/compiler/solve/src/ability.rs b/compiler/solve/src/ability.rs index edbbd54bec..3d51f150ee 100644 --- a/compiler/solve/src/ability.rs +++ b/compiler/solve/src/ability.rs @@ -168,7 +168,10 @@ pub fn type_implementing_member( .collect::>(); ability_implementations_for_specialization.dedup(); - debug_assert!(ability_implementations_for_specialization.len() == 1, "Multiple variables bound to an ability - this is ambiguous and should have been caught in canonicalization"); + debug_assert!( + ability_implementations_for_specialization.len() == 1, + "Multiple variables bound to an ability - this is ambiguous and should have been caught in canonicalization: {:?}", + ability_implementations_for_specialization); ability_implementations_for_specialization .pop() diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index 36a1220d9e..d66ab89937 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -5900,4 +5900,23 @@ mod solve_expr { "U64", ) } + + #[test] + fn alias_ability_member() { + infer_eq_without_problem( + indoc!( + r#" + app "test" provides [ thething ] to "./platform" + + Hash has + hash : a -> U64 | a has Hash + + thething = + itis = hash + itis + "# + ), + "a -> U64 | a has Hash", + ) + } } From 99d684a3a1c43bef84b90d3c1dce6df6ae5039eb Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 14 Apr 2022 17:36:08 -0400 Subject: [PATCH 246/846] Annotate `init` in breakout example --- examples/breakout/breakout.roc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index e8ff4a9c0d..bb755ad9f6 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -7,7 +7,7 @@ Model : { height : F32, width : F32, pos : F32 } program = { init, update, render } -# init : { height : F32, width : F32 } -> Model +init : { height : F32, width : F32 } -> Model init = \_ -> { width: 1900, height: 1000, pos: 100 } # update : Model, Event -> Model From ba2eeb576c8369aa60d44607c6e245feeacdda2f Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 14 Apr 2022 18:06:21 -0400 Subject: [PATCH 247/846] Extract Game module, fix annotations --- examples/breakout/breakout.roc | 8 ++++---- examples/breakout/platform/Game.roc | 12 ++++++++++++ examples/breakout/platform/Package-Config.roc | 12 ++---------- 3 files changed, 18 insertions(+), 14 deletions(-) create mode 100644 examples/breakout/platform/Game.roc diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index bb755ad9f6..dab0335aef 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -1,23 +1,23 @@ app "breakout" packages { pf: "platform" } - imports [] + imports [ pf.Game.{ Bounds, Elem, Event } ] provides [ program ] { Model } to pf Model : { height : F32, width : F32, pos : F32 } program = { init, update, render } -init : { height : F32, width : F32 } -> Model +init : Bounds -> Model init = \_ -> { width: 1900, height: 1000, pos: 100 } -# update : Model, Event -> Model +update : Model, Event -> Model update = \model, event -> when event is Resize size -> { model & width: size.width, height: size.height } KeyUp _ -> model KeyDown keyCode -> { model & pos: model.pos + 50 } -# render : Model -> List Elem +render : Model -> List Elem render = \model -> numRows = 4 numCols = 8 diff --git a/examples/breakout/platform/Game.roc b/examples/breakout/platform/Game.roc new file mode 100644 index 0000000000..a70d7542bf --- /dev/null +++ b/examples/breakout/platform/Game.roc @@ -0,0 +1,12 @@ +interface Game + exposes [ Bounds, Elem, Event ] + imports [] + +Rgba : { r : F32, g : F32, b : F32, a : F32 } + +Bounds : { height : F32, width: F32 } + +Elem : [ Rect { color : Rgba, left : F32, top : F32, width : F32, height : F32 }, Text Str ] + +Event : [ Resize { width : F32, height : F32 }, KeyDown U32, KeyUp U32 ] + diff --git a/examples/breakout/platform/Package-Config.roc b/examples/breakout/platform/Package-Config.roc index 7a9f031e64..3e37292a1c 100644 --- a/examples/breakout/platform/Package-Config.roc +++ b/examples/breakout/platform/Package-Config.roc @@ -1,18 +1,10 @@ platform "gui" requires { Model } { program : _ } - exposes [] + exposes [ Game ] packages {} - imports [] + imports [ Game.{ Bounds, Elem, Event } ] provides [ programForHost ] -Rgba : { r : F32, g : F32, b : F32, a : F32 } - -Bounds : { height : F32, width: F32 } - -Elem : [ Rect { color : Rgba, left : F32, top : F32, width : F32, height : F32 }, Text Str ] - -Event : [ Resize { width : F32, height : F32 }, KeyDown U32, KeyUp U32 ] - # TODO allow changing the window title - maybe via a Task, since that shouldn't happen all the time programForHost : { init : (Bounds -> Model) as Init, From 2be9825b7b133310bf1e09a9b4caf2cc8252d26a Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 14 Apr 2022 20:19:27 -0400 Subject: [PATCH 248/846] Add --force-roc-linker and --legacy-linker --- cli/src/lib.rs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 1b1fdeec80..07de87eedf 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -40,6 +40,8 @@ pub const FLAG_NO_LINK: &str = "no-link"; pub const FLAG_TARGET: &str = "target"; pub const FLAG_TIME: &str = "time"; pub const FLAG_LINK: &str = "roc-linker"; +pub const FLAG_FORCE_LINK: &str = "force-roc-linker"; +pub const FLAG_LEGACY_LINK: &str = "legacy-linker"; pub const FLAG_PRECOMPILED: &str = "precompiled-host"; pub const FLAG_VALGRIND: &str = "valgrind"; pub const FLAG_CHECK: &str = "check"; @@ -112,7 +114,19 @@ pub fn build_app<'a>() -> App<'a> { .arg( Arg::new(FLAG_LINK) .long(FLAG_LINK) - .about("Uses the roc linker instead of the system linker.") + .about("Deprecated in favor of --force-roc-linker and --legacy-linker") + .required(false), + ) + .arg( + Arg::new(FLAG_FORCE_LINK) + .long(FLAG_FORCE_LINK) + .about("Forces using the roc linker. Useful for trying out the Roc linker on new targets.") + .required(false), + ) + .arg( + Arg::new(FLAG_LEGACY_LINK) + .long(FLAG_LEGACY_LINK) + .about("Uses the legacy linker when otherwise the roc linker would be used. (Currently, only Linux x64 uses the Roc linker by default.)") .required(false), ) .arg( @@ -209,7 +223,19 @@ pub fn build_app<'a>() -> App<'a> { .arg( Arg::new(FLAG_LINK) .long(FLAG_LINK) - .about("Uses the roc linker instead of the system linker.") + .about("Deprecated in favor of --force-roc-linker and --legacy-linker") + .required(false), + ) + .arg( + Arg::new(FLAG_FORCE_LINK) + .long(FLAG_FORCE_LINK) + .about("Forces using the roc linker. Useful for trying out the Roc linker on new targets.") + .required(false), + ) + .arg( + Arg::new(FLAG_LEGACY_LINK) + .long(FLAG_LEGACY_LINK) + .about("Uses the legacy linker when otherwise the roc linker would be used. (Currently, only Linux x64 uses the Roc linker by default.)") .required(false), ) .arg( From 3daba1f6c0fe93468895f5a5128a5cd77833684a Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 14 Apr 2022 20:30:02 -0400 Subject: [PATCH 249/846] Introduce --linker flag --- cli/src/lib.rs | 55 ++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 07de87eedf..ace8a53607 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -40,8 +40,7 @@ pub const FLAG_NO_LINK: &str = "no-link"; pub const FLAG_TARGET: &str = "target"; pub const FLAG_TIME: &str = "time"; pub const FLAG_LINK: &str = "roc-linker"; -pub const FLAG_FORCE_LINK: &str = "force-roc-linker"; -pub const FLAG_LEGACY_LINK: &str = "legacy-linker"; +pub const FLAG_LINKER: &str = "linker"; pub const FLAG_PRECOMPILED: &str = "precompiled-host"; pub const FLAG_VALGRIND: &str = "valgrind"; pub const FLAG_CHECK: &str = "check"; @@ -118,15 +117,10 @@ pub fn build_app<'a>() -> App<'a> { .required(false), ) .arg( - Arg::new(FLAG_FORCE_LINK) - .long(FLAG_FORCE_LINK) - .about("Forces using the roc linker. Useful for trying out the Roc linker on new targets.") - .required(false), - ) - .arg( - Arg::new(FLAG_LEGACY_LINK) - .long(FLAG_LEGACY_LINK) - .about("Uses the legacy linker when otherwise the roc linker would be used. (Currently, only Linux x64 uses the Roc linker by default.)") + Arg::new(FLAG_LINKER) + .long(FLAG_LINKER) + .about("Sets which linker to use. The surgical linker is enabeld by default only when building for wasm32 or x86_64 Linux, because those are the only targets it currently supports. Otherwise the legacy linker is used by default.") + .possible_values(["surgical", "legacy"]) .required(false), ) .arg( @@ -223,25 +217,20 @@ pub fn build_app<'a>() -> App<'a> { .arg( Arg::new(FLAG_LINK) .long(FLAG_LINK) - .about("Deprecated in favor of --force-roc-linker and --legacy-linker") + .about("Deprecated in favor of --linker") .required(false), ) .arg( - Arg::new(FLAG_FORCE_LINK) - .long(FLAG_FORCE_LINK) - .about("Forces using the roc linker. Useful for trying out the Roc linker on new targets.") - .required(false), - ) - .arg( - Arg::new(FLAG_LEGACY_LINK) - .long(FLAG_LEGACY_LINK) - .about("Uses the legacy linker when otherwise the roc linker would be used. (Currently, only Linux x64 uses the Roc linker by default.)") + Arg::new(FLAG_LINKER) + .long(FLAG_LINKER) + .about("Sets which linker to use. The surgical linker is enabeld by default only when building for wasm32 or x86_64 Linux, because those are the only targets it currently supports. Otherwise the legacy linker is used by default.") + .possible_values(["surgical", "legacy"]) .required(false), ) .arg( Arg::new(FLAG_PRECOMPILED) .long(FLAG_PRECOMPILED) - .about("Assumes the host has been precompiled and skips recompiling the host.") + .about("Assumes the host has been precompiled and skips recompiling the host. (Enabled by default when using --target other than --target host)") .required(false), ) .arg( @@ -335,16 +324,23 @@ pub fn build(matches: &ArgMatches, config: BuildConfig) -> io::Result { (false, true) => LinkType::None, (false, false) => LinkType::Executable, }; - let surgically_link = matches.is_present(FLAG_LINK); - let precompiled = matches.is_present(FLAG_PRECOMPILED); - if surgically_link && !roc_linker::supported(&link_type, &triple) { - panic!( - "Link type, {:?}, with target, {}, not supported by roc linker", - link_type, triple - ); + // TODO remove FLAG_LINK from the code base anytime after the end of May 2022 + if matches.is_present(FLAG_LINK) { + eprintln!("ERROR: The --roc-linker flag has been deprecated because the roc linker is now used automatically where it's supported. (Currently that's only x64 Linux.) No need to use --roc-linker anymore, but you can use the --linker flag to switch linkers."); + process::exit(1); } + // Use surgical linking when supported, or when explicitly requested with --force-roc-linker + let surgically_link = if matches.is_present(FLAG_LINKER) { + matches.value_of(FLAG_LINKER) == Some("surgical") + } else { + roc_linker::supported(&link_type, &triple) + }; + + // When compiling for a different target, we assume a precompiled host. + // Otherwise compilation would most likely fail! + let precompiled = target != Target::Host || matches.is_present(FLAG_PRECOMPILED); let path = Path::new(filename); // Spawn the root task @@ -535,6 +531,7 @@ fn run_with_wasmer(_wasm_path: &std::path::Path, _args: &[String]) { println!("Running wasm files not support"); } +#[derive(Debug, Copy, Clone, PartialEq, Eq)] enum Target { Host, Linux32, From 6b213be99755154e4278c59c7f23e51d263af34d Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 14 Apr 2022 20:35:42 -0400 Subject: [PATCH 250/846] Minor formatting --- cli/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index ace8a53607..b706ec7040 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -82,7 +82,7 @@ pub fn build_app<'a>() -> App<'a> { Arg::new(FLAG_TARGET) .long(FLAG_TARGET) .about("Choose a different target") - .default_value(Target::default().as_str()) + .default_value(Target::default().as_str()) .possible_values(Target::OPTIONS) .required(false), ) From 1f93973dbf7aac50f3ced438d23355436883c791 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 14 Apr 2022 20:36:11 -0400 Subject: [PATCH 251/846] Allow --precompiled-host=false --- cli/src/lib.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index b706ec7040..67e3e3e2fb 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -126,7 +126,9 @@ pub fn build_app<'a>() -> App<'a> { .arg( Arg::new(FLAG_PRECOMPILED) .long(FLAG_PRECOMPILED) - .about("Assumes the host has been precompiled and skips recompiling the host.") + .about("Assumes the host has been precompiled and skips recompiling the host. (Enabled by default when using a --target other than `--target host`)") + .possible_values(["true", "false"]) + .default_value("true") .required(false), ) .arg( @@ -230,7 +232,9 @@ pub fn build_app<'a>() -> App<'a> { .arg( Arg::new(FLAG_PRECOMPILED) .long(FLAG_PRECOMPILED) - .about("Assumes the host has been precompiled and skips recompiling the host. (Enabled by default when using --target other than --target host)") + .about("Assumes the host has been precompiled and skips recompiling the host. (Enabled by default when using a --target other than `--target host`)") + .possible_values(["true", "false"]) + .default_value("true") .required(false), ) .arg( @@ -338,9 +342,13 @@ pub fn build(matches: &ArgMatches, config: BuildConfig) -> io::Result { roc_linker::supported(&link_type, &triple) }; - // When compiling for a different target, we assume a precompiled host. - // Otherwise compilation would most likely fail! - let precompiled = target != Target::Host || matches.is_present(FLAG_PRECOMPILED); + let precompiled = if matches.is_present(FLAG_PRECOMPILED) { + matches.value_of(FLAG_PRECOMPILED) == Some("true") + } else { + // When compiling for a different target, default to assuming a precompiled host. + // Otherwise compilation would most likely fail! + target != Target::Host + }; let path = Path::new(filename); // Spawn the root task From 4f10ccc5d1e27af4f1d40f422cf7b213ba3f9f09 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 14 Apr 2022 20:43:55 -0400 Subject: [PATCH 252/846] Rename Target::Host to Target::System --- cli/src/lib.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 67e3e3e2fb..4791d29448 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -347,7 +347,7 @@ pub fn build(matches: &ArgMatches, config: BuildConfig) -> io::Result { } else { // When compiling for a different target, default to assuming a precompiled host. // Otherwise compilation would most likely fail! - target != Target::Host + target != Target::System }; let path = Path::new(filename); @@ -541,7 +541,7 @@ fn run_with_wasmer(_wasm_path: &std::path::Path, _args: &[String]) { #[derive(Debug, Copy, Clone, PartialEq, Eq)] enum Target { - Host, + System, Linux32, Linux64, Wasm32, @@ -549,7 +549,7 @@ enum Target { impl Default for Target { fn default() -> Self { - Target::Host + Target::System } } @@ -558,7 +558,7 @@ impl Target { use Target::*; match self { - Host => "host", + System => "system", Linux32 => "linux32", Linux64 => "linux64", Wasm32 => "wasm32", @@ -567,7 +567,7 @@ impl Target { /// NOTE keep up to date! const OPTIONS: &'static [&'static str] = &[ - Target::Host.as_str(), + Target::System.as_str(), Target::Linux32.as_str(), Target::Linux64.as_str(), Target::Wasm32.as_str(), @@ -577,7 +577,7 @@ impl Target { use Target::*; match self { - Host => Triple::host(), + System => Triple::host(), Linux32 => Triple { architecture: Architecture::X86_32(X86_32Architecture::I386), vendor: Vendor::Unknown, @@ -620,7 +620,7 @@ impl std::str::FromStr for Target { fn from_str(s: &str) -> Result { match s { - "host" => Ok(Target::Host), + "system" => Ok(Target::System), "linux32" => Ok(Target::Linux32), "linux64" => Ok(Target::Linux64), "wasm32" => Ok(Target::Wasm32), From 03c189c0490d4b57b4b21fbab59694342c23377a Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 14 Apr 2022 21:52:00 -0400 Subject: [PATCH 253/846] c-c-c-c-clippy! (turn and face the strange) --- cli/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 4791d29448..31d8e2adec 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -573,7 +573,7 @@ impl Target { Target::Wasm32.as_str(), ]; - fn to_triple(&self) -> Triple { + fn to_triple(self) -> Triple { use Target::*; match self { From 4065645d3c931e4b15a1e2d3655c7cc5e6a39843 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 15 Apr 2022 08:46:12 -0400 Subject: [PATCH 254/846] Fix references to obsolete CLI flags --- cli/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 31d8e2adec..8124054a21 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -113,7 +113,7 @@ pub fn build_app<'a>() -> App<'a> { .arg( Arg::new(FLAG_LINK) .long(FLAG_LINK) - .about("Deprecated in favor of --force-roc-linker and --legacy-linker") + .about("Deprecated in favor of --linker") .required(false), ) .arg( @@ -335,7 +335,7 @@ pub fn build(matches: &ArgMatches, config: BuildConfig) -> io::Result { process::exit(1); } - // Use surgical linking when supported, or when explicitly requested with --force-roc-linker + // Use surgical linking when supported, or when explicitly requested with --linker surgical let surgically_link = if matches.is_present(FLAG_LINKER) { matches.value_of(FLAG_LINKER) == Some("surgical") } else { From fbe7ccf4c8da9eaab70044f13f4e8b4049dcb7de Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 15 Apr 2022 08:51:29 -0400 Subject: [PATCH 255/846] Use error macro --- compiler/unify/src/unify.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/unify/src/unify.rs b/compiler/unify/src/unify.rs index 35685d8a4c..6aa294f461 100644 --- a/compiler/unify/src/unify.rs +++ b/compiler/unify/src/unify.rs @@ -1,5 +1,5 @@ use bitflags::bitflags; -use roc_error_macros::todo_abilities; +use roc_error_macros::{internal_error, todo_abilities}; use roc_module::ident::{Lowercase, TagName}; use roc_module::symbol::Symbol; use roc_types::subs::Content::{self, *}; @@ -147,7 +147,7 @@ impl Unified { vars, must_implement_ability, } => (vars, must_implement_ability), - _ => panic!("{}", err_msg), + _ => internal_error!("{}", err_msg), } } } From 56f97a2edc8b7ff23fa82b348fb8c0429d603eaa Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 15 Apr 2022 09:24:57 -0400 Subject: [PATCH 256/846] Fix some cli_run warnings --- cli/tests/cli_run.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cli/tests/cli_run.rs b/cli/tests/cli_run.rs index 9b2a36b0ac..6b740b93ad 100644 --- a/cli/tests/cli_run.rs +++ b/cli/tests/cli_run.rs @@ -2,13 +2,11 @@ extern crate pretty_assertions; extern crate bumpalo; +extern crate indoc; extern crate roc_collections; extern crate roc_load; extern crate roc_module; -#[macro_use] -extern crate indoc; - #[cfg(test)] mod cli_run { use cli_utils::helpers::{ @@ -228,6 +226,7 @@ mod cli_run { ($($test_name:ident:$name:expr => $example:expr,)+) => { $( #[test] + #[allow(non_snake_case)] fn $test_name() { let dir_name = $name; let example = $example; From 7d4a0063778caa3ffd0ec314794ff96b1a4a4a49 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 15 Apr 2022 09:29:12 -0400 Subject: [PATCH 257/846] Bugfix sorting must implement constraints Also makes things go faster --- compiler/solve/src/ability.rs | 72 ++++++++++++++++++++--------------- compiler/unify/src/unify.rs | 35 +++++++++++++++-- 2 files changed, 72 insertions(+), 35 deletions(-) diff --git a/compiler/solve/src/ability.rs b/compiler/solve/src/ability.rs index 3d51f150ee..a9796590cf 100644 --- a/compiler/solve/src/ability.rs +++ b/compiler/solve/src/ability.rs @@ -5,6 +5,7 @@ use roc_types::subs::Subs; use roc_types::subs::Variable; use roc_types::types::{Category, PatternCategory}; use roc_unify::unify::MustImplementAbility; +use roc_unify::unify::MustImplementConstraints; use crate::solve::{IncompleteAbilityImplementation, TypeError}; @@ -19,17 +20,14 @@ pub enum AbilityImplError { } #[derive(Default)] -pub struct DeferredMustImplementAbility(Vec<(Vec, AbilityImplError)>); +pub struct DeferredMustImplementAbility(Vec<(MustImplementConstraints, AbilityImplError)>); impl DeferredMustImplementAbility { - pub fn add(&mut self, must_implement: Vec, on_error: AbilityImplError) { + pub fn add(&mut self, must_implement: MustImplementConstraints, on_error: AbilityImplError) { self.0.push((must_implement, on_error)); } pub fn check(self, subs: &mut Subs, abilities_store: &AbilitiesStore) -> Vec { - // Two passes here. First up let's build up records of what types fully implement - // abilities, and what specializations are available/missing for the ones that don't. - // Use a vec since these lists should usually be pretty small. let mut good = vec![]; let mut bad = vec![]; @@ -46,8 +44,21 @@ impl DeferredMustImplementAbility { }; } - for (mias, _) in self.0.iter() { - for &mia @ MustImplementAbility { typ, ability } in mias { + let mut problems = vec![]; + + // Keep track of which types that have an incomplete ability were reported as part of + // another type error (from an expression or pattern). If we reported an error for a type + // that doesn't implement an ability in that context, we don't want to repeat the error + // message. + let mut reported_in_context = vec![]; + let mut incomplete_not_in_context = vec![]; + + for (constraints, on_error) in self.0.into_iter() { + let must_implement = constraints.get_unique(); + + // First off, make sure we populate information about which of the "must implement" + // constraints are met, and which aren't. + for &mia @ MustImplementAbility { typ, ability } in must_implement.iter() { if is_good!(&mia) || get_bad!(mia).is_some() { continue; } @@ -81,22 +92,16 @@ impl DeferredMustImplementAbility { )); } } - } - // Now figure out what errors we need to report. - let mut problems = vec![]; - - // Keep track of which types that have an incomplete ability were reported as part of - // another type error (from an expression or pattern). If we reported an error for a type - // that doesn't implement an ability in that context, we don't want to repeat the error - // message. - let mut reported_in_context = vec![]; - let mut incomplete_not_in_context = vec![]; - - for (must_implement, on_error) in self.0.into_iter() { + // Now, figure out what errors we need to report. use AbilityImplError::*; match on_error { IncompleteAbility => { + // These aren't attached to another type error, so if these must_implement + // constraints aren't met, we'll emit a generic "this type doesn't implement an + // ability" error message at the end. We only want to do this if it turns out + // the "must implement" constraint indeed wasn't part of a more specific type + // error. incomplete_not_in_context.extend(must_implement); } BadExpr(region, category, var) => { @@ -139,9 +144,11 @@ impl DeferredMustImplementAbility { reported_in_context.extend(must_implement); } } - }; + } } + // Go through and attach generic "type does not implement ability" errors, if they were not + // part of a larger context. for mia in incomplete_not_in_context.into_iter() { if let Some(must_implement) = get_bad!(mia) { if !reported_in_context.contains(&mia) { @@ -159,22 +166,25 @@ impl DeferredMustImplementAbility { /// Determines what type implements an ability member of a specialized signature, given the /// [MustImplementAbility] constraints of the signature. pub fn type_implementing_member( - specialization_must_implement_constraints: &[MustImplementAbility], + specialization_must_implement_constraints: &MustImplementConstraints, ability: Symbol, ) -> Symbol { - let mut ability_implementations_for_specialization = specialization_must_implement_constraints - .iter() - .filter(|mia| mia.ability == ability) - .collect::>(); - ability_implementations_for_specialization.dedup(); + debug_assert_eq!({ + let ability_implementations_for_specialization = + specialization_must_implement_constraints + .clone() + .get_unique(); - debug_assert!( - ability_implementations_for_specialization.len() == 1, + ability_implementations_for_specialization.len() + }, + 1, "Multiple variables bound to an ability - this is ambiguous and should have been caught in canonicalization: {:?}", - ability_implementations_for_specialization); + specialization_must_implement_constraints + ); - ability_implementations_for_specialization - .pop() + specialization_must_implement_constraints + .iter_for_ability(ability) + .next() .unwrap() .typ } diff --git a/compiler/unify/src/unify.rs b/compiler/unify/src/unify.rs index 6aa294f461..17208e0b47 100644 --- a/compiler/unify/src/unify.rs +++ b/compiler/unify/src/unify.rs @@ -134,14 +134,14 @@ pub struct Context { pub enum Unified { Success { vars: Pool, - must_implement_ability: Vec, + must_implement_ability: MustImplementConstraints, }, Failure(Pool, ErrorType, ErrorType, DoesNotImplementAbility), BadType(Pool, roc_types::types::Problem), } impl Unified { - pub fn expect_success(self, err_msg: &'static str) -> (Pool, Vec) { + pub fn expect_success(self, err_msg: &'static str) -> (Pool, MustImplementConstraints) { match self { Unified::Success { vars, @@ -153,7 +153,7 @@ impl Unified { } /// Specifies that `type` must implement the ability `ability`. -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] pub struct MustImplementAbility { // This only points to opaque type names currently. // TODO(abilities) support structural types in general @@ -161,12 +161,39 @@ pub struct MustImplementAbility { pub ability: Symbol, } +#[derive(Debug, Clone, PartialEq, Eq, Default)] +pub struct MustImplementConstraints(Vec); + +impl MustImplementConstraints { + pub fn push(&mut self, must_implement: MustImplementAbility) { + self.0.push(must_implement) + } + + pub fn extend(&mut self, other: Self) { + self.0.extend(other.0) + } + + pub fn is_empty(&self) -> bool { + self.0.is_empty() + } + + pub fn get_unique(mut self) -> Vec { + self.0.sort(); + self.0.dedup(); + self.0 + } + + pub fn iter_for_ability(&self, ability: Symbol) -> impl Iterator { + self.0.iter().filter(move |mia| mia.ability == ability) + } +} + #[derive(Debug, Default)] pub struct Outcome { mismatches: Vec, /// We defer these checks until the end of a solving phase. /// NOTE: this vector is almost always empty! - must_implement_ability: Vec, + must_implement_ability: MustImplementConstraints, } impl Outcome { From 089a3de22fbc3f06cce6915cb81a37a1c3ba686f Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 15 Apr 2022 09:42:31 -0400 Subject: [PATCH 258/846] Try fixing the Killed: 9 problem on M1 Mac --- cli/src/build.rs | 14 ++++++++++++++ compiler/build/src/link.rs | 7 +++++++ 2 files changed, 21 insertions(+) diff --git a/cli/src/build.rs b/cli/src/build.rs index 0ccf118178..6ad0b58a5a 100644 --- a/cli/src/build.rs +++ b/cli/src/build.rs @@ -255,6 +255,13 @@ pub fn build_file<'a>( } else if matches!(link_type, LinkType::None) { // Just copy the object file to the output folder. binary_path.set_extension(app_extension); + + if cfg!(target_os = "macos") { + // See https://apple.stackexchange.com/a/428388 + // for why we need to remove the file before copying it. + std::fs::remove_file(&binary_path).unwrap(); + } + std::fs::copy(app_o_file, &binary_path).unwrap(); BuildOutcome::NoProblems } else { @@ -346,6 +353,13 @@ fn spawn_rebuild_thread( if surgically_link { // Copy preprocessed host to executable location. let prehost = host_input_path.with_file_name("preprocessedhost"); + + if cfg!(target_os = "macos") { + // See https://apple.stackexchange.com/a/428388 + // for why we need to remove the file before copying it. + std::fs::remove_file(&binary_path).unwrap(); + } + std::fs::copy(prehost, binary_path.as_path()).unwrap(); } let rebuild_host_end = rebuild_host_start.elapsed().unwrap(); diff --git a/compiler/build/src/link.rs b/compiler/build/src/link.rs index a7e32d0328..c5ae5af003 100644 --- a/compiler/build/src/link.rs +++ b/compiler/build/src/link.rs @@ -499,6 +499,13 @@ pub fn rebuild_host( if shared_lib_path.is_some() { // For surgical linking, just copy the dynamically linked rust app. + + if cfg!(target_os = "macos") { + // See https://apple.stackexchange.com/a/428388 + // for why we need to remove the file before copying it. + std::fs::remove_file(&host_dest_native).unwrap(); + } + std::fs::copy(cargo_out_dir.join("host"), host_dest_native).unwrap(); } else { // Cargo hosts depend on a c wrapper for the api. Compile host.c as well. From 0b979ebe1e0f95110c4f4ec3afbf29cb898ad268 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 15 Apr 2022 09:42:44 -0400 Subject: [PATCH 259/846] Revert "Try fixing the Killed: 9 problem on M1 Mac" (this didn't fix it) This reverts commit 089a3de22fbc3f06cce6915cb81a37a1c3ba686f. --- cli/src/build.rs | 14 -------------- compiler/build/src/link.rs | 7 ------- 2 files changed, 21 deletions(-) diff --git a/cli/src/build.rs b/cli/src/build.rs index 6ad0b58a5a..0ccf118178 100644 --- a/cli/src/build.rs +++ b/cli/src/build.rs @@ -255,13 +255,6 @@ pub fn build_file<'a>( } else if matches!(link_type, LinkType::None) { // Just copy the object file to the output folder. binary_path.set_extension(app_extension); - - if cfg!(target_os = "macos") { - // See https://apple.stackexchange.com/a/428388 - // for why we need to remove the file before copying it. - std::fs::remove_file(&binary_path).unwrap(); - } - std::fs::copy(app_o_file, &binary_path).unwrap(); BuildOutcome::NoProblems } else { @@ -353,13 +346,6 @@ fn spawn_rebuild_thread( if surgically_link { // Copy preprocessed host to executable location. let prehost = host_input_path.with_file_name("preprocessedhost"); - - if cfg!(target_os = "macos") { - // See https://apple.stackexchange.com/a/428388 - // for why we need to remove the file before copying it. - std::fs::remove_file(&binary_path).unwrap(); - } - std::fs::copy(prehost, binary_path.as_path()).unwrap(); } let rebuild_host_end = rebuild_host_start.elapsed().unwrap(); diff --git a/compiler/build/src/link.rs b/compiler/build/src/link.rs index c5ae5af003..a7e32d0328 100644 --- a/compiler/build/src/link.rs +++ b/compiler/build/src/link.rs @@ -499,13 +499,6 @@ pub fn rebuild_host( if shared_lib_path.is_some() { // For surgical linking, just copy the dynamically linked rust app. - - if cfg!(target_os = "macos") { - // See https://apple.stackexchange.com/a/428388 - // for why we need to remove the file before copying it. - std::fs::remove_file(&host_dest_native).unwrap(); - } - std::fs::copy(cargo_out_dir.join("host"), host_dest_native).unwrap(); } else { // Cargo hosts depend on a c wrapper for the api. Compile host.c as well. From 00e5205d4c6bb681a9ffda90c0e0f4b13f16f8cf Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 8 Apr 2022 11:57:32 -0400 Subject: [PATCH 260/846] More debugging for unified types --- compiler/unify/src/unify.rs | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/compiler/unify/src/unify.rs b/compiler/unify/src/unify.rs index a586cdaed7..8de5e0245f 100644 --- a/compiler/unify/src/unify.rs +++ b/compiler/unify/src/unify.rs @@ -235,8 +235,10 @@ pub fn unify_pool( } } -fn unify_context(subs: &mut Subs, pool: &mut Pool, ctx: Context) -> Outcome { - if false { +#[cfg(debug_assertions)] +fn debug_print_unified_types(subs: &mut Subs, ctx: &Context, before_unified: bool) { + if std::env::var("ROC_PRINT_UNIFICATIONS").is_ok() { + let time = if before_unified { "START" } else { "END" }; // if true, print the types that are unified. // // NOTE: names are generated here (when creating an error type) and that modifies names @@ -252,8 +254,11 @@ fn unify_context(subs: &mut Subs, pool: &mut Pool, ctx: Context) -> Outcome { let content_1 = subs.get(ctx.first).content; let content_2 = subs.get(ctx.second).content; let mode = if ctx.mode.is_eq() { "~" } else { "+=" }; - println!( - "{:?} {:?} {} {:?} {:?}", + eprintln!( + "{}({:?}-{:?}): {:?} {:?} {} {:?} {:?}", + time, + ctx.first, + ctx.second, ctx.first, roc_types::subs::SubsFmtContent(&content_1, subs), mode, @@ -261,7 +266,13 @@ fn unify_context(subs: &mut Subs, pool: &mut Pool, ctx: Context) -> Outcome { roc_types::subs::SubsFmtContent(&content_2, subs), ); } - match &ctx.first_desc.content { +} + +fn unify_context(subs: &mut Subs, pool: &mut Pool, ctx: Context) -> Outcome { + #[cfg(debug_assertions)] + debug_print_unified_types(subs, &ctx, true); + + let result = match &ctx.first_desc.content { FlexVar(opt_name) => unify_flex(subs, &ctx, opt_name, None, &ctx.second_desc.content), FlexAbleVar(opt_name, ability) => unify_flex( subs, @@ -296,7 +307,12 @@ fn unify_context(subs: &mut Subs, pool: &mut Pool, ctx: Context) -> Outcome { // Error propagates. Whatever we're comparing it to doesn't matter! merge(subs, &ctx, Error) } - } + }; + + #[cfg(debug_assertions)] + debug_print_unified_types(subs, &ctx, true); + + result } #[inline(always)] From 491ec0034a6ccb787e57093da77ae6c0546cbb79 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 15 Apr 2022 10:01:26 -0400 Subject: [PATCH 261/846] Don't try to send type problems over module boundaries Closes #2863 Closes #2858 --- compiler/load_internal/tests/test_load.rs | 61 +++++++++++++++++++++++ compiler/types/src/subs.rs | 12 ++++- 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/compiler/load_internal/tests/test_load.rs b/compiler/load_internal/tests/test_load.rs index 9cc4a46721..5aaace9f19 100644 --- a/compiler/load_internal/tests/test_load.rs +++ b/compiler/load_internal/tests/test_load.rs @@ -815,4 +815,65 @@ mod test_load { err ); } + + #[test] + fn issue_2863_module_type_does_not_exist() { + let modules = vec![ + ( + "platform/Package-Config.roc", + indoc!( + r#" + platform "testplatform" + requires {} { main : Str } + exposes [] + packages {} + imports [] + provides [ mainForHost ] + + mainForHost : Str + mainForHost = main + "# + ), + ), + ( + "Main", + indoc!( + r#" + app "test" + packages { pf: "platform" } + provides [ main ] to pf + + main : DoesNotExist + main = 1 + "# + ), + ), + ]; + + match multiple_modules(modules) { + Err(report) => { + assert_eq!( + report, + indoc!( + " + ── UNRECOGNIZED NAME ─────────────────────────────────────────────────────────── + + I cannot find a `DoesNotExist` value + + 5│ main : DoesNotExist + ^^^^^^^^^^^^ + + Did you mean one of these? + + Dict + Result + List + Nat + " + ) + ) + } + Ok(_) => unreachable!("we expect failure here"), + } + } } diff --git a/compiler/types/src/subs.rs b/compiler/types/src/subs.rs index 827bf03fb9..1aac8b45bd 100644 --- a/compiler/types/src/subs.rs +++ b/compiler/types/src/subs.rs @@ -3,6 +3,7 @@ use crate::types::{ name_type_var, AliasKind, ErrorType, Problem, RecordField, RecordFieldsError, TypeExt, }; use roc_collections::all::{ImMap, ImSet, MutSet, SendMap}; +use roc_error_macros::internal_error; use roc_module::ident::{Lowercase, TagName, Uppercase}; use roc_module::symbol::Symbol; use std::fmt; @@ -4551,6 +4552,13 @@ fn copy_import_to_help(env: &mut CopyImportEnv<'_>, max_rank: Rank, var: Variabl // We have already marked the variable as copied, so we // will not repeat this work or crawl this variable again. match desc.content { + Structure(Erroneous(_)) => { + // Make this into a flex var so that we don't have to copy problems across module + // boundaries - the error will be reported locally. + env.target.set(copy, make_descriptor(FlexVar(None))); + + copy + } Structure(flat_type) => { let new_flat_type = match flat_type { Apply(symbol, arguments) => { @@ -4581,7 +4589,9 @@ fn copy_import_to_help(env: &mut CopyImportEnv<'_>, max_rank: Rank, var: Variabl Func(new_arguments, new_closure_var, new_ret_var) } - same @ EmptyRecord | same @ EmptyTagUnion | same @ Erroneous(_) => same, + Erroneous(_) => internal_error!("I thought this was handled above"), + + same @ EmptyRecord | same @ EmptyTagUnion => same, Record(fields, ext_var) => { let record_fields = { From f56972742fe3522ee583befad61c7790c6b081f5 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 15 Apr 2022 10:21:17 -0400 Subject: [PATCH 262/846] Default to not precompiled --- cli/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 8124054a21..38a52097ed 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -128,7 +128,7 @@ pub fn build_app<'a>() -> App<'a> { .long(FLAG_PRECOMPILED) .about("Assumes the host has been precompiled and skips recompiling the host. (Enabled by default when using a --target other than `--target host`)") .possible_values(["true", "false"]) - .default_value("true") + .default_value("false") .required(false), ) .arg( @@ -234,7 +234,7 @@ pub fn build_app<'a>() -> App<'a> { .long(FLAG_PRECOMPILED) .about("Assumes the host has been precompiled and skips recompiling the host. (Enabled by default when using a --target other than `--target host`)") .possible_values(["true", "false"]) - .default_value("true") + .default_value("false") .required(false), ) .arg( From 95783e03a1ccf102eca1e62c75b6e63ffcb010e9 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 15 Apr 2022 10:21:35 -0400 Subject: [PATCH 263/846] Handle aliasing of ability members --- compiler/mono/src/ir.rs | 148 ++++++++++++++++--------- compiler/test_gen/src/gen_abilities.rs | 25 +++++ 2 files changed, 119 insertions(+), 54 deletions(-) diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index baf8576c49..59d7a69100 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -252,11 +252,22 @@ impl<'a> PartialProc<'a> { } #[derive(Clone, Debug)] -enum PartialExprLink { - Aliases(Symbol), +enum PolymorphicExpr { + /// A root ability member, which must be specialized at a call site, for example + /// "hash" which must be specialized to an exact symbol implementing "hash" for a type. + AbilityMember(Symbol), + /// A polymorphic expression we inline at the usage site. Expr(roc_can::expr::Expr, Variable), } +#[derive(Clone, Debug)] +enum PartialExprLink { + /// The root polymorphic expresison + Sink(PolymorphicExpr), + /// A hop in a partial expression alias chain + Aliases(Symbol), +} + /// A table of symbols to polymorphic expressions. For example, in the program /// /// n = 1 @@ -282,8 +293,8 @@ impl PartialExprs { Self(BumpMap::new_in(arena)) } - fn insert(&mut self, symbol: Symbol, expr: roc_can::expr::Expr, expr_var: Variable) { - self.0.insert(symbol, PartialExprLink::Expr(expr, expr_var)); + fn insert(&mut self, symbol: Symbol, expr: PolymorphicExpr) { + self.0.insert(symbol, PartialExprLink::Sink(expr)); } fn insert_alias(&mut self, symbol: Symbol, aliases: Symbol) { @@ -294,7 +305,7 @@ impl PartialExprs { self.0.contains_key(&symbol) } - fn get(&mut self, mut symbol: Symbol) -> Option<(&roc_can::expr::Expr, Variable)> { + fn get(&mut self, mut symbol: Symbol) -> Option<&PolymorphicExpr> { // In practice the alias chain is very short loop { match self.0.get(&symbol) { @@ -304,8 +315,8 @@ impl PartialExprs { Some(&PartialExprLink::Aliases(real_symbol)) => { symbol = real_symbol; } - Some(PartialExprLink::Expr(expr, var)) => { - return Some((expr, *var)); + Some(PartialExprLink::Sink(expr)) => { + return Some(expr); } } } @@ -4226,7 +4237,7 @@ pub fn with_hole<'a>( match loc_expr.value { roc_can::expr::Expr::Var(proc_name) if is_known(proc_name) => { // This might be an ability member - if so, use the appropriate specialization. - let proc_name = repoint_to_specialization(env, fn_var, proc_name); + let proc_name = get_specialization(env, fn_var, proc_name).unwrap_or(proc_name); // a call by a known name call_by_name( @@ -4336,47 +4347,68 @@ pub fn with_hole<'a>( unreachable!("calling a non-closure layout") } }, - UnspecializedExpr(symbol) => match full_layout { - RawFunctionLayout::Function(arg_layouts, lambda_set, ret_layout) => { - let closure_data_symbol = env.unique_symbol(); + UnspecializedExpr(symbol) => match procs.partial_exprs.get(symbol).unwrap() + { + &PolymorphicExpr::AbilityMember(member) => { + let proc_name = get_specialization(env, fn_var, member).expect("Recorded as an ability member, but it doesn't have a specialization"); - result = match_on_lambda_set( + // a call by a known name + return call_by_name( env, - lambda_set, - closure_data_symbol, - arg_symbols, - arg_layouts, - ret_layout, + procs, + fn_var, + proc_name, + loc_args, + layout_cache, assigned, hole, ); - - let (lambda_expr, lambda_expr_var) = - procs.partial_exprs.get(symbol).unwrap(); - - let snapshot = env.subs.snapshot(); - let cache_snapshot = layout_cache.snapshot(); - let _unified = roc_unify::unify::unify( - env.subs, - fn_var, - lambda_expr_var, - roc_unify::unify::Mode::EQ, - ); - - result = with_hole( - env, - lambda_expr.clone(), - fn_var, - procs, - layout_cache, - closure_data_symbol, - env.arena.alloc(result), - ); - env.subs.rollback_to(snapshot); - layout_cache.rollback_to(cache_snapshot); } - RawFunctionLayout::ZeroArgumentThunk(_) => { - unreachable!("calling a non-closure layout") + PolymorphicExpr::Expr(lambda_expr, lambda_expr_var) => { + match full_layout { + RawFunctionLayout::Function( + arg_layouts, + lambda_set, + ret_layout, + ) => { + let closure_data_symbol = env.unique_symbol(); + + result = match_on_lambda_set( + env, + lambda_set, + closure_data_symbol, + arg_symbols, + arg_layouts, + ret_layout, + assigned, + hole, + ); + + let snapshot = env.subs.snapshot(); + let cache_snapshot = layout_cache.snapshot(); + let _unified = roc_unify::unify::unify( + env.subs, + fn_var, + *lambda_expr_var, + roc_unify::unify::Mode::EQ, + ); + + result = with_hole( + env, + lambda_expr.clone(), + fn_var, + procs, + layout_cache, + closure_data_symbol, + env.arena.alloc(result), + ); + env.subs.rollback_to(snapshot); + layout_cache.rollback_to(cache_snapshot); + } + RawFunctionLayout::ZeroArgumentThunk(_) => { + unreachable!("calling a non-closure layout") + } + } } }, NotASymbol => { @@ -4712,18 +4744,18 @@ pub fn with_hole<'a>( } #[inline(always)] -fn repoint_to_specialization<'a>( +fn get_specialization<'a>( env: &mut Env<'a, '_>, symbol_var: Variable, symbol: Symbol, -) -> Symbol { +) -> Option { use roc_solve::ability::type_implementing_member; use roc_unify::unify::unify; match env.abilities_store.member_def(symbol) { None => { // This is not an ability member, it doesn't need specialization. - symbol + None } Some(member) => { let snapshot = env.subs.snapshot(); @@ -4743,7 +4775,7 @@ fn repoint_to_specialization<'a>( .get_specialization(symbol, specializing_type) .expect("No specialization is recorded - I thought there would only be a type error here."); - specialization.symbol + Some(specialization.symbol) } } } @@ -5664,9 +5696,10 @@ pub fn from_can<'a>( // At the definition site `n = 1` we only know `1` to have the type `[Int *]`, // which won't be refined until the call `asU8 n`. Add it as a partial expression // that will be specialized at each concrete usage site. - procs - .partial_exprs - .insert(*symbol, def.loc_expr.value, def.expr_var); + procs.partial_exprs.insert( + *symbol, + PolymorphicExpr::Expr(def.loc_expr.value, def.expr_var), + ); let result = from_can(env, variable, cont.value, procs, layout_cache); @@ -6372,7 +6405,7 @@ fn store_pattern_help<'a>( match can_pat { Identifier(symbol) => { - if let Some((_, var)) = procs.partial_exprs.get(outer_symbol) { + if let Some(&PolymorphicExpr::Expr(_, var)) = procs.partial_exprs.get(outer_symbol) { // It might be the case that symbol we're storing hasn't been reified to a value // yet, if it's polymorphic. Do that now. stmt = specialize_symbol( @@ -6770,6 +6803,13 @@ fn handle_variable_aliasing<'a, BuildRest>( where BuildRest: FnOnce(&mut Env<'a, '_>, &mut Procs<'a>, &mut LayoutCache<'a>) -> Stmt<'a>, { + if env.abilities_store.is_ability_member_name(right) { + procs + .partial_exprs + .insert(left, PolymorphicExpr::AbilityMember(right)); + return build_rest(env, procs, layout_cache); + } + if procs.partial_exprs.contains(right) { // If `right` links to a partial expression, make sure we link `left` to it as well, so // that usages of it will be specialized when building the rest of the program. @@ -6847,7 +6887,7 @@ fn specialize_symbol<'a>( result: Stmt<'a>, original: Symbol, ) -> Stmt<'a> { - if let Some((expr, expr_var)) = procs.partial_exprs.get(original) { + if let Some(PolymorphicExpr::Expr(expr, expr_var)) = procs.partial_exprs.get(original) { // Specialize the expression type now, based off the `arg_var` we've been given. // TODO: cache the specialized result let snapshot = env.subs.snapshot(); @@ -6855,14 +6895,14 @@ fn specialize_symbol<'a>( let _unified = roc_unify::unify::unify( env.subs, arg_var.unwrap(), - expr_var, + *expr_var, roc_unify::unify::Mode::EQ, ); let result = with_hole( env, expr.clone(), - expr_var, + *expr_var, procs, layout_cache, symbol, diff --git a/compiler/test_gen/src/gen_abilities.rs b/compiler/test_gen/src/gen_abilities.rs index 6522440dc7..9b0b1f0ed5 100644 --- a/compiler/test_gen/src/gen_abilities.rs +++ b/compiler/test_gen/src/gen_abilities.rs @@ -59,3 +59,28 @@ fn hash_specialization_multiple_add() { u64 ); } + +#[test] +#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] +fn alias_member_specialization() { + assert_evals_to!( + indoc!( + r#" + app "test" provides [ main ] to "./platform" + + Hash has + hash : a -> U64 | a has Hash + + Id := U64 + + hash = \$Id n -> n + + main = + aliasedHash = hash + aliasedHash ($Id 1234) + "# + ), + 1234, + u64 + ); +} From e6b0d9a8203bd822a7e906930f411cddf0eda877 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 15 Apr 2022 10:54:35 -0400 Subject: [PATCH 264/846] Fix typo --- compiler/mono/src/ir.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 59d7a69100..c025d5fa19 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -262,7 +262,7 @@ enum PolymorphicExpr { #[derive(Clone, Debug)] enum PartialExprLink { - /// The root polymorphic expresison + /// The root polymorphic expression Sink(PolymorphicExpr), /// A hop in a partial expression alias chain Aliases(Symbol), From 34813eeae1fa5c2d631253b4202fd814b767269a Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 15 Apr 2022 10:54:54 -0400 Subject: [PATCH 265/846] Update AUTHORS --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index cd10ba4f0c..6ee89aec52 100644 --- a/AUTHORS +++ b/AUTHORS @@ -74,3 +74,4 @@ Ananda Umamil SylvanSign Nikita Mounier <36044205+nikitamounier@users.noreply.github.com> Cai Bingjun <62678643+C-BJ@users.noreply.github.com> +Jared Cone From c67a1bb8d41966b7c551678048c7691abdbcad02 Mon Sep 17 00:00:00 2001 From: Sean Hagstrom Date: Fri, 15 Apr 2022 13:36:27 +0100 Subject: [PATCH 266/846] fix(repl) and fix(pretty_print): update pretty_print output for `Num FloatingPoint *` to be `Float *` instead of `F64` --- compiler/solve/tests/solve_expr.rs | 6 +++--- compiler/types/src/pretty_print.rs | 13 ++++++++++++- repl_test/src/tests.rs | 6 +++--- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index cf822538a2..e08c2e049b 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -2397,7 +2397,7 @@ mod solve_expr { { numIdentity, x : numIdentity 42, y } "# ), - "{ numIdentity : Num a -> Num a, x : Num a, y : F64 }", + "{ numIdentity : Num a -> Num a, x : Num a, y : Float * }", ); } @@ -3820,7 +3820,7 @@ mod solve_expr { negatePoint { x: 1, y: 2.1, z: 0x3 } "# ), - "{ x : Num a, y : F64, z : Int * }", + "{ x : Num a, y : Float *, z : Int * }", ); } @@ -3837,7 +3837,7 @@ mod solve_expr { { a, b } "# ), - "{ a : { x : Num a, y : F64, z : c }, b : { blah : Str, x : Num a, y : F64, z : c } }", + "{ a : { x : Num a, y : Float *, z : c }, b : { blah : Str, x : Num a, y : Float *, z : c } }", ); } diff --git a/compiler/types/src/pretty_print.rs b/compiler/types/src/pretty_print.rs index e4e8456fe3..148186e444 100644 --- a/compiler/types/src/pretty_print.rs +++ b/compiler/types/src/pretty_print.rs @@ -387,7 +387,18 @@ fn write_content<'a>( false, ); } - Symbol::NUM_FLOATINGPOINT => buf.push_str("F64"), + Symbol::NUM_FLOATINGPOINT => { + let content = get_single_arg(subs, &args); + match content { + Alias(Symbol::NUM_BINARY32, _, _, _) => buf.push_str("F32"), + Alias(Symbol::NUM_BINARY64, _, _, _) => buf.push_str("F64"), + Alias(Symbol::NUM_DECIMAL, _, _, _) => buf.push_str("Dec"), + _ => write_parens!(write_parens, buf, { + buf.push_str("Float "); + write_content(env, ctx, content, subs, buf, parens); + }), + } + } _ => write_parens!(write_parens, buf, { buf.push_str("Num "); diff --git a/repl_test/src/tests.rs b/repl_test/src/tests.rs index 9f46137f38..d0360ac569 100644 --- a/repl_test/src/tests.rs +++ b/repl_test/src/tests.rs @@ -50,7 +50,7 @@ fn int_addition() { #[test] fn float_addition() { - expect_success("1.1 + 2", "3.1 : F64"); + expect_success("1.1 + 2", "3.1 : Float *"); } #[cfg(not(feature = "wasm"))] @@ -309,7 +309,7 @@ fn nested_int_list() { fn nested_float_list() { expect_success( r#"[ [ [ 4, 3, 2 ], [ 1, 0.0 ] ], [ [] ], [] ]"#, - r#"[ [ [ 4, 3, 2 ], [ 1, 0 ] ], [ [] ], [] ] : List (List (List F64))"#, + r#"[ [ [ 4, 3, 2 ], [ 1, 0 ] ], [ [] ], [] ] : List (List (List (Float *)))"#, ); } @@ -403,7 +403,7 @@ fn list_contains() { fn list_sum() { expect_success("List.sum []", "0 : Num *"); expect_success("List.sum [ 1, 2, 3 ]", "6 : Num *"); - expect_success("List.sum [ 1.1, 2.2, 3.3 ]", "6.6 : F64"); + expect_success("List.sum [ 1.1, 2.2, 3.3 ]", "6.6 : Float *"); } #[cfg(not(feature = "wasm"))] From 37d3e355ca42d6523b31126eb6a0ed02de198986 Mon Sep 17 00:00:00 2001 From: Sean Hagstrom Date: Fri, 15 Apr 2022 15:02:55 +0100 Subject: [PATCH 267/846] refactor the logic for pretty printing float types into one function --- compiler/types/src/pretty_print.rs | 71 ++++++++++++++++-------------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/compiler/types/src/pretty_print.rs b/compiler/types/src/pretty_print.rs index 148186e444..998684d777 100644 --- a/compiler/types/src/pretty_print.rs +++ b/compiler/types/src/pretty_print.rs @@ -387,18 +387,15 @@ fn write_content<'a>( false, ); } - Symbol::NUM_FLOATINGPOINT => { - let content = get_single_arg(subs, &args); - match content { - Alias(Symbol::NUM_BINARY32, _, _, _) => buf.push_str("F32"), - Alias(Symbol::NUM_BINARY64, _, _, _) => buf.push_str("F64"), - Alias(Symbol::NUM_DECIMAL, _, _, _) => buf.push_str("Dec"), - _ => write_parens!(write_parens, buf, { - buf.push_str("Float "); - write_content(env, ctx, content, subs, buf, parens); - }), - } - } + Symbol::NUM_FLOATINGPOINT => write_float( + env, + ctx, + get_single_arg(subs, &args), + subs, + buf, + parens, + write_parens, + ), _ => write_parens!(write_parens, buf, { buf.push_str("Num "); @@ -419,26 +416,15 @@ fn write_content<'a>( write_integer(env, ctx, content, subs, buf, parens, write_parens) } - Symbol::NUM_FLOAT => { - debug_assert_eq!(args.len(), 1); - - let arg_var_index = args - .into_iter() - .next() - .expect("Num was not applied to a type argument!"); - let arg_var = subs[arg_var_index]; - let content = subs.get_content_without_compacting(arg_var); - - match content { - Alias(Symbol::NUM_BINARY32, _, _, _) => buf.push_str("F32"), - Alias(Symbol::NUM_BINARY64, _, _, _) => buf.push_str("F64"), - Alias(Symbol::NUM_DECIMAL, _, _, _) => buf.push_str("Dec"), - _ => write_parens!(write_parens, buf, { - buf.push_str("Float "); - write_content(env, ctx, content, subs, buf, parens); - }), - } - } + Symbol::NUM_FLOAT => write_float( + env, + ctx, + get_single_arg(subs, args), + subs, + buf, + parens, + write_parens, + ), _ => write_parens!(write_parens, buf, { write_symbol(env, *symbol, buf); @@ -478,6 +464,27 @@ fn write_content<'a>( } } +fn write_float<'a>( + env: &Env, + ctx: &mut Context<'a>, + content: &Content, + subs: &'a Subs, + buf: &mut String, + parens: Parens, + write_parens: bool, +) { + use crate::subs::Content::*; + match content { + Alias(Symbol::NUM_BINARY32, _, _, _) => buf.push_str("F32"), + Alias(Symbol::NUM_BINARY64, _, _, _) => buf.push_str("F64"), + Alias(Symbol::NUM_DECIMAL, _, _, _) => buf.push_str("Dec"), + _ => write_parens!(write_parens, buf, { + buf.push_str("Float "); + write_content(env, ctx, content, subs, buf, parens); + }), + } +} + fn write_integer<'a>( env: &Env, ctx: &mut Context<'a>, From b60235f3af0f3da52ddf369bb31cc248eba0e63c Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 15 Apr 2022 12:12:50 -0400 Subject: [PATCH 268/846] Change TEST_SURGICAL_LINKER to TEST_LEGACY_LINKER --- cli/tests/cli_run.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cli/tests/cli_run.rs b/cli/tests/cli_run.rs index 6b740b93ad..93c72d421b 100644 --- a/cli/tests/cli_run.rs +++ b/cli/tests/cli_run.rs @@ -23,11 +23,12 @@ mod cli_run { use roc_collections::all::MutMap; #[cfg(all(target_os = "linux", target_arch = "x86_64"))] - const TEST_SURGICAL_LINKER: bool = true; + const TEST_LEGACY_LINKER: bool = true; - // Surgical linker currently only supports linux x86_64. + // Surgical linker currently only supports linux x86_64, + // so we're always testing the legacy linker on other targets. #[cfg(not(all(target_os = "linux", target_arch = "x86_64")))] - const TEST_SURGICAL_LINKER: bool = false; + const TEST_LEGACY_LINKER: bool = false; #[cfg(not(target_os = "macos"))] const ALLOW_VALGRIND: bool = true; @@ -287,14 +288,14 @@ mod cli_run { example.use_valgrind, ); - // Also check with the surgical linker. + // Also check with the legacy linker. - if TEST_SURGICAL_LINKER { + if TEST_LEGACY_LINKER { check_output_with_stdin( &file_name, example.stdin, example.executable_filename, - &["--roc-linker"], + &["--linker", "legacy"], example.input_file.and_then(|file| Some(example_file(dir_name, file))), example.expected_ending, example.use_valgrind, From d5c843a771e2aa3f2d451029aefaec305f0e69a1 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 15 Apr 2022 12:13:05 -0400 Subject: [PATCH 269/846] Don't use deprecated --roc-linker flag in tests --- cli/tests/cli_run.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/cli/tests/cli_run.rs b/cli/tests/cli_run.rs index 93c72d421b..32ef62de18 100644 --- a/cli/tests/cli_run.rs +++ b/cli/tests/cli_run.rs @@ -252,12 +252,7 @@ mod cli_run { } "hello-gui" => { // Since this one requires opening a window, we do `roc build` on it but don't run it. - if cfg!(all(target_os = "linux", target_arch = "x86_64")) { - // The surgical linker can successfully link this on Linux, but the legacy linker errors! - build_example(&file_name, &["--optimize", "--roc-linker"]); - } else { - build_example(&file_name, &["--optimize"]); - } + build_example(&file_name, &["--optimize"]); return; } From be4fee6b5c00fe9c59c15e60135a980b086d48be Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 15 Apr 2022 12:23:03 -0400 Subject: [PATCH 270/846] Add Sean Hagstrom to AUTHORS --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 6ee89aec52..88baae4952 100644 --- a/AUTHORS +++ b/AUTHORS @@ -75,3 +75,4 @@ SylvanSign Nikita Mounier <36044205+nikitamounier@users.noreply.github.com> Cai Bingjun <62678643+C-BJ@users.noreply.github.com> Jared Cone +Sean Hagstrom From 1b2ae945914ae0a8bec527ec8576f3bd2a56ce0e Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 15 Apr 2022 12:54:52 -0400 Subject: [PATCH 271/846] Fix Rgba conversion in breakout --- examples/breakout/platform/src/graphics/colors.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/breakout/platform/src/graphics/colors.rs b/examples/breakout/platform/src/graphics/colors.rs index 3ec448413f..71be9c8fa5 100644 --- a/examples/breakout/platform/src/graphics/colors.rs +++ b/examples/breakout/platform/src/graphics/colors.rs @@ -19,7 +19,7 @@ impl Rgba { } pub const fn to_array(self) -> [f32; 4] { - [self.r, self.b, self.g, self.a] + [self.r, self.g, self.b, self.a] } pub fn from_hsb(hue: usize, saturation: usize, brightness: usize) -> Self { From 03db0d3206d008a6ef090b2ef90500591d1fc6b5 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 15 Apr 2022 12:55:08 -0400 Subject: [PATCH 272/846] Add ball to breakout example --- examples/breakout/breakout.roc | 44 +++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index dab0335aef..56980beaed 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -3,19 +3,40 @@ app "breakout" imports [ pf.Game.{ Bounds, Elem, Event } ] provides [ program ] { Model } to pf -Model : { height : F32, width : F32, pos : F32 } +Model : { + # Screen height and width + height : F32, + width : F32, -program = { init, update, render } + # Paddle X-coordinate + paddleX : F32, + + # Ball coordinates + ballX : F32, + ballY : F32, +} init : Bounds -> Model -init = \_ -> { width: 1900, height: 1000, pos: 100 } +init = \{ width, height } -> + { + # Screen height and width + width, + height, + + # Paddle X-coordinate + paddleX: (width * 0.5), + + # Ball coordinates + ballX: (width * 0.5), + ballY : (height * 0.5), + } update : Model, Event -> Model update = \model, event -> when event is Resize size -> { model & width: size.width, height: size.height } KeyUp _ -> model - KeyDown keyCode -> { model & pos: model.pos + 50 } + KeyDown keyCode -> { model & paddleX: model.paddleX + 50 } render : Model -> List Elem render = \model -> @@ -51,13 +72,24 @@ render = \model -> Rect { left, top, width: blockWidth, height: blockHeight, color } + ball = + color = { r: 0.7, g: 0.3, b: 0.9, a: 1.0 } + width = 50 + height = 50 + left = model.ballX + top = model.ballY + + Rect { left, top, width, height, color } + paddle = color = { r: 0.8, g: 0.8, b: 0.8, a: 1.0 } width = model.width * 0.25 height = blockHeight - left = (model.width * 0.5) - (width * 0.5) + model.pos + left = (model.width * 0.5) - (width * 0.5) + model.paddleX top = model.height - (height * 2) Rect { left, top, width, height, color } - List.append rects paddle + List.concat rects [ paddle, ball ] + +program = { init, update, render } From bb9e30e361072effe0aebf05d075391934897764 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 15 Apr 2022 13:08:22 -0400 Subject: [PATCH 273/846] Move the paddle left and right --- examples/breakout/breakout.roc | 4 +++- examples/breakout/platform/Game.roc | 4 +++- examples/breakout/platform/src/gui.rs | 15 ++++++++------ examples/breakout/platform/src/roc.rs | 29 +++++++++++++++++++++++---- 4 files changed, 40 insertions(+), 12 deletions(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index 56980beaed..8bce971b03 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -36,7 +36,9 @@ update = \model, event -> when event is Resize size -> { model & width: size.width, height: size.height } KeyUp _ -> model - KeyDown keyCode -> { model & paddleX: model.paddleX + 50 } + KeyDown Left -> { model & paddleX: model.paddleX - 50 } + KeyDown Right -> { model & paddleX: model.paddleX + 50 } + KeyDown _ -> model render : Model -> List Elem render = \model -> diff --git a/examples/breakout/platform/Game.roc b/examples/breakout/platform/Game.roc index a70d7542bf..0fae5ff006 100644 --- a/examples/breakout/platform/Game.roc +++ b/examples/breakout/platform/Game.roc @@ -8,5 +8,7 @@ Bounds : { height : F32, width: F32 } Elem : [ Rect { color : Rgba, left : F32, top : F32, width : F32, height : F32 }, Text Str ] -Event : [ Resize { width : F32, height : F32 }, KeyDown U32, KeyUp U32 ] +KeyCode : [ Left, Right, Other ] + +Event : [ Resize { width : F32, height : F32 }, KeyDown KeyCode, KeyUp KeyCode ] diff --git a/examples/breakout/platform/src/gui.rs b/examples/breakout/platform/src/gui.rs index 25c44af7c7..15abb1af31 100644 --- a/examples/breakout/platform/src/gui.rs +++ b/examples/breakout/platform/src/gui.rs @@ -151,10 +151,13 @@ pub fn run_event_loop(title: &str, window_bounds: Bounds) -> Result<(), Box Result<(), Box { let roc_event = match input_state { - ElementState::Pressed => RocEvent::key_down(keycode), - ElementState::Released => RocEvent::key_up(keycode), + ElementState::Pressed => RocEvent::key_down(keycode.into()), + ElementState::Released => RocEvent::key_up(keycode.into()), }; // TODO use (model, elems) = ... once we've upgraded rust versions diff --git a/examples/breakout/platform/src/roc.rs b/examples/breakout/platform/src/roc.rs index 3699a23e5d..ea70719a53 100644 --- a/examples/breakout/platform/src/roc.rs +++ b/examples/breakout/platform/src/roc.rs @@ -56,8 +56,8 @@ extern "C" { #[repr(C)] pub union RocEventEntry { - pub key_down: winit::event::VirtualKeyCode, - pub key_up: winit::event::VirtualKeyCode, + pub key_down: RocKeyCode, + pub key_up: RocKeyCode, pub resize: Bounds, } @@ -106,14 +106,14 @@ impl RocEvent { } } - pub fn key_down(keycode: VirtualKeyCode) -> Self { + pub fn key_down(keycode: RocKeyCode) -> Self { Self { tag: RocEventTag::KeyDown, entry: RocEventEntry { key_down: keycode }, } } - pub fn key_up(keycode: VirtualKeyCode) -> Self { + pub fn key_up(keycode: RocKeyCode) -> Self { Self { tag: RocEventTag::KeyUp, entry: RocEventEntry { key_up: keycode }, @@ -121,6 +121,27 @@ impl RocEvent { } } +#[repr(u8)] +#[allow(unused)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum RocKeyCode { + Left = 0, + Other, + Right, +} + +impl From for RocKeyCode { + fn from(keycode: VirtualKeyCode) -> Self { + use VirtualKeyCode::*; + + match keycode { + Left => RocKeyCode::Left, + Right => RocKeyCode::Right, + _ => RocKeyCode::Other, + } + } +} + #[no_mangle] pub unsafe extern "C" fn roc_alloc(size: usize, _alignment: u32) -> *mut c_void { return libc::malloc(size); From eda9c411d85fab1565dd8b5bc16a2f11ee61ccbd Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 15 Apr 2022 13:20:31 -0400 Subject: [PATCH 274/846] Use more named constants in breakout --- examples/breakout/breakout.roc | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index 8bce971b03..9f619a3d1f 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -3,6 +3,10 @@ app "breakout" imports [ pf.Game.{ Bounds, Elem, Event } ] provides [ program ] { Model } to pf +paddleWidth = 0.2 # width of the paddle, as a % of screen width +paddleHeight = 50 # height of the paddle, in pixels +paddleSpeed = 60 # how many pixels the paddle moves per keypress + Model : { # Screen height and width height : F32, @@ -24,7 +28,7 @@ init = \{ width, height } -> height, # Paddle X-coordinate - paddleX: (width * 0.5), + paddleX: (width * 0.5) - (paddleWidth * width * 0.5), # Ball coordinates ballX: (width * 0.5), @@ -35,10 +39,9 @@ update : Model, Event -> Model update = \model, event -> when event is Resize size -> { model & width: size.width, height: size.height } - KeyUp _ -> model - KeyDown Left -> { model & paddleX: model.paddleX - 50 } - KeyDown Right -> { model & paddleX: model.paddleX + 50 } - KeyDown _ -> model + KeyDown Left -> { model & paddleX: model.paddleX - paddleSpeed } + KeyDown Right -> { model & paddleX: model.paddleX + paddleSpeed } + _ -> model render : Model -> List Elem render = \model -> @@ -85,10 +88,10 @@ render = \model -> paddle = color = { r: 0.8, g: 0.8, b: 0.8, a: 1.0 } - width = model.width * 0.25 - height = blockHeight - left = (model.width * 0.5) - (width * 0.5) + model.paddleX - top = model.height - (height * 2) + width = model.width * paddleWidth + height = paddleHeight + left = model.paddleX + top = model.height - blockHeight - height Rect { left, top, width, height, color } From 9a89287365b09515090c366c696667fdaf5738bc Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 15 Apr 2022 16:23:27 -0400 Subject: [PATCH 275/846] Don't specify a default value for --precompiled-host If we do, it's treated as always present even if it's not passed in, which overrides the default of "infer based on target." --- cli/src/lib.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 38a52097ed..792071fbcd 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -128,7 +128,6 @@ pub fn build_app<'a>() -> App<'a> { .long(FLAG_PRECOMPILED) .about("Assumes the host has been precompiled and skips recompiling the host. (Enabled by default when using a --target other than `--target host`)") .possible_values(["true", "false"]) - .default_value("false") .required(false), ) .arg( @@ -234,7 +233,6 @@ pub fn build_app<'a>() -> App<'a> { .long(FLAG_PRECOMPILED) .about("Assumes the host has been precompiled and skips recompiling the host. (Enabled by default when using a --target other than `--target host`)") .possible_values(["true", "false"]) - .default_value("false") .required(false), ) .arg( From 392b429e1a70d2a557bf6fa30378fc20b7fdae29 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 16 Apr 2022 19:41:29 +0200 Subject: [PATCH 276/846] stop skipping builtin imports --- compiler/constrain/src/module.rs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/compiler/constrain/src/module.rs b/compiler/constrain/src/module.rs index 8537932a72..26fff0e73a 100644 --- a/compiler/constrain/src/module.rs +++ b/compiler/constrain/src/module.rs @@ -64,17 +64,8 @@ impl ExposedForModule { let mut imported_values = Vec::new(); for symbol in it { - // Today, builtins are not actually imported, - // but generated in each module that uses them - // - // This will change when we write builtins in roc - if symbol.is_builtin() { - continue; - } - - if let Some(ExposedModuleTypes::Valid { .. }) = - exposed_by_module.exposed.get(&symbol.module_id()) - { + let module = exposed_by_module.exposed.get(&symbol.module_id()); + if let Some(ExposedModuleTypes::Valid { .. }) = module { imported_values.push(*symbol); } else { continue; From 1568a57de099d0b376545526d87d12c5dbaf6bb6 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 16 Apr 2022 19:42:08 +0200 Subject: [PATCH 277/846] turn panic into runtime error --- compiler/mono/src/ir.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 715f0b526a..767e9700e5 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -6844,9 +6844,10 @@ fn specialize_symbol<'a>( None => { match arg_var { Some(arg_var) if env.is_imported_symbol(original) => { - let raw = layout_cache - .raw_from_var(env.arena, arg_var, env.subs) - .expect("creating layout does not fail"); + let raw = match layout_cache.raw_from_var(env.arena, arg_var, env.subs) { + Ok(v) => v, + Err(e) => return_on_layout_error_help!(env, e), + }; if procs.is_imported_module_thunk(original) { let layout = match raw { From 86c86ab41e7acf08a7c06d3d7b1ce8c458ed37a5 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 16 Apr 2022 20:35:50 +0200 Subject: [PATCH 278/846] stop inserting builtin implementations in all modules --- compiler/can/src/module.rs | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index 0a6bfe6bf7..78662b0c50 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -534,17 +534,6 @@ pub fn canonicalize_module_defs<'a>( } } - // TODO this loops over all symbols in the module, we can speed it up by having an - // iterator over all builtin symbols - for symbol in referenced_values.iter() { - if symbol.is_builtin() { - // this can fail when the symbol is for builtin types, or has no implementation yet - if let Some(def) = crate::builtins::builtin_defs_map(*symbol, var_store) { - declarations.push(Declaration::Builtin(def)); - } - } - } - let output = ModuleOutput { scope, aliases, From 51a02b05dcecba9e7dee506c47f73e3eccd26b93 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 16 Apr 2022 20:36:25 +0200 Subject: [PATCH 279/846] don't cache builtins when the target is wasm (wasm declaration order is different from the cached version we make at compile time) --- compiler/load/src/lib.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/compiler/load/src/lib.rs b/compiler/load/src/lib.rs index 065e263467..812f95edc9 100644 --- a/compiler/load/src/lib.rs +++ b/compiler/load/src/lib.rs @@ -173,14 +173,20 @@ fn deserialize_help(bytes: &[u8]) -> (Subs, Vec<(Symbol, Variable)>) { fn read_cached_subs() -> MutMap)> { let mut output = MutMap::default(); - output.insert(ModuleId::BOOL, deserialize_help(BOOL)); - output.insert(ModuleId::RESULT, deserialize_help(RESULT)); - output.insert(ModuleId::LIST, deserialize_help(LIST)); - output.insert(ModuleId::STR, deserialize_help(STR)); - output.insert(ModuleId::DICT, deserialize_help(DICT)); - output.insert(ModuleId::SET, deserialize_help(SET)); - output.insert(ModuleId::BOX, deserialize_help(BOX)); - output.insert(ModuleId::NUM, deserialize_help(NUM)); + // Wasm seems to re-order definitions between build time and runtime, but only in release mode. + // That is very strange, but we can solve it separately + if !cfg!(target_family = "wasm") { + output.insert(ModuleId::BOOL, deserialize_help(BOOL)); + output.insert(ModuleId::RESULT, deserialize_help(RESULT)); + output.insert(ModuleId::NUM, deserialize_help(NUM)); + + output.insert(ModuleId::LIST, deserialize_help(LIST)); + output.insert(ModuleId::STR, deserialize_help(STR)); + output.insert(ModuleId::DICT, deserialize_help(DICT)); + + output.insert(ModuleId::SET, deserialize_help(SET)); + output.insert(ModuleId::BOX, deserialize_help(BOX)); + } output } From c6f10011614f78adee1e34881b10efa650d5fd17 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 16 Apr 2022 21:38:39 +0200 Subject: [PATCH 280/846] fix reporting tests --- reporting/tests/test_reporting.rs | 45 +++++++++++++------------------ 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index ce3bd5721a..65030ebcb1 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -9190,16 +9190,6 @@ I need all branches in an `if` to have the same type! 3│ Hash has hash : a, b -> Num.U64 | a has Hash, b has Bool.Bool ^^^^^^^^^ - - ── UNUSED DEFINITION ─────────────────────────────────────────────────────────── - - `hash` is not used anywhere in your code. - - 3│ Hash has hash : a, b -> Num.U64 | a has Hash, b has Bool.Bool - ^^^^ - - If you didn't intend on using `hash` then remove it so future readers of - your code don't wonder why it is there. "# ), ) @@ -9294,27 +9284,27 @@ I need all branches in an `if` to have the same type! indoc!( r#" ── DUPLICATE NAME ────────────────────────────────────────────────────────────── - + The `Ability` name is first defined here: - - 1│ Ability has ab : a -> Num.U64 | a has Ability - ^^^^^^^ - + + 4│ Ability has ab : a -> Num.U64 | a has Ability + ^^^^^^^ + But then it's defined a second time here: - - 3│ Ability has ab1 : a -> Num.U64 | a has Ability - ^^^^^^^ - + + 6│ Ability has ab1 : a -> Num.U64 | a has Ability + ^^^^^^^ + Since these abilities have the same name, it's easy to use the wrong one on accident. Give one of them a new name. - + ── UNUSED DEFINITION ─────────────────────────────────────────────────────────── - + `ab` is not used anywhere in your code. - - 1│ Ability has ab : a -> Num.U64 | a has Ability - ^^ - + + 4│ Ability has ab : a -> Num.U64 | a has Ability + ^^ + If you didn't intend on using `ab` then remove it so future readers of your code don't wonder why it is there. "# @@ -9393,6 +9383,7 @@ I need all branches in an `if` to have the same type! 4│ Hash has hash : a, b -> Num.U64 | a has Eq, b has Hash ^^^^^^^^ + Currently, ability members can only bind variables to the ability they are a part of. @@ -9430,7 +9421,7 @@ I need all branches in an `if` to have the same type! bound to the `Eq`` ability:` 3│ Eq has eq : a, b -> Bool.Bool | a has Eq, b has Eq - ^^^^^^^^^^^^^^^^^^ + ^^^^^^^^^^^^^^^^^^ Ability members can only bind one type variable to their parent ability. Otherwise, I wouldn't know what type implements an ability by @@ -9471,7 +9462,7 @@ I need all branches in an `if` to have the same type! A `has` clause is not allowed here: 5│ f : a -> Num.U64 | a has Hash - ^^^^^^^^^^ + ^^^^^^^^^^ `has` clauses can only be specified on the top-level type annotation of an ability member. From cd93cf85cb24bb6a0d3f417a8d96fa376d57bc36 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sun, 17 Apr 2022 02:31:52 -0400 Subject: [PATCH 281/846] Use lto=fat on breakout release builds --- examples/breakout/platform/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/breakout/platform/Cargo.toml b/examples/breakout/platform/Cargo.toml index dee9bee179..47281be89d 100644 --- a/examples/breakout/platform/Cargo.toml +++ b/examples/breakout/platform/Cargo.toml @@ -66,7 +66,7 @@ features = ["derive"] # Optimizations based on https://deterministic.space/high-performance-rust.html [profile.release] -lto = "thin" +lto = "fat" codegen-units = 1 # debug = true # enable when profiling From 5501787e64abddc1aa3f9b4ec4152a97805b1bd7 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 17 Apr 2022 13:53:17 +0200 Subject: [PATCH 282/846] delete unused code --- compiler/types/src/builtin_aliases.rs | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/compiler/types/src/builtin_aliases.rs b/compiler/types/src/builtin_aliases.rs index 129b12d0c4..23b3983cc9 100644 --- a/compiler/types/src/builtin_aliases.rs +++ b/compiler/types/src/builtin_aliases.rs @@ -318,21 +318,6 @@ pub fn aliases() -> MutMap { }, ); - /* - // Result ok err : [ Ok ok, Err err ] - add_alias( - Symbol::RESULT_RESULT, - BuiltinAlias { - region: Region::zero(), - vars: vec![ - Loc::at(Region::zero(), "ok".into()), - Loc::at(Region::zero(), "err".into()), - ], - typ: result_alias_content(flex(TVAR1), flex(TVAR2)), - }, - ); - */ - // Utf8ByteProblem : [ InvalidStartByte, UnexpectedEndOfSequence, ExpectedContinuation, OverlongEncoding, CodepointTooLarge, EncodesSurrogateHalf ] add_alias( Symbol::STR_UT8_BYTE_PROBLEM, From 90a980a3e91f078dd18b489c248647a57af2d9fd Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 17 Apr 2022 13:54:53 +0200 Subject: [PATCH 283/846] remove debug code --- compiler/load_internal/src/file.rs | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index 34e2d5e960..864ef3bb2e 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -3610,20 +3610,6 @@ fn run_solve_solve( abilities_store, ); - let solved_subs = if true { - solved_subs - } else { - let vars_by_symbol: Vec<(Symbol, Variable)> = solved_env.vars_by_symbol().collect(); - let mut serialized = Vec::new(); - solved_subs - .inner() - .serialize(&vars_by_symbol, &mut serialized) - .unwrap(); - let (subs, _vbs) = Subs::deserialize(&serialized); - - Solved(subs) - }; - let exposed_vars_by_symbol: Vec<_> = solved_env .vars_by_symbol() .filter(|(k, _)| exposed_symbols.contains(k)) From d7d884b4f795ad247d507a6076479d798cdf5e6e Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 17 Apr 2022 13:55:21 +0200 Subject: [PATCH 284/846] cleanup --- compiler/load_internal/src/file.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index 864ef3bb2e..870cf57ab5 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -1758,8 +1758,6 @@ fn update<'a>( // add the prelude let mut header = header; - // let mut imports = header.package_qualified_imported_modules.clone(); - // if ![ModuleId::RESULT, ModuleId::BOOL].contains(&header.module_id) { header From 4254ece2c6d7e1b3d84b3d69c2dafd8780840f16 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 17 Apr 2022 14:00:21 +0200 Subject: [PATCH 285/846] stop special-casing builtins --- compiler/solve/src/solve.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index 527f12705c..fb44e44347 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -1016,10 +1016,7 @@ fn solve( } } None => { - // TODO fix this properly - if symbol.module_id() != ModuleId::ATTR { - problems.push(TypeError::UnexposedLookup(*symbol)); - } + problems.push(TypeError::UnexposedLookup(*symbol)); state } From d0c02ada8a41dfa81cabf6184b936cfc5f4b1bc4 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 17 Apr 2022 14:00:34 +0200 Subject: [PATCH 286/846] re-enable ignored test --- compiler/test_gen/src/gen_primitives.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/test_gen/src/gen_primitives.rs b/compiler/test_gen/src/gen_primitives.rs index 999d85eb67..e9de763814 100644 --- a/compiler/test_gen/src/gen_primitives.rs +++ b/compiler/test_gen/src/gen_primitives.rs @@ -2971,7 +2971,6 @@ fn mix_function_and_closure_level_of_indirection() { } #[test] -#[ignore] #[cfg(any(feature = "gen-llvm"))] fn do_pass_bool_byte_closure_layout() { // see https://github.com/rtfeldman/roc/pull/1706 From ec17367707cfd29d6cf0a36f2c6d0cb656a82efa Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 17 Apr 2022 14:46:11 +0200 Subject: [PATCH 287/846] clippy --- compiler/solve/src/solve.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index fb44e44347..2902eaefda 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -6,7 +6,7 @@ use roc_can::constraint::{Constraints, LetConstraint}; use roc_can::expected::{Expected, PExpected}; use roc_collections::all::MutMap; use roc_module::ident::TagName; -use roc_module::symbol::{ModuleId, Symbol}; +use roc_module::symbol::Symbol; use roc_region::all::{Loc, Region}; use roc_types::solved_types::Solved; use roc_types::subs::{ From 2784affbc1a9dc8981fac30dc9bf038c2150f778 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 17 Apr 2022 14:51:56 +0200 Subject: [PATCH 288/846] skip constraint gen for cached modules --- compiler/load_internal/src/file.rs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index 870cf57ab5..a06022ce88 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -286,12 +286,15 @@ fn start_phase<'a>( } } + let skip_constraint_gen = state.cached_subs.lock().contains_key(&module_id); + BuildTask::CanonicalizeAndConstrain { parsed, dep_idents, exposed_symbols, module_ids, aliases, + skip_constraint_gen, } } @@ -810,6 +813,7 @@ enum BuildTask<'a> { dep_idents: MutMap, exposed_symbols: MutSet, aliases: MutMap, + skip_constraint_gen: bool, }, Solve { module: Module, @@ -3767,6 +3771,7 @@ fn canonicalize_and_constrain<'a>( exposed_symbols: MutSet, aliases: MutMap, parsed: ParsedModule<'a>, + skip_constraint_gen: bool, ) -> Result, LoadingProblem<'a>> { let canonicalize_start = SystemTime::now(); @@ -3836,13 +3841,16 @@ fn canonicalize_and_constrain<'a>( let mut constraints = Constraints::new(); - // TODO: don't generate constraints for a builtin module if it's cached - let constraint = constrain_module( - &mut constraints, - &module_output.scope.abilities_store, - &module_output.declarations, - module_id, - ); + let constraint = if skip_constraint_gen { + roc_can::constraint::Constraint::True + } else { + constrain_module( + &mut constraints, + &module_output.scope.abilities_store, + &module_output.declarations, + module_id, + ) + }; let after = roc_types::types::get_type_clone_count(); @@ -4367,6 +4375,7 @@ fn run_task<'a>( dep_idents, exposed_symbols, aliases, + skip_constraint_gen, } => canonicalize_and_constrain( arena, &module_ids, @@ -4374,6 +4383,7 @@ fn run_task<'a>( exposed_symbols, aliases, parsed, + skip_constraint_gen, ), Solve { module, From cf97f8099d789ded7a854355fa150d97a5c0dda2 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sun, 17 Apr 2022 11:37:23 -0400 Subject: [PATCH 289/846] Add basic animation system, add basic gravity --- examples/breakout/breakout.roc | 1 + examples/breakout/platform/Game.roc | 2 +- examples/breakout/platform/src/gui.rs | 94 +++++++++++++-------------- examples/breakout/platform/src/roc.rs | 61 ++++++++++------- 4 files changed, 85 insertions(+), 73 deletions(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index 9f619a3d1f..09b0b6fc3c 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -41,6 +41,7 @@ update = \model, event -> Resize size -> { model & width: size.width, height: size.height } KeyDown Left -> { model & paddleX: model.paddleX - paddleSpeed } KeyDown Right -> { model & paddleX: model.paddleX + paddleSpeed } + Tick _ -> { model & ballY: model.ballY + 1 } _ -> model render : Model -> List Elem diff --git a/examples/breakout/platform/Game.roc b/examples/breakout/platform/Game.roc index 0fae5ff006..5b38203de2 100644 --- a/examples/breakout/platform/Game.roc +++ b/examples/breakout/platform/Game.roc @@ -10,5 +10,5 @@ Elem : [ Rect { color : Rgba, left : F32, top : F32, width : F32, height : F32 } KeyCode : [ Left, Right, Other ] -Event : [ Resize { width : F32, height : F32 }, KeyDown KeyCode, KeyUp KeyCode ] +Event : [ Resize { width : F32, height : F32 }, KeyDown KeyCode, KeyUp KeyCode, Tick U128 ] diff --git a/examples/breakout/platform/src/gui.rs b/examples/breakout/platform/src/gui.rs index 15abb1af31..feece8cb07 100644 --- a/examples/breakout/platform/src/gui.rs +++ b/examples/breakout/platform/src/gui.rs @@ -23,7 +23,7 @@ use wgpu_glyph::GlyphBrush; use winit::{ dpi::PhysicalSize, event, - event::{ElementState, Event, ModifiersState}, + event::{ElementState, Event, ModifiersState, StartCause}, event_loop::ControlFlow, platform::run_return::EventLoopExtRunReturn, }; @@ -34,7 +34,7 @@ use winit::{ // // See this link to learn wgpu: https://sotrh.github.io/learn-wgpu/ -const TIME_BETWEEN_RENDERS: Duration = Duration::new(0, 1000 / 60); +const TIME_BETWEEN_TICKS: Duration = Duration::new(0, 1000 / 60); pub fn run_event_loop(title: &str, window_bounds: Bounds) -> Result<(), Box> { let (mut model, mut elems) = roc::init_and_render(window_bounds); @@ -48,8 +48,19 @@ pub fn run_event_loop(title: &str, window_bounds: Bounds) -> Result<(), Box { + // TODO use (model, elems) = ... once we've upgraded rust versions + let pair = roc::update_and_render(model, $event); + model = pair.0; + elems = pair.1; + + window.request_redraw(); + }; + } + + let instance = wgpu::Instance::new(wgpu::Backends::all()); let surface = unsafe { instance.create_surface(&window) }; // Initialize GPU @@ -100,31 +111,22 @@ pub fn run_event_loop(title: &str, window_bounds: Bounds) -> Result<(), Box *control_flow = ControlFlow::Exit, - //Resize + // Resize Event::WindowEvent { event: event::WindowEvent::Resized(new_size), .. @@ -150,19 +152,10 @@ pub fn run_event_loop(title: &str, window_bounds: Bounds) -> Result<(), Box Result<(), Box RocEvent::key_up(keycode.into()), }; - // TODO use (model, elems) = ... once we've upgraded rust versions - let pair = roc::update_and_render(model, roc_event); - - model = pair.0; - elems = pair.1; - - window.request_redraw(); + model = roc::update(model, roc_event); } - //Modifiers Changed + // Modifiers Changed Event::WindowEvent { event: event::WindowEvent::ModifiersChanged(modifiers), .. @@ -199,16 +186,6 @@ pub fn run_event_loop(title: &str, window_bounds: Bounds) -> Result<(), Box { - // If we shouldn't draw yet, keep waiting until we should. - let current_time = Instant::now(); - - if next_render_time.saturating_duration_since(current_time) > TIME_BETWEEN_RENDERS { - // Keep waiting until it's time to draw again. - return; - } - - next_render_time = current_time + TIME_BETWEEN_RENDERS; - // Get a command cmd_encoder for the current frame let mut cmd_encoder = gpu_device.create_command_encoder(&wgpu::CommandEncoderDescriptor { @@ -262,8 +239,27 @@ pub fn run_event_loop(title: &str, window_bounds: Bounds) -> Result<(), Box { + // Only run this logic if this is the tick we originally requested. + if requested_resume == next_tick { + let now = Instant::now(); + + // Set a new next_tick *before* running update and rerender, + // so their runtime isn't factored into when we want to render next. + next_tick = now + TIME_BETWEEN_TICKS; + + let tick = now.saturating_duration_since(app_start_time); + + update_and_rerender!(RocEvent::tick(tick)); + + *control_flow = winit::event_loop::ControlFlow::WaitUntil(next_tick); + } + } _ => { - *control_flow = winit::event_loop::ControlFlow::Wait; + // Keep waiting until the next tick. + *control_flow = winit::event_loop::ControlFlow::WaitUntil(next_tick); } } }); diff --git a/examples/breakout/platform/src/roc.rs b/examples/breakout/platform/src/roc.rs index ea70719a53..949367e038 100644 --- a/examples/breakout/platform/src/roc.rs +++ b/examples/breakout/platform/src/roc.rs @@ -7,6 +7,7 @@ use std::ffi::CStr; use std::fmt::Debug; use std::mem::MaybeUninit; use std::os::raw::c_char; +use std::time::Duration; use winit::event::VirtualKeyCode; extern "C" { @@ -59,6 +60,7 @@ pub union RocEventEntry { pub key_down: RocKeyCode, pub key_up: RocKeyCode, pub resize: Bounds, + pub tick: u128, } #[repr(u8)] @@ -66,8 +68,9 @@ pub union RocEventEntry { #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum RocEventTag { KeyDown = 0, - KeyUp = 1, - Resize = 2, + KeyUp, + Resize, + Tick, } #[repr(C)] @@ -85,6 +88,7 @@ impl Debug for RocEvent { KeyDown => unsafe { self.entry().key_down }.fmt(f), KeyUp => unsafe { self.entry().key_up }.fmt(f), Resize => unsafe { self.entry().resize }.fmt(f), + Tick => unsafe { self.entry().tick }.fmt(f), } } } @@ -119,6 +123,15 @@ impl RocEvent { entry: RocEventEntry { key_up: keycode }, } } + + pub fn tick(duration: Duration) -> Self { + Self { + tag: RocEventTag::Tick, + entry: RocEventEntry { + tick: duration.as_nanos(), + }, + } + } } #[repr(u8)] @@ -305,27 +318,6 @@ pub struct ButtonStyles { pub text_color: Rgba, } -pub fn render(event: RocEvent) -> RocList { - let mut output = MaybeUninit::uninit(); - - // Call the program's render function - unsafe { - let layout = Layout::array::(roc_render_size() as usize).unwrap(); - - // TODO allocate on the stack if it's under a certain size - let buffer = std::alloc::alloc(layout); - - if true { - todo!("call render here"); - // call_render(&event, buffer, output.as_mut_ptr()); - } - - std::alloc::dealloc(buffer, layout); - - output.assume_init() - } -} - #[derive(Copy, Clone, Debug, Default)] #[repr(C)] pub struct Bounds { @@ -375,6 +367,29 @@ pub fn init_and_render(bounds: Bounds) -> (*const Model, RocList) { (model, elems) } +/// Call the app's update function, then render and return that result +pub fn update(model: *const Model, event: RocEvent) -> *const Model { + let closure_data_buf; + let closure_layout; + + // Call update to get the new model + unsafe { + let ret_val_layout = Layout::array::(update_result_size() as usize).unwrap(); + + // TODO allocate on the stack if it's under a certain size + let ret_val_buf = std::alloc::alloc(ret_val_layout) as *mut Model; + + closure_layout = Layout::array::(update_size() as usize).unwrap(); + + // TODO allocate on the stack if it's under a certain size + closure_data_buf = std::alloc::alloc(closure_layout); + + call_update(model, &event, closure_data_buf, ret_val_buf); + + ret_val_buf + } +} + /// Call the app's update function, then render and return that result pub fn update_and_render(model: *const Model, event: RocEvent) -> (*const Model, RocList) { let closure_data_buf; From d0b2cde1f49d18ae28e9a80ce62e80054b91e44b Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 17 Apr 2022 19:13:58 +0200 Subject: [PATCH 290/846] use Vec instead of MutSet for references in can_ann --- compiler/can/src/annotation.rs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index 087cc9d9b8..da38565aa8 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -201,7 +201,7 @@ pub fn canonicalize_annotation( var_store: &mut VarStore, ) -> Annotation { let mut introduced_variables = IntroducedVariables::default(); - let mut references = MutSet::default(); + let mut references = Vec::new(); let mut aliases = SendMap::default(); let typ = can_annotation_help( @@ -215,6 +215,8 @@ pub fn canonicalize_annotation( &mut references, ); + let references = references.into_iter().collect(); + Annotation { typ, introduced_variables, @@ -232,7 +234,7 @@ pub fn canonicalize_annotation_with_possible_clauses( abilities_in_scope: &[Symbol], ) -> Annotation { let mut introduced_variables = IntroducedVariables::default(); - let mut references = MutSet::default(); + let mut references = Vec::new(); let mut aliases = SendMap::default(); let (annotation, region) = match annotation { @@ -253,7 +255,7 @@ pub fn canonicalize_annotation_with_possible_clauses( return Annotation { typ: err_type, introduced_variables, - references, + references: references.into_iter().collect(), aliases, }; } @@ -277,7 +279,7 @@ pub fn canonicalize_annotation_with_possible_clauses( Annotation { typ, introduced_variables, - references, + references: references.into_iter().collect(), aliases, } } @@ -433,7 +435,7 @@ fn can_annotation_help( var_store: &mut VarStore, introduced_variables: &mut IntroducedVariables, local_aliases: &mut SendMap, - references: &mut MutSet, + references: &mut Vec, ) -> Type { use roc_parse::ast::TypeAnnotation::*; @@ -481,7 +483,7 @@ fn can_annotation_help( let mut args = Vec::new(); - references.insert(symbol); + references.push(symbol); for arg in *type_arguments { let arg_ann = can_annotation_help( @@ -617,7 +619,7 @@ fn can_annotation_help( let mut vars = Vec::with_capacity(loc_vars.len()); let mut lowercase_vars = Vec::with_capacity(loc_vars.len()); - references.insert(symbol); + references.push(symbol); for loc_var in *loc_vars { let var = match loc_var.value { @@ -861,7 +863,7 @@ fn canonicalize_has_clause( introduced_variables: &mut IntroducedVariables, clause: &Loc>, abilities_in_scope: &[Symbol], - references: &mut MutSet, + references: &mut Vec, ) -> Result<(), Type> { let Loc { region, @@ -893,7 +895,7 @@ fn canonicalize_has_clause( } }; - references.insert(ability); + references.push(ability); if let Some(shadowing) = introduced_variables.named_var_by_name(&var_name) { let var_name_ident = var_name.to_string().into(); @@ -923,7 +925,7 @@ fn can_extension_type<'a>( var_store: &mut VarStore, introduced_variables: &mut IntroducedVariables, local_aliases: &mut SendMap, - references: &mut MutSet, + references: &mut Vec, opt_ext: &Option<&Loc>>, ext_problem_kind: roc_problem::can::ExtensionTypeKind, ) -> Type { @@ -1105,7 +1107,7 @@ fn can_assigned_fields<'a>( var_store: &mut VarStore, introduced_variables: &mut IntroducedVariables, local_aliases: &mut SendMap, - references: &mut MutSet, + references: &mut Vec, ) -> SendMap> { use roc_parse::ast::AssignedField::*; use roc_types::types::RecordField::*; @@ -1218,7 +1220,7 @@ fn can_tags<'a>( var_store: &mut VarStore, introduced_variables: &mut IntroducedVariables, local_aliases: &mut SendMap, - references: &mut MutSet, + references: &mut Vec, ) -> Vec<(TagName, Vec)> { let mut tag_types = Vec::with_capacity(tags.len()); From aa2118699714d343fbc7b99d69a4632707a33ed0 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 17 Apr 2022 19:36:31 +0200 Subject: [PATCH 291/846] add VecSet type to collections --- compiler/collections/src/all.rs | 63 +++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/compiler/collections/src/all.rs b/compiler/collections/src/all.rs index 391f48e488..e1506d56ee 100644 --- a/compiler/collections/src/all.rs +++ b/compiler/collections/src/all.rs @@ -220,3 +220,66 @@ macro_rules! mut_map { } }; } + +#[derive(Clone, Debug, PartialEq)] +pub struct VecSet { + elements: Vec, +} + +impl Default for VecSet { + fn default() -> Self { + Self { + elements: Vec::new(), + } + } +} + +impl VecSet { + pub fn insert(&mut self, value: T) -> bool { + if self.elements.contains(&value) { + true + } else { + self.elements.push(value); + + false + } + } + + pub fn contains(&self, value: &T) -> bool { + self.elements.contains(value) + } + + pub fn remove(&mut self, value: &T) { + match self.elements.iter().position(|x| x == value) { + None => { + // just do nothing + } + Some(index) => { + self.elements.swap_remove(index); + } + } + } + + pub fn iter(&self) -> impl Iterator { + self.elements.iter() + } +} + +impl Extend for VecSet { + fn extend>(&mut self, iter: T) { + self.elements.extend(iter); + + self.elements.sort(); + self.elements.dedup(); + } +} + +impl IntoIterator for VecSet { + type Item = T; + + type IntoIter = std::vec::IntoIter; + + fn into_iter(self) -> Self::IntoIter { + self.elements.into_iter() + } +} From dda4f46e6731052da9fb8199b87ef5b83c04f907 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 17 Apr 2022 19:37:10 +0200 Subject: [PATCH 292/846] use VecSet in References --- compiler/can/src/def.rs | 16 +++++++-------- compiler/can/src/expr.rs | 18 ++++++++--------- compiler/can/src/procedure.rs | 37 ++++++++++++++--------------------- 3 files changed, 32 insertions(+), 39 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 33473cd886..289b026dc5 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -696,7 +696,7 @@ pub fn sort_can_defs( if let Some(References { value_lookups, .. }) = env.closures.get(symbol) { let home = env.home; - for lookup in value_lookups { + for lookup in value_lookups.iter() { if lookup != symbol && lookup.module_id() == home { // DO NOT register a self-call behind a lambda! // @@ -747,7 +747,7 @@ pub fn sort_can_defs( // if the current symbol is a closure, peek into its body if let Some(References { value_lookups, .. }) = env.closures.get(symbol) { - for lookup in value_lookups { + for lookup in value_lookups.iter() { loc_succ.push(*lookup); } } @@ -1312,7 +1312,7 @@ fn canonicalize_pending_value_def<'a>( let (mut loc_can_expr, can_output) = canonicalize_expr(env, var_store, scope, loc_expr.region, &loc_expr.value); - output.references = output.references.union(can_output.references.clone()); + output.references.union_mut(&can_output.references); // reset the tailcallable_symbol env.tailcallable_symbol = outer_identifier; @@ -1362,7 +1362,7 @@ fn canonicalize_pending_value_def<'a>( // Recursion doesn't count as referencing. (If it did, all recursive functions // would result in circular def errors!) refs_by_symbol.entry(symbol).and_modify(|(_, refs)| { - refs.value_lookups = refs.value_lookups.without(&symbol); + refs.value_lookups.remove(&symbol); }); // renamed_closure_def = Some(&symbol); @@ -1502,7 +1502,7 @@ fn canonicalize_pending_value_def<'a>( // Recursion doesn't count as referencing. (If it did, all recursive functions // would result in circular def errors!) refs_by_symbol.entry(symbol).and_modify(|(_, refs)| { - refs.value_lookups = refs.value_lookups.without(&symbol); + refs.value_lookups.remove(&symbol); }); loc_can_expr.value = Closure(ClosureData { @@ -1592,7 +1592,7 @@ pub fn can_defs_with_return<'a>( output .introduced_variables .union(&defs_output.introduced_variables); - output.references = output.references.union(defs_output.references); + output.references.union_mut(&defs_output.references); // Now that we've collected all the references, check to see if any of the new idents // we defined went unused by the return expression. If any were unused, report it. @@ -1646,7 +1646,7 @@ fn closure_recursivity(symbol: Symbol, closures: &MutMap) -> let mut stack = Vec::new(); if let Some(references) = closures.get(&symbol) { - for v in &references.calls { + for v in references.calls.iter() { stack.push(*v); } @@ -1662,7 +1662,7 @@ fn closure_recursivity(symbol: Symbol, closures: &MutMap) -> // if it calls any functions if let Some(nested_references) = closures.get(&nested_symbol) { // add its called to the stack - for v in &nested_references.calls { + for v in nested_references.calls.iter() { stack.push(*v); } } diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index d9262ceab1..8212343bda 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -34,7 +34,7 @@ pub struct Output { impl Output { pub fn union(&mut self, other: Self) { - self.references.union_mut(other.references); + self.references.union_mut(&other.references); if let (None, Some(later)) = (self.tail_call, other.tail_call) { self.tail_call = Some(later); @@ -354,7 +354,7 @@ pub fn canonicalize_expr<'a>( if let Var(symbol) = &can_update.value { match canonicalize_fields(env, var_store, scope, region, fields.items) { Ok((can_fields, mut output)) => { - output.references = output.references.union(update_out.references); + output.references.union_mut(&update_out.references); let answer = Update { record_var: var_store.fresh(), @@ -432,7 +432,7 @@ pub fn canonicalize_expr<'a>( let (can_expr, elem_out) = canonicalize_expr(env, var_store, scope, loc_elem.region, &loc_elem.value); - references = references.union(elem_out.references); + references.union_mut(&elem_out.references); can_elems.push(can_expr); } @@ -466,7 +466,7 @@ pub fn canonicalize_expr<'a>( canonicalize_expr(env, var_store, scope, loc_arg.region, &loc_arg.value); args.push((var_store.fresh(), arg_expr)); - output.references = output.references.union(arg_out.references); + output.references.union_mut(&arg_out.references); } if let ast::Expr::OpaqueRef(name) = loc_fn.value { @@ -753,7 +753,7 @@ pub fn canonicalize_expr<'a>( let (can_when_branch, branch_references) = canonicalize_when_branch(env, var_store, scope, region, *branch, &mut output); - output.references = output.references.union(branch_references); + output.references.union_mut(&branch_references); can_branches.push(can_when_branch); } @@ -886,8 +886,8 @@ pub fn canonicalize_expr<'a>( branches.push((loc_cond, loc_then)); - output.references = output.references.union(cond_output.references); - output.references = output.references.union(then_output.references); + output.references.union_mut(&cond_output.references); + output.references.union_mut(&then_output.references); } let (loc_else, else_output) = canonicalize_expr( @@ -898,7 +898,7 @@ pub fn canonicalize_expr<'a>( &final_else_branch.value, ); - output.references = output.references.union(else_output.references); + output.references.union_mut(&else_output.references); ( If { @@ -1167,7 +1167,7 @@ fn canonicalize_fields<'a>( }); } - output.references = output.references.union(field_out.references); + output.references.union_mut(&field_out.references); } Err(CanonicalizeFieldProblem::InvalidOptionalValue { field_name, diff --git a/compiler/can/src/procedure.rs b/compiler/can/src/procedure.rs index 6f616206e0..3aa1b92153 100644 --- a/compiler/can/src/procedure.rs +++ b/compiler/can/src/procedure.rs @@ -1,6 +1,6 @@ use crate::expr::Expr; use crate::pattern::Pattern; -use roc_collections::all::ImSet; +use roc_collections::all::VecSet; use roc_module::symbol::Symbol; use roc_region::all::{Loc, Region}; use roc_types::subs::Variable; @@ -44,12 +44,12 @@ impl Procedure { /// so it's important that building the same code gives the same order every time! #[derive(Clone, Debug, Default, PartialEq)] pub struct References { - pub bound_symbols: ImSet, - pub type_lookups: ImSet, - pub value_lookups: ImSet, + pub bound_symbols: VecSet, + pub type_lookups: VecSet, + pub value_lookups: VecSet, /// Aliases or opaque types referenced - pub referenced_type_defs: ImSet, - pub calls: ImSet, + pub referenced_type_defs: VecSet, + pub calls: VecSet, } impl References { @@ -57,22 +57,15 @@ impl References { Self::default() } - pub fn union(mut self, other: References) -> Self { - self.value_lookups = self.value_lookups.union(other.value_lookups); - self.type_lookups = self.type_lookups.union(other.type_lookups); - self.calls = self.calls.union(other.calls); - self.bound_symbols = self.bound_symbols.union(other.bound_symbols); - self.referenced_type_defs = self.referenced_type_defs.union(other.referenced_type_defs); - - self - } - - pub fn union_mut(&mut self, other: References) { - self.value_lookups.extend(other.value_lookups); - self.type_lookups.extend(other.type_lookups); - self.calls.extend(other.calls); - self.bound_symbols.extend(other.bound_symbols); - self.referenced_type_defs.extend(other.referenced_type_defs); + pub fn union_mut(&mut self, other: &References) { + self.value_lookups + .extend(other.value_lookups.iter().copied()); + self.type_lookups.extend(other.type_lookups.iter().copied()); + self.calls.extend(other.calls.iter().copied()); + self.bound_symbols + .extend(other.bound_symbols.iter().copied()); + self.referenced_type_defs + .extend(other.referenced_type_defs.iter().copied()); } pub fn has_value_lookup(&self, symbol: Symbol) -> bool { From cc6c63355a01d89679ab90ab1028ca57e3a50b67 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 17 Apr 2022 20:02:40 +0200 Subject: [PATCH 293/846] optimize for empty and singleton extends --- compiler/collections/src/all.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/compiler/collections/src/all.rs b/compiler/collections/src/all.rs index e1506d56ee..01860a9e7f 100644 --- a/compiler/collections/src/all.rs +++ b/compiler/collections/src/all.rs @@ -267,10 +267,24 @@ impl VecSet { impl Extend for VecSet { fn extend>(&mut self, iter: T) { - self.elements.extend(iter); + let mut it = iter.into_iter(); + let hint = it.size_hint(); - self.elements.sort(); - self.elements.dedup(); + match hint { + (0, Some(0)) => { + // done, do nothing + } + (1, Some(1)) => { + let value = it.next().unwrap(); + self.insert(value); + } + _ => { + self.elements.extend(it); + + self.elements.sort(); + self.elements.dedup(); + } + } } } From be1aff390c64b0dd348d1302f7b3835f008cfee6 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 17 Apr 2022 20:06:07 +0200 Subject: [PATCH 294/846] use VecSet in canonicalizing annotations --- compiler/can/src/annotation.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index 087cc9d9b8..256e7eecae 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -1,6 +1,6 @@ use crate::env::Env; use crate::scope::Scope; -use roc_collections::all::{ImMap, MutMap, MutSet, SendMap}; +use roc_collections::all::{ImMap, MutMap, MutSet, SendMap, VecSet}; use roc_module::ident::{Ident, Lowercase, TagName}; use roc_module::symbol::{IdentIds, ModuleId, Symbol}; use roc_parse::ast::{AssignedField, ExtractSpaces, Pattern, Tag, TypeAnnotation, TypeHeader}; @@ -15,7 +15,7 @@ use roc_types::types::{ pub struct Annotation { pub typ: Type, pub introduced_variables: IntroducedVariables, - pub references: MutSet, + pub references: VecSet, pub aliases: SendMap, } @@ -201,7 +201,7 @@ pub fn canonicalize_annotation( var_store: &mut VarStore, ) -> Annotation { let mut introduced_variables = IntroducedVariables::default(); - let mut references = MutSet::default(); + let mut references = VecSet::default(); let mut aliases = SendMap::default(); let typ = can_annotation_help( @@ -232,7 +232,7 @@ pub fn canonicalize_annotation_with_possible_clauses( abilities_in_scope: &[Symbol], ) -> Annotation { let mut introduced_variables = IntroducedVariables::default(); - let mut references = MutSet::default(); + let mut references = VecSet::default(); let mut aliases = SendMap::default(); let (annotation, region) = match annotation { @@ -433,7 +433,7 @@ fn can_annotation_help( var_store: &mut VarStore, introduced_variables: &mut IntroducedVariables, local_aliases: &mut SendMap, - references: &mut MutSet, + references: &mut VecSet, ) -> Type { use roc_parse::ast::TypeAnnotation::*; @@ -861,7 +861,7 @@ fn canonicalize_has_clause( introduced_variables: &mut IntroducedVariables, clause: &Loc>, abilities_in_scope: &[Symbol], - references: &mut MutSet, + references: &mut VecSet, ) -> Result<(), Type> { let Loc { region, @@ -923,7 +923,7 @@ fn can_extension_type<'a>( var_store: &mut VarStore, introduced_variables: &mut IntroducedVariables, local_aliases: &mut SendMap, - references: &mut MutSet, + references: &mut VecSet, opt_ext: &Option<&Loc>>, ext_problem_kind: roc_problem::can::ExtensionTypeKind, ) -> Type { @@ -1105,7 +1105,7 @@ fn can_assigned_fields<'a>( var_store: &mut VarStore, introduced_variables: &mut IntroducedVariables, local_aliases: &mut SendMap, - references: &mut MutSet, + references: &mut VecSet, ) -> SendMap> { use roc_parse::ast::AssignedField::*; use roc_types::types::RecordField::*; @@ -1218,7 +1218,7 @@ fn can_tags<'a>( var_store: &mut VarStore, introduced_variables: &mut IntroducedVariables, local_aliases: &mut SendMap, - references: &mut MutSet, + references: &mut VecSet, ) -> Vec<(TagName, Vec)> { let mut tag_types = Vec::with_capacity(tags.len()); From f772c87c4b5540d9adbb3c0c7a8a634a5d59c740 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 17 Apr 2022 20:08:06 +0200 Subject: [PATCH 295/846] more VecSet use, in canonical Env this time --- compiler/can/src/env.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/compiler/can/src/env.rs b/compiler/can/src/env.rs index ebbb79b349..f81c7cecfc 100644 --- a/compiler/can/src/env.rs +++ b/compiler/can/src/env.rs @@ -1,5 +1,5 @@ use crate::procedure::References; -use roc_collections::all::{MutMap, MutSet}; +use roc_collections::all::{MutMap, VecSet}; use roc_module::ident::{Ident, Lowercase, ModuleName}; use roc_module::symbol::{IdentIds, ModuleId, ModuleIds, Symbol}; use roc_problem::can::{Problem, RuntimeError}; @@ -28,12 +28,12 @@ pub struct Env<'a> { pub closure_name_symbol: Option, /// Symbols of values/functions which were referenced by qualified lookups. - pub qualified_value_lookups: MutSet, + pub qualified_value_lookups: VecSet, /// Symbols of types which were referenced by qualified lookups. - pub qualified_type_lookups: MutSet, + pub qualified_type_lookups: VecSet, - pub top_level_symbols: MutSet, + pub top_level_symbols: VecSet, pub ident_ids: IdentIds, pub exposed_ident_ids: IdentIds, @@ -54,11 +54,11 @@ impl<'a> Env<'a> { exposed_ident_ids, problems: Vec::new(), closures: MutMap::default(), - qualified_value_lookups: MutSet::default(), - qualified_type_lookups: MutSet::default(), + qualified_value_lookups: VecSet::default(), + qualified_type_lookups: VecSet::default(), tailcallable_symbol: None, closure_name_symbol: None, - top_level_symbols: MutSet::default(), + top_level_symbols: VecSet::default(), } } From 39aa112fd52d8e3417fdc7edd88adc10e9b29e41 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 17 Apr 2022 20:14:25 +0200 Subject: [PATCH 296/846] more VecSet --- compiler/can/src/module.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index 01e6664d14..f6f8ce853b 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -7,7 +7,7 @@ use crate::operator::desugar_def; use crate::pattern::Pattern; use crate::scope::Scope; use bumpalo::Bump; -use roc_collections::all::{MutMap, MutSet, SendMap}; +use roc_collections::all::{MutMap, MutSet, SendMap, VecSet}; use roc_module::ident::Lowercase; use roc_module::ident::{Ident, TagName}; use roc_module::symbol::{IdentIds, ModuleId, ModuleIds, Symbol}; @@ -24,8 +24,8 @@ pub struct Module { pub module_id: ModuleId, pub exposed_imports: MutMap, pub exposed_symbols: MutSet, - pub referenced_values: MutSet, - pub referenced_types: MutSet, + pub referenced_values: VecSet, + pub referenced_types: VecSet, /// all aliases. `bool` indicates whether it is exposed pub aliases: MutMap, pub rigid_variables: RigidVariables, @@ -36,7 +36,7 @@ pub struct Module { pub struct RigidVariables { pub named: MutMap, pub able: MutMap, - pub wildcards: MutSet, + pub wildcards: VecSet, } #[derive(Debug)] @@ -48,8 +48,8 @@ pub struct ModuleOutput { pub lookups: Vec<(Symbol, Variable, Region)>, pub problems: Vec, pub ident_ids: IdentIds, - pub referenced_values: MutSet, - pub referenced_types: MutSet, + pub referenced_values: VecSet, + pub referenced_types: VecSet, pub scope: Scope, } @@ -273,8 +273,8 @@ pub fn canonicalize_module_defs<'a>( rigid_variables.wildcards.insert(var.value); } - let mut referenced_values = MutSet::default(); - let mut referenced_types = MutSet::default(); + let mut referenced_values = VecSet::default(); + let mut referenced_types = VecSet::default(); // Gather up all the symbols that were referenced across all the defs' lookups. referenced_values.extend(output.references.value_lookups); From 304b7fd569c07d4937d4190c36fca995a889443c Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 17 Apr 2022 20:23:29 +0200 Subject: [PATCH 297/846] use VecSet for exposed_symbols --- compiler/can/src/effect_module.rs | 4 ++-- compiler/can/src/module.rs | 6 +++--- compiler/collections/src/all.rs | 6 ++++++ compiler/load_internal/src/file.rs | 13 ++++++------- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/compiler/can/src/effect_module.rs b/compiler/can/src/effect_module.rs index 1c2f76d951..20cf8a9e3e 100644 --- a/compiler/can/src/effect_module.rs +++ b/compiler/can/src/effect_module.rs @@ -4,7 +4,7 @@ use crate::env::Env; use crate::expr::{ClosureData, Expr, Recursive}; use crate::pattern::Pattern; use crate::scope::Scope; -use roc_collections::all::{MutSet, SendMap}; +use roc_collections::all::{SendMap, VecSet}; use roc_module::called_via::CalledVia; use roc_module::ident::TagName; use roc_module::symbol::Symbol; @@ -39,7 +39,7 @@ pub(crate) fn build_effect_builtins( scope: &mut Scope, effect_symbol: Symbol, var_store: &mut VarStore, - exposed_symbols: &mut MutSet, + exposed_symbols: &mut VecSet, declarations: &mut Vec, generated_functions: HostedGeneratedFunctions, ) { diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index f6f8ce853b..bc1961acbf 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -23,7 +23,7 @@ use roc_types::types::{Alias, AliasKind, Type}; pub struct Module { pub module_id: ModuleId, pub exposed_imports: MutMap, - pub exposed_symbols: MutSet, + pub exposed_symbols: VecSet, pub referenced_values: VecSet, pub referenced_types: VecSet, /// all aliases. `bool` indicates whether it is exposed @@ -89,7 +89,7 @@ pub fn canonicalize_module_defs<'a>( dep_idents: &'a MutMap, aliases: MutMap, exposed_imports: MutMap, - exposed_symbols: &MutSet, + exposed_symbols: &VecSet, var_store: &mut VarStore, ) -> Result { let mut can_exposed_imports = MutMap::default(); @@ -319,7 +319,7 @@ pub fn canonicalize_module_defs<'a>( generated_functions, }) = hosted_info { - let mut exposed_symbols = MutSet::default(); + let mut exposed_symbols = VecSet::default(); // NOTE this currently builds all functions, not just the ones that the user requested crate::effect_module::build_effect_builtins( diff --git a/compiler/collections/src/all.rs b/compiler/collections/src/all.rs index 01860a9e7f..879c2783a9 100644 --- a/compiler/collections/src/all.rs +++ b/compiler/collections/src/all.rs @@ -235,6 +235,12 @@ impl Default for VecSet { } impl VecSet { + pub fn with_capacity(capacity: usize) -> Self { + Self { + elements: Vec::with_capacity(capacity), + } + } + pub fn insert(&mut self, value: T) -> bool { if self.elements.contains(&value) { true diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index 6c52590996..37ed5b1269 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -9,7 +9,7 @@ use roc_can::abilities::AbilitiesStore; use roc_can::constraint::{Constraint as ConstraintSoa, Constraints}; use roc_can::def::Declaration; use roc_can::module::{canonicalize_module_defs, Module}; -use roc_collections::all::{default_hasher, BumpMap, MutMap, MutSet}; +use roc_collections::all::{default_hasher, BumpMap, MutMap, MutSet, VecSet}; use roc_constrain::module::{ constrain_builtin_imports, constrain_module, ExposedByModule, ExposedForModule, ExposedModuleTypes, @@ -40,7 +40,7 @@ use roc_types::solved_types::Solved; use roc_types::subs::{Subs, VarStore, Variable}; use roc_types::types::{Alias, AliasCommon, TypeExtension}; use std::collections::hash_map::Entry::{Occupied, Vacant}; -use std::collections::{HashMap, HashSet}; +use std::collections::{HashMap, }; use std::io; use std::iter; use std::ops::ControlFlow; @@ -605,7 +605,7 @@ struct State<'a> { pub declarations_by_id: MutMap>, - pub exposed_symbols_by_module: MutMap>, + pub exposed_symbols_by_module: MutMap>, pub timings: MutMap, @@ -749,7 +749,7 @@ enum BuildTask<'a> { parsed: ParsedModule<'a>, module_ids: ModuleIds, dep_idents: MutMap, - exposed_symbols: MutSet, + exposed_symbols: VecSet, aliases: MutMap, }, Solve { @@ -1680,8 +1680,7 @@ fn update<'a>( } // This was a dependency. Write it down and keep processing messages. - let mut exposed_symbols: MutSet = - HashSet::with_capacity_and_hasher(header.exposes.len(), default_hasher()); + let mut exposed_symbols: VecSet = VecSet::with_capacity(header.exposes.len()); // TODO can we avoid this loop by storing them as a Set in Header to begin with? for symbol in header.exposes.iter() { @@ -3399,7 +3398,7 @@ fn canonicalize_and_constrain<'a>( arena: &'a Bump, module_ids: &ModuleIds, dep_idents: MutMap, - exposed_symbols: MutSet, + exposed_symbols: VecSet, aliases: MutMap, parsed: ParsedModule<'a>, ) -> Result, LoadingProblem<'a>> { From c47460d7921aa2b7029a8cdca33c1139a1b234f6 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 17 Apr 2022 20:27:47 +0200 Subject: [PATCH 298/846] use VecSet in recursive alias correction --- compiler/can/src/module.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index bc1961acbf..dc2b33acec 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -7,7 +7,7 @@ use crate::operator::desugar_def; use crate::pattern::Pattern; use crate::scope::Scope; use bumpalo::Bump; -use roc_collections::all::{MutMap, MutSet, SendMap, VecSet}; +use roc_collections::all::{MutMap, SendMap, VecSet}; use roc_module::ident::Lowercase; use roc_module::ident::{Ident, TagName}; use roc_module::symbol::{IdentIds, ModuleId, ModuleIds, Symbol}; @@ -495,9 +495,9 @@ pub fn canonicalize_module_defs<'a>( for declaration in declarations.iter_mut() { match declaration { - Declare(def) => fix_values_captured_in_closure_def(def, &mut MutSet::default()), + Declare(def) => fix_values_captured_in_closure_def(def, &mut VecSet::default()), DeclareRec(defs) => { - fix_values_captured_in_closure_defs(defs, &mut MutSet::default()) + fix_values_captured_in_closure_defs(defs, &mut VecSet::default()) } InvalidCycle(_) | Builtin(_) => {} } @@ -535,7 +535,7 @@ pub fn canonicalize_module_defs<'a>( fn fix_values_captured_in_closure_def( def: &mut crate::def::Def, - no_capture_symbols: &mut MutSet, + no_capture_symbols: &mut VecSet, ) { // patterns can contain default expressions, so much go over them too! fix_values_captured_in_closure_pattern(&mut def.loc_pattern.value, no_capture_symbols); @@ -545,7 +545,7 @@ fn fix_values_captured_in_closure_def( fn fix_values_captured_in_closure_defs( defs: &mut Vec, - no_capture_symbols: &mut MutSet, + no_capture_symbols: &mut VecSet, ) { // recursive defs cannot capture each other for def in defs.iter() { @@ -561,7 +561,7 @@ fn fix_values_captured_in_closure_defs( fn fix_values_captured_in_closure_pattern( pattern: &mut crate::pattern::Pattern, - no_capture_symbols: &mut MutSet, + no_capture_symbols: &mut VecSet, ) { use crate::pattern::Pattern::*; @@ -610,7 +610,7 @@ fn fix_values_captured_in_closure_pattern( fn fix_values_captured_in_closure_expr( expr: &mut crate::expr::Expr, - no_capture_symbols: &mut MutSet, + no_capture_symbols: &mut VecSet, ) { use crate::expr::Expr::*; From 9f453a7ba209538fac644f6e717120ba2dbb9c34 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 17 Apr 2022 20:30:32 +0200 Subject: [PATCH 299/846] use vecset for non_closures --- compiler/can/src/expr.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index 8212343bda..fb14cf2db1 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -9,7 +9,7 @@ use crate::num::{ use crate::pattern::{canonicalize_pattern, Pattern}; use crate::procedure::References; use crate::scope::Scope; -use roc_collections::all::{MutMap, MutSet, SendMap}; +use roc_collections::all::{MutMap, MutSet, SendMap, VecSet}; use roc_module::called_via::CalledVia; use roc_module::ident::{ForeignSymbol, Lowercase, TagName}; use roc_module::low_level::LowLevel; @@ -29,7 +29,7 @@ pub struct Output { pub tail_call: Option, pub introduced_variables: IntroducedVariables, pub aliases: SendMap, - pub non_closures: MutSet, + pub non_closures: VecSet, } impl Output { From d53a888540696e85638f9a1654e149866cda095c Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 17 Apr 2022 20:32:20 +0200 Subject: [PATCH 300/846] Revert "use Vec instead of MutSet for references in can_ann" This reverts commit d0b2cde1f49d18ae28e9a80ce62e80054b91e44b. --- compiler/can/src/annotation.rs | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index da38565aa8..087cc9d9b8 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -201,7 +201,7 @@ pub fn canonicalize_annotation( var_store: &mut VarStore, ) -> Annotation { let mut introduced_variables = IntroducedVariables::default(); - let mut references = Vec::new(); + let mut references = MutSet::default(); let mut aliases = SendMap::default(); let typ = can_annotation_help( @@ -215,8 +215,6 @@ pub fn canonicalize_annotation( &mut references, ); - let references = references.into_iter().collect(); - Annotation { typ, introduced_variables, @@ -234,7 +232,7 @@ pub fn canonicalize_annotation_with_possible_clauses( abilities_in_scope: &[Symbol], ) -> Annotation { let mut introduced_variables = IntroducedVariables::default(); - let mut references = Vec::new(); + let mut references = MutSet::default(); let mut aliases = SendMap::default(); let (annotation, region) = match annotation { @@ -255,7 +253,7 @@ pub fn canonicalize_annotation_with_possible_clauses( return Annotation { typ: err_type, introduced_variables, - references: references.into_iter().collect(), + references, aliases, }; } @@ -279,7 +277,7 @@ pub fn canonicalize_annotation_with_possible_clauses( Annotation { typ, introduced_variables, - references: references.into_iter().collect(), + references, aliases, } } @@ -435,7 +433,7 @@ fn can_annotation_help( var_store: &mut VarStore, introduced_variables: &mut IntroducedVariables, local_aliases: &mut SendMap, - references: &mut Vec, + references: &mut MutSet, ) -> Type { use roc_parse::ast::TypeAnnotation::*; @@ -483,7 +481,7 @@ fn can_annotation_help( let mut args = Vec::new(); - references.push(symbol); + references.insert(symbol); for arg in *type_arguments { let arg_ann = can_annotation_help( @@ -619,7 +617,7 @@ fn can_annotation_help( let mut vars = Vec::with_capacity(loc_vars.len()); let mut lowercase_vars = Vec::with_capacity(loc_vars.len()); - references.push(symbol); + references.insert(symbol); for loc_var in *loc_vars { let var = match loc_var.value { @@ -863,7 +861,7 @@ fn canonicalize_has_clause( introduced_variables: &mut IntroducedVariables, clause: &Loc>, abilities_in_scope: &[Symbol], - references: &mut Vec, + references: &mut MutSet, ) -> Result<(), Type> { let Loc { region, @@ -895,7 +893,7 @@ fn canonicalize_has_clause( } }; - references.push(ability); + references.insert(ability); if let Some(shadowing) = introduced_variables.named_var_by_name(&var_name) { let var_name_ident = var_name.to_string().into(); @@ -925,7 +923,7 @@ fn can_extension_type<'a>( var_store: &mut VarStore, introduced_variables: &mut IntroducedVariables, local_aliases: &mut SendMap, - references: &mut Vec, + references: &mut MutSet, opt_ext: &Option<&Loc>>, ext_problem_kind: roc_problem::can::ExtensionTypeKind, ) -> Type { @@ -1107,7 +1105,7 @@ fn can_assigned_fields<'a>( var_store: &mut VarStore, introduced_variables: &mut IntroducedVariables, local_aliases: &mut SendMap, - references: &mut Vec, + references: &mut MutSet, ) -> SendMap> { use roc_parse::ast::AssignedField::*; use roc_types::types::RecordField::*; @@ -1220,7 +1218,7 @@ fn can_tags<'a>( var_store: &mut VarStore, introduced_variables: &mut IntroducedVariables, local_aliases: &mut SendMap, - references: &mut Vec, + references: &mut MutSet, ) -> Vec<(TagName, Vec)> { let mut tag_types = Vec::with_capacity(tags.len()); From a1a7feca45094f22d2dc23fc483b0e0f00f0b017 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 17 Apr 2022 20:43:45 +0200 Subject: [PATCH 301/846] use VecSet in IntroducedVariables --- compiler/can/src/annotation.rs | 16 +++++----------- compiler/can/src/def.rs | 3 ++- compiler/collections/src/all.rs | 13 +++++++++++++ 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index 256e7eecae..97b74f2101 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -58,8 +58,8 @@ pub struct IntroducedVariables { pub wildcards: Vec>, pub lambda_sets: Vec, pub inferred: Vec>, - pub named: Vec, - pub able: Vec, + pub named: VecSet, + pub able: VecSet, pub host_exposed_aliases: MutMap, } @@ -84,7 +84,7 @@ impl IntroducedVariables { first_seen: var.region, }; - self.named.push(named_variable); + self.named.insert(named_variable); } pub fn insert_able(&mut self, name: Lowercase, var: Loc, ability: Symbol) { @@ -97,7 +97,7 @@ impl IntroducedVariables { first_seen: var.region, }; - self.able.push(able_variable); + self.able.insert(able_variable); } pub fn insert_wildcard(&mut self, var: Loc) { @@ -128,12 +128,7 @@ impl IntroducedVariables { .extend(other.host_exposed_aliases.clone()); self.named.extend(other.named.iter().cloned()); - self.named.sort(); - self.named.dedup(); - self.able.extend(other.able.iter().cloned()); - self.able.sort(); - self.able.dedup(); } pub fn union_owned(&mut self, other: Self) { @@ -143,8 +138,7 @@ impl IntroducedVariables { self.host_exposed_aliases.extend(other.host_exposed_aliases); self.named.extend(other.named); - self.named.sort(); - self.named.dedup(); + self.able.extend(other.able.iter().cloned()); } pub fn var_by_name(&self, name: &Lowercase) -> Option { diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 289b026dc5..cd4d2c79d5 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -344,7 +344,8 @@ pub fn canonicalize_defs<'a>( let mut named = can_ann.introduced_variables.named; for loc_lowercase in vars.iter() { - match named.iter().position(|nv| nv.name == loc_lowercase.value) { + let opt_index = named.iter().position(|nv| nv.name == loc_lowercase.value); + match opt_index { Some(index) => { // This is a valid lowercase rigid var for the type def. let named_variable = named.swap_remove(index); diff --git a/compiler/collections/src/all.rs b/compiler/collections/src/all.rs index 879c2783a9..f773f0e48a 100644 --- a/compiler/collections/src/all.rs +++ b/compiler/collections/src/all.rs @@ -241,6 +241,18 @@ impl VecSet { } } + pub fn len(&self) -> usize { + self.elements.len() + } + + pub fn is_empty(&self) -> bool { + self.elements.is_empty() + } + + pub fn swap_remove(&mut self, index: usize) -> T { + self.elements.swap_remove(index) + } + pub fn insert(&mut self, value: T) -> bool { if self.elements.contains(&value) { true @@ -285,6 +297,7 @@ impl Extend for VecSet { self.insert(value); } _ => { + println!("extend {:?}", hint); self.elements.extend(it); self.elements.sort(); From 7f3ca4458a6f64dfecb2485013d3077873e0f751 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 17 Apr 2022 20:43:45 +0200 Subject: [PATCH 302/846] use VecSet in IntroducedVariables --- compiler/can/src/annotation.rs | 16 +++++----------- compiler/can/src/def.rs | 3 ++- compiler/collections/src/all.rs | 21 +++++++++++++++++---- compiler/load_internal/src/file.rs | 2 +- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index 256e7eecae..97b74f2101 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -58,8 +58,8 @@ pub struct IntroducedVariables { pub wildcards: Vec>, pub lambda_sets: Vec, pub inferred: Vec>, - pub named: Vec, - pub able: Vec, + pub named: VecSet, + pub able: VecSet, pub host_exposed_aliases: MutMap, } @@ -84,7 +84,7 @@ impl IntroducedVariables { first_seen: var.region, }; - self.named.push(named_variable); + self.named.insert(named_variable); } pub fn insert_able(&mut self, name: Lowercase, var: Loc, ability: Symbol) { @@ -97,7 +97,7 @@ impl IntroducedVariables { first_seen: var.region, }; - self.able.push(able_variable); + self.able.insert(able_variable); } pub fn insert_wildcard(&mut self, var: Loc) { @@ -128,12 +128,7 @@ impl IntroducedVariables { .extend(other.host_exposed_aliases.clone()); self.named.extend(other.named.iter().cloned()); - self.named.sort(); - self.named.dedup(); - self.able.extend(other.able.iter().cloned()); - self.able.sort(); - self.able.dedup(); } pub fn union_owned(&mut self, other: Self) { @@ -143,8 +138,7 @@ impl IntroducedVariables { self.host_exposed_aliases.extend(other.host_exposed_aliases); self.named.extend(other.named); - self.named.sort(); - self.named.dedup(); + self.able.extend(other.able.iter().cloned()); } pub fn var_by_name(&self, name: &Lowercase) -> Option { diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 289b026dc5..cd4d2c79d5 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -344,7 +344,8 @@ pub fn canonicalize_defs<'a>( let mut named = can_ann.introduced_variables.named; for loc_lowercase in vars.iter() { - match named.iter().position(|nv| nv.name == loc_lowercase.value) { + let opt_index = named.iter().position(|nv| nv.name == loc_lowercase.value); + match opt_index { Some(index) => { // This is a valid lowercase rigid var for the type def. let named_variable = named.swap_remove(index); diff --git a/compiler/collections/src/all.rs b/compiler/collections/src/all.rs index 879c2783a9..6c1a2b78c4 100644 --- a/compiler/collections/src/all.rs +++ b/compiler/collections/src/all.rs @@ -241,6 +241,18 @@ impl VecSet { } } + pub fn len(&self) -> usize { + self.elements.len() + } + + pub fn is_empty(&self) -> bool { + self.elements.is_empty() + } + + pub fn swap_remove(&mut self, index: usize) -> T { + self.elements.swap_remove(index) + } + pub fn insert(&mut self, value: T) -> bool { if self.elements.contains(&value) { true @@ -273,16 +285,17 @@ impl VecSet { impl Extend for VecSet { fn extend>(&mut self, iter: T) { - let mut it = iter.into_iter(); + let it = iter.into_iter(); let hint = it.size_hint(); match hint { (0, Some(0)) => { // done, do nothing } - (1, Some(1)) => { - let value = it.next().unwrap(); - self.insert(value); + (1, Some(1)) | (2, Some(2)) => { + for value in it { + self.insert(value); + } } _ => { self.elements.extend(it); diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index 37ed5b1269..6a277847e5 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -40,7 +40,7 @@ use roc_types::solved_types::Solved; use roc_types::subs::{Subs, VarStore, Variable}; use roc_types::types::{Alias, AliasCommon, TypeExtension}; use std::collections::hash_map::Entry::{Occupied, Vacant}; -use std::collections::{HashMap, }; +use std::collections::HashMap; use std::io; use std::iter; use std::ops::ControlFlow; From 2c0b29efd13aaacab98a9024ae8eefb8b89a528f Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 17 Apr 2022 20:43:45 +0200 Subject: [PATCH 303/846] use VecSet in IntroducedVariables --- compiler/collections/src/all.rs | 10 +++++----- compiler/load_internal/src/file.rs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/compiler/collections/src/all.rs b/compiler/collections/src/all.rs index f773f0e48a..6c1a2b78c4 100644 --- a/compiler/collections/src/all.rs +++ b/compiler/collections/src/all.rs @@ -285,19 +285,19 @@ impl VecSet { impl Extend for VecSet { fn extend>(&mut self, iter: T) { - let mut it = iter.into_iter(); + let it = iter.into_iter(); let hint = it.size_hint(); match hint { (0, Some(0)) => { // done, do nothing } - (1, Some(1)) => { - let value = it.next().unwrap(); - self.insert(value); + (1, Some(1)) | (2, Some(2)) => { + for value in it { + self.insert(value); + } } _ => { - println!("extend {:?}", hint); self.elements.extend(it); self.elements.sort(); diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index 902fba613c..3eabe6bb65 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -41,7 +41,7 @@ use roc_types::solved_types::Solved; use roc_types::subs::{Subs, VarStore, Variable}; use roc_types::types::{Alias, AliasCommon, TypeExtension}; use std::collections::hash_map::Entry::{Occupied, Vacant}; -use std::collections::{HashMap, }; +use std::collections::HashMap; use std::io; use std::iter; use std::ops::ControlFlow; From 1908ff41c3cc332fb2355444ef6011496e2dd675 Mon Sep 17 00:00:00 2001 From: Kevin Gillette Date: Fri, 15 Apr 2022 00:04:38 -0600 Subject: [PATCH 304/846] rem, sqrt, log are unchecked but have checked variants mod exists but is not implemented due to lack of hardware support (emulation, possibly in terms of rem, is needed). --- compiler/builtins/docs/Num.roc | 9 ++- compiler/builtins/roc/Num.roc | 23 +++--- compiler/builtins/src/std.rs | 45 ++++++++---- compiler/can/src/builtins.rs | 107 +++++++++++++++++++++++++++- compiler/gen_llvm/src/llvm/build.rs | 12 ++-- compiler/gen_wasm/src/low_level.rs | 5 ++ compiler/module/src/low_level.rs | 12 +++- compiler/module/src/symbol.rs | 4 +- compiler/mono/src/borrow.rs | 7 +- compiler/mono/src/low_level.rs | 1 + compiler/test_gen/src/gen_list.rs | 4 +- compiler/test_gen/src/gen_num.rs | 37 +++++----- examples/benchmarks/Deriv.roc | 2 +- examples/benchmarks/RBTreeCk.roc | 13 +--- repl_test/src/tests.rs | 2 +- 15 files changed, 208 insertions(+), 75 deletions(-) diff --git a/compiler/builtins/docs/Num.roc b/compiler/builtins/docs/Num.roc index 2f45e22600..e33a7eda94 100644 --- a/compiler/builtins/docs/Num.roc +++ b/compiler/builtins/docs/Num.roc @@ -61,6 +61,7 @@ interface Num isPositive, isZero, log, + logChecked, maxFloat, maxI8, maxU8, @@ -81,8 +82,8 @@ interface Num minI64, minU64, minI128, - modInt, - modFloat, + mod, + modChecked, mul, mulChecked, mulWrap, @@ -90,6 +91,7 @@ interface Num pow, powInt, rem, + remChecked, round, shiftLeftBy, shiftRightBy, @@ -99,6 +101,7 @@ interface Num subChecked, subWrap, sqrt, + sqrtChecked, tan, toI8, toI8Checked, @@ -1316,7 +1319,7 @@ isInfinite : Float * -> Bool ## ## >>> Num.isNaN 12.3 ## -## >>> Num.isNaN (Num.sqrt -2) +## >>> Num.isNaN (Num.pow -1 0.5) ## ## *NaN* is unusual from other numberic values in that: ## * *NaN* is not equal to any other number, even itself. [Bool.isEq] always returns `False` if either argument is *NaN*. diff --git a/compiler/builtins/roc/Num.roc b/compiler/builtins/roc/Num.roc index 3038842caa..3a56f282f1 100644 --- a/compiler/builtins/roc/Num.roc +++ b/compiler/builtins/roc/Num.roc @@ -68,12 +68,15 @@ interface Num isPositive, isNegative, rem, + remChecked, div, divChecked, - modInt, - modFloat, + mod, + modChecked, sqrt, + sqrtChecked, log, + logChecked, round, ceiling, floor, @@ -230,19 +233,23 @@ asin : Float a -> Float a acos : Float a -> Float a atan : Float a -> Float a -sqrt : Float a -> Result (Float a) [ SqrtOfNegative ]* -log : Float a -> Result (Float a) [ LogNeedsPositive ]* +sqrt : Float a -> Float a +sqrtChecked : Float a -> Result (Float a) [ SqrtOfNegative ]* +log : Float a -> Float a +logChecked : Float a -> Result (Float a) [ LogNeedsPositive ]* + div : Float a, Float a -> Float a divChecked : Float a, Float a -> Result (Float a) [ DivByZero ]* - divCeil : Int a, Int a -> Int a divCeilChecked : Int a, Int a -> Result (Int a) [ DivByZero ]* divFloor : Int a, Int a -> Int a divFloorChecked : Int a, Int a -> Result (Int a) [ DivByZero ]* -# mod : Float a, Float a -> Result (Float a) [ DivByZero ]* -rem : Int a, Int a -> Result (Int a) [ DivByZero ]* -# mod : Int a, Int a -> Result (Int a) [ DivByZero ]* +rem : Int a, Int a -> Int a +remChecked : Int a, Int a -> Result (Int a) [ DivByZero ]* +mod : Int a, Int a -> Int a +modChecked : Int a, Int a -> Result (Int a) [ DivByZero ]* + isMultipleOf : Int a, Int a -> Bool bitwiseAnd : Int a, Int a -> Int a diff --git a/compiler/builtins/src/std.rs b/compiler/builtins/src/std.rs index cc0fd16ef0..111523e170 100644 --- a/compiler/builtins/src/std.rs +++ b/compiler/builtins/src/std.rs @@ -393,16 +393,30 @@ pub fn types() -> MutMap { Box::new(int_type(flex(TVAR2))) ); - // rem : Int a, Int a -> Result (Int a) [ DivByZero ]* + // rem : Int a, Int a -> Int a add_top_level_function_type!( Symbol::NUM_REM, vec![int_type(flex(TVAR1)), int_type(flex(TVAR1))], + Box::new(int_type(flex(TVAR1))), + ); + + // remChecked : Int a, Int a -> Result (Int a) [ DivByZero ]* + add_top_level_function_type!( + Symbol::NUM_REM_CHECKED, + vec![int_type(flex(TVAR1)), int_type(flex(TVAR1))], Box::new(result_type(int_type(flex(TVAR1)), div_by_zero.clone())), ); - // mod : Int a, Int a -> Result (Int a) [ DivByZero ]* + // mod : Int a, Int a -> Int a add_top_level_function_type!( - Symbol::NUM_MOD_INT, + Symbol::NUM_MOD, + vec![int_type(flex(TVAR1)), int_type(flex(TVAR1))], + Box::new(int_type(flex(TVAR1))), + ); + + // modChecked : Int a, Int a -> Result (Int a) [ DivByZero ]* + add_top_level_function_type!( + Symbol::NUM_MOD_CHECKED, vec![int_type(flex(TVAR1)), int_type(flex(TVAR1))], Box::new(result_type(int_type(flex(TVAR1)), div_by_zero.clone())), ); @@ -680,36 +694,43 @@ pub fn types() -> MutMap { add_top_level_function_type!( Symbol::NUM_DIV_FLOAT_CHECKED, vec![float_type(flex(TVAR1)), float_type(flex(TVAR1))], - Box::new(result_type(float_type(flex(TVAR1)), div_by_zero.clone())), - ); - - // mod : Float a, Float a -> Result (Float a) [ DivByZero ]* - add_top_level_function_type!( - Symbol::NUM_MOD_FLOAT, - vec![float_type(flex(TVAR1)), float_type(flex(TVAR1))], Box::new(result_type(float_type(flex(TVAR1)), div_by_zero)), ); // sqrt : Float a -> Float a + add_top_level_function_type!( + Symbol::NUM_SQRT, + vec![float_type(flex(TVAR1))], + Box::new(float_type(flex(TVAR1))), + ); + + // sqrtChecked : Float a -> Result (Float a) [ SqrtOfNegative ]* let sqrt_of_negative = SolvedType::TagUnion( vec![(TagName::Global("SqrtOfNegative".into()), vec![])], Box::new(SolvedType::Wildcard), ); add_top_level_function_type!( - Symbol::NUM_SQRT, + Symbol::NUM_SQRT_CHECKED, vec![float_type(flex(TVAR1))], Box::new(result_type(float_type(flex(TVAR1)), sqrt_of_negative)), ); // log : Float a -> Float a + add_top_level_function_type!( + Symbol::NUM_LOG, + vec![float_type(flex(TVAR1))], + Box::new(float_type(flex(TVAR1))), + ); + + // logChecked : Float a -> Result (Float a) [ LogNeedsPositive ]* let log_needs_positive = SolvedType::TagUnion( vec![(TagName::Global("LogNeedsPositive".into()), vec![])], Box::new(SolvedType::Wildcard), ); add_top_level_function_type!( - Symbol::NUM_LOG, + Symbol::NUM_LOG_CHECKED, vec![float_type(flex(TVAR1))], Box::new(result_type(float_type(flex(TVAR1)), log_needs_positive)), ); diff --git a/compiler/can/src/builtins.rs b/compiler/can/src/builtins.rs index d194966b8b..b715d983e1 100644 --- a/compiler/can/src/builtins.rs +++ b/compiler/can/src/builtins.rs @@ -203,9 +203,14 @@ pub fn builtin_defs_map(symbol: Symbol, var_store: &mut VarStore) -> Option NUM_ABS => num_abs, NUM_NEG => num_neg, NUM_REM => num_rem, + NUM_REM_CHECKED => num_rem_checked, + NUM_MOD => num_mod, + NUM_MOD_CHECKED => num_mod_checked, NUM_IS_MULTIPLE_OF => num_is_multiple_of, NUM_SQRT => num_sqrt, + NUM_SQRT_CHECKED => num_sqrt_checked, NUM_LOG => num_log, + NUM_LOG_CHECKED => num_log_checked, NUM_ROUND => num_round, NUM_IS_ODD => num_is_odd, NUM_IS_EVEN => num_is_even, @@ -730,6 +735,23 @@ fn bool_and(symbol: Symbol, var_store: &mut VarStore) -> Def { ) } +fn num_unaryop(symbol: Symbol, var_store: &mut VarStore, op: LowLevel) -> Def { + let num_var = var_store.fresh(); + let body = RunLowLevel { + op, + args: vec![(num_var, Var(Symbol::ARG_1))], + ret_var: num_var, + }; + + defn( + symbol, + vec![(num_var, Symbol::ARG_1)], + var_store, + body, + num_var, + ) +} + /// Num a, Num a -> Num a fn num_binop(symbol: Symbol, var_store: &mut VarStore, op: LowLevel) -> Def { let num_var = var_store.fresh(); @@ -1169,8 +1191,13 @@ fn num_to_float(symbol: Symbol, var_store: &mut VarStore) -> Def { ) } -/// Num.sqrt : Float -> Result Float [ SqrtOfNegative ]* +/// Num.sqrt : Float a -> Float a fn num_sqrt(symbol: Symbol, var_store: &mut VarStore) -> Def { + num_unaryop(symbol, var_store, LowLevel::NumSqrtUnchecked) +} + +/// Num.sqrtChecked : Float a -> Result (Float a) [ SqrtOfNegative ]* +fn num_sqrt_checked(symbol: Symbol, var_store: &mut VarStore) -> Def { let bool_var = var_store.fresh(); let float_var = var_store.fresh(); let unbound_zero_var = var_store.fresh(); @@ -1218,8 +1245,13 @@ fn num_sqrt(symbol: Symbol, var_store: &mut VarStore) -> Def { ) } -/// Num.log : Float -> Result Float [ LogNeedsPositive ]* +/// Num.log : Float a -> Float a fn num_log(symbol: Symbol, var_store: &mut VarStore) -> Def { + num_unaryop(symbol, var_store, LowLevel::NumLogUnchecked) +} + +/// Num.logChecked : Float a -> Result (Float a) [ LogNeedsPositive ]* +fn num_log_checked(symbol: Symbol, var_store: &mut VarStore) -> Def { let bool_var = var_store.fresh(); let float_var = var_store.fresh(); let unbound_zero_var = var_store.fresh(); @@ -4196,8 +4228,13 @@ fn set_walk(symbol: Symbol, var_store: &mut VarStore) -> Def { ) } -/// Num.rem : Int a, Int a -> Result (Int a) [ DivByZero ]* +/// Num.rem : Int a, Int a -> Int a fn num_rem(symbol: Symbol, var_store: &mut VarStore) -> Def { + num_binop(symbol, var_store, LowLevel::NumRemUnchecked) +} + +/// Num.remChecked : Int a, Int a -> Result (Int a) [ DivByZero ]* +fn num_rem_checked(symbol: Symbol, var_store: &mut VarStore) -> Def { let num_var = var_store.fresh(); let unbound_zero_var = var_store.fresh(); let bool_var = var_store.fresh(); @@ -4255,6 +4292,70 @@ fn num_rem(symbol: Symbol, var_store: &mut VarStore) -> Def { ) } +/// Num.mod : Int a, Int a -> Int a +fn num_mod(symbol: Symbol, var_store: &mut VarStore) -> Def { + num_binop(symbol, var_store, LowLevel::NumModUnchecked) +} + +/// Num.modChecked : Int a, Int a -> Result (Int a) [ DivByZero ]* +fn num_mod_checked(symbol: Symbol, var_store: &mut VarStore) -> Def { + let num_var = var_store.fresh(); + let unbound_zero_var = var_store.fresh(); + let bool_var = var_store.fresh(); + let ret_var = var_store.fresh(); + + let body = If { + branch_var: ret_var, + cond_var: bool_var, + branches: vec![( + // if condition + no_region( + // Num.isNeq arg2 0 + RunLowLevel { + op: LowLevel::NotEq, + args: vec![ + (num_var, Var(Symbol::ARG_2)), + (num_var, num(unbound_zero_var, 0, num_no_bound())), + ], + ret_var: bool_var, + }, + ), + // arg1 was not zero + no_region( + // Ok (Int.#modUnsafe arg1 arg2) + tag( + "Ok", + vec![ + // Num.#modUnsafe arg1 arg2 + RunLowLevel { + op: LowLevel::NumModUnchecked, + args: vec![ + (num_var, Var(Symbol::ARG_1)), + (num_var, Var(Symbol::ARG_2)), + ], + ret_var: num_var, + }, + ], + var_store, + ), + ), + )], + final_else: Box::new(no_region(tag( + "Err", + vec![tag("DivByZero", Vec::new(), var_store)], + var_store, + ))), + }; + + defn( + symbol, + vec![(num_var, Symbol::ARG_1), (num_var, Symbol::ARG_2)], + var_store, + body, + ret_var, + ) +} + /// Num.isMultipleOf : Int a, Int a -> Bool fn num_is_multiple_of(symbol: Symbol, var_store: &mut VarStore) -> Def { lowlevel_2(symbol, LowLevel::NumIsMultipleOf, var_store) diff --git a/compiler/gen_llvm/src/llvm/build.rs b/compiler/gen_llvm/src/llvm/build.rs index d80b48dfea..d147da254b 100644 --- a/compiler/gen_llvm/src/llvm/build.rs +++ b/compiler/gen_llvm/src/llvm/build.rs @@ -5814,9 +5814,9 @@ fn run_low_level<'a, 'ctx, 'env>( } NumAdd | NumSub | NumMul | NumLt | NumLte | NumGt | NumGte | NumRemUnchecked - | NumIsMultipleOf | NumAddWrap | NumAddChecked | NumAddSaturated | NumDivUnchecked - | NumDivCeilUnchecked | NumPow | NumPowInt | NumSubWrap | NumSubChecked - | NumSubSaturated | NumMulWrap | NumMulChecked => { + | NumModUnchecked | NumIsMultipleOf | NumAddWrap | NumAddChecked | NumAddSaturated + | NumDivUnchecked | NumDivCeilUnchecked | NumPow | NumPowInt | NumSubWrap + | NumSubChecked | NumSubSaturated | NumMulWrap | NumMulChecked => { debug_assert_eq!(args.len(), 2); let (lhs_arg, lhs_layout) = load_symbol_and_layout(scope, &args[0]); @@ -6578,6 +6578,11 @@ fn build_int_binop<'a, 'ctx, 'env>( bd.build_int_unsigned_rem(lhs, rhs, "rem_uint").into() } } + NumModUnchecked => { + // there generally is not hardware support for flooring mod; + // it could probably be implemented in pure Roc in terms of Num.rem. + todo!("mod is not implemented") + } NumIsMultipleOf => { // this builds the following construct // @@ -6908,7 +6913,6 @@ fn build_float_binop<'a, 'ctx, 'env>( NumGte => bd.build_float_compare(OGE, lhs, rhs, "float_gte").into(), NumLt => bd.build_float_compare(OLT, lhs, rhs, "float_lt").into(), NumLte => bd.build_float_compare(OLE, lhs, rhs, "float_lte").into(), - NumRemUnchecked => bd.build_float_rem(lhs, rhs, "rem_float").into(), NumDivUnchecked => bd.build_float_div(lhs, rhs, "div_float").into(), NumPow => env.call_intrinsic(&LLVM_POW[float_width], &[lhs.into(), rhs.into()]), _ => { diff --git a/compiler/gen_wasm/src/low_level.rs b/compiler/gen_wasm/src/low_level.rs index b376f613b5..f3b3b2b180 100644 --- a/compiler/gen_wasm/src/low_level.rs +++ b/compiler/gen_wasm/src/low_level.rs @@ -434,6 +434,11 @@ impl<'a> LowLevelCall<'a> { _ => todo!("{:?} for {:?}", self.lowlevel, self.ret_layout), } } + NumModUnchecked => { + // wasm does not provide a flooring modulo instruction, + // so it would need to be emulated. + todo!("{:?}", self.lowlevel) + } NumIsMultipleOf => todo!("{:?}", self.lowlevel), NumAbs => { self.load_args(backend); diff --git a/compiler/module/src/low_level.rs b/compiler/module/src/low_level.rs index ef888bc878..12fc990851 100644 --- a/compiler/module/src/low_level.rs +++ b/compiler/module/src/low_level.rs @@ -85,6 +85,7 @@ pub enum LowLevel { NumDivUnchecked, NumDivCeilUnchecked, NumRemUnchecked, + NumModUnchecked, NumIsMultipleOf, NumAbs, NumNeg, @@ -293,14 +294,19 @@ impl LowLevelWrapperType { Symbol::NUM_DIV_FLOAT_CHECKED => WrapperIsRequired, Symbol::NUM_DIV_CEIL => CanBeReplacedBy(NumDivCeilUnchecked), Symbol::NUM_DIV_CEIL_CHECKED => WrapperIsRequired, - Symbol::NUM_REM => WrapperIsRequired, + Symbol::NUM_REM => CanBeReplacedBy(NumRemUnchecked), + Symbol::NUM_REM_CHECKED => WrapperIsRequired, + Symbol::NUM_MOD => CanBeReplacedBy(NumModUnchecked), + Symbol::NUM_MOD_CHECKED => WrapperIsRequired, Symbol::NUM_IS_MULTIPLE_OF => CanBeReplacedBy(NumIsMultipleOf), Symbol::NUM_ABS => CanBeReplacedBy(NumAbs), Symbol::NUM_NEG => CanBeReplacedBy(NumNeg), Symbol::NUM_SIN => CanBeReplacedBy(NumSin), Symbol::NUM_COS => CanBeReplacedBy(NumCos), - Symbol::NUM_SQRT => WrapperIsRequired, - Symbol::NUM_LOG => WrapperIsRequired, + Symbol::NUM_SQRT => CanBeReplacedBy(NumSqrtUnchecked), + Symbol::NUM_SQRT_CHECKED => WrapperIsRequired, + Symbol::NUM_LOG => CanBeReplacedBy(NumLogUnchecked), + Symbol::NUM_LOG_CHECKED => WrapperIsRequired, Symbol::NUM_ROUND => CanBeReplacedBy(NumRound), Symbol::NUM_TO_FLOAT => CanBeReplacedBy(NumToFloat), Symbol::NUM_POW => CanBeReplacedBy(NumPow), diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index 5be160e1d8..067e4b01a0 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -950,8 +950,8 @@ define_builtins! { 41 NUM_DIV_FLOAT_CHECKED: "divChecked" 42 NUM_DIV_FLOOR: "divFloor" 43 NUM_DIV_FLOOR_CHECKED: "divFloorChecked" - 44 NUM_MOD_INT: "modInt" - 45 NUM_MOD_INT_CHECKED: "modIntChecked" + 44 NUM_MOD: "mod" + 45 NUM_MOD_CHECKED: "modChecked" 46 NUM_MOD_FLOAT: "modFloat" 47 NUM_MOD_FLOAT_CHECKED: "modFloatChecked" 48 NUM_SQRT: "sqrt" diff --git a/compiler/mono/src/borrow.rs b/compiler/mono/src/borrow.rs index 7fd09d0bfc..8174ca8918 100644 --- a/compiler/mono/src/borrow.rs +++ b/compiler/mono/src/borrow.rs @@ -994,10 +994,9 @@ pub fn lowlevel_borrow_signature(arena: &Bump, op: LowLevel) -> &[bool] { And | Or | NumAdd | NumAddWrap | NumAddChecked | NumAddSaturated | NumSub | NumSubWrap | NumSubChecked | NumSubSaturated | NumMul | NumMulWrap | NumMulChecked | NumGt | NumGte | NumLt | NumLte | NumCompare | NumDivUnchecked | NumDivCeilUnchecked - | NumRemUnchecked | NumIsMultipleOf | NumPow | NumPowInt | NumBitwiseAnd - | NumBitwiseXor | NumBitwiseOr | NumShiftLeftBy | NumShiftRightBy | NumShiftRightZfBy => { - arena.alloc_slice_copy(&[irrelevant, irrelevant]) - } + | NumRemUnchecked | NumModUnchecked | NumIsMultipleOf | NumPow | NumPowInt + | NumBitwiseAnd | NumBitwiseXor | NumBitwiseOr | NumShiftLeftBy | NumShiftRightBy + | NumShiftRightZfBy => arena.alloc_slice_copy(&[irrelevant, irrelevant]), NumToStr | NumAbs | NumNeg | NumSin | NumCos | NumSqrtUnchecked | NumLogUnchecked | NumRound | NumCeiling | NumFloor | NumToFloat | Not | NumIsFinite | NumAtan | NumAcos diff --git a/compiler/mono/src/low_level.rs b/compiler/mono/src/low_level.rs index 03092a25cb..5dc37091df 100644 --- a/compiler/mono/src/low_level.rs +++ b/compiler/mono/src/low_level.rs @@ -144,6 +144,7 @@ enum FirstOrder { NumCompare, NumDivUnchecked, NumRemUnchecked, + NumModUnchecked, NumIsMultipleOf, NumAbs, NumNeg, diff --git a/compiler/test_gen/src/gen_list.rs b/compiler/test_gen/src/gen_list.rs index cb46f2de49..517e3d9c58 100644 --- a/compiler/test_gen/src/gen_list.rs +++ b/compiler/test_gen/src/gen_list.rs @@ -2534,7 +2534,7 @@ fn list_keep_oks() { RocList ); assert_evals_to!( - "List.keepOks [1,2] (\\x -> x % 2)", + "List.keepOks [1,2] (\\x -> Num.remChecked x 2)", RocList::from_slice(&[1, 0]), RocList ); @@ -2561,7 +2561,7 @@ fn list_keep_errs() { assert_evals_to!( indoc!( r#" - List.keepErrs [0,1,2] (\x -> x % 0 |> Result.mapErr (\_ -> 32)) + List.keepErrs [0,1,2] (\x -> Num.remChecked x 0 |> Result.mapErr (\_ -> 32)) "# ), RocList::from_slice(&[32, 32, 32]), diff --git a/compiler/test_gen/src/gen_num.rs b/compiler/test_gen/src/gen_num.rs index 88480c6310..ac089cdc9d 100644 --- a/compiler/test_gen/src/gen_num.rs +++ b/compiler/test_gen/src/gen_num.rs @@ -473,7 +473,7 @@ fn f64_sqrt() { assert_evals_to!( indoc!( r#" - when Num.sqrt 100 is + when Num.sqrtChecked 100 is Ok val -> val Err _ -> -1 "# @@ -489,9 +489,7 @@ fn f64_log() { assert_evals_to!( indoc!( r#" - when Num.log 7.38905609893 is - Ok val -> val - Err _ -> -1 + Num.log 7.38905609893 "# ), 1.999999999999912, @@ -501,11 +499,11 @@ fn f64_log() { #[test] #[cfg(any(feature = "gen-llvm"))] -fn f64_log_one() { +fn f64_log_checked_one() { assert_evals_to!( indoc!( r#" - when Num.log 1 is + when Num.logChecked 1 is Ok val -> val Err _ -> -1 "# @@ -521,7 +519,7 @@ fn f64_sqrt_zero() { assert_evals_to!( indoc!( r#" - when Num.sqrt 0 is + when Num.sqrtChecked 0 is Ok val -> val Err _ -> -1 "# @@ -533,11 +531,11 @@ fn f64_sqrt_zero() { #[test] #[cfg(any(feature = "gen-llvm"))] -fn f64_sqrt_negative() { +fn f64_sqrt_checked_negative() { assert_evals_to!( indoc!( r#" - when Num.sqrt -1 is + when Num.sqrtChecked -1 is Err _ -> 42 Ok val -> val "# @@ -549,11 +547,11 @@ fn f64_sqrt_negative() { #[test] #[cfg(any(feature = "gen-llvm"))] -fn f64_log_zero() { +fn f64_log_checked_zero() { assert_evals_to!( indoc!( r#" - when Num.log 0 is + when Num.logChecked 0 is Err _ -> 42 Ok val -> val "# @@ -569,13 +567,12 @@ fn f64_log_negative() { assert_evals_to!( indoc!( r#" - when Num.log -1 is - Err _ -> 42 - Ok val -> val + Num.log -1 "# ), - 42.0, - f64 + true, + f64, + |f: f64| f.is_nan() ); } @@ -1082,9 +1079,7 @@ fn gen_rem_i64() { assert_evals_to!( indoc!( r#" - when Num.rem 8 3 is - Ok val -> val - Err _ -> -1 + Num.rem 8 3 "# ), 2, @@ -1094,11 +1089,11 @@ fn gen_rem_i64() { #[test] #[cfg(any(feature = "gen-llvm"))] -fn gen_rem_div_by_zero_i64() { +fn gen_rem_checked_div_by_zero_i64() { assert_evals_to!( indoc!( r#" - when Num.rem 8 0 is + when Num.remChecked 8 0 is Err DivByZero -> 4 Ok _ -> -23 "# diff --git a/examples/benchmarks/Deriv.roc b/examples/benchmarks/Deriv.roc index caf08906a6..90e641cb0f 100644 --- a/examples/benchmarks/Deriv.roc +++ b/examples/benchmarks/Deriv.roc @@ -41,7 +41,7 @@ Expr : [ Val I64, Var Str, Add Expr Expr, Mul Expr Expr, Pow Expr Expr, Ln Expr divmod : I64, I64 -> Result { div : I64, mod : I64 } [ DivByZero ]* divmod = \l, r -> - when Pair (l // r) (l % r) is + when Pair (Num.divFloorChecked l r) (Num.remChecked l r) is Pair div (Ok mod) -> Ok { div, mod } diff --git a/examples/benchmarks/RBTreeCk.roc b/examples/benchmarks/RBTreeCk.roc index 225df33161..90c6fb3d4f 100644 --- a/examples/benchmarks/RBTreeCk.roc +++ b/examples/benchmarks/RBTreeCk.roc @@ -23,12 +23,12 @@ makeMapHelp = \freq, n, m, acc -> _ -> powerOf10 = - (n % 10 |> resultWithDefault 0) == 0 + n % 10 == 0 m1 = insert m n powerOf10 isFrequency = - (n % freq |> resultWithDefault 0) == 0 + n % freq == 0 x = (if isFrequency then Cons m1 acc else acc) @@ -43,15 +43,6 @@ fold = \f, tree, b -> Node _ l k v r -> fold f r (f k v (fold f l b)) -resultWithDefault : Result a e, a -> a -resultWithDefault = \res, default -> - when res is - Ok v -> - v - - Err _ -> - default - main : Task.Task {} [] main = Task.after diff --git a/repl_test/src/tests.rs b/repl_test/src/tests.rs index 9f46137f38..9480cbce91 100644 --- a/repl_test/src/tests.rs +++ b/repl_test/src/tests.rs @@ -56,7 +56,7 @@ fn float_addition() { #[cfg(not(feature = "wasm"))] #[test] fn num_rem() { - expect_success("299 % 10", "Ok 9 : Result (Int *) [ DivByZero ]*"); + expect_success("299 % 10", "9 : Int *"); } #[cfg(not(feature = "wasm"))] From 3dce2a00dfccd5509ed9c72301c1e1a602e85339 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sun, 17 Apr 2022 20:42:17 -0400 Subject: [PATCH 305/846] Animate breakout, give blocks a border --- examples/breakout/breakout.roc | 70 ++++++++++++++++++++++++--- examples/breakout/platform/src/gui.rs | 8 +-- examples/breakout/platform/src/roc.rs | 16 +++--- 3 files changed, 77 insertions(+), 17 deletions(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index 09b0b6fc3c..a2f00f6784 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -5,7 +5,9 @@ app "breakout" paddleWidth = 0.2 # width of the paddle, as a % of screen width paddleHeight = 50 # height of the paddle, in pixels -paddleSpeed = 60 # how many pixels the paddle moves per keypress +paddleSpeed = 65 # how many pixels the paddle moves per keypress +blockHeight = 80 # height of a block, in pixels +blockBorder = 0.025 # border of a block, as a % of its width Model : { # Screen height and width @@ -18,6 +20,8 @@ Model : { # Ball coordinates ballX : F32, ballY : F32, + dBallX : F32, # delta x - how much it moves per tick + dBallY : F32, # delta y - how much it moves per tick } init : Bounds -> Model @@ -31,8 +35,12 @@ init = \{ width, height } -> paddleX: (width * 0.5) - (paddleWidth * width * 0.5), # Ball coordinates - ballX: (width * 0.5), - ballY : (height * 0.5), + ballX: width * 0.5, + ballY: height * 0.4, + + # Delta - how much ball moves in each tick + dBallX: 4, + dBallY: 4, } update : Model, Event -> Model @@ -41,9 +49,39 @@ update = \model, event -> Resize size -> { model & width: size.width, height: size.height } KeyDown Left -> { model & paddleX: model.paddleX - paddleSpeed } KeyDown Right -> { model & paddleX: model.paddleX + paddleSpeed } - Tick _ -> { model & ballY: model.ballY + 1 } + Tick _ -> tick model _ -> model +tick : Model -> Model +tick = \model -> + model + |> moveBall + +moveBall : Model -> Model +moveBall = \model -> + ballX = model.ballX + model.dBallX + ballY = model.ballY + model.dBallY + + paddleTop = model.height - blockHeight - (paddleHeight * 2) + paddleLeft = model.paddleX + paddleRight = paddleLeft + (model.width * paddleWidth) + + # If its y used to be less than the paddle, and now it's greater than or equal, + # then this is the frame where the ball collided with it. + crossingPaddle = model.ballY < paddleTop && ballY >= paddleTop + + # If it collided with the paddle, bounce off. + directionChange = + if crossingPaddle && (ballX >= paddleLeft && ballX <= paddleRight) then + -1f32 + else + 1f32 + + dBallX = model.dBallX * directionChange + dBallY = model.dBallY * directionChange + + { model & ballX, ballY, dBallX, dBallY } + render : Model -> List Elem render = \model -> numRows = 4 @@ -69,14 +107,32 @@ render = \model -> { row, col, color } blockWidth = model.width / numCols - blockHeight = 80 rects = - List.map blocks \{ row, col, color } -> + List.joinMap blocks \{ row, col, color } -> left = Num.toF32 col * blockWidth top = Num.toF32 (row * blockHeight) + border = blockBorder * blockWidth - Rect { left, top, width: blockWidth, height: blockHeight, color } + outer = Rect + { + left, + top, + width: blockWidth, + height: blockHeight, + color: { r: color.r * 0.8, g: color.g * 0.8, b: color.b * 0.8, a: 1 }, + } + + inner = Rect + { + left: left + border, + top: top + border, + width: blockWidth - (border * 2), + height: blockHeight - (border * 2), + color, + } + + [ outer, inner ] ball = color = { r: 0.7, g: 0.3, b: 0.9, a: 1.0 } diff --git a/examples/breakout/platform/src/gui.rs b/examples/breakout/platform/src/gui.rs index feece8cb07..ef0412ea25 100644 --- a/examples/breakout/platform/src/gui.rs +++ b/examples/breakout/platform/src/gui.rs @@ -152,7 +152,7 @@ pub fn run_event_loop(title: &str, window_bounds: Bounds) -> Result<(), Box Result<(), Box { let roc_event = match input_state { - ElementState::Pressed => RocEvent::key_down(keycode.into()), - ElementState::Released => RocEvent::key_up(keycode.into()), + ElementState::Pressed => RocEvent::KeyDown(keycode.into()), + ElementState::Released => RocEvent::KeyUp(keycode.into()), }; model = roc::update(model, roc_event); @@ -252,7 +252,7 @@ pub fn run_event_loop(title: &str, window_bounds: Bounds) -> Result<(), Box Self { + #[allow(non_snake_case)] + pub fn Resize(size: Bounds) -> Self { Self { tag: RocEventTag::Resize, entry: RocEventEntry { resize: size }, } } - pub fn key_down(keycode: RocKeyCode) -> Self { + #[allow(non_snake_case)] + pub fn KeyDown(keycode: RocKeyCode) -> Self { Self { tag: RocEventTag::KeyDown, entry: RocEventEntry { key_down: keycode }, } } - pub fn key_up(keycode: RocKeyCode) -> Self { + #[allow(non_snake_case)] + pub fn KeyUp(keycode: RocKeyCode) -> Self { Self { tag: RocEventTag::KeyUp, entry: RocEventEntry { key_up: keycode }, } } - pub fn tick(duration: Duration) -> Self { + #[allow(non_snake_case)] + pub fn Tick(duration: Duration) -> Self { Self { tag: RocEventTag::Tick, entry: RocEventEntry { - tick: duration.as_nanos(), + tick: duration.as_nanos().to_ne_bytes(), }, } } From cbe0b0fb4c334a52e653b5d537d88546b9c6f3a6 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sun, 17 Apr 2022 20:58:24 -0400 Subject: [PATCH 306/846] Reproduce multiple confusing error messages --- examples/breakout/breakout.roc | 103 ++++++++++++++++++++++++--------- 1 file changed, 75 insertions(+), 28 deletions(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index a2f00f6784..3624cc6348 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -1,6 +1,6 @@ app "breakout" packages { pf: "platform" } - imports [ pf.Game.{ Bounds, Elem, Event } ] + imports [ pf.Game.{ Bounds, Elem, Event, Rgba } ] provides [ program ] { Model } to pf paddleWidth = 0.2 # width of the paddle, as a % of screen width @@ -8,8 +8,14 @@ paddleHeight = 50 # height of the paddle, in pixels paddleSpeed = 65 # how many pixels the paddle moves per keypress blockHeight = 80 # height of a block, in pixels blockBorder = 0.025 # border of a block, as a % of its width +ballSize = 55 +numRows = 4 +numCols = 8 +numBlocks = numRows * numCols Model : { + blocks : List Block, + # Screen height and width height : F32, width : F32, @@ -24,9 +30,18 @@ Model : { dBallY : F32, # delta y - how much it moves per tick } +Block : { + left : F32, + top : F32, + color : Rgba, + status : [ Active, Removed, Fading F32 ], +} + init : Bounds -> Model init = \{ width, height } -> { + blocks: initBlocks width, + # Screen height and width width, height, @@ -43,6 +58,31 @@ init = \{ width, height } -> dBallY: 4, } +initBlocks : F32 -> List Block +initBlocks = \width -> + blockWidth = width / numCols + + List.map (List.range 0 numBlocks) \index -> + col = + Num.rem index numCols + |> Result.withDefault 0 + |> Num.toF32 + + row = + index // numCols + |> Num.toF32 + + red = col / Num.toF32 numCols + green = row / Num.toF32 numRows + blue = Num.toF32 index / Num.toF32 numBlocks + + color = { r: red * 0.8, g: 0.2 + green * 0.6, b: 0.2 + blue * 0.8, a: 1 } + + left = Num.toF32 col * blockWidth + top = Num.toF32 row * blockHeight + + { left, top, color, status: Active } + update : Model, Event -> Model update = \model, event -> when event is @@ -56,6 +96,7 @@ tick : Model -> Model tick = \model -> model |> moveBall + |> updateBlocks moveBall : Model -> Model moveBall = \model -> @@ -82,37 +123,43 @@ moveBall = \model -> { model & ballX, ballY, dBallX, dBallY } +updateBlocks : Model -> Model +updateBlocks = \model -> + ball = { left: model.ballX, top: model.ballY, width: ballSize, height: ballSize } + blocks = List.map model.blocks \block -> + when block.status is + Removed -> block + Active -> + if isOverlapping block ball then + { block & status: Fading 1 } + else + block + Fading amount -> + if amount <= 0 then + { block & status: Removed } + else + { block & status: Fading (amount - 0.1) } + + { model & blocks } + +isOverlapping = \rect1, rect2 -> + (rect1.left + rect1.width >= rect2.left) + && (rect2.left + rect2.width >= rect1.left) + && (rect1.top + rect1.height >= rect2.top) + && (rect2.top + rect2.height >= rect1.top) + render : Model -> List Elem render = \model -> - numRows = 4 - numCols = 8 - numBlocks = numRows * numCols - - blocks = List.map (List.range 0 numBlocks) \index -> - col = - Num.rem index numCols - |> Result.withDefault 0 - |> Num.toF32 - - row = - index // numCols - |> Num.toF32 - - red = col / Num.toF32 numCols - green = row / Num.toF32 numRows - blue = Num.toF32 index / Num.toF32 numBlocks - - color = { r: red * 0.8, g: 0.2 + green * 0.6, b: 0.2 + blue * 0.8, a: 1 } - - { row, col, color } - blockWidth = model.width / numCols rects = - List.joinMap blocks \{ row, col, color } -> - left = Num.toF32 col * blockWidth - top = Num.toF32 (row * blockHeight) + List.joinMap model.blocks \{ left, top, color, status } -> border = blockBorder * blockWidth + a = + when status is + Fading alpha -> alpha + Active -> 1 + Removed -> 0 outer = Rect { @@ -136,8 +183,8 @@ render = \model -> ball = color = { r: 0.7, g: 0.3, b: 0.9, a: 1.0 } - width = 50 - height = 50 + width = ballSize + height = ballSize left = model.ballX top = model.ballY From 0758bfc487ea2066eb9d77d94d6d6eafc91304ba Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sun, 17 Apr 2022 21:10:43 -0400 Subject: [PATCH 307/846] Fix type mismatch in breakout --- examples/breakout/breakout.roc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index 3624cc6348..65a19689ff 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -125,12 +125,15 @@ moveBall = \model -> updateBlocks : Model -> Model updateBlocks = \model -> + blockWidth = model.width / numCols ball = { left: model.ballX, top: model.ballY, width: ballSize, height: ballSize } blocks = List.map model.blocks \block -> when block.status is Removed -> block Active -> - if isOverlapping block ball then + blockRect = { left: block.left, top: block.top, height: blockHeight, width: blockWidth } + + if isOverlapping blockRect ball then { block & status: Fading 1 } else block From 4d7e7f2e0e6127cecc79b231dfa03d9fef35426f Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sun, 17 Apr 2022 21:12:04 -0400 Subject: [PATCH 308/846] Reproduce alias analysis crash --- examples/breakout/breakout.roc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index 65a19689ff..e4879f110c 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -134,7 +134,7 @@ updateBlocks = \model -> blockRect = { left: block.left, top: block.top, height: blockHeight, width: blockWidth } if isOverlapping blockRect ball then - { block & status: Fading 1 } + { block & status: Removed } else block Fading amount -> @@ -158,9 +158,9 @@ render = \model -> rects = List.joinMap model.blocks \{ left, top, color, status } -> border = blockBorder * blockWidth - a = + alpha = when status is - Fading alpha -> alpha + Fading amount -> amount Active -> 1 Removed -> 0 @@ -170,7 +170,7 @@ render = \model -> top, width: blockWidth, height: blockHeight, - color: { r: color.r * 0.8, g: color.g * 0.8, b: color.b * 0.8, a: 1 }, + color: { r: color.r * 0.8, g: color.g * 0.8, b: color.b * 0.8, a: alpha }, } inner = Rect @@ -179,7 +179,7 @@ render = \model -> top: top + border, width: blockWidth - (border * 2), height: blockHeight - (border * 2), - color, + color: { color & a: alpha }, } [ outer, inner ] From ec4c8023735604711abe6098780bfeac8382c326 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sun, 17 Apr 2022 22:39:22 -0400 Subject: [PATCH 309/846] Use outdented curly braces more --- examples/breakout/breakout.roc | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index e4879f110c..38967e17ab 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -164,23 +164,24 @@ render = \model -> Active -> 1 Removed -> 0 - outer = Rect - { - left, - top, - width: blockWidth, - height: blockHeight, - color: { r: color.r * 0.8, g: color.g * 0.8, b: color.b * 0.8, a: alpha }, - } + # This outer rectangle gets drawn first, and will appear to be a border. + outer = Rect { + left, + top, + width: blockWidth, + height: blockHeight, + color: { r: color.r * 0.8, g: color.g * 0.8, b: color.b * 0.8, a: alpha }, + } - inner = Rect - { - left: left + border, - top: top + border, - width: blockWidth - (border * 2), - height: blockHeight - (border * 2), - color: { color & a: alpha }, - } + # The inner retangle is smaller than the outer one, but gets drawn on top of it, + # such that the outer one appears to be a border. + inner = Rect { + left: left + border, + top: top + border, + width: blockWidth - (border * 2), + height: blockHeight - (border * 2), + color: { color & a: alpha }, + } [ outer, inner ] From 8a16c963d1ac6570ac1a812ead00e2fa0f8c6ff6 Mon Sep 17 00:00:00 2001 From: Kas Buunk Date: Mon, 18 Apr 2022 07:11:31 +0200 Subject: [PATCH 310/846] chore: correct typo in docs --- BUILDING_FROM_SOURCE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BUILDING_FROM_SOURCE.md b/BUILDING_FROM_SOURCE.md index 4182939e77..cae2627685 100644 --- a/BUILDING_FROM_SOURCE.md +++ b/BUILDING_FROM_SOURCE.md @@ -107,7 +107,7 @@ To run the test suite (via `cargo test`), you additionally need to install: * [`valgrind`](https://www.valgrind.org/) (needs special treatment to [install on macOS](https://stackoverflow.com/a/61359781) Alternatively, you can use `cargo test --no-fail-fast` or `cargo test -p specific_tests` to skip over the valgrind failures & tests. -For debugging LLVM IR, we use [DebugIR](https://github.com/vaivaswatha/debugir). This dependency is only required to build with the `--debug` flag, and for normal developtment you should be fine without it. +For debugging LLVM IR, we use [DebugIR](https://github.com/vaivaswatha/debugir). This dependency is only required to build with the `--debug` flag, and for normal development you should be fine without it. ### libxcb libraries From a8f0b771f67f2e17bb9d7623bb2164d49c0a5d78 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 18 Apr 2022 01:21:23 -0400 Subject: [PATCH 311/846] Add Kas Buunk to AUTHORS --- AUTHORS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/AUTHORS b/AUTHORS index 88baae4952..490d2b97ac 100644 --- a/AUTHORS +++ b/AUTHORS @@ -76,3 +76,5 @@ Nikita Mounier <36044205+nikitamounier@users.noreply.github.com> Cai Bingjun <62678643+C-BJ@users.noreply.github.com> Jared Cone Sean Hagstrom + Kas Buunk + From 340f6b7c88fc91bdaca7131c7f39f91a4f8b7b0e Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 18 Apr 2022 01:21:33 -0400 Subject: [PATCH 312/846] fix typo --- AUTHORS | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/AUTHORS b/AUTHORS index 490d2b97ac..554d987aac 100644 --- a/AUTHORS +++ b/AUTHORS @@ -76,5 +76,4 @@ Nikita Mounier <36044205+nikitamounier@users.noreply.github.com> Cai Bingjun <62678643+C-BJ@users.noreply.github.com> Jared Cone Sean Hagstrom - Kas Buunk - +Kas Buunk From 6a3fd3a60794675bf36833ff4b62382079232bd3 Mon Sep 17 00:00:00 2001 From: Kevin Gillette Date: Mon, 18 Apr 2022 02:33:31 -0600 Subject: [PATCH 313/846] rename divFloor to divTrunc --- TUTORIAL.md | 2 +- compiler/builtins/docs/Num.roc | 12 ++++++------ compiler/builtins/roc/Num.roc | 8 ++++---- compiler/builtins/src/std.rs | 8 ++++---- compiler/can/src/builtins.rs | 12 ++++++------ compiler/can/src/operator.rs | 2 +- compiler/module/src/symbol.rs | 4 ++-- compiler/solve/tests/solve_expr.rs | 8 ++++---- compiler/test_gen/src/gen_num.rs | 4 ++-- compiler/test_mono/src/tests.rs | 2 +- examples/false-interpreter/False.roc | 2 +- repl_test/src/tests.rs | 6 +++--- roc-for-elm-programmers.md | 2 +- 13 files changed, 36 insertions(+), 36 deletions(-) diff --git a/TUTORIAL.md b/TUTORIAL.md index e8820da585..616541fe22 100644 --- a/TUTORIAL.md +++ b/TUTORIAL.md @@ -1941,7 +1941,7 @@ Here are various Roc expressions involving operators, and what they desugar to. | `a - b` | `Num.sub a b` | | `a * b` | `Num.mul a b` | | `a / b` | `Num.div a b` | -| `a // b` | `Num.divFloor a b` | +| `a // b` | `Num.divTrunc a b` | | `a ^ b` | `Num.pow a b` | | `a % b` | `Num.rem a b` | | `a %% b` | `Num.mod a b` | diff --git a/compiler/builtins/docs/Num.roc b/compiler/builtins/docs/Num.roc index 2f45e22600..76b7c4f52b 100644 --- a/compiler/builtins/docs/Num.roc +++ b/compiler/builtins/docs/Num.roc @@ -47,7 +47,7 @@ interface Num compare, cos, div, - divFloor, + divTrunc, floor, intCast, isEven, @@ -781,7 +781,7 @@ toU128 : Int * -> U128 ## there will be a loss of precision. toDec : Num * -> Dec -## Divide two integers and #Num.round the resulut. +## Divide two integers, truncating the result towards zero. ## ## Division by zero is undefined in mathematics. As such, you should make ## sure never to pass zero as the denomaintor to this function! @@ -791,18 +791,18 @@ toDec : Num * -> Dec ## * In a development build, you'll get an assertion failure. ## * In an optimized build, the function will return 0. ## -## `a // b` is shorthand for `Num.divRound a b`. +## `a // b` is shorthand for `Num.divTrunc a b`. ## ## >>> 5 // 7 ## -## >>> Num.divRound 5 7 +## >>> Num.divTrunc 5 7 ## ## >>> 8 // -3 ## -## >>> Num.divRound 8 -3 +## >>> Num.divTrunc 8 -3 ## ## This is the same as the #// operator. -divRound : Int a, Int a -> Int a +divTrunc : Int a, Int a -> Int a ## Perform flooring modulo on two integers. ## diff --git a/compiler/builtins/roc/Num.roc b/compiler/builtins/roc/Num.roc index 3038842caa..d7a4daaa8b 100644 --- a/compiler/builtins/roc/Num.roc +++ b/compiler/builtins/roc/Num.roc @@ -99,8 +99,8 @@ interface Num bytesToU32, divCeil, divCeilChecked, - divFloor, - divFloorChecked, + divTrunc, + divTruncChecked, toStr, isMultipleOf, minI8, @@ -237,8 +237,8 @@ divChecked : Float a, Float a -> Result (Float a) [ DivByZero ]* divCeil : Int a, Int a -> Int a divCeilChecked : Int a, Int a -> Result (Int a) [ DivByZero ]* -divFloor : Int a, Int a -> Int a -divFloorChecked : Int a, Int a -> Result (Int a) [ DivByZero ]* +divTrunc : Int a, Int a -> Int a +divTruncChecked : Int a, Int a -> Result (Int a) [ DivByZero ]* # mod : Float a, Float a -> Result (Float a) [ DivByZero ]* rem : Int a, Int a -> Result (Int a) [ DivByZero ]* diff --git a/compiler/builtins/src/std.rs b/compiler/builtins/src/std.rs index cc0fd16ef0..68bab5db31 100644 --- a/compiler/builtins/src/std.rs +++ b/compiler/builtins/src/std.rs @@ -316,16 +316,16 @@ pub fn types() -> MutMap { Box::new(SolvedType::Wildcard), ); - // divFloor : Int a, Int a -> Int a + // divTrunc : Int a, Int a -> Int a add_top_level_function_type!( - Symbol::NUM_DIV_FLOOR, + Symbol::NUM_DIV_TRUNC, vec![int_type(flex(TVAR1)), int_type(flex(TVAR1))], Box::new(int_type(flex(TVAR1))) ); - // divFloorChecked : Int a, Int a -> Result (Int a) [ DivByZero ]* + // divTruncChecked : Int a, Int a -> Result (Int a) [ DivByZero ]* add_top_level_function_type!( - Symbol::NUM_DIV_FLOOR_CHECKED, + Symbol::NUM_DIV_TRUNC_CHECKED, vec![int_type(flex(TVAR1)), int_type(flex(TVAR1))], Box::new(result_type(int_type(flex(TVAR1)), div_by_zero.clone())), ); diff --git a/compiler/can/src/builtins.rs b/compiler/can/src/builtins.rs index d194966b8b..a6f9e13957 100644 --- a/compiler/can/src/builtins.rs +++ b/compiler/can/src/builtins.rs @@ -196,8 +196,8 @@ pub fn builtin_defs_map(symbol: Symbol, var_store: &mut VarStore) -> Option NUM_TAN => num_tan, NUM_DIV_FLOAT => num_div_float, NUM_DIV_FLOAT_CHECKED => num_div_float_checked, - NUM_DIV_FLOOR => num_div_floor, - NUM_DIV_FLOOR_CHECKED => num_div_floor_checked, + NUM_DIV_TRUNC => num_div_trunc, + NUM_DIV_TRUNC_CHECKED => num_div_trunc_checked, NUM_DIV_CEIL => num_div_ceil, NUM_DIV_CEIL_CHECKED => num_div_ceil_checked, NUM_ABS => num_abs, @@ -4369,13 +4369,13 @@ fn num_div_float_checked(symbol: Symbol, var_store: &mut VarStore) -> Def { ) } -/// Num.divFloor : Int a, Int a -> Int a -fn num_div_floor(symbol: Symbol, var_store: &mut VarStore) -> Def { +/// Num.divTrunc : Int a, Int a -> Int a +fn num_div_trunc(symbol: Symbol, var_store: &mut VarStore) -> Def { num_binop(symbol, var_store, LowLevel::NumDivUnchecked) } -/// Num.divFloorChecked : Int a , Int a -> Result (Int a) [ DivByZero ]* -fn num_div_floor_checked(symbol: Symbol, var_store: &mut VarStore) -> Def { +/// Num.divTruncChecked : Int a , Int a -> Result (Int a) [ DivByZero ]* +fn num_div_trunc_checked(symbol: Symbol, var_store: &mut VarStore) -> Def { let bool_var = var_store.fresh(); let num_var = var_store.fresh(); let unbound_zero_var = var_store.fresh(); diff --git a/compiler/can/src/operator.rs b/compiler/can/src/operator.rs index 6bbb3d23b9..0386408b47 100644 --- a/compiler/can/src/operator.rs +++ b/compiler/can/src/operator.rs @@ -423,7 +423,7 @@ fn binop_to_function(binop: BinOp) -> (&'static str, &'static str) { Caret => (ModuleName::NUM, "pow"), Star => (ModuleName::NUM, "mul"), Slash => (ModuleName::NUM, "div"), - DoubleSlash => (ModuleName::NUM, "divFloor"), + DoubleSlash => (ModuleName::NUM, "divTrunc"), Percent => (ModuleName::NUM, "rem"), DoublePercent => (ModuleName::NUM, "mod"), Plus => (ModuleName::NUM, "add"), diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index 5be160e1d8..e5b12d8b0a 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -948,8 +948,8 @@ define_builtins! { 39 NUM_REM_CHECKED: "remChecked" 40 NUM_DIV_FLOAT: "div" 41 NUM_DIV_FLOAT_CHECKED: "divChecked" - 42 NUM_DIV_FLOOR: "divFloor" - 43 NUM_DIV_FLOOR_CHECKED: "divFloorChecked" + 42 NUM_DIV_TRUNC: "divTrunc" + 43 NUM_DIV_TRUNC_CHECKED: "divTruncChecked" 44 NUM_MOD_INT: "modInt" 45 NUM_MOD_INT_CHECKED: "modIntChecked" 46 NUM_MOD_FLOAT: "modFloat" diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index 678175cbb5..af6512cc1c 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -3402,11 +3402,11 @@ mod solve_expr { } #[test] - fn div_floor() { + fn div_trunc() { infer_eq_without_problem( indoc!( r#" - Num.divFloor + Num.divTrunc "# ), "Int a, Int a -> Int a", @@ -3414,11 +3414,11 @@ mod solve_expr { } #[test] - fn div_floor_checked() { + fn div_trunc_checked() { infer_eq_without_problem( indoc!( r#" - Num.divFloorChecked + Num.divTruncChecked "# ), "Int a, Int a -> Result (Int a) [ DivByZero ]*", diff --git a/compiler/test_gen/src/gen_num.rs b/compiler/test_gen/src/gen_num.rs index 62f9f21eb4..0b1fa649f6 100644 --- a/compiler/test_gen/src/gen_num.rs +++ b/compiler/test_gen/src/gen_num.rs @@ -1050,7 +1050,7 @@ fn gen_div_checked_i64() { assert_evals_to!( indoc!( r#" - when Num.divFloorChecked 1000 10 is + when Num.divTruncChecked 1000 10 is Ok val -> val Err _ -> -1 "# @@ -1066,7 +1066,7 @@ fn gen_div_checked_by_zero_i64() { assert_evals_to!( indoc!( r#" - when Num.divFloorChecked 1000 0 is + when Num.divTruncChecked 1000 0 is Err DivByZero -> 99 _ -> -24 "# diff --git a/compiler/test_mono/src/tests.rs b/compiler/test_mono/src/tests.rs index bba051e6b6..e64a36f72e 100644 --- a/compiler/test_mono/src/tests.rs +++ b/compiler/test_mono/src/tests.rs @@ -275,7 +275,7 @@ fn ir_round() { #[mono_test] fn ir_when_idiv() { r#" - when Num.divFloorChecked 1000 10 is + when Num.divTruncChecked 1000 10 is Ok val -> val Err _ -> -1 "# diff --git a/examples/false-interpreter/False.roc b/examples/false-interpreter/False.roc index f8306e7d8d..537d794a18 100644 --- a/examples/false-interpreter/False.roc +++ b/examples/false-interpreter/False.roc @@ -434,7 +434,7 @@ stepExecCtx = \ctx, char -> ( (T popCtx1 numR) <- Result.after (popNumber ctx) (T popCtx2 numL) <- Result.after (popNumber popCtx1) - res <- Result.after (Num.divFloorChecked numL numR) + res <- Result.after (Num.divTruncChecked numL numR) Ok (Context.pushStack popCtx2 (Number res)) ) diff --git a/repl_test/src/tests.rs b/repl_test/src/tests.rs index d0360ac569..53b692266c 100644 --- a/repl_test/src/tests.rs +++ b/repl_test/src/tests.rs @@ -62,14 +62,14 @@ fn num_rem() { #[cfg(not(feature = "wasm"))] #[test] fn num_floor_division() { - expect_success("Num.divFloor 4 3", "1 : Int *"); + expect_success("Num.divTrunc 4 3", "1 : Int *"); } #[cfg(not(feature = "wasm"))] #[test] fn num_floor_checked_division_success() { expect_success( - "Num.divFloorChecked 4 3", + "Num.divTruncChecked 4 3", "Ok 1 : Result (Int *) [ DivByZero ]*", ); } @@ -78,7 +78,7 @@ fn num_floor_checked_division_success() { #[test] fn num_floor_checked_division_divby_zero() { expect_success( - "Num.divFloorChecked 4 0", + "Num.divTruncChecked 4 0", "Err DivByZero : Result (Int *) [ DivByZero ]*", ); } diff --git a/roc-for-elm-programmers.md b/roc-for-elm-programmers.md index 204ad125a9..ced8f5811e 100644 --- a/roc-for-elm-programmers.md +++ b/roc-for-elm-programmers.md @@ -1294,7 +1294,7 @@ Here are various Roc expressions involving operators, and what they desugar to. | `a - b` | `Num.sub a b` | | `a * b` | `Num.mul a b` | | `a / b` | `Num.div a b` | -| `a // b` | `Num.divFloor a b` | +| `a // b` | `Num.divTrunc a b` | | `a ^ b` | `Num.pow a b` | | `a % b` | `Num.rem a b` | | `a %% b` | `Num.mod a b` | From 1bb71021257317622c706075f0c2fb28fe467745 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 18 Apr 2022 09:47:34 -0400 Subject: [PATCH 314/846] Work around alias analysis bug --- examples/breakout/breakout.roc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index 38967e17ab..22a7c2d98c 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -126,14 +126,14 @@ moveBall = \model -> updateBlocks : Model -> Model updateBlocks = \model -> blockWidth = model.width / numCols - ball = { left: model.ballX, top: model.ballY, width: ballSize, height: ballSize } blocks = List.map model.blocks \block -> when block.status is Removed -> block Active -> + ballRect = { left: model.ballX, top: model.ballY, width: ballSize, height: ballSize } blockRect = { left: block.left, top: block.top, height: blockHeight, width: blockWidth } - if isOverlapping blockRect ball then + if isOverlapping blockRect ballRect then { block & status: Removed } else block From e0c99313265d5153c6b39f268198c62d1f5ab5b5 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Mon, 18 Apr 2022 10:21:56 -0400 Subject: [PATCH 315/846] Bugfix debug printing --- compiler/unify/src/unify.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/unify/src/unify.rs b/compiler/unify/src/unify.rs index 0b78afd630..794f9ad00b 100644 --- a/compiler/unify/src/unify.rs +++ b/compiler/unify/src/unify.rs @@ -349,7 +349,7 @@ fn unify_context(subs: &mut Subs, pool: &mut Pool, ctx: Context) -> Outcome { }; #[cfg(debug_assertions)] - debug_print_unified_types(subs, &ctx, true); + debug_print_unified_types(subs, &ctx, false); result } From 2856a382364404e8a4cbb185ea9c7e8dcda475e6 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Mon, 18 Apr 2022 11:03:25 -0400 Subject: [PATCH 316/846] Solve all when branch pattern constraints before solving their bodies Closes #2886 --- compiler/constrain/src/expr.rs | 214 +++++++++++++++-------------- compiler/solve/tests/solve_expr.rs | 17 +++ 2 files changed, 127 insertions(+), 104 deletions(-) diff --git a/compiler/constrain/src/expr.rs b/compiler/constrain/src/expr.rs index 9fc45351dc..6eff9c376d 100644 --- a/compiler/constrain/src/expr.rs +++ b/compiler/constrain/src/expr.rs @@ -596,109 +596,90 @@ pub fn constrain_expr( NoExpectation(cond_type.clone()), ); - let mut branch_constraints = Vec::with_capacity(branches.len() + 1); - branch_constraints.push(expr_con); + let branch_var = *expr_var; + let branch_type = Variable(branch_var); - match &expected { - FromAnnotation(name, arity, ann_source, _typ) => { - // NOTE deviation from elm. - // - // in elm, `_typ` is used, but because we have this `expr_var` too - // and need to constrain it, this is what works and gives better error messages - let typ = Type::Variable(*expr_var); - - for (index, when_branch) in branches.iter().enumerate() { - let pattern_region = - Region::across_all(when_branch.patterns.iter().map(|v| &v.region)); - - let branch_con = constrain_when_branch( - constraints, - env, - when_branch.value.region, - when_branch, - PExpected::ForReason( - PReason::WhenMatch { - index: HumanIndex::zero_based(index), - }, - cond_type.clone(), - pattern_region, - ), - FromAnnotation( - name.clone(), - *arity, - AnnotationSource::TypedWhenBranch { - index: HumanIndex::zero_based(index), - region: ann_source.region(), - }, - typ.clone(), - ), - ); - - branch_constraints.push(branch_con); + let branch_expr_reason = + |expected: &Expected, index, branch_region| match expected { + FromAnnotation(name, arity, ann_source, _typ) => { + // NOTE deviation from elm. + // + // in elm, `_typ` is used, but because we have this `expr_var` too + // and need to constrain it, this is what works and gives better error messages + FromAnnotation( + name.clone(), + *arity, + AnnotationSource::TypedWhenBranch { + index, + region: ann_source.region(), + }, + branch_type.clone(), + ) } - branch_constraints.push(constraints.equal_types_var( - *expr_var, - expected, - Category::When, - region, - )); + _ => ForReason( + Reason::WhenBranch { index }, + branch_type.clone(), + branch_region, + ), + }; - return constraints.exists_many([cond_var, *expr_var], branch_constraints); - } + let mut branch_cons = Vec::with_capacity(branches.len()); + let mut pattern_cons = Vec::with_capacity(branches.len()); - _ => { - let branch_var = *expr_var; - let branch_type = Variable(branch_var); - let mut branch_cons = Vec::with_capacity(branches.len()); + for (index, when_branch) in branches.iter().enumerate() { + let pattern_region = + Region::across_all(when_branch.patterns.iter().map(|v| &v.region)); - for (index, when_branch) in branches.iter().enumerate() { - let pattern_region = - Region::across_all(when_branch.patterns.iter().map(|v| &v.region)); - let branch_con = constrain_when_branch( - constraints, - env, - region, - when_branch, - PExpected::ForReason( - PReason::WhenMatch { - index: HumanIndex::zero_based(index), - }, - cond_type.clone(), - pattern_region, - ), - ForReason( - Reason::WhenBranch { - index: HumanIndex::zero_based(index), - }, - branch_type.clone(), - when_branch.value.region, - ), - ); + let (pattern_con, branch_con) = constrain_when_branch( + constraints, + env, + region, + when_branch, + PExpected::ForReason( + PReason::WhenMatch { + index: HumanIndex::zero_based(index), + }, + cond_type.clone(), + pattern_region, + ), + branch_expr_reason( + &expected, + HumanIndex::zero_based(index), + when_branch.value.region, + ), + ); - branch_cons.push(branch_con); - } - - // Deviation: elm adds another layer of And nesting - // - // Record the original conditional expression's constraint. - // Each branch's pattern must have the same type - // as the condition expression did. - // - // The return type of each branch must equal the return type of - // the entire when-expression. - branch_cons.push(constraints.equal_types_var( - branch_var, - expected, - Category::When, - region, - )); - branch_constraints.push(constraints.and_constraint(branch_cons)); - } + pattern_cons.push(pattern_con); + branch_cons.push(branch_con); } + // Deviation: elm adds another layer of And nesting + // + // Record the original conditional expression's constraint. + // Each branch's pattern must have the same type + // as the condition expression did. + // + // The return type of each branch must equal the return type of + // the entire when-expression. + // branch_cons.extend(pattern_cons); + // branch_constraints.push(constraints.and_constraint(pattern_cons)); + let mut total_cons = Vec::with_capacity(1 + 2 * branches.len() + 1); + total_cons.push(expr_con); + total_cons.extend(pattern_cons); + total_cons.extend(branch_cons); + total_cons.push(constraints.equal_types_var( + branch_var, + expected, + Category::When, + region, + )); + + let branch_constraints = constraints.and_constraint(total_cons); + // exhautiveness checking happens when converting to mono::Expr - constraints.exists_many([cond_var, *expr_var], branch_constraints) + // ...for now + constraints.exists([cond_var, *expr_var], branch_constraints) } Access { record_var, @@ -1087,6 +1068,8 @@ pub fn constrain_expr( } } +/// Constrain a when branch, returning a pair of constraints (pattern constraint, body constraint). +/// We want to constraint all pattern constraints in a "when" before body constraints. #[inline(always)] fn constrain_when_branch( constraints: &mut Constraints, @@ -1095,7 +1078,7 @@ fn constrain_when_branch( when_branch: &WhenBranch, pattern_expected: PExpected, expr_expected: Expected, -) -> Constraint { +) -> (Constraint, Constraint) { let ret_constraint = constrain_expr( constraints, env, @@ -1123,7 +1106,7 @@ fn constrain_when_branch( ); } - if let Some(loc_guard) = &when_branch.guard { + let (pattern_constraints, body_constraints) = if let Some(loc_guard) = &when_branch.guard { let guard_constraint = constrain_expr( constraints, env, @@ -1140,17 +1123,40 @@ fn constrain_when_branch( let state_constraints = constraints.and_constraint(state.constraints); let inner = constraints.let_constraint([], [], [], guard_constraint, ret_constraint); - constraints.let_constraint([], state.vars, state.headers, state_constraints, inner) + (state_constraints, inner) } else { let state_constraints = constraints.and_constraint(state.constraints); - constraints.let_constraint( - [], - state.vars, - state.headers, - state_constraints, - ret_constraint, - ) - } + (state_constraints, ret_constraint) + }; + + // Our goal is to constrain and introduce variables in all pattern when branch patterns before + // looking at their bodies. + // + // pat1 -> body1 + // *^^^ +~~~~ + // pat2 -> body2 + // *^^^ +~~~~ + // + // * solve first + // + solve second + // + // For a single pattern/body pair, we must introduce variables and symbols defined in the + // pattern before solving the body, since those definitions are effectively let-bound. + // + // But also, we'd like to solve all branch pattern constraints in one swoop before looking at + // the bodies, because the patterns may have presence constraints that expect to be built up + // together. + // + // For this reason, we distinguish the two - and introduce variables in the branch patterns + // as part of the pattern constraint, while only binding those variables during solving of the + // bodies. + let pattern_introduction_constraints = + constraints.let_constraint([], state.vars, [], pattern_constraints, Constraint::True); + + let branch_body_constraints = + constraints.let_constraint([], [], state.headers, Constraint::True, body_constraints); + + (pattern_introduction_constraints, branch_body_constraints) } fn constrain_field( diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index 678175cbb5..c3dbf84746 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -5932,4 +5932,21 @@ mod solve_expr { "a -> U64 | a has Hash", ) } + + #[test] + fn when_branch_and_body_flipflop() { + infer_eq_without_problem( + indoc!( + r#" + func = \record -> + when record.tag is + A -> { record & tag: B } + B -> { record & tag: A } + + func + "# + ), + "{ tag : [ A, B ] }a -> { tag : [ A, B ] }a", + ) + } } From fc606fd220c28e0427425fec10d7f87aab52107a Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 18 Apr 2022 11:55:26 -0400 Subject: [PATCH 317/846] Reproduce canonicalization bug --- examples/breakout/breakout.roc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index 22a7c2d98c..3ab0a9ed79 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -1,6 +1,6 @@ app "breakout" packages { pf: "platform" } - imports [ pf.Game.{ Bounds, Elem, Event, Rgba } ] + imports [ pf.Game.{ Bounds, Elem, Event, Rgba, Rect } ] provides [ program ] { Model } to pf paddleWidth = 0.2 # width of the paddle, as a % of screen width @@ -15,6 +15,7 @@ numBlocks = numRows * numCols Model : { blocks : List Block, + rects : List Rect, # Screen height and width height : F32, @@ -41,6 +42,7 @@ init : Bounds -> Model init = \{ width, height } -> { blocks: initBlocks width, + rects: [ Rect { left: 0, top: 0, width: 100, height: 100, color: { r: 1, g: 0.5, b: 1, a: 1 } } ], # Screen height and width width, @@ -170,7 +172,7 @@ render = \model -> top, width: blockWidth, height: blockHeight, - color: { r: color.r * 0.8, g: color.g * 0.8, b: color.b * 0.8, a: alpha }, + color: { r: color.r * 0.8, g: color.g * 0.8, b: color.b * 0.8, a: color.a * alpha }, } # The inner retangle is smaller than the outer one, but gets drawn on top of it, @@ -180,7 +182,7 @@ render = \model -> top: top + border, width: blockWidth - (border * 2), height: blockHeight - (border * 2), - color: { color & a: alpha }, + color: { color & a: color.a * alpha }, } [ outer, inner ] From 8c64db5c0a6b7fb246f20b16cd7f6248d8a6f9be Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 18 Apr 2022 11:59:48 -0400 Subject: [PATCH 318/846] Reproduce a different canonicalization bug --- examples/breakout/breakout.roc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index 3ab0a9ed79..43f31002fe 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -1,6 +1,6 @@ app "breakout" packages { pf: "platform" } - imports [ pf.Game.{ Bounds, Elem, Event, Rgba, Rect } ] + imports [ pf.Game.{ Bounds, Elem, Event, Rgba } ] provides [ program ] { Model } to pf paddleWidth = 0.2 # width of the paddle, as a % of screen width @@ -15,7 +15,7 @@ numBlocks = numRows * numCols Model : { blocks : List Block, - rects : List Rect, + foo : List _, # Screen height and width height : F32, @@ -42,7 +42,7 @@ init : Bounds -> Model init = \{ width, height } -> { blocks: initBlocks width, - rects: [ Rect { left: 0, top: 0, width: 100, height: 100, color: { r: 1, g: 0.5, b: 1, a: 1 } } ], + foo: [ {} ] # Screen height and width width, From 443bb28f1b968286090e84a9c35b6b2ded603add Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 18 Apr 2022 12:23:07 -0400 Subject: [PATCH 319/846] Remove bug reproduction code --- examples/breakout/breakout.roc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index 43f31002fe..a807d9ab64 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -15,7 +15,6 @@ numBlocks = numRows * numCols Model : { blocks : List Block, - foo : List _, # Screen height and width height : F32, @@ -40,9 +39,10 @@ Block : { init : Bounds -> Model init = \{ width, height } -> + blocks = initBlocks width + { - blocks: initBlocks width, - foo: [ {} ] + blocks, # Screen height and width width, @@ -164,7 +164,7 @@ render = \model -> when status is Fading amount -> amount Active -> 1 - Removed -> 0 + Removed -> 1 # TODO this should be 0, but for some reason Active blocks have this memory. # This outer rectangle gets drawn first, and will appear to be a border. outer = Rect { From 4fa98e964ec3e2f2af567bf6d1198b0bdd5c4f44 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 18 Apr 2022 12:23:33 -0400 Subject: [PATCH 320/846] Reproduce malloc error (on M1 Mac at least) --- examples/breakout/breakout.roc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index a807d9ab64..d1f6ef6cc4 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -97,8 +97,8 @@ update = \model, event -> tick : Model -> Model tick = \model -> model - |> moveBall - |> updateBlocks + #|> moveBall + #|> updateBlocks moveBall : Model -> Model moveBall = \model -> @@ -157,8 +157,15 @@ render : Model -> List Elem render = \model -> blockWidth = model.width / numCols + blocks = + # Drop the conditional to fix the malloc error + if True then + initBlocks model.width + else + model.blocks + rects = - List.joinMap model.blocks \{ left, top, color, status } -> + List.joinMap blocks \{ left, top, color, status } -> border = blockBorder * blockWidth alpha = when status is From ceea194db44da35fff29fc9411ce04f2b1897430 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Mon, 18 Apr 2022 12:56:22 -0400 Subject: [PATCH 321/846] Make sure "is open" constraints add flex vars at the right rank --- compiler/solve/src/solve.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index 61814b7282..e30be26df4 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -1187,6 +1187,7 @@ fn solve( match new_desc.content { Content::Structure(FlatType::TagUnion(tags, _)) => { let new_ext = subs.fresh_unnamed_flex_var(); + subs.set_rank(new_ext, new_desc.rank); let new_union = Content::Structure(FlatType::TagUnion(tags, new_ext)); new_desc.content = new_union; subs.set(actual, new_desc); From b81bbefa751530f45c662652c7cad626bfa0567a Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Mon, 18 Apr 2022 12:56:48 -0400 Subject: [PATCH 322/846] Make sure we solve all variables in all patterns before all bodies --- compiler/constrain/src/expr.rs | 133 ++++++++++++++++++++------------- 1 file changed, 81 insertions(+), 52 deletions(-) diff --git a/compiler/constrain/src/expr.rs b/compiler/constrain/src/expr.rs index 6eff9c376d..c9b41c1da8 100644 --- a/compiler/constrain/src/expr.rs +++ b/compiler/constrain/src/expr.rs @@ -624,33 +624,67 @@ pub fn constrain_expr( ), }; - let mut branch_cons = Vec::with_capacity(branches.len()); + // Our goal is to constrain and introduce variables in all pattern when branch patterns before + // looking at their bodies. + // + // pat1 -> body1 + // *^^^ +~~~~ + // pat2 -> body2 + // *^^^ +~~~~ + // + // * solve first + // + solve second + // + // For a single pattern/body pair, we must introduce variables and symbols defined in the + // pattern before solving the body, since those definitions are effectively let-bound. + // + // But also, we'd like to solve all branch pattern constraints in one swoop before looking at + // the bodies, because the patterns may have presence constraints that expect to be built up + // together. + // + // For this reason, we distinguish the two - and introduce variables in the branch patterns + // as part of the pattern constraint, solving all of those at once, and then solving the body + // constraints. + let mut pattern_vars = Vec::with_capacity(branches.len()); + let mut pattern_headers = SendMap::default(); let mut pattern_cons = Vec::with_capacity(branches.len()); + let mut branch_cons = Vec::with_capacity(branches.len()); for (index, when_branch) in branches.iter().enumerate() { let pattern_region = Region::across_all(when_branch.patterns.iter().map(|v| &v.region)); - let (pattern_con, branch_con) = constrain_when_branch( - constraints, - env, - region, - when_branch, - PExpected::ForReason( - PReason::WhenMatch { - index: HumanIndex::zero_based(index), - }, - cond_type.clone(), - pattern_region, - ), - branch_expr_reason( - &expected, - HumanIndex::zero_based(index), - when_branch.value.region, - ), - ); + let (new_pattern_vars, new_pattern_headers, pattern_con, branch_con) = + constrain_when_branch_help( + constraints, + env, + region, + when_branch, + PExpected::ForReason( + PReason::WhenMatch { + index: HumanIndex::zero_based(index), + }, + cond_type.clone(), + pattern_region, + ), + branch_expr_reason( + &expected, + HumanIndex::zero_based(index), + when_branch.value.region, + ), + ); + pattern_vars.extend(new_pattern_vars); + debug_assert!( + pattern_headers + .clone() + .intersection(new_pattern_headers.clone()) + .is_empty(), + "Two patterns introduce the same symbols - that's a bug!" + ); + pattern_headers.extend(new_pattern_headers); pattern_cons.push(pattern_con); + branch_cons.push(branch_con); } @@ -666,8 +700,20 @@ pub fn constrain_expr( // branch_constraints.push(constraints.and_constraint(pattern_cons)); let mut total_cons = Vec::with_capacity(1 + 2 * branches.len() + 1); total_cons.push(expr_con); - total_cons.extend(pattern_cons); - total_cons.extend(branch_cons); + + // Solve all the pattern constraints together, introducing variables in the pattern as + // need be before solving the bodies. + let pattern_constraints = constraints.and_constraint(pattern_cons); + let body_constraints = constraints.and_constraint(branch_cons); + let when_body_con = constraints.let_constraint( + [], + pattern_vars, + pattern_headers, + pattern_constraints, + body_constraints, + ); + total_cons.push(when_body_con); + total_cons.push(constraints.equal_types_var( branch_var, expected, @@ -1068,17 +1114,22 @@ pub fn constrain_expr( } } -/// Constrain a when branch, returning a pair of constraints (pattern constraint, body constraint). +/// Constrain a when branch, returning (variables in pattern, symbols introduced in pattern, pattern constraint, body constraint). /// We want to constraint all pattern constraints in a "when" before body constraints. #[inline(always)] -fn constrain_when_branch( +fn constrain_when_branch_help( constraints: &mut Constraints, env: &Env, region: Region, when_branch: &WhenBranch, pattern_expected: PExpected, expr_expected: Expected, -) -> (Constraint, Constraint) { +) -> ( + Vec, + SendMap>, + Constraint, + Constraint, +) { let ret_constraint = constrain_expr( constraints, env, @@ -1129,34 +1180,12 @@ fn constrain_when_branch( (state_constraints, ret_constraint) }; - // Our goal is to constrain and introduce variables in all pattern when branch patterns before - // looking at their bodies. - // - // pat1 -> body1 - // *^^^ +~~~~ - // pat2 -> body2 - // *^^^ +~~~~ - // - // * solve first - // + solve second - // - // For a single pattern/body pair, we must introduce variables and symbols defined in the - // pattern before solving the body, since those definitions are effectively let-bound. - // - // But also, we'd like to solve all branch pattern constraints in one swoop before looking at - // the bodies, because the patterns may have presence constraints that expect to be built up - // together. - // - // For this reason, we distinguish the two - and introduce variables in the branch patterns - // as part of the pattern constraint, while only binding those variables during solving of the - // bodies. - let pattern_introduction_constraints = - constraints.let_constraint([], state.vars, [], pattern_constraints, Constraint::True); - - let branch_body_constraints = - constraints.let_constraint([], [], state.headers, Constraint::True, body_constraints); - - (pattern_introduction_constraints, branch_body_constraints) + ( + state.vars, + state.headers, + pattern_constraints, + body_constraints, + ) } fn constrain_field( From 1c8b18f17640b98909455715d474dac1cf6a34fd Mon Sep 17 00:00:00 2001 From: Folkert Date: Mon, 18 Apr 2022 21:43:16 +0200 Subject: [PATCH 323/846] import Box by default --- compiler/load_internal/src/file.rs | 13 +++++++++++++ compiler/module/src/ident.rs | 1 + 2 files changed, 14 insertions(+) diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index 3eabe6bb65..cd0517b7b5 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -143,6 +143,11 @@ impl Default for ModuleCache<'_> { PQModuleName::Unqualified(ModuleName::from(ModuleName::NUM)), ); + module_names.insert( + ModuleId::BOX, + PQModuleName::Unqualified(ModuleName::from(ModuleName::BOX)), + ); + Self { module_names, headers: Default::default(), @@ -1853,6 +1858,14 @@ fn update<'a>( } if !header.module_id.is_builtin() { + header + .package_qualified_imported_modules + .insert(PackageQualified::Unqualified(ModuleId::BOX)); + + header + .imported_modules + .insert(ModuleId::BOX, Region::zero()); + header .package_qualified_imported_modules .insert(PackageQualified::Unqualified(ModuleId::STR)); diff --git a/compiler/module/src/ident.rs b/compiler/module/src/ident.rs index 3f3c8d51f1..1056f9eeaf 100644 --- a/compiler/module/src/ident.rs +++ b/compiler/module/src/ident.rs @@ -90,6 +90,7 @@ impl ModuleName { pub const DICT: &'static str = "Dict"; pub const SET: &'static str = "Set"; pub const RESULT: &'static str = "Result"; + pub const BOX: &'static str = "Box"; pub fn as_str(&self) -> &str { self.0.as_str() From c0f9fb52a968d2d80d37996b084381b6bf0beb71 Mon Sep 17 00:00:00 2001 From: Folkert Date: Mon, 18 Apr 2022 21:45:40 +0200 Subject: [PATCH 324/846] update Box imports/ignores because it is now available by default --- compiler/test_gen/src/gen_primitives.rs | 24 ++++++------------------ repl_test/src/tests.rs | 2 -- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/compiler/test_gen/src/gen_primitives.rs b/compiler/test_gen/src/gen_primitives.rs index e9de763814..16f4248dc8 100644 --- a/compiler/test_gen/src/gen_primitives.rs +++ b/compiler/test_gen/src/gen_primitives.rs @@ -3266,12 +3266,9 @@ fn box_and_unbox_string() { assert_evals_to!( indoc!( r#" - app "test" imports [ Box ] provides [ main ] to "./platform" - - main = - Str.concat "Leverage " "agile frameworks to provide a robust synopsis for high level overviews" - |> Box.box - |> Box.unbox + Str.concat "Leverage " "agile frameworks to provide a robust synopsis for high level overviews" + |> Box.box + |> Box.unbox "# ), RocStr::from( @@ -3287,10 +3284,7 @@ fn box_and_unbox_num() { assert_evals_to!( indoc!( r#" - app "test" imports [ Box ] provides [ main ] to "./platform" - - main = - Box.unbox (Box.box (123u8)) + Box.unbox (Box.box (123u8)) "# ), 123, @@ -3304,10 +3298,7 @@ fn box_and_unbox_record() { assert_evals_to!( indoc!( r#" - app "test" imports [ Box ] provides [ main ] to "./platform" - - main = - Box.unbox (Box.box { a: 15u8, b: 27u8 }) + Box.unbox (Box.box { a: 15u8, b: 27u8 }) "# ), (15, 27), @@ -3321,13 +3312,10 @@ fn box_and_unbox_tag_union() { assert_evals_to!( indoc!( r#" - app "test" imports [ Box ] provides [ main ] to "./platform" - v : [ A U8, B U8 ] # usually stack allocated v = B 27u8 - main = - Box.unbox (Box.box v) + Box.unbox (Box.box v) "# ), (27, 1), diff --git a/repl_test/src/tests.rs b/repl_test/src/tests.rs index 7e920cfaf5..d0360ac569 100644 --- a/repl_test/src/tests.rs +++ b/repl_test/src/tests.rs @@ -1086,7 +1086,6 @@ fn print_i8_issue_2710() { #[cfg(not(feature = "wasm"))] #[test] -#[ignore] fn box_box() { expect_success( indoc!( @@ -1100,7 +1099,6 @@ fn box_box() { #[cfg(not(feature = "wasm"))] #[test] -#[ignore] fn box_box_type_alias() { expect_success( indoc!( From 9ed4ca973928970c3a9d29f6334fc7a3a5745109 Mon Sep 17 00:00:00 2001 From: Kevin Gillette Date: Mon, 18 Apr 2022 13:54:40 -0600 Subject: [PATCH 325/846] remove Num.mod and Num.modUnchecked --- TUTORIAL.md | 1 - compiler/builtins/README.md | 2 +- compiler/builtins/docs/Num.roc | 50 +++------------------- compiler/builtins/roc/Num.roc | 4 -- compiler/builtins/src/std.rs | 14 ------ compiler/can/src/builtins.rs | 66 ----------------------------- compiler/fmt/tests/test_fmt.rs | 4 +- compiler/gen_llvm/src/llvm/build.rs | 11 ++--- compiler/gen_wasm/src/low_level.rs | 5 --- compiler/module/src/low_level.rs | 3 -- compiler/module/src/symbol.rs | 4 -- compiler/mono/src/borrow.rs | 7 +-- compiler/mono/src/low_level.rs | 1 - roc-for-elm-programmers.md | 1 - 14 files changed, 17 insertions(+), 156 deletions(-) diff --git a/TUTORIAL.md b/TUTORIAL.md index e8820da585..78d24474b6 100644 --- a/TUTORIAL.md +++ b/TUTORIAL.md @@ -1944,7 +1944,6 @@ Here are various Roc expressions involving operators, and what they desugar to. | `a // b` | `Num.divFloor a b` | | `a ^ b` | `Num.pow a b` | | `a % b` | `Num.rem a b` | -| `a %% b` | `Num.mod a b` | | `a >> b` | `Num.shr a b` | | `a << b` | `Num.shl a b` | | `-a` | `Num.neg a` | diff --git a/compiler/builtins/README.md b/compiler/builtins/README.md index 2ab95cd260..9954fc4c87 100644 --- a/compiler/builtins/README.md +++ b/compiler/builtins/README.md @@ -4,7 +4,7 @@ Builtins are the functions and modules that are implicitly imported into every m ### module/src/symbol.rs -Towards the bottom of `symbol.rs` there is a `define_builtins!` macro being used that takes many modules and function names. The first level (`List`, `Int` ..) is the module name, and the second level is the function or value name (`reverse`, `mod` ..). If you wanted to add a `Int` function called `addTwo` go to `2 Int: "Int" => {` and inside that case add to the bottom `38 INT_ADD_TWO: "addTwo"` (assuming there are 37 existing ones). +Towards the bottom of `symbol.rs` there is a `define_builtins!` macro being used that takes many modules and function names. The first level (`List`, `Int` ..) is the module name, and the second level is the function or value name (`reverse`, `rem` ..). If you wanted to add a `Int` function called `addTwo` go to `2 Int: "Int" => {` and inside that case add to the bottom `38 INT_ADD_TWO: "addTwo"` (assuming there are 37 existing ones). Some of these have `#` inside their name (`first#list`, `#lt` ..). This is a trick we are doing to hide implementation details from Roc programmers. To a Roc programmer, a name with `#` in it is invalid, because `#` means everything after it is parsed to a comment. We are constructing these functions manually, so we are circumventing the parsing step and dont have such restrictions. We get to make functions and values with `#` which as a consequence are not accessible to Roc programmers. Roc programmers simply cannot reference them. diff --git a/compiler/builtins/docs/Num.roc b/compiler/builtins/docs/Num.roc index e33a7eda94..320c308a8e 100644 --- a/compiler/builtins/docs/Num.roc +++ b/compiler/builtins/docs/Num.roc @@ -82,8 +82,6 @@ interface Num minI64, minU64, minI128, - mod, - modChecked, mul, mulChecked, mulWrap, @@ -807,27 +805,18 @@ toDec : Num * -> Dec ## This is the same as the #// operator. divRound : Int a, Int a -> Int a -## Perform flooring modulo on two integers. +## Obtain the remainder (truncating modulo) from the division of two integers. ## -## Modulo is the same as remainder when working with positive numbers, -## but if either number is negative, then modulo works differently. +## `a % b` is shorthand for `Num.rem a b`. ## -## Additionally, flooring modulo uses [Float].floor on the result. +## >>> 5 % 7 ## -## (Use [Float].mod for non-flooring modulo.) +## >>> Num.rem 5 7 ## -## Return `Err DivByZero` if the second integer is zero, because division by zero is undefined in mathematics. +## >>> -8 % -3 ## -## `a %% b` is shorthand for `Int.modFloor a b`. -## -## >>> 5 %% 7 -## -## >>> Int.modFloor 5 7 -## -## >>> -8 %% -3 -## -## >>> Int.modFloor -8 -3 -#modFloor : Int a, Int a -> Result (Int a) [ DivByZero ]* +## >>> Num.rem -8 -3 +rem : Int a, Int a -> Int a ## Bitwise @@ -1099,31 +1088,6 @@ atan : Float a -> Float a ## >>> |> Num.div 2.0 div : Float a, Float a -> Float a -## Perform modulo on two [Float]s. -## -## Modulo is the same as remainder when working with positive numbers, -## but if either number is negative, then modulo works differently. -## -## `a % b` is shorthand for `Num.mod a b`. -## -## [Division by zero is undefined in mathematics](https://en.wikipedia.org/wiki/Division_by_zero), -## and as such, so is modulo by zero. Because of this, you should make sure never -## to pass zero for the second argument to this function! -## -## Passing [mod] a [Dec] value of zero for its second argument will cause a panic. -## Passing [mod] a [F32] and [F64] value for its second argument will cause it -## to return [*NaN*](Num.isNaN). -## -## >>> 5.0 % 7.0 -## -## >>> Num.mod 5 7 -## -## `Num.mod` can be convenient in pipelines. -## -## >>> Num.pi -## >>> |> Num.mod 2.0 -mod : Float a, Float a -> Float a - ## Raises a [Float] to the power of another [Float]. ## ## ` diff --git a/compiler/builtins/roc/Num.roc b/compiler/builtins/roc/Num.roc index 3a56f282f1..e7a7cfd5e3 100644 --- a/compiler/builtins/roc/Num.roc +++ b/compiler/builtins/roc/Num.roc @@ -71,8 +71,6 @@ interface Num remChecked, div, divChecked, - mod, - modChecked, sqrt, sqrtChecked, log, @@ -247,8 +245,6 @@ divFloorChecked : Int a, Int a -> Result (Int a) [ DivByZero ]* rem : Int a, Int a -> Int a remChecked : Int a, Int a -> Result (Int a) [ DivByZero ]* -mod : Int a, Int a -> Int a -modChecked : Int a, Int a -> Result (Int a) [ DivByZero ]* isMultipleOf : Int a, Int a -> Bool diff --git a/compiler/builtins/src/std.rs b/compiler/builtins/src/std.rs index 111523e170..ad40de78b4 100644 --- a/compiler/builtins/src/std.rs +++ b/compiler/builtins/src/std.rs @@ -407,20 +407,6 @@ pub fn types() -> MutMap { Box::new(result_type(int_type(flex(TVAR1)), div_by_zero.clone())), ); - // mod : Int a, Int a -> Int a - add_top_level_function_type!( - Symbol::NUM_MOD, - vec![int_type(flex(TVAR1)), int_type(flex(TVAR1))], - Box::new(int_type(flex(TVAR1))), - ); - - // modChecked : Int a, Int a -> Result (Int a) [ DivByZero ]* - add_top_level_function_type!( - Symbol::NUM_MOD_CHECKED, - vec![int_type(flex(TVAR1)), int_type(flex(TVAR1))], - Box::new(result_type(int_type(flex(TVAR1)), div_by_zero.clone())), - ); - // isMultipleOf : Int a, Int a -> Bool add_top_level_function_type!( Symbol::NUM_IS_MULTIPLE_OF, diff --git a/compiler/can/src/builtins.rs b/compiler/can/src/builtins.rs index b715d983e1..0cfc71498e 100644 --- a/compiler/can/src/builtins.rs +++ b/compiler/can/src/builtins.rs @@ -204,8 +204,6 @@ pub fn builtin_defs_map(symbol: Symbol, var_store: &mut VarStore) -> Option NUM_NEG => num_neg, NUM_REM => num_rem, NUM_REM_CHECKED => num_rem_checked, - NUM_MOD => num_mod, - NUM_MOD_CHECKED => num_mod_checked, NUM_IS_MULTIPLE_OF => num_is_multiple_of, NUM_SQRT => num_sqrt, NUM_SQRT_CHECKED => num_sqrt_checked, @@ -4292,70 +4290,6 @@ fn num_rem_checked(symbol: Symbol, var_store: &mut VarStore) -> Def { ) } -/// Num.mod : Int a, Int a -> Int a -fn num_mod(symbol: Symbol, var_store: &mut VarStore) -> Def { - num_binop(symbol, var_store, LowLevel::NumModUnchecked) -} - -/// Num.modChecked : Int a, Int a -> Result (Int a) [ DivByZero ]* -fn num_mod_checked(symbol: Symbol, var_store: &mut VarStore) -> Def { - let num_var = var_store.fresh(); - let unbound_zero_var = var_store.fresh(); - let bool_var = var_store.fresh(); - let ret_var = var_store.fresh(); - - let body = If { - branch_var: ret_var, - cond_var: bool_var, - branches: vec![( - // if condition - no_region( - // Num.isNeq arg2 0 - RunLowLevel { - op: LowLevel::NotEq, - args: vec![ - (num_var, Var(Symbol::ARG_2)), - (num_var, num(unbound_zero_var, 0, num_no_bound())), - ], - ret_var: bool_var, - }, - ), - // arg1 was not zero - no_region( - // Ok (Int.#modUnsafe arg1 arg2) - tag( - "Ok", - vec![ - // Num.#modUnsafe arg1 arg2 - RunLowLevel { - op: LowLevel::NumModUnchecked, - args: vec![ - (num_var, Var(Symbol::ARG_1)), - (num_var, Var(Symbol::ARG_2)), - ], - ret_var: num_var, - }, - ], - var_store, - ), - ), - )], - final_else: Box::new(no_region(tag( - "Err", - vec![tag("DivByZero", Vec::new(), var_store)], - var_store, - ))), - }; - - defn( - symbol, - vec![(num_var, Symbol::ARG_1), (num_var, Symbol::ARG_2)], - var_store, - body, - ret_var, - ) -} - /// Num.isMultipleOf : Int a, Int a -> Bool fn num_is_multiple_of(symbol: Symbol, var_store: &mut VarStore) -> Def { lowlevel_2(symbol, LowLevel::NumIsMultipleOf, var_store) diff --git a/compiler/fmt/tests/test_fmt.rs b/compiler/fmt/tests/test_fmt.rs index c5bde106a7..c514ff7cf0 100644 --- a/compiler/fmt/tests/test_fmt.rs +++ b/compiler/fmt/tests/test_fmt.rs @@ -2537,7 +2537,7 @@ mod test_fmt { indoc!( r#" 2 % 3 - %% 5 + // 5 + 7 "# ), @@ -2545,7 +2545,7 @@ mod test_fmt { r#" 2 % 3 - %% 5 + // 5 + 7 "# ), diff --git a/compiler/gen_llvm/src/llvm/build.rs b/compiler/gen_llvm/src/llvm/build.rs index d147da254b..4a61732299 100644 --- a/compiler/gen_llvm/src/llvm/build.rs +++ b/compiler/gen_llvm/src/llvm/build.rs @@ -5814,9 +5814,9 @@ fn run_low_level<'a, 'ctx, 'env>( } NumAdd | NumSub | NumMul | NumLt | NumLte | NumGt | NumGte | NumRemUnchecked - | NumModUnchecked | NumIsMultipleOf | NumAddWrap | NumAddChecked | NumAddSaturated - | NumDivUnchecked | NumDivCeilUnchecked | NumPow | NumPowInt | NumSubWrap - | NumSubChecked | NumSubSaturated | NumMulWrap | NumMulChecked => { + | NumIsMultipleOf | NumAddWrap | NumAddChecked | NumAddSaturated | NumDivUnchecked + | NumDivCeilUnchecked | NumPow | NumPowInt | NumSubWrap | NumSubChecked + | NumSubSaturated | NumMulWrap | NumMulChecked => { debug_assert_eq!(args.len(), 2); let (lhs_arg, lhs_layout) = load_symbol_and_layout(scope, &args[0]); @@ -6578,11 +6578,6 @@ fn build_int_binop<'a, 'ctx, 'env>( bd.build_int_unsigned_rem(lhs, rhs, "rem_uint").into() } } - NumModUnchecked => { - // there generally is not hardware support for flooring mod; - // it could probably be implemented in pure Roc in terms of Num.rem. - todo!("mod is not implemented") - } NumIsMultipleOf => { // this builds the following construct // diff --git a/compiler/gen_wasm/src/low_level.rs b/compiler/gen_wasm/src/low_level.rs index f3b3b2b180..b376f613b5 100644 --- a/compiler/gen_wasm/src/low_level.rs +++ b/compiler/gen_wasm/src/low_level.rs @@ -434,11 +434,6 @@ impl<'a> LowLevelCall<'a> { _ => todo!("{:?} for {:?}", self.lowlevel, self.ret_layout), } } - NumModUnchecked => { - // wasm does not provide a flooring modulo instruction, - // so it would need to be emulated. - todo!("{:?}", self.lowlevel) - } NumIsMultipleOf => todo!("{:?}", self.lowlevel), NumAbs => { self.load_args(backend); diff --git a/compiler/module/src/low_level.rs b/compiler/module/src/low_level.rs index 12fc990851..f1d5c9a6fb 100644 --- a/compiler/module/src/low_level.rs +++ b/compiler/module/src/low_level.rs @@ -85,7 +85,6 @@ pub enum LowLevel { NumDivUnchecked, NumDivCeilUnchecked, NumRemUnchecked, - NumModUnchecked, NumIsMultipleOf, NumAbs, NumNeg, @@ -296,8 +295,6 @@ impl LowLevelWrapperType { Symbol::NUM_DIV_CEIL_CHECKED => WrapperIsRequired, Symbol::NUM_REM => CanBeReplacedBy(NumRemUnchecked), Symbol::NUM_REM_CHECKED => WrapperIsRequired, - Symbol::NUM_MOD => CanBeReplacedBy(NumModUnchecked), - Symbol::NUM_MOD_CHECKED => WrapperIsRequired, Symbol::NUM_IS_MULTIPLE_OF => CanBeReplacedBy(NumIsMultipleOf), Symbol::NUM_ABS => CanBeReplacedBy(NumAbs), Symbol::NUM_NEG => CanBeReplacedBy(NumNeg), diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index 067e4b01a0..c569e8044f 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -950,10 +950,6 @@ define_builtins! { 41 NUM_DIV_FLOAT_CHECKED: "divChecked" 42 NUM_DIV_FLOOR: "divFloor" 43 NUM_DIV_FLOOR_CHECKED: "divFloorChecked" - 44 NUM_MOD: "mod" - 45 NUM_MOD_CHECKED: "modChecked" - 46 NUM_MOD_FLOAT: "modFloat" - 47 NUM_MOD_FLOAT_CHECKED: "modFloatChecked" 48 NUM_SQRT: "sqrt" 49 NUM_SQRT_CHECKED: "sqrtChecked" 50 NUM_LOG: "log" diff --git a/compiler/mono/src/borrow.rs b/compiler/mono/src/borrow.rs index 8174ca8918..7fd09d0bfc 100644 --- a/compiler/mono/src/borrow.rs +++ b/compiler/mono/src/borrow.rs @@ -994,9 +994,10 @@ pub fn lowlevel_borrow_signature(arena: &Bump, op: LowLevel) -> &[bool] { And | Or | NumAdd | NumAddWrap | NumAddChecked | NumAddSaturated | NumSub | NumSubWrap | NumSubChecked | NumSubSaturated | NumMul | NumMulWrap | NumMulChecked | NumGt | NumGte | NumLt | NumLte | NumCompare | NumDivUnchecked | NumDivCeilUnchecked - | NumRemUnchecked | NumModUnchecked | NumIsMultipleOf | NumPow | NumPowInt - | NumBitwiseAnd | NumBitwiseXor | NumBitwiseOr | NumShiftLeftBy | NumShiftRightBy - | NumShiftRightZfBy => arena.alloc_slice_copy(&[irrelevant, irrelevant]), + | NumRemUnchecked | NumIsMultipleOf | NumPow | NumPowInt | NumBitwiseAnd + | NumBitwiseXor | NumBitwiseOr | NumShiftLeftBy | NumShiftRightBy | NumShiftRightZfBy => { + arena.alloc_slice_copy(&[irrelevant, irrelevant]) + } NumToStr | NumAbs | NumNeg | NumSin | NumCos | NumSqrtUnchecked | NumLogUnchecked | NumRound | NumCeiling | NumFloor | NumToFloat | Not | NumIsFinite | NumAtan | NumAcos diff --git a/compiler/mono/src/low_level.rs b/compiler/mono/src/low_level.rs index 5dc37091df..03092a25cb 100644 --- a/compiler/mono/src/low_level.rs +++ b/compiler/mono/src/low_level.rs @@ -144,7 +144,6 @@ enum FirstOrder { NumCompare, NumDivUnchecked, NumRemUnchecked, - NumModUnchecked, NumIsMultipleOf, NumAbs, NumNeg, diff --git a/roc-for-elm-programmers.md b/roc-for-elm-programmers.md index 204ad125a9..e9225d2195 100644 --- a/roc-for-elm-programmers.md +++ b/roc-for-elm-programmers.md @@ -1297,7 +1297,6 @@ Here are various Roc expressions involving operators, and what they desugar to. | `a // b` | `Num.divFloor a b` | | `a ^ b` | `Num.pow a b` | | `a % b` | `Num.rem a b` | -| `a %% b` | `Num.mod a b` | | `a >> b` | `Num.shr a b` | | `a << b` | `Num.shl a b` | | `-a` | `Num.neg a` | From 833aecbf8aa8a30f110aeb10bd796afc135e91e5 Mon Sep 17 00:00:00 2001 From: Folkert Date: Mon, 18 Apr 2022 22:05:06 +0200 Subject: [PATCH 326/846] fix name --- compiler/load_internal/src/file.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index cd0517b7b5..893369354d 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -2525,7 +2525,7 @@ fn load_pkg_config<'a>( } } -fn foo<'a>( +fn load_builtin_module_help<'a>( arena: &'a Bump, filename: &str, src_bytes: &'a str, @@ -2576,7 +2576,7 @@ fn load_builtin_module<'a>( ) -> (ModuleId, Msg<'a>) { let src_bytes = module_source(module_id); - let (info, parse_state) = foo(arena, module_name, src_bytes); + let (info, parse_state) = load_builtin_module_help(arena, module_name, src_bytes); send_header( info, From f129777115963b9829f78e181ba775e6d9c49ddb Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Mon, 18 Apr 2022 18:04:46 -0400 Subject: [PATCH 327/846] Explicitly disallow ability definitions in nested scopes Abilities can only be defined on the toplevel of a module. There is a technical reason to this, which is that during type solving we must introduce all abilities at the very beginning, and we need to make sure ranks are correct. But there is a practical reason as well, which is that nested ability definitions don't seem to be very useful. Note that specializations can be nested, and are allowed to be. Also, we can revisit this in the future. I just don't want experiments to break right now because someone uses an ability in a nested scope where we don't expect. Closes #2878 --- compiler/can/src/def.rs | 24 ++++++++-- compiler/parse/src/ast.rs | 6 +++ compiler/problem/src/can.rs | 3 ++ reporting/src/error/canonicalize.rs | 13 +++++ reporting/tests/test_reporting.rs | 74 ++++++++++++++++++----------- 5 files changed, 89 insertions(+), 31 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index cd4d2c79d5..2cc1cd85ae 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -241,10 +241,12 @@ pub fn canonicalize_defs<'a>( let pending_type_defs = type_defs .into_iter() .filter_map(|loc_def| { - to_pending_type_def(env, loc_def.value, &mut scope).map(|(new_output, pending_def)| { - output.union(new_output); - pending_def - }) + to_pending_type_def(env, loc_def.value, &mut scope, pattern_type).map( + |(new_output, pending_def)| { + output.union(new_output); + pending_def + }, + ) }) .collect::>(); @@ -1679,6 +1681,7 @@ fn to_pending_type_def<'a>( env: &mut Env<'a>, def: &'a ast::TypeDef<'a>, scope: &mut Scope, + pattern_type: PatternType, ) -> Option<(Output, PendingTypeDef<'a>)> { use ast::TypeDef::*; @@ -1762,6 +1765,19 @@ fn to_pending_type_def<'a>( } } + Ability { + header, members, .. + } if pattern_type != PatternType::TopLevelDef => { + let header_region = header.region(); + let region = Region::span_across( + &header_region, + &members.last().map(|m| m.region()).unwrap_or(header_region), + ); + env.problem(Problem::AbilityNotOnToplevel { region }); + + Some((Output::default(), PendingTypeDef::InvalidAbility)) + } + Ability { header: TypeHeader { name, vars }, members, diff --git a/compiler/parse/src/ast.rs b/compiler/parse/src/ast.rs index f616f07d7f..0c086b32b7 100644 --- a/compiler/parse/src/ast.rs +++ b/compiler/parse/src/ast.rs @@ -278,6 +278,12 @@ pub struct AbilityMember<'a> { pub typ: Loc>, } +impl AbilityMember<'_> { + pub fn region(&self) -> Region { + Region::across_all([self.name.region, self.typ.region].iter()) + } +} + #[derive(Debug, Clone, Copy, PartialEq)] pub enum TypeDef<'a> { /// A type alias. This is like a standalone annotation, except the pattern diff --git a/compiler/problem/src/can.rs b/compiler/problem/src/can.rs index f8d1684418..a12584c580 100644 --- a/compiler/problem/src/can.rs +++ b/compiler/problem/src/can.rs @@ -135,6 +135,9 @@ pub enum Problem { loc_name: Loc, ability: Symbol, }, + AbilityNotOnToplevel { + region: Region, + }, } #[derive(Clone, Debug, PartialEq)] diff --git a/reporting/src/error/canonicalize.rs b/reporting/src/error/canonicalize.rs index d366baf6f2..33962e08ab 100644 --- a/reporting/src/error/canonicalize.rs +++ b/reporting/src/error/canonicalize.rs @@ -45,6 +45,7 @@ const ILLEGAL_HAS_CLAUSE: &str = "ILLEGAL HAS CLAUSE"; const ABILITY_MEMBER_MISSING_HAS_CLAUSE: &str = "ABILITY MEMBER MISSING HAS CLAUSE"; const ABILITY_MEMBER_HAS_EXTRANEOUS_HAS_CLAUSE: &str = "ABILITY MEMBER HAS EXTRANEOUS HAS CLAUSE"; const ABILITY_MEMBER_BINDS_MULTIPLE_VARIABLES: &str = "ABILITY MEMBER BINDS MULTIPLE VARIABLES"; +const ABILITY_NOT_ON_TOPLEVEL: &str = "ABILITY NOT ON TOP-LEVEL"; pub fn can_problem<'b>( alloc: &'b RocDocAllocator<'b>, @@ -736,6 +737,18 @@ pub fn can_problem<'b>( title = ABILITY_MEMBER_HAS_EXTRANEOUS_HAS_CLAUSE.to_string(); severity = Severity::RuntimeError; } + + Problem::AbilityNotOnToplevel { region } => { + doc = alloc.stack(vec![ + alloc.concat(vec![alloc.reflow( + "This ability definition is not on the top-level of a module:", + )]), + alloc.region(lines.convert_region(region)), + alloc.reflow("Abilities can only be defined on the top-level of a Roc module."), + ]); + title = ABILITY_NOT_ON_TOPLEVEL.to_string(); + severity = Severity::RuntimeError; + } }; Report { diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 265edb773b..712befac26 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -9137,10 +9137,10 @@ I need all branches in an `if` to have the same type! new_report_problem_as( indoc!( r#" + app "test" provides [] to "./platform" + Hash a b c has hash : a -> U64 | a has Hash - - 1 "# ), indoc!( @@ -9149,8 +9149,8 @@ I need all branches in an `if` to have the same type! The definition of the `Hash` ability includes type variables: - 4│ Hash a b c has - ^^^^^ + 3│ Hash a b c has + ^^^^^ Abilities cannot depend on type variables, but their member values can! @@ -9159,8 +9159,8 @@ I need all branches in an `if` to have the same type! `Hash` is not used anywhere in your code. - 4│ Hash a b c has - ^^^^ + 3│ Hash a b c has + ^^^^ If you didn't intend on using `Hash` then remove it so future readers of your code don't wonder why it is there. @@ -9228,12 +9228,13 @@ I need all branches in an `if` to have the same type! new_report_problem_as( indoc!( r#" + app "test" provides [ a ] to "./platform" + Ability has ab : a -> {} | a has Ability Alias : Ability a : Alias - a "# ), indoc!( @@ -9242,8 +9243,8 @@ I need all branches in an `if` to have the same type! The definition of the `Alias` aliases references the ability `Ability`: - 6│ Alias : Ability - ^^^^^ + 5│ Alias : Ability + ^^^^^ Abilities are not types, but you can add an ability constraint to a type variable `a` by writing @@ -9256,8 +9257,8 @@ I need all branches in an `if` to have the same type! `ab` is not used anywhere in your code. - 4│ Ability has ab : a -> {} | a has Ability - ^^ + 3│ Ability has ab : a -> {} | a has Ability + ^^ If you didn't intend on using `ab` then remove it so future readers of your code don't wonder why it is there. @@ -9271,11 +9272,11 @@ I need all branches in an `if` to have the same type! new_report_problem_as( indoc!( r#" + app "test" provides [ ab ] to "./platform" + Ability has ab : a -> U64 | a has Ability Ability has ab1 : a -> U64 | a has Ability - - 1 "# ), indoc!( @@ -9284,26 +9285,16 @@ I need all branches in an `if` to have the same type! The `Ability` name is first defined here: - 4│ Ability has ab : a -> U64 | a has Ability - ^^^^^^^ + 3│ Ability has ab : a -> U64 | a has Ability + ^^^^^^^ But then it's defined a second time here: - 6│ Ability has ab1 : a -> U64 | a has Ability - ^^^^^^^ + 5│ Ability has ab1 : a -> U64 | a has Ability + ^^^^^^^ Since these abilities have the same name, it's easy to use the wrong one on accident. Give one of them a new name. - - ── UNUSED DEFINITION ─────────────────────────────────────────────────────────── - - `ab` is not used anywhere in your code. - - 4│ Ability has ab : a -> U64 | a has Ability - ^^ - - If you didn't intend on using `ab` then remove it so future readers of - your code don't wonder why it is there. "# ), ) @@ -9783,4 +9774,33 @@ I need all branches in an `if` to have the same type! ), ) } + + #[test] + fn ability_not_on_toplevel() { + new_report_problem_as( + indoc!( + r#" + app "test" provides [ main ] to "./platform" + + main = + Hash has + hash : a -> U64 | a has Hash + + 123 + "# + ), + indoc!( + r#" + ── ABILITY NOT ON TOP-LEVEL ──────────────────────────────────────────────────── + + This ability definition is not on the top-level of a module: + + 4│> Hash has + 5│> hash : a -> U64 | a has Hash + + Abilities can only be defined on the top-level of a Roc module. + "# + ), + ) + } } From 777363afd072d8f1682973fbcf52d97524be3b7d Mon Sep 17 00:00:00 2001 From: Kevin Gillette Date: Mon, 18 Apr 2022 19:14:43 -0600 Subject: [PATCH 328/846] decrement symbol IDs to account for mod removal --- compiler/module/src/symbol.rs | 222 +++++++++++++++++----------------- 1 file changed, 111 insertions(+), 111 deletions(-) diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index bc7d57f6b0..5be2237189 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -950,117 +950,117 @@ define_builtins! { 41 NUM_DIV_FLOAT_CHECKED: "divChecked" 42 NUM_DIV_FLOOR: "divFloor" 43 NUM_DIV_FLOOR_CHECKED: "divFloorChecked" - 48 NUM_SQRT: "sqrt" - 49 NUM_SQRT_CHECKED: "sqrtChecked" - 50 NUM_LOG: "log" - 51 NUM_LOG_CHECKED: "logChecked" - 52 NUM_ROUND: "round" - 53 NUM_COMPARE: "compare" - 54 NUM_POW: "pow" - 55 NUM_CEILING: "ceiling" - 56 NUM_POW_INT: "powInt" - 57 NUM_FLOOR: "floor" - 58 NUM_ADD_WRAP: "addWrap" - 59 NUM_ADD_CHECKED: "addChecked" - 60 NUM_ADD_SATURATED: "addSaturated" - 61 NUM_ATAN: "atan" - 62 NUM_ACOS: "acos" - 63 NUM_ASIN: "asin" - 64 NUM_AT_SIGNED128: "@Signed128" - 65 NUM_SIGNED128: "Signed128" - 66 NUM_AT_SIGNED64: "@Signed64" - 67 NUM_SIGNED64: "Signed64" - 68 NUM_AT_SIGNED32: "@Signed32" - 69 NUM_SIGNED32: "Signed32" - 70 NUM_AT_SIGNED16: "@Signed16" - 71 NUM_SIGNED16: "Signed16" - 72 NUM_AT_SIGNED8: "@Signed8" - 73 NUM_SIGNED8: "Signed8" - 74 NUM_AT_UNSIGNED128: "@Unsigned128" - 75 NUM_UNSIGNED128: "Unsigned128" - 76 NUM_AT_UNSIGNED64: "@Unsigned64" - 77 NUM_UNSIGNED64: "Unsigned64" - 78 NUM_AT_UNSIGNED32: "@Unsigned32" - 79 NUM_UNSIGNED32: "Unsigned32" - 80 NUM_AT_UNSIGNED16: "@Unsigned16" - 81 NUM_UNSIGNED16: "Unsigned16" - 82 NUM_AT_UNSIGNED8: "@Unsigned8" - 83 NUM_UNSIGNED8: "Unsigned8" - 84 NUM_AT_BINARY64: "@Binary64" - 85 NUM_BINARY64: "Binary64" - 86 NUM_AT_BINARY32: "@Binary32" - 87 NUM_BINARY32: "Binary32" - 88 NUM_BITWISE_AND: "bitwiseAnd" - 89 NUM_BITWISE_XOR: "bitwiseXor" - 90 NUM_BITWISE_OR: "bitwiseOr" - 91 NUM_SHIFT_LEFT: "shiftLeftBy" - 92 NUM_SHIFT_RIGHT: "shiftRightBy" - 93 NUM_SHIFT_RIGHT_ZERO_FILL: "shiftRightZfBy" - 94 NUM_SUB_WRAP: "subWrap" - 95 NUM_SUB_CHECKED: "subChecked" - 96 NUM_SUB_SATURATED: "subSaturated" - 97 NUM_MUL_WRAP: "mulWrap" - 98 NUM_MUL_CHECKED: "mulChecked" - 99 NUM_INT: "Int" - 100 NUM_FLOAT: "Float" - 101 NUM_AT_NATURAL: "@Natural" - 102 NUM_NATURAL: "Natural" - 103 NUM_NAT: "Nat" - 104 NUM_INT_CAST: "intCast" - 105 NUM_IS_MULTIPLE_OF: "isMultipleOf" - 106 NUM_AT_DECIMAL: "@Decimal" - 107 NUM_DECIMAL: "Decimal" - 108 NUM_DEC: "Dec" // the Num.Dectype alias - 109 NUM_BYTES_TO_U16: "bytesToU16" - 110 NUM_BYTES_TO_U32: "bytesToU32" - 111 NUM_CAST_TO_NAT: "#castToNat" - 112 NUM_DIV_CEIL: "divCeil" - 113 NUM_DIV_CEIL_CHECKED: "divCeilChecked" - 114 NUM_TO_STR: "toStr" - 115 NUM_MIN_I8: "minI8" - 116 NUM_MAX_I8: "maxI8" - 117 NUM_MIN_U8: "minU8" - 118 NUM_MAX_U8: "maxU8" - 119 NUM_MIN_I16: "minI16" - 120 NUM_MAX_I16: "maxI16" - 121 NUM_MIN_U16: "minU16" - 122 NUM_MAX_U16: "maxU16" - 123 NUM_MIN_I32: "minI32" - 124 NUM_MAX_I32: "maxI32" - 125 NUM_MIN_U32: "minU32" - 126 NUM_MAX_U32: "maxU32" - 127 NUM_MIN_I64: "minI64" - 128 NUM_MAX_I64: "maxI64" - 129 NUM_MIN_U64: "minU64" - 130 NUM_MAX_U64: "maxU64" - 131 NUM_MIN_I128: "minI128" - 132 NUM_MAX_I128: "maxI128" - 133 NUM_TO_I8: "toI8" - 134 NUM_TO_I8_CHECKED: "toI8Checked" - 135 NUM_TO_I16: "toI16" - 136 NUM_TO_I16_CHECKED: "toI16Checked" - 137 NUM_TO_I32: "toI32" - 138 NUM_TO_I32_CHECKED: "toI32Checked" - 139 NUM_TO_I64: "toI64" - 140 NUM_TO_I64_CHECKED: "toI64Checked" - 141 NUM_TO_I128: "toI128" - 142 NUM_TO_I128_CHECKED: "toI128Checked" - 143 NUM_TO_U8: "toU8" - 144 NUM_TO_U8_CHECKED: "toU8Checked" - 145 NUM_TO_U16: "toU16" - 146 NUM_TO_U16_CHECKED: "toU16Checked" - 147 NUM_TO_U32: "toU32" - 148 NUM_TO_U32_CHECKED: "toU32Checked" - 149 NUM_TO_U64: "toU64" - 150 NUM_TO_U64_CHECKED: "toU64Checked" - 151 NUM_TO_U128: "toU128" - 152 NUM_TO_U128_CHECKED: "toU128Checked" - 153 NUM_TO_NAT: "toNat" - 154 NUM_TO_NAT_CHECKED: "toNatChecked" - 155 NUM_TO_F32: "toF32" - 156 NUM_TO_F32_CHECKED: "toF32Checked" - 157 NUM_TO_F64: "toF64" - 158 NUM_TO_F64_CHECKED: "toF64Checked" + 44 NUM_SQRT: "sqrt" + 45 NUM_SQRT_CHECKED: "sqrtChecked" + 46 NUM_LOG: "log" + 47 NUM_LOG_CHECKED: "logChecked" + 48 NUM_ROUND: "round" + 49 NUM_COMPARE: "compare" + 50 NUM_POW: "pow" + 51 NUM_CEILING: "ceiling" + 52 NUM_POW_INT: "powInt" + 53 NUM_FLOOR: "floor" + 54 NUM_ADD_WRAP: "addWrap" + 55 NUM_ADD_CHECKED: "addChecked" + 56 NUM_ADD_SATURATED: "addSaturated" + 57 NUM_ATAN: "atan" + 58 NUM_ACOS: "acos" + 59 NUM_ASIN: "asin" + 60 NUM_AT_SIGNED128: "@Signed128" + 61 NUM_SIGNED128: "Signed128" + 62 NUM_AT_SIGNED64: "@Signed64" + 63 NUM_SIGNED64: "Signed64" + 64 NUM_AT_SIGNED32: "@Signed32" + 65 NUM_SIGNED32: "Signed32" + 66 NUM_AT_SIGNED16: "@Signed16" + 67 NUM_SIGNED16: "Signed16" + 68 NUM_AT_SIGNED8: "@Signed8" + 69 NUM_SIGNED8: "Signed8" + 70 NUM_AT_UNSIGNED128: "@Unsigned128" + 71 NUM_UNSIGNED128: "Unsigned128" + 72 NUM_AT_UNSIGNED64: "@Unsigned64" + 73 NUM_UNSIGNED64: "Unsigned64" + 74 NUM_AT_UNSIGNED32: "@Unsigned32" + 75 NUM_UNSIGNED32: "Unsigned32" + 76 NUM_AT_UNSIGNED16: "@Unsigned16" + 77 NUM_UNSIGNED16: "Unsigned16" + 78 NUM_AT_UNSIGNED8: "@Unsigned8" + 79 NUM_UNSIGNED8: "Unsigned8" + 80 NUM_AT_BINARY64: "@Binary64" + 81 NUM_BINARY64: "Binary64" + 82 NUM_AT_BINARY32: "@Binary32" + 83 NUM_BINARY32: "Binary32" + 84 NUM_BITWISE_AND: "bitwiseAnd" + 85 NUM_BITWISE_XOR: "bitwiseXor" + 86 NUM_BITWISE_OR: "bitwiseOr" + 87 NUM_SHIFT_LEFT: "shiftLeftBy" + 88 NUM_SHIFT_RIGHT: "shiftRightBy" + 89 NUM_SHIFT_RIGHT_ZERO_FILL: "shiftRightZfBy" + 90 NUM_SUB_WRAP: "subWrap" + 91 NUM_SUB_CHECKED: "subChecked" + 92 NUM_SUB_SATURATED: "subSaturated" + 93 NUM_MUL_WRAP: "mulWrap" + 94 NUM_MUL_CHECKED: "mulChecked" + 95 NUM_INT: "Int" + 96 NUM_FLOAT: "Float" + 97 NUM_AT_NATURAL: "@Natural" + 98 NUM_NATURAL: "Natural" + 99 NUM_NAT: "Nat" + 100 NUM_INT_CAST: "intCast" + 101 NUM_IS_MULTIPLE_OF: "isMultipleOf" + 102 NUM_AT_DECIMAL: "@Decimal" + 103 NUM_DECIMAL: "Decimal" + 104 NUM_DEC: "Dec" // the Num.Dectype alias + 105 NUM_BYTES_TO_U16: "bytesToU16" + 106 NUM_BYTES_TO_U32: "bytesToU32" + 107 NUM_CAST_TO_NAT: "#castToNat" + 108 NUM_DIV_CEIL: "divCeil" + 109 NUM_DIV_CEIL_CHECKED: "divCeilChecked" + 110 NUM_TO_STR: "toStr" + 111 NUM_MIN_I8: "minI8" + 112 NUM_MAX_I8: "maxI8" + 113 NUM_MIN_U8: "minU8" + 114 NUM_MAX_U8: "maxU8" + 115 NUM_MIN_I16: "minI16" + 116 NUM_MAX_I16: "maxI16" + 117 NUM_MIN_U16: "minU16" + 118 NUM_MAX_U16: "maxU16" + 119 NUM_MIN_I32: "minI32" + 120 NUM_MAX_I32: "maxI32" + 121 NUM_MIN_U32: "minU32" + 122 NUM_MAX_U32: "maxU32" + 123 NUM_MIN_I64: "minI64" + 124 NUM_MAX_I64: "maxI64" + 125 NUM_MIN_U64: "minU64" + 126 NUM_MAX_U64: "maxU64" + 127 NUM_MIN_I128: "minI128" + 128 NUM_MAX_I128: "maxI128" + 129 NUM_TO_I8: "toI8" + 130 NUM_TO_I8_CHECKED: "toI8Checked" + 131 NUM_TO_I16: "toI16" + 132 NUM_TO_I16_CHECKED: "toI16Checked" + 133 NUM_TO_I32: "toI32" + 134 NUM_TO_I32_CHECKED: "toI32Checked" + 135 NUM_TO_I64: "toI64" + 136 NUM_TO_I64_CHECKED: "toI64Checked" + 137 NUM_TO_I128: "toI128" + 138 NUM_TO_I128_CHECKED: "toI128Checked" + 139 NUM_TO_U8: "toU8" + 140 NUM_TO_U8_CHECKED: "toU8Checked" + 141 NUM_TO_U16: "toU16" + 142 NUM_TO_U16_CHECKED: "toU16Checked" + 143 NUM_TO_U32: "toU32" + 144 NUM_TO_U32_CHECKED: "toU32Checked" + 145 NUM_TO_U64: "toU64" + 146 NUM_TO_U64_CHECKED: "toU64Checked" + 147 NUM_TO_U128: "toU128" + 148 NUM_TO_U128_CHECKED: "toU128Checked" + 149 NUM_TO_NAT: "toNat" + 150 NUM_TO_NAT_CHECKED: "toNatChecked" + 151 NUM_TO_F32: "toF32" + 152 NUM_TO_F32_CHECKED: "toF32Checked" + 153 NUM_TO_F64: "toF64" + 154 NUM_TO_F64_CHECKED: "toF64Checked" } 2 BOOL: "Bool" => { 0 BOOL_BOOL: "Bool" // the Bool.Bool type alias From cd8ab753e3af4bff3c8b71a3b5409f239e6d930d Mon Sep 17 00:00:00 2001 From: Kevin Gillette Date: Mon, 18 Apr 2022 14:01:01 -0600 Subject: [PATCH 329/846] remove %% operator --- compiler/can/src/operator.rs | 1 - compiler/fmt/src/expr.rs | 2 -- compiler/module/src/called_via.rs | 12 ++++-------- compiler/parse/fuzz/dict.txt | 1 - compiler/parse/src/expr.rs | 1 - highlight/src/tokenizer.rs | 2 -- highlight/tests/peg_grammar.rs | 1 - 7 files changed, 4 insertions(+), 16 deletions(-) diff --git a/compiler/can/src/operator.rs b/compiler/can/src/operator.rs index 6bbb3d23b9..7ab7a0c8e7 100644 --- a/compiler/can/src/operator.rs +++ b/compiler/can/src/operator.rs @@ -425,7 +425,6 @@ fn binop_to_function(binop: BinOp) -> (&'static str, &'static str) { Slash => (ModuleName::NUM, "div"), DoubleSlash => (ModuleName::NUM, "divFloor"), Percent => (ModuleName::NUM, "rem"), - DoublePercent => (ModuleName::NUM, "mod"), Plus => (ModuleName::NUM, "add"), Minus => (ModuleName::NUM, "sub"), Equals => (ModuleName::BOOL, "isEq"), diff --git a/compiler/fmt/src/expr.rs b/compiler/fmt/src/expr.rs index b54ff826b2..70b62b0e13 100644 --- a/compiler/fmt/src/expr.rs +++ b/compiler/fmt/src/expr.rs @@ -372,7 +372,6 @@ fn push_op(buf: &mut Buf, op: BinOp) { called_via::BinOp::Slash => buf.push('/'), called_via::BinOp::DoubleSlash => buf.push_str("//"), called_via::BinOp::Percent => buf.push('%'), - called_via::BinOp::DoublePercent => buf.push_str("%%"), called_via::BinOp::Plus => buf.push('+'), called_via::BinOp::Minus => buf.push('-'), called_via::BinOp::Equals => buf.push_str("=="), @@ -1104,7 +1103,6 @@ fn sub_expr_requests_parens(expr: &Expr<'_>) -> bool { | BinOp::Slash | BinOp::DoubleSlash | BinOp::Percent - | BinOp::DoublePercent | BinOp::Plus | BinOp::Minus | BinOp::Equals diff --git a/compiler/module/src/called_via.rs b/compiler/module/src/called_via.rs index c83245d3e9..bc314e0eec 100644 --- a/compiler/module/src/called_via.rs +++ b/compiler/module/src/called_via.rs @@ -34,7 +34,6 @@ pub enum BinOp { Slash, DoubleSlash, Percent, - DoublePercent, Plus, Minus, Equals, @@ -58,8 +57,8 @@ impl BinOp { pub fn width(self) -> u16 { match self { Caret | Star | Slash | Percent | Plus | Minus | LessThan | GreaterThan => 1, - DoubleSlash | DoublePercent | Equals | NotEquals | LessThanOrEq | GreaterThanOrEq - | And | Or | Pizza => 2, + DoubleSlash | Equals | NotEquals | LessThanOrEq | GreaterThanOrEq | And | Or + | Pizza => 2, Assignment | IsAliasType | IsOpaqueType | Backpassing => unreachable!(), } } @@ -97,9 +96,7 @@ impl BinOp { use self::Associativity::*; match self { - Pizza | Star | Slash | DoubleSlash | DoublePercent | Percent | Plus | Minus => { - LeftAssociative - } + Pizza | Star | Slash | DoubleSlash | Percent | Plus | Minus => LeftAssociative, And | Or | Caret => RightAssociative, Equals | NotEquals | LessThan | GreaterThan | LessThanOrEq | GreaterThanOrEq => { NonAssociative @@ -111,7 +108,7 @@ impl BinOp { fn precedence(self) -> u8 { match self { Caret => 7, - Star | Slash | DoubleSlash | DoublePercent | Percent => 6, + Star | Slash | DoubleSlash | Percent => 6, Plus | Minus => 5, Equals | NotEquals | LessThan | GreaterThan | LessThanOrEq | GreaterThanOrEq => 4, And => 3, @@ -142,7 +139,6 @@ impl std::fmt::Display for BinOp { Slash => "/", DoubleSlash => "//", Percent => "%", - DoublePercent => "%%", Plus => "+", Minus => "-", Equals => "==", diff --git a/compiler/parse/fuzz/dict.txt b/compiler/parse/fuzz/dict.txt index c22976ccb2..c2e458bbda 100644 --- a/compiler/parse/fuzz/dict.txt +++ b/compiler/parse/fuzz/dict.txt @@ -30,7 +30,6 @@ ">=" ">" "^" -"%%" "%" "->" \ No newline at end of file diff --git a/compiler/parse/src/expr.rs b/compiler/parse/src/expr.rs index 4d0654b31f..b3e94f2f6d 100644 --- a/compiler/parse/src/expr.rs +++ b/compiler/parse/src/expr.rs @@ -2762,7 +2762,6 @@ where "&&" => good!(BinOp::And, 2), "||" => good!(BinOp::Or, 2), "//" => good!(BinOp::DoubleSlash, 2), - "%%" => good!(BinOp::DoublePercent, 2), "->" => { // makes no progress, so it does not interfere with `_ if isGood -> ...` Err((NoProgress, to_error("->", state.pos()), state)) diff --git a/highlight/src/tokenizer.rs b/highlight/src/tokenizer.rs index 9eddb99da1..7cb486cd6d 100644 --- a/highlight/src/tokenizer.rs +++ b/highlight/src/tokenizer.rs @@ -63,7 +63,6 @@ pub enum Token { OpAnd = 0b_0110_1101, OpOr = 0b_0110_1110, OpDoubleSlash = 0b_0110_1111, - OpDoublePercent = 0b_0111_0001, OpBackpassing = 0b_0111_1010, TodoNextThing = 0b_1000_0000, @@ -395,7 +394,6 @@ fn lex_operator(bytes: &[u8]) -> (Token, usize) { b"&" => Token::Ampersand, b"||" => Token::OpOr, b"//" => Token::OpDoubleSlash, - b"%%" => Token::OpDoublePercent, b"->" => Token::Arrow, b"<-" => Token::OpBackpassing, op => { diff --git a/highlight/tests/peg_grammar.rs b/highlight/tests/peg_grammar.rs index 7b8bde04c5..f28b9af74c 100644 --- a/highlight/tests/peg_grammar.rs +++ b/highlight/tests/peg_grammar.rs @@ -368,7 +368,6 @@ mod test_peg_grammar { / [T::OpSlash] / [T::OpDoubleSlash] / [T::OpPercent] - / [T::OpDoublePercent] rule mul_level_expr() = unary_expr() (mul_level_op() unary_expr())* From b59d33a1d580f11aabff84116ae2c0263904aabc Mon Sep 17 00:00:00 2001 From: Folkert Date: Tue, 19 Apr 2022 23:00:05 +0200 Subject: [PATCH 330/846] refactor roc_collections --- compiler/can/src/annotation.rs | 2 +- compiler/can/src/def.rs | 3 +- compiler/can/src/effect_module.rs | 2 +- compiler/can/src/env.rs | 2 +- compiler/can/src/expr.rs | 2 +- compiler/can/src/module.rs | 2 +- compiler/can/src/procedure.rs | 2 +- compiler/collections/src/all.rs | 96 ----------------------------- compiler/collections/src/lib.rs | 4 ++ compiler/collections/src/vec_set.rs | 95 ++++++++++++++++++++++++++++ compiler/load_internal/src/file.rs | 4 +- 11 files changed, 108 insertions(+), 106 deletions(-) create mode 100644 compiler/collections/src/vec_set.rs diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index 97b74f2101..92caf9298b 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -1,6 +1,6 @@ use crate::env::Env; use crate::scope::Scope; -use roc_collections::all::{ImMap, MutMap, MutSet, SendMap, VecSet}; +use roc_collections::{ImMap, MutMap, MutSet, SendMap, VecSet}; use roc_module::ident::{Ident, Lowercase, TagName}; use roc_module::symbol::{IdentIds, ModuleId, Symbol}; use roc_parse::ast::{AssignedField, ExtractSpaces, Pattern, Tag, TypeAnnotation, TypeHeader}; diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index cd4d2c79d5..1acf368e9b 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -10,8 +10,7 @@ use crate::pattern::{bindings_from_patterns, canonicalize_def_header_pattern, Pa use crate::procedure::References; use crate::scope::create_alias; use crate::scope::Scope; -use roc_collections::all::ImSet; -use roc_collections::all::{default_hasher, ImEntry, ImMap, MutMap, MutSet, SendMap}; +use roc_collections::{default_hasher, ImEntry, ImMap, ImSet, MutMap, MutSet, SendMap}; use roc_module::ident::Lowercase; use roc_module::symbol::Symbol; use roc_parse::ast; diff --git a/compiler/can/src/effect_module.rs b/compiler/can/src/effect_module.rs index 3695757117..2e58dc1bd1 100644 --- a/compiler/can/src/effect_module.rs +++ b/compiler/can/src/effect_module.rs @@ -4,7 +4,7 @@ use crate::env::Env; use crate::expr::{ClosureData, Expr, Recursive}; use crate::pattern::Pattern; use crate::scope::Scope; -use roc_collections::all::{SendMap, VecSet}; +use roc_collections::{SendMap, VecSet}; use roc_module::called_via::CalledVia; use roc_module::ident::TagName; use roc_module::symbol::Symbol; diff --git a/compiler/can/src/env.rs b/compiler/can/src/env.rs index 1d63c283c1..8c3f3fb8b1 100644 --- a/compiler/can/src/env.rs +++ b/compiler/can/src/env.rs @@ -1,5 +1,5 @@ use crate::procedure::References; -use roc_collections::all::{MutMap, VecSet}; +use roc_collections::{MutMap, VecSet}; use roc_module::ident::{Ident, Lowercase, ModuleName}; use roc_module::symbol::{IdentIds, ModuleId, ModuleIds, Symbol}; use roc_problem::can::{Problem, RuntimeError}; diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index fb14cf2db1..63c44001bd 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -9,7 +9,7 @@ use crate::num::{ use crate::pattern::{canonicalize_pattern, Pattern}; use crate::procedure::References; use crate::scope::Scope; -use roc_collections::all::{MutMap, MutSet, SendMap, VecSet}; +use roc_collections::{MutMap, MutSet, SendMap, VecSet}; use roc_module::called_via::CalledVia; use roc_module::ident::{ForeignSymbol, Lowercase, TagName}; use roc_module::low_level::LowLevel; diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index 974230051c..dbd4a30274 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -7,7 +7,7 @@ use crate::operator::desugar_def; use crate::pattern::Pattern; use crate::scope::Scope; use bumpalo::Bump; -use roc_collections::all::{MutMap, SendMap, VecSet}; +use roc_collections::{MutMap, SendMap, VecSet}; use roc_module::ident::Lowercase; use roc_module::ident::{Ident, TagName}; use roc_module::symbol::{IdentIds, ModuleId, ModuleIds, Symbol}; diff --git a/compiler/can/src/procedure.rs b/compiler/can/src/procedure.rs index 3aa1b92153..c3f7088957 100644 --- a/compiler/can/src/procedure.rs +++ b/compiler/can/src/procedure.rs @@ -1,6 +1,6 @@ use crate::expr::Expr; use crate::pattern::Pattern; -use roc_collections::all::VecSet; +use roc_collections::VecSet; use roc_module::symbol::Symbol; use roc_region::all::{Loc, Region}; use roc_types::subs::Variable; diff --git a/compiler/collections/src/all.rs b/compiler/collections/src/all.rs index 6c1a2b78c4..391f48e488 100644 --- a/compiler/collections/src/all.rs +++ b/compiler/collections/src/all.rs @@ -220,99 +220,3 @@ macro_rules! mut_map { } }; } - -#[derive(Clone, Debug, PartialEq)] -pub struct VecSet { - elements: Vec, -} - -impl Default for VecSet { - fn default() -> Self { - Self { - elements: Vec::new(), - } - } -} - -impl VecSet { - pub fn with_capacity(capacity: usize) -> Self { - Self { - elements: Vec::with_capacity(capacity), - } - } - - pub fn len(&self) -> usize { - self.elements.len() - } - - pub fn is_empty(&self) -> bool { - self.elements.is_empty() - } - - pub fn swap_remove(&mut self, index: usize) -> T { - self.elements.swap_remove(index) - } - - pub fn insert(&mut self, value: T) -> bool { - if self.elements.contains(&value) { - true - } else { - self.elements.push(value); - - false - } - } - - pub fn contains(&self, value: &T) -> bool { - self.elements.contains(value) - } - - pub fn remove(&mut self, value: &T) { - match self.elements.iter().position(|x| x == value) { - None => { - // just do nothing - } - Some(index) => { - self.elements.swap_remove(index); - } - } - } - - pub fn iter(&self) -> impl Iterator { - self.elements.iter() - } -} - -impl Extend for VecSet { - fn extend>(&mut self, iter: T) { - let it = iter.into_iter(); - let hint = it.size_hint(); - - match hint { - (0, Some(0)) => { - // done, do nothing - } - (1, Some(1)) | (2, Some(2)) => { - for value in it { - self.insert(value); - } - } - _ => { - self.elements.extend(it); - - self.elements.sort(); - self.elements.dedup(); - } - } - } -} - -impl IntoIterator for VecSet { - type Item = T; - - type IntoIter = std::vec::IntoIter; - - fn into_iter(self) -> Self::IntoIter { - self.elements.into_iter() - } -} diff --git a/compiler/collections/src/lib.rs b/compiler/collections/src/lib.rs index 16f8d165dc..c5d3e2c31c 100644 --- a/compiler/collections/src/lib.rs +++ b/compiler/collections/src/lib.rs @@ -4,3 +4,7 @@ pub mod all; pub mod soa; +mod vec_set; + +pub use all::{default_hasher, BumpMap, ImEntry, ImMap, ImSet, MutMap, MutSet, SendMap}; +pub use vec_set::VecSet; diff --git a/compiler/collections/src/vec_set.rs b/compiler/collections/src/vec_set.rs new file mode 100644 index 0000000000..4869084677 --- /dev/null +++ b/compiler/collections/src/vec_set.rs @@ -0,0 +1,95 @@ +#[derive(Clone, Debug, PartialEq)] +pub struct VecSet { + elements: Vec, +} + +impl Default for VecSet { + fn default() -> Self { + Self { + elements: Vec::new(), + } + } +} + +impl VecSet { + pub fn with_capacity(capacity: usize) -> Self { + Self { + elements: Vec::with_capacity(capacity), + } + } + + pub fn len(&self) -> usize { + self.elements.len() + } + + pub fn is_empty(&self) -> bool { + self.elements.is_empty() + } + + pub fn swap_remove(&mut self, index: usize) -> T { + self.elements.swap_remove(index) + } + + pub fn insert(&mut self, value: T) -> bool { + if self.elements.contains(&value) { + true + } else { + self.elements.push(value); + + false + } + } + + pub fn contains(&self, value: &T) -> bool { + self.elements.contains(value) + } + + pub fn remove(&mut self, value: &T) { + match self.elements.iter().position(|x| x == value) { + None => { + // just do nothing + } + Some(index) => { + self.elements.swap_remove(index); + } + } + } + + pub fn iter(&self) -> impl Iterator { + self.elements.iter() + } +} + +impl Extend for VecSet { + fn extend>(&mut self, iter: T) { + let it = iter.into_iter(); + let hint = it.size_hint(); + + match hint { + (0, Some(0)) => { + // done, do nothing + } + (1, Some(1)) | (2, Some(2)) => { + for value in it { + self.insert(value); + } + } + _ => { + self.elements.extend(it); + + self.elements.sort(); + self.elements.dedup(); + } + } + } +} + +impl IntoIterator for VecSet { + type Item = T; + + type IntoIter = std::vec::IntoIter; + + fn into_iter(self) -> Self::IntoIter { + self.elements.into_iter() + } +} diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index 893369354d..f8f60cfe4c 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -10,7 +10,7 @@ use roc_can::abilities::AbilitiesStore; use roc_can::constraint::{Constraint as ConstraintSoa, Constraints}; use roc_can::def::Declaration; use roc_can::module::{canonicalize_module_defs, Module}; -use roc_collections::all::{default_hasher, BumpMap, MutMap, MutSet, VecSet}; +use roc_collections::{default_hasher, BumpMap, MutMap, MutSet, VecSet}; use roc_constrain::module::{ constrain_builtin_imports, constrain_module, ExposedByModule, ExposedForModule, ExposedModuleTypes, @@ -1110,7 +1110,7 @@ pub fn load<'a>( ) -> Result, LoadingProblem<'a>> { // When compiling to wasm, we cannot spawn extra threads // so we have a single-threaded implementation - if cfg!(target_family = "wasm") { + if true || cfg!(target_family = "wasm") { load_single_threaded( arena, load_start, From ab44f23e0fa343a973a8eda187876756f11caa7f Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Tue, 19 Apr 2022 18:18:34 -0400 Subject: [PATCH 331/846] Revise record field typo error report --- reporting/src/error/type.rs | 213 ++++++++++++++++++------------------ 1 file changed, 104 insertions(+), 109 deletions(-) diff --git a/reporting/src/error/type.rs b/reporting/src/error/type.rs index d0105febd3..97814456e5 100644 --- a/reporting/src/error/type.rs +++ b/reporting/src/error/type.rs @@ -827,111 +827,111 @@ fn to_expr_report<'b>( You can achieve that with record literal syntax.", )), ), - Reason::RecordUpdateKeys(symbol, expected_fields) => match found - .clone() - .unwrap_structural_alias() - { - ErrorType::Record(actual_fields, ext) => { - let expected_set: MutSet<_> = expected_fields.keys().cloned().collect(); - let actual_set: MutSet<_> = actual_fields.keys().cloned().collect(); + Reason::RecordUpdateKeys(symbol, expected_fields) => { + match found.clone().unwrap_structural_alias() { + ErrorType::Record(actual_fields, ext) => { + let expected_set: MutSet<_> = expected_fields.keys().cloned().collect(); + let actual_set: MutSet<_> = actual_fields.keys().cloned().collect(); - let mut diff = expected_set.difference(&actual_set); + let mut diff = expected_set.difference(&actual_set); - match diff.next().and_then(|k| Some((k, expected_fields.get(k)?))) { - None => report_mismatch( - alloc, - lines, - filename, - &category, - found, - expected_type, - region, - Some(expr_region), - alloc.reflow("Something is off with this record update:"), - alloc.concat(vec![ - alloc.reflow("The"), - alloc.symbol_unqualified(symbol), - alloc.reflow(" record is"), - ]), - alloc.reflow("But this update needs it to be compatible with:"), - None, - ), - Some((field, field_region)) => { - let r_doc = alloc.symbol_unqualified(symbol); - let f_doc = alloc.record_field(field.clone()); - - let header = alloc.concat(vec![ - alloc.reflow("The "), - r_doc.clone(), - alloc.reflow(" record does not have a "), - f_doc.clone(), - alloc.reflow(" field:"), - ]); - - let mut suggestions = suggest::sort( - field.as_str(), - actual_fields.into_iter().collect::>(), - ); - - let doc = alloc.stack(vec![ - header, - alloc.region(lines.convert_region(*field_region)), - if suggestions.is_empty() { - alloc.concat(vec![ - alloc.reflow("In fact, "), - r_doc, - alloc.reflow(" is a record with NO fields!"), - ]) - } else { - let f = suggestions.remove(0); - let fs = suggestions; - - alloc.stack(vec![ - alloc.concat(vec![ - alloc.reflow("This is usually a typo. Here are the "), - r_doc, - alloc.reflow(" fields that are most similar:"), - ]), - report_text::to_suggestion_record( - alloc, - f.clone(), - fs, - ext, - ), - alloc.concat(vec![ - alloc.reflow("So maybe "), - f_doc, - alloc.reflow(" should be "), - alloc.record_field(f.0), - alloc.reflow("?"), - ]), - ]) - }, - ]); - - Report { + match diff.next().and_then(|k| Some((k, expected_fields.get(k)?))) { + None => report_mismatch( + alloc, + lines, filename, - title: "TYPE MISMATCH".to_string(), - doc, - severity: Severity::RuntimeError, + &category, + found, + expected_type, + region, + Some(expr_region), + alloc.reflow("Something is off with this record update:"), + alloc.concat(vec![ + alloc.reflow("The"), + alloc.symbol_unqualified(symbol), + alloc.reflow(" record is"), + ]), + alloc.reflow("But this update needs it to be compatible with:"), + None, + ), + Some((field, field_region)) => { + let r_doc = alloc.symbol_unqualified(symbol); + let f_doc = alloc.type_variable(field.clone()); + + let header = alloc.concat(vec![ + alloc.reflow("The "), + r_doc.clone(), + alloc.reflow(" record does not have a "), + f_doc.clone(), + alloc.reflow(" field:"), + ]); + + let mut suggestions = suggest::sort( + field.as_str(), + actual_fields.into_iter().collect::>(), + ); + + let doc = alloc.stack(vec![ + header, + alloc.region(lines.convert_region(*field_region)), + if suggestions.is_empty() { + alloc.concat(vec![ + alloc.reflow("In fact, "), + r_doc, + alloc.reflow(" is a record with NO fields!"), + ]) + } else { + let f = suggestions.remove(0); + let fs = suggestions; + + alloc.stack(vec![ + alloc.concat(vec![ + alloc.reflow("There may be a typo. Here are the "), + r_doc, + alloc.reflow(" fields that are most similar:"), + ]), + report_text::to_suggestion_record( + alloc, + f.clone(), + fs, + ext, + ), + alloc.concat(vec![ + alloc.reflow("So maybe "), + f_doc, + alloc.reflow(" should be "), + alloc.type_variable(f.0), + //alloc.record_field(f.0), + alloc.reflow("?"), + ]), + ]) + }, + ]); + + Report { + filename, + title: "TYPE MISMATCH".to_string(), + doc, + severity: Severity::RuntimeError, + } } } } + _ => report_bad_type( + alloc, + lines, + filename, + &category, + found, + expected_type, + region, + Some(expr_region), + alloc.reflow("This is not a record, so it has no fields to update!"), + alloc.reflow("It is"), + alloc.reflow("But I need a record!"), + ), } - _ => report_bad_type( - alloc, - lines, - filename, - &category, - found, - expected_type, - region, - Some(expr_region), - alloc.reflow("This is not a record, so it has no fields to update!"), - alloc.reflow("It is"), - alloc.reflow("But I need a record!"), - ), - }, + } Reason::FnCall { name, arity } => match count_arguments(&found) { 0 => { let this_value = match name { @@ -2956,23 +2956,18 @@ mod report_text { ) -> RocDocBuilder<'b> { let entry_to_doc = |(field_name, field_type): (RocDocBuilder<'b>, RocDocBuilder<'b>)| { field_name + .indent(4) .append(alloc.text(" : ")) - .hang(4) .append(field_type) + .append(alloc.text(",")) }; - let field = alloc.reflow("{ ").append(entry_to_doc(entry)); - let fields = std::iter::repeat(alloc.reflow(", ")) - .zip( - entries - .into_iter() - .map(entry_to_doc) - .chain(std::iter::once(alloc.text("..."))), - ) - .map(|(a, b)| a.append(b)); + let fields = std::iter::once(entry_to_doc(entry)) + .chain(entries.into_iter().map(entry_to_doc)) + .chain(std::iter::once(alloc.text("…").indent(4))); alloc.vcat( - std::iter::once(field) + std::iter::once(alloc.reflow("{")) .chain(fields) .chain(std::iter::once(alloc.text("}"))), ) From 681e73d393385151ba6ab7084aac740d06f8f038 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Tue, 19 Apr 2022 18:39:22 -0400 Subject: [PATCH 332/846] Combine record and record snippet reporting --- reporting/src/error/type.rs | 111 ++++++++++++++---------------------- 1 file changed, 43 insertions(+), 68 deletions(-) diff --git a/reporting/src/error/type.rs b/reporting/src/error/type.rs index 97814456e5..b5a4a6144d 100644 --- a/reporting/src/error/type.rs +++ b/reporting/src/error/type.rs @@ -886,9 +886,9 @@ fn to_expr_report<'b>( alloc.stack(vec![ alloc.concat(vec![ - alloc.reflow("There may be a typo. Here are the "), + alloc.reflow("There may be a typo. These "), r_doc, - alloc.reflow(" fields that are most similar:"), + alloc.reflow(" fields are the most similar:"), ]), report_text::to_suggestion_record( alloc, @@ -897,7 +897,7 @@ fn to_expr_report<'b>( ext, ), alloc.concat(vec![ - alloc.reflow("So maybe "), + alloc.reflow("Maybe "), f_doc, alloc.reflow(" should be "), alloc.type_variable(f.0), @@ -2893,22 +2893,14 @@ mod report_text { ) }; - if fs.len() <= 3 { - let mut selection = vec![f]; - selection.extend(fs); + let mut selection = vec![f]; + selection.extend(fs); - let fields = selection.into_iter().map(entry_to_doc).collect(); + let fields = selection.into_iter().map(entry_to_doc).collect(); - vertical_record(alloc, fields, ext_to_doc(alloc, ext)) - .annotate(Annotation::TypeBlock) - .indent(4) - } else { - let fields = fs.into_iter().take(3).map(entry_to_doc).collect(); - - vertical_record_snippet(alloc, entry_to_doc(f), fields) - .annotate(Annotation::TypeBlock) - .indent(4) - } + vertical_record(alloc, fields, ext_to_doc(alloc, ext)) + .annotate(Annotation::TypeBlock) + .indent(4) } fn vertical_record<'b>( @@ -2916,63 +2908,46 @@ mod report_text { entries: Vec<(RocDocBuilder<'b>, RocDocBuilder<'b>)>, opt_ext: Option>, ) -> RocDocBuilder<'b> { - let entry_to_doc = |(field_name, field_type): (RocDocBuilder<'b>, RocDocBuilder<'b>)| { - field_name - .append(alloc.text(" : ")) - .hang(4) - .append(field_type) + let fields = if entries.is_empty() { + alloc.text("{}") + } else { + const MAX_ENTRIES_TO_DISPLAY: usize = 4; + + let is_truncated = entries.len() > MAX_ENTRIES_TO_DISPLAY; + let entry_to_doc = + |(field_name, field_type): (RocDocBuilder<'b>, RocDocBuilder<'b>)| { + field_name + .indent(4) + .append(alloc.text(" : ")) + .append(field_type) + .append(alloc.text(",")) + }; + + let closing = std::iter::once(alloc.text("}")); + let fields = std::iter::once(alloc.reflow("{")).chain( + entries + .into_iter() + .map(entry_to_doc) + .take(MAX_ENTRIES_TO_DISPLAY), + ); + + if is_truncated { + alloc.vcat( + fields + .chain(std::iter::once(alloc.text("…").indent(4))) + .chain(closing), + ) + } else { + alloc.vcat(fields.chain(closing)) + } }; match opt_ext { - None => { - if entries.is_empty() { - alloc.text("{}") - } else { - let start = std::iter::once(alloc.reflow("{ ")) - .chain(std::iter::repeat(alloc.reflow(", "))); - let entry_docs = start - .zip(entries.into_iter().map(entry_to_doc)) - .map(|(a, b)| a.append(b)); - alloc.vcat(entry_docs.chain(std::iter::once(alloc.text("}")))) - } - } - Some(ext) => { - let start = std::iter::once(alloc.reflow("{ ")) - .chain(std::iter::repeat(alloc.reflow(", "))); - let entry_docs = start - .zip(entries.into_iter().map(entry_to_doc)) - .map(|(a, b)| a.append(b)); - alloc - .vcat(entry_docs.chain(std::iter::once(alloc.text("}")))) - .append(ext) - } + Some(ext) => fields.append(ext), + None => fields, } } - fn vertical_record_snippet<'b>( - alloc: &'b RocDocAllocator<'b>, - entry: (RocDocBuilder<'b>, RocDocBuilder<'b>), - entries: Vec<(RocDocBuilder<'b>, RocDocBuilder<'b>)>, - ) -> RocDocBuilder<'b> { - let entry_to_doc = |(field_name, field_type): (RocDocBuilder<'b>, RocDocBuilder<'b>)| { - field_name - .indent(4) - .append(alloc.text(" : ")) - .append(field_type) - .append(alloc.text(",")) - }; - - let fields = std::iter::once(entry_to_doc(entry)) - .chain(entries.into_iter().map(entry_to_doc)) - .chain(std::iter::once(alloc.text("…").indent(4))); - - alloc.vcat( - std::iter::once(alloc.reflow("{")) - .chain(fields) - .chain(std::iter::once(alloc.text("}"))), - ) - } - pub fn tag_union<'b>( alloc: &'b RocDocAllocator<'b>, entries: Vec<(RocDocBuilder<'b>, Vec>)>, From 3a736c6ecef032165862f47682f85aea416da23d Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Tue, 19 Apr 2022 18:51:03 -0400 Subject: [PATCH 333/846] Match typo suggestion color with typo color --- reporting/src/report.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reporting/src/report.rs b/reporting/src/report.rs index fb6de7f29b..29cfe43c09 100644 --- a/reporting/src/report.rs +++ b/reporting/src/report.rs @@ -194,7 +194,7 @@ const fn default_palette_from_style_codes(codes: StyleCodes) -> Palette { module_name: codes.green, binop: codes.green, typo: codes.yellow, - typo_suggestion: codes.green, + typo_suggestion: codes.yellow, parser_suggestion: codes.yellow, bold: codes.bold, underline: codes.underline, From 7fc01a0a9b8438d335465c3be3a128e98783d57f Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Tue, 19 Apr 2022 18:51:28 -0400 Subject: [PATCH 334/846] Annotate record typos and suggestions better --- reporting/src/error/type.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/reporting/src/error/type.rs b/reporting/src/error/type.rs index b5a4a6144d..807ad6064f 100644 --- a/reporting/src/error/type.rs +++ b/reporting/src/error/type.rs @@ -856,7 +856,9 @@ fn to_expr_report<'b>( ), Some((field, field_region)) => { let r_doc = alloc.symbol_unqualified(symbol); - let f_doc = alloc.type_variable(field.clone()); + let f_doc = alloc + .text(field.as_str().to_string()) + .annotate(Annotation::Typo); let header = alloc.concat(vec![ alloc.reflow("The "), @@ -900,8 +902,9 @@ fn to_expr_report<'b>( alloc.reflow("Maybe "), f_doc, alloc.reflow(" should be "), - alloc.type_variable(f.0), - //alloc.record_field(f.0), + alloc + .text(f.0.as_str().to_string()) + .annotate(Annotation::TypoSuggestion), alloc.reflow("?"), ]), ]) From 3f698c9878f3a4f3a9d8aaf0e37142dde19c892a Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Tue, 19 Apr 2022 20:22:17 -0400 Subject: [PATCH 335/846] Remove a gazillion allocations from reporting --- compiler/load_internal/src/file.rs | 15 +- reporting/src/error/canonicalize.rs | 187 ++++++++++---------- reporting/src/error/mono.rs | 10 +- reporting/src/error/parse.rs | 258 ++++++++++++++-------------- reporting/src/error/type.rs | 184 ++++++++++---------- 5 files changed, 316 insertions(+), 338 deletions(-) diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index 893369354d..c64b9c738e 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -4518,7 +4518,7 @@ fn to_file_problem_report(filename: &Path, error: io::ErrorKind) -> String { alloc .parser_suggestion(filename.to_str().unwrap()) .indent(4), - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"Is the file supposed to be there? "), alloc.reflow("Maybe there is a typo in the file name?"), ]), @@ -4537,9 +4537,8 @@ fn to_file_problem_report(filename: &Path, error: io::ErrorKind) -> String { alloc .parser_suggestion(filename.to_str().unwrap()) .indent(4), - alloc.concat(vec![ - alloc.reflow(r"Is it the right file? Maybe change its permissions?") - ]), + alloc + .concat([alloc.reflow(r"Is it the right file? Maybe change its permissions?")]), ]); Report { @@ -4552,7 +4551,7 @@ fn to_file_problem_report(filename: &Path, error: io::ErrorKind) -> String { _ => { let error = std::io::Error::from(error); let formatted = format!("{}", error); - let doc = alloc.concat(vec![ + let doc = alloc.concat([ alloc.reflow(r"I tried to read this file, but ran into a "), alloc.text(formatted), alloc.reflow(r" problem."), @@ -4650,7 +4649,7 @@ fn to_missing_platform_report(module_id: ModuleId, other: PlatformPath) -> Strin RootIsInterface => { let doc = alloc.stack(vec![ alloc.reflow(r"The input file is an interface module, but only app modules can be ran."), - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"I will still parse and typecheck the input file and its dependencies, "), alloc.reflow(r"but won't output any executable."), ]) @@ -4666,7 +4665,7 @@ fn to_missing_platform_report(module_id: ModuleId, other: PlatformPath) -> Strin RootIsHosted => { let doc = alloc.stack(vec![ alloc.reflow(r"The input file is a hosted module, but only app modules can be ran."), - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"I will still parse and typecheck the input file and its dependencies, "), alloc.reflow(r"but won't output any executable."), ]) @@ -4682,7 +4681,7 @@ fn to_missing_platform_report(module_id: ModuleId, other: PlatformPath) -> Strin RootIsPkgConfig => { let doc = alloc.stack(vec![ alloc.reflow(r"The input file is a package config file, but only app modules can be ran."), - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"I will still parse and typecheck the input file and its dependencies, "), alloc.reflow(r"but won't output any executable."), ]) diff --git a/reporting/src/error/canonicalize.rs b/reporting/src/error/canonicalize.rs index d366baf6f2..d22c091a4b 100644 --- a/reporting/src/error/canonicalize.rs +++ b/reporting/src/error/canonicalize.rs @@ -77,13 +77,13 @@ pub fn can_problem<'b>( } Problem::UnusedImport(module_id, region) => { doc = alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow("Nothing from "), alloc.module(module_id), alloc.reflow(" is used in this module."), ]), alloc.region(lines.convert_region(region)), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("Since "), alloc.module(module_id), alloc.reflow(" isn't used, you don't need to import it."), @@ -128,14 +128,14 @@ pub fn can_problem<'b>( let line = "\". Adding an underscore at the start of a variable name is a way of saying that the variable is not used."; doc = alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.symbol_unqualified(closure_symbol), alloc.reflow(" doesn't use "), alloc.symbol_unqualified(argument_symbol), alloc.text("."), ]), alloc.region(lines.convert_region(region)), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("If you don't need "), alloc.symbol_unqualified(argument_symbol), alloc.reflow(", then you can just remove it. However, if you really do need "), @@ -154,7 +154,7 @@ pub fn can_problem<'b>( Problem::PrecedenceProblem(BothNonAssociative(region, left_bin_op, right_bin_op)) => { doc = alloc.stack(vec![ if left_bin_op.value == right_bin_op.value { - alloc.concat(vec![ + alloc.concat([ alloc.reflow("Using more than one "), alloc.binop(left_bin_op.value), alloc.reflow(concat!( @@ -163,7 +163,7 @@ pub fn can_problem<'b>( )), ]) } else { - alloc.concat(vec![ + alloc.concat([ alloc.reflow("Using "), alloc.binop(left_bin_op.value), alloc.reflow(" and "), @@ -243,7 +243,7 @@ pub fn can_problem<'b>( variable_name, } => { doc = alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow("The "), alloc.type_variable(variable_name), alloc.reflow(" type parameter is not used in the "), @@ -270,13 +270,13 @@ pub fn can_problem<'b>( } => { let mut stack = Vec::with_capacity(4); if num_unbound == 1 { - stack.push(alloc.concat(vec![ + stack.push(alloc.concat([ alloc.reflow("The definition of "), alloc.symbol_unqualified(alias), alloc.reflow(" has an unbound type variable:"), ])); } else { - stack.push(alloc.concat(vec![ + stack.push(alloc.concat([ alloc.reflow("The definition of "), alloc.symbol_unqualified(alias), alloc.reflow(" has "), @@ -286,7 +286,7 @@ pub fn can_problem<'b>( stack.push(alloc.reflow("Here is one occurrence:")); } stack.push(alloc.region(lines.convert_region(one_occurrence))); - stack.push(alloc.tip().append(alloc.concat(vec![ + stack.push(alloc.tip().append(alloc.concat([ alloc.reflow("Type variables must be bound before the "), alloc.keyword(match kind { AliasKind::Structural => ":", @@ -311,7 +311,7 @@ pub fn can_problem<'b>( replaced_region, } => { doc = alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow("This record defines the "), alloc.record_field(field_name.clone()), alloc.reflow(" field twice!"), @@ -329,7 +329,7 @@ pub fn can_problem<'b>( lines.convert_region(field_region), Annotation::TypoSuggestion, ), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("For clarity, remove the previous "), alloc.record_field(field_name), alloc.reflow(" definitions from this record."), @@ -360,7 +360,7 @@ pub fn can_problem<'b>( replaced_region, } => { doc = alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow("This record type defines the "), alloc.record_field(field_name.clone()), alloc.reflow(" field twice!"), @@ -378,7 +378,7 @@ pub fn can_problem<'b>( lines.convert_region(field_region), Annotation::TypoSuggestion, ), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("For clarity, remove the previous "), alloc.record_field(field_name), alloc.reflow(" definitions from this record type."), @@ -395,7 +395,7 @@ pub fn can_problem<'b>( replaced_region, } => { doc = alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow("This tag union type defines the "), alloc.tag_name(tag_name.clone()), alloc.reflow(" tag twice!"), @@ -413,7 +413,7 @@ pub fn can_problem<'b>( lines.convert_region(tag_region), Annotation::TypoSuggestion, ), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("For clarity, remove the previous "), alloc.tag_name(tag_name), alloc.reflow(" definitions from this tag union type."), @@ -445,13 +445,13 @@ pub fn can_problem<'b>( region, } => { doc = alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow("This pattern in the definition of "), alloc.symbol_unqualified(type_name), alloc.reflow(" is not what I expect:"), ]), alloc.region(lines.convert_region(region)), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("Only type variables like "), alloc.type_variable("a".into()), alloc.reflow(" or "), @@ -467,7 +467,7 @@ pub fn can_problem<'b>( doc = alloc.stack(vec![ alloc.reflow("This unicode code point is invalid:"), alloc.region(lines.convert_region(region)), - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"I was expecting a hexadecimal number, like "), alloc.parser_suggestion("\\u(1100)"), alloc.reflow(" or "), @@ -494,7 +494,7 @@ pub fn can_problem<'b>( doc = alloc.stack(vec![ alloc.reflow("This string interpolation is invalid:"), alloc.region(lines.convert_region(region)), - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"I was expecting an identifier, like "), alloc.parser_suggestion("\\u(message)"), alloc.reflow(" or "), @@ -520,19 +520,19 @@ pub fn can_problem<'b>( differing_recursion_region, } => { doc = alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.symbol_unqualified(alias), alloc.reflow(" is a nested datatype. Here is one recursive usage of it:"), ]), alloc.region(lines.convert_region(differing_recursion_region)), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("But recursive usages of "), alloc.symbol_unqualified(alias), alloc.reflow(" must match its definition:"), ]), alloc.region(lines.convert_region(def_region)), alloc.reflow("Nested datatypes are not supported in Roc."), - alloc.concat(vec![ + alloc.concat([ alloc.hint("Consider rewriting the definition of "), alloc.symbol_unqualified(alias), alloc.text(" to use the recursive type with the same arguments."), @@ -552,13 +552,13 @@ pub fn can_problem<'b>( }; doc = alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow("This "), alloc.text(kind_str), alloc.reflow(" extension type is invalid:"), ]), alloc.region(lines.convert_region(region)), - alloc.concat(vec![ + alloc.concat([ alloc.note("A "), alloc.reflow(kind_str), alloc.reflow(" extension variable can only contain "), @@ -576,7 +576,7 @@ pub fn can_problem<'b>( variables_region, } => { doc = alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow("The definition of the "), alloc.symbol_unqualified(name), alloc.reflow(" ability includes type variables:"), @@ -609,7 +609,7 @@ pub fn can_problem<'b>( ability, } => { doc = alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow("The definition of the "), alloc.symbol_unqualified(name), alloc.reflow(" aliases references the ability "), @@ -617,12 +617,12 @@ pub fn can_problem<'b>( alloc.reflow(":"), ]), alloc.region(lines.convert_region(region)), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("Abilities are not types, but you can add an ability constraint to a type variable "), alloc.type_variable("a".into()), alloc.reflow(" by writing"), ]), - alloc.type_block(alloc.concat(vec![ + alloc.type_block(alloc.concat([ alloc.reflow("| a has "), alloc.symbol_unqualified(ability), ])), @@ -634,13 +634,13 @@ pub fn can_problem<'b>( Problem::IllegalHasClause { region } => { doc = alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow("A "), alloc.keyword("has"), alloc.reflow(" clause is not allowed here:"), ]), alloc.region(lines.convert_region(region)), - alloc.concat(vec![ + alloc.concat([ alloc.keyword("has"), alloc.reflow(" clauses can only be specified on the top-level type annotation of an ability member."), ]), @@ -655,7 +655,7 @@ pub fn can_problem<'b>( region, } => { doc = alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow("The definition of the ability member "), alloc.symbol_unqualified(member), alloc.reflow(" does not include a "), @@ -665,21 +665,20 @@ pub fn can_problem<'b>( alloc.reflow(":"), ]), alloc.region(lines.convert_region(region)), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("Ability members must include a "), alloc.keyword("has"), alloc.reflow(" clause binding a type variable to an ability, like"), ]), - alloc.type_block(alloc.concat(vec![ + alloc.type_block(alloc.concat([ alloc.type_variable("a".into()), alloc.space(), alloc.keyword("has"), alloc.space(), alloc.symbol_unqualified(ability), ])), - alloc.concat(vec![alloc.reflow( - "Otherwise, the function does not need to be part of the ability!", - )]), + alloc.concat([alloc + .reflow("Otherwise, the function does not need to be part of the ability!")]), ]); title = ABILITY_MEMBER_MISSING_HAS_CLAUSE.to_string(); severity = Severity::RuntimeError; @@ -692,7 +691,7 @@ pub fn can_problem<'b>( mut bound_var_names, } => { doc = alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow("The definition of the ability member "), alloc.symbol_unqualified(member), alloc.reflow(" includes multiple variables bound to the "), @@ -701,7 +700,7 @@ pub fn can_problem<'b>( ]), alloc.region(lines.convert_region(span_has_clauses)), alloc.reflow("Ability members can only bind one type variable to their parent ability. Otherwise, I wouldn't know what type implements an ability by looking at specializations!"), - alloc.concat(vec![ + alloc.concat([ alloc.hint("Did you mean to only bind "), alloc.type_variable(bound_var_names.swap_remove(0)), alloc.reflow(" to "), @@ -719,14 +718,14 @@ pub fn can_problem<'b>( region, } => { doc = alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow("The definition of the ability member "), alloc.symbol_unqualified(member), alloc.reflow(" includes a has clause binding an ability it is not a part of:"), ]), alloc.region(lines.convert_region(region)), alloc.reflow("Currently, ability members can only bind variables to the ability they are a part of."), - alloc.concat(vec![ + alloc.concat([ alloc.hint(""), alloc.reflow("Did you mean to bind the "), alloc.symbol_unqualified(ability), @@ -778,7 +777,7 @@ fn to_invalid_optional_value_report_help<'b>( record_region: Region, ) -> RocDocBuilder<'b> { alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow("This record uses an optional value for the "), alloc.record_field(field_name), alloc.reflow(" field in an incorrect context!"), @@ -812,7 +811,7 @@ fn to_bad_ident_expr_report<'b>( alloc.stack(vec![ alloc.reflow(r"I trying to parse a record field access here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("So I expect to see a lowercase letter next, like "), alloc.parser_suggestion(".name"), alloc.reflow(" or "), @@ -825,7 +824,7 @@ fn to_bad_ident_expr_report<'b>( WeirdAccessor(_pos) => alloc.stack(vec![ alloc.reflow("I am very confused by this field access"), alloc.region(lines.convert_region(surroundings)), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("It looks like a field access on an accessor. I parse"), alloc.parser_suggestion(".client.name"), alloc.reflow(" as "), @@ -843,7 +842,7 @@ fn to_bad_ident_expr_report<'b>( alloc.stack(vec![ alloc.reflow("I am trying to parse a qualified name here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("I was expecting to see an identifier next, like "), alloc.parser_suggestion("height"), alloc.reflow(". A complete qualified name looks something like "), @@ -858,7 +857,7 @@ fn to_bad_ident_expr_report<'b>( alloc.stack(vec![ alloc.reflow("I am trying to parse a qualified name here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"This looks like a qualified tag name to me, "), alloc.reflow(r"but tags cannot be qualified! "), alloc.reflow(r"Maybe you wanted a qualified name, something like "), @@ -876,7 +875,7 @@ fn to_bad_ident_expr_report<'b>( lines.convert_region(surroundings), lines.convert_region(region), ), - alloc.concat(vec![alloc.reflow( + alloc.concat([alloc.reflow( r"I recommend using camelCase, it is the standard in the Roc ecosystem.", )]), ]) @@ -898,7 +897,7 @@ fn to_bad_ident_expr_report<'b>( lines.convert_region(surroundings), lines.convert_region(region), ), - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"It looks like a record field access on "), alloc.reflow(kind), alloc.text("."), @@ -913,7 +912,7 @@ fn to_bad_ident_expr_report<'b>( lines.convert_region(surroundings), lines.convert_region(region), ), - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"Looks like "), alloc.reflow(kind), alloc.reflow(" is treated like a module name. "), @@ -927,7 +926,7 @@ fn to_bad_ident_expr_report<'b>( let region = Region::new(surroundings.start().bump_column(1), pos.bump_column(1)); alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow("I am trying to parse "), alloc.reflow(kind), alloc.reflow(" here:"), @@ -936,7 +935,7 @@ fn to_bad_ident_expr_report<'b>( lines.convert_region(surroundings), lines.convert_region(region), ), - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"But after the "), alloc.keyword("@"), alloc.reflow(r" symbol I found a lowercase letter. "), @@ -971,7 +970,7 @@ fn to_bad_ident_pattern_report<'b>( alloc.stack(vec![ alloc.reflow(r"I trying to parse a record field accessor here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("Something like "), alloc.parser_suggestion(".name"), alloc.reflow(" or "), @@ -984,7 +983,7 @@ fn to_bad_ident_pattern_report<'b>( WeirdAccessor(_pos) => alloc.stack(vec![ alloc.reflow("I am very confused by this field access"), alloc.region(lines.convert_region(surroundings)), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("It looks like a field access on an accessor. I parse"), alloc.parser_suggestion(".client.name"), alloc.reflow(" as "), @@ -1002,7 +1001,7 @@ fn to_bad_ident_pattern_report<'b>( alloc.stack(vec![ alloc.reflow("I am trying to parse a qualified name here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("I was expecting to see an identifier next, like "), alloc.parser_suggestion("height"), alloc.reflow(". A complete qualified name looks something like "), @@ -1017,7 +1016,7 @@ fn to_bad_ident_pattern_report<'b>( alloc.stack(vec![ alloc.reflow("I am trying to parse a qualified name here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"This looks like a qualified tag name to me, "), alloc.reflow(r"but tags cannot be qualified! "), alloc.reflow(r"Maybe you wanted a qualified name, something like "), @@ -1036,7 +1035,7 @@ fn to_bad_ident_pattern_report<'b>( lines.convert_region(surroundings), lines.convert_region(region), ), - alloc.concat(vec![alloc.reflow( + alloc.concat([alloc.reflow( r"Underscores are not allowed in identifiers. Use camelCase instead!", )]), ]) @@ -1131,7 +1130,7 @@ fn report_shadowing<'b>( alloc.region(lines.convert_region(original_region)), alloc.reflow("But then it's defined a second time here:"), alloc.region(lines.convert_region(shadow.region)), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("Since these "), alloc.reflow(what), alloc.reflow(" have the same name, it's easy to use the wrong one on accident. Give one of them a new name."), @@ -1219,7 +1218,7 @@ fn pretty_runtime_error<'b>( }; doc = alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow("This"), alloc.text(name), alloc.reflow("pattern is malformed:"), @@ -1243,7 +1242,7 @@ fn pretty_runtime_error<'b>( suggestions.truncate(4); let did_you_mean = if suggestions.is_empty() { - alloc.concat(vec![ + alloc.concat([ alloc.reflow("In fact, it looks like "), alloc.module_name(module_name.clone()), alloc.reflow(" doesn't expose any values!"), @@ -1258,7 +1257,7 @@ fn pretty_runtime_error<'b>( ]) }; doc = alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow("The "), alloc.module_name(module_name), alloc.reflow(" module does not expose `"), @@ -1302,7 +1301,7 @@ fn pretty_runtime_error<'b>( doc = alloc.stack(vec![ alloc.reflow(r"I am confused by this type name:"), alloc.region(lines.convert_region(surroundings)), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("Type names start with an uppercase letter, "), alloc.reflow("and can optionally be qualified by a module name, like "), alloc.parser_suggestion("Bool"), @@ -1330,13 +1329,13 @@ fn pretty_runtime_error<'b>( }; doc = alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow("This float literal is too "), alloc.text(big_or_small), alloc.reflow(":"), ]), alloc.region(lines.convert_region(region)), - alloc.concat(vec![ + alloc.concat([ alloc .reflow("Roc uses signed 64-bit floating points, allowing values between "), alloc.text(format!("{:e}", f64::MIN)), @@ -1354,11 +1353,11 @@ fn pretty_runtime_error<'b>( .append(alloc.reflow("Learn more about number literals at TODO")); doc = alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow("This float literal contains an invalid digit:"), ]), alloc.region(lines.convert_region(region)), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("Floating point literals can only contain the digits 0-9, or use scientific notation 10e4, or have a float suffix."), ]), tip, @@ -1368,9 +1367,9 @@ fn pretty_runtime_error<'b>( } RuntimeError::InvalidFloat(FloatErrorKind::IntSuffix, region, _raw_str) => { doc = alloc.stack(vec![ - alloc.concat(vec![alloc.reflow( - "This number literal is a float, but it has an integer suffix:", - )]), + alloc + .concat([alloc + .reflow("This number literal is a float, but it has an integer suffix:")]), alloc.region(lines.convert_region(region)), ]); @@ -1418,7 +1417,7 @@ fn pretty_runtime_error<'b>( .append(alloc.reflow("Learn more about number literals at TODO")); doc = alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow("This "), alloc.text(name), alloc.reflow(" literal contains "), @@ -1426,7 +1425,7 @@ fn pretty_runtime_error<'b>( alloc.text(":"), ]), alloc.region(lines.convert_region(region)), - alloc.concat(vec![ + alloc.concat([ alloc.text(plurals), contains, alloc.text(charset), @@ -1442,7 +1441,7 @@ fn pretty_runtime_error<'b>( let (big_or_small, info) = if let IntErrorKind::Underflow = error_kind { ( "small", - alloc.concat(vec![ + alloc.concat([ alloc.reflow( "The smallest number representable in Roc is the minimum I128 value, ", ), @@ -1453,7 +1452,7 @@ fn pretty_runtime_error<'b>( } else { ( "big", - alloc.concat(vec![ + alloc.concat([ alloc.reflow( "The largest number representable in Roc is the maximum U128 value, ", ), @@ -1468,7 +1467,7 @@ fn pretty_runtime_error<'b>( .append(alloc.reflow("Learn more about number literals at TODO")); doc = alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow("This integer literal is too "), alloc.text(big_or_small), alloc.reflow(":"), @@ -1482,9 +1481,9 @@ fn pretty_runtime_error<'b>( } RuntimeError::InvalidInt(IntErrorKind::FloatSuffix, _base, region, _raw_str) => { doc = alloc.stack(vec![ - alloc.concat(vec![alloc.reflow( - "This number literal is an integer, but it has a float suffix:", - )]), + alloc + .concat([alloc + .reflow("This number literal is an integer, but it has a float suffix:")]), alloc.region(lines.convert_region(region)), ]); @@ -1500,11 +1499,10 @@ fn pretty_runtime_error<'b>( _raw_str, ) => { doc = alloc.stack(vec![ - alloc.concat(vec![alloc.reflow( - "This integer literal overflows the type indicated by its suffix:", - )]), + alloc.concat([alloc + .reflow("This integer literal overflows the type indicated by its suffix:")]), alloc.region(lines.convert_region(region)), - alloc.tip().append(alloc.concat(vec![ + alloc.tip().append(alloc.concat([ alloc.reflow("The suffix indicates this integer is a "), alloc.type_str(suffix_type), alloc.reflow(", whose maximum value is "), @@ -1525,11 +1523,10 @@ fn pretty_runtime_error<'b>( _raw_str, ) => { doc = alloc.stack(vec![ - alloc.concat(vec![alloc.reflow( - "This integer literal underflows the type indicated by its suffix:", - )]), + alloc.concat([alloc + .reflow("This integer literal underflows the type indicated by its suffix:")]), alloc.region(lines.convert_region(region)), - alloc.tip().append(alloc.concat(vec![ + alloc.tip().append(alloc.concat([ alloc.reflow("The suffix indicates this integer is a "), alloc.type_str(suffix_type), alloc.reflow(", whose minimum value is "), @@ -1557,7 +1554,7 @@ fn pretty_runtime_error<'b>( } RuntimeError::InvalidRecordUpdate { region } => { doc = alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow("This expression cannot be updated"), alloc.reflow(":"), ]), @@ -1608,7 +1605,7 @@ fn pretty_runtime_error<'b>( .append(alloc.reflow("Learn more about character literals at TODO")); doc = alloc.stack(vec![ - alloc.concat(vec![alloc.reflow("This character literal is empty.")]), + alloc.concat([alloc.reflow("This character literal is empty.")]), alloc.region(lines.convert_region(region)), tip, ]); @@ -1621,13 +1618,11 @@ fn pretty_runtime_error<'b>( .append(alloc.reflow("Learn more about character literals at TODO")); doc = alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow("This character literal contains more than one code point.") ]), alloc.region(lines.convert_region(region)), - alloc.concat(vec![ - alloc.reflow("Character literals can only contain one code point.") - ]), + alloc.concat([alloc.reflow("Character literals can only contain one code point.")]), tip, ]); @@ -1662,7 +1657,7 @@ fn pretty_runtime_error<'b>( }; let mut stack = vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow("The opaque type "), alloc.type_str(opaque.as_inline_str().as_str()), alloc.reflow(" referenced here is not defined:"), @@ -1689,7 +1684,7 @@ fn pretty_runtime_error<'b>( imported_region, } => { doc = alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow("The unwrapped opaque type "), alloc.type_str(opaque.as_inline_str().as_str()), alloc.reflow(" referenced here:"), @@ -1784,7 +1779,7 @@ fn not_found<'b>( ); suggestions.truncate(4); - let default_no = alloc.concat(vec![ + let default_no = alloc.concat([ alloc.reflow("Is there an "), alloc.keyword("import"), alloc.reflow(" or "), @@ -1808,7 +1803,7 @@ fn not_found<'b>( }; alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow("I cannot find a `"), alloc.string(name.to_string()), alloc.reflow("` "), @@ -1842,7 +1837,7 @@ fn module_not_found<'b>( if suggestions.is_empty() { // We don't have any recommended spelling corrections - alloc.concat(vec![ + alloc.concat([ alloc.reflow("Is there an "), alloc.keyword("import"), alloc.reflow(" or "), @@ -1860,7 +1855,7 @@ fn module_not_found<'b>( }; alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow("The `"), alloc.string(name.to_string()), alloc.reflow("` module is not imported:"), diff --git a/reporting/src/error/mono.rs b/reporting/src/error/mono.rs index 270f037a7d..691e9b31cc 100644 --- a/reporting/src/error/mono.rs +++ b/reporting/src/error/mono.rs @@ -22,7 +22,7 @@ pub fn mono_problem<'b>( alloc.region(lines.convert_region(region)), alloc.reflow("Other possibilities include:"), unhandled_patterns_to_doc_block(alloc, missing), - alloc.concat(vec![ + alloc.concat([ alloc.reflow( "I would have to crash if I saw one of those! \ So rather than pattern matching in function arguments, put a ", @@ -45,7 +45,7 @@ pub fn mono_problem<'b>( alloc.region(lines.convert_region(region)), alloc.reflow("Other possibilities include:"), unhandled_patterns_to_doc_block(alloc, missing), - alloc.concat(vec![ + alloc.concat([ alloc.reflow( "I would have to crash if I saw one of those! \ You can use a binding to deconstruct a value if there is only ONE possibility. \ @@ -65,7 +65,7 @@ pub fn mono_problem<'b>( } BadCase => { let doc = alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow("This "), alloc.keyword("when"), alloc.reflow(" does not cover all the possibilities:"), @@ -94,7 +94,7 @@ pub fn mono_problem<'b>( index, }) => { let doc = alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow("The "), alloc.string(index.ordinal()), alloc.reflow(" pattern is redundant:"), @@ -169,7 +169,7 @@ fn pattern_to_doc_help<'b>( ); debug_assert!(args.len() == 2); let tag = pattern_to_doc_help(alloc, args[1].clone(), in_type_param); - alloc.concat(vec![ + alloc.concat([ tag, alloc.text(AFTER_TAG_INDENT), alloc.text("(note the lack of an "), diff --git a/reporting/src/error/parse.rs b/reporting/src/error/parse.rs index 83b878a6c0..63581bff7a 100644 --- a/reporting/src/error/parse.rs +++ b/reporting/src/error/parse.rs @@ -28,7 +28,7 @@ fn note_for_tag_union_type_indent<'a>(alloc: &'a RocDocAllocator<'a>) -> RocDocB } fn hint_for_tag_name<'a>(alloc: &'a RocDocAllocator<'a>) -> RocDocBuilder<'a> { - alloc.concat(vec![ + alloc.concat([ alloc.hint("Tag names "), alloc.reflow("start with an uppercase letter, like "), alloc.parser_suggestion("Err"), @@ -39,7 +39,7 @@ fn hint_for_tag_name<'a>(alloc: &'a RocDocAllocator<'a>) -> RocDocBuilder<'a> { } fn hint_for_private_tag_name<'a>(alloc: &'a RocDocAllocator<'a>) -> RocDocBuilder<'a> { - alloc.concat(vec![ + alloc.concat([ alloc.hint("Private tag names "), alloc.reflow("start with an `@` symbol followed by an uppercase letter, like "), alloc.parser_suggestion("@UID"), @@ -50,7 +50,7 @@ fn hint_for_private_tag_name<'a>(alloc: &'a RocDocAllocator<'a>) -> RocDocBuilde } fn record_patterns_look_like<'a>(alloc: &'a RocDocAllocator<'a>) -> RocDocBuilder<'a> { - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"Record pattern look like "), alloc.parser_suggestion("{ name, age: currentAge },"), alloc.reflow(" so I was expecting to see a field name next."), @@ -93,7 +93,7 @@ fn to_syntax_report<'a>( } let doc = alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow("Unexpected token "), // context(alloc, &parse_problem.context_stack, "here"), alloc.text(":"), @@ -205,7 +205,7 @@ fn to_expr_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I am partway through parsing a definition, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("Looks like you are trying to define a function. "), alloc.reflow("In roc, functions are always written as a lambda, like "), alloc.parser_suggestion("increment = \\n -> n + 1"), @@ -241,7 +241,7 @@ fn to_expr_report<'a>( alloc.reflow(" instead."), ], ":" => vec![alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow("The has-type operator "), alloc.parser_suggestion(":"), alloc.reflow(" can only occur in a definition's type signature, like"), @@ -259,7 +259,7 @@ fn to_expr_report<'a>( } _ => { vec![alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow("The arrow "), alloc.parser_suggestion("->"), alloc.reflow(" is only used to define cases in a "), @@ -317,7 +317,7 @@ fn to_expr_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I am very confused by this identifier:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("Are you trying to qualify a name? I am execting something like "), alloc.parser_suggestion("Json.Decode.string"), alloc.reflow(". Maybe you are trying to qualify a tag? Tags like "), @@ -338,7 +338,7 @@ fn to_expr_report<'a>( let (title, expecting) = match &context { Context::InNode { .. } | Context::InDef { .. } => ( "MISSING EXPRESSION", - alloc.concat(vec![ + alloc.concat([ alloc.reflow("I was expecting to see an expression like "), alloc.parser_suggestion("42"), alloc.reflow(" or "), @@ -349,7 +349,7 @@ fn to_expr_report<'a>( Context::InDefFinalExpr { .. } => ( "MISSING FINAL EXPRESSION", alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow("This definition is missing a final expression."), alloc.reflow(" A nested definition must be followed by"), alloc.reflow(" either another definition, or an expression"), @@ -368,7 +368,7 @@ fn to_expr_report<'a>( Context::InNode(node, pos, _) => match node { Node::WhenCondition | Node::WhenBranch | Node::WhenIfGuard => ( pos, - alloc.concat(vec![ + alloc.concat([ alloc.text("an "), alloc.keyword("when"), alloc.text(" expression"), @@ -376,7 +376,7 @@ fn to_expr_report<'a>( ), Node::IfCondition | Node::IfThenBranch | Node::IfElseBranch => ( pos, - alloc.concat(vec![ + alloc.concat([ alloc.text("an "), alloc.keyword("if"), alloc.text(" expression"), @@ -397,7 +397,7 @@ fn to_expr_report<'a>( let region = LineColumnRegion::from_pos(lines.convert_pos(*pos)); let doc = alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"I am partway through parsing "), a_thing, alloc.reflow(", but I got stuck here:"), @@ -421,7 +421,7 @@ fn to_expr_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I am partway through parsing a definition, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("This definition is missing a final expression."), alloc.reflow(" A nested definition must be followed by"), alloc.reflow(" either another definition, or an expression"), @@ -458,7 +458,7 @@ fn to_expr_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("Whatever I am running into is confusing me a lot! "), alloc.reflow("Normally I can give fairly specific hints, "), alloc.reflow("but something is really tripping me up this time."), @@ -480,7 +480,7 @@ fn to_expr_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I am partway through parsing a definition, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("Looks like you are trying to define a function. "), alloc.reflow("In roc, functions are always written as a lambda, like "), alloc.parser_suggestion("increment = \\n -> n + 1"), @@ -503,9 +503,7 @@ fn to_expr_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I am partway through parsing an expression, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ - alloc.reflow("Looks like you are trying to define a function. ") - ]), + alloc.concat([alloc.reflow("Looks like you are trying to define a function. ")]), ]); Report { @@ -523,7 +521,7 @@ fn to_expr_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I am partway through parsing an record, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![alloc.reflow("TODO provide more context.")]), + alloc.concat([alloc.reflow("TODO provide more context.")]), ]); Report { @@ -566,7 +564,7 @@ fn to_lambda_report<'a>( alloc .reflow(r"I am partway through parsing a function argument list, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("I was expecting a "), alloc.parser_suggestion("->"), alloc.reflow(" next."), @@ -588,7 +586,7 @@ fn to_lambda_report<'a>( alloc .reflow(r"I am partway through parsing a function argument list, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("I was expecting a "), alloc.parser_suggestion("->"), alloc.reflow(" next."), @@ -613,7 +611,7 @@ fn to_lambda_report<'a>( alloc .reflow(r"I am partway through parsing a function argument list, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("I was expecting a "), alloc.parser_suggestion("->"), alloc.reflow(" next."), @@ -635,7 +633,7 @@ fn to_lambda_report<'a>( alloc .reflow(r"I am partway through parsing a function argument list, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("I was expecting a "), alloc.parser_suggestion("->"), alloc.reflow(" next."), @@ -660,7 +658,7 @@ fn to_lambda_report<'a>( alloc .reflow(r"I am partway through parsing a function argument list, but I got stuck at this comma:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("I was expecting an argument pattern before this, "), alloc.reflow("so try adding an argument before the comma and see if that helps?"), ]), @@ -681,7 +679,7 @@ fn to_lambda_report<'a>( alloc .reflow(r"I am partway through parsing a function argument list, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("I was expecting an argument pattern before this, "), alloc.reflow("so try adding an argument and see if that helps?"), ]), @@ -712,7 +710,7 @@ fn to_lambda_report<'a>( filename, pos, start, - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"I just saw a pattern, so I was expecting to see a "), alloc.parser_suggestion("->"), alloc.reflow(" next."), @@ -725,7 +723,7 @@ fn to_lambda_report<'a>( filename, pos, start, - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"I just saw a pattern, so I was expecting to see a "), alloc.parser_suggestion("->"), alloc.reflow(" next."), @@ -738,7 +736,7 @@ fn to_lambda_report<'a>( filename, pos, start, - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"I just saw a pattern, so I was expecting to see a "), alloc.parser_suggestion("->"), alloc.reflow(" next."), @@ -760,7 +758,7 @@ fn to_unfinished_lambda_report<'a>( let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); let doc = alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"I was partway through parsing a "), alloc.reflow(r" function, but I got stuck here:"), ]), @@ -809,7 +807,7 @@ fn to_str_report<'a>( }; let doc = alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"I was partway through parsing a "), alloc.reflow(r" string literal, but I got stuck here:"), ]), @@ -817,7 +815,7 @@ fn to_str_report<'a>( lines.convert_region(surroundings), lines.convert_region(region), ), - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"This is not an escape sequence I recognize."), alloc.reflow(r" After a backslash, I am looking for one of these:"), ]), @@ -850,7 +848,7 @@ fn to_str_report<'a>( r"I am partway through parsing a unicode code point, but I got stuck here:", ), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"I was expecting a hexadecimal number, like "), alloc.parser_suggestion("\\u(1100)"), alloc.reflow(" or "), @@ -874,7 +872,7 @@ fn to_str_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I cannot find the end of this format expression:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"You could change it to something like "), alloc.parser_suggestion("\"The count is \\(count\\)\""), alloc.reflow("."), @@ -895,7 +893,7 @@ fn to_str_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I cannot find the end of this string:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"You could change it to something like "), alloc.parser_suggestion("\"to be or not to be\""), alloc.reflow(" or even just "), @@ -918,7 +916,7 @@ fn to_str_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I cannot find the end of this block string:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"You could change it to something like "), alloc.parser_suggestion("\"\"\"to be or not to be\"\"\""), alloc.reflow(" or even just "), @@ -964,7 +962,7 @@ fn to_expr_in_parens_report<'a>( alloc .reflow("I am partway through parsing a record pattern, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow( r"I was expecting to see a closing parenthesis next, so try adding a ", ), @@ -989,7 +987,7 @@ fn to_expr_in_parens_report<'a>( r"I just started parsing an expression in parentheses, but I got stuck here:", ), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"An expression in parentheses looks like "), alloc.parser_suggestion("(32)"), alloc.reflow(r" or "), @@ -1041,7 +1039,7 @@ fn to_list_report<'a>( r"I am partway through started parsing a list, but I got stuck here:", ), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc .reflow(r"I was expecting to see a list entry before this comma, "), alloc.reflow(r"so try adding a list entry"), @@ -1064,7 +1062,7 @@ fn to_list_report<'a>( r"I am partway through started parsing a list, but I got stuck here:", ), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow( r"I was expecting to see a closing square bracket before this, ", ), @@ -1072,7 +1070,7 @@ fn to_list_report<'a>( alloc.parser_suggestion("]"), alloc.reflow(r" and see if that helps?"), ]), - alloc.concat(vec![ + alloc.concat([ alloc.note("When "), alloc.reflow(r"I get stuck like this, "), alloc.reflow(r"it usually means that there is a missing parenthesis "), @@ -1098,7 +1096,7 @@ fn to_list_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I cannot find the end of this list:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"You could change it to something like "), alloc.parser_suggestion("[ 1, 2, 3 ]"), alloc.reflow(" or even just "), @@ -1169,7 +1167,7 @@ fn to_if_report<'a>( filename, pos, start, - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"I was expecting to see the "), alloc.keyword("then"), alloc.reflow(r" keyword next."), @@ -1184,7 +1182,7 @@ fn to_if_report<'a>( filename, pos, start, - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"I was expecting to see the "), alloc.keyword("else"), alloc.reflow(r" keyword next."), @@ -1198,9 +1196,7 @@ fn to_if_report<'a>( filename, pos, start, - alloc.concat(vec![ - alloc.reflow(r"I was expecting to see a expression next") - ]), + alloc.concat([alloc.reflow(r"I was expecting to see a expression next")]), ), } } @@ -1217,7 +1213,7 @@ fn to_unfinished_if_report<'a>( let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); let doc = alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"I was partway through parsing an "), alloc.keyword("if"), alloc.reflow(r" expression, but I got stuck here:"), @@ -1256,9 +1252,7 @@ fn to_when_report<'a>( r"I just started parsing an if guard, but there is no guard condition:", ), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ - alloc.reflow("Try adding an expression before the arrow!") - ]), + alloc.concat([alloc.reflow("Try adding an expression before the arrow!")]), ]); Report { @@ -1283,13 +1277,13 @@ fn to_when_report<'a>( let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); let doc = alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"I am partway through parsing a "), alloc.keyword("when"), alloc.reflow(r" expression, but got stuck here:"), ]), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![alloc.reflow("I was expecting to see an arrow next.")]), + alloc.concat([alloc.reflow("I was expecting to see an arrow next.")]), note_for_when_indent_error(alloc), ]); @@ -1327,7 +1321,7 @@ fn to_when_report<'a>( filename, pos, start, - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"I just saw a "), alloc.parser_suggestion(r"|"), alloc.reflow(r" so I was expecting to see a pattern next."), @@ -1343,7 +1337,7 @@ fn to_when_report<'a>( filename, pos, start, - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"I was expecting to see the "), alloc.keyword("is"), alloc.reflow(r" keyword next."), @@ -1356,9 +1350,7 @@ fn to_when_report<'a>( filename, pos, start, - alloc.concat(vec![ - alloc.reflow(r"I was expecting to see a expression next") - ]), + alloc.concat([alloc.reflow(r"I was expecting to see a expression next")]), ), EWhen::IndentPattern(pos) => to_unfinished_when_report( @@ -1367,7 +1359,7 @@ fn to_when_report<'a>( filename, pos, start, - alloc.concat(vec![alloc.reflow(r"I was expecting to see a pattern next")]), + alloc.concat([alloc.reflow(r"I was expecting to see a pattern next")]), ), EWhen::IndentArrow(pos) => to_unfinished_when_report( @@ -1376,7 +1368,7 @@ fn to_when_report<'a>( filename, pos, start, - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"I just saw a pattern, so I was expecting to see a "), alloc.parser_suggestion("->"), alloc.reflow(" next."), @@ -1389,7 +1381,7 @@ fn to_when_report<'a>( filename, pos, start, - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"I just saw the "), alloc.keyword("if"), alloc.reflow(" keyword, so I was expecting to see an expression next."), @@ -1402,7 +1394,7 @@ fn to_when_report<'a>( filename, pos, start, - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"I was expecting to see an expression next. "), alloc.reflow("What should I do when I run into this particular pattern?"), ]), @@ -1414,7 +1406,7 @@ fn to_when_report<'a>( filename, pos, start, - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"I suspect this is a pattern that is not indented enough? (by "), alloc.text(indent.to_string()), alloc.reflow(" spaces)"), @@ -1440,7 +1432,7 @@ fn to_unfinished_when_report<'a>( let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); let doc = alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"I was partway through parsing a "), alloc.keyword("when"), alloc.reflow(r" expression, but I got stuck here:"), @@ -1471,7 +1463,7 @@ fn to_unexpected_arrow_report<'a>( let region = Region::new(pos, pos.bump_column(2)); let doc = alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"I am parsing a "), alloc.keyword("when"), alloc.reflow(r" expression right now, but this arrow is confusing me:"), @@ -1480,7 +1472,7 @@ fn to_unexpected_arrow_report<'a>( lines.convert_region(surroundings), lines.convert_region(region), ), - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"It makes sense to see arrows around here, "), alloc.reflow(r"so I suspect it is something earlier."), alloc.reflow( @@ -1500,7 +1492,7 @@ fn to_unexpected_arrow_report<'a>( fn note_for_when_error<'a>(alloc: &'a RocDocAllocator<'a>) -> RocDocBuilder<'a> { alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.note("Here is an example of a valid "), alloc.keyword("when"), alloc.reflow(r" expression for reference."), @@ -1513,7 +1505,7 @@ fn note_for_when_error<'a>(alloc: &'a RocDocAllocator<'a>) -> RocDocBuilder<'a> alloc.text("Err _ ->").indent(6), alloc.text("200").indent(8), ]), - alloc.concat(vec![ + alloc.concat([ alloc.reflow( "Notice the indentation. All patterns are aligned, and each branch is indented", ), @@ -1524,7 +1516,7 @@ fn note_for_when_error<'a>(alloc: &'a RocDocAllocator<'a>) -> RocDocBuilder<'a> fn note_for_when_indent_error<'a>(alloc: &'a RocDocAllocator<'a>) -> RocDocBuilder<'a> { alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.note("Sometimes I get confused by indentation, so try to make your "), alloc.keyword("when"), alloc.reflow(r" look something like this:"), @@ -1537,7 +1529,7 @@ fn note_for_when_indent_error<'a>(alloc: &'a RocDocAllocator<'a>) -> RocDocBuild alloc.text("Err _ ->").indent(6), alloc.text("200").indent(8), ]), - alloc.concat(vec![ + alloc.concat([ alloc.reflow( "Notice the indentation. All patterns are aligned, and each branch is indented", ), @@ -1602,7 +1594,7 @@ fn to_precord_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I just started parsing a record pattern, but I got stuck on this field name:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"Looks like you are trying to use "), alloc.keyword(keyword), alloc.reflow(" as a field name, but that is a reserved word. Try using a different name!"), @@ -1644,7 +1636,7 @@ fn to_precord_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I am partway through parsing a record pattern, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow( r"I was expecting to see a colon, question mark, comma or closing curly brace.", ), @@ -1662,7 +1654,7 @@ fn to_precord_report<'a>( let doc = alloc.stack(vec![ alloc.reflow("I am partway through parsing a record pattern, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow( r"I was expecting to see a closing curly brace before this, so try adding a ", ), @@ -1689,7 +1681,7 @@ fn to_precord_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I just started parsing a record pattern, but I got stuck on this field name:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"Looks like you are trying to use "), alloc.keyword(keyword), alloc.reflow(" as a field name, but that is a reserved word. Try using a different name!"), @@ -1712,7 +1704,7 @@ fn to_precord_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I am partway through parsing a record pattern, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"I was expecting to see another record field defined next, so I am looking for a name like "), alloc.parser_suggestion("userName"), alloc.reflow(" or "), @@ -1782,7 +1774,7 @@ fn to_precord_report<'a>( "I am partway through parsing a record pattern, but I got stuck here:", ), alloc.region_with_subregion(surroundings, region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("I need this curly brace to be indented more. Try adding more spaces before it!"), ]), ]); @@ -1803,7 +1795,7 @@ fn to_precord_report<'a>( r"I am partway through parsing a record pattern, but I got stuck here:", ), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("I was expecting to see a closing curly "), alloc.reflow("brace before this, so try adding a "), alloc.parser_suggestion("}"), @@ -1854,7 +1846,7 @@ fn to_pattern_in_parens_report<'a>( r"I just started parsing a pattern in parentheses, but I got stuck here:", ), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"A pattern in parentheses looks like "), alloc.parser_suggestion("(Ok 32)"), alloc.reflow(r" or "), @@ -1878,7 +1870,7 @@ fn to_pattern_in_parens_report<'a>( let doc = alloc.stack(vec![ alloc.reflow("I am partway through parsing a pattern in parentheses, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow( r"I was expecting to see a closing parenthesis before this, so try adding a ", ), @@ -1929,7 +1921,7 @@ fn to_pattern_in_parens_report<'a>( "I am partway through parsing a pattern in parentheses, but I got stuck here:", ), alloc.region_with_subregion(surroundings, region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("I need this parenthesis to be indented more. Try adding more spaces before it!"), ]), ]); @@ -1950,7 +1942,7 @@ fn to_pattern_in_parens_report<'a>( r"I am partway through parsing a pattern in parentheses, but I got stuck here:", ), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("I was expecting to see a closing parenthesis "), alloc.reflow("before this, so try adding a "), alloc.parser_suggestion(")"), @@ -2024,7 +2016,7 @@ fn to_type_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I just started parsing a function argument type, but I encountered two commas in a row:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![alloc.reflow("Try removing one of them.")]), + alloc.concat([alloc.reflow("Try removing one of them.")]), ]); Report { @@ -2045,7 +2037,7 @@ fn to_type_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I just started parsing a type, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"I am expecting a type next, like "), alloc.parser_suggestion("Bool"), alloc.reflow(r" or "), @@ -2155,7 +2147,7 @@ fn to_trecord_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I just started parsing a record type, but I got stuck on this field name:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"Looks like you are trying to use "), alloc.keyword(keyword), alloc.reflow(" as a field name, but that is a reserved word. Try using a different name!"), @@ -2176,7 +2168,7 @@ fn to_trecord_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I just started parsing a record type, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"Record types look like "), alloc.parser_suggestion("{ name : String, age : Int },"), alloc.reflow(" so I was expecting to see a field name next."), @@ -2201,7 +2193,7 @@ fn to_trecord_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I am partway through parsing a record type, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow( r"I was expecting to see a colon, question mark, comma or closing curly brace.", ), @@ -2219,7 +2211,7 @@ fn to_trecord_report<'a>( let doc = alloc.stack(vec![ alloc.reflow("I am partway through parsing a record type, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow( r"I was expecting to see a closing curly brace before this, so try adding a ", ), @@ -2246,7 +2238,7 @@ fn to_trecord_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I just started parsing a record type, but I got stuck on this field name:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"Looks like you are trying to use "), alloc.keyword(keyword), alloc.reflow(" as a field name, but that is a reserved word. Try using a different name!"), @@ -2269,7 +2261,7 @@ fn to_trecord_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I am partway through parsing a record type, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"I was expecting to see another record field defined next, so I am looking for a name like "), alloc.parser_suggestion("userName"), alloc.reflow(" or "), @@ -2303,7 +2295,7 @@ fn to_trecord_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I just started parsing a record type, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"Record types look like "), alloc.parser_suggestion("{ name : String, age : Int },"), alloc.reflow(" so I was expecting to see a field name next."), @@ -2330,7 +2322,7 @@ fn to_trecord_report<'a>( "I am partway through parsing a record type, but I got stuck here:", ), alloc.region_with_subregion(surroundings, region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("I need this curly brace to be indented more. Try adding more spaces before it!"), ]), ]); @@ -2351,7 +2343,7 @@ fn to_trecord_report<'a>( r"I am partway through parsing a record type, but I got stuck here:", ), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("I was expecting to see a closing curly "), alloc.reflow("brace before this, so try adding a "), alloc.parser_suggestion("}"), @@ -2400,7 +2392,7 @@ fn to_ttag_union_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I just started parsing a tag union, but I got stuck on this field name:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"Looks like you are trying to use "), alloc.keyword(keyword), alloc.reflow(" as a tag name, but that is a reserved word. Tag names must start with a uppercase letter."), @@ -2443,7 +2435,7 @@ fn to_ttag_union_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I just started parsing a tag union type, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"Tag unions look like "), alloc.parser_suggestion("[ Many I64, None ],"), alloc.reflow(" so I was expecting to see a tag name next."), @@ -2504,7 +2496,7 @@ fn to_ttag_union_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I am partway through parsing a tag union type, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow( r"I was expecting to see a closing square bracket before this, so try adding a ", ), @@ -2532,7 +2524,7 @@ fn to_ttag_union_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I just started parsing a tag union type, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"Tag unions look like "), alloc.parser_suggestion("[ Many I64, None ],"), alloc.reflow(" so I was expecting to see a tag name next."), @@ -2562,7 +2554,7 @@ fn to_ttag_union_report<'a>( "I am partway through parsing a tag union type, but I got stuck here:", ), alloc.region_with_subregion(surroundings, region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("I need this square bracket to be indented more. Try adding more spaces before it!"), ]), ]); @@ -2583,7 +2575,7 @@ fn to_ttag_union_report<'a>( r"I am partway through parsing a tag union type, but I got stuck here:", ), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("I was expecting to see a closing square "), alloc.reflow("bracket before this, so try adding a "), alloc.parser_suggestion("]"), @@ -2625,7 +2617,7 @@ fn to_tinparens_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I just saw an open parenthesis, so I was expecting to see a type next."), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"Something like "), alloc.parser_suggestion("(List Person)"), alloc.text(" or "), @@ -2671,7 +2663,7 @@ fn to_tinparens_report<'a>( r"I just started parsing a type in parentheses, but I got stuck here:", ), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"Tag unions look like "), alloc.parser_suggestion("[ Many I64, None ],"), alloc.reflow(" so I was expecting to see a tag name next."), @@ -2717,7 +2709,7 @@ fn to_tinparens_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I am partway through parsing a type in parentheses, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow( r"I was expecting to see a closing parenthesis before this, so try adding a ", ), @@ -2746,7 +2738,7 @@ fn to_tinparens_report<'a>( alloc .reflow(r"I just started parsing a type in parentheses, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow(r"Tag unions look like "), alloc.parser_suggestion("[ Many I64, None ],"), alloc.reflow(" so I was expecting to see a tag name next."), @@ -2773,7 +2765,7 @@ fn to_tinparens_report<'a>( "I am partway through parsing a type in parentheses, but I got stuck here:", ), alloc.region_with_subregion(surroundings, region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("I need this parenthesis to be indented more. Try adding more spaces before it!"), ]), ]); @@ -2794,7 +2786,7 @@ fn to_tinparens_report<'a>( r"I am partway through parsing a type in parentheses, but I got stuck here:", ), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("I was expecting to see a parenthesis "), alloc.reflow("before this, so try adding a "), alloc.parser_suggestion(")"), @@ -2833,7 +2825,7 @@ fn to_tapply_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I encountered two dots in a row:"), alloc.region(region), - alloc.concat(vec![alloc.reflow("Try removing one of them.")]), + alloc.concat([alloc.reflow("Try removing one of them.")]), ]); Report { @@ -2849,7 +2841,7 @@ fn to_tapply_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I encountered a dot with nothing after it:"), alloc.region(region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("Dots are used to refer to a type in a qualified way, like "), alloc.parser_suggestion("Num.I64"), alloc.text(" or "), @@ -2871,7 +2863,7 @@ fn to_tapply_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I encountered a number at the start of a qualified name segment:"), alloc.region(region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("All parts of a qualified type name must start with an uppercase letter, like "), alloc.parser_suggestion("Num.I64"), alloc.text(" or "), @@ -2893,7 +2885,7 @@ fn to_tapply_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I encountered a lowercase letter at the start of a qualified name segment:"), alloc.region(region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("All parts of a qualified type name must start with an uppercase letter, like "), alloc.parser_suggestion("Num.I64"), alloc.text(" or "), @@ -2945,13 +2937,13 @@ fn to_talias_report<'a>( let region = Region::from_pos(pos); let doc = alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow("The inline type after this "), alloc.keyword("as"), alloc.reflow(" is not a type alias:"), ]), alloc.region(lines.convert_region(region)), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("Inline alias types must start with an uppercase identifier and be followed by zero or more type arguments, like "), alloc.type_str("Point"), alloc.reflow(" or "), @@ -3035,7 +3027,7 @@ fn to_header_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I am partway through parsing a header, but got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![alloc.reflow("I may be confused by indentation.")]), + alloc.concat([alloc.reflow("I may be confused by indentation.")]), ]); Report { @@ -3053,7 +3045,7 @@ fn to_header_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I am expecting a header, but got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("I am expecting a module keyword next, one of "), alloc.keyword("interface"), alloc.reflow(", "), @@ -3079,7 +3071,7 @@ fn to_header_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I am partway through parsing a header, but got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("I am expecting a module name next, like "), alloc.parser_suggestion("BigNum"), alloc.reflow(" or "), @@ -3103,7 +3095,7 @@ fn to_header_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I am partway through parsing a header, but got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("I am expecting an application name next, like "), alloc.parser_suggestion("app \"main\""), alloc.reflow(" or "), @@ -3127,7 +3119,7 @@ fn to_header_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I am partway through parsing a header, but got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("I am expecting a platform name next, like "), alloc.parser_suggestion("\"roc/core\""), alloc.reflow(". Platform names must be quoted."), @@ -3150,7 +3142,7 @@ fn to_header_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I am partway through parsing a header, but got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("I am expecting a type name next, like "), alloc.parser_suggestion("Effect"), alloc.reflow(". Type names must start with an uppercase letter."), @@ -3189,7 +3181,7 @@ fn to_generates_with_report<'a>( alloc .reflow(r"I am partway through parsing a provides list, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![alloc.reflow( + alloc.concat([alloc.reflow( "I was expecting a type name, value name or function name next, like", )]), alloc @@ -3212,7 +3204,7 @@ fn to_generates_with_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I am partway through parsing a header, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("I am expecting the "), alloc.keyword("with"), alloc.reflow(" keyword next, like "), @@ -3255,7 +3247,7 @@ fn to_provides_report<'a>( alloc .reflow(r"I am partway through parsing a provides list, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![alloc.reflow( + alloc.concat([alloc.reflow( "I was expecting a type name, value name or function name next, like", )]), alloc @@ -3278,7 +3270,7 @@ fn to_provides_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I am partway through parsing a header, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("I am expecting the "), alloc.keyword("provides"), alloc.reflow(" keyword next, like "), @@ -3320,7 +3312,7 @@ fn to_exposes_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I am partway through parsing an `exposes` list, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![alloc.reflow( + alloc.concat([alloc.reflow( "I was expecting a type name, value name or function name next, like", )]), alloc @@ -3343,7 +3335,7 @@ fn to_exposes_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I am partway through parsing a header, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("I am expecting the "), alloc.keyword("exposes"), alloc.reflow(" keyword next, like "), @@ -3384,7 +3376,7 @@ fn to_imports_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I am partway through parsing a imports list, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![alloc.reflow( + alloc.concat([alloc.reflow( "I was expecting a type name, value name or function name next, like ", )]), alloc @@ -3407,7 +3399,7 @@ fn to_imports_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I am partway through parsing a header, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("I am expecting the "), alloc.keyword("imports"), alloc.reflow(" keyword next, like "), @@ -3434,7 +3426,7 @@ fn to_imports_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I am partway through parsing a header, but got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("I am expecting a module name next, like "), alloc.parser_suggestion("BigNum"), alloc.reflow(" or "), @@ -3472,7 +3464,7 @@ fn to_requires_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I am partway through parsing a header, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("I am expecting the "), alloc.keyword("requires"), alloc.reflow(" keyword next, like "), @@ -3499,7 +3491,7 @@ fn to_requires_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I am partway through parsing a header, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("I am expecting the "), alloc.keyword("requires"), alloc.reflow(" keyword next, like "), @@ -3524,7 +3516,7 @@ fn to_requires_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I am partway through parsing a header, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("I am expecting a list of rigids like "), alloc.keyword("{}"), alloc.reflow(" or "), @@ -3553,7 +3545,7 @@ fn to_requires_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I am partway through parsing a header, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("I am expecting a list of type names like "), alloc.keyword("{}"), alloc.reflow(" or "), @@ -3596,7 +3588,7 @@ fn to_packages_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I am partway through parsing a header, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("I am expecting the "), alloc.keyword("packages"), alloc.reflow(" keyword next, like "), @@ -3634,7 +3626,7 @@ fn to_space_report<'a>( let doc = alloc.stack(vec![ alloc.reflow(r"I encountered a tab character"), alloc.region(region), - alloc.concat(vec![alloc.reflow("Tab characters are not allowed.")]), + alloc.concat([alloc.reflow("Tab characters are not allowed.")]), ]); Report { @@ -3668,7 +3660,7 @@ fn to_ability_def_report<'a>( alloc.reflow("not indented enough") }; - let msg = alloc.concat(vec![ + let msg = alloc.concat([ alloc.reflow("I suspect this line is "), over_under_msg, alloc.reflow(" (by "), @@ -3692,7 +3684,7 @@ fn to_ability_def_report<'a>( filename, *pos, start, - alloc.concat(vec![ + alloc.concat([ alloc.reflow("I was expecting to see a "), alloc.parser_suggestion(":"), alloc.reflow(" annotating the signature of this value next."), diff --git a/reporting/src/error/type.rs b/reporting/src/error/type.rs index 807ad6064f..c8be328966 100644 --- a/reporting/src/error/type.rs +++ b/reporting/src/error/type.rs @@ -81,7 +81,7 @@ pub fn type_problem<'b>( let found_arguments = alloc.text(type_got.to_string()); let doc = alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.reflow("The "), alloc.symbol_unqualified(symbol), alloc.reflow(" alias expects "), @@ -210,7 +210,7 @@ fn report_incomplete_ability<'a>( debug_assert!(!missing_members.is_empty()); - let mut stack = vec![alloc.concat(vec![ + let mut stack = vec![alloc.concat([ alloc.reflow("The type "), alloc.symbol_unqualified(typ), alloc.reflow(" does not fully implement the ability "), @@ -219,7 +219,7 @@ fn report_incomplete_ability<'a>( ])]; for member in missing_members.into_iter() { - stack.push(alloc.concat(vec![ + stack.push(alloc.concat([ alloc.reflow("A specialization for "), alloc.symbol_unqualified(member.value), alloc.reflow(", which is defined here:"), @@ -228,7 +228,7 @@ fn report_incomplete_ability<'a>( } if !specialized_members.is_empty() { - stack.push(alloc.concat(vec![ + stack.push(alloc.concat([ alloc.note(""), alloc.symbol_unqualified(typ), alloc.reflow(" specializes the following members of "), @@ -237,7 +237,7 @@ fn report_incomplete_ability<'a>( ])); for spec in specialized_members { - stack.push(alloc.concat(vec![ + stack.push(alloc.concat([ alloc.symbol_unqualified(spec.value), alloc.reflow(", specialized here:"), ])); @@ -461,8 +461,8 @@ fn to_expr_report<'b>( let (the_name_text, on_name_text) = match pattern_to_doc(alloc, &name.value) { Some(doc) => ( - alloc.concat(vec![alloc.reflow("the "), doc.clone()]), - alloc.concat(vec![alloc.reflow(" on "), doc]), + alloc.concat([alloc.reflow("the "), doc.clone()]), + alloc.concat([alloc.reflow(" on "), doc]), ), None => (alloc.text("this"), alloc.nil()), }; @@ -474,7 +474,7 @@ fn to_expr_report<'b>( index, num_branches, .. - } if num_branches == 2 => alloc.concat(vec![ + } if num_branches == 2 => alloc.concat([ alloc.keyword(if index == HumanIndex::FIRST { "then" } else { @@ -484,19 +484,19 @@ fn to_expr_report<'b>( alloc.keyword("if"), alloc.text(" expression:"), ]), - TypedIfBranch { index, .. } => alloc.concat(vec![ + TypedIfBranch { index, .. } => alloc.concat([ alloc.string(index.ordinal()), alloc.reflow(" branch of this "), alloc.keyword("if"), alloc.text(" expression:"), ]), - TypedWhenBranch { index, .. } => alloc.concat(vec![ + TypedWhenBranch { index, .. } => alloc.concat([ alloc.string(index.ordinal()), alloc.reflow(" branch of this "), alloc.keyword("when"), alloc.text(" expression:"), ]), - TypedBody { .. } => alloc.concat(vec![ + TypedBody { .. } => alloc.concat([ alloc.text("body of "), the_name_text, alloc.text(" definition:"), @@ -525,14 +525,14 @@ fn to_expr_report<'b>( found, expected_type, expectation_context, - alloc.concat(vec![ + alloc.concat([ alloc.reflow("The type annotation"), on_name_text, alloc.reflow(" says "), it.clone(), alloc.reflow(" should have the type:"), ]), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("However, the type of "), it, alloc.reflow(" is connected to another type in a way that isn't reflected in this annotation.") @@ -545,7 +545,7 @@ fn to_expr_report<'b>( expected_type, expectation_context, add_category(alloc, alloc.text(it_is), &category), - alloc.concat(vec![ + alloc.concat([ alloc.text("But the type annotation"), on_name_text, alloc.text(" says it should be:"), @@ -575,7 +575,7 @@ fn to_expr_report<'b>( } Expected::ForReason(reason, expected_type, region) => match reason { Reason::ExpectCondition => { - let problem = alloc.concat(vec![ + let problem = alloc.concat([ alloc.text("This "), alloc.keyword("expect"), alloc.text(" condition needs to be a "), @@ -594,7 +594,7 @@ fn to_expr_report<'b>( Some(expr_region), problem, alloc.text("Right now it’s"), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("But I need every "), alloc.keyword("expect"), alloc.reflow(" condition to evaluate to a "), @@ -614,7 +614,7 @@ fn to_expr_report<'b>( ) } Reason::IfCondition => { - let problem = alloc.concat(vec![ + let problem = alloc.concat([ alloc.text("This "), alloc.keyword("if"), alloc.text(" condition needs to be a "), @@ -633,7 +633,7 @@ fn to_expr_report<'b>( Some(expr_region), problem, alloc.text("Right now it’s"), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("But I need every "), alloc.keyword("if"), alloc.reflow(" condition to evaluate to a "), @@ -653,7 +653,7 @@ fn to_expr_report<'b>( ) } Reason::WhenGuard => { - let problem = alloc.concat(vec![ + let problem = alloc.concat([ alloc.text("This "), alloc.keyword("if"), alloc.text(" guard condition needs to be a "), @@ -671,7 +671,7 @@ fn to_expr_report<'b>( Some(expr_region), problem, alloc.text("Right now it’s"), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("But I need every "), alloc.keyword("if"), alloc.reflow(" guard condition to evaluate to a "), @@ -697,7 +697,7 @@ fn to_expr_report<'b>( expected_type, region, Some(expr_region), - alloc.concat(vec![ + alloc.concat([ alloc.text("This "), alloc.keyword("if"), alloc.text(" has an "), @@ -706,17 +706,17 @@ fn to_expr_report<'b>( alloc.keyword("then"), alloc.text(" branch:"), ]), - alloc.concat(vec![ + alloc.concat([ alloc.text("The "), alloc.keyword("else"), alloc.text(" branch is"), ]), - alloc.concat(vec![ + alloc.concat([ alloc.text("but the "), alloc.keyword("then"), alloc.text(" branch has the type:"), ]), - Some(alloc.concat(vec![ + Some(alloc.concat([ alloc.text("I need all branches in an "), alloc.keyword("if"), alloc.text(" to have the same type!"), @@ -731,7 +731,7 @@ fn to_expr_report<'b>( expected_type, region, Some(expr_region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("The "), alloc.string(index.ordinal()), alloc.reflow(" branch of this "), @@ -740,7 +740,7 @@ fn to_expr_report<'b>( ]), alloc.string(format!("The {} branch is", index.ordinal())), alloc.reflow("But all the previous branches have type:"), - Some(alloc.concat(vec![ + Some(alloc.concat([ alloc.reflow("I need all branches in an "), alloc.keyword("if"), alloc.reflow(" to have the same type!"), @@ -756,20 +756,20 @@ fn to_expr_report<'b>( expected_type, region, Some(expr_region), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("The "), alloc.string(index.ordinal()), alloc.reflow(" branch of this "), alloc.keyword("when"), alloc.reflow(" does not match all the previous branches:"), ]), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("The "), alloc.string(index.ordinal()), alloc.reflow(" branch is"), ]), alloc.reflow("But all the previous branches have type:"), - Some(alloc.concat(vec![ + Some(alloc.concat([ alloc.reflow("I need all branches of a "), alloc.keyword("when"), alloc.reflow(" to have the same type!"), @@ -810,12 +810,12 @@ fn to_expr_report<'b>( expected_type, region, Some(expr_region), - alloc.concat(vec![ + alloc.concat([ alloc.text("I cannot update the "), alloc.record_field(field.to_owned()), alloc.text(" field like this:"), ]), - alloc.concat(vec![ + alloc.concat([ alloc.text("You are trying to update "), alloc.record_field(field), alloc.text(" to be"), @@ -846,7 +846,7 @@ fn to_expr_report<'b>( region, Some(expr_region), alloc.reflow("Something is off with this record update:"), - alloc.concat(vec![ + alloc.concat([ alloc.reflow("The"), alloc.symbol_unqualified(symbol), alloc.reflow(" record is"), @@ -939,7 +939,7 @@ fn to_expr_report<'b>( 0 => { let this_value = match name { None => alloc.text("This value"), - Some(symbol) => alloc.concat(vec![ + Some(symbol) => alloc.concat([ alloc.text("The "), alloc.symbol_unqualified(symbol), alloc.text(" value"), @@ -947,7 +947,7 @@ fn to_expr_report<'b>( }; let lines = vec![ - alloc.concat(vec![ + alloc.concat([ this_value, alloc.string(format!( " is not a function, but it was given {}:", @@ -972,7 +972,7 @@ fn to_expr_report<'b>( n => { let this_function = match name { None => alloc.text("This function"), - Some(symbol) => alloc.concat(vec![ + Some(symbol) => alloc.concat([ alloc.text("The "), alloc.symbol_unqualified(symbol), alloc.text(" function"), @@ -981,7 +981,7 @@ fn to_expr_report<'b>( if n < arity as usize { let lines = vec![ - alloc.concat(vec![ + alloc.concat([ this_function, alloc.string(format!( " expects {}, but it got {} instead:", @@ -1005,7 +1005,7 @@ fn to_expr_report<'b>( } } else { let lines = vec![ - alloc.concat(vec![ + alloc.concat([ this_function, alloc.string(format!( " expects {}, but it got only {}:", @@ -1050,13 +1050,13 @@ fn to_expr_report<'b>( expected_type, region, Some(expr_region), - alloc.concat(vec![ + alloc.concat([ alloc.string(format!("The {} argument to ", ith)), this_function.clone(), alloc.text(" is not what I expect:"), ]), alloc.text("This argument is"), - alloc.concat(vec![ + alloc.concat([ alloc.text("But "), this_function, alloc.string(format!(" needs the {} argument to be:", ith)), @@ -1085,13 +1085,13 @@ fn to_expr_report<'b>( def_region: _, unimplemented_abilities, } => { - let problem = alloc.concat(vec![ + let problem = alloc.concat([ alloc.reflow("Something is off with this specialization of "), alloc.symbol_unqualified(member_name), alloc.reflow(":"), ]); let this_is = alloc.reflow("This value is"); - let instead_of = alloc.concat(vec![ + let instead_of = alloc.concat([ alloc.reflow("But the type annotation on "), alloc.symbol_unqualified(member_name), alloc.reflow(" says it must match:"), @@ -1106,7 +1106,7 @@ fn to_expr_report<'b>( } let hint = alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.note(""), alloc.reflow("Some types in this specialization don't implement the abilities they are expected to. I found the following missing implementations:"), ]), @@ -1136,20 +1136,20 @@ fn to_expr_report<'b>( member_name, def_region: _, } => { - let problem = alloc.concat(vec![ + let problem = alloc.concat([ alloc.reflow("This specialization of "), alloc.symbol_unqualified(member_name), alloc.reflow(" is overly general:"), ]); let this_is = alloc.reflow("This value is"); - let instead_of = alloc.concat(vec![ + let instead_of = alloc.concat([ alloc.reflow("But the type annotation on "), alloc.symbol_unqualified(member_name), alloc.reflow(" says it must match:"), ]); let note = alloc.stack(vec![ - alloc.concat(vec![ + alloc.concat([ alloc.note(""), alloc.reflow("The specialized type is too general, and does not provide a concrete type where a type variable is bound to an ability."), ]), @@ -1211,7 +1211,7 @@ fn does_not_implement<'a>( err_type: ErrorType, ability: Symbol, ) -> RocDocBuilder<'a> { - alloc.concat(vec![ + alloc.concat([ to_doc(alloc, Parens::Unnecessary, err_type).0, alloc.reflow(" does not implement "), alloc.symbol_unqualified(ability), @@ -1223,7 +1223,7 @@ fn symbol_does_not_implement<'a>( symbol: Symbol, ability: Symbol, ) -> RocDocBuilder<'a> { - alloc.concat(vec![ + alloc.concat([ alloc.symbol_unqualified(symbol), alloc.reflow(" does not implement "), alloc.symbol_unqualified(ability), @@ -1325,7 +1325,7 @@ fn format_category<'b>( match category { Lookup(name) => ( - alloc.concat(vec![ + alloc.concat([ alloc.text(format!("{}his ", t)), alloc.symbol_foreign_qualified(*name), alloc.text(" value"), @@ -1334,7 +1334,7 @@ fn format_category<'b>( ), If => ( - alloc.concat(vec![ + alloc.concat([ alloc.text(format!("{}his ", t)), alloc.keyword("if"), alloc.text(" expression"), @@ -1342,7 +1342,7 @@ fn format_category<'b>( alloc.text(" produces:"), ), When => ( - alloc.concat(vec![ + alloc.concat([ alloc.text(format!("{}his ", t)), alloc.keyword("when"), alloc.text(" expression"), @@ -1350,47 +1350,44 @@ fn format_category<'b>( alloc.text(" produces:"), ), List => ( - alloc.concat(vec![this_is, alloc.text(" a list")]), + alloc.concat([this_is, alloc.text(" a list")]), alloc.text(" of type:"), ), Num => ( - alloc.concat(vec![this_is, alloc.text(" a number")]), + alloc.concat([this_is, alloc.text(" a number")]), alloc.text(" of type:"), ), Int => ( - alloc.concat(vec![this_is, alloc.text(" an integer")]), + alloc.concat([this_is, alloc.text(" an integer")]), alloc.text(" of type:"), ), Float => ( - alloc.concat(vec![this_is, alloc.text(" a float")]), + alloc.concat([this_is, alloc.text(" a float")]), alloc.text(" of type:"), ), Str => ( - alloc.concat(vec![this_is, alloc.text(" a string")]), + alloc.concat([this_is, alloc.text(" a string")]), alloc.text(" of type:"), ), StrInterpolation => ( - alloc.concat(vec![ - this_is, - alloc.text(" a value in a string interpolation,"), - ]), + alloc.concat([this_is, alloc.text(" a value in a string interpolation,")]), alloc.text(" which was of type:"), ), Character => ( - alloc.concat(vec![this_is, alloc.text(" a character")]), + alloc.concat([this_is, alloc.text(" a character")]), alloc.text(" of type:"), ), Lambda => ( - alloc.concat(vec![this_is, alloc.text(" an anonymous function")]), + alloc.concat([this_is, alloc.text(" an anonymous function")]), alloc.text(" of type:"), ), ClosureSize => ( - alloc.concat(vec![this_is, alloc.text(" the closure size of a function")]), + alloc.concat([this_is, alloc.text(" the closure size of a function")]), alloc.text(" of type:"), ), OpaqueWrap(opaque) => ( - alloc.concat(vec![ + alloc.concat([ alloc.text(format!("{}his ", t)), alloc.opaque_name(*opaque), alloc.text(" opaque wrapping"), @@ -1399,9 +1396,7 @@ fn format_category<'b>( ), OpaqueArg => ( - alloc.concat(vec![ - alloc.text(format!("{}his argument to an opaque type", t)) - ]), + alloc.concat([alloc.text(format!("{}his argument to an opaque type", t))]), alloc.text(" has type:"), ), @@ -1409,7 +1404,7 @@ fn format_category<'b>( tag_name: TagName::Global(name), args_count: 0, } => ( - alloc.concat(vec![ + alloc.concat([ alloc.text(format!("{}his ", t)), alloc.global_tag_name(name.to_owned()), if name.as_str() == "True" || name.as_str() == "False" { @@ -1424,7 +1419,7 @@ fn format_category<'b>( tag_name: TagName::Private(name), args_count: 0, } => ( - alloc.concat(vec![ + alloc.concat([ alloc.text(format!("{}his ", t)), alloc.private_tag_name(*name), alloc.text(" private tag"), @@ -1436,7 +1431,7 @@ fn format_category<'b>( tag_name: TagName::Global(name), args_count: _, } => ( - alloc.concat(vec![ + alloc.concat([ alloc.text(format!("{}his ", t)), alloc.global_tag_name(name.to_owned()), alloc.text(" global tag application"), @@ -1447,7 +1442,7 @@ fn format_category<'b>( tag_name: TagName::Private(name), args_count: _, } => ( - alloc.concat(vec![ + alloc.concat([ alloc.text("This "), alloc.private_tag_name(*name), alloc.text(" private tag application"), @@ -1460,12 +1455,12 @@ fn format_category<'b>( } => unreachable!("closure tags are for internal use only"), Record => ( - alloc.concat(vec![this_is, alloc.text(" a record")]), + alloc.concat([this_is, alloc.text(" a record")]), alloc.text(" of type:"), ), Accessor(field) => ( - alloc.concat(vec![ + alloc.concat([ alloc.text(format!("{}his ", t)), alloc.record_field(field.to_owned()), alloc.text(" value"), @@ -1473,7 +1468,7 @@ fn format_category<'b>( alloc.text(" is a:"), ), Access(field) => ( - alloc.concat(vec![ + alloc.concat([ alloc.text(format!("{}he value at ", t)), alloc.record_field(field.to_owned()), ]), @@ -1494,11 +1489,11 @@ fn format_category<'b>( alloc.text(" produces:"), ), CallResult(Some(_), CalledVia::StringInterpolation) => ( - alloc.concat(vec![this_is, alloc.text(" a string")]), + alloc.concat([this_is, alloc.text(" a string")]), alloc.text(" of type:"), ), CallResult(Some(symbol), _) => ( - alloc.concat(vec![ + alloc.concat([ alloc.text(format!("{}his ", t)), alloc.symbol_foreign_qualified(*symbol), alloc.text(" call"), @@ -1517,19 +1512,19 @@ fn format_category<'b>( } Uniqueness => ( - alloc.concat(vec![this_is, alloc.text(" an uniqueness attribute")]), + alloc.concat([this_is, alloc.text(" an uniqueness attribute")]), alloc.text(" of type:"), ), Storage(_file, _line) => ( - alloc.concat(vec![this_is, alloc.text(" a value")]), + alloc.concat([this_is, alloc.text(" a value")]), alloc.text(" of type:"), ), DefaultValue(_) => ( - alloc.concat(vec![this_is, alloc.text(" a default field")]), + alloc.concat([this_is, alloc.text(" a default field")]), alloc.text(" of type:"), ), AbilityMemberSpecialization(_ability_member) => ( - alloc.concat(vec![this_is, alloc.text(" a declared specialization")]), + alloc.concat([this_is, alloc.text(" a declared specialization")]), alloc.text(" of type:"), ), } @@ -1541,7 +1536,7 @@ fn add_category<'b>( category: &Category, ) -> RocDocBuilder<'b> { let (summary, suffix) = format_category(alloc, this_is, category, true); - alloc.concat(vec![summary, suffix]) + alloc.concat([summary, suffix]) } fn to_pattern_report<'b>( @@ -1602,7 +1597,7 @@ fn to_pattern_report<'b>( alloc.text("The argument is a pattern that matches"), &category, ), - alloc.concat(vec![ + alloc.concat([ alloc.text("But the annotation on "), name, alloc.text(" says the "), @@ -1637,7 +1632,7 @@ fn to_pattern_report<'b>( alloc.text("The first pattern is trying to match"), &category, ), - alloc.concat(vec![ + alloc.concat([ alloc.text("But the expression between "), alloc.keyword("when"), alloc.text(" and "), @@ -1734,12 +1729,12 @@ fn add_pattern_category<'b>( PatternDefault => alloc.reflow(" an optional field of type:"), Set => alloc.reflow(" sets of type:"), Map => alloc.reflow(" maps of type:"), - Ctor(tag_name) => alloc.concat(vec![ + Ctor(tag_name) => alloc.concat([ alloc.reflow(" a "), alloc.tag_name(tag_name.clone()), alloc.reflow(" tag of type:"), ]), - Opaque(opaque) => alloc.concat(vec![ + Opaque(opaque) => alloc.concat([ alloc.opaque_name(*opaque), alloc.reflow(" unwrappings of type:"), ]), @@ -1750,7 +1745,7 @@ fn add_pattern_category<'b>( Character => alloc.reflow(" characters:"), }; - alloc.concat(vec![i_am_trying_to_match, rest]) + alloc.concat([i_am_trying_to_match, rest]) } fn to_circular_report<'b>( @@ -2804,7 +2799,7 @@ mod report_text { args: Vec>, ret: RocDocBuilder<'b>, ) -> RocDocBuilder<'b> { - let function_doc = alloc.concat(vec![ + let function_doc = alloc.concat([ alloc.intersperse(args, alloc.reflow(", ")), alloc.reflow(" -> "), ret, @@ -2825,11 +2820,8 @@ mod report_text { if args.is_empty() { name } else { - let apply_doc = alloc.concat(vec![ - name, - alloc.space(), - alloc.intersperse(args, alloc.space()), - ]); + let apply_doc = + alloc.concat([name, alloc.space(), alloc.intersperse(args, alloc.space())]); match parens { Parens::Unnecessary | Parens::InFn => apply_doc, @@ -3209,7 +3201,7 @@ fn type_problem_to_pretty<'b>( Infinite | Error | FlexVar(_) => alloc.nil(), FlexAbleVar(_, ability) => bad_rigid_var( x, - alloc.concat(vec![ + alloc.concat([ alloc.reflow("an instance of the ability "), alloc.symbol_unqualified(ability), ]), @@ -3222,7 +3214,7 @@ fn type_problem_to_pretty<'b>( } Alias(symbol, _, _, _) | Type(symbol, _) => bad_rigid_var( x, - alloc.concat(vec![ + alloc.concat([ alloc.reflow("a "), alloc.symbol_unqualified(symbol), alloc.reflow(" value"), @@ -3232,7 +3224,7 @@ fn type_problem_to_pretty<'b>( } } - (IntFloat, _) => alloc.tip().append(alloc.concat(vec![ + (IntFloat, _) => alloc.tip().append(alloc.concat([ alloc.reflow("You can convert between "), alloc.type_str("Int"), alloc.reflow(" and "), @@ -3285,7 +3277,7 @@ fn type_problem_to_pretty<'b>( alloc.stack(vec![tip1, tip2]) } }, - (OptionalRequiredMismatch(field), _) => alloc.tip().append(alloc.concat(vec![ + (OptionalRequiredMismatch(field), _) => alloc.tip().append(alloc.concat([ alloc.reflow("To extract the "), alloc.record_field(field), alloc.reflow( @@ -3294,7 +3286,7 @@ fn type_problem_to_pretty<'b>( alloc.reflow("Learn more about optional fields at TODO."), ])), - (OpaqueComparedToNonOpaque, _) => alloc.tip().append(alloc.concat(vec![ + (OpaqueComparedToNonOpaque, _) => alloc.tip().append(alloc.concat([ alloc.reflow( "Type comparisons between an opaque type are only ever \ equal if both types are the same opaque type. Did you mean \ From 27edc492716f42efb4bfc3282717126ef4c33e07 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Tue, 19 Apr 2022 20:24:32 -0400 Subject: [PATCH 336/846] Use nicer report for record field mismatches --- reporting/src/error/type.rs | 190 +++++++++++++++++++++++------------- 1 file changed, 124 insertions(+), 66 deletions(-) diff --git a/reporting/src/error/type.rs b/reporting/src/error/type.rs index c8be328966..e7e06ccd03 100644 --- a/reporting/src/error/type.rs +++ b/reporting/src/error/type.rs @@ -1,3 +1,4 @@ +use crate::report::{Annotation, Report, RocDocAllocator, RocDocBuilder, Severity}; use roc_can::expected::{Expected, PExpected}; use roc_collections::all::{HumanIndex, MutSet, SendMap}; use roc_module::called_via::{BinOp, CalledVia}; @@ -10,8 +11,6 @@ use roc_types::types::{ AliasKind, Category, ErrorType, PatternCategory, Reason, RecordField, TypeExt, }; use std::path::PathBuf; - -use crate::report::{Annotation, Report, RocDocAllocator, RocDocBuilder, Severity}; use ven_pretty::DocAllocator; const DUPLICATE_NAME: &str = "DUPLICATE NAME"; @@ -435,6 +434,36 @@ fn to_expr_report<'b>( ) -> Report<'b> { match expected { Expected::NoExpectation(expected_type) => { + // If it looks like a record field typo, early return with a special report for that. + if let ErrorType::Record(expected_fields, _) = + expected_type.clone().unwrap_structural_alias() + { + if let ErrorType::Record(found_fields, found_ext) = + found.clone().unwrap_structural_alias() + { + let expected_set: MutSet<_> = expected_fields.keys().cloned().collect(); + let found_set: MutSet<_> = found_fields.keys().cloned().collect(); + let mut diff = expected_set.difference(&found_set); + + if let Some(field) = diff.next() { + let opt_sym = match category { + Category::Lookup(name) => Some(name), + _ => None, + }; + return report_record_field_typo( + alloc, + lines, + filename, + opt_sym, + field, + expr_region, + found_fields, + found_ext, + ); + } + } + }; + let comparison = type_comparison( alloc, found, @@ -854,70 +883,16 @@ fn to_expr_report<'b>( alloc.reflow("But this update needs it to be compatible with:"), None, ), - Some((field, field_region)) => { - let r_doc = alloc.symbol_unqualified(symbol); - let f_doc = alloc - .text(field.as_str().to_string()) - .annotate(Annotation::Typo); - - let header = alloc.concat(vec![ - alloc.reflow("The "), - r_doc.clone(), - alloc.reflow(" record does not have a "), - f_doc.clone(), - alloc.reflow(" field:"), - ]); - - let mut suggestions = suggest::sort( - field.as_str(), - actual_fields.into_iter().collect::>(), - ); - - let doc = alloc.stack(vec![ - header, - alloc.region(lines.convert_region(*field_region)), - if suggestions.is_empty() { - alloc.concat(vec![ - alloc.reflow("In fact, "), - r_doc, - alloc.reflow(" is a record with NO fields!"), - ]) - } else { - let f = suggestions.remove(0); - let fs = suggestions; - - alloc.stack(vec![ - alloc.concat(vec![ - alloc.reflow("There may be a typo. These "), - r_doc, - alloc.reflow(" fields are the most similar:"), - ]), - report_text::to_suggestion_record( - alloc, - f.clone(), - fs, - ext, - ), - alloc.concat(vec![ - alloc.reflow("Maybe "), - f_doc, - alloc.reflow(" should be "), - alloc - .text(f.0.as_str().to_string()) - .annotate(Annotation::TypoSuggestion), - alloc.reflow("?"), - ]), - ]) - }, - ]); - - Report { - filename, - title: "TYPE MISMATCH".to_string(), - doc, - severity: Severity::RuntimeError, - } - } + Some((field, field_region)) => report_record_field_typo( + alloc, + lines, + filename, + Some(symbol), + field, + *field_region, + actual_fields, + ext, + ), } } _ => report_bad_type( @@ -3299,3 +3274,86 @@ fn type_problem_to_pretty<'b>( ])), } } + +fn report_record_field_typo<'b>( + alloc: &'b RocDocAllocator<'b>, + lines: &LineInfo, + filename: PathBuf, + opt_sym: Option, + field: &Lowercase, + field_region: Region, + actual_fields: SendMap>, + ext: TypeExt, +) -> Report<'b> { + let f_doc = alloc + .text(field.as_str().to_string()) + .annotate(Annotation::Typo); + + let header = { + let r_doc = match opt_sym { + Some(symbol) => alloc.symbol_unqualified(symbol).append(" "), + None => alloc.text(""), + }; + + alloc.concat([ + alloc.reflow("This "), + r_doc, + alloc.reflow("record doesn’t have a "), + f_doc.clone(), + alloc.reflow(" field:"), + ]) + }; + + let mut suggestions = suggest::sort( + field.as_str(), + actual_fields.into_iter().collect::>(), + ); + + let doc = alloc.stack(vec![ + header, + alloc.region(lines.convert_region(field_region)), + if suggestions.is_empty() { + let r_doc = match opt_sym { + Some(symbol) => alloc.symbol_unqualified(symbol).append(" is"), + None => alloc.text("it’s"), + }; + alloc.concat([ + alloc.reflow("In fact, "), + r_doc, + alloc.reflow(" a record with no fields at all!"), + ]) + } else { + let f = suggestions.remove(0); + let fs = suggestions; + let r_doc = match opt_sym { + Some(symbol) => alloc.symbol_unqualified(symbol).append(" fields"), + None => alloc.text("fields on the record"), + }; + + alloc.stack(vec![ + alloc.concat([ + alloc.reflow("There may be a typo. These "), + r_doc, + alloc.reflow(" are the most similar:"), + ]), + report_text::to_suggestion_record(alloc, f.clone(), fs, ext), + alloc.concat([ + alloc.reflow("Maybe "), + f_doc, + alloc.reflow(" should be "), + alloc + .text(f.0.as_str().to_string()) + .annotate(Annotation::TypoSuggestion), + alloc.reflow("?"), + ]), + ]) + }, + ]); + + Report { + filename, + title: "TYPE MISMATCH".to_string(), + doc, + severity: Severity::RuntimeError, + } +} From 40aca3c20dec4c46aedaa9a9fc5a8bde51e12ee9 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Tue, 19 Apr 2022 20:25:28 -0400 Subject: [PATCH 337/846] Remove another gazillion allocations from reporting --- compiler/load_internal/src/file.rs | 12 +- reporting/src/error/canonicalize.rs | 138 ++++++++-------- reporting/src/error/mono.rs | 8 +- reporting/src/error/parse.rs | 238 ++++++++++++++-------------- reporting/src/error/type.rs | 40 ++--- reporting/src/report.rs | 5 +- 6 files changed, 218 insertions(+), 223 deletions(-) diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index c64b9c738e..9259818027 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -4513,7 +4513,7 @@ fn to_file_problem_report(filename: &Path, error: io::ErrorKind) -> String { let report = match error { io::ErrorKind::NotFound => { - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I am looking for this file, but it's not there:"), alloc .parser_suggestion(filename.to_str().unwrap()) @@ -4532,7 +4532,7 @@ fn to_file_problem_report(filename: &Path, error: io::ErrorKind) -> String { } } io::ErrorKind::PermissionDenied => { - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I don't have the required permissions to read this file:"), alloc .parser_suggestion(filename.to_str().unwrap()) @@ -4630,7 +4630,7 @@ fn to_missing_platform_report(module_id: ModuleId, other: PlatformPath) -> Strin match other { Valid(_) => unreachable!(), NotSpecified => { - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow("I could not find a platform based on your input file."), alloc.reflow(r"Does the module header contain an entry that looks like this:"), alloc @@ -4647,7 +4647,7 @@ fn to_missing_platform_report(module_id: ModuleId, other: PlatformPath) -> Strin } } RootIsInterface => { - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"The input file is an interface module, but only app modules can be ran."), alloc.concat([ alloc.reflow(r"I will still parse and typecheck the input file and its dependencies, "), @@ -4663,7 +4663,7 @@ fn to_missing_platform_report(module_id: ModuleId, other: PlatformPath) -> Strin } } RootIsHosted => { - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"The input file is a hosted module, but only app modules can be ran."), alloc.concat([ alloc.reflow(r"I will still parse and typecheck the input file and its dependencies, "), @@ -4679,7 +4679,7 @@ fn to_missing_platform_report(module_id: ModuleId, other: PlatformPath) -> Strin } } RootIsPkgConfig => { - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"The input file is a package config file, but only app modules can be ran."), alloc.concat([ alloc.reflow(r"I will still parse and typecheck the input file and its dependencies, "), diff --git a/reporting/src/error/canonicalize.rs b/reporting/src/error/canonicalize.rs index d22c091a4b..4e627cb2dc 100644 --- a/reporting/src/error/canonicalize.rs +++ b/reporting/src/error/canonicalize.rs @@ -61,7 +61,7 @@ pub fn can_problem<'b>( let line = r#" then remove it so future readers of your code don't wonder why it is there."#; - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc .symbol_unqualified(symbol) .append(alloc.reflow(" is not used anywhere in your code.")), @@ -76,7 +76,7 @@ pub fn can_problem<'b>( severity = Severity::Warning; } Problem::UnusedImport(module_id, region) => { - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc.concat([ alloc.reflow("Nothing from "), alloc.module(module_id), @@ -94,7 +94,7 @@ pub fn can_problem<'b>( severity = Severity::Warning; } Problem::ExposedButNotDefined(symbol) => { - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc.symbol_unqualified(symbol).append( alloc.reflow(" is listed as exposed, but it isn't defined in this module."), ), @@ -110,7 +110,7 @@ pub fn can_problem<'b>( severity = Severity::RuntimeError; } Problem::UnknownGeneratesWith(loc_ident) => { - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc .reflow("I don't know how to generate the ") .append(alloc.ident(loc_ident.value)) @@ -127,7 +127,7 @@ pub fn can_problem<'b>( Problem::UnusedArgument(closure_symbol, argument_symbol, region) => { let line = "\". Adding an underscore at the start of a variable name is a way of saying that the variable is not used."; - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc.concat([ alloc.symbol_unqualified(closure_symbol), alloc.reflow(" doesn't use "), @@ -152,7 +152,7 @@ pub fn can_problem<'b>( severity = Severity::Warning; } Problem::PrecedenceProblem(BothNonAssociative(region, left_bin_op, right_bin_op)) => { - doc = alloc.stack(vec![ + doc = alloc.stack([ if left_bin_op.value == right_bin_op.value { alloc.concat([ alloc.reflow("Using more than one "), @@ -181,7 +181,7 @@ pub fn can_problem<'b>( severity = Severity::RuntimeError; } Problem::UnsupportedPattern(BadPattern::UnderscoreInDef, region) => { - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc.reflow("Underscore patterns are not allowed in definitions"), alloc.region(lines.convert_region(region)), ]); @@ -209,7 +209,7 @@ pub fn can_problem<'b>( alloc.reflow(" instead."), ]; - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc .reflow("This pattern is not allowed in ") .append(alloc.reflow(this_thing)), @@ -242,7 +242,7 @@ pub fn can_problem<'b>( variable_region, variable_name, } => { - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc.concat([ alloc.reflow("The "), alloc.type_variable(variable_name), @@ -310,7 +310,7 @@ pub fn can_problem<'b>( record_region, replaced_region, } => { - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc.concat([ alloc.reflow("This record defines the "), alloc.record_field(field_name.clone()), @@ -359,7 +359,7 @@ pub fn can_problem<'b>( record_region, replaced_region, } => { - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc.concat([ alloc.reflow("This record type defines the "), alloc.record_field(field_name.clone()), @@ -394,7 +394,7 @@ pub fn can_problem<'b>( tag_region, replaced_region, } => { - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc.concat([ alloc.reflow("This tag union type defines the "), alloc.tag_name(tag_name.clone()), @@ -427,7 +427,7 @@ pub fn can_problem<'b>( ref annotation_pattern, ref def_pattern, } => { - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc.reflow( "This annotation does not match the definition immediately following it:", ), @@ -444,7 +444,7 @@ pub fn can_problem<'b>( alias_name: type_name, region, } => { - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc.concat([ alloc.reflow("This pattern in the definition of "), alloc.symbol_unqualified(type_name), @@ -464,7 +464,7 @@ pub fn can_problem<'b>( severity = Severity::RuntimeError; } Problem::InvalidHexadecimal(region) => { - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc.reflow("This unicode code point is invalid:"), alloc.region(lines.convert_region(region)), alloc.concat([ @@ -481,7 +481,7 @@ pub fn can_problem<'b>( severity = Severity::RuntimeError; } Problem::InvalidUnicodeCodePt(region) => { - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc.reflow("This unicode code point is invalid:"), alloc.region(lines.convert_region(region)), alloc.reflow("Learn more about working with unicode in roc at TODO"), @@ -491,7 +491,7 @@ pub fn can_problem<'b>( severity = Severity::RuntimeError; } Problem::InvalidInterpolation(region) => { - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc.reflow("This string interpolation is invalid:"), alloc.region(lines.convert_region(region)), alloc.concat([ @@ -519,7 +519,7 @@ pub fn can_problem<'b>( def_region, differing_recursion_region, } => { - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc.concat([ alloc.symbol_unqualified(alias), alloc.reflow(" is a nested datatype. Here is one recursive usage of it:"), @@ -551,7 +551,7 @@ pub fn can_problem<'b>( } }; - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc.concat([ alloc.reflow("This "), alloc.text(kind_str), @@ -575,7 +575,7 @@ pub fn can_problem<'b>( name, variables_region, } => { - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc.concat([ alloc.reflow("The definition of the "), alloc.symbol_unqualified(name), @@ -593,7 +593,7 @@ pub fn can_problem<'b>( Problem::HasClauseIsNotAbility { region: clause_region, } => { - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc.reflow(r#"The type referenced in this "has" clause is not an ability:"#), alloc.region(lines.convert_region(clause_region)), ]); @@ -608,7 +608,7 @@ pub fn can_problem<'b>( }, ability, } => { - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc.concat([ alloc.reflow("The definition of the "), alloc.symbol_unqualified(name), @@ -633,7 +633,7 @@ pub fn can_problem<'b>( } Problem::IllegalHasClause { region } => { - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc.concat([ alloc.reflow("A "), alloc.keyword("has"), @@ -654,7 +654,7 @@ pub fn can_problem<'b>( ability, region, } => { - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc.concat([ alloc.reflow("The definition of the ability member "), alloc.symbol_unqualified(member), @@ -690,7 +690,7 @@ pub fn can_problem<'b>( span_has_clauses, mut bound_var_names, } => { - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc.concat([ alloc.reflow("The definition of the ability member "), alloc.symbol_unqualified(member), @@ -717,7 +717,7 @@ pub fn can_problem<'b>( ability, region, } => { - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc.concat([ alloc.reflow("The definition of the ability member "), alloc.symbol_unqualified(member), @@ -776,7 +776,7 @@ fn to_invalid_optional_value_report_help<'b>( field_region: Region, record_region: Region, ) -> RocDocBuilder<'b> { - alloc.stack(vec![ + alloc.stack([ alloc.concat([ alloc.reflow("This record uses an optional value for the "), alloc.record_field(field_name), @@ -808,7 +808,7 @@ fn to_bad_ident_expr_report<'b>( WeirdDotAccess(pos) | StrayDot(pos) => { let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - alloc.stack(vec![ + alloc.stack([ alloc.reflow(r"I trying to parse a record field access here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -821,7 +821,7 @@ fn to_bad_ident_expr_report<'b>( ]) } - WeirdAccessor(_pos) => alloc.stack(vec![ + WeirdAccessor(_pos) => alloc.stack([ alloc.reflow("I am very confused by this field access"), alloc.region(lines.convert_region(surroundings)), alloc.concat([ @@ -839,7 +839,7 @@ fn to_bad_ident_expr_report<'b>( WeirdDotQualified(pos) => { let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - alloc.stack(vec![ + alloc.stack([ alloc.reflow("I am trying to parse a qualified name here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -854,7 +854,7 @@ fn to_bad_ident_expr_report<'b>( QualifiedTag(pos) => { let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - alloc.stack(vec![ + alloc.stack([ alloc.reflow("I am trying to parse a qualified name here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -869,7 +869,7 @@ fn to_bad_ident_expr_report<'b>( Underscore(pos) => { let region = Region::new(surroundings.start(), pos); - alloc.stack(vec![ + alloc.stack([ alloc.reflow("Underscores are not allowed in identifier names:"), alloc.region_with_subregion( lines.convert_region(surroundings), @@ -891,7 +891,7 @@ fn to_bad_ident_expr_report<'b>( match what_is_next(alloc.src_lines, lines.convert_pos(pos)) { LowercaseAccess(width) => { let region = Region::new(pos, pos.bump_column(width)); - alloc.stack(vec![ + alloc.stack([ alloc.reflow("I am very confused by this field access:"), alloc.region_with_subregion( lines.convert_region(surroundings), @@ -906,7 +906,7 @@ fn to_bad_ident_expr_report<'b>( } UppercaseAccess(width) => { let region = Region::new(pos, pos.bump_column(width)); - alloc.stack(vec![ + alloc.stack([ alloc.reflow("I am very confused by this expression:"), alloc.region_with_subregion( lines.convert_region(surroundings), @@ -925,7 +925,7 @@ fn to_bad_ident_expr_report<'b>( Other(Some(c)) if c.is_lowercase() => { let region = Region::new(surroundings.start().bump_column(1), pos.bump_column(1)); - alloc.stack(vec![ + alloc.stack([ alloc.concat([ alloc.reflow("I am trying to parse "), alloc.reflow(kind), @@ -967,7 +967,7 @@ fn to_bad_ident_pattern_report<'b>( WeirdDotAccess(pos) | StrayDot(pos) => { let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - alloc.stack(vec![ + alloc.stack([ alloc.reflow(r"I trying to parse a record field accessor here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -980,7 +980,7 @@ fn to_bad_ident_pattern_report<'b>( ]) } - WeirdAccessor(_pos) => alloc.stack(vec![ + WeirdAccessor(_pos) => alloc.stack([ alloc.reflow("I am very confused by this field access"), alloc.region(lines.convert_region(surroundings)), alloc.concat([ @@ -998,7 +998,7 @@ fn to_bad_ident_pattern_report<'b>( WeirdDotQualified(pos) => { let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - alloc.stack(vec![ + alloc.stack([ alloc.reflow("I am trying to parse a qualified name here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -1013,7 +1013,7 @@ fn to_bad_ident_pattern_report<'b>( QualifiedTag(pos) => { let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - alloc.stack(vec![ + alloc.stack([ alloc.reflow("I am trying to parse a qualified name here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -1029,7 +1029,7 @@ fn to_bad_ident_pattern_report<'b>( Underscore(pos) => { let region = Region::from_pos(pos.sub(1)); - alloc.stack(vec![ + alloc.stack([ alloc.reflow("I am trying to parse an identifier here:"), alloc.region_with_subregion( lines.convert_region(surroundings), @@ -1122,7 +1122,7 @@ fn report_shadowing<'b>( ShadowKind::Ability => "abilities", }; - alloc.stack(vec![ + alloc.stack([ alloc .text("The ") .append(alloc.ident(shadow.value)) @@ -1217,7 +1217,7 @@ fn pretty_runtime_error<'b>( ), }; - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc.concat([ alloc.reflow("This"), alloc.text(name), @@ -1251,12 +1251,12 @@ fn pretty_runtime_error<'b>( let qualified_suggestions = suggestions .into_iter() .map(|v| alloc.string(module_name.to_string() + "." + v.as_str())); - alloc.stack(vec![ + alloc.stack([ alloc.reflow("Did you mean one of these?"), alloc.vcat(qualified_suggestions).indent(4), ]) }; - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc.concat([ alloc.reflow("The "), alloc.module_name(module_name), @@ -1298,7 +1298,7 @@ fn pretty_runtime_error<'b>( title = SYNTAX_PROBLEM; } RuntimeError::MalformedTypeName(_box_str, surroundings) => { - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc.reflow(r"I am confused by this type name:"), alloc.region(lines.convert_region(surroundings)), alloc.concat([ @@ -1328,7 +1328,7 @@ fn pretty_runtime_error<'b>( "small" }; - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc.concat([ alloc.reflow("This float literal is too "), alloc.text(big_or_small), @@ -1352,7 +1352,7 @@ fn pretty_runtime_error<'b>( .tip() .append(alloc.reflow("Learn more about number literals at TODO")); - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc.concat([ alloc.reflow("This float literal contains an invalid digit:"), ]), @@ -1366,7 +1366,7 @@ fn pretty_runtime_error<'b>( title = SYNTAX_PROBLEM; } RuntimeError::InvalidFloat(FloatErrorKind::IntSuffix, region, _raw_str) => { - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc .concat([alloc .reflow("This number literal is a float, but it has an integer suffix:")]), @@ -1416,7 +1416,7 @@ fn pretty_runtime_error<'b>( .tip() .append(alloc.reflow("Learn more about number literals at TODO")); - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc.concat([ alloc.reflow("This "), alloc.text(name), @@ -1466,7 +1466,7 @@ fn pretty_runtime_error<'b>( .tip() .append(alloc.reflow("Learn more about number literals at TODO")); - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc.concat([ alloc.reflow("This integer literal is too "), alloc.text(big_or_small), @@ -1480,7 +1480,7 @@ fn pretty_runtime_error<'b>( title = SYNTAX_PROBLEM; } RuntimeError::InvalidInt(IntErrorKind::FloatSuffix, _base, region, _raw_str) => { - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc .concat([alloc .reflow("This number literal is an integer, but it has a float suffix:")]), @@ -1498,7 +1498,7 @@ fn pretty_runtime_error<'b>( region, _raw_str, ) => { - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc.concat([alloc .reflow("This integer literal overflows the type indicated by its suffix:")]), alloc.region(lines.convert_region(region)), @@ -1522,7 +1522,7 @@ fn pretty_runtime_error<'b>( region, _raw_str, ) => { - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc.concat([alloc .reflow("This integer literal underflows the type indicated by its suffix:")]), alloc.region(lines.convert_region(region)), @@ -1553,7 +1553,7 @@ fn pretty_runtime_error<'b>( title = SYNTAX_PROBLEM; } RuntimeError::InvalidRecordUpdate { region } => { - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc.concat([ alloc.reflow("This expression cannot be updated"), alloc.reflow(":"), @@ -1589,13 +1589,11 @@ fn pretty_runtime_error<'b>( unreachable!("not currently reported (but can blow up at runtime)") } RuntimeError::ExposedButNotDefined(symbol) => { - doc = alloc.stack(vec![alloc + doc = alloc.stack([alloc .symbol_unqualified(symbol) .append(alloc.reflow(" was listed as exposed in ")) .append(alloc.module(symbol.module_id())) - .append( - alloc.reflow(", but it was not defined anywhere in that module."), - )]); + .append(alloc.reflow(", but it was not defined anywhere in that module."))]); title = MISSING_DEFINITION; } @@ -1604,7 +1602,7 @@ fn pretty_runtime_error<'b>( .tip() .append(alloc.reflow("Learn more about character literals at TODO")); - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc.concat([alloc.reflow("This character literal is empty.")]), alloc.region(lines.convert_region(region)), tip, @@ -1617,7 +1615,7 @@ fn pretty_runtime_error<'b>( .tip() .append(alloc.reflow("Learn more about character literals at TODO")); - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc.concat([ alloc.reflow("This character literal contains more than one code point.") ]), @@ -1648,7 +1646,7 @@ fn pretty_runtime_error<'b>( } else { let qualified_suggestions = suggestions.into_iter().map(|v| alloc.string(v.to_string())); - alloc.stack(vec![ + alloc.stack([ alloc .tip() .append(alloc.reflow("Did you mean one of these opaque types?")), @@ -1666,7 +1664,7 @@ fn pretty_runtime_error<'b>( ]; if let Some(defined_alias_region) = opt_defined_alias { - stack.push(alloc.stack(vec![ + stack.push(alloc.stack([ alloc.note("There is an alias of the same name:"), alloc.region(lines.convert_region(defined_alias_region)), ])); @@ -1683,7 +1681,7 @@ fn pretty_runtime_error<'b>( referenced_region, imported_region, } => { - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc.concat([ alloc.reflow("The unwrapped opaque type "), alloc.type_str(opaque.as_inline_str().as_str()), @@ -1700,7 +1698,7 @@ fn pretty_runtime_error<'b>( title = OPAQUE_DECLARED_OUTSIDE_SCOPE; } RuntimeError::OpaqueNotApplied(loc_ident) => { - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc.reflow("This opaque type is not applied to an argument:"), alloc.region(lines.convert_region(loc_ident.region)), alloc.note("Opaque types always wrap exactly one argument!"), @@ -1709,7 +1707,7 @@ fn pretty_runtime_error<'b>( title = OPAQUE_NOT_APPLIED; } RuntimeError::OpaqueAppliedToMultipleArgs(region) => { - doc = alloc.stack(vec![ + doc = alloc.stack([ alloc.reflow("This opaque type is applied to multiple arguments:"), alloc.region(lines.convert_region(region)), alloc.note("Opaque types always wrap exactly one argument!"), @@ -1738,7 +1736,7 @@ fn to_circular_def_doc<'b>( " value is defined directly in terms of itself, causing an infinite loop.", )), [first, others @ ..] => { - alloc.stack(vec![ + alloc.stack([ alloc .reflow("The ") .append(alloc.symbol_unqualified(first.symbol)) @@ -1793,7 +1791,7 @@ fn not_found<'b>( if suggestions.is_empty() { no_suggestion_details } else { - alloc.stack(vec![ + alloc.stack([ yes_suggestion_details, alloc .vcat(suggestions.into_iter().map(|v| alloc.string(v.to_string()))) @@ -1802,7 +1800,7 @@ fn not_found<'b>( } }; - alloc.stack(vec![ + alloc.stack([ alloc.concat([ alloc.reflow("I cannot find a `"), alloc.string(name.to_string()), @@ -1845,7 +1843,7 @@ fn module_not_found<'b>( alloc.reflow(" missing up-top"), ]) } else { - alloc.stack(vec![ + alloc.stack([ alloc.reflow("Is there an import missing? Perhaps there is a typo. Did you mean one of these?"), alloc .vcat(suggestions.into_iter().map(|v| alloc.string(v.to_string()))) @@ -1854,7 +1852,7 @@ fn module_not_found<'b>( } }; - alloc.stack(vec![ + alloc.stack([ alloc.concat([ alloc.reflow("The `"), alloc.string(name.to_string()), diff --git a/reporting/src/error/mono.rs b/reporting/src/error/mono.rs index 691e9b31cc..7ca6608c7d 100644 --- a/reporting/src/error/mono.rs +++ b/reporting/src/error/mono.rs @@ -17,7 +17,7 @@ pub fn mono_problem<'b>( match problem { PatternProblem(Incomplete(region, context, missing)) => match context { BadArg => { - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow("This pattern does not cover all the possibilities:"), alloc.region(lines.convert_region(region)), alloc.reflow("Other possibilities include:"), @@ -40,7 +40,7 @@ pub fn mono_problem<'b>( } } BadDestruct => { - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow("This pattern does not cover all the possibilities:"), alloc.region(lines.convert_region(region)), alloc.reflow("Other possibilities include:"), @@ -64,7 +64,7 @@ pub fn mono_problem<'b>( } } BadCase => { - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.concat([ alloc.reflow("This "), alloc.keyword("when"), @@ -93,7 +93,7 @@ pub fn mono_problem<'b>( branch_region, index, }) => { - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.concat([ alloc.reflow("The "), alloc.string(index.ordinal()), diff --git a/reporting/src/error/parse.rs b/reporting/src/error/parse.rs index 63581bff7a..c46a03aea1 100644 --- a/reporting/src/error/parse.rs +++ b/reporting/src/error/parse.rs @@ -74,7 +74,7 @@ fn to_syntax_report<'a>( match parse_problem { SyntaxError::ArgumentsBeforeEquals(region) => { - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow("Unexpected tokens in front of the `=` symbol:"), alloc.region(lines.convert_region(*region)), ]); @@ -92,7 +92,7 @@ fn to_syntax_report<'a>( region = LineColumnRegion::new(region.start(), region.end().bump_column(1)); } - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.concat([ alloc.reflow("Unexpected token "), // context(alloc, &parse_problem.context_stack, "here"), @@ -106,7 +106,7 @@ fn to_syntax_report<'a>( NotEndOfFile(pos) => { let region = LineColumnRegion::from_pos(lines.convert_pos(*pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I expected to reach the end of the file, but got stuck here:"), alloc.region(region), ]); @@ -119,7 +119,7 @@ fn to_syntax_report<'a>( } } SyntaxError::Eof(region) => { - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow("End of Field"), alloc.region(lines.convert_region(*region)), ]); @@ -132,7 +132,7 @@ fn to_syntax_report<'a>( } } SyntaxError::OutdentedTooFar => { - let doc = alloc.stack(vec![alloc.reflow("OutdentedTooFar")]); + let doc = alloc.stack([alloc.reflow("OutdentedTooFar")]); Report { filename, @@ -202,7 +202,7 @@ fn to_expr_report<'a>( let surroundings = Region::new(start, *pos); let region = lines.convert_region(*region); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I am partway through parsing a definition, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -240,7 +240,7 @@ fn to_expr_report<'a>( alloc.parser_suggestion("Str.concat"), alloc.reflow(" instead."), ], - ":" => vec![alloc.stack(vec![ + ":" => vec![alloc.stack([ alloc.concat([ alloc.reflow("The has-type operator "), alloc.parser_suggestion(":"), @@ -258,7 +258,7 @@ fn to_expr_report<'a>( return to_unexpected_arrow_report(alloc, lines, filename, *pos, start); } _ => { - vec![alloc.stack(vec![ + vec![alloc.stack([ alloc.concat([ alloc.reflow("The arrow "), alloc.parser_suggestion("->"), @@ -291,7 +291,7 @@ fn to_expr_report<'a>( ], }; - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"This looks like an operator, but it's not one I recognize!"), alloc.region_with_subregion( lines.convert_region(surroundings), @@ -314,7 +314,7 @@ fn to_expr_report<'a>( let surroundings = Region::new(start, *pos); let region = LineColumnRegion::from_pos(lines.convert_pos(*pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I am very confused by this identifier:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -348,7 +348,7 @@ fn to_expr_report<'a>( ), Context::InDefFinalExpr { .. } => ( "MISSING FINAL EXPRESSION", - alloc.stack(vec![ + alloc.stack([ alloc.concat([ alloc.reflow("This definition is missing a final expression."), alloc.reflow(" A nested definition must be followed by"), @@ -396,7 +396,7 @@ fn to_expr_report<'a>( let surroundings = Region::new(context_pos, *pos); let region = LineColumnRegion::from_pos(lines.convert_pos(*pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.concat([ alloc.reflow(r"I am partway through parsing "), a_thing, @@ -418,7 +418,7 @@ fn to_expr_report<'a>( let surroundings = Region::new(start, *pos); let region = LineColumnRegion::from_pos(lines.convert_pos(*pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I am partway through parsing a definition, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -455,7 +455,7 @@ fn to_expr_report<'a>( let surroundings = Region::new(start, *pos); let region = LineColumnRegion::from_pos(lines.convert_pos(*pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -477,7 +477,7 @@ fn to_expr_report<'a>( let surroundings = Region::new(start, *pos); let region = LineColumnRegion::from_pos(lines.convert_pos(*pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I am partway through parsing a definition, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -500,7 +500,7 @@ fn to_expr_report<'a>( let surroundings = Region::new(start, *pos); let region = LineColumnRegion::from_pos(lines.convert_pos(*pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I am partway through parsing an expression, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([alloc.reflow("Looks like you are trying to define a function. ")]), @@ -518,7 +518,7 @@ fn to_expr_report<'a>( let surroundings = Region::new(start, *pos); let region = LineColumnRegion::from_pos(lines.convert_pos(*pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I am partway through parsing an record, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([alloc.reflow("TODO provide more context.")]), @@ -560,7 +560,7 @@ fn to_lambda_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc .reflow(r"I am partway through parsing a function argument list, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), @@ -582,7 +582,7 @@ fn to_lambda_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc .reflow(r"I am partway through parsing a function argument list, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), @@ -607,7 +607,7 @@ fn to_lambda_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc .reflow(r"I am partway through parsing a function argument list, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), @@ -629,7 +629,7 @@ fn to_lambda_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc .reflow(r"I am partway through parsing a function argument list, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), @@ -654,7 +654,7 @@ fn to_lambda_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc .reflow(r"I am partway through parsing a function argument list, but I got stuck at this comma:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), @@ -675,7 +675,7 @@ fn to_lambda_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc .reflow(r"I am partway through parsing a function argument list, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), @@ -757,7 +757,7 @@ fn to_unfinished_lambda_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.concat([ alloc.reflow(r"I was partway through parsing a "), alloc.reflow(r" function, but I got stuck here:"), @@ -806,7 +806,7 @@ fn to_str_report<'a>( .append(alloc.parser_suggestion(sugg)) }; - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.concat([ alloc.reflow(r"I was partway through parsing a "), alloc.reflow(r" string literal, but I got stuck here:"), @@ -843,7 +843,7 @@ fn to_str_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow( r"I am partway through parsing a unicode code point, but I got stuck here:", ), @@ -869,7 +869,7 @@ fn to_str_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I cannot find the end of this format expression:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -890,7 +890,7 @@ fn to_str_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I cannot find the end of this string:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -913,7 +913,7 @@ fn to_str_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I cannot find the end of this block string:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -958,7 +958,7 @@ fn to_expr_in_parens_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc .reflow("I am partway through parsing a record pattern, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), @@ -982,7 +982,7 @@ fn to_expr_in_parens_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow( r"I just started parsing an expression in parentheses, but I got stuck here:", ), @@ -1034,7 +1034,7 @@ fn to_list_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow( r"I am partway through started parsing a list, but I got stuck here:", ), @@ -1057,7 +1057,7 @@ fn to_list_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow( r"I am partway through started parsing a list, but I got stuck here:", ), @@ -1093,7 +1093,7 @@ fn to_list_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I cannot find the end of this list:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -1212,7 +1212,7 @@ fn to_unfinished_if_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.concat([ alloc.reflow(r"I was partway through parsing an "), alloc.keyword("if"), @@ -1247,7 +1247,7 @@ fn to_when_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow( r"I just started parsing an if guard, but there is no guard condition:", ), @@ -1276,7 +1276,7 @@ fn to_when_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.concat([ alloc.reflow(r"I am partway through parsing a "), alloc.keyword("when"), @@ -1431,7 +1431,7 @@ fn to_unfinished_when_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.concat([ alloc.reflow(r"I was partway through parsing a "), alloc.keyword("when"), @@ -1462,7 +1462,7 @@ fn to_unexpected_arrow_report<'a>( let surroundings = Region::new(start, pos); let region = Region::new(pos, pos.bump_column(2)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.concat([ alloc.reflow(r"I am parsing a "), alloc.keyword("when"), @@ -1491,7 +1491,7 @@ fn to_unexpected_arrow_report<'a>( } fn note_for_when_error<'a>(alloc: &'a RocDocAllocator<'a>) -> RocDocBuilder<'a> { - alloc.stack(vec![ + alloc.stack([ alloc.concat([ alloc.note("Here is an example of a valid "), alloc.keyword("when"), @@ -1515,7 +1515,7 @@ fn note_for_when_error<'a>(alloc: &'a RocDocAllocator<'a>) -> RocDocBuilder<'a> } fn note_for_when_indent_error<'a>(alloc: &'a RocDocAllocator<'a>) -> RocDocBuilder<'a> { - alloc.stack(vec![ + alloc.stack([ alloc.concat([ alloc.note("Sometimes I get confused by indentation, so try to make your "), alloc.keyword("when"), @@ -1552,7 +1552,7 @@ fn to_pattern_report<'a>( let surroundings = Region::new(start, *pos); let region = LineColumnRegion::from_pos(lines.convert_pos(*pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I just started parsing a pattern, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.note("I may be confused by indentation"), @@ -1591,7 +1591,7 @@ fn to_precord_report<'a>( let surroundings = Region::new(start, pos); let region = to_keyword_region(lines.convert_pos(pos), keyword); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I just started parsing a record pattern, but I got stuck on this field name:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -1612,7 +1612,7 @@ fn to_precord_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I just started parsing a record pattern, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), record_patterns_look_like(alloc), @@ -1633,7 +1633,7 @@ fn to_precord_report<'a>( match what_is_next(alloc.src_lines, lines.convert_pos(pos)) { Next::Other(Some(c)) if c.is_alphabetic() => { - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I am partway through parsing a record pattern, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -1651,7 +1651,7 @@ fn to_precord_report<'a>( } } _ => { - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow("I am partway through parsing a record pattern, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -1678,7 +1678,7 @@ fn to_precord_report<'a>( let surroundings = Region::new(start, pos); let region = to_keyword_region(lines.convert_pos(pos), keyword); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I just started parsing a record pattern, but I got stuck on this field name:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -1701,7 +1701,7 @@ fn to_precord_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I am partway through parsing a record pattern, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -1748,7 +1748,7 @@ fn to_precord_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I just started parsing a record pattern, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), record_patterns_look_like(alloc), @@ -1769,7 +1769,7 @@ fn to_precord_report<'a>( let surroundings = LineColumnRegion::new(lines.convert_pos(start), curly_pos); let region = LineColumnRegion::from_pos(curly_pos); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow( "I am partway through parsing a record pattern, but I got stuck here:", ), @@ -1790,7 +1790,7 @@ fn to_precord_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow( r"I am partway through parsing a record pattern, but I got stuck here:", ), @@ -1841,7 +1841,7 @@ fn to_pattern_in_parens_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow( r"I just started parsing a pattern in parentheses, but I got stuck here:", ), @@ -1867,7 +1867,7 @@ fn to_pattern_in_parens_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow("I am partway through parsing a pattern in parentheses, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -1893,7 +1893,7 @@ fn to_pattern_in_parens_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow( r"I just started parsing a pattern in parentheses, but I got stuck here:", ), @@ -1916,7 +1916,7 @@ fn to_pattern_in_parens_report<'a>( let surroundings = LineColumnRegion::new(lines.convert_pos(start), curly_pos); let region = LineColumnRegion::from_pos(curly_pos); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow( "I am partway through parsing a pattern in parentheses, but I got stuck here:", ), @@ -1937,7 +1937,7 @@ fn to_pattern_in_parens_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow( r"I am partway through parsing a pattern in parentheses, but I got stuck here:", ), @@ -1974,7 +1974,7 @@ fn to_malformed_number_literal_report<'a>( let surroundings = Region::new(start, start); let region = LineColumnRegion::from_pos(lines.convert_pos(start)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"This number literal is malformed:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), ]); @@ -2013,7 +2013,7 @@ fn to_type_report<'a>( let surroundings = Region::new(start, *pos); let region = LineColumnRegion::from_pos(lines.convert_pos(*pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I just started parsing a function argument type, but I encountered two commas in a row:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([alloc.reflow("Try removing one of them.")]), @@ -2034,7 +2034,7 @@ fn to_type_report<'a>( let surroundings = Region::new(start, *pos); let region = LineColumnRegion::from_pos(lines.convert_pos(*pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I just started parsing a type, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -2058,7 +2058,7 @@ fn to_type_report<'a>( let surroundings = Region::new(start, *pos); let region = LineColumnRegion::from_pos(lines.convert_pos(*pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I just started parsing a type, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.note("I may be confused by indentation"), @@ -2076,7 +2076,7 @@ fn to_type_report<'a>( let surroundings = Region::new(start, *pos); let region = LineColumnRegion::from_pos(lines.convert_pos(*pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I am partway through parsing a type, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.note("I may be confused by indentation"), @@ -2094,7 +2094,7 @@ fn to_type_report<'a>( let surroundings = Region::new(start, *pos); let region = LineColumnRegion::from_pos(lines.convert_pos(*pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I just started parsing an inline type alias, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.note("I may be confused by indentation"), @@ -2112,7 +2112,7 @@ fn to_type_report<'a>( let surroundings = Region::new(start, *pos); let region = LineColumnRegion::from_pos(lines.convert_pos(*pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I am expecting a type variable, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), ]); @@ -2144,7 +2144,7 @@ fn to_trecord_report<'a>( let surroundings = Region::new(start, pos); let region = to_keyword_region(lines.convert_pos(pos), keyword); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I just started parsing a record type, but I got stuck on this field name:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -2165,7 +2165,7 @@ fn to_trecord_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I just started parsing a record type, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -2190,7 +2190,7 @@ fn to_trecord_report<'a>( match what_is_next(alloc.src_lines, lines.convert_pos(pos)) { Next::Other(Some(c)) if c.is_alphabetic() => { - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I am partway through parsing a record type, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -2208,7 +2208,7 @@ fn to_trecord_report<'a>( } } _ => { - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow("I am partway through parsing a record type, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -2235,7 +2235,7 @@ fn to_trecord_report<'a>( let surroundings = Region::new(start, pos); let region = to_keyword_region(lines.convert_pos(pos), keyword); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I just started parsing a record type, but I got stuck on this field name:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -2258,7 +2258,7 @@ fn to_trecord_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I am partway through parsing a record type, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -2292,7 +2292,7 @@ fn to_trecord_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I just started parsing a record type, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -2317,7 +2317,7 @@ fn to_trecord_report<'a>( let surroundings = LineColumnRegion::new(lines.convert_pos(start), curly_pos); let region = LineColumnRegion::from_pos(curly_pos); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow( "I am partway through parsing a record type, but I got stuck here:", ), @@ -2338,7 +2338,7 @@ fn to_trecord_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow( r"I am partway through parsing a record type, but I got stuck here:", ), @@ -2389,7 +2389,7 @@ fn to_ttag_union_report<'a>( let surroundings = Region::new(start, pos); let region = to_keyword_region(lines.convert_pos(pos), keyword); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I just started parsing a tag union, but I got stuck on this field name:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -2412,7 +2412,7 @@ fn to_ttag_union_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow( r"I am partway through parsing a tag union type, but I got stuck here:", ), @@ -2432,7 +2432,7 @@ fn to_ttag_union_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I just started parsing a tag union type, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -2459,7 +2459,7 @@ fn to_ttag_union_report<'a>( Next::Other(Some(c)) if c.is_alphabetic() => { debug_assert!(c.is_lowercase()); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow( r"I am partway through parsing a tag union type, but I got stuck here:", ), @@ -2476,7 +2476,7 @@ fn to_ttag_union_report<'a>( } } Next::Other(Some('@')) => { - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow( r"I am partway through parsing a tag union type, but I got stuck here:", ), @@ -2493,7 +2493,7 @@ fn to_ttag_union_report<'a>( } } _ => { - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I am partway through parsing a tag union type, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -2521,7 +2521,7 @@ fn to_ttag_union_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I just started parsing a tag union type, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -2549,7 +2549,7 @@ fn to_ttag_union_report<'a>( let surroundings = LineColumnRegion::new(lines.convert_pos(start), curly_pos); let region = LineColumnRegion::from_pos(curly_pos); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow( "I am partway through parsing a tag union type, but I got stuck here:", ), @@ -2570,7 +2570,7 @@ fn to_ttag_union_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow( r"I am partway through parsing a tag union type, but I got stuck here:", ), @@ -2614,7 +2614,7 @@ fn to_tinparens_report<'a>( let surroundings = Region::new(start, pos); let region = to_keyword_region(lines.convert_pos(pos), keyword); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I just saw an open parenthesis, so I was expecting to see a type next."), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -2638,7 +2638,7 @@ fn to_tinparens_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow( r"I am partway through parsing a type in parentheses, but I got stuck here:", ), @@ -2658,7 +2658,7 @@ fn to_tinparens_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow( r"I just started parsing a type in parentheses, but I got stuck here:", ), @@ -2689,7 +2689,7 @@ fn to_tinparens_report<'a>( debug_assert!(c.is_lowercase()); // TODO hint for tuples? - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow( r"I am partway through parsing a type in parentheses, but I got stuck here:", ), @@ -2706,7 +2706,7 @@ fn to_tinparens_report<'a>( } } _ => { - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I am partway through parsing a type in parentheses, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -2734,7 +2734,7 @@ fn to_tinparens_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc .reflow(r"I just started parsing a type in parentheses, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), @@ -2760,7 +2760,7 @@ fn to_tinparens_report<'a>( let surroundings = LineColumnRegion::new(lines.convert_pos(start), curly_pos); let region = LineColumnRegion::from_pos(curly_pos); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow( "I am partway through parsing a type in parentheses, but I got stuck here:", ), @@ -2781,7 +2781,7 @@ fn to_tinparens_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow( r"I am partway through parsing a type in parentheses, but I got stuck here:", ), @@ -2822,7 +2822,7 @@ fn to_tapply_report<'a>( ETypeApply::DoubleDot(pos) => { let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I encountered two dots in a row:"), alloc.region(region), alloc.concat([alloc.reflow("Try removing one of them.")]), @@ -2838,7 +2838,7 @@ fn to_tapply_report<'a>( ETypeApply::TrailingDot(pos) => { let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I encountered a dot with nothing after it:"), alloc.region(region), alloc.concat([ @@ -2860,7 +2860,7 @@ fn to_tapply_report<'a>( ETypeApply::StartIsNumber(pos) => { let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I encountered a number at the start of a qualified name segment:"), alloc.region(region), alloc.concat([ @@ -2882,7 +2882,7 @@ fn to_tapply_report<'a>( ETypeApply::StartNotUppercase(pos) => { let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I encountered a lowercase letter at the start of a qualified name segment:"), alloc.region(region), alloc.concat([ @@ -2905,7 +2905,7 @@ fn to_tapply_report<'a>( ETypeApply::End(pos) => { let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow( r"I reached the end of the input file while parsing a qualified type name", ), @@ -2936,7 +2936,7 @@ fn to_talias_report<'a>( ETypeInlineAlias::NotAnAlias(pos) => { let region = Region::from_pos(pos); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.concat([ alloc.reflow("The inline type after this "), alloc.keyword("as"), @@ -2962,7 +2962,7 @@ fn to_talias_report<'a>( ETypeInlineAlias::Qualified(pos) => { let region = Region::from_pos(pos); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"This type alias has a qualified name:"), alloc.region(lines.convert_region(region)), alloc.reflow("An alias introduces a new name to the current scope, so it must be unqualified."), @@ -2978,7 +2978,7 @@ fn to_talias_report<'a>( ETypeInlineAlias::ArgumentNotLowercase(pos) => { let region = Region::from_pos(pos); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"This alias type argument is not lowercase:"), alloc.region(lines.convert_region(region)), alloc.reflow("All type arguments must be lowercase."), @@ -3024,7 +3024,7 @@ fn to_header_report<'a>( let surroundings = Region::new(start, *pos); let region = LineColumnRegion::from_pos(lines.convert_pos(*pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I am partway through parsing a header, but got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([alloc.reflow("I may be confused by indentation.")]), @@ -3042,7 +3042,7 @@ fn to_header_report<'a>( let surroundings = Region::new(start, *pos); let region = LineColumnRegion::from_pos(lines.convert_pos(*pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I am expecting a header, but got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -3068,7 +3068,7 @@ fn to_header_report<'a>( let surroundings = Region::new(start, *pos); let region = LineColumnRegion::from_pos(lines.convert_pos(*pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I am partway through parsing a header, but got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -3092,7 +3092,7 @@ fn to_header_report<'a>( let surroundings = Region::new(start, *pos); let region = LineColumnRegion::from_pos(lines.convert_pos(*pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I am partway through parsing a header, but got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -3116,7 +3116,7 @@ fn to_header_report<'a>( let surroundings = Region::new(start, *pos); let region = LineColumnRegion::from_pos(lines.convert_pos(*pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I am partway through parsing a header, but got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -3139,7 +3139,7 @@ fn to_header_report<'a>( let surroundings = Region::new(start, *pos); let region = LineColumnRegion::from_pos(lines.convert_pos(*pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I am partway through parsing a header, but got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -3177,7 +3177,7 @@ fn to_generates_with_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc .reflow(r"I am partway through parsing a provides list, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), @@ -3201,7 +3201,7 @@ fn to_generates_with_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I am partway through parsing a header, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -3243,7 +3243,7 @@ fn to_provides_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc .reflow(r"I am partway through parsing a provides list, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), @@ -3267,7 +3267,7 @@ fn to_provides_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I am partway through parsing a header, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -3309,7 +3309,7 @@ fn to_exposes_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I am partway through parsing an `exposes` list, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([alloc.reflow( @@ -3332,7 +3332,7 @@ fn to_exposes_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I am partway through parsing a header, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -3373,7 +3373,7 @@ fn to_imports_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I am partway through parsing a imports list, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([alloc.reflow( @@ -3396,7 +3396,7 @@ fn to_imports_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I am partway through parsing a header, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -3423,7 +3423,7 @@ fn to_imports_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I am partway through parsing a header, but got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -3461,7 +3461,7 @@ fn to_requires_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I am partway through parsing a header, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -3488,7 +3488,7 @@ fn to_requires_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I am partway through parsing a header, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -3513,7 +3513,7 @@ fn to_requires_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I am partway through parsing a header, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -3542,7 +3542,7 @@ fn to_requires_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I am partway through parsing a header, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -3585,7 +3585,7 @@ fn to_packages_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I am partway through parsing a header, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), alloc.concat([ @@ -3623,7 +3623,7 @@ fn to_space_report<'a>( BadInputError::HasTab => { let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I encountered a tab character"), alloc.region(region), alloc.concat([alloc.reflow("Tab characters are not allowed.")]), @@ -3704,7 +3704,7 @@ fn to_unfinished_ability_report<'a>( let surroundings = Region::new(start, pos); let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.reflow(r"I was partway through parsing an ability definition, but I got stuck here:"), alloc.region_with_subregion(lines.convert_region(surroundings), region), message, diff --git a/reporting/src/error/type.rs b/reporting/src/error/type.rs index e7e06ccd03..89c25f55c6 100644 --- a/reporting/src/error/type.rs +++ b/reporting/src/error/type.rs @@ -79,7 +79,7 @@ pub fn type_problem<'b>( let found_arguments = alloc.text(type_got.to_string()); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.concat([ alloc.reflow("The "), alloc.symbol_unqualified(symbol), @@ -125,7 +125,7 @@ pub fn type_problem<'b>( report(title, doc, filename) } BadExprMissingAbility(region, category, found, incomplete) => { - let note = alloc.stack(vec![ + let note = alloc.stack([ alloc.reflow("The ways this expression is used requires that the following types implement the following abilities, which they do not:"), alloc.type_block(alloc.stack(incomplete.iter().map(|incomplete| { symbol_does_not_implement(alloc, incomplete.typ, incomplete.ability) @@ -159,7 +159,7 @@ pub fn type_problem<'b>( Some(report) } BadPatternMissingAbility(region, category, found, incomplete) => { - let note = alloc.stack(vec![ + let note = alloc.stack([ alloc.reflow("The ways this expression is used requires that the following types implement the following abilities, which they do not:"), alloc.type_block(alloc.stack(incomplete.iter().map(|incomplete| { symbol_does_not_implement(alloc, incomplete.typ, incomplete.ability) @@ -255,7 +255,7 @@ fn report_shadowing<'b>( ) -> RocDocBuilder<'b> { let line = r#"Since these types have the same name, it's easy to use the wrong one on accident. Give one of them a new name."#; - alloc.stack(vec![ + alloc.stack([ alloc .text("The ") .append(alloc.ident(shadow.value)) @@ -278,7 +278,7 @@ pub fn cyclic_alias<'b>( alloc.reflow("Recursion in aliases is only allowed if recursion happens behind a tagged union, at least one variant of which is not recursive."); let doc = if others.is_empty() { - alloc.stack(vec![ + alloc.stack([ alloc .reflow("The ") .append(alloc.symbol_unqualified(symbol)) @@ -287,7 +287,7 @@ pub fn cyclic_alias<'b>( when_is_recursion_legal, ]) } else { - alloc.stack(vec![ + alloc.stack([ alloc .reflow("The ") .append(alloc.symbol_unqualified(symbol)) @@ -477,7 +477,7 @@ fn to_expr_report<'b>( Report { filename, title: "TYPE MISMATCH".to_string(), - doc: alloc.stack(vec![ + doc: alloc.stack([ alloc.text("This expression is used in an unexpected way:"), alloc.region(lines.convert_region(expr_region)), comparison, @@ -586,7 +586,7 @@ fn to_expr_report<'b>( Report { title: "TYPE MISMATCH".to_string(), filename, - doc: alloc.stack(vec![ + doc: alloc.stack([ alloc.text("Something is off with the ").append(thing), { // for typed bodies, include the line(s) with the signature @@ -1080,7 +1080,7 @@ fn to_expr_report<'b>( stack.push(does_not_implement(alloc, err_type, ability)); } - let hint = alloc.stack(vec![ + let hint = alloc.stack([ alloc.concat([ alloc.note(""), alloc.reflow("Some types in this specialization don't implement the abilities they are expected to. I found the following missing implementations:"), @@ -1123,7 +1123,7 @@ fn to_expr_report<'b>( alloc.reflow(" says it must match:"), ]); - let note = alloc.stack(vec![ + let note = alloc.stack([ alloc.concat([ alloc.note(""), alloc.reflow("The specialized type is too general, and does not provide a concrete type where a type variable is bound to an ability."), @@ -1527,7 +1527,7 @@ fn to_pattern_report<'b>( match expected { PExpected::NoExpectation(expected_type) => { - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc.text("This pattern is being used in an unexpected way:"), alloc.region(lines.convert_region(expr_region)), pattern_type_comparison( @@ -1555,7 +1555,7 @@ fn to_pattern_report<'b>( Some(n) => alloc.symbol_unqualified(n), None => alloc.text(" this definition "), }; - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc .text("The ") .append(alloc.text(index.ordinal())) @@ -1592,7 +1592,7 @@ fn to_pattern_report<'b>( } PReason::WhenMatch { index } => { if index == HumanIndex::FIRST { - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc .text("The 1st pattern in this ") .append(alloc.keyword("when")) @@ -1625,7 +1625,7 @@ fn to_pattern_report<'b>( severity: Severity::RuntimeError, } } else { - let doc = alloc.stack(vec![ + let doc = alloc.stack([ alloc .string(format!("The {} pattern in this ", index.ordinal())) .append(alloc.keyword("when")) @@ -1735,13 +1735,13 @@ fn to_circular_report<'b>( title: "CIRCULAR TYPE".to_string(), filename, doc: { - alloc.stack(vec![ + alloc.stack([ alloc .reflow("I'm inferring a weird self-referential type for ") .append(alloc.symbol_unqualified(symbol)) .append(alloc.text(":")), alloc.region(lines.convert_region(region)), - alloc.stack(vec![ + alloc.stack([ alloc.reflow( "Here is my best effort at writing down the type. \ You will see ∞ for parts of the type that repeat \ @@ -3226,7 +3226,7 @@ fn type_problem_to_pretty<'b>( Can you use an open tag union?", )); - alloc.stack(vec![tip1, tip2]) + alloc.stack([tip1, tip2]) } Some((last, init)) => { @@ -3249,7 +3249,7 @@ fn type_problem_to_pretty<'b>( Can you use an open tag union?", )); - alloc.stack(vec![tip1, tip2]) + alloc.stack([tip1, tip2]) } }, (OptionalRequiredMismatch(field), _) => alloc.tip().append(alloc.concat([ @@ -3309,7 +3309,7 @@ fn report_record_field_typo<'b>( actual_fields.into_iter().collect::>(), ); - let doc = alloc.stack(vec![ + let doc = alloc.stack([ header, alloc.region(lines.convert_region(field_region)), if suggestions.is_empty() { @@ -3330,7 +3330,7 @@ fn report_record_field_typo<'b>( None => alloc.text("fields on the record"), }; - alloc.stack(vec![ + alloc.stack([ alloc.concat([ alloc.reflow("There may be a typo. These "), r_doc, diff --git a/reporting/src/report.rs b/reporting/src/report.rs index 29cfe43c09..a97537e18c 100644 --- a/reporting/src/report.rs +++ b/reporting/src/report.rs @@ -135,10 +135,7 @@ impl<'b> Report<'b> { "─".repeat(80 - (self.title.len() + 4)) ); - alloc.stack(vec![ - alloc.text(header).annotate(Annotation::Header), - self.doc, - ]) + alloc.stack([alloc.text(header).annotate(Annotation::Header), self.doc]) } } From fdb378f8598cb745be2d884c99593adf4f7393e9 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Tue, 19 Apr 2022 20:49:30 -0400 Subject: [PATCH 338/846] Drop extraneous space before newline --- reporting/src/error/parse.rs | 14 +++++++------- reporting/tests/test_reporting.rs | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/reporting/src/error/parse.rs b/reporting/src/error/parse.rs index c46a03aea1..b03c5d0826 100644 --- a/reporting/src/error/parse.rs +++ b/reporting/src/error/parse.rs @@ -3207,7 +3207,7 @@ fn to_generates_with_report<'a>( alloc.concat([ alloc.reflow("I am expecting the "), alloc.keyword("with"), - alloc.reflow(" keyword next, like "), + alloc.reflow(" keyword next, like"), ]), alloc .parser_suggestion("with [ after, map ]") @@ -3273,7 +3273,7 @@ fn to_provides_report<'a>( alloc.concat([ alloc.reflow("I am expecting the "), alloc.keyword("provides"), - alloc.reflow(" keyword next, like "), + alloc.reflow(" keyword next, like"), ]), alloc .parser_suggestion("provides [ Animal, default, tame ]") @@ -3338,7 +3338,7 @@ fn to_exposes_report<'a>( alloc.concat([ alloc.reflow("I am expecting the "), alloc.keyword("exposes"), - alloc.reflow(" keyword next, like "), + alloc.reflow(" keyword next, like"), ]), alloc .parser_suggestion("exposes [ Animal, default, tame ]") @@ -3402,7 +3402,7 @@ fn to_imports_report<'a>( alloc.concat([ alloc.reflow("I am expecting the "), alloc.keyword("imports"), - alloc.reflow(" keyword next, like "), + alloc.reflow(" keyword next, like"), ]), alloc .parser_suggestion("imports [ Animal, default, tame ]") @@ -3467,7 +3467,7 @@ fn to_requires_report<'a>( alloc.concat([ alloc.reflow("I am expecting the "), alloc.keyword("requires"), - alloc.reflow(" keyword next, like "), + alloc.reflow(" keyword next, like"), ]), alloc .parser_suggestion("requires { main : Task I64 Str }") @@ -3494,7 +3494,7 @@ fn to_requires_report<'a>( alloc.concat([ alloc.reflow("I am expecting the "), alloc.keyword("requires"), - alloc.reflow(" keyword next, like "), + alloc.reflow(" keyword next, like"), ]), alloc .parser_suggestion("requires { main : Task I64 Str }") @@ -3591,7 +3591,7 @@ fn to_packages_report<'a>( alloc.concat([ alloc.reflow("I am expecting the "), alloc.keyword("packages"), - alloc.reflow(" keyword next, like "), + alloc.reflow(" keyword next, like"), ]), alloc.parser_suggestion("packages {}").indent(4), ]); diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 30f9c4bc1e..5c00c48c90 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -6393,7 +6393,7 @@ I need all branches in an `if` to have the same type! 2│ exposes [ main, Foo ] ^ - I am expecting the `imports` keyword next, like + I am expecting the `imports` keyword next, like imports [ Animal, default, tame ] "# From 55621210061e91857f57484f01c4aa8a648a3bea Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Tue, 19 Apr 2022 20:49:42 -0400 Subject: [PATCH 339/846] Use ':' and '.' contextually in error messages e.g. record update errors complain about 'foo:' being wrong, whereas record access errors complain about '.foo' being wrong. --- reporting/src/error/type.rs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/reporting/src/error/type.rs b/reporting/src/error/type.rs index 89c25f55c6..cf95e383cb 100644 --- a/reporting/src/error/type.rs +++ b/reporting/src/error/type.rs @@ -455,7 +455,9 @@ fn to_expr_report<'b>( lines, filename, opt_sym, + ".", field, + "", expr_region, found_fields, found_ext, @@ -888,7 +890,9 @@ fn to_expr_report<'b>( lines, filename, Some(symbol), + "", field, + ":", *field_region, actual_fields, ext, @@ -3280,16 +3284,18 @@ fn report_record_field_typo<'b>( lines: &LineInfo, filename: PathBuf, opt_sym: Option, + field_prefix: &str, field: &Lowercase, + field_suffix: &str, field_region: Region, actual_fields: SendMap>, ext: TypeExt, ) -> Report<'b> { - let f_doc = alloc - .text(field.as_str().to_string()) - .annotate(Annotation::Typo); - let header = { + let f_doc = alloc + .text(field.as_str().to_string()) + .annotate(Annotation::Typo); + let r_doc = match opt_sym { Some(symbol) => alloc.symbol_unqualified(symbol).append(" "), None => alloc.text(""), @@ -3299,7 +3305,7 @@ fn report_record_field_typo<'b>( alloc.reflow("This "), r_doc, alloc.reflow("record doesn’t have a "), - f_doc.clone(), + f_doc, alloc.reflow(" field:"), ]) }; @@ -3325,6 +3331,10 @@ fn report_record_field_typo<'b>( } else { let f = suggestions.remove(0); let fs = suggestions; + let f_doc = alloc + .text(format!("{}{}{}", field_prefix, field, field_suffix)) + .annotate(Annotation::Typo); + let r_doc = match opt_sym { Some(symbol) => alloc.symbol_unqualified(symbol).append(" fields"), None => alloc.text("fields on the record"), @@ -3342,9 +3352,9 @@ fn report_record_field_typo<'b>( f_doc, alloc.reflow(" should be "), alloc - .text(f.0.as_str().to_string()) + .text(format!("{}{}{}", field_prefix, f.0, field_suffix)) .annotate(Annotation::TypoSuggestion), - alloc.reflow("?"), + alloc.reflow(" instead?"), ]), ]) }, From 85d30a541dd36071b029462b33625f316cb5b644 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Tue, 19 Apr 2022 20:50:27 -0400 Subject: [PATCH 340/846] Update reporting tests --- reporting/tests/test_reporting.rs | 53 ++++++++++++++----------------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 5c00c48c90..3566a36370 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -2379,12 +2379,12 @@ mod test_reporting { r#" ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── - The `x` record does not have a `.foo` field: + This `x` record doesn’t have a `foo` field: 3│ { x & foo: 3 } ^^^^^^ - In fact, `x` is a record with NO fields! + In fact, `x` is a record with no fields at all! "# ), ) @@ -2405,18 +2405,19 @@ mod test_reporting { r#" ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── - The `x` record does not have a `.foo` field: + This `x` record doesn’t have a `foo` field: 3│ { x & foo: 3 } ^^^^^^ - This is usually a typo. Here are the `x` fields that are most similar: + There may be a typo. These `x` fields are the most similar: - { fo : Num b - , bar : Num a + { + fo : Num b, + bar : Num a, } - So maybe `.foo` should be `.fo`? + Maybe `foo:` should be `fo:` instead? "# ), ) @@ -2441,17 +2442,18 @@ mod test_reporting { r#" ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── - The `r` record does not have a `.foo` field: + This `r` record doesn’t have a `foo` field: 3│ r2 = { r & foo: r.fo } ^^^^^^^^^ - This is usually a typo. Here are the `r` fields that are most similar: + There may be a typo. These `r` fields are the most similar: - { fo : I64 + { + fo : I64, }ext - So maybe `.foo` should be `.fo`? + Maybe `foo:` should be `fo:` instead? "# ), ) @@ -2472,21 +2474,22 @@ mod test_reporting { r#" ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── - The `x` record does not have a `.foo` field: + This `x` record doesn’t have a `foo` field: 3│ { x & foo: 3 } ^^^^^^ - This is usually a typo. Here are the `x` fields that are most similar: + There may be a typo. These `x` fields are the most similar: - { fo : Num c - , foobar : Num d - , bar : Num a - , baz : Num b - , ... + { + fo : Num c, + foobar : Num d, + bar : Num a, + baz : Num b, + … } - So maybe `.foo` should be `.fo`? + Maybe `foo:` should be `fo:` instead? "# ), ) @@ -5922,20 +5925,12 @@ I need all branches in an `if` to have the same type! r#" ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── - This expression is used in an unexpected way: + This `foo` record doesn’t have a `if` field: 3│ foo.if ^^^^^^ - This `foo` value is a: - - {} - - But you are trying to use it as: - - { if : a }b - - + In fact, `foo` is a record with no fields at all! "# ), ) From b35ff3add38dd84dbef3c5a5386d3fa7cbbe4bb9 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Tue, 19 Apr 2022 20:50:43 -0400 Subject: [PATCH 341/846] cargo fmt --- reporting/tests/test_reporting.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 3566a36370..b87fe6218f 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -8256,21 +8256,21 @@ I need all branches in an `if` to have the same type! indoc!( r#" ── CYCLIC ALIAS ──────────────────────────────────────────────────────────────── - + The `Foo` alias is recursive in an invalid way: - + 1│ Foo a : [ Thing (Bar a) ] ^^^ - + The `Foo` alias depends on itself through the following chain of definitions: - + ┌─────┐ │ Foo │ ↓ │ Bar └─────┘ - + Recursion in aliases is only allowed if recursion happens behind a tagged union, at least one variant of which is not recursive. "# @@ -8847,11 +8847,11 @@ I need all branches in an `if` to have the same type! indoc!( r#" Type : [ Constructor UnknownType ] - + insertHelper : UnknownType, Type -> Type insertHelper = \h, m -> when m is - Constructor _ -> Constructor h + Constructor _ -> Constructor h insertHelper "# From 0c96c0b66f8ce19cf64e80cd115d343cb72eeed6 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Tue, 19 Apr 2022 20:51:34 -0400 Subject: [PATCH 342/846] Professional basketball team Los Angeles Clippy --- reporting/src/error/type.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/reporting/src/error/type.rs b/reporting/src/error/type.rs index cf95e383cb..0351636408 100644 --- a/reporting/src/error/type.rs +++ b/reporting/src/error/type.rs @@ -3279,6 +3279,7 @@ fn type_problem_to_pretty<'b>( } } +#[allow(clippy::too_many_arguments)] fn report_record_field_typo<'b>( alloc: &'b RocDocAllocator<'b>, lines: &LineInfo, From d4d8f6d902c2d976504d541948a1d51bbc845fab Mon Sep 17 00:00:00 2001 From: ayazhafiz Date: Tue, 19 Apr 2022 21:21:11 -0400 Subject: [PATCH 343/846] Turn on concurrency groups for GitHub CI This ensures that we only one set of workflows is running for an active GH ref (usually a PR). Stale workflows will be term'd when a new one associated with the same PR is kicked off. See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#concurrency --- .github/workflows/benchmarks.yml | 4 ++++ .github/workflows/ci.yml | 4 ++++ .github/workflows/spellcheck.yml | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml index c5f2a8d123..dbc7005e80 100644 --- a/.github/workflows/benchmarks.yml +++ b/.github/workflows/benchmarks.yml @@ -2,6 +2,10 @@ on: [pull_request] name: Benchmarks +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + env: RUST_BACKTRACE: 1 ROC_NUM_WORKERS: 1 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 72bfdc7151..845a8e9425 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,6 +2,10 @@ on: [pull_request] name: CI +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + env: RUST_BACKTRACE: 1 diff --git a/.github/workflows/spellcheck.yml b/.github/workflows/spellcheck.yml index 0a44b6576e..0a1eee7af9 100644 --- a/.github/workflows/spellcheck.yml +++ b/.github/workflows/spellcheck.yml @@ -2,6 +2,10 @@ on: [pull_request] name: SpellCheck +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + env: RUST_BACKTRACE: 1 From 84727b31e567081ed25622d5517722f4f0049a0b Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 20 Apr 2022 08:23:44 -0400 Subject: [PATCH 344/846] Only support --target with `roc build` --- cli/src/lib.rs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 792071fbcd..6bb78f495a 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -231,18 +231,10 @@ pub fn build_app<'a>() -> App<'a> { .arg( Arg::new(FLAG_PRECOMPILED) .long(FLAG_PRECOMPILED) - .about("Assumes the host has been precompiled and skips recompiling the host. (Enabled by default when using a --target other than `--target host`)") + .about("Assumes the host has been precompiled and skips recompiling the host. (Enabled by default when using `roc build` with a --target other than `--target host`)") .possible_values(["true", "false"]) .required(false), ) - .arg( - Arg::new(FLAG_TARGET) - .long(FLAG_TARGET) - .about("Choose a different target") - .default_value(Target::default().as_str()) - .possible_values(Target::OPTIONS) - .required(false), - ) .arg( Arg::new(ROC_FILE) .about("The .roc file of an app to build and run") From 8b144c446dbe44bc8e40be0bb6d5840ad865e1d8 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 20 Apr 2022 16:30:20 +0200 Subject: [PATCH 345/846] remove PartialEq for a bunch of types that we should not compare --- ast/src/solve_type.rs | 2 +- compiler/can/src/annotation.rs | 8 +- compiler/can/src/constraint.rs | 8 +- compiler/can/src/def.rs | 10 +- compiler/can/src/expected.rs | 4 +- compiler/can/src/expr.rs | 14 +-- compiler/can/src/pattern.rs | 6 +- compiler/can/src/procedure.rs | 2 +- compiler/can/tests/can_inline.rs | 110 ---------------------- compiler/can/tests/test_can.rs | 77 ++++++++------- compiler/collections/src/lib.rs | 2 + compiler/load_internal/tests/test_load.rs | 48 ++++------ compiler/mono/src/ir.rs | 4 +- compiler/solve/src/solve.rs | 2 +- compiler/test_mono/src/tests.rs | 2 +- 15 files changed, 94 insertions(+), 205 deletions(-) delete mode 100644 compiler/can/tests/can_inline.rs diff --git a/ast/src/solve_type.rs b/ast/src/solve_type.rs index f15b128827..096a405d5c 100644 --- a/ast/src/solve_type.rs +++ b/ast/src/solve_type.rs @@ -75,7 +75,7 @@ use crate::mem_pool::shallow_clone::ShallowClone; // Ranks are used to limit the number of type variables considered for generalization. Only those inside // of the let (so those used in inferring the type of `\x -> x`) are considered. -#[derive(PartialEq, Debug, Clone)] +#[derive(Debug, Clone)] pub enum TypeError { BadExpr(Region, Category, ErrorType, Expected), BadPattern(Region, PatternCategory, ErrorType, PExpected), diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index 92caf9298b..87dc27f336 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -1,6 +1,6 @@ use crate::env::Env; use crate::scope::Scope; -use roc_collections::{ImMap, MutMap, MutSet, SendMap, VecSet}; +use roc_collections::{ImMap, MutMap, MutSet, SendMap, VecMap, VecSet}; use roc_module::ident::{Ident, Lowercase, TagName}; use roc_module::symbol::{IdentIds, ModuleId, Symbol}; use roc_parse::ast::{AssignedField, ExtractSpaces, Pattern, Tag, TypeAnnotation, TypeHeader}; @@ -11,7 +11,7 @@ use roc_types::types::{ Alias, AliasCommon, AliasKind, LambdaSet, Problem, RecordField, Type, TypeExtension, }; -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug)] pub struct Annotation { pub typ: Type, pub introduced_variables: IntroducedVariables, @@ -53,14 +53,14 @@ pub struct AbleVariable { pub first_seen: Region, } -#[derive(Clone, Debug, PartialEq, Default)] +#[derive(Clone, Debug, Default)] pub struct IntroducedVariables { pub wildcards: Vec>, pub lambda_sets: Vec, pub inferred: Vec>, pub named: VecSet, pub able: VecSet, - pub host_exposed_aliases: MutMap, + pub host_exposed_aliases: VecMap, } impl IntroducedVariables { diff --git a/compiler/can/src/constraint.rs b/compiler/can/src/constraint.rs index 58d7b1f065..c858834263 100644 --- a/compiler/can/src/constraint.rs +++ b/compiler/can/src/constraint.rs @@ -601,7 +601,7 @@ impl Constraints { roc_error_macros::assert_sizeof_default!(Constraint, 3 * 8); -#[derive(Clone, PartialEq)] +#[derive(Clone)] pub enum Constraint { Eq( EitherIndex, @@ -643,13 +643,13 @@ pub enum Constraint { ), } -#[derive(Debug, Clone, Copy, PartialEq, Default)] +#[derive(Debug, Clone, Copy, Default)] pub struct DefTypes { pub types: Slice, pub loc_symbols: Slice<(Symbol, Region)>, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone)] pub struct LetConstraint { pub rigid_vars: Slice, pub flex_vars: Slice, @@ -657,7 +657,7 @@ pub struct LetConstraint { pub defs_and_ret_constraint: Index<(Constraint, Constraint)>, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone)] pub struct IncludesTag { pub type_index: Index, pub tag_name: TagName, diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 1acf368e9b..0fbe917e30 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -29,7 +29,7 @@ use std::collections::HashMap; use std::fmt::Debug; use ven_graph::{strongly_connected_components, topological_sort}; -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug)] pub struct Def { pub loc_pattern: Loc, pub loc_expr: Loc, @@ -38,7 +38,7 @@ pub struct Def { pub annotation: Option, } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug)] pub struct Annotation { pub signature: Type, pub introduced_variables: IntroducedVariables, @@ -56,7 +56,7 @@ pub struct CanDefs { /// A Def that has had patterns and type annnotations canonicalized, /// but no Expr canonicalization has happened yet. Also, it has had spaces /// and nesting resolved, and knows whether annotations are standalone or not. -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone)] enum PendingValueDef<'a> { /// A standalone annotation with no body AnnotationOnly( @@ -79,7 +79,7 @@ enum PendingValueDef<'a> { ), } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone)] enum PendingTypeDef<'a> { /// A structural or opaque type alias, e.g. `Ints : List Int` or `Age := U32` respectively. Alias { @@ -105,7 +105,7 @@ enum PendingTypeDef<'a> { } // See github.com/rtfeldman/roc/issues/800 for discussion of the large_enum_variant check. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug)] #[allow(clippy::large_enum_variant)] pub enum Declaration { Declare(Def), diff --git a/compiler/can/src/expected.rs b/compiler/can/src/expected.rs index aad8bd42b4..df156e00fc 100644 --- a/compiler/can/src/expected.rs +++ b/compiler/can/src/expected.rs @@ -2,7 +2,7 @@ use crate::pattern::Pattern; use roc_region::all::{Loc, Region}; use roc_types::types::{AnnotationSource, PReason, Reason}; -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone)] pub enum Expected { NoExpectation(T), FromAnnotation(Loc, usize, AnnotationSource, T), @@ -10,7 +10,7 @@ pub enum Expected { } /// Like Expected, but for Patterns. -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone)] pub enum PExpected { NoExpectation(T), ForReason(PReason, T, Region), diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index 63c44001bd..9ec675185f 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -9,7 +9,7 @@ use crate::num::{ use crate::pattern::{canonicalize_pattern, Pattern}; use crate::procedure::References; use crate::scope::Scope; -use roc_collections::{MutMap, MutSet, SendMap, VecSet}; +use roc_collections::{MutMap, MutSet, SendMap, VecMap, VecSet}; use roc_module::called_via::CalledVia; use roc_module::ident::{ForeignSymbol, Lowercase, TagName}; use roc_module::low_level::LowLevel; @@ -23,12 +23,12 @@ use roc_types::types::{Alias, LambdaSet, Type}; use std::fmt::{Debug, Display}; use std::{char, u32}; -#[derive(Clone, Default, Debug, PartialEq)] +#[derive(Clone, Default, Debug)] pub struct Output { pub references: References, pub tail_call: Option, pub introduced_variables: IntroducedVariables, - pub aliases: SendMap, + pub aliases: VecMap, pub non_closures: VecSet, } @@ -62,7 +62,7 @@ impl Display for IntValue { } } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug)] pub enum Expr { // Literals @@ -194,7 +194,7 @@ pub enum Expr { // Compiles, but will crash if reached RuntimeError(RuntimeError), } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug)] pub struct ClosureData { pub function_type: Variable, pub closure_type: Variable, @@ -271,7 +271,7 @@ impl AccessorData { } } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug)] pub struct Field { pub var: Variable, // The region of the full `foo: f bar`, rather than just `f bar` @@ -286,7 +286,7 @@ pub enum Recursive { TailRecursive = 2, } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug)] pub struct WhenBranch { pub patterns: Vec>, pub value: Loc, diff --git a/compiler/can/src/pattern.rs b/compiler/can/src/pattern.rs index e620f41f00..c47af17fb4 100644 --- a/compiler/can/src/pattern.rs +++ b/compiler/can/src/pattern.rs @@ -17,7 +17,7 @@ use roc_types::types::{LambdaSet, Type}; /// A pattern, including possible problems (e.g. shadowing) so that /// codegen can generate a runtime error if this pattern is reached. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug)] pub enum Pattern { Identifier(Symbol), AppliedTag { @@ -82,7 +82,7 @@ pub enum Pattern { MalformedPattern(MalformedPatternProblem, Region), } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug)] pub struct RecordDestruct { pub var: Variable, pub label: Lowercase, @@ -90,7 +90,7 @@ pub struct RecordDestruct { pub typ: DestructType, } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug)] pub enum DestructType { Required, Optional(Variable, Loc), diff --git a/compiler/can/src/procedure.rs b/compiler/can/src/procedure.rs index c3f7088957..fd0fd5d372 100644 --- a/compiler/can/src/procedure.rs +++ b/compiler/can/src/procedure.rs @@ -5,7 +5,7 @@ use roc_module::symbol::Symbol; use roc_region::all::{Loc, Region}; use roc_types::subs::Variable; -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug)] pub struct Procedure { pub name: Option>, pub is_self_tail_recursive: bool, diff --git a/compiler/can/tests/can_inline.rs b/compiler/can/tests/can_inline.rs deleted file mode 100644 index ac26cb90a3..0000000000 --- a/compiler/can/tests/can_inline.rs +++ /dev/null @@ -1,110 +0,0 @@ -#[macro_use] -extern crate pretty_assertions; -#[macro_use] -extern crate indoc; - -extern crate bumpalo; -extern crate roc_can; -extern crate roc_parse; -extern crate roc_region; - -mod helpers; - -#[cfg(test)] -mod can_inline { - use crate::helpers::{can_expr_with, test_home}; - use bumpalo::Bump; - use roc_can::expr::inline_calls; - use roc_can::expr::Expr::{self, *}; - use roc_can::scope::Scope; - use roc_types::subs::VarStore; - - fn assert_inlines_to(input: &str, expected: Expr, var_store: &mut VarStore) { - let arena = Bump::new(); - let scope = &mut Scope::new(test_home(), var_store); - let actual_out = can_expr_with(&arena, test_home(), input); - let actual = inline_calls(var_store, scope, actual_out.loc_expr.value); - - assert_eq!(actual, expected); - } - - #[test] - fn inline_empty_record() { - // fn inline_list_len() { - let var_store = &mut VarStore::default(); - - assert_inlines_to( - indoc!( - r#" - {} - "# - ), - EmptyRecord, - var_store, - ); - - // TODO testing with hardcoded variables is very brittle. - // Should find a better way to test this! - // (One idea would be to traverse both Exprs and zero out all the Variables, - // so they always pass equality.) - // let aliases = SendMap::default(); - // assert_inlines_to( - // indoc!( - // r#" - // Int.isZero 5 - // "# - // ), - // LetNonRec( - // Box::new(Def { - // loc_pattern: Located { - // region: Region::zero(), - // value: Pattern::Identifier(Symbol::ARG_1), - // }, - // pattern_vars: SendMap::default(), - // loc_expr: Located { - // region: Region::new(0, 0, 11, 12), - // value: Num(unsafe { Variable::unsafe_test_debug_variable(7) }, 5), - // }, - // expr_var: unsafe { Variable::unsafe_test_debug_variable(8) }, - // annotation: None, - // }), - // Box::new(Located { - // region: Region::zero(), - // value: Expr::Call( - // Box::new(( - // unsafe { Variable::unsafe_test_debug_variable(138) }, - // Located { - // region: Region::zero(), - // value: Expr::Var(Symbol::BOOL_EQ), - // }, - // unsafe { Variable::unsafe_test_debug_variable(139) }, - // )), - // vec![ - // ( - // unsafe { Variable::unsafe_test_debug_variable(140) }, - // Located { - // region: Region::zero(), - // value: Var(Symbol::ARG_1), - // }, - // ), - // ( - // unsafe { Variable::unsafe_test_debug_variable(141) }, - // Located { - // region: Region::zero(), - // value: Int( - // unsafe { Variable::unsafe_test_debug_variable(137) }, - // 0, - // ), - // }, - // ), - // ], - // CalledVia::Space, - // ), - // }), - // unsafe { Variable::unsafe_test_debug_variable(198) }, - // aliases, - // ), - // var_store, - // ) - } -} diff --git a/compiler/can/tests/test_can.rs b/compiler/can/tests/test_can.rs index 83481c882b..838280f73d 100644 --- a/compiler/can/tests/test_can.rs +++ b/compiler/can/tests/test_can.rs @@ -20,11 +20,32 @@ mod test_can { use roc_region::all::{Position, Region}; use std::{f64, i64}; - fn assert_can(input: &str, expected: Expr) { + fn assert_can_runtime_error(input: &str, expected: RuntimeError) { let arena = Bump::new(); let actual_out = can_expr_with(&arena, test_home(), input); - assert_eq!(actual_out.loc_expr.value, expected); + match actual_out.loc_expr.value { + Expr::RuntimeError(actual) => { + assert_eq!(expected, actual); + } + actual => { + panic!("Expected a Float, but got: {:?}", actual); + } + } + } + + fn assert_can_string(input: &str, expected: &str) { + let arena = Bump::new(); + let actual_out = can_expr_with(&arena, test_home(), input); + + match actual_out.loc_expr.value { + Expr::Str(actual) => { + assert_eq!(expected, &*actual); + } + actual => { + panic!("Expected a Float, but got: {:?}", actual); + } + } } fn assert_can_float(input: &str, expected: f64) { @@ -69,10 +90,6 @@ mod test_can { } } - fn expr_str(contents: &str) -> Expr { - Expr::Str(contents.into()) - } - // NUMBER LITERALS #[test] @@ -81,14 +98,14 @@ mod test_can { let string = "340_282_366_920_938_463_463_374_607_431_768_211_456".to_string(); - assert_can( + assert_can_runtime_error( &string.clone(), - RuntimeError(RuntimeError::InvalidInt( + RuntimeError::InvalidInt( IntErrorKind::Overflow, Base::Decimal, Region::zero(), string.into_boxed_str(), - )), + ), ); } @@ -98,14 +115,14 @@ mod test_can { let string = "-170_141_183_460_469_231_731_687_303_715_884_105_729".to_string(); - assert_can( + assert_can_runtime_error( &string.clone(), - RuntimeError(RuntimeError::InvalidInt( + RuntimeError::InvalidInt( IntErrorKind::Underflow, Base::Decimal, Region::zero(), string.into(), - )), + ), ); } @@ -114,13 +131,9 @@ mod test_can { let string = format!("{}1.0", f64::MAX); let region = Region::zero(); - assert_can( + assert_can_runtime_error( &string.clone(), - RuntimeError(RuntimeError::InvalidFloat( - FloatErrorKind::PositiveInfinity, - region, - string.into(), - )), + RuntimeError::InvalidFloat(FloatErrorKind::PositiveInfinity, region, string.into()), ); } @@ -129,13 +142,9 @@ mod test_can { let string = format!("{}1.0", f64::MIN); let region = Region::zero(); - assert_can( + assert_can_runtime_error( &string.clone(), - RuntimeError(RuntimeError::InvalidFloat( - FloatErrorKind::NegativeInfinity, - region, - string.into(), - )), + RuntimeError::InvalidFloat(FloatErrorKind::NegativeInfinity, region, string.into()), ); } @@ -144,13 +153,9 @@ mod test_can { let string = "1.1.1"; let region = Region::zero(); - assert_can( + assert_can_runtime_error( string.clone(), - RuntimeError(RuntimeError::InvalidFloat( - FloatErrorKind::Error, - region, - string.into(), - )), + RuntimeError::InvalidFloat(FloatErrorKind::Error, region, string.into()), ); } @@ -1582,27 +1587,27 @@ mod test_can { #[test] fn string_with_valid_unicode_escapes() { - assert_can(r#""x\u(00A0)x""#, expr_str("x\u{00A0}x")); - assert_can(r#""x\u(101010)x""#, expr_str("x\u{101010}x")); + assert_can_string(r#""x\u(00A0)x""#, "x\u{00A0}x"); + assert_can_string(r#""x\u(101010)x""#, "x\u{101010}x"); } #[test] fn block_string() { - assert_can( + assert_can_string( r#" """foobar""" "#, - expr_str("foobar"), + "foobar", ); - assert_can( + assert_can_string( indoc!( r#" """foo bar""" "# ), - expr_str("foo\nbar"), + "foo\nbar", ); } diff --git a/compiler/collections/src/lib.rs b/compiler/collections/src/lib.rs index c5d3e2c31c..f0f98b5e64 100644 --- a/compiler/collections/src/lib.rs +++ b/compiler/collections/src/lib.rs @@ -4,7 +4,9 @@ pub mod all; pub mod soa; +mod vec_map; mod vec_set; pub use all::{default_hasher, BumpMap, ImEntry, ImMap, ImSet, MutMap, MutSet, SendMap}; +pub use vec_map::VecMap; pub use vec_set::VecSet; diff --git a/compiler/load_internal/tests/test_load.rs b/compiler/load_internal/tests/test_load.rs index 5aaace9f19..0574311f0e 100644 --- a/compiler/load_internal/tests/test_load.rs +++ b/compiler/load_internal/tests/test_load.rs @@ -112,13 +112,11 @@ mod test_load { )); } - assert_eq!( - loaded_module - .type_problems - .remove(&home) - .unwrap_or_default(), - Vec::new() - ); + assert!(loaded_module + .type_problems + .remove(&home) + .unwrap_or_default() + .is_empty(),); Ok(loaded_module) } @@ -208,13 +206,11 @@ mod test_load { loaded_module.can_problems.remove(&home).unwrap_or_default(), Vec::new() ); - assert_eq!( - loaded_module - .type_problems - .remove(&home) - .unwrap_or_default(), - Vec::new() - ); + assert!(loaded_module + .type_problems + .remove(&home) + .unwrap_or_default() + .is_empty()); let expected_name = loaded_module .interns @@ -261,13 +257,11 @@ mod test_load { loaded_module.can_problems.remove(&home).unwrap_or_default(), Vec::new() ); - assert_eq!( - loaded_module - .type_problems - .remove(&home) - .unwrap_or_default(), - Vec::new() - ); + assert!(loaded_module + .type_problems + .remove(&home) + .unwrap_or_default() + .is_empty()); for decl in loaded_module.declarations_by_id.remove(&home).unwrap() { match decl { @@ -365,13 +359,11 @@ mod test_load { loaded_module.can_problems.remove(&home).unwrap_or_default(), Vec::new() ); - assert_eq!( - loaded_module - .type_problems - .remove(&home) - .unwrap_or_default(), - Vec::new() - ); + assert!(loaded_module + .type_problems + .remove(&home) + .unwrap_or_default() + .is_empty(),); let def_count: usize = loaded_module .declarations_by_id diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 5bb784d3c4..9a12b67ef5 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -108,7 +108,7 @@ pub struct EntryPoint<'a> { #[derive(Clone, Copy, Debug)] pub struct PartialProcId(usize); -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug)] pub struct PartialProcs<'a> { /// maps a function name (symbol) to an index symbols: Vec<'a, Symbol>, @@ -190,7 +190,7 @@ impl<'a> PartialProcs<'a> { } } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug)] pub struct PartialProc<'a> { pub annotation: Variable, pub pattern_symbols: &'a [Symbol], diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index e30be26df4..dbe6f50c5d 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -79,7 +79,7 @@ pub struct IncompleteAbilityImplementation { pub missing_members: Vec>, } -#[derive(PartialEq, Debug, Clone)] +#[derive(Debug, Clone)] pub enum TypeError { BadExpr(Region, Category, ErrorType, Expected), BadPattern(Region, PatternCategory, ErrorType, PExpected), diff --git a/compiler/test_mono/src/tests.rs b/compiler/test_mono/src/tests.rs index bba051e6b6..23df54d27a 100644 --- a/compiler/test_mono/src/tests.rs +++ b/compiler/test_mono/src/tests.rs @@ -129,7 +129,7 @@ fn compiles_to_ir(test_name: &str, src: &str) { println!("Ignoring {} canonicalization problems", can_problems.len()); } - assert_eq!(type_problems, Vec::new()); + assert!(type_problems.is_empty()); assert_eq!(mono_problems, Vec::new()); debug_assert_eq!(exposed_to_host.values.len(), 1); From e740bbe529e2d181dc74fae91b34bba43a18dfb8 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 20 Apr 2022 17:25:22 +0200 Subject: [PATCH 346/846] make some of References' fields private --- compiler/can/src/annotation.rs | 2 +- compiler/can/src/def.rs | 12 ++++-------- compiler/can/src/expr.rs | 5 ++--- compiler/can/src/module.rs | 8 ++++---- compiler/can/src/pattern.rs | 3 +-- compiler/can/src/procedure.rs | 17 +++++++++++++++-- 6 files changed, 27 insertions(+), 20 deletions(-) diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index 87dc27f336..1d83835d38 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -125,7 +125,7 @@ impl IntroducedVariables { self.lambda_sets.extend(other.lambda_sets.iter().copied()); self.inferred.extend(other.inferred.iter().copied()); self.host_exposed_aliases - .extend(other.host_exposed_aliases.clone()); + .extend(other.host_exposed_aliases.iter().map(|(k, v)| (*k, *v))); self.named.extend(other.named.iter().cloned()); self.able.extend(other.able.iter().cloned()); diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 0fbe917e30..5d7b0ced91 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -334,8 +334,7 @@ pub fn canonicalize_defs<'a>( // Record all the annotation's references in output.references.lookups for symbol in can_ann.references { - output.references.type_lookups.insert(symbol); - output.references.referenced_type_defs.insert(symbol); + output.references.insert_type_lookup(symbol); } let mut can_vars: Vec> = Vec::with_capacity(vars.len()); @@ -445,8 +444,7 @@ pub fn canonicalize_defs<'a>( // Record all the annotation's references in output.references.lookups for symbol in member_annot.references { - output.references.type_lookups.insert(symbol); - output.references.referenced_type_defs.insert(symbol); + output.references.insert_type_lookup(symbol); } let name_region = member.name.region; @@ -1162,8 +1160,7 @@ fn canonicalize_pending_value_def<'a>( // Record all the annotation's references in output.references.lookups for symbol in type_annotation.references.iter() { - output.references.type_lookups.insert(*symbol); - output.references.referenced_type_defs.insert(*symbol); + output.references.insert_type_lookup(*symbol); } add_annotation_aliases(&type_annotation, aliases); @@ -1282,8 +1279,7 @@ fn canonicalize_pending_value_def<'a>( // Record all the annotation's references in output.references.lookups for symbol in type_annotation.references.iter() { - output.references.type_lookups.insert(*symbol); - output.references.referenced_type_defs.insert(*symbol); + output.references.insert_type_lookup(*symbol); } add_annotation_aliases(&type_annotation, aliases); diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index 9ec675185f..c916ffe2f7 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -487,8 +487,7 @@ pub fn canonicalize_expr<'a>( } Ok((name, opaque_def)) => { let argument = Box::new(args.pop().unwrap()); - output.references.referenced_type_defs.insert(name); - output.references.type_lookups.insert(name); + output.references.insert_type_lookup(name); let (type_arguments, lambda_set_variables, specialized_def_type) = freshen_opaque_def(var_store, opaque_def); @@ -685,7 +684,7 @@ pub fn canonicalize_expr<'a>( // filter out aliases debug_assert!(captured_symbols .iter() - .all(|s| !output.references.referenced_type_defs.contains(s))); + .all(|s| !output.references.references_type_def(*s))); // captured_symbols.retain(|s| !output.references.referenced_type_defs.contains(s)); // filter out functions that don't close over anything diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index dbd4a30274..ba4ece29d5 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -329,8 +329,8 @@ pub fn canonicalize_module_defs<'a>( let mut referenced_types = VecSet::default(); // Gather up all the symbols that were referenced across all the defs' lookups. - referenced_values.extend(output.references.value_lookups); - referenced_types.extend(output.references.type_lookups); + referenced_values.extend(output.references.value_lookups.iter().copied()); + referenced_types.extend(output.references.type_lookups().copied()); // Gather up all the symbols that were referenced across all the defs' calls. referenced_values.extend(output.references.calls); @@ -528,8 +528,8 @@ pub fn canonicalize_module_defs<'a>( } // Incorporate any remaining output.lookups entries into references. - referenced_values.extend(output.references.value_lookups); - referenced_types.extend(output.references.type_lookups); + referenced_values.extend(output.references.value_lookups.iter().copied()); + referenced_types.extend(output.references.type_lookups().copied()); // Incorporate any remaining output.calls entries into references. referenced_values.extend(output.references.calls); diff --git a/compiler/can/src/pattern.rs b/compiler/can/src/pattern.rs index c47af17fb4..f6885c15d0 100644 --- a/compiler/can/src/pattern.rs +++ b/compiler/can/src/pattern.rs @@ -318,8 +318,7 @@ pub fn canonicalize_pattern<'a>( let (type_arguments, lambda_set_variables, specialized_def_type) = freshen_opaque_def(var_store, opaque_def); - output.references.referenced_type_defs.insert(opaque); - output.references.type_lookups.insert(opaque); + output.references.insert_type_lookup(opaque); Pattern::UnwrappedOpaque { whole_var: var_store.fresh(), diff --git a/compiler/can/src/procedure.rs b/compiler/can/src/procedure.rs index fd0fd5d372..d893f1a1bb 100644 --- a/compiler/can/src/procedure.rs +++ b/compiler/can/src/procedure.rs @@ -45,10 +45,10 @@ impl Procedure { #[derive(Clone, Debug, Default, PartialEq)] pub struct References { pub bound_symbols: VecSet, - pub type_lookups: VecSet, + type_lookups: VecSet, pub value_lookups: VecSet, /// Aliases or opaque types referenced - pub referenced_type_defs: VecSet, + referenced_type_defs: VecSet, pub calls: VecSet, } @@ -75,4 +75,17 @@ impl References { pub fn has_type_lookup(&self, symbol: Symbol) -> bool { self.type_lookups.contains(&symbol) } + + pub fn references_type_def(&self, symbol: Symbol) -> bool { + self.referenced_type_defs.contains(&symbol) + } + + pub fn insert_type_lookup(&mut self, symbol: Symbol) { + self.type_lookups.insert(symbol); + self.referenced_type_defs.insert(symbol); + } + + pub fn type_lookups(&self) -> impl Iterator { + self.type_lookups.iter() + } } From c531191e4943850b736d432ebc909a9ce2a792a7 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 20 Apr 2022 17:34:08 +0200 Subject: [PATCH 347/846] make value_lookups private --- compiler/can/src/def.rs | 12 ++++++------ compiler/can/src/expr.rs | 18 +++++++----------- compiler/can/src/module.rs | 4 ++-- compiler/can/src/procedure.rs | 14 +++++++++++++- 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 5d7b0ced91..231ecabc1f 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -691,10 +691,10 @@ pub fn sort_can_defs( let mut loc_succ = local_successors_with_duplicates(references, &env.closures); // if the current symbol is a closure, peek into its body - if let Some(References { value_lookups, .. }) = env.closures.get(symbol) { + if let Some(references) = env.closures.get(symbol) { let home = env.home; - for lookup in value_lookups.iter() { + for lookup in references.value_lookups() { if lookup != symbol && lookup.module_id() == home { // DO NOT register a self-call behind a lambda! // @@ -744,8 +744,8 @@ pub fn sort_can_defs( let mut loc_succ = local_successors_with_duplicates(references, &env.closures); // if the current symbol is a closure, peek into its body - if let Some(References { value_lookups, .. }) = env.closures.get(symbol) { - for lookup in value_lookups.iter() { + if let Some(references) = env.closures.get(symbol) { + for lookup in references.value_lookups() { loc_succ.push(*lookup); } } @@ -1358,7 +1358,7 @@ fn canonicalize_pending_value_def<'a>( // Recursion doesn't count as referencing. (If it did, all recursive functions // would result in circular def errors!) refs_by_symbol.entry(symbol).and_modify(|(_, refs)| { - refs.value_lookups.remove(&symbol); + refs.remove_value_lookup(&symbol); }); // renamed_closure_def = Some(&symbol); @@ -1498,7 +1498,7 @@ fn canonicalize_pending_value_def<'a>( // Recursion doesn't count as referencing. (If it did, all recursive functions // would result in circular def errors!) refs_by_symbol.entry(symbol).and_modify(|(_, refs)| { - refs.value_lookups.remove(&symbol); + refs.remove_value_lookup(&symbol); }); loc_can_expr.value = Closure(ClosureData { diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index c916ffe2f7..f808787a8c 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -655,12 +655,8 @@ pub fn canonicalize_expr<'a>( &loc_body_expr.value, ); - let mut captured_symbols: MutSet = new_output - .references - .value_lookups - .iter() - .copied() - .collect(); + let mut captured_symbols: MutSet = + new_output.references.value_lookups().copied().collect(); // filter out the closure's name itself captured_symbols.remove(&symbol); @@ -702,7 +698,7 @@ pub fn canonicalize_expr<'a>( // We shouldn't ultimately count arguments as referenced locals. Otherwise, // we end up with weird conclusions like the expression (\x -> x + 1) // references the (nonexistent) local variable x! - output.references.value_lookups.remove(sub_symbol); + output.references.remove_value_lookup(sub_symbol); } } @@ -1105,7 +1101,7 @@ pub fn local_successors_with_duplicates<'a>( references: &'a References, closures: &'a MutMap, ) -> Vec { - let mut answer: Vec<_> = references.value_lookups.iter().copied().collect(); + let mut answer: Vec<_> = references.value_lookups().copied().collect(); let mut stack: Vec<_> = references.calls.iter().copied().collect(); let mut seen = Vec::new(); @@ -1116,7 +1112,7 @@ pub fn local_successors_with_duplicates<'a>( } if let Some(references) = closures.get(&symbol) { - answer.extend(references.value_lookups.iter().copied()); + answer.extend(references.value_lookups().copied()); stack.extend(references.calls.iter().copied()); seen.push(symbol); @@ -1254,7 +1250,7 @@ fn canonicalize_var_lookup( // Look it up in scope! match scope.lookup(&(*ident).into(), region) { Ok(symbol) => { - output.references.value_lookups.insert(symbol); + output.references.insert_value_lookup(symbol); Var(symbol) } @@ -1269,7 +1265,7 @@ fn canonicalize_var_lookup( // Look it up in the env! match env.qualified_lookup(module_name, ident, region) { Ok(symbol) => { - output.references.value_lookups.insert(symbol); + output.references.insert_value_lookup(symbol); Var(symbol) } diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index ba4ece29d5..4445fa6486 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -329,7 +329,7 @@ pub fn canonicalize_module_defs<'a>( let mut referenced_types = VecSet::default(); // Gather up all the symbols that were referenced across all the defs' lookups. - referenced_values.extend(output.references.value_lookups.iter().copied()); + referenced_values.extend(output.references.value_lookups().copied()); referenced_types.extend(output.references.type_lookups().copied()); // Gather up all the symbols that were referenced across all the defs' calls. @@ -528,7 +528,7 @@ pub fn canonicalize_module_defs<'a>( } // Incorporate any remaining output.lookups entries into references. - referenced_values.extend(output.references.value_lookups.iter().copied()); + referenced_values.extend(output.references.value_lookups().copied()); referenced_types.extend(output.references.type_lookups().copied()); // Incorporate any remaining output.calls entries into references. diff --git a/compiler/can/src/procedure.rs b/compiler/can/src/procedure.rs index d893f1a1bb..24028dab08 100644 --- a/compiler/can/src/procedure.rs +++ b/compiler/can/src/procedure.rs @@ -46,7 +46,7 @@ impl Procedure { pub struct References { pub bound_symbols: VecSet, type_lookups: VecSet, - pub value_lookups: VecSet, + value_lookups: VecSet, /// Aliases or opaque types referenced referenced_type_defs: VecSet, pub calls: VecSet, @@ -80,11 +80,23 @@ impl References { self.referenced_type_defs.contains(&symbol) } + pub fn insert_value_lookup(&mut self, symbol: Symbol) { + self.value_lookups.insert(symbol); + } + + pub fn remove_value_lookup(&mut self, symbol: &Symbol) { + self.value_lookups.remove(symbol); + } + pub fn insert_type_lookup(&mut self, symbol: Symbol) { self.type_lookups.insert(symbol); self.referenced_type_defs.insert(symbol); } + pub fn value_lookups(&self) -> impl Iterator { + self.value_lookups.iter() + } + pub fn type_lookups(&self) -> impl Iterator { self.type_lookups.iter() } From ab8ac2edadeba6ff4e03bdb2ecd020a92c069e0b Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 20 Apr 2022 17:39:19 +0200 Subject: [PATCH 348/846] make bound_symbols private --- compiler/can/src/expr.rs | 5 ++--- compiler/can/src/pattern.rs | 12 ++++++------ compiler/can/src/procedure.rs | 10 +++++++++- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index f808787a8c..282d981050 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -639,8 +639,7 @@ pub fn canonicalize_expr<'a>( loc_pattern.region, ); - bound_by_argument_patterns - .extend(new_output.references.bound_symbols.iter().copied()); + bound_by_argument_patterns.extend(new_output.references.bound_symbols().copied()); output.union(new_output); @@ -662,7 +661,7 @@ pub fn canonicalize_expr<'a>( captured_symbols.remove(&symbol); // symbols bound either in this pattern or deeper down are not captured! - captured_symbols.retain(|s| !new_output.references.bound_symbols.contains(s)); + captured_symbols.retain(|s| !new_output.references.bound_symbols().any(|x| x == s)); captured_symbols.retain(|s| !bound_by_argument_patterns.contains(s)); // filter out top-level symbols diff --git a/compiler/can/src/pattern.rs b/compiler/can/src/pattern.rs index f6885c15d0..dc8a11a5b0 100644 --- a/compiler/can/src/pattern.rs +++ b/compiler/can/src/pattern.rs @@ -172,7 +172,7 @@ pub fn canonicalize_def_header_pattern<'a>( region, ) { Ok((symbol, shadowing_ability_member)) => { - output.references.bound_symbols.insert(symbol); + output.references.insert_bound(symbol); let can_pattern = match shadowing_ability_member { // A fresh identifier. None => Pattern::Identifier(symbol), @@ -190,7 +190,7 @@ pub fn canonicalize_def_header_pattern<'a>( shadow: shadow.clone(), kind: ShadowKind::Variable, })); - output.references.bound_symbols.insert(new_symbol); + output.references.insert_bound(new_symbol); let can_pattern = Pattern::Shadowed(original_region, shadow, new_symbol); (output, Loc::at(region, can_pattern)) @@ -220,7 +220,7 @@ pub fn canonicalize_pattern<'a>( region, ) { Ok(symbol) => { - output.references.bound_symbols.insert(symbol); + output.references.insert_bound(symbol); Pattern::Identifier(symbol) } @@ -230,7 +230,7 @@ pub fn canonicalize_pattern<'a>( shadow: shadow.clone(), kind: ShadowKind::Variable, })); - output.references.bound_symbols.insert(new_symbol); + output.references.insert_bound(new_symbol); Pattern::Shadowed(original_region, shadow, new_symbol) } @@ -460,7 +460,7 @@ pub fn canonicalize_pattern<'a>( region, ) { Ok(symbol) => { - output.references.bound_symbols.insert(symbol); + output.references.insert_bound(symbol); destructs.push(Loc { region: loc_pattern.region, @@ -531,7 +531,7 @@ pub fn canonicalize_pattern<'a>( ); // an optional field binds the symbol! - output.references.bound_symbols.insert(symbol); + output.references.insert_bound(symbol); output.union(expr_output); diff --git a/compiler/can/src/procedure.rs b/compiler/can/src/procedure.rs index 24028dab08..04a5efdb99 100644 --- a/compiler/can/src/procedure.rs +++ b/compiler/can/src/procedure.rs @@ -44,7 +44,7 @@ impl Procedure { /// so it's important that building the same code gives the same order every time! #[derive(Clone, Debug, Default, PartialEq)] pub struct References { - pub bound_symbols: VecSet, + bound_symbols: VecSet, type_lookups: VecSet, value_lookups: VecSet, /// Aliases or opaque types referenced @@ -84,6 +84,10 @@ impl References { self.value_lookups.insert(symbol); } + pub fn insert_bound(&mut self, symbol: Symbol) { + self.bound_symbols.insert(symbol); + } + pub fn remove_value_lookup(&mut self, symbol: &Symbol) { self.value_lookups.remove(symbol); } @@ -100,4 +104,8 @@ impl References { pub fn type_lookups(&self) -> impl Iterator { self.type_lookups.iter() } + + pub fn bound_symbols(&self) -> impl Iterator { + self.bound_symbols.iter() + } } From a47b3be9c0fd6ff03da0b60c08fef95dc6921b1e Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 20 Apr 2022 10:04:37 -0400 Subject: [PATCH 349/846] Revise some CLI flag descriptions --- cli/src/lib.rs | 19 ++++++++++--------- version.txt | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 6bb78f495a..e64aeb9d63 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -49,10 +49,12 @@ pub const ROC_DIR: &str = "ROC_DIR"; pub const DIRECTORY_OR_FILES: &str = "DIRECTORY_OR_FILES"; pub const ARGS_FOR_APP: &str = "ARGS_FOR_APP"; +const VERSION: &str = include_str!("../../version.txt"); + pub fn build_app<'a>() -> App<'a> { let app = App::new("roc") - .version(concatcp!(include_str!("../../version.txt"), "\n")) - .about("Runs the given .roc file. Use one of the SUBCOMMANDS below to do something else!") + .version(concatcp!(VERSION, "\n")) + .about("Runs the given .roc file, if there are no compilation errors.\nUse one of the SUBCOMMANDS below to do something else!") .subcommand(App::new(CMD_BUILD) .about("Build a binary from the given .roc file, but don't run it") .arg( @@ -141,7 +143,7 @@ pub fn build_app<'a>() -> App<'a> { .about("Launch the interactive Read Eval Print Loop (REPL)") ) .subcommand(App::new(CMD_FORMAT) - .about("Format Roc code") + .about("Format a .roc file using standard Roc formatting") .arg( Arg::new(DIRECTORY_OR_FILES) .index(1) @@ -155,10 +157,9 @@ pub fn build_app<'a>() -> App<'a> { ) ) .subcommand(App::new(CMD_VERSION) - .about("Print version information") - ) + .about(concatcp!("Print the Roc compiler’s version, which is currently ", VERSION))) .subcommand(App::new(CMD_CHECK) - .about("When developing, it's recommended to run `check` before `build`. It may provide a useful error message in cases where `build` panics") + .about("Check the code for problems, but doesn’t build or run it") .arg( Arg::new(FLAG_TIME) .long(FLAG_TIME) @@ -193,19 +194,19 @@ pub fn build_app<'a>() -> App<'a> { .arg( Arg::new(FLAG_OPT_SIZE) .long(FLAG_OPT_SIZE) - .about("Optimize your compiled Roc program to have a small binary size. (Optimization takes time to complete.)") + .about("Optimize the compiled program to have a small binary size. (Optimization takes time to complete.)") .required(false), ) .arg( Arg::new(FLAG_DEV) .long(FLAG_DEV) - .about("Make compilation as fast as possible. (Runtime performance may suffer)") + .about("Make compilation finish as soon as possible, at the expense of runtime performance.") .required(false), ) .arg( Arg::new(FLAG_DEBUG) .long(FLAG_DEBUG) - .about("Store LLVM debug information in the generated program") + .about("Store LLVM debug information in the generated program.") .requires(ROC_FILE) .required(false), ) diff --git a/version.txt b/version.txt index 27ffb11fc3..3fed276742 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ - \ No newline at end of file +(built from source) \ No newline at end of file From b92c28b237e5d77f838224ac15523f2d146ee989 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 20 Apr 2022 17:43:18 +0200 Subject: [PATCH 350/846] make calls private --- compiler/can/src/def.rs | 4 ++-- compiler/can/src/expr.rs | 8 ++++---- compiler/can/src/module.rs | 4 ++-- compiler/can/src/procedure.rs | 10 +++++++++- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 231ecabc1f..2b99f698d7 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1642,7 +1642,7 @@ fn closure_recursivity(symbol: Symbol, closures: &MutMap) -> let mut stack = Vec::new(); if let Some(references) = closures.get(&symbol) { - for v in references.calls.iter() { + for v in references.calls() { stack.push(*v); } @@ -1658,7 +1658,7 @@ fn closure_recursivity(symbol: Symbol, closures: &MutMap) -> // if it calls any functions if let Some(nested_references) = closures.get(&nested_symbol) { // add its called to the stack - for v in nested_references.calls.iter() { + for v in nested_references.calls() { stack.push(*v); } } diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index 282d981050..e8db25e794 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -517,7 +517,7 @@ pub fn canonicalize_expr<'a>( let expr = match fn_expr.value { Var(symbol) => { - output.references.calls.insert(symbol); + output.references.insert_call(symbol); // we're tail-calling a symbol by name, check if it's the tail-callable symbol output.tail_call = match &env.tailcallable_symbol { @@ -1102,7 +1102,7 @@ pub fn local_successors_with_duplicates<'a>( ) -> Vec { let mut answer: Vec<_> = references.value_lookups().copied().collect(); - let mut stack: Vec<_> = references.calls.iter().copied().collect(); + let mut stack: Vec<_> = references.calls().copied().collect(); let mut seen = Vec::new(); while let Some(symbol) = stack.pop() { @@ -1112,7 +1112,7 @@ pub fn local_successors_with_duplicates<'a>( if let Some(references) = closures.get(&symbol) { answer.extend(references.value_lookups().copied()); - stack.extend(references.calls.iter().copied()); + stack.extend(references.calls().copied()); seen.push(symbol); } @@ -1720,7 +1720,7 @@ fn flatten_str_lines<'a>( Interpolated(loc_expr) => { if is_valid_interpolation(loc_expr.value) { // Interpolations desugar to Str.concat calls - output.references.calls.insert(Symbol::STR_CONCAT); + output.references.insert_call(Symbol::STR_CONCAT); if !buf.is_empty() { segments.push(StrSegment::Plaintext(buf.into())); diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index 4445fa6486..fa901a6cec 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -333,7 +333,7 @@ pub fn canonicalize_module_defs<'a>( referenced_types.extend(output.references.type_lookups().copied()); // Gather up all the symbols that were referenced across all the defs' calls. - referenced_values.extend(output.references.calls); + referenced_values.extend(output.references.calls().copied()); // Gather up all the symbols that were referenced from other modules. referenced_values.extend(env.qualified_value_lookups.iter().copied()); @@ -532,7 +532,7 @@ pub fn canonicalize_module_defs<'a>( referenced_types.extend(output.references.type_lookups().copied()); // Incorporate any remaining output.calls entries into references. - referenced_values.extend(output.references.calls); + referenced_values.extend(output.references.calls().copied()); // Gather up all the symbols that were referenced from other modules. referenced_values.extend(env.qualified_value_lookups.iter().copied()); diff --git a/compiler/can/src/procedure.rs b/compiler/can/src/procedure.rs index 04a5efdb99..1378a4a012 100644 --- a/compiler/can/src/procedure.rs +++ b/compiler/can/src/procedure.rs @@ -49,7 +49,7 @@ pub struct References { value_lookups: VecSet, /// Aliases or opaque types referenced referenced_type_defs: VecSet, - pub calls: VecSet, + calls: VecSet, } impl References { @@ -88,6 +88,10 @@ impl References { self.bound_symbols.insert(symbol); } + pub fn insert_call(&mut self, symbol: Symbol) { + self.calls.insert(symbol); + } + pub fn remove_value_lookup(&mut self, symbol: &Symbol) { self.value_lookups.remove(symbol); } @@ -108,4 +112,8 @@ impl References { pub fn bound_symbols(&self) -> impl Iterator { self.bound_symbols.iter() } + + pub fn calls(&self) -> impl Iterator { + self.calls.iter() + } } From 0267963e14bc5b83d8f00b0c794739afd86515ca Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 20 Apr 2022 18:02:11 +0200 Subject: [PATCH 351/846] stop using referenced_type_defs --- compiler/can/src/procedure.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/can/src/procedure.rs b/compiler/can/src/procedure.rs index 1378a4a012..34496bd09e 100644 --- a/compiler/can/src/procedure.rs +++ b/compiler/can/src/procedure.rs @@ -77,7 +77,7 @@ impl References { } pub fn references_type_def(&self, symbol: Symbol) -> bool { - self.referenced_type_defs.contains(&symbol) + self.type_lookups.contains(&symbol) } pub fn insert_value_lookup(&mut self, symbol: Symbol) { From ec43d7d770335b68b7bd4d3663a1986ac8351dbb Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 20 Apr 2022 18:05:06 +0200 Subject: [PATCH 352/846] clippy --- compiler/can/src/annotation.rs | 2 +- compiler/can/src/def.rs | 1 + compiler/load_internal/src/file.rs | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index 1d83835d38..47f11353cf 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -1,6 +1,6 @@ use crate::env::Env; use crate::scope::Scope; -use roc_collections::{ImMap, MutMap, MutSet, SendMap, VecMap, VecSet}; +use roc_collections::{ImMap, MutSet, SendMap, VecMap, VecSet}; use roc_module::ident::{Ident, Lowercase, TagName}; use roc_module::symbol::{IdentIds, ModuleId, Symbol}; use roc_parse::ast::{AssignedField, ExtractSpaces, Pattern, Tag, TypeAnnotation, TypeHeader}; diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 2b99f698d7..9235cd32ca 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -97,6 +97,7 @@ enum PendingTypeDef<'a> { /// An invalid alias, that is ignored in the rest of the pipeline /// e.g. a shadowed alias, or a definition like `MyAlias 1 : Int` /// with an incorrect pattern + #[allow(dead_code)] InvalidAlias { kind: AliasKind }, /// An invalid ability, that is ignored in the rest of the pipeline. diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index f8f60cfe4c..cdab508046 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -1110,7 +1110,7 @@ pub fn load<'a>( ) -> Result, LoadingProblem<'a>> { // When compiling to wasm, we cannot spawn extra threads // so we have a single-threaded implementation - if true || cfg!(target_family = "wasm") { + if cfg!(target_family = "wasm") { load_single_threaded( arena, load_start, From 9eddd23250e413fe20e498cb56667dde8caf0980 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 20 Apr 2022 18:09:09 +0200 Subject: [PATCH 353/846] add vec_map --- compiler/collections/src/vec_map.rs | 133 ++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 compiler/collections/src/vec_map.rs diff --git a/compiler/collections/src/vec_map.rs b/compiler/collections/src/vec_map.rs new file mode 100644 index 0000000000..57ab5c31b8 --- /dev/null +++ b/compiler/collections/src/vec_map.rs @@ -0,0 +1,133 @@ +#[derive(Debug, Clone)] +pub struct VecMap { + keys: Vec, + values: Vec, +} + +impl Default for VecMap { + fn default() -> Self { + Self { + keys: Vec::new(), + values: Vec::new(), + } + } +} + +impl VecMap { + pub fn with_capacity(capacity: usize) -> Self { + Self { + keys: Vec::with_capacity(capacity), + values: Vec::with_capacity(capacity), + } + } + + pub fn len(&self) -> usize { + debug_assert_eq!(self.keys.len(), self.values.len()); + self.keys.len() + } + + pub fn is_empty(&self) -> bool { + debug_assert_eq!(self.keys.len(), self.values.len()); + self.keys.is_empty() + } + + pub fn swap_remove(&mut self, index: usize) -> (K, V) { + let k = self.keys.swap_remove(index); + let v = self.values.swap_remove(index); + + (k, v) + } + + pub fn insert(&mut self, key: K, mut value: V) -> Option { + match self.keys.iter().position(|x| x == &key) { + Some(index) => { + std::mem::swap(&mut value, &mut self.values[index]); + + Some(value) + } + None => { + self.keys.push(key); + self.values.push(value); + + None + } + } + } + + pub fn contains(&self, key: &K) -> bool { + self.keys.contains(key) + } + + pub fn remove(&mut self, key: &K) { + match self.keys.iter().position(|x| x == key) { + None => { + // just do nothing + } + Some(index) => { + self.swap_remove(index); + } + } + } + + pub fn iter(&self) -> impl Iterator { + self.keys.iter().zip(self.values.iter()) + } + + pub fn values(&self) -> impl Iterator { + self.values.iter() + } +} + +impl Extend<(K, V)> for VecMap { + #[inline(always)] + fn extend>(&mut self, iter: T) { + let it = iter.into_iter(); + let hint = it.size_hint(); + + match hint { + (0, Some(0)) => { + // done, do nothing + } + (1, Some(1)) | (2, Some(2)) => { + for (k, v) in it { + self.insert(k, v); + } + } + (_min, _opt_max) => { + // TODO do this with sorting and dedup? + for (k, v) in it { + self.insert(k, v); + } + } + } + } +} + +impl IntoIterator for VecMap { + type Item = (K, V); + + type IntoIter = IntoIter; + + fn into_iter(self) -> Self::IntoIter { + IntoIter { + keys: self.keys.into_iter(), + values: self.values.into_iter(), + } + } +} + +pub struct IntoIter { + keys: std::vec::IntoIter, + values: std::vec::IntoIter, +} + +impl Iterator for IntoIter { + type Item = (K, V); + + fn next(&mut self) -> Option { + match (self.keys.next(), self.values.next()) { + (Some(k), Some(v)) => Some((k, v)), + _ => None, + } + } +} From 19dce40cd18b31e5a58db394716fa81c7b48e569 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 20 Apr 2022 18:11:44 +0200 Subject: [PATCH 354/846] fix formatting --- compiler/can/src/annotation.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index 47f11353cf..07b1faac64 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -1,6 +1,6 @@ use crate::env::Env; use crate::scope::Scope; -use roc_collections::{ImMap, MutSet, SendMap, VecMap, VecSet}; +use roc_collections::{ImMap, MutSet, SendMap, VecMap, VecSet}; use roc_module::ident::{Ident, Lowercase, TagName}; use roc_module::symbol::{IdentIds, ModuleId, Symbol}; use roc_parse::ast::{AssignedField, ExtractSpaces, Pattern, Tag, TypeAnnotation, TypeHeader}; From b557929276e65cb2163e93f594246a604481bbdf Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 20 Apr 2022 20:22:02 +0200 Subject: [PATCH 355/846] compact References into just two allocations --- compiler/can/src/procedure.rs | 183 ++++++++++++++++++++++++---------- 1 file changed, 128 insertions(+), 55 deletions(-) diff --git a/compiler/can/src/procedure.rs b/compiler/can/src/procedure.rs index 34496bd09e..97cf8f762b 100644 --- a/compiler/can/src/procedure.rs +++ b/compiler/can/src/procedure.rs @@ -1,6 +1,5 @@ use crate::expr::Expr; use crate::pattern::Pattern; -use roc_collections::VecSet; use roc_module::symbol::Symbol; use roc_region::all::{Loc, Region}; use roc_types::subs::Variable; @@ -39,81 +38,155 @@ impl Procedure { } } -/// These are all ordered sets because they end up getting traversed in a graph search -/// to determine how defs should be ordered. We want builds to be reproducible, -/// so it's important that building the same code gives the same order every time! -#[derive(Clone, Debug, Default, PartialEq)] +#[derive(Debug, Default, Clone, Copy)] +struct ReferencesBitflags(u8); + +impl ReferencesBitflags { + const VALUE_LOOKUP: Self = ReferencesBitflags(1); + const TYPE_LOOKUP: Self = ReferencesBitflags(2); + const CALL: Self = ReferencesBitflags(4); + const BOUND: Self = ReferencesBitflags(8); +} + +#[derive(Clone, Debug, Default)] pub struct References { - bound_symbols: VecSet, - type_lookups: VecSet, - value_lookups: VecSet, - /// Aliases or opaque types referenced - referenced_type_defs: VecSet, - calls: VecSet, + symbols: Vec, + bitflags: Vec, } impl References { - pub fn new() -> References { + pub fn new() -> Self { Self::default() } - pub fn union_mut(&mut self, other: &References) { - self.value_lookups - .extend(other.value_lookups.iter().copied()); - self.type_lookups.extend(other.type_lookups.iter().copied()); - self.calls.extend(other.calls.iter().copied()); - self.bound_symbols - .extend(other.bound_symbols.iter().copied()); - self.referenced_type_defs - .extend(other.referenced_type_defs.iter().copied()); + pub fn union_mut(&mut self, other: &Self) { + for (k, v) in other.symbols.iter().zip(other.bitflags.iter()) { + self.insert(*k, *v); + } } - pub fn has_value_lookup(&self, symbol: Symbol) -> bool { - self.value_lookups.contains(&symbol) - } + // iterators - pub fn has_type_lookup(&self, symbol: Symbol) -> bool { - self.type_lookups.contains(&symbol) - } - - pub fn references_type_def(&self, symbol: Symbol) -> bool { - self.type_lookups.contains(&symbol) - } - - pub fn insert_value_lookup(&mut self, symbol: Symbol) { - self.value_lookups.insert(symbol); - } - - pub fn insert_bound(&mut self, symbol: Symbol) { - self.bound_symbols.insert(symbol); - } - - pub fn insert_call(&mut self, symbol: Symbol) { - self.calls.insert(symbol); - } - - pub fn remove_value_lookup(&mut self, symbol: &Symbol) { - self.value_lookups.remove(symbol); - } - - pub fn insert_type_lookup(&mut self, symbol: Symbol) { - self.type_lookups.insert(symbol); - self.referenced_type_defs.insert(symbol); + fn retain<'a, P: Fn(&'a ReferencesBitflags) -> bool>( + &'a self, + pred: P, + ) -> impl Iterator { + self.symbols + .iter() + .zip(self.bitflags.iter()) + .filter_map(move |(a, b)| if pred(b) { Some(a) } else { None }) } pub fn value_lookups(&self) -> impl Iterator { - self.value_lookups.iter() + self.retain(|b| b.0 & ReferencesBitflags::VALUE_LOOKUP.0 > 0) } pub fn type_lookups(&self) -> impl Iterator { - self.type_lookups.iter() + self.retain(|b| b.0 & ReferencesBitflags::TYPE_LOOKUP.0 > 0) } pub fn bound_symbols(&self) -> impl Iterator { - self.bound_symbols.iter() + self.retain(|b| b.0 & ReferencesBitflags::BOUND.0 > 0) } pub fn calls(&self) -> impl Iterator { - self.calls.iter() + self.retain(|b| b.0 & ReferencesBitflags::CALL.0 > 0) + } + + // insert + + fn insert(&mut self, symbol: Symbol, flags: ReferencesBitflags) { + match self.symbols.iter().position(|x| *x == symbol) { + None => { + self.symbols.push(symbol); + self.bitflags.push(flags); + } + Some(index) => { + // idea: put some debug_asserts in here? + self.bitflags[index].0 |= flags.0; + } + } + } + + pub fn insert_value_lookup(&mut self, symbol: Symbol) { + self.insert(symbol, ReferencesBitflags::VALUE_LOOKUP); + } + + pub fn insert_type_lookup(&mut self, symbol: Symbol) { + self.insert(symbol, ReferencesBitflags::TYPE_LOOKUP); + } + + pub fn insert_bound(&mut self, symbol: Symbol) { + self.insert(symbol, ReferencesBitflags::BOUND); + } + + pub fn insert_call(&mut self, symbol: Symbol) { + self.insert(symbol, ReferencesBitflags::CALL); + } + + // remove + + pub fn remove_value_lookup(&mut self, symbol: &Symbol) { + match self.symbols.iter().position(|x| x == symbol) { + None => { + // it's not in there; do nothing + } + Some(index) => { + // idea: put some debug_asserts in here? + self.bitflags[index].0 ^= ReferencesBitflags::VALUE_LOOKUP.0; + } + } + } + + // contains + + pub fn has_value_lookup(&self, symbol: Symbol) -> bool { + // println!("has a value lookup? {} {:?}", self.symbols.len(), symbol); + let it = self.symbols.iter().zip(self.bitflags.iter()); + + for (a, b) in it { + if *a == symbol && b.0 & ReferencesBitflags::VALUE_LOOKUP.0 > 0 { + return true; + } + } + + false + } + + pub fn has_type_lookup(&self, symbol: Symbol) -> bool { + let it = self.symbols.iter().zip(self.bitflags.iter()); + + for (a, b) in it { + if *a == symbol && b.0 & ReferencesBitflags::TYPE_LOOKUP.0 > 0 { + return true; + } + } + + false + } + + pub fn has_type_or_value_lookup(&self, symbol: Symbol) -> bool { + // if self.symbols.len() > 100 { + // panic!() + // } + // println!( + // "has a type or value lookup? {} {:?}", + // self.symbols.len(), + // symbol + // ); + let mask = ReferencesBitflags::VALUE_LOOKUP.0 | ReferencesBitflags::TYPE_LOOKUP.0; + let it = self.symbols.iter().zip(self.bitflags.iter()); + + for (a, b) in it { + if *a == symbol && b.0 & mask > 0 { + return true; + } + } + + false + } + + pub fn references_type_def(&self, symbol: Symbol) -> bool { + self.has_type_lookup(symbol) } } From 9d17a075d98f09b4852d4d239fe415aa8bba68d3 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 20 Apr 2022 20:22:52 +0200 Subject: [PATCH 356/846] halve the number of lookups into References --- compiler/can/src/def.rs | 3 +-- compiler/can/src/expr.rs | 6 ++---- compiler/can/src/module.rs | 3 +-- compiler/can/src/procedure.rs | 2 +- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 9235cd32ca..3d18978806 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1594,8 +1594,7 @@ pub fn can_defs_with_return<'a>( // Now that we've collected all the references, check to see if any of the new idents // we defined went unused by the return expression. If any were unused, report it. for (symbol, region) in symbols_introduced { - if !output.references.has_value_lookup(symbol) - && !output.references.has_type_lookup(symbol) + if !output.references.has_type_or_value_lookup(symbol) && !scope.abilities_store.is_specialization_name(symbol) { env.problem(Problem::UnusedDef(symbol, region)); diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index e8db25e794..be8dd26648 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -1072,10 +1072,8 @@ fn canonicalize_when_branch<'a>( for (symbol, region) in scope.symbols() { let symbol = *symbol; - if !output.references.has_value_lookup(symbol) - && !output.references.has_type_lookup(symbol) - && !branch_output.references.has_value_lookup(symbol) - && !branch_output.references.has_type_lookup(symbol) + if !output.references.has_type_or_value_lookup(symbol) + && !branch_output.references.has_type_or_value_lookup(symbol) && !original_scope.contains_symbol(symbol) && !scope.abilities_store.is_specialization_name(symbol) { diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index fa901a6cec..b34aba4fc5 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -302,8 +302,7 @@ pub fn canonicalize_module_defs<'a>( // See if any of the new idents we defined went unused. // If any were unused and also not exposed, report it. for (symbol, region) in symbols_introduced { - if !output.references.has_value_lookup(symbol) - && !output.references.has_type_lookup(symbol) + if !output.references.has_type_or_value_lookup(symbol) && !exposed_symbols.contains(&symbol) && !scope.abilities_store.is_specialization_name(symbol) { diff --git a/compiler/can/src/procedure.rs b/compiler/can/src/procedure.rs index 97cf8f762b..778688d74f 100644 --- a/compiler/can/src/procedure.rs +++ b/compiler/can/src/procedure.rs @@ -153,7 +153,7 @@ impl References { false } - pub fn has_type_lookup(&self, symbol: Symbol) -> bool { + fn has_type_lookup(&self, symbol: Symbol) -> bool { let it = self.symbols.iter().zip(self.bitflags.iter()); for (a, b) in it { From e87ca7e4b7f853e55f8778888df290caf1e8ceb0 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 20 Apr 2022 21:20:59 +0200 Subject: [PATCH 357/846] create and union fewer Output's --- compiler/can/src/def.rs | 46 +++++++++++++++++++++++++------------ compiler/can/src/expr.rs | 19 +++++++-------- compiler/can/src/pattern.rs | 45 +++++++++++++++++++----------------- 3 files changed, 63 insertions(+), 47 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 3d18978806..aca0206831 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -564,9 +564,17 @@ pub fn canonicalize_defs<'a>( // once we've finished assembling the entire scope. let mut pending_value_defs = Vec::with_capacity(value_defs.len()); for loc_def in value_defs.into_iter() { - match to_pending_value_def(env, var_store, loc_def.value, &mut scope, pattern_type) { + let mut new_output = Output::default(); + match to_pending_value_def( + env, + var_store, + loc_def.value, + &mut scope, + &mut new_output, + pattern_type, + ) { None => { /* skip */ } - Some((new_output, pending_def)) => { + Some(pending_def) => { // store the top-level defs, used to ensure that closures won't capture them if let PatternType::TopLevelDef = pattern_type { match &pending_def { @@ -1806,41 +1814,46 @@ fn to_pending_value_def<'a>( var_store: &mut VarStore, def: &'a ast::ValueDef<'a>, scope: &mut Scope, + output: &mut Output, pattern_type: PatternType, -) -> Option<(Output, PendingValueDef<'a>)> { +) -> Option> { use ast::ValueDef::*; match def { Annotation(loc_pattern, loc_ann) => { // This takes care of checking for shadowing and adding idents to scope. - let (output, loc_can_pattern) = canonicalize_def_header_pattern( + let loc_can_pattern = canonicalize_def_header_pattern( env, var_store, scope, + output, pattern_type, &loc_pattern.value, loc_pattern.region, ); - Some(( - output, - PendingValueDef::AnnotationOnly(loc_pattern, loc_can_pattern, loc_ann), + Some(PendingValueDef::AnnotationOnly( + loc_pattern, + loc_can_pattern, + loc_ann, )) } Body(loc_pattern, loc_expr) => { // This takes care of checking for shadowing and adding idents to scope. - let (output, loc_can_pattern) = canonicalize_def_header_pattern( + let loc_can_pattern = canonicalize_def_header_pattern( env, var_store, scope, + output, pattern_type, &loc_pattern.value, loc_pattern.region, ); - Some(( - output, - PendingValueDef::Body(loc_pattern, loc_can_pattern, loc_expr), + Some(PendingValueDef::Body( + loc_pattern, + loc_can_pattern, + loc_expr, )) } @@ -1859,18 +1872,21 @@ fn to_pending_value_def<'a>( // { x, y ? False } = rec // // This takes care of checking for shadowing and adding idents to scope. - let (output, loc_can_pattern) = canonicalize_def_header_pattern( + let loc_can_pattern = canonicalize_def_header_pattern( env, var_store, scope, + output, pattern_type, &body_pattern.value, body_pattern.region, ); - Some(( - output, - PendingValueDef::TypedBody(body_pattern, loc_can_pattern, ann_type, body_expr), + Some(PendingValueDef::TypedBody( + body_pattern, + loc_can_pattern, + ann_type, + body_expr, )) } else { // the pattern of the annotation does not match the pattern of the body direc diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index be8dd26648..10e9479f23 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -627,25 +627,23 @@ pub fn canonicalize_expr<'a>( let mut can_args = Vec::with_capacity(loc_arg_patterns.len()); let mut output = Output::default(); - let mut bound_by_argument_patterns = MutSet::default(); - for loc_pattern in loc_arg_patterns.iter() { - let (new_output, can_arg) = canonicalize_pattern( + let can_argument_pattern = canonicalize_pattern( env, var_store, &mut scope, + &mut output, FunctionArg, &loc_pattern.value, loc_pattern.region, ); - bound_by_argument_patterns.extend(new_output.references.bound_symbols().copied()); - - output.union(new_output); - - can_args.push((var_store.fresh(), can_arg)); + can_args.push((var_store.fresh(), can_argument_pattern)); } + let bound_by_argument_patterns: Vec<_> = + output.references.bound_symbols().copied().collect(); + let (loc_body_expr, new_output) = canonicalize_expr( env, var_store, @@ -1034,17 +1032,16 @@ fn canonicalize_when_branch<'a>( // TODO report symbols not bound in all patterns for loc_pattern in branch.patterns.iter() { - let (new_output, can_pattern) = canonicalize_pattern( + let can_pattern = canonicalize_pattern( env, var_store, &mut scope, + output, WhenBranch, &loc_pattern.value, loc_pattern.region, ); - output.union(new_output); - patterns.push(can_pattern); } diff --git a/compiler/can/src/pattern.rs b/compiler/can/src/pattern.rs index dc8a11a5b0..9804707b2c 100644 --- a/compiler/can/src/pattern.rs +++ b/compiler/can/src/pattern.rs @@ -156,13 +156,13 @@ pub fn canonicalize_def_header_pattern<'a>( env: &mut Env<'a>, var_store: &mut VarStore, scope: &mut Scope, + output: &mut Output, pattern_type: PatternType, pattern: &ast::Pattern<'a>, region: Region, -) -> (Output, Loc) { +) -> Loc { use roc_parse::ast::Pattern::*; - let mut output = Output::default(); match pattern { // Identifiers that shadow ability members may appear (and may only appear) at the header of a def. Identifier(name) => match scope.introduce_or_shadow_ability_member( @@ -182,7 +182,7 @@ pub fn canonicalize_def_header_pattern<'a>( specializes: ability_member_name, }, }; - (output, Loc::at(region, can_pattern)) + Loc::at(region, can_pattern) } Err((original_region, shadow, new_symbol)) => { env.problem(Problem::RuntimeError(RuntimeError::Shadowing { @@ -193,10 +193,10 @@ pub fn canonicalize_def_header_pattern<'a>( output.references.insert_bound(new_symbol); let can_pattern = Pattern::Shadowed(original_region, shadow, new_symbol); - (output, Loc::at(region, can_pattern)) + Loc::at(region, can_pattern) } }, - _ => canonicalize_pattern(env, var_store, scope, pattern_type, pattern, region), + _ => canonicalize_pattern(env, var_store, scope, output, pattern_type, pattern, region), } } @@ -204,14 +204,14 @@ pub fn canonicalize_pattern<'a>( env: &mut Env<'a>, var_store: &mut VarStore, scope: &mut Scope, + output: &mut Output, pattern_type: PatternType, pattern: &ast::Pattern<'a>, region: Region, -) -> (Output, Loc) { +) -> Loc { use roc_parse::ast::Pattern::*; use PatternType::*; - let mut output = Output::default(); let can_pattern = match pattern { Identifier(name) => match scope.introduce( (*name).into(), @@ -266,17 +266,16 @@ pub fn canonicalize_pattern<'a>( Apply(tag, patterns) => { let mut can_patterns = Vec::with_capacity(patterns.len()); for loc_pattern in *patterns { - let (new_output, can_pattern) = canonicalize_pattern( + let can_pattern = canonicalize_pattern( env, var_store, scope, + output, pattern_type, &loc_pattern.value, loc_pattern.region, ); - output.union(new_output); - can_patterns.push((var_store.fresh(), can_pattern)); } @@ -442,7 +441,15 @@ pub fn canonicalize_pattern<'a>( } SpaceBefore(sub_pattern, _) | SpaceAfter(sub_pattern, _) => { - return canonicalize_pattern(env, var_store, scope, pattern_type, sub_pattern, region) + return canonicalize_pattern( + env, + var_store, + scope, + output, + pattern_type, + sub_pattern, + region, + ) } RecordDestructure(patterns) => { let ext_var = var_store.fresh(); @@ -492,17 +499,16 @@ pub fn canonicalize_pattern<'a>( RequiredField(label, loc_guard) => { // a guard does not introduce the label into scope! let symbol = scope.ignore(label.into(), &mut env.ident_ids); - let (new_output, can_guard) = canonicalize_pattern( + let can_guard = canonicalize_pattern( env, var_store, scope, + output, pattern_type, &loc_guard.value, loc_guard.region, ); - output.union(new_output); - destructs.push(Loc { region: loc_pattern.region, value: RecordDestruct { @@ -597,13 +603,10 @@ pub fn canonicalize_pattern<'a>( } }; - ( - output, - Loc { - region, - value: can_pattern, - }, - ) + Loc { + region, + value: can_pattern, + } } /// When we detect an unsupported pattern type (e.g. 5 = 1 + 2 is unsupported because you can't From 62484d3890a62fc264c0643c56a9c20c7df46f5d Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 20 Apr 2022 13:50:00 -0400 Subject: [PATCH 358/846] Add `roc run` to run even if there are build errors. --- cli/src/build.rs | 46 ++++--------- cli/src/lib.rs | 126 +++++++++++++++++++++------------- cli/src/main.rs | 28 ++++++-- compiler/build/src/program.rs | 32 +++++++-- 4 files changed, 141 insertions(+), 91 deletions(-) diff --git a/cli/src/build.rs b/cli/src/build.rs index 0ccf118178..a898d7eb6f 100644 --- a/cli/src/build.rs +++ b/cli/src/build.rs @@ -1,7 +1,7 @@ use bumpalo::Bump; use roc_build::{ link::{link, rebuild_host, LinkType}, - program, + program::{self, Problems}, }; use roc_builtins::bitcode; use roc_load::LoadingProblem; @@ -21,25 +21,9 @@ fn report_timing(buf: &mut String, label: &str, duration: Duration) { )); } -pub enum BuildOutcome { - NoProblems, - OnlyWarnings, - Errors, -} - -impl BuildOutcome { - pub fn status_code(&self) -> i32 { - match self { - Self::NoProblems => 0, - Self::OnlyWarnings => 1, - Self::Errors => 2, - } - } -} - pub struct BuiltFile { pub binary_path: PathBuf, - pub outcome: BuildOutcome, + pub problems: Problems, pub total_time: Duration, } @@ -184,7 +168,7 @@ pub fn build_file<'a>( // This only needs to be mutable for report_problems. This can't be done // inside a nested scope without causing a borrow error! let mut loaded = loaded; - program::report_problems_monomorphized(&mut loaded); + let problems = program::report_problems_monomorphized(&mut loaded); let loaded = loaded; let code_gen_timing = program::gen_from_mono_module( @@ -243,7 +227,7 @@ pub fn build_file<'a>( // Step 2: link the precompiled host and compiled app let link_start = SystemTime::now(); - let outcome = if surgically_link { + let problems = if surgically_link { roc_linker::link_preprocessed_host(target, &host_input_path, app_o_file, &binary_path) .map_err(|err| { todo!( @@ -251,12 +235,12 @@ pub fn build_file<'a>( err ); })?; - BuildOutcome::NoProblems + problems } else if matches!(link_type, LinkType::None) { // Just copy the object file to the output folder. binary_path.set_extension(app_extension); std::fs::copy(app_o_file, &binary_path).unwrap(); - BuildOutcome::NoProblems + problems } else { let mut inputs = vec![ host_input_path.as_path().to_str().unwrap(), @@ -281,11 +265,15 @@ pub fn build_file<'a>( todo!("gracefully handle error after `ld` spawned"); })?; - // TODO change this to report whether there were errors or warnings! if exit_status.success() { - BuildOutcome::NoProblems + problems } else { - BuildOutcome::Errors + let mut problems = problems; + + // Add an error for `ld` failing + problems.errors += 1; + + problems } }; let linking_time = link_start.elapsed().unwrap(); @@ -298,7 +286,7 @@ pub fn build_file<'a>( Ok(BuiltFile { binary_path, - outcome, + problems, total_time, }) } @@ -350,10 +338,6 @@ fn spawn_rebuild_thread( } let rebuild_host_end = rebuild_host_start.elapsed().unwrap(); - if !precompiled { - println!("Done!"); - } - rebuild_host_end.as_millis() }) } @@ -364,7 +348,7 @@ pub fn check_file( src_dir: PathBuf, roc_file_path: PathBuf, emit_timings: bool, -) -> Result { +) -> Result { let compilation_start = SystemTime::now(); // only used for generating errors. We don't do code generation, so hardcoding should be fine diff --git a/cli/src/lib.rs b/cli/src/lib.rs index e64aeb9d63..6a503b80b5 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -1,7 +1,7 @@ #[macro_use] extern crate const_format; -use build::{BuildOutcome, BuiltFile}; +use build::BuiltFile; use bumpalo::Bump; use clap::{App, AppSettings, Arg, ArgMatches}; use roc_build::link::LinkType; @@ -24,6 +24,7 @@ mod format; pub use format::format; pub const CMD_BUILD: &str = "build"; +pub const CMD_RUN: &str = "run"; pub const CMD_REPL: &str = "repl"; pub const CMD_EDIT: &str = "edit"; pub const CMD_DOCS: &str = "docs"; @@ -142,6 +143,14 @@ pub fn build_app<'a>() -> App<'a> { .subcommand(App::new(CMD_REPL) .about("Launch the interactive Read Eval Print Loop (REPL)") ) + .subcommand(App::new(CMD_RUN) + .about("Run a .roc file even if it has build errors") + .arg( + Arg::new(ROC_FILE) + .about("The .roc file of an app to run") + .required(true), + ) + ) .subcommand(App::new(CMD_FORMAT) .about("Format a .roc file using standard Roc formatting") .arg( @@ -168,7 +177,7 @@ pub fn build_app<'a>() -> App<'a> { ) .arg( Arg::new(ROC_FILE) - .about("The .roc file of an app to run") + .about("The .roc file of an app to check") .required(true), ) ) @@ -273,6 +282,7 @@ pub fn docs(files: Vec) { pub enum BuildConfig { BuildOnly, BuildAndRun { roc_file_arg_index: usize }, + BuildAndRunIfNoErrors { roc_file_arg_index: usize }, } pub enum FormatMode { @@ -380,7 +390,7 @@ pub fn build(matches: &ArgMatches, config: BuildConfig) -> io::Result { match res_binary_path { Ok(BuiltFile { binary_path, - outcome, + problems, total_time, }) => { match config { @@ -401,50 +411,26 @@ pub fn build(matches: &ArgMatches, config: BuildConfig) -> io::Result { ); // Return a nonzero exit code if there were problems - Ok(outcome.status_code()) + Ok(problems.exit_code()) } - BuildAndRun { roc_file_arg_index } => { - let mut cmd = match triple.architecture { - Architecture::Wasm32 => { - // If possible, report the generated executable name relative to the current dir. - let generated_filename = binary_path - .strip_prefix(env::current_dir().unwrap()) - .unwrap_or(&binary_path); - - // No need to waste time freeing this memory, - // since the process is about to exit anyway. - std::mem::forget(arena); - - let args = std::env::args() - .skip(roc_file_arg_index) - .collect::>(); - - run_with_wasmer(generated_filename, &args); - return Ok(0); - } - _ => Command::new(&binary_path), - }; - - if let Architecture::Wasm32 = triple.architecture { - cmd.arg(binary_path); - } - - // Forward all the arguments after the .roc file argument - // to the new process. This way, you can do things like: - // - // roc app.roc foo bar baz - // - // ...and have it so that app.roc will receive only `foo`, - // `bar`, and `baz` as its arguments. - for (index, arg) in std::env::args().enumerate() { - if index > roc_file_arg_index { - cmd.arg(arg); - } - } - - match outcome { - BuildOutcome::Errors => Ok(outcome.status_code()), - _ => roc_run(cmd.current_dir(original_cwd)), + BuildAndRun { roc_file_arg_index } => roc_run( + &arena, + &original_cwd, + triple, + roc_file_arg_index, + &binary_path, + ), + BuildAndRunIfNoErrors { roc_file_arg_index } => { + if problems.errors == 0 { + roc_run( + &arena, + &original_cwd, + triple, + roc_file_arg_index, + &binary_path, + ) + } else { + Ok(problems.exit_code()) } } } @@ -461,11 +447,55 @@ pub fn build(matches: &ArgMatches, config: BuildConfig) -> io::Result { } #[cfg(target_family = "unix")] -fn roc_run(cmd: &mut Command) -> io::Result { +fn roc_run( + arena: &Bump, + cwd: &Path, + triple: Triple, + roc_file_arg_index: usize, + binary_path: &Path, +) -> io::Result { use std::os::unix::process::CommandExt; + let mut cmd = match triple.architecture { + Architecture::Wasm32 => { + // If possible, report the generated executable name relative to the current dir. + let generated_filename = binary_path + .strip_prefix(env::current_dir().unwrap()) + .unwrap_or(&binary_path); + + // No need to waste time freeing this memory, + // since the process is about to exit anyway. + std::mem::forget(arena); + + let args = std::env::args() + .skip(roc_file_arg_index) + .collect::>(); + + run_with_wasmer(generated_filename, &args); + return Ok(0); + } + _ => Command::new(&binary_path), + }; + + if let Architecture::Wasm32 = triple.architecture { + cmd.arg(binary_path); + } + + // Forward all the arguments after the .roc file argument + // to the new process. This way, you can do things like: + // + // roc app.roc foo bar baz + // + // ...and have it so that app.roc will receive only `foo`, + // `bar`, and `baz` as its arguments. + for (index, arg) in std::env::args().enumerate() { + if index > roc_file_arg_index { + cmd.arg(arg); + } + } + // This is much faster than spawning a subprocess if we're on a UNIX system! - let err = cmd.exec(); + let err = cmd.current_dir(cwd).exec(); // If exec actually returned, it was definitely an error! (Otherwise, // this process would have been replaced by the other one, and we'd diff --git a/cli/src/main.rs b/cli/src/main.rs index 6a5c984ef3..871e93af9a 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -1,7 +1,8 @@ use roc_cli::build::check_file; use roc_cli::{ build_app, docs, format, BuildConfig, FormatMode, CMD_BUILD, CMD_CHECK, CMD_DOCS, CMD_EDIT, - CMD_FORMAT, CMD_REPL, CMD_VERSION, DIRECTORY_OR_FILES, FLAG_CHECK, FLAG_TIME, ROC_FILE, + CMD_FORMAT, CMD_REPL, CMD_RUN, CMD_VERSION, DIRECTORY_OR_FILES, FLAG_CHECK, FLAG_TIME, + ROC_FILE, }; use roc_load::LoadingProblem; use std::fs::{self, FileType}; @@ -27,7 +28,10 @@ fn main() -> io::Result<()> { Some(arg_index) => { let roc_file_arg_index = arg_index + 1; // Not sure why this +1 is necessary, but it is! - build(&matches, BuildConfig::BuildAndRun { roc_file_arg_index }) + build( + &matches, + BuildConfig::BuildAndRunIfNoErrors { roc_file_arg_index }, + ) } None => { @@ -37,6 +41,21 @@ fn main() -> io::Result<()> { } } } + Some((CMD_RUN, matches)) => { + match matches.index_of(ROC_FILE) { + Some(arg_index) => { + let roc_file_arg_index = arg_index + 1; // Not sure why this +1 is necessary, but it is! + + build(&matches, BuildConfig::BuildAndRun { roc_file_arg_index }) + } + + None => { + eprintln!("What .roc file do you want to run? Specify it at the end of the `roc run` command."); + + Ok(1) + } + } + } Some((CMD_BUILD, matches)) => Ok(build(matches, BuildConfig::BuildOnly)?), Some((CMD_CHECK, matches)) => { let arena = bumpalo::Bump::new(); @@ -47,10 +66,7 @@ fn main() -> io::Result<()> { let src_dir = roc_file_path.parent().unwrap().to_owned(); match check_file(&arena, src_dir, roc_file_path, emit_timings) { - Ok(number_of_errors) => { - let exit_code = if number_of_errors != 0 { 1 } else { 0 }; - Ok(exit_code) - } + Ok(problems) => Ok(problems.exit_code()), Err(LoadingProblem::FormattedReport(report)) => { print!("{}", report); diff --git a/compiler/build/src/program.rs b/compiler/build/src/program.rs index 518bc0c3e4..3d8ac5e456 100644 --- a/compiler/build/src/program.rs +++ b/compiler/build/src/program.rs @@ -28,7 +28,7 @@ const LLVM_VERSION: &str = "12"; // them after type checking (like Elm does) so we can complete the entire // `roc check` process without needing to monomorphize. /// Returns the number of problems reported. -pub fn report_problems_monomorphized(loaded: &mut MonomorphizedModule) -> usize { +pub fn report_problems_monomorphized(loaded: &mut MonomorphizedModule) -> Problems { report_problems_help( loaded.total_problems(), &loaded.sources, @@ -39,7 +39,7 @@ pub fn report_problems_monomorphized(loaded: &mut MonomorphizedModule) -> usize ) } -pub fn report_problems_typechecked(loaded: &mut LoadedModule) -> usize { +pub fn report_problems_typechecked(loaded: &mut LoadedModule) -> Problems { report_problems_help( loaded.total_problems(), &loaded.sources, @@ -50,6 +50,23 @@ pub fn report_problems_typechecked(loaded: &mut LoadedModule) -> usize { ) } +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] +pub struct Problems { + pub errors: usize, + pub warnings: usize, +} + +impl Problems { + pub fn exit_code(&self) -> i32 { + // 0 means no problems, 1 means errors, 2 means warnings + if self.errors > 0 { + 1 + } else { + self.warnings.min(1) as i32 + } + } +} + fn report_problems_help( total_problems: usize, sources: &MutMap)>, @@ -57,7 +74,7 @@ fn report_problems_help( can_problems: &mut MutMap>, type_problems: &mut MutMap>, mono_problems: &mut MutMap>, -) -> usize { +) -> Problems { use roc_reporting::report::{ can_problem, mono_problem, type_problem, Report, RocDocAllocator, Severity::*, DEFAULT_PALETTE, @@ -144,13 +161,13 @@ fn report_problems_help( if errors.is_empty() { problems_reported = warnings.len(); - for warning in warnings { + for warning in warnings.iter() { println!("\n{}\n", warning); } } else { problems_reported = errors.len(); - for error in errors { + for error in errors.iter() { println!("\n{}\n", error); } } @@ -165,7 +182,10 @@ fn report_problems_help( println!("{}\u{001B}[0m\n", Report::horizontal_rule(&palette)); } - problems_reported + Problems { + errors: errors.len(), + warnings: warnings.len(), + } } #[cfg(not(feature = "llvm"))] From 4d11e7cbe6580eb84f6063f813739b9d66ab7be9 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 20 Apr 2022 16:47:25 -0400 Subject: [PATCH 359/846] Revamp notes printed after compilation finishes. --- cli/src/build.rs | 9 ++-- cli/src/lib.rs | 116 +++++++++++++++++++++++++++++++++++++++++++---- cli/src/main.rs | 31 ++++++++++++- 3 files changed, 142 insertions(+), 14 deletions(-) diff --git a/cli/src/build.rs b/cli/src/build.rs index a898d7eb6f..be2bd0736e 100644 --- a/cli/src/build.rs +++ b/cli/src/build.rs @@ -306,7 +306,7 @@ fn spawn_rebuild_thread( let thread_local_target = target.clone(); std::thread::spawn(move || { if !precompiled { - print!("🔨 Rebuilding host... "); + println!("🔨 Rebuilding host..."); } let rebuild_host_start = SystemTime::now(); @@ -348,7 +348,7 @@ pub fn check_file( src_dir: PathBuf, roc_file_path: PathBuf, emit_timings: bool, -) -> Result { +) -> Result<(program::Problems, Duration), LoadingProblem> { let compilation_start = SystemTime::now(); // only used for generating errors. We don't do code generation, so hardcoding should be fine @@ -421,5 +421,8 @@ pub fn check_file( println!("Finished checking in {} ms\n", compilation_end.as_millis(),); } - Ok(program::report_problems_typechecked(&mut loaded)) + Ok(( + program::report_problems_typechecked(&mut loaded), + compilation_end, + )) } diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 6a503b80b5..e92ff626a5 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -405,23 +405,91 @@ pub fn build(matches: &ArgMatches, config: BuildConfig) -> io::Result { std::mem::forget(arena); println!( - "🎉 Built {} in {} ms", - generated_filename.to_str().unwrap(), - total_time.as_millis() + "\x1B[{}m{}\x1B[39m {} and \x1B[{}m{}\x1B[39m {} found in {} ms while sucessfully building:\n\n {}", + if problems.errors == 0 { + 32 // green + } else { + 33 // yellow + }, + problems.errors, + if problems.errors == 1 { + "error" + } else { + "errors" + }, + if problems.warnings == 0 { + 32 // green + } else { + 33 // yellow + }, + problems.warnings, + if problems.warnings == 1 { + "warning" + } else { + "warnings" + }, + total_time.as_millis(), + generated_filename.to_str().unwrap() ); // Return a nonzero exit code if there were problems Ok(problems.exit_code()) } - BuildAndRun { roc_file_arg_index } => roc_run( - &arena, - &original_cwd, - triple, - roc_file_arg_index, - &binary_path, - ), + BuildAndRun { roc_file_arg_index } => { + if problems.errors > 0 || problems.warnings > 0 { + println!( + "\x1B[{}m{}\x1B[39m {} and \x1B[{}m{}\x1B[39m {} found in {} ms.\n\nRunning program anyway…\n\n\x1B[36m{}\x1B[39m", + if problems.errors == 0 { + 32 // green + } else { + 33 // yellow + }, + problems.errors, + if problems.errors == 1 { + "error" + } else { + "errors" + }, + if problems.warnings == 0 { + 32 // green + } else { + 33 // yellow + }, + problems.warnings, + if problems.warnings == 1 { + "warning" + } else { + "warnings" + }, + total_time.as_millis(), + "─".repeat(80) + ); + } + + roc_run( + &arena, + &original_cwd, + triple, + roc_file_arg_index, + &binary_path, + ) + } BuildAndRunIfNoErrors { roc_file_arg_index } => { if problems.errors == 0 { + if problems.warnings > 0 { + println!( + "\x1B[32m0\x1B[39m errors and \x1B[33m{}\x1B[39m {} found in {} ms.\n\nRunning program…\n\n\x1B[36m{}\x1B[39m", + problems.warnings, + if problems.warnings == 1 { + "warning" + } else { + "warnings" + }, + total_time.as_millis(), + "─".repeat(80) + ); + } + roc_run( &arena, &original_cwd, @@ -430,6 +498,34 @@ pub fn build(matches: &ArgMatches, config: BuildConfig) -> io::Result { &binary_path, ) } else { + println!( + "\x1B[{}m{}\x1B[39m {} and \x1B[{}m{}\x1B[39m {} found in {} ms.\n\nYou can run the program anyway with: \x1B[32mroc run {}\x1B[39m", + if problems.errors == 0 { + 32 // green + } else { + 33 // yellow + }, + problems.errors, + if problems.errors == 1 { + "error" + } else { + "errors" + }, + if problems.warnings == 0 { + 32 // green + } else { + 33 // yellow + }, + problems.warnings, + if problems.warnings == 1 { + "warning" + } else { + "warnings" + }, + total_time.as_millis(), + filename + ); + Ok(problems.exit_code()) } } diff --git a/cli/src/main.rs b/cli/src/main.rs index 871e93af9a..a657aedc3d 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -66,7 +66,36 @@ fn main() -> io::Result<()> { let src_dir = roc_file_path.parent().unwrap().to_owned(); match check_file(&arena, src_dir, roc_file_path, emit_timings) { - Ok(problems) => Ok(problems.exit_code()), + Ok((problems, total_time)) => { + println!( + "\x1B[{}m{}\x1B[39m {} and \x1B[{}m{}\x1B[39m {} found in {} ms.", + if problems.errors == 0 { + 32 // green + } else { + 33 // yellow + }, + problems.errors, + if problems.errors == 1 { + "error" + } else { + "errors" + }, + if problems.warnings == 0 { + 32 // green + } else { + 33 // yellow + }, + problems.warnings, + if problems.warnings == 1 { + "warning" + } else { + "warnings" + }, + total_time.as_millis(), + ); + + Ok(problems.exit_code()) + } Err(LoadingProblem::FormattedReport(report)) => { print!("{}", report); From 729aab21a1801c776d0c230d8803e79351d519e8 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 20 Apr 2022 17:06:17 -0400 Subject: [PATCH 360/846] Don't try to mem::forget a reference --- cli/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index e92ff626a5..fce91935d9 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -467,7 +467,7 @@ pub fn build(matches: &ArgMatches, config: BuildConfig) -> io::Result { } roc_run( - &arena, + arena, &original_cwd, triple, roc_file_arg_index, @@ -491,7 +491,7 @@ pub fn build(matches: &ArgMatches, config: BuildConfig) -> io::Result { } roc_run( - &arena, + arena, &original_cwd, triple, roc_file_arg_index, @@ -544,7 +544,7 @@ pub fn build(matches: &ArgMatches, config: BuildConfig) -> io::Result { #[cfg(target_family = "unix")] fn roc_run( - arena: &Bump, + arena: Bump, // This should be passed an owned value, not a reference, so we can usefully mem::forget it! cwd: &Path, triple: Triple, roc_file_arg_index: usize, From 41fafd85fd7ec92a2a578cab575e2a076449c08a Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 20 Apr 2022 17:06:20 -0400 Subject: [PATCH 361/846] C L I P P Y --- cli/src/lib.rs | 2 +- cli/src/main.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index fce91935d9..ced6c61823 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -557,7 +557,7 @@ fn roc_run( // If possible, report the generated executable name relative to the current dir. let generated_filename = binary_path .strip_prefix(env::current_dir().unwrap()) - .unwrap_or(&binary_path); + .unwrap_or(binary_path); // No need to waste time freeing this memory, // since the process is about to exit anyway. diff --git a/cli/src/main.rs b/cli/src/main.rs index a657aedc3d..b38445980b 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -46,7 +46,7 @@ fn main() -> io::Result<()> { Some(arg_index) => { let roc_file_arg_index = arg_index + 1; // Not sure why this +1 is necessary, but it is! - build(&matches, BuildConfig::BuildAndRun { roc_file_arg_index }) + build(matches, BuildConfig::BuildAndRun { roc_file_arg_index }) } None => { From 6c1e8d3789d5860a65fe7dd051e9e64217730b29 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 20 Apr 2022 17:14:22 -0400 Subject: [PATCH 362/846] fix typo --- cli/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index ced6c61823..25f831d1f0 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -405,7 +405,7 @@ pub fn build(matches: &ArgMatches, config: BuildConfig) -> io::Result { std::mem::forget(arena); println!( - "\x1B[{}m{}\x1B[39m {} and \x1B[{}m{}\x1B[39m {} found in {} ms while sucessfully building:\n\n {}", + "\x1B[{}m{}\x1B[39m {} and \x1B[{}m{}\x1B[39m {} found in {} ms while successfully building:\n\n {}", if problems.errors == 0 { 32 // green } else { From a07323fb40b7ffef3b33948bb4d4b9489da96db6 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 19 Apr 2022 13:03:08 -0400 Subject: [PATCH 363/846] Typecheck annotations with able variables outside ability members --- compiler/can/src/annotation.rs | 34 ++---------------- compiler/can/src/def.rs | 35 +++++++++++++----- compiler/solve/tests/solve_expr.rs | 57 ++++++++++++++++++++++++++++++ compiler/types/src/pretty_print.rs | 2 ++ 4 files changed, 88 insertions(+), 40 deletions(-) diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index 97b74f2101..09395d3e3f 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -187,37 +187,8 @@ fn malformed(env: &mut Env, region: Region, name: &str) { env.problem(roc_problem::can::Problem::RuntimeError(problem)); } +/// Canonicalizes a top-level type annotation. pub fn canonicalize_annotation( - env: &mut Env, - scope: &mut Scope, - annotation: &roc_parse::ast::TypeAnnotation, - region: Region, - var_store: &mut VarStore, -) -> Annotation { - let mut introduced_variables = IntroducedVariables::default(); - let mut references = VecSet::default(); - let mut aliases = SendMap::default(); - - let typ = can_annotation_help( - env, - annotation, - region, - scope, - var_store, - &mut introduced_variables, - &mut aliases, - &mut references, - ); - - Annotation { - typ, - introduced_variables, - references, - aliases, - } -} - -pub fn canonicalize_annotation_with_possible_clauses( env: &mut Env, scope: &mut Scope, annotation: &TypeAnnotation, @@ -828,8 +799,7 @@ fn can_annotation_help( Where(_annotation, clauses) => { debug_assert!(!clauses.is_empty()); - // Has clauses are allowed only on the top level of an ability member signature (for - // now), which we handle elsewhere. + // Has clauses are allowed only on the top level of a signature, which we handle elsewhere. env.problem(roc_problem::can::Problem::IllegalHasClause { region: Region::across_all(clauses.iter().map(|clause| &clause.region)), }); diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 2cc1cd85ae..6b9c4450c5 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1,6 +1,5 @@ use crate::abilities::MemberVariables; use crate::annotation::canonicalize_annotation; -use crate::annotation::canonicalize_annotation_with_possible_clauses; use crate::annotation::IntroducedVariables; use crate::env::Env; use crate::expr::ClosureData; @@ -318,8 +317,14 @@ pub fn canonicalize_defs<'a>( match type_defs.remove(&type_name).unwrap() { TypeDef::AliasLike(name, vars, ann, kind) => { let symbol = name.value; - let can_ann = - canonicalize_annotation(env, &mut scope, &ann.value, ann.region, var_store); + let can_ann = canonicalize_annotation( + env, + &mut scope, + &ann.value, + ann.region, + var_store, + &abilities_in_scope, + ); // Does this alias reference any abilities? For now, we don't permit that. let ability_references = can_ann @@ -437,7 +442,7 @@ pub fn canonicalize_defs<'a>( let mut can_members = Vec::with_capacity(members.len()); for member in members { - let member_annot = canonicalize_annotation_with_possible_clauses( + let member_annot = canonicalize_annotation( env, &mut scope, &member.typ.value, @@ -605,6 +610,7 @@ pub fn canonicalize_defs<'a>( var_store, &mut refs_by_symbol, &mut aliases, + &abilities_in_scope, ); // TODO we should do something with these references; they include @@ -1148,6 +1154,7 @@ fn canonicalize_pending_value_def<'a>( var_store: &mut VarStore, refs_by_symbol: &mut MutMap, aliases: &mut ImMap, + abilities_in_scope: &[Symbol], ) -> Output { use PendingValueDef::*; @@ -1159,8 +1166,14 @@ fn canonicalize_pending_value_def<'a>( AnnotationOnly(_, loc_can_pattern, loc_ann) => { // annotation sans body cannot introduce new rigids that are visible in other annotations // but the rigids can show up in type error messages, so still register them - let type_annotation = - canonicalize_annotation(env, scope, &loc_ann.value, loc_ann.region, var_store); + let type_annotation = canonicalize_annotation( + env, + scope, + &loc_ann.value, + loc_ann.region, + var_store, + abilities_in_scope, + ); // Record all the annotation's references in output.references.lookups @@ -1280,8 +1293,14 @@ fn canonicalize_pending_value_def<'a>( } TypedBody(_loc_pattern, loc_can_pattern, loc_ann, loc_expr) => { - let type_annotation = - canonicalize_annotation(env, scope, &loc_ann.value, loc_ann.region, var_store); + let type_annotation = canonicalize_annotation( + env, + scope, + &loc_ann.value, + loc_ann.region, + var_store, + &abilities_in_scope, + ); // Record all the annotation's references in output.references.lookups for symbol in type_annotation.references.iter() { diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index 54bd3626d6..b31b6502b7 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -5951,4 +5951,61 @@ mod solve_expr { "{ tag : [ A, B ] }a -> { tag : [ A, B ] }a", ) } + + #[test] + fn ability_constrained_in_non_member_check() { + infer_eq_without_problem( + indoc!( + r#" + app "test" provides [ hashEq ] to "./platform" + + Hash has + hash : a -> U64 | a has Hash + + hashEq : a, a -> Bool | a has Hash + hashEq = \x, y -> hash x == hash y + "# + ), + "a, a -> Bool | a has Hash", + ) + } + + #[test] + fn ability_constrained_in_non_member_infer() { + infer_eq_without_problem( + indoc!( + r#" + app "test" provides [ hashEq ] to "./platform" + + Hash has + hash : a -> U64 | a has Hash + + hashEq = \x, y -> hash x == hash y + "# + ), + "a, a -> Bool | a has Hash", + ) + } + + #[test] + fn ability_constrained_in_non_member_infer_usage() { + infer_eq_without_problem( + indoc!( + r#" + app "test" provides [ result ] to "./platform" + + Hash has + hash : a -> U64 | a has Hash + + hashEq = \x, y -> hash x == hash y + + Id := U64 + hash = \$Id n -> n + + result = hashEq ($Id 100) ($Id 101) + "# + ), + "Bool", + ) + } } diff --git a/compiler/types/src/pretty_print.rs b/compiler/types/src/pretty_print.rs index 998684d777..ddcb05895a 100644 --- a/compiler/types/src/pretty_print.rs +++ b/compiler/types/src/pretty_print.rs @@ -307,6 +307,8 @@ pub fn content_to_string( write_content(&env, &mut ctx, content, subs, &mut buf, Parens::Unnecessary); + ctx.able_variables.sort(); + ctx.able_variables.dedup(); for (i, (var, ability)) in ctx.able_variables.into_iter().enumerate() { buf.push_str(if i == 0 { " | " } else { ", " }); buf.push_str(var); From b9f79fdd31fa65be79dfe714d32d8cc75e666da2 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 19 Apr 2022 13:09:40 -0400 Subject: [PATCH 364/846] Able variables through different functions compile --- compiler/can/src/def.rs | 4 ++++ compiler/test_gen/src/gen_abilities.rs | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 6b9c4450c5..2b981510f0 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -478,6 +478,10 @@ pub fn canonicalize_defs<'a>( } }; + if pattern_type == PatternType::TopLevelDef { + env.top_level_symbols.insert(member_sym); + } + // What variables in the annotation are bound to the parent ability, and what variables // are bound to some other ability? let (variables_bound_to_ability, variables_bound_to_other_abilities): (Vec<_>, Vec<_>) = diff --git a/compiler/test_gen/src/gen_abilities.rs b/compiler/test_gen/src/gen_abilities.rs index 9b0b1f0ed5..40711c9baf 100644 --- a/compiler/test_gen/src/gen_abilities.rs +++ b/compiler/test_gen/src/gen_abilities.rs @@ -84,3 +84,26 @@ fn alias_member_specialization() { u64 ); } + +#[test] +fn ability_constrained_in_non_member_usage() { + assert_evals_to!( + indoc!( + r#" + app "test" provides [ result ] to "./platform" + + Hash has + hash : a -> U64 | a has Hash + + mulHashes = \x, y -> hash x * hash y + + Id := U64 + hash = \$Id n -> n + + result = mulHashes ($Id 5) ($Id 7) + "# + ), + 35, + u64 + ) +} From ff5ae67094a82ba3472f740c3bf3803004dca200 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 19 Apr 2022 13:13:33 -0400 Subject: [PATCH 365/846] Multi-specializations of able variables through function compile --- compiler/solve/tests/solve_expr.rs | 25 +++++++++++++++++++++++ compiler/test_gen/src/gen_abilities.rs | 28 ++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index b31b6502b7..da03df77e2 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -6008,4 +6008,29 @@ mod solve_expr { "Bool", ) } + + #[test] + fn ability_constrained_in_non_member_multiple_specializations() { + infer_eq_without_problem( + indoc!( + r#" + app "test" provides [ result ] to "./platform" + + Hash has + hash : a -> U64 | a has Hash + + mulHashes = \x, y -> hash x * hash y + + Id := U64 + hash = \$Id n -> n + + Three := {} + hash = \$Three _ -> 3 + + result = mulHashes ($Id 100) ($Three {}) + "# + ), + "U64", + ) + } } diff --git a/compiler/test_gen/src/gen_abilities.rs b/compiler/test_gen/src/gen_abilities.rs index 40711c9baf..384ba85b36 100644 --- a/compiler/test_gen/src/gen_abilities.rs +++ b/compiler/test_gen/src/gen_abilities.rs @@ -86,6 +86,7 @@ fn alias_member_specialization() { } #[test] +#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] fn ability_constrained_in_non_member_usage() { assert_evals_to!( indoc!( @@ -107,3 +108,30 @@ fn ability_constrained_in_non_member_usage() { u64 ) } + +#[test] +#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] +fn ability_constrained_in_non_member_multiple_specializations() { + assert_evals_to!( + indoc!( + r#" + app "test" provides [ result ] to "./platform" + + Hash has + hash : a -> U64 | a has Hash + + mulHashes = \x, y -> hash x * hash y + + Id := U64 + hash = \$Id n -> n + + Three := {} + hash = \$Three _ -> 3 + + result = mulHashes ($Id 100) ($Three {}) + "# + ), + 300, + u64 + ) +} From bd6078a34ae8834cc8cd78a90f817950da41b2fc Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 19 Apr 2022 13:18:27 -0400 Subject: [PATCH 366/846] Fix reporting tests --- reporting/src/error/canonicalize.rs | 4 ++- reporting/tests/test_reporting.rs | 38 +++++++++++++++++++++++------ 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/reporting/src/error/canonicalize.rs b/reporting/src/error/canonicalize.rs index 7facf2ec27..87ab93c885 100644 --- a/reporting/src/error/canonicalize.rs +++ b/reporting/src/error/canonicalize.rs @@ -643,7 +643,9 @@ pub fn can_problem<'b>( alloc.region(lines.convert_region(region)), alloc.concat([ alloc.keyword("has"), - alloc.reflow(" clauses can only be specified on the top-level type annotation of an ability member."), + alloc.reflow( + " clauses can only be specified on the top-level type annotations.", + ), ]), ]); title = ILLEGAL_HAS_CLAUSE.to_string(); diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index d8a615cfe3..d7314f9082 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -9433,13 +9433,13 @@ I need all branches in an `if` to have the same type! } #[test] - fn has_clause_outside_of_ability() { + fn has_clause_not_on_toplevel() { new_report_problem_as( indoc!( r#" - app "test" provides [ hash, f ] to "./platform" + app "test" provides [ f ] to "./platform" - Hash has hash : a -> Num.U64 | a has Hash + Hash has hash : (a | a has Hash) -> Num.U64 f : a -> Num.U64 | a has Hash "# @@ -9450,11 +9450,35 @@ I need all branches in an `if` to have the same type! A `has` clause is not allowed here: - 5│ f : a -> Num.U64 | a has Hash - ^^^^^^^^^^ + 3│ Hash has hash : (a | a has Hash) -> Num.U64 + ^^^^^^^^^^ - `has` clauses can only be specified on the top-level type annotation of - an ability member. + `has` clauses can only be specified on the top-level type annotations. + + ── ABILITY MEMBER MISSING HAS CLAUSE ─────────────────────────────────────────── + + The definition of the ability member `hash` does not include a `has` + clause binding a type variable to the ability `Hash`: + + 3│ Hash has hash : (a | a has Hash) -> Num.U64 + ^^^^ + + Ability members must include a `has` clause binding a type variable to + an ability, like + + a has Hash + + Otherwise, the function does not need to be part of the ability! + + ── UNUSED DEFINITION ─────────────────────────────────────────────────────────── + + `hash` is not used anywhere in your code. + + 3│ Hash has hash : (a | a has Hash) -> Num.U64 + ^^^^ + + If you didn't intend on using `hash` then remove it so future readers of + your code don't wonder why it is there. "# ), ) From 9d71a3d1ac539bd71a418050558104c5f64edf57 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 19 Apr 2022 13:26:22 -0400 Subject: [PATCH 367/846] Generalizing ability type instance to ability is illegal Closes #2881 --- compiler/unify/src/unify.rs | 18 ++++++------- reporting/tests/test_reporting.rs | 44 +++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 9 deletions(-) diff --git a/compiler/unify/src/unify.rs b/compiler/unify/src/unify.rs index 794f9ad00b..cebebcca4f 100644 --- a/compiler/unify/src/unify.rs +++ b/compiler/unify/src/unify.rs @@ -1,5 +1,5 @@ use bitflags::bitflags; -use roc_error_macros::{internal_error, todo_abilities}; +use roc_error_macros::internal_error; use roc_module::ident::{Lowercase, TagName}; use roc_module::symbol::Symbol; use roc_types::subs::Content::{self, *}; @@ -369,9 +369,12 @@ fn unify_ranged_number( // Ranged number wins merge(subs, ctx, RangedNumber(real_var, range_vars)) } - RecursionVar { .. } | RigidVar(..) | Alias(..) | Structure(..) => { - unify_pool(subs, pool, real_var, ctx.second, ctx.mode) - } + RecursionVar { .. } + | RigidVar(..) + | Alias(..) + | Structure(..) + | RigidAbleVar(..) + | FlexAbleVar(..) => unify_pool(subs, pool, real_var, ctx.second, ctx.mode), &RangedNumber(other_real_var, other_range_vars) => { let outcome = unify_pool(subs, pool, real_var, other_real_var, ctx.mode); if outcome.mismatches.is_empty() { @@ -382,9 +385,6 @@ fn unify_ranged_number( // TODO: We should probably check that "range_vars" and "other_range_vars" intersect } Error => merge(subs, ctx, Error), - FlexAbleVar(..) | RigidAbleVar(..) => { - todo_abilities!("I don't think this can be reached yet") - } }; if !outcome.mismatches.is_empty() { @@ -451,8 +451,8 @@ fn unify_alias( RecursionVar { structure, .. } if !either_is_opaque => { unify_pool(subs, pool, real_var, *structure, ctx.mode) } - RigidVar(_) => unify_pool(subs, pool, real_var, ctx.second, ctx.mode), - RigidAbleVar (_, ability) | FlexAbleVar(_, ability) if kind == AliasKind::Opaque && args.is_empty() => { + RigidVar(_) | RigidAbleVar(..) => unify_pool(subs, pool, real_var, ctx.second, ctx.mode), + FlexAbleVar(_, ability) if kind == AliasKind::Opaque && args.is_empty() => { // Opaque type wins let mut outcome = merge(subs, ctx, Alias(symbol, args, real_var, kind)); outcome.must_implement_ability.push(MustImplementAbility { typ: symbol, ability: *ability }); diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index d7314f9082..70f5d5bf2e 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -9828,4 +9828,48 @@ I need all branches in an `if` to have the same type! ), ) } + + #[test] + fn expression_generalization_to_ability_is_an_error() { + new_report_problem_as( + indoc!( + r#" + app "test" provides [ hash, hashable ] to "./platform" + + Hash has + hash : a -> U64 | a has Hash + + Id := U64 + hash = \$Id n -> n + + hashable : a | a has Hash + hashable = $Id 15 + "# + ), + indoc!( + r#" + ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + + Something is off with the body of the `hashable` definition: + + 9│ hashable : a | a has Hash + 10│ hashable = $Id 15 + ^^^^^^ + + This Id opaque wrapping has the type: + + Id + + But the type annotation on `hashable` says it should be: + + a | a has Hash + + Tip: Type comparisons between an opaque type are only ever equal if + both types are the same opaque type. Did you mean to create an opaque + type by wrapping it? If I have an opaque type Age := U32 I can create + an instance of this opaque type by doing @Age 23. + "# + ), + ) + } } From cbfd76380a170bcacb4493f17ba7d176d58a2881 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 19 Apr 2022 13:36:42 -0400 Subject: [PATCH 368/846] Improve ability generalization error message --- reporting/src/error/type.rs | 46 +++++++++++++++++++++++++++---- reporting/tests/test_reporting.rs | 9 +++--- 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/reporting/src/error/type.rs b/reporting/src/error/type.rs index 0351636408..c1640a9eef 100644 --- a/reporting/src/error/type.rs +++ b/reporting/src/error/type.rs @@ -1767,7 +1767,7 @@ pub enum Problem { FieldsMissing(Vec), TagTypo(TagName, Vec), TagsMissing(Vec), - BadRigidVar(Lowercase, ErrorType), + BadRigidVar(Lowercase, ErrorType, Option), OptionalRequiredMismatch(Lowercase), OpaqueComparedToNonOpaque, } @@ -1872,7 +1872,7 @@ fn diff_is_wildcard_comparison<'b>( ) -> bool { let Comparison { problems, .. } = to_comparison(alloc, actual, expected); match problems.last() { - Some(Problem::BadRigidVar(v1, ErrorType::RigidVar(v2))) => { + Some(Problem::BadRigidVar(v1, ErrorType::RigidVar(v2), None)) => { v1.as_str() == WILDCARD && v2.as_str() == WILDCARD } _ => false, @@ -2143,6 +2143,32 @@ fn to_diff<'b>( same(alloc, parens, type1) } + (RigidVar(x), other) | (other, RigidVar(x)) => { + let (left, left_able) = to_doc(alloc, Parens::InFn, type1); + let (right, right_able) = to_doc(alloc, Parens::InFn, type2); + + Diff { + left, + right, + status: Status::Different(vec![Problem::BadRigidVar(x, other, None)]), + left_able, + right_able, + } + } + + (RigidAbleVar(x, ab), other) | (other, RigidAbleVar(x, ab)) => { + let (left, left_able) = to_doc(alloc, Parens::InFn, type1); + let (right, right_able) = to_doc(alloc, Parens::InFn, type2); + + Diff { + left, + right, + status: Status::Different(vec![Problem::BadRigidVar(x, other, Some(ab))]), + left_able, + right_able, + } + } + (Function(args1, _, ret1), Function(args2, _, ret2)) => { if args1.len() == args2.len() { let mut status = Status::Similar; @@ -2325,7 +2351,6 @@ fn to_diff<'b>( }; let problems = match pair { - (RigidVar(x), other) | (other, RigidVar(x)) => vec![Problem::BadRigidVar(x, other)], (a, b) if (is_int(&a) && is_float(&b)) || (is_float(&a) && is_int(&b)) => { vec![Problem::IntFloat] } @@ -2751,6 +2776,7 @@ fn ext_to_status(ext1: &TypeExt, ext2: &TypeExt) -> Status { Status::Different(vec![Problem::BadRigidVar( x.clone(), ErrorType::RigidVar(y.clone()), + None, )]) } } @@ -3128,15 +3154,25 @@ fn type_problem_to_pretty<'b>( alloc.tip().append(line) } - (BadRigidVar(x, tipe), expectation) => { + (BadRigidVar(x, tipe, opt_ability), expectation) => { use ErrorType::*; let bad_rigid_var = |name: Lowercase, a_thing| { + let kind_of_value = match opt_ability { + Some(ability) => alloc.concat(vec![ + alloc.reflow("any value implementing the "), + alloc.symbol_unqualified(ability), + alloc.reflow(" ability"), + ]), + None => alloc.reflow("any type of value"), + }; alloc .tip() .append(alloc.reflow("The type annotation uses the type variable ")) .append(alloc.type_variable(name)) - .append(alloc.reflow(" to say that this definition can produce any type of value. But in the body I see that it will only produce ")) + .append(alloc.reflow(" to say that this definition can produce ") + .append(kind_of_value) + .append(alloc.reflow(". But in the body I see that it will only produce "))) .append(a_thing) .append(alloc.reflow(" of a single specific type. Maybe change the type annotation to be more specific? Maybe change the code to be more general?")) }; diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 70f5d5bf2e..6fa7e8c10e 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -9864,10 +9864,11 @@ I need all branches in an `if` to have the same type! a | a has Hash - Tip: Type comparisons between an opaque type are only ever equal if - both types are the same opaque type. Did you mean to create an opaque - type by wrapping it? If I have an opaque type Age := U32 I can create - an instance of this opaque type by doing @Age 23. + Tip: The type annotation uses the type variable `a` to say that this + definition can produce any value implementing the `Hash` ability. But in + the body I see that it will only produce a `Id` value of a single + specific type. Maybe change the type annotation to be more specific? + Maybe change the code to be more general? "# ), ) From 0387eeed23420ced74d4840fa7950e2393a187b7 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 19 Apr 2022 16:21:06 -0400 Subject: [PATCH 369/846] Make sure we're generating correct code with has annotations --- compiler/can/src/annotation.rs | 32 ++++++++++------ compiler/constrain/src/expr.rs | 10 ++--- compiler/mono/src/ir.rs | 2 + compiler/test_gen/src/gen_abilities.rs | 53 ++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 17 deletions(-) diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index 09395d3e3f..72f2f89f8f 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -32,6 +32,20 @@ impl<'a> NamedOrAbleVariable<'a> { NamedOrAbleVariable::Able(av) => av.first_seen, } } + + pub fn name(&self) -> &Lowercase { + match self { + NamedOrAbleVariable::Named(nv) => &nv.name, + NamedOrAbleVariable::Able(av) => &av.name, + } + } + + pub fn variable(&self) -> Variable { + match self { + NamedOrAbleVariable::Named(nv) => nv.variable, + NamedOrAbleVariable::Able(av) => av.variable, + } + } } /// A named type variable, not bound to an ability. @@ -148,19 +162,13 @@ impl IntroducedVariables { .map(|(_, var)| var) } + pub fn iter_named(&self) -> impl Iterator { + (self.named.iter().map(NamedOrAbleVariable::Named)) + .chain(self.able.iter().map(NamedOrAbleVariable::Able)) + } + pub fn named_var_by_name(&self, name: &Lowercase) -> Option { - if let Some(nav) = self - .named - .iter() - .find(|nv| &nv.name == name) - .map(NamedOrAbleVariable::Named) - { - return Some(nav); - } - self.able - .iter() - .find(|av| &av.name == name) - .map(NamedOrAbleVariable::Able) + self.iter_named().find(|v| v.name() == name) } pub fn collect_able(&self) -> Vec { diff --git a/compiler/constrain/src/expr.rs b/compiler/constrain/src/expr.rs index c9b41c1da8..1b820bf762 100644 --- a/compiler/constrain/src/expr.rs +++ b/compiler/constrain/src/expr.rs @@ -1684,18 +1684,18 @@ fn instantiate_rigids( let mut new_rigid_variables: Vec = Vec::new(); let mut rigid_substitution: MutMap = MutMap::default(); - for named in introduced_vars.named.iter() { + for named in introduced_vars.iter_named() { use std::collections::hash_map::Entry::*; - match ftv.entry(named.name.clone()) { + match ftv.entry(named.name().clone()) { Occupied(occupied) => { let existing_rigid = occupied.get(); - rigid_substitution.insert(named.variable, *existing_rigid); + rigid_substitution.insert(named.variable(), *existing_rigid); } Vacant(vacant) => { // It's possible to use this rigid in nested defs - vacant.insert(named.variable); - new_rigid_variables.push(named.variable); + vacant.insert(named.variable()); + new_rigid_variables.push(named.variable()); } } } diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 5bb784d3c4..099f5f8dfc 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -4750,6 +4750,7 @@ fn get_specialization<'a>( symbol: Symbol, ) -> Option { use roc_solve::ability::type_implementing_member; + use roc_solve::solve::instantiate_rigids; use roc_unify::unify::unify; match env.abilities_store.member_def(symbol) { @@ -4759,6 +4760,7 @@ fn get_specialization<'a>( } Some(member) => { let snapshot = env.subs.snapshot(); + instantiate_rigids(env.subs, member.signature_var); let (_, must_implement_ability) = unify( env.subs, symbol_var, diff --git a/compiler/test_gen/src/gen_abilities.rs b/compiler/test_gen/src/gen_abilities.rs index 384ba85b36..0fa3f804ab 100644 --- a/compiler/test_gen/src/gen_abilities.rs +++ b/compiler/test_gen/src/gen_abilities.rs @@ -88,6 +88,31 @@ fn alias_member_specialization() { #[test] #[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] fn ability_constrained_in_non_member_usage() { + assert_evals_to!( + indoc!( + r#" + app "test" provides [ result ] to "./platform" + + Hash has + hash : a -> U64 | a has Hash + + mulHashes : a, a -> U64 | a has Hash + mulHashes = \x, y -> hash x * hash y + + Id := U64 + hash = \$Id n -> n + + result = mulHashes ($Id 5) ($Id 7) + "# + ), + 35, + u64 + ) +} + +#[test] +#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] +fn ability_constrained_in_non_member_usage_inferred() { assert_evals_to!( indoc!( r#" @@ -112,6 +137,34 @@ fn ability_constrained_in_non_member_usage() { #[test] #[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] fn ability_constrained_in_non_member_multiple_specializations() { + assert_evals_to!( + indoc!( + r#" + app "test" provides [ result ] to "./platform" + + Hash has + hash : a -> U64 | a has Hash + + mulHashes : a, b -> U64 | a has Hash, b has Hash + mulHashes = \x, y -> hash x * hash y + + Id := U64 + hash = \$Id n -> n + + Three := {} + hash = \$Three _ -> 3 + + result = mulHashes ($Id 100) ($Three {}) + "# + ), + 300, + u64 + ) +} + +#[test] +#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] +fn ability_constrained_in_non_member_multiple_specializations_inferred() { assert_evals_to!( indoc!( r#" From c0dec1d5bcd092e250105a96898706500d69d96b Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 19 Apr 2022 16:21:46 -0400 Subject: [PATCH 370/846] Fix indent --- compiler/test_gen/src/gen_abilities.rs | 42 +++++++++++++------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/compiler/test_gen/src/gen_abilities.rs b/compiler/test_gen/src/gen_abilities.rs index 0fa3f804ab..4434a77cf7 100644 --- a/compiler/test_gen/src/gen_abilities.rs +++ b/compiler/test_gen/src/gen_abilities.rs @@ -140,22 +140,22 @@ fn ability_constrained_in_non_member_multiple_specializations() { assert_evals_to!( indoc!( r#" - app "test" provides [ result ] to "./platform" + app "test" provides [ result ] to "./platform" - Hash has - hash : a -> U64 | a has Hash + Hash has + hash : a -> U64 | a has Hash - mulHashes : a, b -> U64 | a has Hash, b has Hash - mulHashes = \x, y -> hash x * hash y + mulHashes : a, b -> U64 | a has Hash, b has Hash + mulHashes = \x, y -> hash x * hash y - Id := U64 - hash = \$Id n -> n + Id := U64 + hash = \$Id n -> n - Three := {} - hash = \$Three _ -> 3 + Three := {} + hash = \$Three _ -> 3 - result = mulHashes ($Id 100) ($Three {}) - "# + result = mulHashes ($Id 100) ($Three {}) + "# ), 300, u64 @@ -168,21 +168,21 @@ fn ability_constrained_in_non_member_multiple_specializations_inferred() { assert_evals_to!( indoc!( r#" - app "test" provides [ result ] to "./platform" + app "test" provides [ result ] to "./platform" - Hash has - hash : a -> U64 | a has Hash + Hash has + hash : a -> U64 | a has Hash - mulHashes = \x, y -> hash x * hash y + mulHashes = \x, y -> hash x * hash y - Id := U64 - hash = \$Id n -> n + Id := U64 + hash = \$Id n -> n - Three := {} - hash = \$Three _ -> 3 + Three := {} + hash = \$Three _ -> 3 - result = mulHashes ($Id 100) ($Three {}) - "# + result = mulHashes ($Id 100) ($Three {}) + "# ), 300, u64 From 80dc50763e26ae7d138845e4c7bc58ae1dbce54c Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 19 Apr 2022 16:41:18 -0400 Subject: [PATCH 371/846] Using abilities as types is illegal, but we can still compile them Closes #2881 --- compiler/can/src/abilities.rs | 4 ++ compiler/can/src/annotation.rs | 30 ++++++++++++- compiler/problem/src/can.rs | 1 + compiler/test_gen/src/gen_abilities.rs | 28 +++++++++++++ compiler/test_gen/src/helpers/llvm.rs | 5 ++- reporting/src/error/canonicalize.rs | 29 +++++++++++++ reporting/tests/test_reporting.rs | 58 +++++++++++++++++++++++++- 7 files changed, 151 insertions(+), 4 deletions(-) diff --git a/compiler/can/src/abilities.rs b/compiler/can/src/abilities.rs index b162a1355f..43f958eece 100644 --- a/compiler/can/src/abilities.rs +++ b/compiler/can/src/abilities.rs @@ -85,6 +85,10 @@ impl AbilitiesStore { ); } + pub fn is_ability(&self, ability: Symbol) -> bool { + self.members_of_ability.contains_key(&ability) + } + /// Records a specialization of `ability_member` with specialized type `implementing_type`. /// Entries via this function are considered a source of truth. It must be ensured that a /// specialization is validated before being registered here. diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index 72f2f89f8f..ae3ef9864d 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -8,7 +8,8 @@ use roc_problem::can::ShadowKind; use roc_region::all::{Loc, Region}; use roc_types::subs::{VarStore, Variable}; use roc_types::types::{ - Alias, AliasCommon, AliasKind, LambdaSet, Problem, RecordField, Type, TypeExtension, + name_type_var, Alias, AliasCommon, AliasKind, LambdaSet, Problem, RecordField, Type, + TypeExtension, }; #[derive(Clone, Debug, PartialEq)] @@ -397,6 +398,16 @@ pub fn find_type_def_symbols( result } +/// Generates a fresh type variable name. PERF: not super performant, don't prefer using this in +/// non-degenerate compilation paths! +fn find_fresh_var_name(introduced_variables: &IntroducedVariables) -> Lowercase { + let mut taken = introduced_variables + .iter_named() + .map(|v| v.name().clone()) + .collect(); + name_type_var(0, &mut taken).0 +} + #[allow(clippy::too_many_arguments)] fn can_annotation_help( env: &mut Env, @@ -418,7 +429,7 @@ fn can_annotation_help( let arg_ann = can_annotation_help( env, &arg.value, - region, + arg.region, scope, var_store, introduced_variables, @@ -456,6 +467,21 @@ fn can_annotation_help( references.insert(symbol); + if scope.abilities_store.is_ability(symbol) { + let fresh_ty_var = find_fresh_var_name(introduced_variables); + + env.problem(roc_problem::can::Problem::AbilityUsedAsType( + fresh_ty_var.clone(), + symbol, + region, + )); + + // Generate an variable bound to the ability so we can keep compiling. + let var = var_store.fresh(); + introduced_variables.insert_able(fresh_ty_var, Loc::at(region, var), symbol); + return Type::Variable(var); + } + for arg in *type_arguments { let arg_ann = can_annotation_help( env, diff --git a/compiler/problem/src/can.rs b/compiler/problem/src/can.rs index a12584c580..e28177345f 100644 --- a/compiler/problem/src/can.rs +++ b/compiler/problem/src/can.rs @@ -138,6 +138,7 @@ pub enum Problem { AbilityNotOnToplevel { region: Region, }, + AbilityUsedAsType(Lowercase, Symbol, Region), } #[derive(Clone, Debug, PartialEq)] diff --git a/compiler/test_gen/src/gen_abilities.rs b/compiler/test_gen/src/gen_abilities.rs index 4434a77cf7..f268f0ae2b 100644 --- a/compiler/test_gen/src/gen_abilities.rs +++ b/compiler/test_gen/src/gen_abilities.rs @@ -188,3 +188,31 @@ fn ability_constrained_in_non_member_multiple_specializations_inferred() { u64 ) } + +#[test] +#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] +fn ability_used_as_type_still_compiles() { + assert_evals_to!( + indoc!( + r#" + app "test" provides [ result ] to "./platform" + + Hash has + hash : a -> U64 | a has Hash + + mulHashes : Hash, Hash -> U64 + mulHashes = \x, y -> hash x * hash y + + Id := U64 + hash = \$Id n -> n + + Three := {} + hash = \$Three _ -> 3 + + result = mulHashes ($Id 100) ($Three {}) + "# + ), + 300, + u64 + ) +} diff --git a/compiler/test_gen/src/helpers/llvm.rs b/compiler/test_gen/src/helpers/llvm.rs index 03bc6b7a1e..cf77aba1e2 100644 --- a/compiler/test_gen/src/helpers/llvm.rs +++ b/compiler/test_gen/src/helpers/llvm.rs @@ -106,8 +106,9 @@ fn create_llvm_module<'a>( use roc_problem::can::Problem::*; for problem in can_problems.into_iter() { - // Ignore "unused" problems + dbg!(&problem); match problem { + // Ignore "unused" problems UnusedDef(_, _) | UnusedArgument(_, _, _) | UnusedImport(_, _) @@ -122,6 +123,8 @@ fn create_llvm_module<'a>( delayed_errors.push(buf.clone()); lines.push(buf); } + // We should be able to compile even when abilities are used as types + AbilityUsedAsType(..) => {} _ => { let report = can_problem(&alloc, &line_info, module_path.clone(), problem); let mut buf = String::new(); diff --git a/reporting/src/error/canonicalize.rs b/reporting/src/error/canonicalize.rs index 87ab93c885..9d755bee9c 100644 --- a/reporting/src/error/canonicalize.rs +++ b/reporting/src/error/canonicalize.rs @@ -46,6 +46,7 @@ const ABILITY_MEMBER_MISSING_HAS_CLAUSE: &str = "ABILITY MEMBER MISSING HAS CLAU const ABILITY_MEMBER_HAS_EXTRANEOUS_HAS_CLAUSE: &str = "ABILITY MEMBER HAS EXTRANEOUS HAS CLAUSE"; const ABILITY_MEMBER_BINDS_MULTIPLE_VARIABLES: &str = "ABILITY MEMBER BINDS MULTIPLE VARIABLES"; const ABILITY_NOT_ON_TOPLEVEL: &str = "ABILITY NOT ON TOP-LEVEL"; +const ABILITY_USED_AS_TYPE: &str = "ABILITY USED AS TYPE"; pub fn can_problem<'b>( alloc: &'b RocDocAllocator<'b>, @@ -750,6 +751,34 @@ pub fn can_problem<'b>( title = ABILITY_NOT_ON_TOPLEVEL.to_string(); severity = Severity::RuntimeError; } + + Problem::AbilityUsedAsType(suggested_var_name, ability, region) => { + doc = alloc.stack(vec![ + alloc.concat(vec![ + alloc.reflow("You are attempting to use the ability "), + alloc.symbol_unqualified(ability), + alloc.reflow(" as a type directly:"), + ]), + alloc.region(lines.convert_region(region)), + alloc.reflow( + "Abilities can only be used in type annotations to constrain type variables.", + ), + alloc + .hint("") + .append(alloc.reflow("Perhaps you meant to include a ")) + .append(alloc.keyword("has")) + .append(alloc.reflow(" annotation, like")), + alloc.type_block(alloc.concat(vec![ + alloc.type_variable(suggested_var_name), + alloc.space(), + alloc.keyword("has"), + alloc.space(), + alloc.symbol_unqualified(ability), + ])), + ]); + title = ABILITY_USED_AS_TYPE.to_string(); + severity = Severity::RuntimeError; + } }; Report { diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 6fa7e8c10e..604f245089 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -8877,7 +8877,7 @@ I need all branches in an `if` to have the same type! I cannot find a `UnknownType` value 3│ insertHelper : UnknownType, Type -> Type - ^^^^ + ^^^^^^^^^^^ Did you mean one of these? @@ -9873,4 +9873,60 @@ I need all branches in an `if` to have the same type! ), ) } + + #[test] + fn ability_value_annotations_are_an_error() { + new_report_problem_as( + indoc!( + r#" + app "test" provides [ result ] to "./platform" + + Hash has + hash : a -> U64 | a has Hash + + mulHashes : Hash, Hash -> U64 + mulHashes = \x, y -> hash x * hash y + + Id := U64 + hash = \$Id n -> n + + Three := {} + hash = \$Three _ -> 3 + + result = mulHashes ($Id 100) ($Three {}) + "# + ), + indoc!( + r#" + ── ABILITY USED AS TYPE ──────────────────────────────────────────────────────── + + You are attempting to use the ability `Hash` as a type directly: + + 6│ mulHashes : Hash, Hash -> U64 + ^^^^ + + Abilities can only be used in type annotations to constrain type + variables. + + Hint: Perhaps you meant to include a `has` annotation, like + + a has Hash + + ── ABILITY USED AS TYPE ──────────────────────────────────────────────────────── + + You are attempting to use the ability `Hash` as a type directly: + + 6│ mulHashes : Hash, Hash -> U64 + ^^^^ + + Abilities can only be used in type annotations to constrain type + variables. + + Hint: Perhaps you meant to include a `has` annotation, like + + b has Hash + "# + ), + ) + } } From 4bbc1d3a2bea21a30e15dda2ad882f91722c3d0a Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 19 Apr 2022 16:42:33 -0400 Subject: [PATCH 372/846] Clippy --- compiler/can/src/def.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 2b981510f0..66b82bdb6a 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1303,7 +1303,7 @@ fn canonicalize_pending_value_def<'a>( &loc_ann.value, loc_ann.region, var_store, - &abilities_in_scope, + abilities_in_scope, ); // Record all the annotation's references in output.references.lookups From 35b560f14dc1d5878c95784936f8039e1397343f Mon Sep 17 00:00:00 2001 From: Folkert Date: Thu, 21 Apr 2022 00:47:55 +0200 Subject: [PATCH 373/846] remove debug code --- compiler/can/src/procedure.rs | 8 -------- compiler/load_internal/src/file.rs | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/compiler/can/src/procedure.rs b/compiler/can/src/procedure.rs index 778688d74f..15ab82ff9f 100644 --- a/compiler/can/src/procedure.rs +++ b/compiler/can/src/procedure.rs @@ -166,14 +166,6 @@ impl References { } pub fn has_type_or_value_lookup(&self, symbol: Symbol) -> bool { - // if self.symbols.len() > 100 { - // panic!() - // } - // println!( - // "has a type or value lookup? {} {:?}", - // self.symbols.len(), - // symbol - // ); let mask = ReferencesBitflags::VALUE_LOOKUP.0 | ReferencesBitflags::TYPE_LOOKUP.0; let it = self.symbols.iter().zip(self.bitflags.iter()); diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index cdab508046..f8f60cfe4c 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -1110,7 +1110,7 @@ pub fn load<'a>( ) -> Result, LoadingProblem<'a>> { // When compiling to wasm, we cannot spawn extra threads // so we have a single-threaded implementation - if cfg!(target_family = "wasm") { + if true || cfg!(target_family = "wasm") { load_single_threaded( arena, load_start, From a1c0cdaeb1f6bd60ab86b1cfd34094236a6ae5b0 Mon Sep 17 00:00:00 2001 From: Folkert Date: Thu, 21 Apr 2022 00:50:05 +0200 Subject: [PATCH 374/846] make multi-threaded the default again --- compiler/load_internal/src/file.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index f8f60cfe4c..cdab508046 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -1110,7 +1110,7 @@ pub fn load<'a>( ) -> Result, LoadingProblem<'a>> { // When compiling to wasm, we cannot spawn extra threads // so we have a single-threaded implementation - if true || cfg!(target_family = "wasm") { + if cfg!(target_family = "wasm") { load_single_threaded( arena, load_start, From 928f99957ac6f4374ec25b38301ff7ec1f6b0797 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 20 Apr 2022 18:17:40 -0400 Subject: [PATCH 375/846] Fix warnings in Closure benchmark --- examples/benchmarks/Closure.roc | 58 ++++++++++++++++----------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/examples/benchmarks/Closure.roc b/examples/benchmarks/Closure.roc index d6bf6b3ff8..1a78d99867 100644 --- a/examples/benchmarks/Closure.roc +++ b/examples/benchmarks/Closure.roc @@ -20,32 +20,32 @@ toUnitBorrowed = \x -> Str.countGraphemes x foo = \f, x -> f x # --- -closure2 : {} -> Task.Task {} [] -closure2 = \_ -> - x : Str - x = "a long string such that it's malloced" - - Task.succeed {} - |> Task.map (\_ -> x) - |> Task.map toUnit - -toUnit = \_ -> {} - -# --- -closure3 : {} -> Task.Task {} [] -closure3 = \_ -> - x : Str - x = "a long string such that it's malloced" - - Task.succeed {} - |> Task.after (\_ -> Task.succeed x |> Task.map (\_ -> {})) - -# --- -closure4 : {} -> Task.Task {} [] -closure4 = \_ -> - x : Str - x = "a long string such that it's malloced" - - Task.succeed {} - |> Task.after (\_ -> Task.succeed x) - |> Task.map (\_ -> {}) +# closure2 : {} -> Task.Task {} [] +# closure2 = \_ -> +# x : Str +# x = "a long string such that it's malloced" +# +# Task.succeed {} +# |> Task.map (\_ -> x) +# |> Task.map toUnit +# +# toUnit = \_ -> {} +# +# # --- +# closure3 : {} -> Task.Task {} [] +# closure3 = \_ -> +# x : Str +# x = "a long string such that it's malloced" +# +# Task.succeed {} +# |> Task.after (\_ -> Task.succeed x |> Task.map (\_ -> {})) +# +# # --- +# closure4 : {} -> Task.Task {} [] +# closure4 = \_ -> +# x : Str +# x = "a long string such that it's malloced" +# +# Task.succeed {} +# |> Task.after (\_ -> Task.succeed x) +# |> Task.map (\_ -> {}) From e2ea66043a1c52d2a8d114d7f77c2066be1566a3 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 20 Apr 2022 18:13:18 -0400 Subject: [PATCH 376/846] Add color_reset to StyleCodes --- cli/tests/cli_run.rs | 1 + reporting/src/report.rs | 3 +++ 2 files changed, 4 insertions(+) diff --git a/cli/tests/cli_run.rs b/cli/tests/cli_run.rs index 32ef62de18..989f0054c4 100644 --- a/cli/tests/cli_run.rs +++ b/cli/tests/cli_run.rs @@ -61,6 +61,7 @@ mod cli_run { .replace(ANSI_STYLE_CODES.bold, "") .replace(ANSI_STYLE_CODES.underline, "") .replace(ANSI_STYLE_CODES.reset, "") + .replace(ANSI_STYLE_CODES.color_reset, "") } fn check_compile_error(file: &Path, flags: &[&str], expected: &str) { diff --git a/reporting/src/report.rs b/reporting/src/report.rs index a97537e18c..c3d8204a78 100644 --- a/reporting/src/report.rs +++ b/reporting/src/report.rs @@ -215,6 +215,7 @@ pub struct StyleCodes { pub bold: &'static str, pub underline: &'static str, pub reset: &'static str, + pub color_reset: &'static str, } pub const ANSI_STYLE_CODES: StyleCodes = StyleCodes { @@ -228,6 +229,7 @@ pub const ANSI_STYLE_CODES: StyleCodes = StyleCodes { bold: "\u{001b}[1m", underline: "\u{001b}[4m", reset: "\u{001b}[0m", + color_reset: "\u{1b}[39m", }; macro_rules! html_color { @@ -247,6 +249,7 @@ pub const HTML_STYLE_CODES: StyleCodes = StyleCodes { bold: "", underline: "", reset: "", + color_reset: "", }; // define custom allocator struct so we can `impl RocDocAllocator` custom helpers From 4952f7e9d20062ec5e29114d6d1a412bc72e018f Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 20 Apr 2022 18:16:01 -0400 Subject: [PATCH 377/846] fix cli_run tests --- cli/tests/cli_run.rs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/cli/tests/cli_run.rs b/cli/tests/cli_run.rs index 989f0054c4..bec2eb7047 100644 --- a/cli/tests/cli_run.rs +++ b/cli/tests/cli_run.rs @@ -68,7 +68,12 @@ mod cli_run { let compile_out = run_roc(&[&["check", file.to_str().unwrap()], flags].concat()); let err = compile_out.stdout.trim(); let err = strip_colors(err); - assert_multiline_str_eq!(err, expected.into()); + + // e.g. "1 error and 0 warnings found in 123 ms." + let (before_first_digit, _) = err.split_at(err.rfind("found in ").unwrap()); + let err = format!("{}found in ms.", before_first_digit); + + assert_multiline_str_eq!(err.as_str(), expected.into()); } fn check_format_check_as_expected(file: &Path, expects_success_exit_code: bool) { @@ -859,7 +864,9 @@ mod cli_run { I8 F64 - ────────────────────────────────────────────────────────────────────────────────"# + ──────────────────────────────────────────────────────────────────────────────── + + 1 error and 0 warnings found in ms."# ), ); } @@ -878,7 +885,9 @@ mod cli_run { You can fix this by adding a definition for bar, or by removing it from exposes. - ────────────────────────────────────────────────────────────────────────────────"# + ──────────────────────────────────────────────────────────────────────────────── + + 1 error and 0 warnings found in ms."# ), ); } @@ -899,7 +908,9 @@ mod cli_run { Since Symbol isn't used, you don't need to import it. - ────────────────────────────────────────────────────────────────────────────────"# + ──────────────────────────────────────────────────────────────────────────────── + + 0 errors and 1 warning found in ms."# ), ); } @@ -921,7 +932,9 @@ mod cli_run { Only specific functions like `after` and `map` can be generated.Learn more about hosted modules at TODO. - ────────────────────────────────────────────────────────────────────────────────"# + ──────────────────────────────────────────────────────────────────────────────── + + 1 error and 0 warnings found in ms."# ), ); } From 6fb8481ebd7a883c68f37d919233c42e8c84b688 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 20 Apr 2022 18:34:38 -0400 Subject: [PATCH 378/846] Report contents of stderr when example test fails --- cli/tests/cli_run.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/tests/cli_run.rs b/cli/tests/cli_run.rs index bec2eb7047..38a2460883 100644 --- a/cli/tests/cli_run.rs +++ b/cli/tests/cli_run.rs @@ -181,8 +181,8 @@ mod cli_run { }; if !&out.stdout.ends_with(expected_ending) { panic!( - "expected output to end with {:?} but instead got {:#?}", - expected_ending, out.stdout + "expected output to end with {:?} but instead got {:#?} - stderr was: {:#?}", + expected_ending, out.stdout, out.stderr ); } assert!(out.status.success()); From d903ac59f33e457e01040ef8dac527ce232f8312 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 20 Apr 2022 21:27:55 -0400 Subject: [PATCH 379/846] Make From for IdentStr reuse allocation --- compiler/ident/src/lib.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/compiler/ident/src/lib.rs b/compiler/ident/src/lib.rs index 85342346db..5b5dbefcdf 100644 --- a/compiler/ident/src/lib.rs +++ b/compiler/ident/src/lib.rs @@ -202,8 +202,19 @@ impl From<&str> for IdentStr { } impl From for IdentStr { - fn from(str: String) -> Self { - Self::from_str(&str) + fn from(string: String) -> Self { + if string.len() <= Self::SMALL_STR_BYTES { + Self::from_str(string.as_str()) + } else { + // Take over the string's heap allocation + let length = string.len(); + let elements = string.as_ptr(); + + // Make sure the existing string doesn't get dropped. + std::mem::forget(string); + + Self { elements, length } + } } } From 132213245d3eccddbab8ec4856b19667db740d89 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 20 Apr 2022 21:28:08 -0400 Subject: [PATCH 380/846] Add a way to convert Lowercase to &str --- compiler/module/src/ident.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/compiler/module/src/ident.rs b/compiler/module/src/ident.rs index 1056f9eeaf..2b4347d3d9 100644 --- a/compiler/module/src/ident.rs +++ b/compiler/module/src/ident.rs @@ -204,6 +204,12 @@ impl<'a> From<&'a str> for Lowercase { } } +impl<'a> From<&'a Lowercase> for &'a str { + fn from(lowercase: &'a Lowercase) -> Self { + lowercase.as_str() + } +} + impl<'a> From for Lowercase { fn from(string: String) -> Self { Self(string.into()) From 058bfdb8d0ff6f7065ba17e87c9cfb3ce146ab39 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 20 Apr 2022 21:31:29 -0400 Subject: [PATCH 381/846] Improve perf of finding type new type variables --- compiler/can/src/annotation.rs | 11 ++++------ compiler/types/src/pretty_print.rs | 7 ++++++- compiler/types/src/subs.rs | 6 +++++- compiler/types/src/types.rs | 33 ++++++++++++++++++------------ 4 files changed, 35 insertions(+), 22 deletions(-) diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index ae3ef9864d..79d138c744 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -398,14 +398,11 @@ pub fn find_type_def_symbols( result } -/// Generates a fresh type variable name. PERF: not super performant, don't prefer using this in -/// non-degenerate compilation paths! fn find_fresh_var_name(introduced_variables: &IntroducedVariables) -> Lowercase { - let mut taken = introduced_variables - .iter_named() - .map(|v| v.name().clone()) - .collect(); - name_type_var(0, &mut taken).0 + name_type_var(0, &mut introduced_variables.iter_named(), |var, str| { + var.name().as_str() == str + }) + .0 } #[allow(clippy::too_many_arguments)] diff --git a/compiler/types/src/pretty_print.rs b/compiler/types/src/pretty_print.rs index ddcb05895a..d3111cad1d 100644 --- a/compiler/types/src/pretty_print.rs +++ b/compiler/types/src/pretty_print.rs @@ -248,7 +248,12 @@ fn name_root( subs: &mut Subs, taken: &mut MutSet, ) -> u32 { - let (generated_name, new_letters_used) = name_type_var(letters_used, taken); + let (generated_name, new_letters_used) = + name_type_var(letters_used, &mut taken.iter(), |var, str| { + var.as_str() == str + }); + + taken.insert(generated_name.clone()); set_root_name(root, generated_name, subs); diff --git a/compiler/types/src/subs.rs b/compiler/types/src/subs.rs index 1aac8b45bd..1a327c85c3 100644 --- a/compiler/types/src/subs.rs +++ b/compiler/types/src/subs.rs @@ -3660,10 +3660,14 @@ fn flat_type_to_err_type( } fn get_fresh_var_name(state: &mut ErrorTypeState) -> Lowercase { - let (name, new_index) = name_type_var(state.normals, &mut state.taken); + let (name, new_index) = name_type_var(state.normals, &mut state.taken.iter(), |var, str| { + var.as_str() == str + }); state.normals = new_index; + state.taken.insert(name.clone()); + name } diff --git a/compiler/types/src/types.rs b/compiler/types/src/types.rs index 8f5f68636e..0f3536cd54 100644 --- a/compiler/types/src/types.rs +++ b/compiler/types/src/types.rs @@ -2328,26 +2328,33 @@ fn write_type_ext(ext: TypeExt, buf: &mut String) { static THE_LETTER_A: u32 = 'a' as u32; -pub fn name_type_var(letters_used: u32, taken: &mut MutSet) -> (Lowercase, u32) { +pub fn name_type_var bool>( + letters_used: u32, + taken: &mut impl Iterator, + mut predicate: F, +) -> (Lowercase, u32) { // TODO we should arena-allocate this String, // so all the strings in the entire pass only require ~1 allocation. - let mut generated_name = String::with_capacity((letters_used as usize) / 26 + 1); + let mut buf = String::with_capacity((letters_used as usize) / 26 + 1); - let mut remaining = letters_used as i32; - while remaining >= 0 { - generated_name.push(std::char::from_u32(THE_LETTER_A + ((remaining as u32) % 26)).unwrap()); - remaining -= 26; - } + let is_taken = { + let mut remaining = letters_used as i32; - let generated_name = generated_name.into(); + while remaining >= 0 { + buf.push(std::char::from_u32(THE_LETTER_A + ((remaining as u32) % 26)).unwrap()); + remaining -= 26; + } - if taken.contains(&generated_name) { + let generated_name: &str = buf.as_str(); + + taken.any(|item| predicate(&item, generated_name)) + }; + + if is_taken { // If the generated name is already taken, try again. - name_type_var(letters_used + 1, taken) + name_type_var(letters_used + 1, taken, predicate) } else { - taken.insert(generated_name.clone()); - - (generated_name, letters_used + 1) + (buf.into(), letters_used + 1) } } From 4b1b17ef1b9ac9004c6307230c84074564879041 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 20 Apr 2022 22:11:49 -0400 Subject: [PATCH 382/846] Add examples/breakout/hello.roc --- examples/breakout/hello.roc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 examples/breakout/hello.roc diff --git a/examples/breakout/hello.roc b/examples/breakout/hello.roc new file mode 100644 index 0000000000..05beac5d8c --- /dev/null +++ b/examples/breakout/hello.roc @@ -0,0 +1,18 @@ +app "breakout" + packages { pf: "platform" } + imports [ pf.Game.{ Bounds, Elem, Event } ] + provides [ program ] { Model } to pf + +Model : { text : Str } + +init : Bounds -> Model +init = \_ -> { text: "Hello, World!" } + +update : Model, Event -> Model +update = \model, _ -> model + + +render : Model -> List Elem +render = \model -> [ Text model.text ] + +program = { init, update, render } From 78ce0f8f3e25ed8a75d0bf4dd8ae9544039ca8d6 Mon Sep 17 00:00:00 2001 From: Ayaz <20735482+ayazhafiz@users.noreply.github.com> Date: Wed, 20 Apr 2022 22:50:23 -0400 Subject: [PATCH 383/846] Update reporting/src/error/type.rs Co-authored-by: Richard Feldman --- reporting/src/error/type.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reporting/src/error/type.rs b/reporting/src/error/type.rs index c1640a9eef..3e0a301298 100644 --- a/reporting/src/error/type.rs +++ b/reporting/src/error/type.rs @@ -3159,7 +3159,7 @@ fn type_problem_to_pretty<'b>( let bad_rigid_var = |name: Lowercase, a_thing| { let kind_of_value = match opt_ability { - Some(ability) => alloc.concat(vec![ + Some(ability) => alloc.concat([ alloc.reflow("any value implementing the "), alloc.symbol_unqualified(ability), alloc.reflow(" ability"), From e2a28347bb40163c3a59109d05a3c041936c6e5e Mon Sep 17 00:00:00 2001 From: Ayaz <20735482+ayazhafiz@users.noreply.github.com> Date: Wed, 20 Apr 2022 22:50:31 -0400 Subject: [PATCH 384/846] Update compiler/test_gen/src/helpers/llvm.rs Co-authored-by: Richard Feldman --- compiler/test_gen/src/helpers/llvm.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/test_gen/src/helpers/llvm.rs b/compiler/test_gen/src/helpers/llvm.rs index cf77aba1e2..99252b15c5 100644 --- a/compiler/test_gen/src/helpers/llvm.rs +++ b/compiler/test_gen/src/helpers/llvm.rs @@ -106,7 +106,6 @@ fn create_llvm_module<'a>( use roc_problem::can::Problem::*; for problem in can_problems.into_iter() { - dbg!(&problem); match problem { // Ignore "unused" problems UnusedDef(_, _) From 3243765eb4bb24936d028287d1c4533a2e244157 Mon Sep 17 00:00:00 2001 From: Jared Cone Date: Fri, 15 Apr 2022 10:58:30 -0700 Subject: [PATCH 385/846] Include file path in report If the path is too long to fit in the 80 characters with everything else it will be truncated to '...foo/bar.roc' --- reporting/src/report.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/reporting/src/report.rs b/reporting/src/report.rs index a97537e18c..5eab494398 100644 --- a/reporting/src/report.rs +++ b/reporting/src/report.rs @@ -129,10 +129,30 @@ impl<'b> Report<'b> { if self.title.is_empty() { self.doc } else { + let header_width = 80; + let title_width = self.title.len() + 4; + let full_path = self.filename.to_str().unwrap(); + let full_path_width = full_path.len() + 3; + let available_path_width = header_width - title_width - 1; + + // If path is too long to fit in 80 characters with everything else then truncate it + let path_width = if full_path_width <= available_path_width { + full_path_width + } else { + available_path_width + }; + let path_trim = full_path_width - path_width; + let path = if path_trim > 0 { + format!("...{}", &full_path[(path_trim + 3)..]) + } else { + full_path.to_string() + }; + let header = format!( - "── {} {}", + "── {} {} {} ─", self.title, - "─".repeat(80 - (self.title.len() + 4)) + "─".repeat(header_width - (title_width + path_width)), + path ); alloc.stack([alloc.text(header).annotate(Annotation::Header), self.doc]) From 477055b0fb79286a8fa994f33b1977ec1d573c03 Mon Sep 17 00:00:00 2001 From: Jared Cone Date: Fri, 15 Apr 2022 22:28:19 -0700 Subject: [PATCH 386/846] Show relative path instead of full Relative path is more concise and full path would not work well with unit testing expected output --- reporting/src/report.rs | 62 ++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/reporting/src/report.rs b/reporting/src/report.rs index 5eab494398..a83194036b 100644 --- a/reporting/src/report.rs +++ b/reporting/src/report.rs @@ -60,6 +60,42 @@ pub fn cycle<'b>( .annotate(Annotation::TypeBlock) } +pub fn pretty_header(title : &str, path : &PathBuf) -> String +{ + let cwd = std::env::current_dir().unwrap(); + let relative_path = match path.strip_prefix(cwd) { + Ok(p) => p, + StripPrefixError => &path + }.to_str().unwrap(); + + let header_width = 80; + let title_width = title.len() + 4; + let relative_path_width = relative_path.len() + 3; + let available_path_width = header_width - title_width - 1; + + // If path is too long to fit in 80 characters with everything else then truncate it + let path_width = if relative_path_width <= available_path_width { + relative_path_width + } else { + available_path_width + }; + let path_trim = relative_path_width - path_width; + let path = if path_trim > 0 { + format!("...{}", &relative_path[(path_trim + 3)..]) + } else { + relative_path.to_string() + }; + + let header = format!( + "── {} {} {} ─", + title, + "─".repeat(header_width - (title_width + path_width)), + path + ); + + return header; +} + #[derive(Copy, Clone, Debug, PartialEq, Eq)] pub enum Severity { /// This will cause a runtime error if some code get srun @@ -129,31 +165,7 @@ impl<'b> Report<'b> { if self.title.is_empty() { self.doc } else { - let header_width = 80; - let title_width = self.title.len() + 4; - let full_path = self.filename.to_str().unwrap(); - let full_path_width = full_path.len() + 3; - let available_path_width = header_width - title_width - 1; - - // If path is too long to fit in 80 characters with everything else then truncate it - let path_width = if full_path_width <= available_path_width { - full_path_width - } else { - available_path_width - }; - let path_trim = full_path_width - path_width; - let path = if path_trim > 0 { - format!("...{}", &full_path[(path_trim + 3)..]) - } else { - full_path.to_string() - }; - - let header = format!( - "── {} {} {} ─", - self.title, - "─".repeat(header_width - (title_width + path_width)), - path - ); + let header = crate::report::pretty_header(&self.title, &self.filename); alloc.stack([alloc.text(header).annotate(Annotation::Header), self.doc]) } From 66009c4b3cc717ef1583c652f2127a18f67fdd0d Mon Sep 17 00:00:00 2001 From: Jared Cone Date: Fri, 15 Apr 2022 22:59:35 -0700 Subject: [PATCH 387/846] Updated unit tests --- cli/tests/cli_run.rs | 8 ++--- compiler/load_internal/tests/test_load.rs | 8 ++--- repl_test/src/tests.rs | 10 +++---- reporting/tests/test_reporting.rs | 36 +++++++++++------------ 4 files changed, 31 insertions(+), 31 deletions(-) diff --git a/cli/tests/cli_run.rs b/cli/tests/cli_run.rs index 32ef62de18..5af8c79d97 100644 --- a/cli/tests/cli_run.rs +++ b/cli/tests/cli_run.rs @@ -844,7 +844,7 @@ mod cli_run { &[], indoc!( r#" - ── UNRECOGNIZED NAME ─────────────────────────────────────────────────────────── + ── UNRECOGNIZED NAME ─────────────────────────── tests/known_bad/TypeError.roc ─ I cannot find a `d` value @@ -870,7 +870,7 @@ mod cli_run { &[], indoc!( r#" - ── MISSING DEFINITION ────────────────────────────────────────────────────────── + ── MISSING DEFINITION ────────────────── tests/known_bad/ExposedNotDefined.roc ─ bar is listed as exposed, but it isn't defined in this module. @@ -889,7 +889,7 @@ mod cli_run { &[], indoc!( r#" - ── UNUSED IMPORT ─────────────────────────────────────────────────────────────── + ── UNUSED IMPORT ──────────────────────────── tests/known_bad/UnusedImport.roc ─ Nothing from Symbol is used in this module. @@ -910,7 +910,7 @@ mod cli_run { &[], indoc!( r#" - ── UNKNOWN GENERATES FUNCTION ────────────────────────────────────────────────── + ── UNKNOWN GENERATES FUNCTION ─────── tests/known_bad/UnknownGeneratesWith.roc ─ I don't know how to generate the foobar function. diff --git a/compiler/load_internal/tests/test_load.rs b/compiler/load_internal/tests/test_load.rs index 5aaace9f19..cf74b8b7b2 100644 --- a/compiler/load_internal/tests/test_load.rs +++ b/compiler/load_internal/tests/test_load.rs @@ -589,7 +589,7 @@ mod test_load { report, indoc!( " - ── UNFINISHED LIST ───────────────────────────────────────────────────────────── + ── UNFINISHED LIST ────────────────────────────────────────────────────── Main ─ I cannot find the end of this list: @@ -773,7 +773,7 @@ mod test_load { err, indoc!( r#" - ── OPAQUE TYPE DECLARED OUTSIDE SCOPE ────────────────────────────────────────── + ── OPAQUE TYPE DECLARED OUTSIDE SCOPE ─────────────────────────────────── Main ─ The unwrapped opaque type Age referenced here: @@ -787,7 +787,7 @@ mod test_load { Note: Opaque types can only be wrapped and unwrapped in the module they are defined in! - ── OPAQUE TYPE DECLARED OUTSIDE SCOPE ────────────────────────────────────────── + ── OPAQUE TYPE DECLARED OUTSIDE SCOPE ─────────────────────────────────── Main ─ The unwrapped opaque type Age referenced here: @@ -801,7 +801,7 @@ mod test_load { Note: Opaque types can only be wrapped and unwrapped in the module they are defined in! - ── UNUSED IMPORT ─────────────────────────────────────────────────────────────── + ── UNUSED IMPORT ──────────────────────────────────────────────────────── Main ─ Nothing from Age is used in this module. diff --git a/repl_test/src/tests.rs b/repl_test/src/tests.rs index 53b692266c..b66fcd17aa 100644 --- a/repl_test/src/tests.rs +++ b/repl_test/src/tests.rs @@ -575,7 +575,7 @@ fn too_few_args() { "Num.add 2", indoc!( r#" - ── TOO FEW ARGS ──────────────────────────────────────────────────────────────── + ── TOO FEW ARGS ───────────────────────────────────────────────────── REPL.roc ─ The add function expects 2 arguments, but it got only 1: @@ -596,7 +596,7 @@ fn type_problem() { "1 + \"\"", indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ──────────────────────────────────────────────────── REPL.roc ─ The 2nd argument to add is not what I expect: @@ -882,7 +882,7 @@ fn parse_problem() { "add m n = m + n", indoc!( r#" - ── ARGUMENTS BEFORE EQUALS ───────────────────────────────────────────────────── + ── ARGUMENTS BEFORE EQUALS ────────────────────────────────────────── REPL.roc ─ I am partway through parsing a definition, but I got stuck here: @@ -912,7 +912,7 @@ fn mono_problem() { "#, indoc!( r#" - ── UNSAFE PATTERN ────────────────────────────────────────────────────────────── + ── UNSAFE PATTERN ─────────────────────────────────────────────────── REPL.roc ─ This when does not cover all the possibilities: @@ -948,7 +948,7 @@ fn issue_2343_complete_mono_with_shadowed_vars() { ), indoc!( r#" - ── DUPLICATE NAME ────────────────────────────────────────────────────────────── + ── DUPLICATE NAME ─────────────────────────────────────────────────── REPL.roc ─ The b name is first defined here: diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 604f245089..54829bc130 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -41,7 +41,7 @@ mod test_reporting { Report { title: "".to_string(), doc, - filename: filename_from_string(r"\code\proj\Main.roc"), + filename: filename_from_string(r"/code/proj/Main.roc"), severity: Severity::RuntimeError, } } @@ -205,7 +205,7 @@ mod test_reporting { { use ven_pretty::DocAllocator; - let filename = filename_from_string(r"\code\proj\Main.roc"); + let filename = filename_from_string(r"/code/proj/Main.roc"); let mut buf = String::new(); @@ -359,7 +359,7 @@ mod test_reporting { let src_lines: Vec<&str> = src.split('\n').collect(); let lines = LineInfo::new(src); - let filename = filename_from_string(r"\code\proj\Main.roc"); + let filename = filename_from_string(r"/code/proj/Main.roc"); match infer_expr_help(arena, src) { Err(parse_err) => { @@ -424,7 +424,7 @@ mod test_reporting { let state = State::new(src.as_bytes()); - let filename = filename_from_string(r"\code\proj\Main.roc"); + let filename = filename_from_string(r"/code/proj/Main.roc"); let src_lines: Vec<&str> = src.split('\n').collect(); let lines = LineInfo::new(src); @@ -618,7 +618,7 @@ mod test_reporting { ), indoc!( r#" - ── DUPLICATE NAME ────────────────────────────────────────────────────────────── + ── DUPLICATE NAME ─────────────────────────────────────────────────── REPL.roc ─ The `i` name is first defined here: @@ -655,7 +655,7 @@ mod test_reporting { // Booly is called a "variable" indoc!( r#" - ── DUPLICATE NAME ────────────────────────────────────────────────────────────── + ── DUPLICATE NAME ─────────────────────────────────────────────────── REPL.roc ─ The `Booly` name is first defined here: @@ -807,7 +807,7 @@ mod test_reporting { ), indoc!( r#" - ── UNRECOGNIZED NAME ─────────────────────────────────────────────────────────── + ── UNRECOGNIZED NAME ─────────────────────────── tests/known_bad/TypeError.roc ─ I cannot find a `bar` value @@ -835,7 +835,7 @@ mod test_reporting { ), indoc!( r#" - ── UNRECOGNIZED NAME ─────────────────────────────────────────────────────────── + ── UNRECOGNIZED NAME ─────────────────────────── tests/known_bad/TypeError.roc ─ I cannot find a `true` value @@ -1000,7 +1000,7 @@ mod test_reporting { ), indoc!( r#" - ── UNRECOGNIZED NAME ─────────────────────────────────────────────────────────── + ── UNRECOGNIZED NAME ─────────────────────────── tests/known_bad/TypeError.roc ─ I cannot find a `theAdmin` value @@ -1783,7 +1783,7 @@ mod test_reporting { ), indoc!( r#" - ── UNRECOGNIZED NAME ─────────────────────────────────────────────────────────── + ── UNRECOGNIZED NAME ─────────────────────────── tests/known_bad/TypeError.roc ─ I cannot find a `foo` value @@ -2240,7 +2240,7 @@ mod test_reporting { ), indoc!( r#" - ── UNRECOGNIZED NAME ─────────────────────────────────────────────────────────── + ── UNRECOGNIZED NAME ─────────────────────────── tests/known_bad/TypeError.roc ─ I cannot find a `ok` value @@ -6173,7 +6173,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── UNRECOGNIZED NAME ─────────────────────────────────────────────────────────── + ── UNRECOGNIZED NAME ─────────────────────────── tests/known_bad/TypeError.roc ─ I cannot find a `bar` value @@ -8858,7 +8858,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── UNRECOGNIZED NAME ─────────────────────────────────────────────────────────── + ── UNRECOGNIZED NAME ─────────────────────────── tests/known_bad/TypeError.roc ─ I cannot find a `UnknownType` value @@ -8872,8 +8872,8 @@ I need all branches in an `if` to have the same type! Box Ok - ── UNRECOGNIZED NAME ─────────────────────────────────────────────────────────── - + ── UNRECOGNIZED NAME ─────────────────────────── tests/known_bad/TypeError.roc ─ + I cannot find a `UnknownType` value 3│ insertHelper : UnknownType, Type -> Type @@ -9205,7 +9205,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── DUPLICATE NAME ────────────────────────────────────────────────────────────── + ── DUPLICATE NAME ─────────────────────────────────────────────────── REPL.roc ─ The `a` name is first defined here: @@ -9282,8 +9282,8 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── DUPLICATE NAME ────────────────────────────────────────────────────────────── - + ── DUPLICATE NAME ─────────────────────────────────────────────────── REPL.roc ─ + The `Ability` name is first defined here: 3│ Ability has ab : a -> U64 | a has Ability From b48e63e931ab1b31c4612f559c791784402232ca Mon Sep 17 00:00:00 2001 From: Jared Cone Date: Fri, 15 Apr 2022 23:07:37 -0700 Subject: [PATCH 388/846] Fixed formatting and clippy errors --- reporting/src/report.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/reporting/src/report.rs b/reporting/src/report.rs index a83194036b..7e8cbe4867 100644 --- a/reporting/src/report.rs +++ b/reporting/src/report.rs @@ -60,13 +60,14 @@ pub fn cycle<'b>( .annotate(Annotation::TypeBlock) } -pub fn pretty_header(title : &str, path : &PathBuf) -> String -{ +pub fn pretty_header(title: &str, path: &std::path::Path) -> String { let cwd = std::env::current_dir().unwrap(); let relative_path = match path.strip_prefix(cwd) { Ok(p) => p, - StripPrefixError => &path - }.to_str().unwrap(); + _ => path, + } + .to_str() + .unwrap(); let header_width = 80; let title_width = title.len() + 4; @@ -92,8 +93,8 @@ pub fn pretty_header(title : &str, path : &PathBuf) -> String "─".repeat(header_width - (title_width + path_width)), path ); - - return header; + + header } #[derive(Copy, Clone, Debug, PartialEq, Eq)] From ec203595c18db82d38aff5db871d9b77c90cddc1 Mon Sep 17 00:00:00 2001 From: Jared Cone Date: Wed, 20 Apr 2022 17:39:16 -0700 Subject: [PATCH 389/846] Util for temporary directory temdir() creates a random directory which isn't good for testing. Adding suppo rt for a temporary named directory that cleans itself up before and after use. Adds a dependency on 'remove_dir_all' crate, but that crate was already an implicit dependency through the 'tempfile' crate. --- test_utils/Cargo.toml | 3 +-- test_utils/src/lib.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/test_utils/Cargo.toml b/test_utils/Cargo.toml index d71698cd2f..b1ce5e9843 100644 --- a/test_utils/Cargo.toml +++ b/test_utils/Cargo.toml @@ -8,5 +8,4 @@ description = "Utility functions used all over the code base." [dependencies] pretty_assertions = "1.0.0" - -[dev-dependencies] +remove_dir_all = "0.7.0" diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs index bca9060a5d..f5e00b7817 100644 --- a/test_utils/src/lib.rs +++ b/test_utils/src/lib.rs @@ -16,3 +16,33 @@ macro_rules! assert_multiline_str_eq { $crate::_pretty_assert_eq!($crate::DebugAsDisplay($a), $crate::DebugAsDisplay($b)) }; } + +/** + * Creates a temporary empty directory that gets deleted when this goes out of scope. + */ +pub struct TmpDir { + path: std::path::PathBuf, +} + +impl TmpDir { + pub fn new(dir: &str) -> TmpDir { + let path = std::path::Path::new(dir); + // ensure_empty_dir will fail if the dir doesn't already exist + std::fs::create_dir_all(path).unwrap(); + remove_dir_all::ensure_empty_dir(&path).unwrap(); + + let mut pathbuf = std::path::PathBuf::new(); + pathbuf.push(path); + TmpDir { path: pathbuf } + } + + pub fn path(&self) -> &std::path::Path { + self.path.as_path() + } +} + +impl Drop for TmpDir { + fn drop(&mut self) { + remove_dir_all::remove_dir_all(&self.path).unwrap(); + } +} From d20542efaed85b0b4ac199735ccd98d45356caf9 Mon Sep 17 00:00:00 2001 From: Jared Cone Date: Wed, 20 Apr 2022 17:40:46 -0700 Subject: [PATCH 390/846] Updated tests to use deterministic tmp dir --- Cargo.lock | 17 +- compiler/load_internal/.gitignore | 1 + compiler/load_internal/Cargo.toml | 1 + compiler/load_internal/tests/test_load.rs | 44 +- reporting/.gitignore | 1 + reporting/tests/test_reporting.rs | 678 +++++++++++----------- 6 files changed, 394 insertions(+), 348 deletions(-) create mode 100644 compiler/load_internal/.gitignore create mode 100644 reporting/.gitignore diff --git a/Cargo.lock b/Cargo.lock index 71b9a3e355..bd46536149 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3271,6 +3271,19 @@ dependencies = [ "winapi", ] +[[package]] +name = "remove_dir_all" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "882f368737489ea543bc5c340e6f3d34a28c39980bd9a979e47322b26f60ac40" +dependencies = [ + "libc", + "log", + "num_cpus", + "rayon", + "winapi", +] + [[package]] name = "renderdoc-sys" version = "0.7.1" @@ -3735,6 +3748,7 @@ dependencies = [ "roc_reporting", "roc_solve", "roc_target", + "roc_test_utils", "roc_types", "roc_unify", "tempfile", @@ -3953,6 +3967,7 @@ name = "roc_test_utils" version = "0.1.0" dependencies = [ "pretty_assertions", + "remove_dir_all 0.7.0", ] [[package]] @@ -4463,7 +4478,7 @@ dependencies = [ "libc", "rand", "redox_syscall", - "remove_dir_all", + "remove_dir_all 0.5.3", "winapi", ] diff --git a/compiler/load_internal/.gitignore b/compiler/load_internal/.gitignore new file mode 100644 index 0000000000..cad2309100 --- /dev/null +++ b/compiler/load_internal/.gitignore @@ -0,0 +1 @@ +/tmp \ No newline at end of file diff --git a/compiler/load_internal/Cargo.toml b/compiler/load_internal/Cargo.toml index 3d876623f5..28641d1c1b 100644 --- a/compiler/load_internal/Cargo.toml +++ b/compiler/load_internal/Cargo.toml @@ -33,3 +33,4 @@ tempfile = "3.2.0" pretty_assertions = "1.0.0" maplit = "1.0.2" indoc = "1.0.3" +roc_test_utils = { path = "../../test_utils" } \ No newline at end of file diff --git a/compiler/load_internal/tests/test_load.rs b/compiler/load_internal/tests/test_load.rs index cf74b8b7b2..72ebf8df50 100644 --- a/compiler/load_internal/tests/test_load.rs +++ b/compiler/load_internal/tests/test_load.rs @@ -89,11 +89,11 @@ mod test_load { buf } - fn multiple_modules(files: Vec<(&str, &str)>) -> Result { + fn multiple_modules(subdir: &str, files: Vec<(&str, &str)>) -> Result { let arena = Bump::new(); let arena = &arena; - match multiple_modules_help(arena, files) { + match multiple_modules_help(subdir, arena, files) { Err(io_error) => panic!("IO trouble: {:?}", io_error), Ok(Err(LoadingProblem::FormattedReport(buf))) => Err(buf), Ok(Err(loading_problem)) => Err(format!("{:?}", loading_problem)), @@ -126,18 +126,21 @@ mod test_load { } fn multiple_modules_help<'a>( + subdir: &str, arena: &'a Bump, mut files: Vec<(&str, &str)>, ) -> Result>, std::io::Error> { use std::fs::{self, File}; use std::io::Write; - use tempfile::tempdir; let mut file_handles: Vec<_> = Vec::new(); - // create a temporary directory - let dir = tempdir()?; + // Use a deterministic temporary directory. + // We can't have all tests use "tmp" because tests run in parallel, + // so append the test name to the tmp path. + let tmp = format!("tmp/{}", subdir); + let dir = roc_test_utils::TmpDir::new(&tmp); let app_module = files.pop().unwrap(); @@ -173,8 +176,6 @@ mod test_load { ) }; - dir.close()?; - Ok(result) } @@ -341,7 +342,7 @@ mod test_load { ), ]; - assert!(multiple_modules(modules).is_ok()); + assert!(multiple_modules("import_transitive_alias", modules).is_ok()); } #[test] @@ -584,12 +585,12 @@ mod test_load { ), )]; - match multiple_modules(modules) { + match multiple_modules("parse_problem", modules) { Err(report) => assert_eq!( report, indoc!( " - ── UNFINISHED LIST ────────────────────────────────────────────────────── Main ─ + ── UNFINISHED LIST ──────────────────────────────────── tmp/parse_problem/Main ─ I cannot find the end of this list: @@ -651,10 +652,14 @@ mod test_load { ), )]; - match multiple_modules(modules) { + match multiple_modules("platform_does_not_exist", modules) { Err(report) => { - assert!(report.contains("FILE NOT FOUND")); - assert!(report.contains("zzz-does-not-exist/Package-Config.roc")); + assert!(report.contains("FILE NOT FOUND"), "report=({})", report); + assert!( + report.contains("zzz-does-not-exist/Package-Config.roc"), + "report=({})", + report + ); } Ok(_) => unreachable!("we expect failure here"), } @@ -694,7 +699,7 @@ mod test_load { ), ]; - match multiple_modules(modules) { + match multiple_modules("platform_parse_error", modules) { Err(report) => { assert!(report.contains("NOT END OF FILE")); assert!(report.contains("blah 1 2 3 # causing a parse error on purpose")); @@ -738,7 +743,7 @@ mod test_load { ), ]; - assert!(multiple_modules(modules).is_ok()); + assert!(multiple_modules("platform_exposes_main_return_by_pointer_issue", modules).is_ok()); } #[test] @@ -768,12 +773,13 @@ mod test_load { ), ]; - let err = multiple_modules(modules).unwrap_err(); + let err = multiple_modules("opaque_wrapped_unwrapped_outside_defining_module", modules) + .unwrap_err(); assert_eq!( err, indoc!( r#" - ── OPAQUE TYPE DECLARED OUTSIDE SCOPE ─────────────────────────────────── Main ─ + ── OPAQUE TYPE DECLARED OUTSIDE SCOPE ─ ...rapped_outside_defining_module/Main ─ The unwrapped opaque type Age referenced here: @@ -787,7 +793,7 @@ mod test_load { Note: Opaque types can only be wrapped and unwrapped in the module they are defined in! - ── OPAQUE TYPE DECLARED OUTSIDE SCOPE ─────────────────────────────────── Main ─ + ── OPAQUE TYPE DECLARED OUTSIDE SCOPE ─ ...rapped_outside_defining_module/Main ─ The unwrapped opaque type Age referenced here: @@ -801,7 +807,7 @@ mod test_load { Note: Opaque types can only be wrapped and unwrapped in the module they are defined in! - ── UNUSED IMPORT ──────────────────────────────────────────────────────── Main ─ + ── UNUSED IMPORT ─── tmp/opaque_wrapped_unwrapped_outside_defining_module/Main ─ Nothing from Age is used in this module. diff --git a/reporting/.gitignore b/reporting/.gitignore new file mode 100644 index 0000000000..cad2309100 --- /dev/null +++ b/reporting/.gitignore @@ -0,0 +1 @@ +/tmp \ No newline at end of file diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 54829bc130..feea376e9c 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -61,12 +61,12 @@ mod test_reporting { } fn run_load_and_infer<'a>( + subdir: &str, arena: &'a Bump, src: &'a str, ) -> (String, Result>) { use std::fs::File; use std::io::Write; - use tempfile::tempdir; let module_src = if src.starts_with("app") { // this is already a module @@ -78,7 +78,12 @@ mod test_reporting { let exposed_types = Default::default(); let loaded = { - let dir = tempdir().unwrap(); + // Use a deterministic temporary directory. + // We can't have all tests use "tmp" because tests run in parallel, + // so append the test name to the tmp path. + let tmp = format!("tmp/{}", subdir); + let dir = roc_test_utils::TmpDir::new(&tmp); + let filename = PathBuf::from("Test.roc"); let file_path = dir.path().join(filename); let full_file_path = file_path.clone(); @@ -94,8 +99,6 @@ mod test_reporting { ); drop(file); - dir.close().unwrap(); - result }; @@ -103,6 +106,7 @@ mod test_reporting { } fn infer_expr_help_new<'a>( + subdir: &str, arena: &'a Bump, expr_src: &'a str, ) -> Result< @@ -116,7 +120,7 @@ mod test_reporting { ), LoadingProblem<'a>, > { - let (module_src, result) = run_load_and_infer(arena, expr_src); + let (module_src, result) = run_load_and_infer(subdir, arena, expr_src); let LoadedModule { module_id: home, mut can_problems, @@ -199,7 +203,7 @@ mod test_reporting { )) } - fn list_reports_new(arena: &Bump, src: &str, finalize_render: F) -> String + fn list_reports_new(subdir: &str, arena: &Bump, src: &str, finalize_render: F) -> String where F: FnOnce(RocDocBuilder<'_>, &mut String), { @@ -209,7 +213,7 @@ mod test_reporting { let mut buf = String::new(); - match infer_expr_help_new(arena, src) { + match infer_expr_help_new(subdir, arena, src) { Err(LoadingProblem::FormattedReport(fail)) => fail, Ok((module_src, type_problems, can_problems, mono_problems, home, interns)) => { let lines = LineInfo::new(&module_src); @@ -514,7 +518,7 @@ mod test_reporting { assert_eq!(readable, expected_rendering); } - fn new_report_problem_as(src: &str, expected_rendering: &str) { + fn new_report_problem_as(subdir: &str, src: &str, expected_rendering: &str) { let arena = Bump::new(); let finalize_render = |doc: RocDocBuilder<'_>, buf: &mut String| { @@ -523,7 +527,7 @@ mod test_reporting { .expect("list_reports") }; - let buf = list_reports_new(&arena, src, finalize_render); + let buf = list_reports_new(subdir, &arena, src, finalize_render); // convenient to copy-paste the generated message if buf != expected_rendering { @@ -558,7 +562,7 @@ mod test_reporting { ), indoc!( r#" - ── NOT EXPOSED ───────────────────────────────────────────────────────────────── + ── NOT EXPOSED ─────────────────────────────────────────── /code/proj/Main.roc ─ The List module does not expose `isempty`: @@ -589,7 +593,7 @@ mod test_reporting { ), indoc!( r#" - ── UNUSED DEFINITION ─────────────────────────────────────────────────────────── + ── UNUSED DEFINITION ───────────────────────────────────── /code/proj/Main.roc ─ `y` is not used anywhere in your code. @@ -618,7 +622,7 @@ mod test_reporting { ), indoc!( r#" - ── DUPLICATE NAME ─────────────────────────────────────────────────── REPL.roc ─ + ── DUPLICATE NAME ──────────────────────────────────────── /code/proj/Main.roc ─ The `i` name is first defined here: @@ -655,7 +659,7 @@ mod test_reporting { // Booly is called a "variable" indoc!( r#" - ── DUPLICATE NAME ─────────────────────────────────────────────────── REPL.roc ─ + ── DUPLICATE NAME ──────────────────────────────────────── /code/proj/Main.roc ─ The `Booly` name is first defined here: @@ -670,7 +674,7 @@ mod test_reporting { Since these aliases have the same name, it's easy to use the wrong one on accident. Give one of them a new name. - ── UNUSED DEFINITION ─────────────────────────────────────────────────────────── + ── UNUSED DEFINITION ───────────────────────────────────── /code/proj/Main.roc ─ `Booly` is not used anywhere in your code. @@ -680,7 +684,7 @@ mod test_reporting { If you didn't intend on using `Booly` then remove it so future readers of your code don't wonder why it is there. - ── UNUSED DEFINITION ─────────────────────────────────────────────────────────── + ── UNUSED DEFINITION ───────────────────────────────────── /code/proj/Main.roc ─ `Booly` is not used anywhere in your code. @@ -775,7 +779,7 @@ mod test_reporting { ), indoc!( r#" - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ Using != and == together requires parentheses, to clarify how they should be grouped. @@ -807,7 +811,7 @@ mod test_reporting { ), indoc!( r#" - ── UNRECOGNIZED NAME ─────────────────────────── tests/known_bad/TypeError.roc ─ + ── UNRECOGNIZED NAME ───────────────────────────────────── /code/proj/Main.roc ─ I cannot find a `bar` value @@ -835,7 +839,7 @@ mod test_reporting { ), indoc!( r#" - ── UNRECOGNIZED NAME ─────────────────────────── tests/known_bad/TypeError.roc ─ + ── UNRECOGNIZED NAME ───────────────────────────────────── /code/proj/Main.roc ─ I cannot find a `true` value @@ -871,7 +875,7 @@ mod test_reporting { ), indoc!( r#" - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ Using more than one == like this requires parentheses, to clarify how things should be grouped. @@ -901,7 +905,7 @@ mod test_reporting { ), indoc!( r#" - ── UNUSED ARGUMENT ───────────────────────────────────────────────────────────── + ── UNUSED ARGUMENT ─────────────────────────────────────── /code/proj/Main.roc ─ `box` doesn't use `htmlChildren`. @@ -914,7 +918,7 @@ mod test_reporting { at the start of a variable name is a way of saying that the variable is not used. - ── UNUSED DEFINITION ─────────────────────────────────────────────────────────── + ── UNUSED DEFINITION ───────────────────────────────────── /code/proj/Main.roc ─ `y` is not used anywhere in your code. @@ -1000,7 +1004,7 @@ mod test_reporting { ), indoc!( r#" - ── UNRECOGNIZED NAME ─────────────────────────── tests/known_bad/TypeError.roc ─ + ── UNRECOGNIZED NAME ───────────────────────────────────── /code/proj/Main.roc ─ I cannot find a `theAdmin` value @@ -1074,7 +1078,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ This `if` condition needs to be a Bool: @@ -1104,7 +1108,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ This `if` guard condition needs to be a Bool: @@ -1133,7 +1137,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ This `if` has an `else` branch with a different type from its `then` branch: @@ -1164,7 +1168,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ The 3rd branch of this `if` does not match all the previous branches: @@ -1197,7 +1201,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ The 2nd branch of this `when` does not match all the previous branches: @@ -1230,7 +1234,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ This list contains elements with different types: @@ -1264,7 +1268,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ I cannot update the `.foo` field like this: @@ -1298,7 +1302,7 @@ mod test_reporting { ), indoc!( r#" - ── CIRCULAR TYPE ─────────────────────────────────────────────────────────────── + ── CIRCULAR TYPE ───────────────────────────────────────── /code/proj/Main.roc ─ I'm inferring a weird self-referential type for `g`: @@ -1327,7 +1331,7 @@ mod test_reporting { ), indoc!( r#" - ── CIRCULAR TYPE ─────────────────────────────────────────────────────────────── + ── CIRCULAR TYPE ───────────────────────────────────────── /code/proj/Main.roc ─ I'm inferring a weird self-referential type for `f`: @@ -1359,7 +1363,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ The 1st argument to `f` is not what I expect: @@ -1397,7 +1401,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ The 1st argument to `f` is not what I expect: @@ -1435,7 +1439,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ The 1st argument to `f` is not what I expect: @@ -1473,7 +1477,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ Something is off with the `then` branch of this `if` expression: @@ -1511,7 +1515,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ Something is off with the body of the `x` definition: @@ -1548,7 +1552,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ Something is off with the body of the `x` definition: @@ -1584,7 +1588,7 @@ mod test_reporting { ), indoc!( r#" - ── TOO MANY ARGS ─────────────────────────────────────────────────────────────── + ── TOO MANY ARGS ───────────────────────────────────────── /code/proj/Main.roc ─ The `x` value is not a function, but it was given 1 argument: @@ -1610,7 +1614,7 @@ mod test_reporting { ), indoc!( r#" - ── TOO MANY ARGS ─────────────────────────────────────────────────────────────── + ── TOO MANY ARGS ───────────────────────────────────────── /code/proj/Main.roc ─ The `f` function expects 1 argument, but it got 2 instead: @@ -1636,7 +1640,7 @@ mod test_reporting { ), indoc!( r#" - ── TOO FEW ARGS ──────────────────────────────────────────────────────────────── + ── TOO FEW ARGS ────────────────────────────────────────── /code/proj/Main.roc ─ The `f` function expects 2 arguments, but it got only 1: @@ -1661,7 +1665,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ The 1st pattern in this `when` is causing a mismatch: @@ -1692,7 +1696,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ The 2nd pattern in this `when` does not match the previous ones: @@ -1722,7 +1726,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ The 1st pattern in this `when` is causing a mismatch: @@ -1752,7 +1756,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ The 1st pattern in this `when` is causing a mismatch: @@ -1783,7 +1787,7 @@ mod test_reporting { ), indoc!( r#" - ── UNRECOGNIZED NAME ─────────────────────────── tests/known_bad/TypeError.roc ─ + ── UNRECOGNIZED NAME ───────────────────────────────────── /code/proj/Main.roc ─ I cannot find a `foo` value @@ -1848,7 +1852,7 @@ mod test_reporting { // Just putting this here. We should probably handle or-patterns better indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ The 1st pattern in this `when` is causing a mismatch: @@ -1880,7 +1884,7 @@ mod test_reporting { // Maybe this should specifically say the pattern doesn't work? indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ This expression is used in an unexpected way: @@ -1912,7 +1916,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ Something is off with the body of this definition: @@ -1947,7 +1951,7 @@ mod test_reporting { ), indoc!( r#" - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ This integer pattern is malformed: @@ -1972,7 +1976,7 @@ mod test_reporting { ), indoc!( r#" - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ This float pattern is malformed: @@ -1997,7 +2001,7 @@ mod test_reporting { ), indoc!( r#" - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ This hex integer pattern is malformed: @@ -2022,7 +2026,7 @@ mod test_reporting { ), indoc!( r#" - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ This octal integer pattern is malformed: @@ -2047,7 +2051,7 @@ mod test_reporting { ), indoc!( r#" - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ This binary integer pattern is malformed: @@ -2073,7 +2077,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ Something is off with the body of the `x` definition: @@ -2123,7 +2127,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ Something is off with the `else` branch of this `if` expression: @@ -2161,7 +2165,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ Something is off with the body of the `f` definition: @@ -2200,7 +2204,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ Something is off with the body of the `f` definition: @@ -2240,7 +2244,7 @@ mod test_reporting { ), indoc!( r#" - ── UNRECOGNIZED NAME ─────────────────────────── tests/known_bad/TypeError.roc ─ + ── UNRECOGNIZED NAME ───────────────────────────────────── /code/proj/Main.roc ─ I cannot find a `ok` value @@ -2275,7 +2279,7 @@ mod test_reporting { ), indoc!( r#" - ── UNUSED DEFINITION ─────────────────────────────────────────────────────────── + ── UNUSED DEFINITION ───────────────────────────────────── /code/proj/Main.roc ─ `ok` is not used anywhere in your code. @@ -2285,7 +2289,7 @@ mod test_reporting { If you didn't intend on using `ok` then remove it so future readers of your code don't wonder why it is there. - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ Something is off with the body of the `f` definition: @@ -2321,7 +2325,7 @@ mod test_reporting { ), indoc!( r#" - ── CIRCULAR DEFINITION ───────────────────────────────────────────────────────── + ── CIRCULAR DEFINITION ─────────────────────────────────── /code/proj/Main.roc ─ The `f` value is defined directly in terms of itself, causing an infinite loop. @@ -2345,7 +2349,7 @@ mod test_reporting { ), indoc!( r#" - ── CIRCULAR DEFINITION ───────────────────────────────────────────────────────── + ── CIRCULAR DEFINITION ─────────────────────────────────── /code/proj/Main.roc ─ The `foo` definition is causing a very tricky infinite loop: @@ -2377,7 +2381,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ This `x` record doesn’t have a `foo` field: @@ -2403,7 +2407,7 @@ mod test_reporting { // TODO also suggest fields with the correct type indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ This `x` record doesn’t have a `foo` field: @@ -2440,7 +2444,7 @@ mod test_reporting { // TODO also suggest fields with the correct type indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ This `r` record doesn’t have a `foo` field: @@ -2472,7 +2476,7 @@ mod test_reporting { // TODO also suggest fields with the correct type indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ This `x` record doesn’t have a `foo` field: @@ -2506,7 +2510,7 @@ mod test_reporting { // TODO also suggest fields with the correct type indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ The 2nd argument to `add` is not what I expect: @@ -2535,7 +2539,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ The 2nd argument to `add` is not what I expect: @@ -2567,7 +2571,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ The 2nd argument to `add` is not what I expect: @@ -2599,7 +2603,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ Something is off with the body of the `f` definition: @@ -2637,7 +2641,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ Something is off with the body of the `f` definition: @@ -2680,7 +2684,7 @@ mod test_reporting { ), indoc!( r#" - ── UNSAFE PATTERN ────────────────────────────────────────────────────────────── + ── UNSAFE PATTERN ──────────────────────────────────────── /code/proj/Main.roc ─ This pattern does not cover all the possibilities: @@ -2715,7 +2719,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ This expression is used in an unexpected way: @@ -2751,7 +2755,7 @@ mod test_reporting { ), indoc!( r#" - ── UNSAFE PATTERN ────────────────────────────────────────────────────────────── + ── UNSAFE PATTERN ──────────────────────────────────────── /code/proj/Main.roc ─ This `when` does not cover all the possibilities: @@ -2782,7 +2786,7 @@ mod test_reporting { ), indoc!( r#" - ── UNSAFE PATTERN ────────────────────────────────────────────────────────────── + ── UNSAFE PATTERN ──────────────────────────────────────── /code/proj/Main.roc ─ This `when` does not cover all the possibilities: @@ -2814,7 +2818,7 @@ mod test_reporting { ), indoc!( r#" - ── UNSAFE PATTERN ────────────────────────────────────────────────────────────── + ── UNSAFE PATTERN ──────────────────────────────────────── /code/proj/Main.roc ─ This `when` does not cover all the possibilities: @@ -2847,7 +2851,7 @@ mod test_reporting { ), indoc!( r#" - ── UNSAFE PATTERN ────────────────────────────────────────────────────────────── + ── UNSAFE PATTERN ──────────────────────────────────────── /code/proj/Main.roc ─ This `when` does not cover all the possibilities: @@ -2880,7 +2884,7 @@ mod test_reporting { // Tip: Looks like a record field guard is not exhaustive. Learn more about record pattern matches at TODO. indoc!( r#" - ── UNSAFE PATTERN ────────────────────────────────────────────────────────────── + ── UNSAFE PATTERN ──────────────────────────────────────── /code/proj/Main.roc ─ This `when` does not cover all the possibilities: @@ -2913,7 +2917,7 @@ mod test_reporting { ), indoc!( r#" - ── UNSAFE PATTERN ────────────────────────────────────────────────────────────── + ── UNSAFE PATTERN ──────────────────────────────────────── /code/proj/Main.roc ─ This `when` does not cover all the possibilities: @@ -2943,7 +2947,7 @@ mod test_reporting { ), indoc!( r#" - ── UNSAFE PATTERN ────────────────────────────────────────────────────────────── + ── UNSAFE PATTERN ──────────────────────────────────────── /code/proj/Main.roc ─ This `when` does not cover all the possibilities: @@ -2974,7 +2978,7 @@ mod test_reporting { ), indoc!( r#" - ── REDUNDANT PATTERN ─────────────────────────────────────────────────────────── + ── REDUNDANT PATTERN ───────────────────────────────────── /code/proj/Main.roc ─ The 2nd pattern is redundant: @@ -3006,7 +3010,7 @@ mod test_reporting { // de-aliases the alias to give a better error message indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ The 1st argument to `f` is not what I expect: @@ -3048,7 +3052,7 @@ mod test_reporting { // should not report Bar as unused! indoc!( r#" - ── CYCLIC ALIAS ──────────────────────────────────────────────────────────────── + ── CYCLIC ALIAS ────────────────────────────────────────── /code/proj/Main.roc ─ The `Foo` alias is recursive in an invalid way: @@ -3067,7 +3071,7 @@ mod test_reporting { Recursion in aliases is only allowed if recursion happens behind a tag. - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ `Bar` is not used anywhere in your code. @@ -3097,7 +3101,7 @@ mod test_reporting { // should not report Bar as unused! indoc!( r#" - ── CYCLIC ALIAS ──────────────────────────────────────────────────────────────── + ── CYCLIC ALIAS ────────────────────────────────────────── /code/proj/Main.roc ─ The `Foo` alias is self-recursive in an invalid way: @@ -3121,7 +3125,7 @@ mod test_reporting { ), indoc!( r#" - ── DUPLICATE FIELD NAME ──────────────────────────────────────────────────────── + ── DUPLICATE FIELD NAME ────────────────────────────────── /code/proj/Main.roc ─ This record defines the `.x` field twice! @@ -3149,7 +3153,7 @@ mod test_reporting { ), indoc!( r#" - ── DUPLICATE FIELD NAME ──────────────────────────────────────────────────────── + ── DUPLICATE FIELD NAME ────────────────────────────────── /code/proj/Main.roc ─ This record defines the `.x` field twice! @@ -3181,7 +3185,7 @@ mod test_reporting { ), indoc!( r#" - ── DUPLICATE FIELD NAME ──────────────────────────────────────────────────────── + ── DUPLICATE FIELD NAME ────────────────────────────────── /code/proj/Main.roc ─ This record defines the `.x` field twice! @@ -3220,7 +3224,7 @@ mod test_reporting { ), indoc!( r#" - ── DUPLICATE FIELD NAME ──────────────────────────────────────────────────────── + ── DUPLICATE FIELD NAME ────────────────────────────────── /code/proj/Main.roc ─ This record defines the `.x` field twice! @@ -3257,8 +3261,8 @@ mod test_reporting { ), indoc!( r#" - ── DUPLICATE FIELD NAME ──────────────────────────────────────────────────────── - + ── DUPLICATE FIELD NAME ────────────────────────────────── /code/proj/Main.roc ─ + This record type defines the `.foo` field twice! 1│ a : { foo : Num.I64, bar : {}, foo : Str } @@ -3289,8 +3293,8 @@ mod test_reporting { ), indoc!( r#" - ── DUPLICATE TAG NAME ────────────────────────────────────────────────────────── - + ── DUPLICATE TAG NAME ──────────────────────────────────── /code/proj/Main.roc ─ + This tag union type defines the `Foo` tag twice! 1│ a : [ Foo Num.I64, Bar {}, Foo Str ] @@ -3322,7 +3326,7 @@ mod test_reporting { ), indoc!( r#" - ── NAMING PROBLEM ────────────────────────────────────────────────────────────── + ── NAMING PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ This annotation does not match the definition immediately following it: @@ -3364,7 +3368,7 @@ mod test_reporting { ), indoc!( r#" - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ This pattern in the definition of `MyAlias` is not what I expect: @@ -3373,7 +3377,7 @@ mod test_reporting { Only type variables like `a` or `value` can occur in this position. - ── UNUSED DEFINITION ─────────────────────────────────────────────────────────── + ── UNUSED DEFINITION ───────────────────────────────────── /code/proj/Main.roc ─ `MyAlias` is not used anywhere in your code. @@ -3400,7 +3404,7 @@ mod test_reporting { ), indoc!( r#" - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ This pattern in the definition of `Age` is not what I expect: @@ -3426,8 +3430,8 @@ mod test_reporting { ), indoc!( r#" - ── TOO MANY TYPE ARGUMENTS ───────────────────────────────────────────────────── - + ── TOO MANY TYPE ARGUMENTS ─────────────────────────────── /code/proj/Main.roc ─ + The `Num` alias expects 1 type argument, but it got 2 instead: 1│ a : Num.Num Num.I64 Num.F64 @@ -3452,8 +3456,8 @@ mod test_reporting { ), indoc!( r#" - ── TOO MANY TYPE ARGUMENTS ───────────────────────────────────────────────────── - + ── TOO MANY TYPE ARGUMENTS ─────────────────────────────── /code/proj/Main.roc ─ + The `Num` alias expects 1 type argument, but it got 2 instead: 1│ f : Str -> Num.Num Num.I64 Num.F64 @@ -3480,7 +3484,7 @@ mod test_reporting { ), indoc!( r#" - ── TOO FEW TYPE ARGUMENTS ────────────────────────────────────────────────────── + ── TOO FEW TYPE ARGUMENTS ──────────────────────────────── /code/proj/Main.roc ─ The `Pair` alias expects 2 type arguments, but it got 1 instead: @@ -3508,7 +3512,7 @@ mod test_reporting { ), indoc!( r#" - ── TOO MANY TYPE ARGUMENTS ───────────────────────────────────────────────────── + ── TOO MANY TYPE ARGUMENTS ─────────────────────────────── /code/proj/Main.roc ─ The `Pair` alias expects 2 type arguments, but it got 3 instead: @@ -3535,7 +3539,7 @@ mod test_reporting { ), indoc!( r#" - ── UNUSED TYPE ALIAS PARAMETER ───────────────────────────────────────────────── + ── UNUSED TYPE ALIAS PARAMETER ─────────────────────────── /code/proj/Main.roc ─ The `a` type parameter is not used in the `Foo` alias definition: @@ -3561,7 +3565,7 @@ mod test_reporting { ), indoc!( r#" - ── ARGUMENTS BEFORE EQUALS ───────────────────────────────────────────────────── + ── ARGUMENTS BEFORE EQUALS ─────────────────────────────── /code/proj/Main.roc ─ I am partway through parsing a definition, but I got stuck here: @@ -3590,7 +3594,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ Something is off with the body of the `x` definition: @@ -3631,7 +3635,7 @@ mod test_reporting { // TODO do not show recursion var if the recursion var does not render on the surface of a type indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ Something is off with the body of the `x` definition: @@ -3673,7 +3677,7 @@ mod test_reporting { ), indoc!( r#" - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ This integer literal is too big: @@ -3685,7 +3689,7 @@ mod test_reporting { Tip: Learn more about number literals at TODO - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ This integer literal is too small: @@ -3697,7 +3701,7 @@ mod test_reporting { Tip: Learn more about number literals at TODO - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ This integer literal is too big: @@ -3709,7 +3713,7 @@ mod test_reporting { Tip: Learn more about number literals at TODO - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ This integer literal is too small: @@ -3739,7 +3743,7 @@ mod test_reporting { ), indoc!( r#" - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ This float literal is too big: @@ -3751,7 +3755,7 @@ mod test_reporting { Tip: Learn more about number literals at TODO - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ This float literal is too small: @@ -3788,7 +3792,7 @@ mod test_reporting { ), indoc!( r#" - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ This integer literal contains an invalid digit: @@ -3800,7 +3804,7 @@ mod test_reporting { Tip: Learn more about number literals at TODO - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ This hex integer literal contains an invalid digit: @@ -3812,7 +3816,7 @@ mod test_reporting { Tip: Learn more about number literals at TODO - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ This octal integer literal contains an invalid digit: @@ -3824,7 +3828,7 @@ mod test_reporting { Tip: Learn more about number literals at TODO - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ This binary integer literal contains an invalid digit: @@ -3858,7 +3862,7 @@ mod test_reporting { ), indoc!( r#" - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ This hex integer literal contains no digits: @@ -3870,7 +3874,7 @@ mod test_reporting { Tip: Learn more about number literals at TODO - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ This octal integer literal contains no digits: @@ -3882,7 +3886,7 @@ mod test_reporting { Tip: Learn more about number literals at TODO - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ This binary integer literal contains no digits: @@ -3910,7 +3914,7 @@ mod test_reporting { ), indoc!( r#" - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ This float literal contains an invalid digit: @@ -3945,7 +3949,7 @@ mod test_reporting { ), indoc!( r#" - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ This expression cannot be updated: @@ -3968,7 +3972,7 @@ mod test_reporting { ), indoc!( r#" - ── MODULE NOT IMPORTED ───────────────────────────────────────────────────────── + ── MODULE NOT IMPORTED ─────────────────────────────────── /code/proj/Main.roc ─ The `Foo` module is not imported: @@ -3997,7 +4001,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ The 2nd argument to `add` is not what I expect: @@ -4029,7 +4033,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ The 1st argument to `f` is weird: @@ -4062,7 +4066,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ Something is off with the body of this definition: @@ -4097,7 +4101,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ The 1st argument to `f` is weird: @@ -4134,7 +4138,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ The 1st pattern in this `when` is causing a mismatch: @@ -4169,7 +4173,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ This expression is used in an unexpected way: @@ -4204,7 +4208,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ The 1st argument to this function is not what I expect: @@ -4242,7 +4246,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ The 1st pattern in this `when` is causing a mismatch: @@ -4277,7 +4281,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ The 1st pattern in this `when` is causing a mismatch: @@ -4306,7 +4310,7 @@ mod test_reporting { ), indoc!( r#" - ── BAD OPTIONAL VALUE ────────────────────────────────────────────────────────── + ── BAD OPTIONAL VALUE ──────────────────────────────────── /code/proj/Main.roc ─ This record uses an optional value for the `.y` field in an incorrect context! @@ -4348,7 +4352,7 @@ mod test_reporting { ), indoc!( r#" - ── REDUNDANT PATTERN ─────────────────────────────────────────────────────────── + ── REDUNDANT PATTERN ───────────────────────────────────── /code/proj/Main.roc ─ The 3rd pattern is redundant: @@ -4399,7 +4403,7 @@ mod test_reporting { ), indoc!( r#" - ── UNUSED ARGUMENT ───────────────────────────────────────────────────────────── + ── UNUSED ARGUMENT ─────────────────────────────────────── /code/proj/Main.roc ─ `f` doesn't use `foo`. @@ -4425,7 +4429,7 @@ mod test_reporting { ), indoc!( r#" - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ I am trying to parse a qualified name here: @@ -4450,7 +4454,7 @@ mod test_reporting { ), indoc!( r#" - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ I am trying to parse a qualified name here: @@ -4474,7 +4478,7 @@ mod test_reporting { ), indoc!( r#" - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ I trying to parse a record field access here: @@ -4497,7 +4501,7 @@ mod test_reporting { ), indoc!( r#" - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ I am very confused by this expression: @@ -4524,7 +4528,7 @@ mod test_reporting { ), indoc!( r#" - ── UNKNOWN OPERATOR ──────────────────────────────────────────────────────────── + ── UNKNOWN OPERATOR ────────────────────────────────────── /code/proj/Main.roc ─ This looks like an operator, but it's not one I recognize! @@ -4557,7 +4561,7 @@ mod test_reporting { ), indoc!( r#" - ── TOO MANY ARGS ─────────────────────────────────────────────────────────────── + ── TOO MANY ARGS ───────────────────────────────────────── /code/proj/Main.roc ─ This value is not a function, but it was given 3 arguments: @@ -4580,7 +4584,7 @@ mod test_reporting { ), indoc!( r#" - ── UNFINISHED TAG UNION TYPE ─────────────────────────────────────────────────── + ── UNFINISHED TAG UNION TYPE ───────────────────────────── /code/proj/Main.roc ─ I just started parsing a tag union type, but I got stuck here: @@ -4604,7 +4608,7 @@ mod test_reporting { ), indoc!( r#" - ── UNFINISHED TAG UNION TYPE ─────────────────────────────────────────────────── + ── UNFINISHED TAG UNION TYPE ───────────────────────────── /code/proj/Main.roc ─ I am partway through parsing a tag union type, but I got stuck here: @@ -4628,7 +4632,7 @@ mod test_reporting { ), indoc!( r#" - ── WEIRD TAG NAME ────────────────────────────────────────────────────────────── + ── WEIRD TAG NAME ──────────────────────────────────────── /code/proj/Main.roc ─ I am partway through parsing a tag union type, but I got stuck here: @@ -4653,7 +4657,7 @@ mod test_reporting { ), indoc!( r#" - ── WEIRD TAG NAME ────────────────────────────────────────────────────────────── + ── WEIRD TAG NAME ──────────────────────────────────────── /code/proj/Main.roc ─ I am partway through parsing a tag union type, but I got stuck here: @@ -4678,7 +4682,7 @@ mod test_reporting { ), indoc!( r#" - ── UNFINISHED RECORD TYPE ────────────────────────────────────────────────────── + ── UNFINISHED RECORD TYPE ──────────────────────────────── /code/proj/Main.roc ─ I just started parsing a record type, but I got stuck here: @@ -4703,7 +4707,7 @@ mod test_reporting { ), indoc!( r#" - ── UNFINISHED RECORD TYPE ────────────────────────────────────────────────────── + ── UNFINISHED RECORD TYPE ──────────────────────────────── /code/proj/Main.roc ─ I am partway through parsing a record type, but I got stuck here: @@ -4729,7 +4733,7 @@ mod test_reporting { ), indoc!( r#" - ── UNFINISHED RECORD TYPE ────────────────────────────────────────────────────── + ── UNFINISHED RECORD TYPE ──────────────────────────────── /code/proj/Main.roc ─ I am partway through parsing a record type, but I got stuck here: @@ -4753,7 +4757,7 @@ mod test_reporting { ), indoc!( r#" - ── UNFINISHED RECORD TYPE ────────────────────────────────────────────────────── + ── UNFINISHED RECORD TYPE ──────────────────────────────── /code/proj/Main.roc ─ I just started parsing a record type, but I got stuck on this field name: @@ -4779,7 +4783,7 @@ mod test_reporting { ), indoc!( r#" - ── UNFINISHED RECORD TYPE ────────────────────────────────────────────────────── + ── UNFINISHED RECORD TYPE ──────────────────────────────── /code/proj/Main.roc ─ I am partway through parsing a record type, but I got stuck here: @@ -4800,7 +4804,7 @@ mod test_reporting { "f : { foo \t }", indoc!( r#" - ── TAB CHARACTER ─────────────────────────────────────────────────────────────── + ── TAB CHARACTER ───────────────────────────────────────── /code/proj/Main.roc ─ I encountered a tab character @@ -4819,7 +4823,7 @@ mod test_reporting { "# comment with a \t\n4", indoc!( " - ── TAB CHARACTER ─────────────────────────────────────────────────────────────── + ── TAB CHARACTER ───────────────────────────────────────── /code/proj/Main.roc ─ I encountered a tab character @@ -4843,7 +4847,7 @@ mod test_reporting { ), indoc!( r#" - ── UNFINISHED TYPE ───────────────────────────────────────────────────────────── + ── UNFINISHED TYPE ─────────────────────────────────────── /code/proj/Main.roc ─ I just started parsing a type, but I got stuck here: @@ -4866,7 +4870,7 @@ mod test_reporting { ), indoc!( r#" - ── UNFINISHED PARENTHESES ────────────────────────────────────────────────────── + ── UNFINISHED PARENTHESES ──────────────────────────────── /code/proj/Main.roc ─ I am partway through parsing a type in parentheses, but I got stuck here: @@ -4895,7 +4899,7 @@ mod test_reporting { ), indoc!( r#" - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ I am confused by this type name: @@ -4930,7 +4934,7 @@ mod test_reporting { ), indoc!( r#" - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ I am confused by this type name: @@ -4964,7 +4968,7 @@ mod test_reporting { ), indoc!( r#" - ── UNFINISHED TYPE ───────────────────────────────────────────────────────────── + ── UNFINISHED TYPE ─────────────────────────────────────── /code/proj/Main.roc ─ I just started parsing a type, but I got stuck here: @@ -4989,7 +4993,7 @@ mod test_reporting { ), indoc!( r#" - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ I am confused by this type name: @@ -5025,7 +5029,7 @@ mod test_reporting { ), indoc!( r#" - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ I am confused by this type name: @@ -5049,7 +5053,7 @@ mod test_reporting { ), indoc!( r#" - ── MISSING FINAL EXPRESSION ──────────────────────────────────────────────────── + ── MISSING FINAL EXPRESSION ────────────────────────────── /code/proj/Main.roc ─ I am partway through parsing a definition's final expression, but I got stuck here: @@ -5082,7 +5086,7 @@ mod test_reporting { ), indoc!( r#" - ── UNFINISHED INLINE ALIAS ───────────────────────────────────────────────────── + ── UNFINISHED INLINE ALIAS ─────────────────────────────── /code/proj/Main.roc ─ I just started parsing an inline type alias, but I got stuck here: @@ -5108,7 +5112,7 @@ mod test_reporting { ), indoc!( r#" - ── DOUBLE COMMA ──────────────────────────────────────────────────────────────── + ── DOUBLE COMMA ────────────────────────────────────────── /code/proj/Main.roc ─ I just started parsing a function argument type, but I encountered two commas in a row: @@ -5135,7 +5139,7 @@ mod test_reporting { ), indoc!( r#" - ── UNFINISHED TYPE ───────────────────────────────────────────────────────────── + ── UNFINISHED TYPE ─────────────────────────────────────── /code/proj/Main.roc ─ I am partway through parsing a type, but I got stuck here: @@ -5162,7 +5166,7 @@ mod test_reporting { ), indoc!( r#" - ── UNFINISHED TYPE ───────────────────────────────────────────────────────────── + ── UNFINISHED TYPE ─────────────────────────────────────── /code/proj/Main.roc ─ I just started parsing a type, but I got stuck here: @@ -5189,7 +5193,7 @@ mod test_reporting { ), indoc!( r#" - ── WEIRD TAG NAME ────────────────────────────────────────────────────────────── + ── WEIRD TAG NAME ──────────────────────────────────────── /code/proj/Main.roc ─ I am partway through parsing a tag union type, but I got stuck here: @@ -5219,7 +5223,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ Something is off with the body of the `myDict` definition: @@ -5256,7 +5260,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ Something is off with the body of the `myDict` definition: @@ -5292,7 +5296,7 @@ mod test_reporting { ), indoc!( r#" - ── IF GUARD NO CONDITION ─────────────────────────────────────────────────────── + ── IF GUARD NO CONDITION ───────────────────────────────── /code/proj/Main.roc ─ I just started parsing an if guard, but there is no guard condition: @@ -5321,7 +5325,7 @@ mod test_reporting { ), indoc!( r#" - ── UNFINISHED PATTERN ────────────────────────────────────────────────────────── + ── UNFINISHED PATTERN ──────────────────────────────────── /code/proj/Main.roc ─ I just started parsing a pattern, but I got stuck here: @@ -5350,7 +5354,7 @@ mod test_reporting { ), indoc!( r#" - ── MISSING EXPRESSION ────────────────────────────────────────────────────────── + ── MISSING EXPRESSION ──────────────────────────────────── /code/proj/Main.roc ─ I am partway through parsing a definition, but I got stuck here: @@ -5377,7 +5381,7 @@ mod test_reporting { ), indoc!( r#" - ── MISSING ARROW ─────────────────────────────────────────────────────────────── + ── MISSING ARROW ───────────────────────────────────────── /code/proj/Main.roc ─ I am partway through parsing a `when` expression, but got stuck here: @@ -5414,7 +5418,7 @@ mod test_reporting { ), indoc!( r#" - ── UNFINISHED ARGUMENT LIST ──────────────────────────────────────────────────── + ── UNFINISHED ARGUMENT LIST ────────────────────────────── /code/proj/Main.roc ─ I am partway through parsing a function argument list, but I got stuck at this comma: @@ -5439,7 +5443,7 @@ mod test_reporting { ), indoc!( r#" - ── UNFINISHED ARGUMENT LIST ──────────────────────────────────────────────────── + ── UNFINISHED ARGUMENT LIST ────────────────────────────── /code/proj/Main.roc ─ I am partway through parsing a function argument list, but I got stuck at this comma: @@ -5467,7 +5471,7 @@ mod test_reporting { ), indoc!( r#" - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ I got stuck here: @@ -5518,7 +5522,7 @@ mod test_reporting { ), indoc!( r#" - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ I got stuck here: @@ -5546,7 +5550,7 @@ mod test_reporting { ), indoc!( r#" - ── UNEXPECTED ARROW ──────────────────────────────────────────────────────────── + ── UNEXPECTED ARROW ────────────────────────────────────── /code/proj/Main.roc ─ I am parsing a `when` expression right now, but this arrow is confusing me: @@ -5589,7 +5593,7 @@ mod test_reporting { ), indoc!( r#" - ── UNFINISHED IF ─────────────────────────────────────────────────────────────── + ── UNFINISHED IF ───────────────────────────────────────── /code/proj/Main.roc ─ I was partway through parsing an `if` expression, but I got stuck here: @@ -5613,7 +5617,7 @@ mod test_reporting { ), indoc!( r#" - ── UNFINISHED IF ─────────────────────────────────────────────────────────────── + ── UNFINISHED IF ───────────────────────────────────────── /code/proj/Main.roc ─ I was partway through parsing an `if` expression, but I got stuck here: @@ -5636,7 +5640,7 @@ mod test_reporting { ), indoc!( r#" - ── UNFINISHED LIST ───────────────────────────────────────────────────────────── + ── UNFINISHED LIST ─────────────────────────────────────── /code/proj/Main.roc ─ I am partway through started parsing a list, but I got stuck here: @@ -5660,7 +5664,7 @@ mod test_reporting { ), indoc!( r#" - ── UNFINISHED LIST ───────────────────────────────────────────────────────────── + ── UNFINISHED LIST ─────────────────────────────────────── /code/proj/Main.roc ─ I am partway through started parsing a list, but I got stuck here: @@ -5688,7 +5692,7 @@ mod test_reporting { ), indoc!( r#" - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ This float literal contains an invalid digit: @@ -5710,7 +5714,7 @@ mod test_reporting { r#""abc\u(zzzz)def""#, indoc!( r#" - ── WEIRD CODE POINT ──────────────────────────────────────────────────────────── + ── WEIRD CODE POINT ────────────────────────────────────── /code/proj/Main.roc ─ I am partway through parsing a unicode code point, but I got stuck here: @@ -5732,7 +5736,7 @@ mod test_reporting { r#""abc\(32)def""#, indoc!( r#" - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ This string interpolation is invalid: @@ -5754,7 +5758,7 @@ mod test_reporting { r#""abc\u(110000)def""#, indoc!( r#" - ── INVALID UNICODE ───────────────────────────────────────────────────────────── + ── INVALID UNICODE ─────────────────────────────────────── /code/proj/Main.roc ─ This unicode code point is invalid: @@ -5773,7 +5777,7 @@ mod test_reporting { r#""abc\qdef""#, indoc!( r#" - ── WEIRD ESCAPE ──────────────────────────────────────────────────────────────── + ── WEIRD ESCAPE ────────────────────────────────────────── /code/proj/Main.roc ─ I was partway through parsing a string literal, but I got stuck here: @@ -5801,7 +5805,7 @@ mod test_reporting { r#""there is no end"#, indoc!( r#" - ── ENDLESS STRING ────────────────────────────────────────────────────────────── + ── ENDLESS STRING ──────────────────────────────────────── /code/proj/Main.roc ─ I cannot find the end of this string: @@ -5821,7 +5825,7 @@ mod test_reporting { r#""""there is no end"#, indoc!( r#" - ── ENDLESS STRING ────────────────────────────────────────────────────────────── + ── ENDLESS STRING ──────────────────────────────────────── /code/proj/Main.roc ─ I cannot find the end of this block string: @@ -5848,7 +5852,7 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ This `if` has an `else` branch with a different type from its `then` branch: @@ -5877,7 +5881,7 @@ mod test_reporting { report_problem_as( &format!(r#"if True then "abc" else 1 {} 2"#, $op), &format!( -r#"── TYPE MISMATCH ─────────────────────────────────────────────────────────────── +r#"── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ This `if` has an `else` branch with a different type from its `then` branch: @@ -5923,7 +5927,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ This `foo` record doesn’t have a `if` field: @@ -5946,7 +5950,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── NOT EXPOSED ───────────────────────────────────────────────────────────────── + ── NOT EXPOSED ─────────────────────────────────────────── /code/proj/Main.roc ─ The Num module does not expose `if`: @@ -5974,7 +5978,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ I trying to parse a record field access here: @@ -5997,7 +6001,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ I am trying to parse a private tag here: @@ -6022,7 +6026,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ I am very confused by this field access: @@ -6045,7 +6049,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ I am very confused by this field access: @@ -6068,7 +6072,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ I am very confused by this field access @@ -6093,7 +6097,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ I trying to parse a record field access here: @@ -6116,7 +6120,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── NAMING PROBLEM ────────────────────────────────────────────────────────────── + ── NAMING PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ I am trying to parse an identifier here: @@ -6173,7 +6177,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── UNRECOGNIZED NAME ─────────────────────────── tests/known_bad/TypeError.roc ─ + ── UNRECOGNIZED NAME ───────────────────────────────────── /code/proj/Main.roc ─ I cannot find a `bar` value @@ -6202,7 +6206,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── UNKNOWN OPERATOR ──────────────────────────────────────────────────────────── + ── UNKNOWN OPERATOR ────────────────────────────────────── /code/proj/Main.roc ─ This looks like an operator, but it's not one I recognize! @@ -6228,7 +6232,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── UNKNOWN OPERATOR ──────────────────────────────────────────────────────────── + ── UNKNOWN OPERATOR ────────────────────────────────────── /code/proj/Main.roc ─ This looks like an operator, but it's not one I recognize! @@ -6256,7 +6260,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── UNKNOWN OPERATOR ──────────────────────────────────────────────────────────── + ── UNKNOWN OPERATOR ────────────────────────────────────── /code/proj/Main.roc ─ This looks like an operator, but it's not one I recognize! @@ -6286,7 +6290,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── UNKNOWN OPERATOR ──────────────────────────────────────────────────────────── + ── UNKNOWN OPERATOR ────────────────────────────────────── /code/proj/Main.roc ─ This looks like an operator, but it's not one I recognize! @@ -6316,7 +6320,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── WEIRD PROVIDES ────────────────────────────────────────────────────────────── + ── WEIRD PROVIDES ──────────────────────────────────────── /code/proj/Main.roc ─ I am partway through parsing a provides list, but I got stuck here: @@ -6353,7 +6357,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── BAD REQUIRES ──────────────────────────────────────────────────────────────── + ── BAD REQUIRES ────────────────────────────────────────── /code/proj/Main.roc ─ I am partway through parsing a header, but I got stuck here: @@ -6381,7 +6385,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── WEIRD IMPORTS ─────────────────────────────────────────────────────────────── + ── WEIRD IMPORTS ───────────────────────────────────────── /code/proj/Main.roc ─ I am partway through parsing a header, but I got stuck here: @@ -6408,7 +6412,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── WEIRD EXPOSES ─────────────────────────────────────────────────────────────── + ── WEIRD EXPOSES ───────────────────────────────────────── /code/proj/Main.roc ─ I am partway through parsing an `exposes` list, but I got stuck here: @@ -6436,7 +6440,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── WEIRD MODULE NAME ─────────────────────────────────────────────────────────── + ── WEIRD MODULE NAME ───────────────────────────────────── /code/proj/Main.roc ─ I am partway through parsing a header, but got stuck here: @@ -6462,7 +6466,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── WEIRD APP NAME ────────────────────────────────────────────────────────────── + ── WEIRD APP NAME ──────────────────────────────────────── /code/proj/Main.roc ─ I am partway through parsing a header, but got stuck here: @@ -6488,7 +6492,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── TOO MANY ARGS ─────────────────────────────────────────────────────────────── + ── TOO MANY ARGS ───────────────────────────────────────── /code/proj/Main.roc ─ This value is not a function, but it was given 2 arguments: @@ -6513,7 +6517,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── TOO MANY ARGS ─────────────────────────────────────────────────────────────── + ── TOO MANY ARGS ───────────────────────────────────────── /code/proj/Main.roc ─ This value is not a function, but it was given 2 arguments: @@ -6539,7 +6543,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ Something is off with the body of the `x` definition: @@ -6569,7 +6573,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── UNFINISHED PARENTHESES ────────────────────────────────────────────────────── + ── UNFINISHED PARENTHESES ──────────────────────────────── /code/proj/Main.roc ─ I am partway through parsing a pattern in parentheses, but I got stuck here: @@ -6594,7 +6598,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── UNFINISHED PARENTHESES ────────────────────────────────────────────────────── + ── UNFINISHED PARENTHESES ──────────────────────────────── /code/proj/Main.roc ─ I am partway through parsing a pattern in parentheses, but I got stuck here: @@ -6619,7 +6623,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── UNFINISHED PARENTHESES ────────────────────────────────────────────────────── + ── UNFINISHED PARENTHESES ──────────────────────────────── /code/proj/Main.roc ─ I am partway through parsing a pattern in parentheses, but I got stuck here: @@ -6645,7 +6649,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── NEED MORE INDENTATION ─────────────────────────────────────────────────────── + ── NEED MORE INDENTATION ───────────────────────────────── /code/proj/Main.roc ─ I am partway through parsing a pattern in parentheses, but I got stuck here: @@ -6671,7 +6675,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── UNFINISHED PATTERN ────────────────────────────────────────────────────────── + ── UNFINISHED PATTERN ──────────────────────────────────── /code/proj/Main.roc ─ I just started parsing a pattern, but I got stuck here: @@ -6698,7 +6702,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── NEED MORE INDENTATION ─────────────────────────────────────────────────────── + ── NEED MORE INDENTATION ───────────────────────────────── /code/proj/Main.roc ─ I am partway through parsing a type in parentheses, but I got stuck here: @@ -6727,7 +6731,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ The 2nd argument to `map` is not what I expect: @@ -6759,7 +6763,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ Underscore patterns are not allowed in definitions @@ -6782,7 +6786,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ This `expect` condition needs to be a Bool: @@ -6813,7 +6817,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ The 2nd argument to `mul` is not what I expect: @@ -6828,7 +6832,7 @@ I need all branches in an `if` to have the same type! Num * - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ Something is off with the body of the `mult` definition: @@ -6861,7 +6865,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ The 2nd argument to `mul` is not what I expect: @@ -6876,7 +6880,7 @@ I need all branches in an `if` to have the same type! Num a - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ Something is off with the body of the `mult` definition: @@ -6915,7 +6919,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── TOO FEW TYPE ARGUMENTS ────────────────────────────────────────────────────── + ── TOO FEW TYPE ARGUMENTS ──────────────────────────────── /code/proj/Main.roc ─ The `Result` alias expects 2 type arguments, but it got 1 instead: @@ -6947,7 +6951,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── TOO MANY TYPE ARGUMENTS ───────────────────────────────────────────────────── + ── TOO MANY TYPE ARGUMENTS ─────────────────────────────── /code/proj/Main.roc ─ The `Result` alias expects 2 type arguments, but it got 3 instead: @@ -6973,7 +6977,7 @@ I need all branches in an `if` to have the same type! // TODO: We should tell the user that we inferred `_` as `a` indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ Something is off with the body of the `f` definition: @@ -7011,7 +7015,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ Something is off with the body of the `f` definition: @@ -7047,7 +7051,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ Something is off with the body of the `f` definition: @@ -7087,7 +7091,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ Something is off with the body of the `f` definition: @@ -7123,7 +7127,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── NOT AN INLINE ALIAS ───────────────────────────────────────────────────────── + ── NOT AN INLINE ALIAS ─────────────────────────────────── /code/proj/Main.roc ─ The inline type after this `as` is not a type alias: @@ -7147,7 +7151,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── QUALIFIED ALIAS NAME ──────────────────────────────────────────────────────── + ── QUALIFIED ALIAS NAME ────────────────────────────────── /code/proj/Main.roc ─ This type alias has a qualified name: @@ -7171,7 +7175,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── TYPE ARGUMENT NOT LOWERCASE ───────────────────────────────────────────────── + ── TYPE ARGUMENT NOT LOWERCASE ─────────────────────────── /code/proj/Main.roc ─ This alias type argument is not lowercase: @@ -7199,7 +7203,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ The 1st argument to `isEmpty` is not what I expect: @@ -7239,7 +7243,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ The 1st argument to `c` is not what I expect: @@ -7276,7 +7280,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── CYCLIC ALIAS ──────────────────────────────────────────────────────────────── + ── CYCLIC ALIAS ────────────────────────────────────────── /code/proj/Main.roc ─ The `F` alias is self-recursive in an invalid way: @@ -7303,7 +7307,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── CYCLIC ALIAS ──────────────────────────────────────────────────────────────── + ── CYCLIC ALIAS ────────────────────────────────────────── /code/proj/Main.roc ─ The `F` alias is self-recursive in an invalid way: @@ -7329,7 +7333,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── CYCLIC ALIAS ──────────────────────────────────────────────────────────────── + ── CYCLIC ALIAS ────────────────────────────────────────── /code/proj/Main.roc ─ The `F` alias is self-recursive in an invalid way: @@ -7358,7 +7362,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ The 1st argument to `job` is weird: @@ -7397,7 +7401,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ Something is off with the body of the `job` definition: @@ -7432,7 +7436,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── NESTED DATATYPE ───────────────────────────────────────────────────────────── + ── NESTED DATATYPE ─────────────────────────────────────── /code/proj/Main.roc ─ `Nested` is a nested datatype. Here is one recursive usage of it: @@ -7464,7 +7468,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── NESTED DATATYPE ───────────────────────────────────────────────────────────── + ── NESTED DATATYPE ─────────────────────────────────────── /code/proj/Main.roc ─ `Nested` is a nested datatype. Here is one recursive usage of it: @@ -7507,7 +7511,7 @@ I need all branches in an `if` to have the same type! ), bad_type, number, $suffix), &format!(indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ The 1st argument to `use` is not what I expect: @@ -7570,7 +7574,7 @@ I need all branches in an `if` to have the same type! ), number, bad_suffix, number, $suffix), &format!(indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ The 1st pattern in this `when` is causing a mismatch: @@ -7619,7 +7623,7 @@ I need all branches in an `if` to have the same type! // TODO: link to number suffixes indoc!( r#" - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ This integer literal contains an invalid digit: @@ -7646,7 +7650,7 @@ I need all branches in an `if` to have the same type! // TODO: link to number suffixes indoc!( r#" - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ This integer literal contains an invalid digit: @@ -7672,7 +7676,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── CONFLICTING NUMBER SUFFIX ─────────────────────────────────────────────────── + ── CONFLICTING NUMBER SUFFIX ───────────────────────────── /code/proj/Main.roc ─ This number literal is an integer, but it has a float suffix: @@ -7693,7 +7697,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── CONFLICTING NUMBER SUFFIX ─────────────────────────────────────────────────── + ── CONFLICTING NUMBER SUFFIX ───────────────────────────── /code/proj/Main.roc ─ This number literal is a float, but it has an integer suffix: @@ -7710,7 +7714,7 @@ I need all branches in an `if` to have the same type! "256u8", indoc!( r#" - ── NUMBER OVERFLOWS SUFFIX ───────────────────────────────────────────────────── + ── NUMBER OVERFLOWS SUFFIX ─────────────────────────────── /code/proj/Main.roc ─ This integer literal overflows the type indicated by its suffix: @@ -7730,7 +7734,7 @@ I need all branches in an `if` to have the same type! "-1u8", indoc!( r#" - ── NUMBER UNDERFLOWS SUFFIX ──────────────────────────────────────────────────── + ── NUMBER UNDERFLOWS SUFFIX ────────────────────────────── /code/proj/Main.roc ─ This integer literal underflows the type indicated by its suffix: @@ -7750,7 +7754,7 @@ I need all branches in an `if` to have the same type! "65536u16", indoc!( r#" - ── NUMBER OVERFLOWS SUFFIX ───────────────────────────────────────────────────── + ── NUMBER OVERFLOWS SUFFIX ─────────────────────────────── /code/proj/Main.roc ─ This integer literal overflows the type indicated by its suffix: @@ -7770,7 +7774,7 @@ I need all branches in an `if` to have the same type! "-1u16", indoc!( r#" - ── NUMBER UNDERFLOWS SUFFIX ──────────────────────────────────────────────────── + ── NUMBER UNDERFLOWS SUFFIX ────────────────────────────── /code/proj/Main.roc ─ This integer literal underflows the type indicated by its suffix: @@ -7790,7 +7794,7 @@ I need all branches in an `if` to have the same type! "4_294_967_296u32", indoc!( r#" - ── NUMBER OVERFLOWS SUFFIX ───────────────────────────────────────────────────── + ── NUMBER OVERFLOWS SUFFIX ─────────────────────────────── /code/proj/Main.roc ─ This integer literal overflows the type indicated by its suffix: @@ -7810,7 +7814,7 @@ I need all branches in an `if` to have the same type! "-1u32", indoc!( r#" - ── NUMBER UNDERFLOWS SUFFIX ──────────────────────────────────────────────────── + ── NUMBER UNDERFLOWS SUFFIX ────────────────────────────── /code/proj/Main.roc ─ This integer literal underflows the type indicated by its suffix: @@ -7830,7 +7834,7 @@ I need all branches in an `if` to have the same type! "18_446_744_073_709_551_616u64", indoc!( r#" - ── NUMBER OVERFLOWS SUFFIX ───────────────────────────────────────────────────── + ── NUMBER OVERFLOWS SUFFIX ─────────────────────────────── /code/proj/Main.roc ─ This integer literal overflows the type indicated by its suffix: @@ -7850,7 +7854,7 @@ I need all branches in an `if` to have the same type! "-1u64", indoc!( r#" - ── NUMBER UNDERFLOWS SUFFIX ──────────────────────────────────────────────────── + ── NUMBER UNDERFLOWS SUFFIX ────────────────────────────── /code/proj/Main.roc ─ This integer literal underflows the type indicated by its suffix: @@ -7870,7 +7874,7 @@ I need all branches in an `if` to have the same type! "-1u128", indoc!( r#" - ── NUMBER UNDERFLOWS SUFFIX ──────────────────────────────────────────────────── + ── NUMBER UNDERFLOWS SUFFIX ────────────────────────────── /code/proj/Main.roc ─ This integer literal underflows the type indicated by its suffix: @@ -7890,7 +7894,7 @@ I need all branches in an `if` to have the same type! "128i8", indoc!( r#" - ── NUMBER OVERFLOWS SUFFIX ───────────────────────────────────────────────────── + ── NUMBER OVERFLOWS SUFFIX ─────────────────────────────── /code/proj/Main.roc ─ This integer literal overflows the type indicated by its suffix: @@ -7910,7 +7914,7 @@ I need all branches in an `if` to have the same type! "-129i8", indoc!( r#" - ── NUMBER UNDERFLOWS SUFFIX ──────────────────────────────────────────────────── + ── NUMBER UNDERFLOWS SUFFIX ────────────────────────────── /code/proj/Main.roc ─ This integer literal underflows the type indicated by its suffix: @@ -7930,7 +7934,7 @@ I need all branches in an `if` to have the same type! "32768i16", indoc!( r#" - ── NUMBER OVERFLOWS SUFFIX ───────────────────────────────────────────────────── + ── NUMBER OVERFLOWS SUFFIX ─────────────────────────────── /code/proj/Main.roc ─ This integer literal overflows the type indicated by its suffix: @@ -7950,7 +7954,7 @@ I need all branches in an `if` to have the same type! "-32769i16", indoc!( r#" - ── NUMBER UNDERFLOWS SUFFIX ──────────────────────────────────────────────────── + ── NUMBER UNDERFLOWS SUFFIX ────────────────────────────── /code/proj/Main.roc ─ This integer literal underflows the type indicated by its suffix: @@ -7970,7 +7974,7 @@ I need all branches in an `if` to have the same type! "2_147_483_648i32", indoc!( r#" - ── NUMBER OVERFLOWS SUFFIX ───────────────────────────────────────────────────── + ── NUMBER OVERFLOWS SUFFIX ─────────────────────────────── /code/proj/Main.roc ─ This integer literal overflows the type indicated by its suffix: @@ -7990,7 +7994,7 @@ I need all branches in an `if` to have the same type! "-2_147_483_649i32", indoc!( r#" - ── NUMBER UNDERFLOWS SUFFIX ──────────────────────────────────────────────────── + ── NUMBER UNDERFLOWS SUFFIX ────────────────────────────── /code/proj/Main.roc ─ This integer literal underflows the type indicated by its suffix: @@ -8010,7 +8014,7 @@ I need all branches in an `if` to have the same type! "9_223_372_036_854_775_808i64", indoc!( r#" - ── NUMBER OVERFLOWS SUFFIX ───────────────────────────────────────────────────── + ── NUMBER OVERFLOWS SUFFIX ─────────────────────────────── /code/proj/Main.roc ─ This integer literal overflows the type indicated by its suffix: @@ -8030,7 +8034,7 @@ I need all branches in an `if` to have the same type! "-9_223_372_036_854_775_809i64", indoc!( r#" - ── NUMBER UNDERFLOWS SUFFIX ──────────────────────────────────────────────────── + ── NUMBER UNDERFLOWS SUFFIX ────────────────────────────── /code/proj/Main.roc ─ This integer literal underflows the type indicated by its suffix: @@ -8050,7 +8054,7 @@ I need all branches in an `if` to have the same type! "170_141_183_460_469_231_731_687_303_715_884_105_728i128", indoc!( r#" - ── NUMBER OVERFLOWS SUFFIX ───────────────────────────────────────────────────── + ── NUMBER OVERFLOWS SUFFIX ─────────────────────────────── /code/proj/Main.roc ─ This integer literal overflows the type indicated by its suffix: @@ -8076,7 +8080,7 @@ I need all branches in an `if` to have the same type! // be used as ... because of its literal value" indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ The 2nd argument to `get` is not what I expect: @@ -8106,7 +8110,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ The 2nd argument to `get` is not what I expect: @@ -8137,7 +8141,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ The 2nd argument to `get` is not what I expect: @@ -8168,7 +8172,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ The 1st pattern in this `when` is causing a mismatch: @@ -8200,7 +8204,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── CYCLIC ALIAS ──────────────────────────────────────────────────────────────── + ── CYCLIC ALIAS ────────────────────────────────────────── /code/proj/Main.roc ─ The `R` alias is self-recursive in an invalid way: @@ -8227,7 +8231,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── CYCLIC ALIAS ──────────────────────────────────────────────────────────────── + ── CYCLIC ALIAS ────────────────────────────────────────── /code/proj/Main.roc ─ The `R` alias is self-recursive in an invalid way: @@ -8255,7 +8259,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── CYCLIC ALIAS ──────────────────────────────────────────────────────────────── + ── CYCLIC ALIAS ────────────────────────────────────────── /code/proj/Main.roc ─ The `Foo` alias is recursive in an invalid way: @@ -8306,7 +8310,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── OPAQUE TYPE NOT DEFINED ───────────────────────────────────────────────────── + ── OPAQUE TYPE NOT DEFINED ─────────────────────────────── /code/proj/Main.roc ─ The opaque type Age referenced here is not defined: @@ -8331,7 +8335,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── OPAQUE TYPE NOT DEFINED ───────────────────────────────────────────────────── + ── OPAQUE TYPE NOT DEFINED ─────────────────────────────── /code/proj/Main.roc ─ The opaque type Age referenced here is not defined: @@ -8345,7 +8349,7 @@ I need all branches in an `if` to have the same type! Note: It looks like there are no opaque types declared in this scope yet! - ── UNUSED DEFINITION ─────────────────────────────────────────────────────────── + ── UNUSED DEFINITION ───────────────────────────────────── /code/proj/Main.roc ─ `Age` is not used anywhere in your code. @@ -8372,7 +8376,7 @@ I need all branches in an `if` to have the same type! // Apply(Error(OtherModule), [ $Age, 21 ]) indoc!( r#" - ── OPAQUE TYPE NOT APPLIED ───────────────────────────────────────────────────── + ── OPAQUE TYPE NOT APPLIED ─────────────────────────────── /code/proj/Main.roc ─ This opaque type is not applied to an argument: @@ -8381,7 +8385,7 @@ I need all branches in an `if` to have the same type! Note: Opaque types always wrap exactly one argument! - ── SYNTAX PROBLEM ────────────────────────────────────────────────────────────── + ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ I am trying to parse a qualified name here: @@ -8412,7 +8416,7 @@ I need all branches in an `if` to have the same type! // raise that declaration to the outer scope. indoc!( r#" - ── UNUSED DEFINITION ─────────────────────────────────────────────────────────── + ── UNUSED DEFINITION ───────────────────────────────────── /code/proj/Main.roc ─ `Age` is not used anywhere in your code. @@ -8422,7 +8426,7 @@ I need all branches in an `if` to have the same type! If you didn't intend on using `Age` then remove it so future readers of your code don't wonder why it is there. - ── OPAQUE TYPE NOT DEFINED ───────────────────────────────────────────────────── + ── OPAQUE TYPE NOT DEFINED ─────────────────────────────── /code/proj/Main.roc ─ The opaque type Age referenced here is not defined: @@ -8447,7 +8451,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── MODULE NOT IMPORTED ───────────────────────────────────────────────────────── + ── MODULE NOT IMPORTED ─────────────────────────────────── /code/proj/Main.roc ─ The `Task` module is not imported: @@ -8483,7 +8487,7 @@ I need all branches in an `if` to have the same type! // that the argument be a U8, and linking to the definitin! indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ This expression is used in an unexpected way: @@ -8516,7 +8520,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ This expression is used in an unexpected way: @@ -8550,7 +8554,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ Something is off with the body of the `v` definition: @@ -8592,7 +8596,7 @@ I need all branches in an `if` to have the same type! // probably wants to change "Age" to "@Age"! indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ This pattern is being used in an unexpected way: @@ -8631,7 +8635,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ The 2nd pattern in this `when` does not match the previous ones: @@ -8666,7 +8670,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── UNSAFE PATTERN ────────────────────────────────────────────────────────────── + ── UNSAFE PATTERN ──────────────────────────────────────── /code/proj/Main.roc ─ This `when` does not cover all the possibilities: @@ -8700,7 +8704,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── UNSAFE PATTERN ────────────────────────────────────────────────────────────── + ── UNSAFE PATTERN ──────────────────────────────────────── /code/proj/Main.roc ─ This `when` does not cover all the possibilities: @@ -8737,7 +8741,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ The 1st argument to `y` is not what I expect: @@ -8774,7 +8778,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── UNSAFE PATTERN ────────────────────────────────────────────────────────────── + ── UNSAFE PATTERN ──────────────────────────────────────── /code/proj/Main.roc ─ This `when` does not cover all the possibilities: @@ -8802,7 +8806,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── INVALID_EXTENSION_TYPE ────────────────────────────────────────────────────── + ── INVALID_EXTENSION_TYPE ──────────────────────────────── /code/proj/Main.roc ─ This record extension type is invalid: @@ -8827,7 +8831,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── INVALID_EXTENSION_TYPE ────────────────────────────────────────────────────── + ── INVALID_EXTENSION_TYPE ──────────────────────────────── /code/proj/Main.roc ─ This tag union extension type is invalid: @@ -8858,7 +8862,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── UNRECOGNIZED NAME ─────────────────────────── tests/known_bad/TypeError.roc ─ + ── UNRECOGNIZED NAME ───────────────────────────────────── /code/proj/Main.roc ─ I cannot find a `UnknownType` value @@ -8872,7 +8876,7 @@ I need all branches in an `if` to have the same type! Box Ok - ── UNRECOGNIZED NAME ─────────────────────────── tests/known_bad/TypeError.roc ─ + ── UNRECOGNIZED NAME ───────────────────────────────────── /code/proj/Main.roc ─ I cannot find a `UnknownType` value @@ -8903,7 +8907,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── UNFINISHED ABILITY ────────────────────────────────────────────────────────── + ── UNFINISHED ABILITY ──────────────────────────────────── /code/proj/Main.roc ─ I was partway through parsing an ability definition, but I got stuck here: @@ -8921,6 +8925,7 @@ I need all branches in an `if` to have the same type! #[test] fn ability_demands_not_indented_with_first() { new_report_problem_as( + "ability_demands_not_indented_with_first", indoc!( r#" Eq has @@ -8932,7 +8937,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── UNFINISHED ABILITY ────────────────────────────────────────────────────────── + ── UNFINISHED ABILITY ─── tmp/ability_demands_not_indented_with_first/Test.roc ─ I was partway through parsing an ability definition, but I got stuck here: @@ -8949,6 +8954,7 @@ I need all branches in an `if` to have the same type! #[test] fn ability_demand_value_has_args() { new_report_problem_as( + "ability_demand_value_has_args", indoc!( r#" Eq has @@ -8959,7 +8965,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── UNFINISHED ABILITY ────────────────────────────────────────────────────────── + ── UNFINISHED ABILITY ───────────── tmp/ability_demand_value_has_args/Test.roc ─ I was partway through parsing an ability definition, but I got stuck here: @@ -8986,7 +8992,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── UNFINISHED ABILITY ────────────────────────────────────────────────────────── + ── UNFINISHED ABILITY ──────────────────────────────────── /code/proj/Main.roc ─ I was partway through parsing an ability definition, but I got stuck here: @@ -9013,7 +9019,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── UNBOUND TYPE VARIABLE ─────────────────────────────────────────────────────── + ── UNBOUND TYPE VARIABLE ───────────────────────────────── /code/proj/Main.roc ─ The definition of `I` has an unbound type variable: @@ -9039,7 +9045,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── UNBOUND TYPE VARIABLE ─────────────────────────────────────────────────────── + ── UNBOUND TYPE VARIABLE ───────────────────────────────── /code/proj/Main.roc ─ The definition of `I` has an unbound type variable: @@ -9065,7 +9071,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── UNBOUND TYPE VARIABLE ─────────────────────────────────────────────────────── + ── UNBOUND TYPE VARIABLE ───────────────────────────────── /code/proj/Main.roc ─ The definition of `I` has 2 unbound type variables. @@ -9093,7 +9099,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── UNBOUND TYPE VARIABLE ─────────────────────────────────────────────────────── + ── UNBOUND TYPE VARIABLE ───────────────────────────────── /code/proj/Main.roc ─ The definition of `I` has an unbound type variable: @@ -9119,7 +9125,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── UNBOUND TYPE VARIABLE ─────────────────────────────────────────────────────── + ── UNBOUND TYPE VARIABLE ───────────────────────────────── /code/proj/Main.roc ─ The definition of `I` has an unbound type variable: @@ -9136,6 +9142,7 @@ I need all branches in an `if` to have the same type! #[test] fn ability_bad_type_parameter() { new_report_problem_as( + "ability_bad_type_parameter", indoc!( r#" app "test" provides [] to "./platform" @@ -9146,7 +9153,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── ABILITY HAS TYPE VARIABLES ────────────────────────────────────────────────── + ── ABILITY HAS TYPE VARIABLES ──────────────────────────── /code/proj/Main.roc ─ The definition of the `Hash` ability includes type variables: @@ -9156,7 +9163,7 @@ I need all branches in an `if` to have the same type! Abilities cannot depend on type variables, but their member values can! - ── UNUSED DEFINITION ─────────────────────────────────────────────────────────── + ── UNUSED DEFINITION ───────────────────────────────────── /code/proj/Main.roc ─ `Hash` is not used anywhere in your code. @@ -9173,6 +9180,7 @@ I need all branches in an `if` to have the same type! #[test] fn alias_in_has_clause() { new_report_problem_as( + "alias_in_has_clause", indoc!( r#" app "test" provides [ hash ] to "./platform" @@ -9182,7 +9190,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── HAS CLAUSE IS NOT AN ABILITY ──────────────────────────────────────────────── + ── HAS CLAUSE IS NOT AN ABILITY ────────────────────────── /code/proj/Main.roc ─ The type referenced in this "has" clause is not an ability: @@ -9196,6 +9204,7 @@ I need all branches in an `if` to have the same type! #[test] fn shadowed_type_variable_in_has_clause() { new_report_problem_as( + "shadowed_type_variable_in_has_clause", indoc!( r#" app "test" provides [ ab1 ] to "./platform" @@ -9205,7 +9214,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── DUPLICATE NAME ─────────────────────────────────────────────────── REPL.roc ─ + ── DUPLICATE NAME ──────────────────────────────────────── /code/proj/Main.roc ─ The `a` name is first defined here: @@ -9227,6 +9236,7 @@ I need all branches in an `if` to have the same type! #[test] fn alias_using_ability() { new_report_problem_as( + "alias_using_ability", indoc!( r#" app "test" provides [ a ] to "./platform" @@ -9240,7 +9250,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── ALIAS USES ABILITY ────────────────────────────────────────────────────────── + ── ALIAS USES ABILITY ──────────────────────────────────── /code/proj/Main.roc ─ The definition of the `Alias` aliases references the ability `Ability`: @@ -9254,7 +9264,7 @@ I need all branches in an `if` to have the same type! at the end of the type. - ── UNUSED DEFINITION ─────────────────────────────────────────────────────────── + ── UNUSED DEFINITION ───────────────────────────────────── /code/proj/Main.roc ─ `ab` is not used anywhere in your code. @@ -9271,6 +9281,7 @@ I need all branches in an `if` to have the same type! #[test] fn ability_shadows_ability() { new_report_problem_as( + "ability_shadows_ability", indoc!( r#" app "test" provides [ ab ] to "./platform" @@ -9282,7 +9293,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── DUPLICATE NAME ─────────────────────────────────────────────────── REPL.roc ─ + ── DUPLICATE NAME ──────────────────────────────────────── /code/proj/Main.roc ─ The `Ability` name is first defined here: @@ -9304,6 +9315,7 @@ I need all branches in an `if` to have the same type! #[test] fn ability_member_does_not_bind_ability() { new_report_problem_as( + "ability_member_does_not_bind_ability", indoc!( r#" app "test" provides [ ] to "./platform" @@ -9313,7 +9325,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── ABILITY MEMBER MISSING HAS CLAUSE ─────────────────────────────────────────── + ── ABILITY MEMBER MISSING HAS CLAUSE ───────────────────── /code/proj/Main.roc ─ The definition of the ability member `ab` does not include a `has` clause binding a type variable to the ability `Ability`: @@ -9328,7 +9340,7 @@ I need all branches in an `if` to have the same type! Otherwise, the function does not need to be part of the ability! - ── UNUSED DEFINITION ─────────────────────────────────────────────────────────── + ── UNUSED DEFINITION ───────────────────────────────────── /code/proj/Main.roc ─ `Ability` is not used anywhere in your code. @@ -9338,7 +9350,7 @@ I need all branches in an `if` to have the same type! If you didn't intend on using `Ability` then remove it so future readers of your code don't wonder why it is there. - ── UNUSED DEFINITION ─────────────────────────────────────────────────────────── + ── UNUSED DEFINITION ───────────────────────────────────── /code/proj/Main.roc ─ `ab` is not used anywhere in your code. @@ -9355,6 +9367,7 @@ I need all branches in an `if` to have the same type! #[test] fn ability_member_binds_extra_ability() { new_report_problem_as( + "ability_member_binds_extra_ability", indoc!( r#" app "test" provides [ eq ] to "./platform" @@ -9365,7 +9378,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── ABILITY MEMBER HAS EXTRANEOUS HAS CLAUSE ──────────────────────────────────── + ── ABILITY MEMBER HAS EXTRANEOUS HAS CLAUSE ────────────── /code/proj/Main.roc ─ The definition of the ability member `hash` includes a has clause binding an ability it is not a part of: @@ -9378,7 +9391,7 @@ I need all branches in an `if` to have the same type! Hint: Did you mean to bind the `Hash` ability instead? - ── UNUSED DEFINITION ─────────────────────────────────────────────────────────── + ── UNUSED DEFINITION ───────────────────────────────────── /code/proj/Main.roc ─ `hash` is not used anywhere in your code. @@ -9395,6 +9408,7 @@ I need all branches in an `if` to have the same type! #[test] fn ability_member_binds_parent_twice() { new_report_problem_as( + "ability_member_binds_parent_twice", indoc!( r#" app "test" provides [ ] to "./platform" @@ -9404,7 +9418,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── ABILITY MEMBER BINDS MULTIPLE VARIABLES ───────────────────────────────────── + ── ABILITY MEMBER BINDS MULTIPLE VARIABLES ─────────────── /code/proj/Main.roc ─ The definition of the ability member `eq` includes multiple variables bound to the `Eq`` ability:` @@ -9418,7 +9432,7 @@ I need all branches in an `if` to have the same type! Hint: Did you mean to only bind `a` to `Eq`? - ── UNUSED DEFINITION ─────────────────────────────────────────────────────────── + ── UNUSED DEFINITION ───────────────────────────────────── /code/proj/Main.roc ─ `eq` is not used anywhere in your code. @@ -9435,6 +9449,7 @@ I need all branches in an `if` to have the same type! #[test] fn has_clause_not_on_toplevel() { new_report_problem_as( + "has_clause_outside_of_ability", indoc!( r#" app "test" provides [ f ] to "./platform" @@ -9446,7 +9461,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── ILLEGAL HAS CLAUSE ────────────────────────────────────────────────────────── + ── ILLEGAL HAS CLAUSE ──────────────────────────────────── /code/proj/Main.roc ─ A `has` clause is not allowed here: @@ -9487,6 +9502,7 @@ I need all branches in an `if` to have the same type! #[test] fn ability_specialization_with_non_implementing_type() { new_report_problem_as( + "ability_specialization_with_non_implementing_type", indoc!( r#" app "test" provides [ hash ] to "./platform" @@ -9498,7 +9514,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ Something is off with this specialization of `hash`: @@ -9525,6 +9541,7 @@ I need all branches in an `if` to have the same type! #[test] fn ability_specialization_does_not_match_type() { new_report_problem_as( + "ability_specialization_does_not_match_type", indoc!( r#" app "test" provides [ hash ] to "./platform" @@ -9538,7 +9555,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ Something is off with this specialization of `hash`: @@ -9560,6 +9577,7 @@ I need all branches in an `if` to have the same type! #[test] fn ability_specialization_is_incomplete() { new_report_problem_as( + "ability_specialization_is_incomplete", indoc!( r#" app "test" provides [ eq, le ] to "./platform" @@ -9575,7 +9593,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── INCOMPLETE ABILITY IMPLEMENTATION ─────────────────────────────────────────── + ── INCOMPLETE ABILITY IMPLEMENTATION ───────────────────── /code/proj/Main.roc ─ The type `Id` does not fully implement the ability `Eq`. The following specializations are missing: @@ -9599,6 +9617,7 @@ I need all branches in an `if` to have the same type! #[test] fn ability_specialization_overly_generalized() { new_report_problem_as( + "ability_specialization_overly_generalized", indoc!( r#" app "test" provides [ hash ] to "./platform" @@ -9611,7 +9630,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ This specialization of `hash` is overly general: @@ -9640,6 +9659,7 @@ I need all branches in an `if` to have the same type! #[test] fn ability_specialization_conflicting_specialization_types() { new_report_problem_as( + "ability_specialization_conflicting_specialization_types", indoc!( r#" app "test" provides [ eq ] to "./platform" @@ -9655,7 +9675,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ Something is off with this specialization of `eq`: @@ -9682,6 +9702,7 @@ I need all branches in an `if` to have the same type! #[test] fn ability_specialization_checked_against_annotation() { new_report_problem_as( + "ability_specialization_checked_against_annotation", indoc!( r#" app "test" provides [ hash ] to "./platform" @@ -9697,7 +9718,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ Something is off with the body of this definition: @@ -9713,7 +9734,7 @@ I need all branches in an `if` to have the same type! U32 - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ Something is off with this specialization of `hash`: @@ -9735,6 +9756,7 @@ I need all branches in an `if` to have the same type! #[test] fn ability_specialization_called_with_non_specializing() { new_report_problem_as( + "ability_specialization_called_with_non_specializing", indoc!( r#" app "test" provides [ noGoodVeryBadTerrible ] to "./platform" @@ -9757,7 +9779,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ The 1st argument to `hash` is not what I expect: @@ -9772,7 +9794,7 @@ I need all branches in an `if` to have the same type! a | a has Hash - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ This expression has a type that does not implement the abilities it's expected to: From bfbd810ae666d4463ff5ca454b339ec1e1c7e3c5 Mon Sep 17 00:00:00 2001 From: Jared Cone Date: Wed, 20 Apr 2022 21:07:25 -0700 Subject: [PATCH 391/846] Updated new tests --- compiler/load_internal/tests/test_load.rs | 2 +- reporting/tests/test_reporting.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/load_internal/tests/test_load.rs b/compiler/load_internal/tests/test_load.rs index 72ebf8df50..cc4499c7f0 100644 --- a/compiler/load_internal/tests/test_load.rs +++ b/compiler/load_internal/tests/test_load.rs @@ -856,7 +856,7 @@ mod test_load { ), ]; - match multiple_modules(modules) { + match multiple_modules("issue_2863_module_type_does_not_exist", modules) { Err(report) => { assert_eq!( report, diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index feea376e9c..43879a808d 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -9825,6 +9825,7 @@ I need all branches in an `if` to have the same type! #[test] fn ability_not_on_toplevel() { new_report_problem_as( + "ability_not_on_toplevel", indoc!( r#" app "test" provides [ main ] to "./platform" From 497b8c114e5df91ff46545fd493ffe752020663d Mon Sep 17 00:00:00 2001 From: Jared Cone Date: Wed, 20 Apr 2022 22:02:13 -0700 Subject: [PATCH 392/846] Updated new tests --- compiler/load_internal/tests/test_load.rs | 2 +- reporting/tests/test_reporting.rs | 2 ++ test_utils/Cargo.toml | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/compiler/load_internal/tests/test_load.rs b/compiler/load_internal/tests/test_load.rs index cc4499c7f0..8cfd332c99 100644 --- a/compiler/load_internal/tests/test_load.rs +++ b/compiler/load_internal/tests/test_load.rs @@ -862,7 +862,7 @@ mod test_load { report, indoc!( " - ── UNRECOGNIZED NAME ─────────────────────────────────────────────────────────── + ── UNRECOGNIZED NAME ────────── tmp/issue_2863_module_type_does_not_exist/Main ─ I cannot find a `DoesNotExist` value diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 43879a808d..ed7f6703c4 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -9855,6 +9855,7 @@ I need all branches in an `if` to have the same type! #[test] fn expression_generalization_to_ability_is_an_error() { new_report_problem_as( + "expression_generalization_to_ability_is_an_error", indoc!( r#" app "test" provides [ hash, hashable ] to "./platform" @@ -9900,6 +9901,7 @@ I need all branches in an `if` to have the same type! #[test] fn ability_value_annotations_are_an_error() { new_report_problem_as( + "ability_value_annotations_are_an_error", indoc!( r#" app "test" provides [ result ] to "./platform" diff --git a/test_utils/Cargo.toml b/test_utils/Cargo.toml index b1ce5e9843..1a2efaceb1 100644 --- a/test_utils/Cargo.toml +++ b/test_utils/Cargo.toml @@ -9,3 +9,5 @@ description = "Utility functions used all over the code base." [dependencies] pretty_assertions = "1.0.0" remove_dir_all = "0.7.0" + +[dev-dependencies] From f097a4ffdb03a6261818fd627138673f0a484d35 Mon Sep 17 00:00:00 2001 From: Jared Cone Date: Wed, 20 Apr 2022 22:59:28 -0700 Subject: [PATCH 393/846] Updated new tests --- reporting/tests/test_reporting.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index ed7f6703c4..8d25660f64 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -9470,7 +9470,7 @@ I need all branches in an `if` to have the same type! `has` clauses can only be specified on the top-level type annotations. - ── ABILITY MEMBER MISSING HAS CLAUSE ─────────────────────────────────────────── + ── ABILITY MEMBER MISSING HAS CLAUSE ───────────────────── /code/proj/Main.roc ─ The definition of the ability member `hash` does not include a `has` clause binding a type variable to the ability `Hash`: @@ -9485,7 +9485,7 @@ I need all branches in an `if` to have the same type! Otherwise, the function does not need to be part of the ability! - ── UNUSED DEFINITION ─────────────────────────────────────────────────────────── + ── UNUSED DEFINITION ───────────────────────────────────── /code/proj/Main.roc ─ `hash` is not used anywhere in your code. @@ -9839,7 +9839,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── ABILITY NOT ON TOP-LEVEL ──────────────────────────────────────────────────── + ── ABILITY NOT ON TOP-LEVEL ────────────────────────────── /code/proj/Main.roc ─ This ability definition is not on the top-level of a module: @@ -9872,7 +9872,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ Something is off with the body of the `hashable` definition: @@ -9923,7 +9923,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── ABILITY USED AS TYPE ──────────────────────────────────────────────────────── + ── ABILITY USED AS TYPE ────────────────────────────────── /code/proj/Main.roc ─ You are attempting to use the ability `Hash` as a type directly: @@ -9937,7 +9937,7 @@ I need all branches in an `if` to have the same type! a has Hash - ── ABILITY USED AS TYPE ──────────────────────────────────────────────────────── + ── ABILITY USED AS TYPE ────────────────────────────────── /code/proj/Main.roc ─ You are attempting to use the ability `Hash` as a type directly: From 21661275d8818e7f58afdfdf885a0a2034f09659 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 20 Apr 2022 14:18:12 -0400 Subject: [PATCH 394/846] Show unified variables as a tree --- compiler/unify/src/unify.rs | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/compiler/unify/src/unify.rs b/compiler/unify/src/unify.rs index cebebcca4f..a8ceea4cd6 100644 --- a/compiler/unify/src/unify.rs +++ b/compiler/unify/src/unify.rs @@ -275,11 +275,24 @@ pub fn unify_pool( } #[cfg(debug_assertions)] -fn debug_print_unified_types(subs: &mut Subs, ctx: &Context, before_unified: bool) { +fn debug_print_unified_types(subs: &mut Subs, ctx: &Context, opt_outcome: Option<&Outcome>) { + static mut UNIFICATION_DEPTH: usize = 0; + if std::env::var("ROC_PRINT_UNIFICATIONS").is_ok() { - let time = if before_unified { "START" } else { "END" }; - // if true, print the types that are unified. - // + let prefix = match opt_outcome { + None => "❔", + Some(outcome) if outcome.mismatches.is_empty() => "✅", + Some(_) => "❌", + }; + + let depth = unsafe { UNIFICATION_DEPTH }; + let indent = 2; + let (use_depth, new_depth) = if opt_outcome.is_none() { + (depth, depth + indent) + } else { + (depth - indent, depth - indent) + }; + // NOTE: names are generated here (when creating an error type) and that modifies names // generated by pretty_print.rs. So many test will fail with changes in variable names when // this block runs. @@ -294,8 +307,9 @@ fn debug_print_unified_types(subs: &mut Subs, ctx: &Context, before_unified: boo let content_2 = subs.get(ctx.second).content; let mode = if ctx.mode.is_eq() { "~" } else { "+=" }; eprintln!( - "{}({:?}-{:?}): {:?} {:?} {} {:?} {:?}", - time, + "{}{}({:?}-{:?}): {:?} {:?} {} {:?} {:?}", + " ".repeat(use_depth), + prefix, ctx.first, ctx.second, ctx.first, @@ -304,12 +318,14 @@ fn debug_print_unified_types(subs: &mut Subs, ctx: &Context, before_unified: boo ctx.second, roc_types::subs::SubsFmtContent(&content_2, subs), ); + + unsafe { UNIFICATION_DEPTH = new_depth }; } } fn unify_context(subs: &mut Subs, pool: &mut Pool, ctx: Context) -> Outcome { #[cfg(debug_assertions)] - debug_print_unified_types(subs, &ctx, true); + debug_print_unified_types(subs, &ctx, None); let result = match &ctx.first_desc.content { FlexVar(opt_name) => unify_flex(subs, &ctx, opt_name, None, &ctx.second_desc.content), @@ -349,7 +365,7 @@ fn unify_context(subs: &mut Subs, pool: &mut Pool, ctx: Context) -> Outcome { }; #[cfg(debug_assertions)] - debug_print_unified_types(subs, &ctx, false); + debug_print_unified_types(subs, &ctx, Some(&result)); result } From 11f29baf25df2cfb4ca30cc20b67d06f1ccaea64 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 21 Apr 2022 09:34:40 -0400 Subject: [PATCH 395/846] Add note about output --- compiler/unify/src/unify.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler/unify/src/unify.rs b/compiler/unify/src/unify.rs index a8ceea4cd6..10738f6382 100644 --- a/compiler/unify/src/unify.rs +++ b/compiler/unify/src/unify.rs @@ -274,6 +274,9 @@ pub fn unify_pool( } } +/// Set `ROC_PRINT_UNIFICATIONS` in debug runs to print unifications as they start and complete as +/// a tree to stderr. +/// NOTE: Only run this on individual tests! Run on multiple threads, this would clobber each others' output. #[cfg(debug_assertions)] fn debug_print_unified_types(subs: &mut Subs, ctx: &Context, opt_outcome: Option<&Outcome>) { static mut UNIFICATION_DEPTH: usize = 0; From 6942216474a8ae873804c1a441a4d5493e91b2b9 Mon Sep 17 00:00:00 2001 From: Tommy Graves Date: Thu, 21 Apr 2022 21:12:30 -0400 Subject: [PATCH 396/846] Adds rwx to the Sponsors section of the README --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2b094900b3..c0c5f98702 100644 --- a/README.md +++ b/README.md @@ -32,11 +32,13 @@ For NQueens, input 10 in the terminal and press enter. **Tip:** when programming in roc, we recommend to execute `./roc check myproject/Foo.roc` before `./roc myproject/Foo.roc` or `./roc build myproject/Foo.roc`. `./roc check` can produce clear error messages in cases where building/running may panic. -## Sponsor +## Sponsors -We are very grateful for our sponsor [NoRedInk](https://www.noredink.com/). +We are very grateful for our sponsors [NoRedInk](https://www.noredink.com/) and [rwx](https://www.rwx.com). -NoRedInk logo +[NoRedInk logo](https://www.noredink.com/) +     +[rwx logo](https://www.rwx.com) ## Applications and Platforms From 1ee2f85f9ee07c3bcdd05a72ce0a02072abb5e08 Mon Sep 17 00:00:00 2001 From: Jared Cone Date: Thu, 21 Apr 2022 22:44:07 -0700 Subject: [PATCH 397/846] Exclude filename from repl reports. --- repl_eval/src/gen.rs | 2 +- repl_test/src/tests.rs | 10 +++++----- reporting/src/report.rs | 29 ++++++++++++++++++----------- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/repl_eval/src/gen.rs b/repl_eval/src/gen.rs index 4e8f698c29..efe32c4ca1 100644 --- a/repl_eval/src/gen.rs +++ b/repl_eval/src/gen.rs @@ -47,7 +47,7 @@ pub fn compile_to_mono<'a>( target_info: TargetInfo, palette: Palette, ) -> Result, Vec> { - let filename = PathBuf::from("REPL.roc"); + let filename = PathBuf::from(""); let src_dir = Path::new("fake/test/path"); let module_src = arena.alloc(promote_expr_to_module(src)); diff --git a/repl_test/src/tests.rs b/repl_test/src/tests.rs index b66fcd17aa..53b692266c 100644 --- a/repl_test/src/tests.rs +++ b/repl_test/src/tests.rs @@ -575,7 +575,7 @@ fn too_few_args() { "Num.add 2", indoc!( r#" - ── TOO FEW ARGS ───────────────────────────────────────────────────── REPL.roc ─ + ── TOO FEW ARGS ──────────────────────────────────────────────────────────────── The add function expects 2 arguments, but it got only 1: @@ -596,7 +596,7 @@ fn type_problem() { "1 + \"\"", indoc!( r#" - ── TYPE MISMATCH ──────────────────────────────────────────────────── REPL.roc ─ + ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── The 2nd argument to add is not what I expect: @@ -882,7 +882,7 @@ fn parse_problem() { "add m n = m + n", indoc!( r#" - ── ARGUMENTS BEFORE EQUALS ────────────────────────────────────────── REPL.roc ─ + ── ARGUMENTS BEFORE EQUALS ───────────────────────────────────────────────────── I am partway through parsing a definition, but I got stuck here: @@ -912,7 +912,7 @@ fn mono_problem() { "#, indoc!( r#" - ── UNSAFE PATTERN ─────────────────────────────────────────────────── REPL.roc ─ + ── UNSAFE PATTERN ────────────────────────────────────────────────────────────── This when does not cover all the possibilities: @@ -948,7 +948,7 @@ fn issue_2343_complete_mono_with_shadowed_vars() { ), indoc!( r#" - ── DUPLICATE NAME ─────────────────────────────────────────────────── REPL.roc ─ + ── DUPLICATE NAME ────────────────────────────────────────────────────────────── The b name is first defined here: diff --git a/reporting/src/report.rs b/reporting/src/report.rs index 448a82162f..2f26a35c75 100644 --- a/reporting/src/report.rs +++ b/reporting/src/report.rs @@ -3,7 +3,7 @@ use roc_module::ident::{Lowercase, ModuleName, TagName, Uppercase}; use roc_module::symbol::{Interns, ModuleId, Symbol}; use roc_region::all::LineColumnRegion; use std::fmt; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use ven_pretty::{BoxAllocator, DocAllocator, DocBuilder, Render, RenderAnnotated}; pub use crate::error::canonicalize::can_problem; @@ -60,7 +60,15 @@ pub fn cycle<'b>( .annotate(Annotation::TypeBlock) } -pub fn pretty_header(title: &str, path: &std::path::Path) -> String { +const HEADER_WIDTH: usize = 80; + +pub fn pretty_header(title: &str) -> String { + let title_width = title.len() + 4; + let header = format!("── {} {}", title, "─".repeat(HEADER_WIDTH - title_width)); + header +} + +pub fn pretty_header_with_path(title: &str, path: &Path) -> String { let cwd = std::env::current_dir().unwrap(); let relative_path = match path.strip_prefix(cwd) { Ok(p) => p, @@ -69,17 +77,12 @@ pub fn pretty_header(title: &str, path: &std::path::Path) -> String { .to_str() .unwrap(); - let header_width = 80; let title_width = title.len() + 4; let relative_path_width = relative_path.len() + 3; - let available_path_width = header_width - title_width - 1; + let available_path_width = HEADER_WIDTH - title_width - 1; // If path is too long to fit in 80 characters with everything else then truncate it - let path_width = if relative_path_width <= available_path_width { - relative_path_width - } else { - available_path_width - }; + let path_width = relative_path_width.min(available_path_width); let path_trim = relative_path_width - path_width; let path = if path_trim > 0 { format!("...{}", &relative_path[(path_trim + 3)..]) @@ -90,7 +93,7 @@ pub fn pretty_header(title: &str, path: &std::path::Path) -> String { let header = format!( "── {} {} {} ─", title, - "─".repeat(header_width - (title_width + path_width)), + "─".repeat(HEADER_WIDTH - (title_width + path_width)), path ); @@ -166,7 +169,11 @@ impl<'b> Report<'b> { if self.title.is_empty() { self.doc } else { - let header = crate::report::pretty_header(&self.title, &self.filename); + let header = if self.filename == PathBuf::from("") { + crate::report::pretty_header(&self.title) + } else { + crate::report::pretty_header_with_path(&self.title, &self.filename) + }; alloc.stack([alloc.text(header).annotate(Annotation::Header), self.doc]) } From a1faa0ad9d670faade92f8e2d80ae42565562311 Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Fri, 22 Apr 2022 08:57:47 +0200 Subject: [PATCH 398/846] recommend using legacy linker for hello C and Zig for now --- getting_started/linux_x86.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/getting_started/linux_x86.md b/getting_started/linux_x86.md index f499209607..bbc672377a 100644 --- a/getting_started/linux_x86.md +++ b/getting_started/linux_x86.md @@ -24,9 +24,9 @@ # Rust. If you installed rust in this terminal you'll need to open a new one first! ./roc examples/hello-world/rust-platform/helloRust.roc # Zig - ./roc examples/hello-world/zig-platform/helloZig.roc + ./roc examples/hello-world/zig-platform/helloZig.roc --linker=legacy # C - ./roc examples/hello-world/c-platform/helloC.roc + ./roc examples/hello-world/c-platform/helloC.roc --linker=legacy ``` 0. See [here](../README.md#examples) for the other examples. From 705564508525ab2b932637184c50c5ae9e28dc91 Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 22 Apr 2022 11:34:02 +0200 Subject: [PATCH 399/846] add bitvec dependency --- Cargo.lock | 42 +++++++++++++++++++++++++++++++++++++---- compiler/can/Cargo.toml | 1 + 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bd46536149..0690cc0fb7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -242,10 +242,22 @@ version = "0.22.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5237f00a8c86130a0cc317830e558b966dd7850d48a953d998c813f01a41b527" dependencies = [ - "funty", - "radium", + "funty 1.2.0", + "radium 0.6.2", "tap", - "wyz", + "wyz 0.4.0", +] + +[[package]] +name = "bitvec" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1489fcb93a5bb47da0462ca93ad252ad6af2145cce58d10d46a83931ba9f016b" +dependencies = [ + "funty 2.0.0", + "radium 0.7.0", + "tap", + "wyz 0.5.0", ] [[package]] @@ -1393,6 +1405,12 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1847abb9cb65d566acd5942e94aea9c8f547ad02c98e1649326fc0e8910b8b1e" +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + [[package]] name = "futures" version = "0.3.17" @@ -2645,7 +2663,7 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c48e482b9a59ad6c2cdb06f7725e7bd33fe3525baaf4699fde7bfea6a5b77b1" dependencies = [ - "bitvec", + "bitvec 0.22.3", "packed_struct_codegen", "serde", ] @@ -3092,6 +3110,12 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "643f8f41a8ebc4c5dc4515c82bb8abd397b527fc20fd681b7c011c2aee5d44fb" +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + [[package]] name = "radix_trie" version = "0.2.1" @@ -3422,6 +3446,7 @@ dependencies = [ name = "roc_can" version = "0.1.0" dependencies = [ + "bitvec 1.0.0", "bumpalo", "indoc", "pretty_assertions", @@ -5595,6 +5620,15 @@ dependencies = [ "tap", ] +[[package]] +name = "wyz" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30b31594f29d27036c383b53b59ed3476874d518f0efb151b27a4c275141390e" +dependencies = [ + "tap", +] + [[package]] name = "x11-clipboard" version = "0.5.3" diff --git a/compiler/can/Cargo.toml b/compiler/can/Cargo.toml index 159b8429a3..b1d092053e 100644 --- a/compiler/can/Cargo.toml +++ b/compiler/can/Cargo.toml @@ -17,6 +17,7 @@ roc_builtins = { path = "../builtins" } ven_graph = { path = "../../vendor/pathfinding" } bumpalo = { version = "3.8.0", features = ["collections"] } static_assertions = "1.1.0" +bitvec = "1" [dev-dependencies] pretty_assertions = "1.0.0" From b6ccd9c8fb2edf2c34b631d2606e1ce2cfa46ba7 Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 22 Apr 2022 11:35:08 +0200 Subject: [PATCH 400/846] use bitvec-based topological sort --- compiler/can/src/def.rs | 496 ++++++++++++++++++++++++++++++++++++- compiler/can/src/module.rs | 6 +- 2 files changed, 496 insertions(+), 6 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 1c0254d315..886d5129a7 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -11,6 +11,8 @@ use crate::scope::create_alias; use crate::scope::Scope; use roc_collections::{default_hasher, ImEntry, ImMap, ImSet, MutMap, MutSet, SendMap}; use roc_module::ident::Lowercase; +use roc_module::symbol::IdentId; +use roc_module::symbol::ModuleId; use roc_module::symbol::Symbol; use roc_parse::ast; use roc_parse::ast::AbilityMember; @@ -659,6 +661,407 @@ pub fn canonicalize_defs<'a>( ) } +#[derive(Clone, Copy)] +struct DefId(u32); + +#[derive(Debug)] +struct DefIds { + home: ModuleId, + symbol_to_id: Vec<(IdentId, u32)>, + + // an length x length matrix indicating who references who + references: bitvec::vec::BitVec, + length: u32, +} + +impl DefIds { + fn with_capacity(home: ModuleId, capacity: usize) -> Self { + use bitvec::vec::BitVec; + + // makes each new row start at a multiple of 8 + // let hack = capacity + (8 - capacity % 8); + let references = BitVec::repeat(false, capacity * capacity); + + Self { + home, + symbol_to_id: Vec::with_capacity(capacity), + references, + length: capacity as u32, + } + } + + fn from_defs_by_symbol( + env: &Env, + can_defs_by_symbol: &MutMap, + refs_by_symbol: &MutMap, + ) -> Self { + let mut this = Self::with_capacity(env.home, can_defs_by_symbol.len()); + + for (i, symbol) in can_defs_by_symbol.keys().enumerate() { + debug_assert_eq!(env.home, symbol.module_id()); + + this.symbol_to_id.push((symbol.ident_id(), i as u32)); + } + + for (symbol, (_, references)) in refs_by_symbol.iter() { + let def_id = DefId(this.get_id(*symbol).unwrap()); + + for referenced in references.value_lookups() { + this.register_reference(def_id, *referenced); + } + + for referenced in references.calls() { + this.register_reference(def_id, *referenced); + } + + if let Some(references) = env.closures.get(symbol) { + for referenced in references.value_lookups() { + this.register_reference(def_id, *referenced); + } + + for referenced in references.calls() { + this.register_reference(def_id, *referenced); + } + } + } + + this + } + + fn get_id(&self, symbol: Symbol) -> Option { + self.symbol_to_id + .iter() + .find(|(id, _)| *id == symbol.ident_id()) + .map(|t| t.1) + } + + fn get_symbol(&self, id: u32) -> Option { + self.symbol_to_id + .iter() + .find(|(_, def_id)| id == *def_id) + .map(|t| Symbol::new(self.home, t.0)) + } + + fn register_reference(&mut self, id: DefId, referenced: Symbol) -> bool { + if referenced.module_id() != self.home { + return false; + } + + match self.get_id(referenced) { + None => { + // this symbol is not defined within the let-block that this DefIds represents + false + } + Some(referenced_id) => { + let row = id.0; + let column = referenced_id; + + let index = row * self.length + column; + + self.references.set(index as usize, true); + + true + } + } + } + + fn calls_itself_directly(&self, id: u32) -> bool { + let row = &self.references[(id * self.length) as usize..][..self.length as usize]; + + row[id as usize] + } + + #[inline(always)] + fn successors(&self, id: u32) -> impl Iterator + '_ { + let row = &self.references[(id * self.length) as usize..][..self.length as usize]; + + row.iter_ones().map(|x| x as u32) + } + + #[inline(always)] + fn successors_without_self(&self, id: u32) -> impl Iterator + '_ { + self.successors(id).filter(move |x| *x != id) + } + + #[allow(clippy::type_complexity)] + fn topological_sort_into_groups(&self) -> Result>, (Vec>, Vec)> { + let length = self.length as usize; + let bitvec = &self.references; + + if length == 0 { + return Ok(Vec::new()); + } + + let mut preds_map: Vec = vec![0; length]; + + // this is basically summing the columns, I don't see a better way to do it + for row in bitvec.chunks(length) { + for succ in row.iter_ones() { + preds_map[succ] += 1; + } + } + + let mut groups = Vec::>::new(); + + // the initial group contains all symbols with no predecessors + let mut prev_group: Vec = preds_map + .iter() + .enumerate() + .filter_map(|(node, &num_preds)| { + if num_preds == 0 { + Some(node as u32) + } else { + None + } + }) + .collect(); + + if prev_group.is_empty() { + let remaining: Vec = (0u32..length as u32).collect(); + return Err((Vec::new(), remaining)); + } + + // NOTE: the original now removes elements from the preds_map if they have count 0 + // for node in &prev_group { + // preds_map.remove(node); + // } + + while preds_map.iter().any(|x| *x > 0) { + let mut next_group = Vec::::new(); + for node in &prev_group { + let row = &bitvec[length * (*node as usize)..][..length]; + for succ in row.iter_ones() { + { + let num_preds = preds_map.get_mut(succ).unwrap(); + *num_preds = num_preds.saturating_sub(1); + if *num_preds > 0 { + continue; + } + } + + let count = preds_map[succ]; + preds_map[succ] = -1; + + if count > -1 { + next_group.push(succ as u32); + } + } + } + groups.push(std::mem::replace(&mut prev_group, next_group)); + if prev_group.is_empty() { + let remaining: Vec = (0u32..length as u32) + .filter(|i| preds_map[*i as usize] > 0) + .collect(); + return Err((groups, remaining)); + } + } + groups.push(prev_group); + Ok(groups) + } + + #[allow(dead_code)] + fn debug_relations(&self) { + for id in 0u32..self.length as u32 { + let row = &self.references[(id * self.length) as usize..][..self.length as usize]; + + let matches = row + .iter() + .enumerate() + .filter(move |t| *t.1) + .map(|t| t.0 as u32); + + for m in matches { + let a = self.get_symbol(id).unwrap(); + let b = self.get_symbol(m).unwrap(); + + println!("{:?} <- {:?}", a, b); + } + } + } +} + +#[inline(always)] +pub fn sort_can_defs_improved( + env: &mut Env<'_>, + defs: CanDefs, + mut output: Output, +) -> (Result, RuntimeError>, Output) { + let def_ids = DefIds::from_defs_by_symbol(env, &defs.can_defs_by_symbol, &defs.refs_by_symbol); + + let CanDefs { + refs_by_symbol, + mut can_defs_by_symbol, + aliases, + } = defs; + + for (symbol, alias) in aliases.into_iter() { + output.aliases.insert(symbol, alias); + } + + // TODO also do the same `addDirects` check elm/compiler does, so we can + // report an error if a recursive definition can't possibly terminate! + match def_ids.topological_sort_into_groups() { + Ok(groups) => { + let mut declarations = Vec::new(); + + // groups are in reversed order + for group in groups.into_iter().rev() { + group_to_declaration_improved( + &def_ids, + &group, + &env.closures, + &mut can_defs_by_symbol, + &mut declarations, + ); + } + + (Ok(declarations), output) + } + Err((mut groups, nodes_in_cycle)) => { + let mut declarations = Vec::new(); + let mut problems = Vec::new(); + + // nodes_in_cycle are symbols that form a syntactic cycle. That isn't always a problem, + // and in general it's impossible to decide whether it is. So we use a crude heuristic: + // + // Definitions where the cycle occurs behind a lambda are OK + // + // boom = \_ -> boom {} + // + // But otherwise we report an error, e.g. + // + // foo = if b then foo else bar + + let all_successors_without_self = |id: &u32| { + let id = *id; + def_ids.successors_without_self(id) + }; + + for cycle in strongly_connected_components(&nodes_in_cycle, all_successors_without_self) + { + // check whether the cycle is faulty, which is when it has + // a direct successor in the current cycle. This catches things like: + // + // x = x + // + // or + // + // p = q + // q = p + let is_invalid_cycle = match cycle.get(0) { + Some(def_id) => def_ids.successors(*def_id).any(|key| cycle.contains(&key)), + None => false, + }; + + if is_invalid_cycle { + // We want to show the entire cycle in the error message, so expand it out. + let mut entries = Vec::new(); + + for def_id in &cycle { + let symbol = def_ids.get_symbol(*def_id).unwrap(); + match refs_by_symbol.get(&symbol) { + None => unreachable!( + r#"Symbol `{:?}` not found in refs_by_symbol! refs_by_symbol was: {:?}"#, + symbol, refs_by_symbol + ), + Some((region, _)) => { + let expr_region = + can_defs_by_symbol.get(&symbol).unwrap().loc_expr.region; + + let entry = CycleEntry { + symbol, + symbol_region: *region, + expr_region, + }; + + entries.push(entry); + } + } + } + + // Sort them by line number to make the report more helpful. + entries.sort_by_key(|entry| entry.symbol_region); + + problems.push(Problem::RuntimeError(RuntimeError::CircularDef( + entries.clone(), + ))); + + declarations.push(Declaration::InvalidCycle(entries)); + } + + // if it's an invalid cycle, other groups may depend on the + // symbols defined here, so also push this cycle onto the groups + // + // if it's not an invalid cycle, this is slightly inefficient, + // because we know this becomes exactly one DeclareRec already + groups.push(cycle); + } + + // now we have a collection of groups whose dependencies are not cyclic. + // They are however not yet topologically sorted. Here we have to get a bit + // creative to get all the definitions in the correct sorted order. + + let mut group_ids = Vec::with_capacity(groups.len()); + let mut symbol_to_group_index = MutMap::default(); + for (i, group) in groups.iter().enumerate() { + for symbol in group { + symbol_to_group_index.insert(*symbol, i); + } + + group_ids.push(i); + } + + let successors_of_group = |group_id: &usize| { + let mut result = MutSet::default(); + + // for each symbol in this group + for symbol in &groups[*group_id] { + // find its successors + for succ in all_successors_without_self(symbol) { + // and add its group to the result + match symbol_to_group_index.get(&succ) { + Some(index) => { + result.insert(*index); + } + None => unreachable!("no index for symbol {:?}", succ), + } + } + } + + // don't introduce any cycles to self + result.remove(group_id); + + result + }; + + match ven_graph::topological_sort_into_groups(&group_ids, successors_of_group) { + Ok(sorted_group_ids) => { + for sorted_group in sorted_group_ids.iter().rev() { + for group_id in sorted_group.iter().rev() { + let group = &groups[*group_id]; + + group_to_declaration_improved( + &def_ids, + group, + &env.closures, + &mut can_defs_by_symbol, + &mut declarations, + ); + } + } + } + Err(_) => unreachable!("there should be no cycles now!"), + } + + for problem in problems { + env.problem(problem); + } + + (Ok(declarations), output) + } + } +} + #[inline(always)] pub fn sort_can_defs( env: &mut Env<'_>, @@ -807,12 +1210,14 @@ pub fn sort_can_defs( } }; - // TODO also do the same `addDirects` check elm/compiler does, so we can - // report an error if a recursive definition can't possibly terminate! - match ven_graph::topological_sort_into_groups( + let grouped2 = ven_graph::topological_sort_into_groups( defined_symbols.as_slice(), all_successors_without_self, - ) { + ); + + // TODO also do the same `addDirects` check elm/compiler does, so we can + // report an error if a recursive definition can't possibly terminate! + match grouped2 { Ok(groups) => { let mut declarations = Vec::new(); @@ -1060,6 +1465,89 @@ fn group_to_declaration( } } +fn group_to_declaration_improved( + def_ids: &DefIds, + group: &[u32], + closures: &MutMap, + can_defs_by_symbol: &mut MutMap, + declarations: &mut Vec, +) { + use Declaration::*; + + // We want only successors in the current group, otherwise definitions get duplicated + let filtered_successors = |id: &u32| def_ids.successors(*id).filter(|key| group.contains(key)); + + // Patterns like + // + // { x, y } = someDef + // + // Can bind multiple symbols. When not incorrectly recursive (which is guaranteed in this function), + // normally `someDef` would be inserted twice. We use the region of the pattern as a unique key + // for a definition, so every definition is only inserted (thus typechecked and emitted) once + let mut seen_pattern_regions: Vec = Vec::with_capacity(2); + + for cycle in strongly_connected_components(group, filtered_successors) { + if cycle.len() == 1 { + let def_id = cycle[0]; + let symbol = def_ids.get_symbol(def_id).unwrap(); + + match can_defs_by_symbol.remove(&symbol) { + Some(mut new_def) => { + // Determine recursivity of closures that are not tail-recursive + if let Closure(ClosureData { + recursive: recursive @ Recursive::NotRecursive, + .. + }) = &mut new_def.loc_expr.value + { + *recursive = closure_recursivity(symbol, closures); + } + + let is_recursive = def_ids.calls_itself_directly(def_id); + + if !seen_pattern_regions.contains(&new_def.loc_pattern.region) { + seen_pattern_regions.push(new_def.loc_pattern.region); + + if is_recursive { + declarations.push(DeclareRec(vec![new_def])); + } else { + declarations.push(Declare(new_def)); + } + } + } + None => roc_error_macros::internal_error!("def not available {:?}", symbol), + } + } else { + let mut can_defs = Vec::new(); + + // Topological sort gives us the reverse of the sorting we want! + for def_id in cycle.into_iter().rev() { + let symbol = def_ids.get_symbol(def_id).unwrap(); + match can_defs_by_symbol.remove(&symbol) { + Some(mut new_def) => { + // Determine recursivity of closures that are not tail-recursive + if let Closure(ClosureData { + recursive: recursive @ Recursive::NotRecursive, + .. + }) = &mut new_def.loc_expr.value + { + *recursive = closure_recursivity(symbol, closures); + } + + if !seen_pattern_regions.contains(&new_def.loc_pattern.region) { + seen_pattern_regions.push(new_def.loc_pattern.region); + + can_defs.push(new_def); + } + } + None => roc_error_macros::internal_error!("def not available {:?}", symbol), + } + } + + declarations.push(DeclareRec(can_defs)); + } + } +} + fn pattern_to_vars_by_symbol( vars_by_symbol: &mut SendMap, pattern: &Pattern, diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index b34aba4fc5..345d6905af 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -1,5 +1,5 @@ use crate::abilities::AbilitiesStore; -use crate::def::{canonicalize_defs, sort_can_defs, Declaration, Def}; +use crate::def::{canonicalize_defs, sort_can_defs_improved, Declaration, Def}; use crate::effect_module::HostedGeneratedFunctions; use crate::env::Env; use crate::expr::{ClosureData, Expr, Output}; @@ -361,7 +361,9 @@ pub fn canonicalize_module_defs<'a>( ..Default::default() }; - match sort_can_defs(&mut env, defs, new_output) { + let sorted = sort_can_defs_improved(&mut env, defs, new_output); + + match sorted { (Ok(mut declarations), output) => { use crate::def::Declaration::*; From 141f88365df330cdebff52f90f5c08af862dedf0 Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 22 Apr 2022 12:56:50 +0200 Subject: [PATCH 401/846] use extra bitvec to spot faulty recursion --- compiler/can/src/def.rs | 80 ++++++++++++++++++++++++++++++++--------- 1 file changed, 63 insertions(+), 17 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 886d5129a7..d568abf4f2 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -671,6 +671,11 @@ struct DefIds { // an length x length matrix indicating who references who references: bitvec::vec::BitVec, + + // references without looking into closure bodies. + // Used to spot definitely-wrong recursion + direct_references: bitvec::vec::BitVec, + length: u32, } @@ -678,14 +683,14 @@ impl DefIds { fn with_capacity(home: ModuleId, capacity: usize) -> Self { use bitvec::vec::BitVec; - // makes each new row start at a multiple of 8 - // let hack = capacity + (8 - capacity % 8); let references = BitVec::repeat(false, capacity * capacity); + let direct_references = BitVec::repeat(false, capacity * capacity); Self { home, symbol_to_id: Vec::with_capacity(capacity), references, + direct_references, length: capacity as u32, } } @@ -708,10 +713,12 @@ impl DefIds { for referenced in references.value_lookups() { this.register_reference(def_id, *referenced); + this.register_direct_reference(def_id, *referenced); } for referenced in references.calls() { this.register_reference(def_id, *referenced); + this.register_direct_reference(def_id, *referenced); } if let Some(references) = env.closures.get(symbol) { @@ -742,33 +749,70 @@ impl DefIds { .map(|t| Symbol::new(self.home, t.0)) } - fn register_reference(&mut self, id: DefId, referenced: Symbol) -> bool { - if referenced.module_id() != self.home { - return false; - } - - match self.get_id(referenced) { + fn register_help( + id: DefId, + referenced: Option, + length: usize, + bitvec: &mut bitvec::vec::BitVec, + ) -> bool { + match referenced { None => { // this symbol is not defined within the let-block that this DefIds represents false } Some(referenced_id) => { - let row = id.0; - let column = referenced_id; + let row = id.0 as usize; + let column = referenced_id as usize; - let index = row * self.length + column; + let index = row * length + column; - self.references.set(index as usize, true); + bitvec.set(index, true); true } } } - fn calls_itself_directly(&self, id: u32) -> bool { - let row = &self.references[(id * self.length) as usize..][..self.length as usize]; + fn register_direct_reference(&mut self, id: DefId, referenced: Symbol) -> bool { + if referenced.module_id() != self.home { + return false; + } - row[id as usize] + Self::register_help( + id, + self.get_id(referenced), + self.length as usize, + &mut self.direct_references, + ) + } + + fn register_reference(&mut self, id: DefId, referenced: Symbol) -> bool { + if referenced.module_id() != self.home { + return false; + } + + Self::register_help( + id, + self.get_id(referenced), + self.length as usize, + &mut self.references, + ) + } + + fn calls_itself(&self, id: u32) -> bool { + debug_assert!(id < self.length); + + // id'th row, id'th column + let index = (id * self.length) + id; + + self.references[index as usize] + } + + #[inline(always)] + fn direct_successors(&self, id: u32) -> impl Iterator + '_ { + let row = &self.direct_references[(id * self.length) as usize..][..self.length as usize]; + + row.iter_ones().map(|x| x as u32) } #[inline(always)] @@ -949,7 +993,9 @@ pub fn sort_can_defs_improved( // p = q // q = p let is_invalid_cycle = match cycle.get(0) { - Some(def_id) => def_ids.successors(*def_id).any(|key| cycle.contains(&key)), + Some(def_id) => def_ids + .direct_successors(*def_id) + .any(|key| cycle.contains(&key)), None => false, }; @@ -1502,7 +1548,7 @@ fn group_to_declaration_improved( *recursive = closure_recursivity(symbol, closures); } - let is_recursive = def_ids.calls_itself_directly(def_id); + let is_recursive = def_ids.calls_itself(def_id); if !seen_pattern_regions.contains(&new_def.loc_pattern.region) { seen_pattern_regions.push(new_def.loc_pattern.region); From 45567a591c10f321e52b3c04d56b50bdd972dae6 Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 22 Apr 2022 13:42:57 +0200 Subject: [PATCH 402/846] rename --- compiler/can/src/def.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index d568abf4f2..3cf7f0904c 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -799,7 +799,7 @@ impl DefIds { ) } - fn calls_itself(&self, id: u32) -> bool { + fn is_self_recursive(&self, id: u32) -> bool { debug_assert!(id < self.length); // id'th row, id'th column @@ -1548,7 +1548,7 @@ fn group_to_declaration_improved( *recursive = closure_recursivity(symbol, closures); } - let is_recursive = def_ids.calls_itself(def_id); + let is_recursive = def_ids.is_self_recursive(def_id); if !seen_pattern_regions.contains(&new_def.loc_pattern.region) { seen_pattern_regions.push(new_def.loc_pattern.region); From 8c08c6315166892a098ebbd3a01c3ccb8867ed14 Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 22 Apr 2022 14:10:46 +0200 Subject: [PATCH 403/846] faster strongly-connected components --- compiler/can/src/def.rs | 114 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 110 insertions(+), 4 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 3cf7f0904c..700332b9c8 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1511,6 +1511,111 @@ fn group_to_declaration( } } +fn strongly_connected_components_improved( + length: usize, + bitvec: &bitvec::vec::BitVec, + group: &[u32], +) -> Vec> { + let mut params = Params::new(length, group); + + 'outer: loop { + for (node, value) in params.preorders.iter().enumerate() { + if let Preorder::Removed = value { + continue; + } + + recurse_onto(length, bitvec, node, &mut params); + + continue 'outer; + } + + break params.scc; + } +} + +#[derive(Clone, Copy)] +enum Preorder { + Empty, + Filled(usize), + Removed, +} + +struct Params { + preorders: Vec, + c: usize, + p: Vec, + s: Vec, + scc: Vec>, + scca: Vec, +} + +impl Params { + fn new(length: usize, group: &[u32]) -> Self { + let mut preorders = vec![Preorder::Removed; length]; + + for value in group { + preorders[*value as usize] = Preorder::Empty; + } + + Self { + preorders, + c: 0, + s: Vec::new(), + p: Vec::new(), + scc: Vec::new(), + scca: Vec::new(), + } + } +} + +fn recurse_onto(length: usize, bitvec: &bitvec::vec::BitVec, v: usize, params: &mut Params) { + params.preorders[v] = Preorder::Filled(params.c); + + params.c += 1; + + params.s.push(v as u32); + params.p.push(v as u32); + + for w in bitvec[v * length..][..length].iter_ones() { + if !params.scca.contains(&(w as u32)) { + match params.preorders[w] { + Preorder::Filled(pw) => loop { + let index = *params.p.last().unwrap(); + + match params.preorders[index as usize] { + Preorder::Empty => unreachable!(), + Preorder::Filled(current) => { + if current > pw { + params.p.pop(); + } else { + break; + } + } + Preorder::Removed => {} + } + }, + Preorder::Empty => recurse_onto(length, bitvec, w, params), + Preorder::Removed => {} + } + } + } + + if params.p.last() == Some(&(v as u32)) { + params.p.pop(); + + let mut component = Vec::new(); + while let Some(node) = params.s.pop() { + component.push(node); + params.scca.push(node); + params.preorders[node as usize] = Preorder::Removed; + if node as usize == v { + break; + } + } + params.scc.push(component); + } +} + fn group_to_declaration_improved( def_ids: &DefIds, group: &[u32], @@ -1520,9 +1625,6 @@ fn group_to_declaration_improved( ) { use Declaration::*; - // We want only successors in the current group, otherwise definitions get duplicated - let filtered_successors = |id: &u32| def_ids.successors(*id).filter(|key| group.contains(key)); - // Patterns like // // { x, y } = someDef @@ -1532,7 +1634,11 @@ fn group_to_declaration_improved( // for a definition, so every definition is only inserted (thus typechecked and emitted) once let mut seen_pattern_regions: Vec = Vec::with_capacity(2); - for cycle in strongly_connected_components(group, filtered_successors) { + let bitvec = def_ids.references.clone(); + + let sccs = strongly_connected_components_improved(def_ids.length as usize, &bitvec, group); + + for cycle in sccs { if cycle.len() == 1 { let def_id = cycle[0]; let symbol = def_ids.get_symbol(def_id).unwrap(); From 887acb751917f24f1547d7023be0af8767603c75 Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 22 Apr 2022 14:41:42 +0200 Subject: [PATCH 404/846] be smarter about when a function is recursive --- compiler/can/src/def.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 700332b9c8..815f7a13e7 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1634,9 +1634,8 @@ fn group_to_declaration_improved( // for a definition, so every definition is only inserted (thus typechecked and emitted) once let mut seen_pattern_regions: Vec = Vec::with_capacity(2); - let bitvec = def_ids.references.clone(); - - let sccs = strongly_connected_components_improved(def_ids.length as usize, &bitvec, group); + let sccs = + strongly_connected_components_improved(def_ids.length as usize, &def_ids.references, group); for cycle in sccs { if cycle.len() == 1 { @@ -1645,21 +1644,25 @@ fn group_to_declaration_improved( match can_defs_by_symbol.remove(&symbol) { Some(mut new_def) => { - // Determine recursivity of closures that are not tail-recursive + // there is only one definition in this cycle, so we only have + // to check whether it recurses with itself; there is nobody else + // to recurse with, or they would also be in this cycle. + let is_self_recursive = def_ids.is_self_recursive(def_id); + if let Closure(ClosureData { recursive: recursive @ Recursive::NotRecursive, .. }) = &mut new_def.loc_expr.value { - *recursive = closure_recursivity(symbol, closures); + if is_self_recursive { + *recursive = Recursive::Recursive + } } - let is_recursive = def_ids.is_self_recursive(def_id); - if !seen_pattern_regions.contains(&new_def.loc_pattern.region) { seen_pattern_regions.push(new_def.loc_pattern.region); - if is_recursive { + if is_self_recursive { declarations.push(DeclareRec(vec![new_def])); } else { declarations.push(Declare(new_def)); From c763d515511bb336d8ebbcf82a8cda161e2fc310 Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 22 Apr 2022 15:01:53 +0200 Subject: [PATCH 405/846] use new sccs in error case too --- compiler/can/src/def.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 815f7a13e7..424fcd8fbd 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -976,13 +976,13 @@ pub fn sort_can_defs_improved( // // foo = if b then foo else bar - let all_successors_without_self = |id: &u32| { - let id = *id; - def_ids.successors_without_self(id) - }; + let sccs = strongly_connected_components_improved( + def_ids.length as usize, + &def_ids.references, + &nodes_in_cycle, + ); - for cycle in strongly_connected_components(&nodes_in_cycle, all_successors_without_self) - { + for cycle in sccs { // check whether the cycle is faulty, which is when it has // a direct successor in the current cycle. This catches things like: // @@ -1063,7 +1063,7 @@ pub fn sort_can_defs_improved( // for each symbol in this group for symbol in &groups[*group_id] { // find its successors - for succ in all_successors_without_self(symbol) { + for succ in def_ids.successors_without_self(*symbol) { // and add its group to the result match symbol_to_group_index.get(&succ) { Some(index) => { From 8837eb2c19edf7023cfce993c0b9f76bf198bb65 Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 22 Apr 2022 15:09:45 +0200 Subject: [PATCH 406/846] remove old def sorting code --- compiler/can/src/def.rs | 407 +-------------------------------------- compiler/can/src/expr.rs | 30 +-- 2 files changed, 3 insertions(+), 434 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 424fcd8fbd..c0f22484a7 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -4,7 +4,7 @@ use crate::annotation::IntroducedVariables; use crate::env::Env; use crate::expr::ClosureData; use crate::expr::Expr::{self, *}; -use crate::expr::{canonicalize_expr, local_successors_with_duplicates, Output, Recursive}; +use crate::expr::{canonicalize_expr, Output, Recursive}; use crate::pattern::{bindings_from_patterns, canonicalize_def_header_pattern, Pattern}; use crate::procedure::References; use crate::scope::create_alias; @@ -1108,409 +1108,6 @@ pub fn sort_can_defs_improved( } } -#[inline(always)] -pub fn sort_can_defs( - env: &mut Env<'_>, - defs: CanDefs, - mut output: Output, -) -> (Result, RuntimeError>, Output) { - let CanDefs { - refs_by_symbol, - mut can_defs_by_symbol, - aliases, - } = defs; - - for (symbol, alias) in aliases.into_iter() { - output.aliases.insert(symbol, alias); - } - - let mut defined_symbols: Vec = Vec::new(); - - for symbol in can_defs_by_symbol.keys() { - defined_symbols.push(*symbol); - } - - // Use topological sort to reorder the defs based on their dependencies to one another. - // This way, during code gen, no def will refer to a value that hasn't been initialized yet. - // As a bonus, the topological sort also reveals any cycles between the defs, allowing - // us to give a CircularAssignment error for invalid (mutual) recursion, and a `DeclareRec` for mutually - // recursive definitions. - - // All successors that occur in the body of a symbol. - let all_successors_without_self = |symbol: &Symbol| -> Vec { - // This may not be in refs_by_symbol. For example, the `f` in `f x` here: - // - // f = \z -> z - // - // (\x -> - // a = f x - // x - // ) - // - // It's not part of the current defs (the one with `a = f x`); rather, - // it's in the enclosing scope. It's still referenced though, so successors - // will receive it as an argument! - match refs_by_symbol.get(symbol) { - Some((_, references)) => { - // We can only sort the symbols at the current level. That is safe because - // symbols defined at higher levels cannot refer to symbols at lower levels. - // Therefore they can never form a cycle! - // - // In the above example, `f` cannot reference `a`, and in the closure - // a call to `f` cannot cycle back to `a`. - let mut loc_succ = local_successors_with_duplicates(references, &env.closures); - - // if the current symbol is a closure, peek into its body - if let Some(references) = env.closures.get(symbol) { - let home = env.home; - - for lookup in references.value_lookups() { - if lookup != symbol && lookup.module_id() == home { - // DO NOT register a self-call behind a lambda! - // - // We allow `boom = \_ -> boom {}`, but not `x = x` - loc_succ.push(*lookup); - } - } - } - - // remove anything that is not defined in the current block - loc_succ.retain(|key| defined_symbols.contains(key)); - - loc_succ.sort(); - loc_succ.dedup(); - - loc_succ - } - None => vec![], - } - }; - - // All successors that occur in the body of a symbol, including the symbol itself - // This is required to determine whether a symbol is recursive. Recursive symbols - // (that are not faulty) always need a DeclareRec, even if there is just one symbol in the - // group - let mut all_successors_with_self = |symbol: &Symbol| -> Vec { - // This may not be in refs_by_symbol. For example, the `f` in `f x` here: - // - // f = \z -> z - // - // (\x -> - // a = f x - // x - // ) - // - // It's not part of the current defs (the one with `a = f x`); rather, - // it's in the enclosing scope. It's still referenced though, so successors - // will receive it as an argument! - match refs_by_symbol.get(symbol) { - Some((_, references)) => { - // We can only sort the symbols at the current level. That is safe because - // symbols defined at higher levels cannot refer to symbols at lower levels. - // Therefore they can never form a cycle! - // - // In the above example, `f` cannot reference `a`, and in the closure - // a call to `f` cannot cycle back to `a`. - let mut loc_succ = local_successors_with_duplicates(references, &env.closures); - - // if the current symbol is a closure, peek into its body - if let Some(references) = env.closures.get(symbol) { - for lookup in references.value_lookups() { - loc_succ.push(*lookup); - } - } - - // remove anything that is not defined in the current block - loc_succ.retain(|key| defined_symbols.contains(key)); - - loc_succ.sort(); - loc_succ.dedup(); - - loc_succ - } - None => vec![], - } - }; - - // If a symbol is a direct successor of itself, there is an invalid cycle. - // The difference with the function above is that this one does not look behind lambdas, - // but does consider direct self-recursion. - let direct_successors = |symbol: &Symbol| -> Vec { - match refs_by_symbol.get(symbol) { - Some((_, references)) => { - let mut loc_succ = local_successors_with_duplicates(references, &env.closures); - - // NOTE: if the symbol is a closure we DONT look into its body - - // remove anything that is not defined in the current block - loc_succ.retain(|key| defined_symbols.contains(key)); - - // NOTE: direct recursion does matter here: `x = x` is invalid recursion! - - loc_succ.sort(); - loc_succ.dedup(); - - loc_succ - } - None => vec![], - } - }; - - let grouped2 = ven_graph::topological_sort_into_groups( - defined_symbols.as_slice(), - all_successors_without_self, - ); - - // TODO also do the same `addDirects` check elm/compiler does, so we can - // report an error if a recursive definition can't possibly terminate! - match grouped2 { - Ok(groups) => { - let mut declarations = Vec::new(); - - // groups are in reversed order - for group in groups.into_iter().rev() { - group_to_declaration( - &group, - &env.closures, - &mut all_successors_with_self, - &mut can_defs_by_symbol, - &mut declarations, - ); - } - - (Ok(declarations), output) - } - Err((mut groups, nodes_in_cycle)) => { - let mut declarations = Vec::new(); - let mut problems = Vec::new(); - - // nodes_in_cycle are symbols that form a syntactic cycle. That isn't always a problem, - // and in general it's impossible to decide whether it is. So we use a crude heuristic: - // - // Definitions where the cycle occurs behind a lambda are OK - // - // boom = \_ -> boom {} - // - // But otherwise we report an error, e.g. - // - // foo = if b then foo else bar - - for cycle in strongly_connected_components(&nodes_in_cycle, all_successors_without_self) - { - // check whether the cycle is faulty, which is when it has - // a direct successor in the current cycle. This catches things like: - // - // x = x - // - // or - // - // p = q - // q = p - let is_invalid_cycle = match cycle.get(0) { - Some(symbol) => { - let mut succs = direct_successors(symbol); - - succs.retain(|key| cycle.contains(key)); - - !succs.is_empty() - } - None => false, - }; - - if is_invalid_cycle { - // We want to show the entire cycle in the error message, so expand it out. - let mut entries = Vec::new(); - - for symbol in &cycle { - match refs_by_symbol.get(symbol) { - None => unreachable!( - r#"Symbol `{:?}` not found in refs_by_symbol! refs_by_symbol was: {:?}"#, - symbol, refs_by_symbol - ), - Some((region, _)) => { - let expr_region = - can_defs_by_symbol.get(symbol).unwrap().loc_expr.region; - - let entry = CycleEntry { - symbol: *symbol, - symbol_region: *region, - expr_region, - }; - - entries.push(entry); - } - } - } - - // Sort them by line number to make the report more helpful. - entries.sort_by_key(|entry| entry.symbol_region); - - problems.push(Problem::RuntimeError(RuntimeError::CircularDef( - entries.clone(), - ))); - - declarations.push(Declaration::InvalidCycle(entries)); - } - - // if it's an invalid cycle, other groups may depend on the - // symbols defined here, so also push this cycle onto the groups - // - // if it's not an invalid cycle, this is slightly inefficient, - // because we know this becomes exactly one DeclareRec already - groups.push(cycle); - } - - // now we have a collection of groups whose dependencies are not cyclic. - // They are however not yet topologically sorted. Here we have to get a bit - // creative to get all the definitions in the correct sorted order. - - let mut group_ids = Vec::with_capacity(groups.len()); - let mut symbol_to_group_index = MutMap::default(); - for (i, group) in groups.iter().enumerate() { - for symbol in group { - symbol_to_group_index.insert(*symbol, i); - } - - group_ids.push(i); - } - - let successors_of_group = |group_id: &usize| { - let mut result = MutSet::default(); - - // for each symbol in this group - for symbol in &groups[*group_id] { - // find its successors - for succ in all_successors_without_self(symbol) { - // and add its group to the result - match symbol_to_group_index.get(&succ) { - Some(index) => { - result.insert(*index); - } - None => unreachable!("no index for symbol {:?}", succ), - } - } - } - - // don't introduce any cycles to self - result.remove(group_id); - - result - }; - - match ven_graph::topological_sort_into_groups(&group_ids, successors_of_group) { - Ok(sorted_group_ids) => { - for sorted_group in sorted_group_ids.iter().rev() { - for group_id in sorted_group.iter().rev() { - let group = &groups[*group_id]; - - group_to_declaration( - group, - &env.closures, - &mut all_successors_with_self, - &mut can_defs_by_symbol, - &mut declarations, - ); - } - } - } - Err(_) => unreachable!("there should be no cycles now!"), - } - - for problem in problems { - env.problem(problem); - } - - (Ok(declarations), output) - } - } -} - -fn group_to_declaration( - group: &[Symbol], - closures: &MutMap, - successors: &mut dyn FnMut(&Symbol) -> Vec, - can_defs_by_symbol: &mut MutMap, - declarations: &mut Vec, -) { - use Declaration::*; - - // We want only successors in the current group, otherwise definitions get duplicated - let filtered_successors = |symbol: &Symbol| -> Vec { - let mut result = successors(symbol); - - result.retain(|key| group.contains(key)); - result - }; - - // Patterns like - // - // { x, y } = someDef - // - // Can bind multiple symbols. When not incorrectly recursive (which is guaranteed in this function), - // normally `someDef` would be inserted twice. We use the region of the pattern as a unique key - // for a definition, so every definition is only inserted (thus typechecked and emitted) once - let mut seen_pattern_regions: Vec = Vec::with_capacity(2); - - for cycle in strongly_connected_components(group, filtered_successors) { - if cycle.len() == 1 { - let symbol = &cycle[0]; - - match can_defs_by_symbol.remove(symbol) { - Some(mut new_def) => { - // Determine recursivity of closures that are not tail-recursive - if let Closure(ClosureData { - recursive: recursive @ Recursive::NotRecursive, - .. - }) = &mut new_def.loc_expr.value - { - *recursive = closure_recursivity(*symbol, closures); - } - - let is_recursive = successors(symbol).contains(symbol); - - if !seen_pattern_regions.contains(&new_def.loc_pattern.region) { - seen_pattern_regions.push(new_def.loc_pattern.region); - - if is_recursive { - declarations.push(DeclareRec(vec![new_def])); - } else { - declarations.push(Declare(new_def)); - } - } - } - None => roc_error_macros::internal_error!("def not available {:?}", symbol), - } - } else { - let mut can_defs = Vec::new(); - - // Topological sort gives us the reverse of the sorting we want! - for symbol in cycle.into_iter().rev() { - match can_defs_by_symbol.remove(&symbol) { - Some(mut new_def) => { - // Determine recursivity of closures that are not tail-recursive - if let Closure(ClosureData { - recursive: recursive @ Recursive::NotRecursive, - .. - }) = &mut new_def.loc_expr.value - { - *recursive = closure_recursivity(symbol, closures); - } - - if !seen_pattern_regions.contains(&new_def.loc_pattern.region) { - seen_pattern_regions.push(new_def.loc_pattern.region); - - can_defs.push(new_def); - } - } - None => roc_error_macros::internal_error!("def not available {:?}", symbol), - } - } - - declarations.push(DeclareRec(can_defs)); - } - } -} - fn strongly_connected_components_improved( length: usize, bitvec: &bitvec::vec::BitVec, @@ -2277,7 +1874,7 @@ pub fn can_defs_with_return<'a>( } } - let (can_defs, output) = sort_can_defs(env, unsorted, output); + let (can_defs, output) = sort_can_defs_improved(env, unsorted, output); match can_defs { Ok(decls) => { diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index 10e9479f23..2dade79cd6 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -9,7 +9,7 @@ use crate::num::{ use crate::pattern::{canonicalize_pattern, Pattern}; use crate::procedure::References; use crate::scope::Scope; -use roc_collections::{MutMap, MutSet, SendMap, VecMap, VecSet}; +use roc_collections::{MutSet, SendMap, VecMap, VecSet}; use roc_module::called_via::CalledVia; use roc_module::ident::{ForeignSymbol, Lowercase, TagName}; use roc_module::low_level::LowLevel; @@ -1091,34 +1091,6 @@ fn canonicalize_when_branch<'a>( ) } -pub fn local_successors_with_duplicates<'a>( - references: &'a References, - closures: &'a MutMap, -) -> Vec { - let mut answer: Vec<_> = references.value_lookups().copied().collect(); - - let mut stack: Vec<_> = references.calls().copied().collect(); - let mut seen = Vec::new(); - - while let Some(symbol) = stack.pop() { - if seen.contains(&symbol) { - continue; - } - - if let Some(references) = closures.get(&symbol) { - answer.extend(references.value_lookups().copied()); - stack.extend(references.calls().copied()); - - seen.push(symbol); - } - } - - answer.sort(); - answer.dedup(); - - answer -} - enum CanonicalizeRecordProblem { InvalidOptionalValue { field_name: Lowercase, From e40e4ae846d30932c3ca2d8d3a56f6b6337f0ac1 Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 22 Apr 2022 15:11:02 +0200 Subject: [PATCH 407/846] rename --- compiler/can/src/def.rs | 24 ++++++++++++------------ compiler/can/src/module.rs | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index c0f22484a7..8491103d26 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -28,7 +28,7 @@ use roc_types::types::LambdaSet; use roc_types::types::{Alias, Type}; use std::collections::HashMap; use std::fmt::Debug; -use ven_graph::{strongly_connected_components, topological_sort}; +use ven_graph::topological_sort; #[derive(Clone, Debug)] pub struct Def { @@ -143,7 +143,7 @@ fn sort_type_defs_before_introduction( let all_successors_with_self = |symbol: &Symbol| referenced_symbols[symbol].iter().copied(); - strongly_connected_components(&defined_symbols, all_successors_with_self) + ven_graph::strongly_connected_components(&defined_symbols, all_successors_with_self) }; // then sort the strongly connected components @@ -925,7 +925,7 @@ impl DefIds { } #[inline(always)] -pub fn sort_can_defs_improved( +pub fn sort_can_defs( env: &mut Env<'_>, defs: CanDefs, mut output: Output, @@ -950,7 +950,7 @@ pub fn sort_can_defs_improved( // groups are in reversed order for group in groups.into_iter().rev() { - group_to_declaration_improved( + group_to_declaration( &def_ids, &group, &env.closures, @@ -976,7 +976,7 @@ pub fn sort_can_defs_improved( // // foo = if b then foo else bar - let sccs = strongly_connected_components_improved( + let sccs = strongly_connected_components( def_ids.length as usize, &def_ids.references, &nodes_in_cycle, @@ -1086,7 +1086,7 @@ pub fn sort_can_defs_improved( for group_id in sorted_group.iter().rev() { let group = &groups[*group_id]; - group_to_declaration_improved( + group_to_declaration( &def_ids, group, &env.closures, @@ -1108,7 +1108,7 @@ pub fn sort_can_defs_improved( } } -fn strongly_connected_components_improved( +fn strongly_connected_components( length: usize, bitvec: &bitvec::vec::BitVec, group: &[u32], @@ -1213,7 +1213,7 @@ fn recurse_onto(length: usize, bitvec: &bitvec::vec::BitVec, v: usize, param } } -fn group_to_declaration_improved( +fn group_to_declaration( def_ids: &DefIds, group: &[u32], closures: &MutMap, @@ -1231,8 +1231,7 @@ fn group_to_declaration_improved( // for a definition, so every definition is only inserted (thus typechecked and emitted) once let mut seen_pattern_regions: Vec = Vec::with_capacity(2); - let sccs = - strongly_connected_components_improved(def_ids.length as usize, &def_ids.references, group); + let sccs = strongly_connected_components(def_ids.length as usize, &def_ids.references, group); for cycle in sccs { if cycle.len() == 1 { @@ -1874,7 +1873,7 @@ pub fn can_defs_with_return<'a>( } } - let (can_defs, output) = sort_can_defs_improved(env, unsorted, output); + let (can_defs, output) = sort_can_defs(env, unsorted, output); match can_defs { Ok(decls) => { @@ -2209,7 +2208,8 @@ fn correct_mutual_recursive_type_alias<'a>( // TODO investigate should this be in a loop? let defined_symbols: Vec = original_aliases.keys().copied().collect(); - let cycles = strongly_connected_components(&defined_symbols, all_successors_with_self); + let cycles = + ven_graph::strongly_connected_components(&defined_symbols, all_successors_with_self); let mut solved_aliases = ImMap::default(); for cycle in cycles { diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index 345d6905af..317b00578a 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -1,5 +1,5 @@ use crate::abilities::AbilitiesStore; -use crate::def::{canonicalize_defs, sort_can_defs_improved, Declaration, Def}; +use crate::def::{canonicalize_defs, sort_can_defs, Declaration, Def}; use crate::effect_module::HostedGeneratedFunctions; use crate::env::Env; use crate::expr::{ClosureData, Expr, Output}; @@ -361,7 +361,7 @@ pub fn canonicalize_module_defs<'a>( ..Default::default() }; - let sorted = sort_can_defs_improved(&mut env, defs, new_output); + let sorted = sort_can_defs(&mut env, defs, new_output); match sorted { (Ok(mut declarations), output) => { From 5d68a00d1cb92ee2120cc9a129f6e5bf111c2984 Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 22 Apr 2022 15:40:43 +0200 Subject: [PATCH 408/846] make ReferenceMatrix type/module --- compiler/can/src/lib.rs | 1 + compiler/can/src/reference_matrix.rs | 224 +++++++++++++++++++++++++++ 2 files changed, 225 insertions(+) create mode 100644 compiler/can/src/reference_matrix.rs diff --git a/compiler/can/src/lib.rs b/compiler/can/src/lib.rs index f22d1a1fe6..4e90bf4d4d 100644 --- a/compiler/can/src/lib.rs +++ b/compiler/can/src/lib.rs @@ -15,5 +15,6 @@ pub mod num; pub mod operator; pub mod pattern; pub mod procedure; +mod reference_matrix; pub mod scope; pub mod string; diff --git a/compiler/can/src/reference_matrix.rs b/compiler/can/src/reference_matrix.rs new file mode 100644 index 0000000000..db8eff5eaa --- /dev/null +++ b/compiler/can/src/reference_matrix.rs @@ -0,0 +1,224 @@ +// see if we get better performance with different integer types +pub(crate) type Element = u8; +pub(crate) type BitVec = bitvec::vec::BitVec; +pub(crate) type BitSlice = bitvec::prelude::BitSlice; + +pub(crate) struct ReferenceMatrix { + bitvec: BitVec, + length: usize, +} + +impl ReferenceMatrix { + pub fn new(length: usize) -> Self { + Self { + bitvec: BitVec::repeat(false, length * length), + length, + } + } + + pub fn references_for(&self, row: usize) -> impl Iterator + '_ { + self.row_slice(row).iter_ones() + } + + #[inline(always)] + fn row_slice(&self, row: usize) -> &BitSlice { + &self.bitvec[row * self.length..][..self.length] + } + + pub const fn len(&self) -> usize { + self.length + } + + pub const fn is_empty(&self) -> bool { + self.length == 0 + } + + #[inline(always)] + fn set(&mut self, index: usize, value: bool) { + self.bitvec.set(index, value) + } + + #[inline(always)] + fn get(&self, index: usize) -> bool { + self.bitvec[index] + } +} + +impl ReferenceMatrix { + pub fn topological_sort_into_groups(&self) -> Result>, (Vec>, Vec)> { + let length = self.length; + let bitvec = &self.bitvec; + + if length == 0 { + return Ok(Vec::new()); + } + + let mut preds_map: Vec = vec![0; length]; + + // this is basically summing the columns, I don't see a better way to do it + for row in bitvec.chunks(length) { + for succ in row.iter_ones() { + preds_map[succ] += 1; + } + } + + let mut groups = Vec::>::new(); + + // the initial group contains all symbols with no predecessors + let mut prev_group: Vec = preds_map + .iter() + .enumerate() + .filter_map(|(node, &num_preds)| { + if num_preds == 0 { + Some(node as u32) + } else { + None + } + }) + .collect(); + + if prev_group.is_empty() { + let remaining: Vec = (0u32..length as u32).collect(); + return Err((Vec::new(), remaining)); + } + + // NOTE: the original now removes elements from the preds_map if they have count 0 + // for node in &prev_group { + // preds_map.remove(node); + // } + + while preds_map.iter().any(|x| *x > 0) { + let mut next_group = Vec::::new(); + for node in &prev_group { + let row = &bitvec[length * (*node as usize)..][..length]; + for succ in row.iter_ones() { + { + let num_preds = preds_map.get_mut(succ).unwrap(); + *num_preds = num_preds.saturating_sub(1); + if *num_preds > 0 { + continue; + } + } + + let count = preds_map[succ]; + preds_map[succ] = -1; + + if count > -1 { + next_group.push(succ as u32); + } + } + } + groups.push(std::mem::replace(&mut prev_group, next_group)); + if prev_group.is_empty() { + let remaining: Vec = (0u32..length as u32) + .filter(|i| preds_map[*i as usize] > 0) + .collect(); + return Err((groups, remaining)); + } + } + groups.push(prev_group); + + Ok(groups) + } + + pub fn strongly_connected_components(&self, group: &[u32]) -> Vec> { + let mut params = Params::new(self.length, group); + + 'outer: loop { + for (node, value) in params.preorders.iter().enumerate() { + if let Preorder::Removed = value { + continue; + } + + recurse_onto(self.length, &self.bitvec, node, &mut params); + + continue 'outer; + } + + break params.scc; + } + } +} + +#[derive(Clone, Copy)] +enum Preorder { + Empty, + Filled(usize), + Removed, +} + +struct Params { + preorders: Vec, + c: usize, + p: Vec, + s: Vec, + scc: Vec>, + scca: Vec, +} + +impl Params { + fn new(length: usize, group: &[u32]) -> Self { + let mut preorders = vec![Preorder::Removed; length]; + + for value in group { + preorders[*value as usize] = Preorder::Empty; + } + + Self { + preorders, + c: 0, + s: Vec::new(), + p: Vec::new(), + scc: Vec::new(), + scca: Vec::new(), + } + } +} + +fn recurse_onto(length: usize, bitvec: &bitvec::vec::BitVec, v: usize, params: &mut Params) { + params.preorders[v] = Preorder::Filled(params.c); + + params.c += 1; + + params.s.push(v as u32); + params.p.push(v as u32); + + for w in bitvec[v * length..][..length].iter_ones() { + if !params.scca.contains(&(w as u32)) { + match params.preorders[w] { + Preorder::Filled(pw) => loop { + let index = *params.p.last().unwrap(); + + match params.preorders[index as usize] { + Preorder::Empty => unreachable!(), + Preorder::Filled(current) => { + if current > pw { + params.p.pop(); + } else { + break; + } + } + Preorder::Removed => {} + } + }, + Preorder::Empty => recurse_onto(length, bitvec, w, params), + Preorder::Removed => {} + } + } + } + + if params.p.last() == Some(&(v as u32)) { + params.p.pop(); + + let mut component = Vec::new(); + while let Some(node) = params.s.pop() { + component.push(node); + params.scca.push(node); + params.preorders[node as usize] = Preorder::Removed; + if node as usize == v { + break; + } + } + params.scc.push(component); + } +} From 0c10fa31f5913f683a5418795a0166b3c38440c3 Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 22 Apr 2022 15:41:21 +0200 Subject: [PATCH 409/846] rename --- compiler/can/src/def.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 8491103d26..dd812ae050 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -665,7 +665,7 @@ pub fn canonicalize_defs<'a>( struct DefId(u32); #[derive(Debug)] -struct DefIds { +struct DefOrdering { home: ModuleId, symbol_to_id: Vec<(IdentId, u32)>, @@ -679,7 +679,7 @@ struct DefIds { length: u32, } -impl DefIds { +impl DefOrdering { fn with_capacity(home: ModuleId, capacity: usize) -> Self { use bitvec::vec::BitVec; @@ -930,7 +930,8 @@ pub fn sort_can_defs( defs: CanDefs, mut output: Output, ) -> (Result, RuntimeError>, Output) { - let def_ids = DefIds::from_defs_by_symbol(env, &defs.can_defs_by_symbol, &defs.refs_by_symbol); + let def_ids = + DefOrdering::from_defs_by_symbol(env, &defs.can_defs_by_symbol, &defs.refs_by_symbol); let CanDefs { refs_by_symbol, @@ -1214,7 +1215,7 @@ fn recurse_onto(length: usize, bitvec: &bitvec::vec::BitVec, v: usize, param } fn group_to_declaration( - def_ids: &DefIds, + def_ids: &DefOrdering, group: &[u32], closures: &MutMap, can_defs_by_symbol: &mut MutMap, From 9f7c7b56a1126356990490eaf9e6005037968328 Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 22 Apr 2022 15:49:32 +0200 Subject: [PATCH 410/846] use ReferenceMatrix in DefOrdering --- compiler/can/src/def.rs | 242 +++------------------------ compiler/can/src/reference_matrix.rs | 14 +- 2 files changed, 23 insertions(+), 233 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index dd812ae050..43c8ad862b 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -7,6 +7,7 @@ use crate::expr::Expr::{self, *}; use crate::expr::{canonicalize_expr, Output, Recursive}; use crate::pattern::{bindings_from_patterns, canonicalize_def_header_pattern, Pattern}; use crate::procedure::References; +use crate::reference_matrix::ReferenceMatrix; use crate::scope::create_alias; use crate::scope::Scope; use roc_collections::{default_hasher, ImEntry, ImMap, ImSet, MutMap, MutSet, SendMap}; @@ -670,21 +671,19 @@ struct DefOrdering { symbol_to_id: Vec<(IdentId, u32)>, // an length x length matrix indicating who references who - references: bitvec::vec::BitVec, + references: ReferenceMatrix, // references without looking into closure bodies. // Used to spot definitely-wrong recursion - direct_references: bitvec::vec::BitVec, + direct_references: ReferenceMatrix, length: u32, } impl DefOrdering { fn with_capacity(home: ModuleId, capacity: usize) -> Self { - use bitvec::vec::BitVec; - - let references = BitVec::repeat(false, capacity * capacity); - let direct_references = BitVec::repeat(false, capacity * capacity); + let references = ReferenceMatrix::new(capacity); + let direct_references = ReferenceMatrix::new(capacity); Self { home, @@ -753,7 +752,7 @@ impl DefOrdering { id: DefId, referenced: Option, length: usize, - bitvec: &mut bitvec::vec::BitVec, + refmatrix: &mut ReferenceMatrix, ) -> bool { match referenced { None => { @@ -766,7 +765,7 @@ impl DefOrdering { let index = row * length + column; - bitvec.set(index, true); + refmatrix.set(index, true); true } @@ -805,123 +804,27 @@ impl DefOrdering { // id'th row, id'th column let index = (id * self.length) + id; - self.references[index as usize] + self.references.get(index as usize) } #[inline(always)] fn direct_successors(&self, id: u32) -> impl Iterator + '_ { - let row = &self.direct_references[(id * self.length) as usize..][..self.length as usize]; - - row.iter_ones().map(|x| x as u32) + self.direct_references + .references_for(id as usize) + .map(|x| x as u32) } #[inline(always)] fn successors(&self, id: u32) -> impl Iterator + '_ { - let row = &self.references[(id * self.length) as usize..][..self.length as usize]; - - row.iter_ones().map(|x| x as u32) + self.references + .references_for(id as usize) + .map(|x| x as u32) } #[inline(always)] fn successors_without_self(&self, id: u32) -> impl Iterator + '_ { self.successors(id).filter(move |x| *x != id) } - - #[allow(clippy::type_complexity)] - fn topological_sort_into_groups(&self) -> Result>, (Vec>, Vec)> { - let length = self.length as usize; - let bitvec = &self.references; - - if length == 0 { - return Ok(Vec::new()); - } - - let mut preds_map: Vec = vec![0; length]; - - // this is basically summing the columns, I don't see a better way to do it - for row in bitvec.chunks(length) { - for succ in row.iter_ones() { - preds_map[succ] += 1; - } - } - - let mut groups = Vec::>::new(); - - // the initial group contains all symbols with no predecessors - let mut prev_group: Vec = preds_map - .iter() - .enumerate() - .filter_map(|(node, &num_preds)| { - if num_preds == 0 { - Some(node as u32) - } else { - None - } - }) - .collect(); - - if prev_group.is_empty() { - let remaining: Vec = (0u32..length as u32).collect(); - return Err((Vec::new(), remaining)); - } - - // NOTE: the original now removes elements from the preds_map if they have count 0 - // for node in &prev_group { - // preds_map.remove(node); - // } - - while preds_map.iter().any(|x| *x > 0) { - let mut next_group = Vec::::new(); - for node in &prev_group { - let row = &bitvec[length * (*node as usize)..][..length]; - for succ in row.iter_ones() { - { - let num_preds = preds_map.get_mut(succ).unwrap(); - *num_preds = num_preds.saturating_sub(1); - if *num_preds > 0 { - continue; - } - } - - let count = preds_map[succ]; - preds_map[succ] = -1; - - if count > -1 { - next_group.push(succ as u32); - } - } - } - groups.push(std::mem::replace(&mut prev_group, next_group)); - if prev_group.is_empty() { - let remaining: Vec = (0u32..length as u32) - .filter(|i| preds_map[*i as usize] > 0) - .collect(); - return Err((groups, remaining)); - } - } - groups.push(prev_group); - Ok(groups) - } - - #[allow(dead_code)] - fn debug_relations(&self) { - for id in 0u32..self.length as u32 { - let row = &self.references[(id * self.length) as usize..][..self.length as usize]; - - let matches = row - .iter() - .enumerate() - .filter(move |t| *t.1) - .map(|t| t.0 as u32); - - for m in matches { - let a = self.get_symbol(id).unwrap(); - let b = self.get_symbol(m).unwrap(); - - println!("{:?} <- {:?}", a, b); - } - } - } } #[inline(always)] @@ -945,7 +848,7 @@ pub fn sort_can_defs( // TODO also do the same `addDirects` check elm/compiler does, so we can // report an error if a recursive definition can't possibly terminate! - match def_ids.topological_sort_into_groups() { + match def_ids.references.topological_sort_into_groups() { Ok(groups) => { let mut declarations = Vec::new(); @@ -977,11 +880,9 @@ pub fn sort_can_defs( // // foo = if b then foo else bar - let sccs = strongly_connected_components( - def_ids.length as usize, - &def_ids.references, - &nodes_in_cycle, - ); + let sccs = def_ids + .references + .strongly_connected_components(&nodes_in_cycle); for cycle in sccs { // check whether the cycle is faulty, which is when it has @@ -1109,111 +1010,6 @@ pub fn sort_can_defs( } } -fn strongly_connected_components( - length: usize, - bitvec: &bitvec::vec::BitVec, - group: &[u32], -) -> Vec> { - let mut params = Params::new(length, group); - - 'outer: loop { - for (node, value) in params.preorders.iter().enumerate() { - if let Preorder::Removed = value { - continue; - } - - recurse_onto(length, bitvec, node, &mut params); - - continue 'outer; - } - - break params.scc; - } -} - -#[derive(Clone, Copy)] -enum Preorder { - Empty, - Filled(usize), - Removed, -} - -struct Params { - preorders: Vec, - c: usize, - p: Vec, - s: Vec, - scc: Vec>, - scca: Vec, -} - -impl Params { - fn new(length: usize, group: &[u32]) -> Self { - let mut preorders = vec![Preorder::Removed; length]; - - for value in group { - preorders[*value as usize] = Preorder::Empty; - } - - Self { - preorders, - c: 0, - s: Vec::new(), - p: Vec::new(), - scc: Vec::new(), - scca: Vec::new(), - } - } -} - -fn recurse_onto(length: usize, bitvec: &bitvec::vec::BitVec, v: usize, params: &mut Params) { - params.preorders[v] = Preorder::Filled(params.c); - - params.c += 1; - - params.s.push(v as u32); - params.p.push(v as u32); - - for w in bitvec[v * length..][..length].iter_ones() { - if !params.scca.contains(&(w as u32)) { - match params.preorders[w] { - Preorder::Filled(pw) => loop { - let index = *params.p.last().unwrap(); - - match params.preorders[index as usize] { - Preorder::Empty => unreachable!(), - Preorder::Filled(current) => { - if current > pw { - params.p.pop(); - } else { - break; - } - } - Preorder::Removed => {} - } - }, - Preorder::Empty => recurse_onto(length, bitvec, w, params), - Preorder::Removed => {} - } - } - } - - if params.p.last() == Some(&(v as u32)) { - params.p.pop(); - - let mut component = Vec::new(); - while let Some(node) = params.s.pop() { - component.push(node); - params.scca.push(node); - params.preorders[node as usize] = Preorder::Removed; - if node as usize == v { - break; - } - } - params.scc.push(component); - } -} - fn group_to_declaration( def_ids: &DefOrdering, group: &[u32], @@ -1232,7 +1028,7 @@ fn group_to_declaration( // for a definition, so every definition is only inserted (thus typechecked and emitted) once let mut seen_pattern_regions: Vec = Vec::with_capacity(2); - let sccs = strongly_connected_components(def_ids.length as usize, &def_ids.references, group); + let sccs = def_ids.references.strongly_connected_components(group); for cycle in sccs { if cycle.len() == 1 { diff --git a/compiler/can/src/reference_matrix.rs b/compiler/can/src/reference_matrix.rs index db8eff5eaa..d1aa5a5766 100644 --- a/compiler/can/src/reference_matrix.rs +++ b/compiler/can/src/reference_matrix.rs @@ -3,6 +3,7 @@ pub(crate) type Element = u8; pub(crate) type BitVec = bitvec::vec::BitVec; pub(crate) type BitSlice = bitvec::prelude::BitSlice; +#[derive(Debug)] pub(crate) struct ReferenceMatrix { bitvec: BitVec, length: usize, @@ -25,26 +26,19 @@ impl ReferenceMatrix { &self.bitvec[row * self.length..][..self.length] } - pub const fn len(&self) -> usize { - self.length - } - - pub const fn is_empty(&self) -> bool { - self.length == 0 - } - #[inline(always)] - fn set(&mut self, index: usize, value: bool) { + pub fn set(&mut self, index: usize, value: bool) { self.bitvec.set(index, value) } #[inline(always)] - fn get(&self, index: usize) -> bool { + pub fn get(&self, index: usize) -> bool { self.bitvec[index] } } impl ReferenceMatrix { + #[allow(clippy::type_complexity)] pub fn topological_sort_into_groups(&self) -> Result>, (Vec>, Vec)> { let length = self.length; let bitvec = &self.bitvec; From a40483a2ecea819bda52823b4e6b011ee612880e Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 22 Apr 2022 16:05:06 +0200 Subject: [PATCH 411/846] cleanup --- compiler/can/src/def.rs | 100 +++++++++------------------ compiler/can/src/reference_matrix.rs | 4 +- 2 files changed, 34 insertions(+), 70 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 43c8ad862b..e5827d40f9 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -662,9 +662,6 @@ pub fn canonicalize_defs<'a>( ) } -#[derive(Clone, Copy)] -struct DefId(u32); - #[derive(Debug)] struct DefOrdering { home: ModuleId, @@ -682,14 +679,11 @@ struct DefOrdering { impl DefOrdering { fn with_capacity(home: ModuleId, capacity: usize) -> Self { - let references = ReferenceMatrix::new(capacity); - let direct_references = ReferenceMatrix::new(capacity); - Self { home, symbol_to_id: Vec::with_capacity(capacity), - references, - direct_references, + references: ReferenceMatrix::new(capacity), + direct_references: ReferenceMatrix::new(capacity), length: capacity as u32, } } @@ -708,7 +702,7 @@ impl DefOrdering { } for (symbol, (_, references)) in refs_by_symbol.iter() { - let def_id = DefId(this.get_id(*symbol).unwrap()); + let def_id = this.get_id(*symbol).unwrap(); for referenced in references.value_lookups() { this.register_reference(def_id, *referenced); @@ -735,67 +729,43 @@ impl DefOrdering { } fn get_id(&self, symbol: Symbol) -> Option { - self.symbol_to_id - .iter() - .find(|(id, _)| *id == symbol.ident_id()) - .map(|t| t.1) + if symbol.module_id() != self.home { + return None; + } + + let target = symbol.ident_id(); + + for (ident_id, def_id) in self.symbol_to_id.iter() { + if target == *ident_id { + return Some(*def_id); + } + } + + None } fn get_symbol(&self, id: u32) -> Option { - self.symbol_to_id - .iter() - .find(|(_, def_id)| id == *def_id) - .map(|t| Symbol::new(self.home, t.0)) - } - - fn register_help( - id: DefId, - referenced: Option, - length: usize, - refmatrix: &mut ReferenceMatrix, - ) -> bool { - match referenced { - None => { - // this symbol is not defined within the let-block that this DefIds represents - false - } - Some(referenced_id) => { - let row = id.0 as usize; - let column = referenced_id as usize; - - let index = row * length + column; - - refmatrix.set(index, true); - - true + for (ident_id, def_id) in self.symbol_to_id.iter() { + if id == *def_id { + return Some(Symbol::new(self.home, *ident_id)); } } + + None } - fn register_direct_reference(&mut self, id: DefId, referenced: Symbol) -> bool { - if referenced.module_id() != self.home { - return false; + fn register_direct_reference(&mut self, id: u32, referenced: Symbol) { + if let Some(ref_id) = self.get_id(referenced) { + self.direct_references + .set_row_col(id as usize, ref_id as usize, true); } - - Self::register_help( - id, - self.get_id(referenced), - self.length as usize, - &mut self.direct_references, - ) } - fn register_reference(&mut self, id: DefId, referenced: Symbol) -> bool { - if referenced.module_id() != self.home { - return false; + fn register_reference(&mut self, id: u32, referenced: Symbol) { + if let Some(ref_id) = self.get_id(referenced) { + self.references + .set_row_col(id as usize, ref_id as usize, true); } - - Self::register_help( - id, - self.get_id(referenced), - self.length as usize, - &mut self.references, - ) } fn is_self_recursive(&self, id: u32) -> bool { @@ -807,13 +777,6 @@ impl DefOrdering { self.references.get(index as usize) } - #[inline(always)] - fn direct_successors(&self, id: u32) -> impl Iterator + '_ { - self.direct_references - .references_for(id as usize) - .map(|x| x as u32) - } - #[inline(always)] fn successors(&self, id: u32) -> impl Iterator + '_ { self.references @@ -896,8 +859,9 @@ pub fn sort_can_defs( // q = p let is_invalid_cycle = match cycle.get(0) { Some(def_id) => def_ids - .direct_successors(*def_id) - .any(|key| cycle.contains(&key)), + .direct_references + .references_for(*def_id as usize) + .any(|key| cycle.contains(&(key as u32))), None => false, }; diff --git a/compiler/can/src/reference_matrix.rs b/compiler/can/src/reference_matrix.rs index d1aa5a5766..4865e95c7e 100644 --- a/compiler/can/src/reference_matrix.rs +++ b/compiler/can/src/reference_matrix.rs @@ -27,8 +27,8 @@ impl ReferenceMatrix { } #[inline(always)] - pub fn set(&mut self, index: usize, value: bool) { - self.bitvec.set(index, value) + pub fn set_row_col(&mut self, row: usize, col: usize, value: bool) { + self.bitvec.set(row * self.length + col, value) } #[inline(always)] From 09869ac6457c6cddb2be32257ad7c9c0f2301bce Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 22 Apr 2022 16:21:28 +0200 Subject: [PATCH 412/846] pick usize as the underlying integer type --- compiler/can/src/reference_matrix.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/can/src/reference_matrix.rs b/compiler/can/src/reference_matrix.rs index 4865e95c7e..12db131e37 100644 --- a/compiler/can/src/reference_matrix.rs +++ b/compiler/can/src/reference_matrix.rs @@ -1,5 +1,5 @@ // see if we get better performance with different integer types -pub(crate) type Element = u8; +pub(crate) type Element = usize; pub(crate) type BitVec = bitvec::vec::BitVec; pub(crate) type BitSlice = bitvec::prelude::BitSlice; @@ -169,7 +169,7 @@ impl Params { } } -fn recurse_onto(length: usize, bitvec: &bitvec::vec::BitVec, v: usize, params: &mut Params) { +fn recurse_onto(length: usize, bitvec: &BitVec, v: usize, params: &mut Params) { params.preorders[v] = Preorder::Filled(params.c); params.c += 1; From 55749e7470f7d8c045b4971850d611bf2d3cb2bc Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 22 Apr 2022 16:22:27 +0200 Subject: [PATCH 413/846] make diff a bit smaller --- compiler/can/src/module.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index 317b00578a..b34aba4fc5 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -361,9 +361,7 @@ pub fn canonicalize_module_defs<'a>( ..Default::default() }; - let sorted = sort_can_defs(&mut env, defs, new_output); - - match sorted { + match sort_can_defs(&mut env, defs, new_output) { (Ok(mut declarations), output) => { use crate::def::Declaration::*; From 6306923e0f72535164527bc763a3e9045c0e0ba7 Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 22 Apr 2022 16:24:47 +0200 Subject: [PATCH 414/846] add thanks comment --- compiler/can/src/reference_matrix.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/compiler/can/src/reference_matrix.rs b/compiler/can/src/reference_matrix.rs index 12db131e37..bafd37cbcb 100644 --- a/compiler/can/src/reference_matrix.rs +++ b/compiler/can/src/reference_matrix.rs @@ -37,6 +37,14 @@ impl ReferenceMatrix { } } +// Topological sort and strongly-connected components +// +// Adapted from the Pathfinding crate v2.0.3 by Samuel Tardieu , +// licensed under the Apache License, version 2.0 - https://www.apache.org/licenses/LICENSE-2.0 +// +// The original source code can be found at: https://github.com/samueltardieu/pathfinding +// +// Thank you, Samuel! impl ReferenceMatrix { #[allow(clippy::type_complexity)] pub fn topological_sort_into_groups(&self) -> Result>, (Vec>, Vec)> { @@ -76,11 +84,6 @@ impl ReferenceMatrix { return Err((Vec::new(), remaining)); } - // NOTE: the original now removes elements from the preds_map if they have count 0 - // for node in &prev_group { - // preds_map.remove(node); - // } - while preds_map.iter().any(|x| *x > 0) { let mut next_group = Vec::::new(); for node in &prev_group { From 7196e7cdac1118cab79336cfc1b4a9d9ee6c13c8 Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 22 Apr 2022 16:26:52 +0200 Subject: [PATCH 415/846] add further comment --- compiler/can/src/reference_matrix.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/compiler/can/src/reference_matrix.rs b/compiler/can/src/reference_matrix.rs index bafd37cbcb..0c2d67cda4 100644 --- a/compiler/can/src/reference_matrix.rs +++ b/compiler/can/src/reference_matrix.rs @@ -3,6 +3,10 @@ pub(crate) type Element = usize; pub(crate) type BitVec = bitvec::vec::BitVec; pub(crate) type BitSlice = bitvec::prelude::BitSlice; +/// A square boolean matrix used to store relations +/// +/// We use this for sorting definitions so every definition is defined before it is used. +/// This functionality is also used to spot and report invalid recursion. #[derive(Debug)] pub(crate) struct ReferenceMatrix { bitvec: BitVec, From 48ce1c14bfed738770e7238f6c5c1ea30cce5029 Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 22 Apr 2022 17:10:27 +0200 Subject: [PATCH 416/846] ordering changed in a test --- compiler/test_gen/src/gen_refcount.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/test_gen/src/gen_refcount.rs b/compiler/test_gen/src/gen_refcount.rs index 5b857a1fbc..25ade5e934 100644 --- a/compiler/test_gen/src/gen_refcount.rs +++ b/compiler/test_gen/src/gen_refcount.rs @@ -301,8 +301,8 @@ fn refcount_different_rosetrees_inc() { (Pointer, Pointer), &[ Live(2), // s - Live(2), // s1 Live(3), // i1 + Live(2), // s1 Live(1), // [i1, i1] Live(1), // i2 Live(1), // [s1, s1] From 28cb9bf36e30f0f15fee07f430a6f4dadbf78c86 Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 22 Apr 2022 19:28:46 +0200 Subject: [PATCH 417/846] use custom type for TopologicalSort result --- compiler/can/src/def.rs | 8 +++++-- compiler/can/src/reference_matrix.rs | 32 ++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index e5827d40f9..4d764d337e 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -8,6 +8,7 @@ use crate::expr::{canonicalize_expr, Output, Recursive}; use crate::pattern::{bindings_from_patterns, canonicalize_def_header_pattern, Pattern}; use crate::procedure::References; use crate::reference_matrix::ReferenceMatrix; +use crate::reference_matrix::TopologicalSort; use crate::scope::create_alias; use crate::scope::Scope; use roc_collections::{default_hasher, ImEntry, ImMap, ImSet, MutMap, MutSet, SendMap}; @@ -812,7 +813,7 @@ pub fn sort_can_defs( // TODO also do the same `addDirects` check elm/compiler does, so we can // report an error if a recursive definition can't possibly terminate! match def_ids.references.topological_sort_into_groups() { - Ok(groups) => { + TopologicalSort::Groups { groups } => { let mut declarations = Vec::new(); // groups are in reversed order @@ -828,7 +829,10 @@ pub fn sort_can_defs( (Ok(declarations), output) } - Err((mut groups, nodes_in_cycle)) => { + TopologicalSort::HasCycles { + mut groups, + nodes_in_cycle, + } => { let mut declarations = Vec::new(); let mut problems = Vec::new(); diff --git a/compiler/can/src/reference_matrix.rs b/compiler/can/src/reference_matrix.rs index 0c2d67cda4..d0052993e4 100644 --- a/compiler/can/src/reference_matrix.rs +++ b/compiler/can/src/reference_matrix.rs @@ -50,13 +50,12 @@ impl ReferenceMatrix { // // Thank you, Samuel! impl ReferenceMatrix { - #[allow(clippy::type_complexity)] - pub fn topological_sort_into_groups(&self) -> Result>, (Vec>, Vec)> { + pub fn topological_sort_into_groups(&self) -> TopologicalSort { let length = self.length; let bitvec = &self.bitvec; if length == 0 { - return Ok(Vec::new()); + return TopologicalSort::Groups { groups: Vec::new() }; } let mut preds_map: Vec = vec![0; length]; @@ -85,7 +84,11 @@ impl ReferenceMatrix { if prev_group.is_empty() { let remaining: Vec = (0u32..length as u32).collect(); - return Err((Vec::new(), remaining)); + + return TopologicalSort::HasCycles { + groups: Vec::new(), + nodes_in_cycle: remaining, + }; } while preds_map.iter().any(|x| *x > 0) { @@ -114,12 +117,16 @@ impl ReferenceMatrix { let remaining: Vec = (0u32..length as u32) .filter(|i| preds_map[*i as usize] > 0) .collect(); - return Err((groups, remaining)); + + return TopologicalSort::HasCycles { + groups, + nodes_in_cycle: remaining, + }; } } groups.push(prev_group); - Ok(groups) + TopologicalSort::Groups { groups } } pub fn strongly_connected_components(&self, group: &[u32]) -> Vec> { @@ -141,6 +148,19 @@ impl ReferenceMatrix { } } +pub(crate) enum TopologicalSort { + /// There were no cycles, all nodes have been partitioned into groups + Groups { groups: Vec> }, + /// Cycles were found. All nodes that are not part of a cycle have been partitioned + /// into groups. The other elements are in the `cyclic` vector. However, there may be + /// many cycles, or just one big one. Use strongly-connected components to find out + /// exactly what the cycles are and how they fit into the groups. + HasCycles { + groups: Vec>, + nodes_in_cycle: Vec, + }, +} + #[derive(Clone, Copy)] enum Preorder { Empty, From 18ba49c694ab67bc3d7c7b112fecb8e9778f70af Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 22 Apr 2022 19:29:52 +0200 Subject: [PATCH 418/846] add comment --- compiler/can/src/reference_matrix.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compiler/can/src/reference_matrix.rs b/compiler/can/src/reference_matrix.rs index d0052993e4..7db76dfd26 100644 --- a/compiler/can/src/reference_matrix.rs +++ b/compiler/can/src/reference_matrix.rs @@ -104,6 +104,8 @@ impl ReferenceMatrix { } } + // NOTE: we use -1 to mark nodes that have no predecessors, but are already + // part of an earlier group. That ensures nodes are added to just 1 group let count = preds_map[succ]; preds_map[succ] = -1; From fdd0910ba05a73f35d505505f3da9c7df917d948 Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 22 Apr 2022 19:32:47 +0200 Subject: [PATCH 419/846] refactor --- compiler/can/src/reference_matrix.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/compiler/can/src/reference_matrix.rs b/compiler/can/src/reference_matrix.rs index 7db76dfd26..524c044fd4 100644 --- a/compiler/can/src/reference_matrix.rs +++ b/compiler/can/src/reference_matrix.rs @@ -51,17 +51,14 @@ impl ReferenceMatrix { // Thank you, Samuel! impl ReferenceMatrix { pub fn topological_sort_into_groups(&self) -> TopologicalSort { - let length = self.length; - let bitvec = &self.bitvec; - - if length == 0 { + if self.length == 0 { return TopologicalSort::Groups { groups: Vec::new() }; } - let mut preds_map: Vec = vec![0; length]; + let mut preds_map: Vec = vec![0; self.length]; // this is basically summing the columns, I don't see a better way to do it - for row in bitvec.chunks(length) { + for row in self.bitvec.chunks(self.length) { for succ in row.iter_ones() { preds_map[succ] += 1; } @@ -83,7 +80,7 @@ impl ReferenceMatrix { .collect(); if prev_group.is_empty() { - let remaining: Vec = (0u32..length as u32).collect(); + let remaining: Vec = (0u32..self.length as u32).collect(); return TopologicalSort::HasCycles { groups: Vec::new(), @@ -94,8 +91,7 @@ impl ReferenceMatrix { while preds_map.iter().any(|x| *x > 0) { let mut next_group = Vec::::new(); for node in &prev_group { - let row = &bitvec[length * (*node as usize)..][..length]; - for succ in row.iter_ones() { + for succ in self.references_for(*node as usize) { { let num_preds = preds_map.get_mut(succ).unwrap(); *num_preds = num_preds.saturating_sub(1); @@ -116,7 +112,7 @@ impl ReferenceMatrix { } groups.push(std::mem::replace(&mut prev_group, next_group)); if prev_group.is_empty() { - let remaining: Vec = (0u32..length as u32) + let remaining: Vec = (0u32..self.length as u32) .filter(|i| preds_map[*i as usize] > 0) .collect(); From 285e4f05ec3f3d02c493b72a78bd5923fdb61e8b Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 22 Apr 2022 19:35:01 +0200 Subject: [PATCH 420/846] add comment --- compiler/can/src/reference_matrix.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/compiler/can/src/reference_matrix.rs b/compiler/can/src/reference_matrix.rs index 524c044fd4..eaadee556c 100644 --- a/compiler/can/src/reference_matrix.rs +++ b/compiler/can/src/reference_matrix.rs @@ -127,8 +127,9 @@ impl ReferenceMatrix { TopologicalSort::Groups { groups } } - pub fn strongly_connected_components(&self, group: &[u32]) -> Vec> { - let mut params = Params::new(self.length, group); + /// Get the strongly-connected components of the set of input nodes. + pub fn strongly_connected_components(&self, nodes: &[u32]) -> Vec> { + let mut params = Params::new(self.length, nodes); 'outer: loop { for (node, value) in params.preorders.iter().enumerate() { From 6ffe14809f2e946605e5a9870f345015e1835691 Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 22 Apr 2022 20:07:28 +0200 Subject: [PATCH 421/846] don't populate Scope with aliases these are now properly imported. For testing reporting we still need a way to provide them without resolving imports (just for speed) --- compiler/can/src/scope.rs | 72 +++++++++++++++++++++------------- reporting/tests/helpers/mod.rs | 2 +- 2 files changed, 45 insertions(+), 29 deletions(-) diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index b71061f7b2..76a08d276a 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -29,44 +29,60 @@ pub struct Scope { home: ModuleId, } -impl Scope { - pub fn new(home: ModuleId, var_store: &mut VarStore) -> Scope { - use roc_types::solved_types::{BuiltinAlias, FreeVars}; - let solved_aliases = roc_types::builtin_aliases::aliases(); - let mut aliases = SendMap::default(); +fn add_aliases(var_store: &mut VarStore) -> SendMap { + use roc_types::solved_types::{BuiltinAlias, FreeVars}; - for (symbol, builtin_alias) in solved_aliases { - let BuiltinAlias { region, vars, typ } = builtin_alias; + let solved_aliases = roc_types::builtin_aliases::aliases(); + let mut aliases = SendMap::default(); - let mut free_vars = FreeVars::default(); - let typ = roc_types::solved_types::to_type(&typ, &mut free_vars, var_store); + for (symbol, builtin_alias) in solved_aliases { + let BuiltinAlias { region, vars, typ } = builtin_alias; - let mut variables = Vec::new(); - // make sure to sort these variables to make them line up with the type arguments - let mut type_variables: Vec<_> = free_vars.unnamed_vars.into_iter().collect(); - type_variables.sort(); - for (loc_name, (_, var)) in vars.iter().zip(type_variables) { - variables.push(Loc::at(loc_name.region, (loc_name.value.clone(), var))); - } + let mut free_vars = FreeVars::default(); + let typ = roc_types::solved_types::to_type(&typ, &mut free_vars, var_store); - let alias = Alias { - region, - typ, - lambda_set_variables: Vec::new(), - recursion_variables: MutSet::default(), - type_variables: variables, - // TODO(opaques): replace when opaques are included in the stdlib - kind: AliasKind::Structural, - }; - - aliases.insert(symbol, alias); + let mut variables = Vec::new(); + // make sure to sort these variables to make them line up with the type arguments + let mut type_variables: Vec<_> = free_vars.unnamed_vars.into_iter().collect(); + type_variables.sort(); + for (loc_name, (_, var)) in vars.iter().zip(type_variables) { + variables.push(Loc::at(loc_name.region, (loc_name.value.clone(), var))); } + let alias = Alias { + region, + typ, + lambda_set_variables: Vec::new(), + recursion_variables: MutSet::default(), + type_variables: variables, + // TODO(opaques): replace when opaques are included in the stdlib + kind: AliasKind::Structural, + }; + + aliases.insert(symbol, alias); + } + + aliases +} + +impl Scope { + pub fn new(home: ModuleId, _var_store: &mut VarStore) -> Scope { Scope { home, idents: Symbol::default_in_scope(), symbols: SendMap::default(), - aliases, + aliases: SendMap::default(), + // TODO(abilities): default abilities in scope + abilities_store: AbilitiesStore::default(), + } + } + + pub fn new_with_aliases(home: ModuleId, var_store: &mut VarStore) -> Scope { + Scope { + home, + idents: Symbol::default_in_scope(), + symbols: SendMap::default(), + aliases: add_aliases(var_store), // TODO(abilities): default abilities in scope abilities_store: AbilitiesStore::default(), } diff --git a/reporting/tests/helpers/mod.rs b/reporting/tests/helpers/mod.rs index 34aa95bf8f..269e0598ff 100644 --- a/reporting/tests/helpers/mod.rs +++ b/reporting/tests/helpers/mod.rs @@ -151,7 +151,7 @@ pub fn can_expr_with<'a>( // rules multiple times unnecessarily. let loc_expr = operator::desugar_expr(arena, &loc_expr); - let mut scope = Scope::new(home, &mut var_store); + let mut scope = Scope::new_with_aliases(home, &mut var_store); let dep_idents = IdentIds::exposed_builtins(0); let mut env = Env::new(home, &dep_idents, &module_ids, IdentIds::default()); let (loc_expr, output) = canonicalize_expr( From 87204628398bbba7f314c39cd420240e342aed62 Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 22 Apr 2022 21:40:06 +0200 Subject: [PATCH 422/846] use more specific function to get symbols/regions --- compiler/can/src/def.rs | 4 ++-- compiler/can/src/scope.rs | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 4d764d337e..4f1821b53b 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1274,7 +1274,7 @@ fn canonicalize_pending_value_def<'a>( ); can_defs_by_symbol.insert(symbol, def); } else { - for (_, (symbol, _)) in scope.idents() { + for (symbol, _) in scope.symbols() { if !vars_by_symbol.contains_key(symbol) { continue; } @@ -1432,7 +1432,7 @@ fn canonicalize_pending_value_def<'a>( ); can_defs_by_symbol.insert(symbol, def); } else { - for (_, (symbol, region)) in scope.idents() { + for (symbol, region) in scope.symbols() { if !vars_by_symbol.contains_key(symbol) { continue; } diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index 76a08d276a..d50cabf52a 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -88,10 +88,6 @@ impl Scope { } } - pub fn idents(&self) -> impl Iterator { - self.idents.iter() - } - pub fn symbols(&self) -> impl Iterator { self.symbols.iter() } @@ -181,7 +177,8 @@ impl Scope { opt_defined_alias: Option, ) -> RuntimeError { let opaques_in_scope = self - .idents() + .idents + .iter() .filter(|(_, (sym, _))| { self.aliases .get(sym) From 894e5bdd5c36f4e6ed7f1ec34d39523cf17c92cd Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 22 Apr 2022 22:06:00 +0200 Subject: [PATCH 423/846] add code for more efficient identifier store --- compiler/can/src/scope.rs | 80 +++++++++++++++++++++++++++-- compiler/collections/src/vec_map.rs | 13 ++++- 2 files changed, 88 insertions(+), 5 deletions(-) diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index d50cabf52a..d2b309db13 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -1,4 +1,6 @@ use roc_collections::all::{MutSet, SendMap}; +use roc_collections::soa; +use roc_collections::VecMap; use roc_module::ident::{Ident, Lowercase}; use roc_module::symbol::{IdentIds, ModuleId, Symbol}; use roc_problem::can::RuntimeError; @@ -8,11 +10,75 @@ use roc_types::types::{Alias, AliasKind, Type}; use crate::abilities::AbilitiesStore; -#[derive(Clone, Debug, PartialEq)] +struct IdentStore { + /// One big byte array that stores all `Ident`s + string: Vec, + + /// Slices into `string` to get an individual `Ident` + idents: Vec>, + + /// A Symbol for each Ident + symbols: Vec, + + /// A Region for each Ident + regions: Vec, +} + +impl IdentStore { + fn new() -> Self { + let defaults = Symbol::default_in_scope(); + let capacity = defaults.len(); + + let mut this = Self { + string: Vec::with_capacity(capacity), + idents: Vec::with_capacity(capacity), + symbols: Vec::with_capacity(capacity), + regions: Vec::with_capacity(capacity), + }; + + for (ident, (symbol, region)) in defaults { + this.insert_unchecked(ident, symbol, region); + } + + this + } + fn get(&self, ident: &Ident) -> Option { + let ident_bytes = ident.as_inline_str().as_str().as_bytes(); + + for (i, slice) in self.idents.iter().enumerate() { + if slice.len() == ident_bytes.len() && &self.string[slice.indices()] == ident_bytes { + return Some(i); + } + } + + None + } + + fn ident_to_symbol(&self, ident: &Ident) -> Option { + Some(self.symbols[self.get(ident)?]) + } + + /// Does not check that the ident is unique + fn insert_unchecked(&mut self, ident: Ident, symbol: Symbol, region: Region) { + let ident_bytes = ident.as_inline_str().as_str().as_bytes(); + + let slice = soa::Slice::extend_new(&mut self.string, ident_bytes.iter().copied()); + + self.idents.push(slice); + self.symbols.push(symbol); + self.regions.push(region); + } + + fn len(&self) -> usize { + self.idents.len() + } +} + +#[derive(Clone, Debug)] pub struct Scope { /// All the identifiers in scope, mapped to were they were defined and /// the Symbol they resolve to. - idents: SendMap, + idents: VecMap, /// A cache of all the symbols in scope. This makes lookups much /// faster when checking for unused defs and unused arguments. @@ -67,9 +133,12 @@ fn add_aliases(var_store: &mut VarStore) -> SendMap { impl Scope { pub fn new(home: ModuleId, _var_store: &mut VarStore) -> Scope { + let mut idents = VecMap::default(); + idents.extend(Symbol::default_in_scope()); + Scope { home, - idents: Symbol::default_in_scope(), + idents, symbols: SendMap::default(), aliases: SendMap::default(), // TODO(abilities): default abilities in scope @@ -78,9 +147,12 @@ impl Scope { } pub fn new_with_aliases(home: ModuleId, var_store: &mut VarStore) -> Scope { + let mut idents = VecMap::default(); + idents.extend(Symbol::default_in_scope()); + Scope { home, - idents: Symbol::default_in_scope(), + idents, symbols: SendMap::default(), aliases: add_aliases(var_store), // TODO(abilities): default abilities in scope diff --git a/compiler/collections/src/vec_map.rs b/compiler/collections/src/vec_map.rs index 57ab5c31b8..88bb8b7c9c 100644 --- a/compiler/collections/src/vec_map.rs +++ b/compiler/collections/src/vec_map.rs @@ -54,10 +54,17 @@ impl VecMap { } } - pub fn contains(&self, key: &K) -> bool { + pub fn contains_key(&self, key: &K) -> bool { self.keys.contains(key) } + pub fn get(&self, key: &K) -> Option<&V> { + match self.keys.iter().position(|k| k == key) { + None => None, + Some(index) => Some(&self.values[index]), + } + } + pub fn remove(&mut self, key: &K) { match self.keys.iter().position(|x| x == key) { None => { @@ -73,6 +80,10 @@ impl VecMap { self.keys.iter().zip(self.values.iter()) } + pub fn keys(&self) -> impl Iterator { + self.keys.iter() + } + pub fn values(&self) -> impl Iterator { self.values.iter() } From 7b234911acff26f73d01247d9fddc4ce2e2026ae Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 22 Apr 2022 23:47:43 +0200 Subject: [PATCH 424/846] do the work --- compiler/can/src/scope.rs | 138 +++++++++++++++++++----------- compiler/module/src/ident.rs | 2 +- reporting/tests/test_reporting.rs | 25 +----- 3 files changed, 91 insertions(+), 74 deletions(-) diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index d2b309db13..cf7d47d753 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -1,6 +1,5 @@ use roc_collections::all::{MutSet, SendMap}; use roc_collections::soa; -use roc_collections::VecMap; use roc_module::ident::{Ident, Lowercase}; use roc_module::symbol::{IdentIds, ModuleId, Symbol}; use roc_problem::can::RuntimeError; @@ -10,6 +9,7 @@ use roc_types::types::{Alias, AliasKind, Type}; use crate::abilities::AbilitiesStore; +#[derive(Clone, Debug)] struct IdentStore { /// One big byte array that stores all `Ident`s string: Vec, @@ -42,7 +42,39 @@ impl IdentStore { this } - fn get(&self, ident: &Ident) -> Option { + + fn iter_idents(&self) -> impl Iterator + '_ { + self.idents.iter().filter_map(move |slice| { + // empty slice is used when ability members are shadowed + if slice.is_empty() { + None + } else { + let bytes = &self.string[slice.indices()]; + let string = unsafe { std::str::from_utf8_unchecked(bytes) }; + + Some(Ident::from(string)) + } + }) + } + + fn iter_idents_symbols(&self) -> impl Iterator + '_ { + self.idents + .iter() + .zip(self.symbols.iter()) + .filter_map(move |(slice, symbol)| { + // empty slice is used when ability members are shadowed + if slice.is_empty() { + None + } else { + let bytes = &self.string[slice.indices()]; + let string = unsafe { std::str::from_utf8_unchecked(bytes) }; + + Some((Ident::from(string), *symbol)) + } + }) + } + + fn get_index(&self, ident: &Ident) -> Option { let ident_bytes = ident.as_inline_str().as_str().as_bytes(); for (i, slice) in self.idents.iter().enumerate() { @@ -54,8 +86,14 @@ impl IdentStore { None } - fn ident_to_symbol(&self, ident: &Ident) -> Option { - Some(self.symbols[self.get(ident)?]) + fn get_symbol(&self, ident: &Ident) -> Option { + Some(self.symbols[self.get_index(ident)?]) + } + + fn get_symbol_and_region(&self, ident: &Ident) -> Option<(Symbol, Region)> { + let index = self.get_index(ident)?; + + Some((self.symbols[index], self.regions[index])) } /// Does not check that the ident is unique @@ -76,13 +114,7 @@ impl IdentStore { #[derive(Clone, Debug)] pub struct Scope { - /// All the identifiers in scope, mapped to were they were defined and - /// the Symbol they resolve to. - idents: VecMap, - - /// A cache of all the symbols in scope. This makes lookups much - /// faster when checking for unused defs and unused arguments. - symbols: SendMap, + idents: IdentStore, /// The type aliases currently in scope pub aliases: SendMap, @@ -133,13 +165,9 @@ fn add_aliases(var_store: &mut VarStore) -> SendMap { impl Scope { pub fn new(home: ModuleId, _var_store: &mut VarStore) -> Scope { - let mut idents = VecMap::default(); - idents.extend(Symbol::default_in_scope()); - Scope { home, - idents, - symbols: SendMap::default(), + idents: IdentStore::new(), aliases: SendMap::default(), // TODO(abilities): default abilities in scope abilities_store: AbilitiesStore::default(), @@ -147,13 +175,9 @@ impl Scope { } pub fn new_with_aliases(home: ModuleId, var_store: &mut VarStore) -> Scope { - let mut idents = VecMap::default(); - idents.extend(Symbol::default_in_scope()); - Scope { home, - idents, - symbols: SendMap::default(), + idents: IdentStore::new(), aliases: add_aliases(var_store), // TODO(abilities): default abilities in scope abilities_store: AbilitiesStore::default(), @@ -161,15 +185,15 @@ impl Scope { } pub fn symbols(&self) -> impl Iterator { - self.symbols.iter() + self.idents.symbols.iter().zip(self.idents.regions.iter()) } pub fn contains_ident(&self, ident: &Ident) -> bool { - self.idents.contains_key(ident) + self.idents.get_index(ident).is_some() } pub fn contains_symbol(&self, symbol: Symbol) -> bool { - self.symbols.contains_key(&symbol) + self.idents.symbols.contains(&symbol) } pub fn num_idents(&self) -> usize { @@ -177,15 +201,23 @@ impl Scope { } pub fn lookup(&self, ident: &Ident, region: Region) -> Result { - match self.idents.get(ident) { - Some((symbol, _)) => Ok(*symbol), + println!( + "stats: string length: {}, ident len {}", + self.idents.string.len(), + self.idents.len() + ); + match self.idents.get_symbol(ident) { + Some(symbol) => Ok(symbol), None => { let error = RuntimeError::LookupNotInScope( Loc { region, value: ident.clone(), }, - self.idents.keys().map(|v| v.as_ref().into()).collect(), + self.idents + .iter_idents() + .map(|v| v.as_ref().into()) + .collect(), ); Err(error) @@ -209,7 +241,7 @@ impl Scope { debug_assert!(opaque_ref.starts_with('$')); let opaque = opaque_ref[1..].into(); - match self.idents.get(&opaque) { + match self.idents.get_symbol_and_region(&opaque) { // TODO: is it worth caching any of these results? Some((symbol, decl_region)) => { if symbol.module_id() != self.home { @@ -219,11 +251,11 @@ impl Scope { return Err(RuntimeError::OpaqueOutsideScope { opaque, referenced_region: lookup_region, - imported_region: *decl_region, + imported_region: decl_region, }); } - match self.aliases.get(symbol) { + match self.aliases.get(&symbol) { None => Err(self.opaque_not_defined_error(opaque, lookup_region, None)), Some(alias) => match alias.kind { @@ -234,7 +266,7 @@ impl Scope { Some(alias.header_region()), )), // All is good - AliasKind::Opaque => Ok((*symbol, alias)), + AliasKind::Opaque => Ok((symbol, alias)), }, } } @@ -250,8 +282,8 @@ impl Scope { ) -> RuntimeError { let opaques_in_scope = self .idents - .iter() - .filter(|(_, (sym, _))| { + .iter_idents_symbols() + .filter(|(_, sym)| { self.aliases .get(sym) .map(|alias| alias.kind) @@ -284,8 +316,9 @@ impl Scope { all_ident_ids: &mut IdentIds, region: Region, ) -> Result, Symbol)> { - match self.idents.get(&ident) { - Some(&(_, original_region)) => { + match self.idents.get_index(&ident) { + Some(index) => { + let original_region = self.idents.regions[index]; let shadow = Loc { value: ident.clone(), region, @@ -294,8 +327,8 @@ impl Scope { let ident_id = all_ident_ids.add(ident.clone()); let symbol = Symbol::new(self.home, ident_id); - self.symbols.insert(symbol, region); - self.idents.insert(ident, (symbol, region)); + self.idents.symbols[index] = symbol; + self.idents.regions[index] = region; Err((original_region, shadow, symbol)) } @@ -311,8 +344,8 @@ impl Scope { all_ident_ids: &mut IdentIds, region: Region, ) -> Result)> { - match self.idents.get(&ident) { - Some(&(_, original_region)) => { + match self.idents.get_symbol_and_region(&ident) { + Some((_, original_region)) => { let shadow = Loc { value: ident.clone(), region, @@ -337,17 +370,22 @@ impl Scope { all_ident_ids: &mut IdentIds, region: Region, ) -> Result<(Symbol, Option), (Region, Loc, Symbol)> { - match self.idents.get(&ident) { - Some(&(original_symbol, original_region)) => { + match self.idents.get_index(&ident) { + Some(index) => { + let original_symbol = self.idents.symbols[index]; + let original_region = self.idents.regions[index]; + let shadow_ident_id = all_ident_ids.add(ident.clone()); let shadow_symbol = Symbol::new(self.home, shadow_ident_id); - self.symbols.insert(shadow_symbol, region); - if self.abilities_store.is_ability_member_name(original_symbol) { self.abilities_store .register_specializing_symbol(shadow_symbol, original_symbol); + // Add a symbol for the shadow, but don't re-associate the member name. + let dummy = Ident::default(); + self.idents.insert_unchecked(dummy, shadow_symbol, region); + Ok((shadow_symbol, Some(original_symbol))) } else { // This is an illegal shadow. @@ -356,7 +394,9 @@ impl Scope { region, }; - self.idents.insert(ident, (shadow_symbol, region)); + // overwrite the data for this ident with the shadowed values + self.idents.symbols[index] = shadow_symbol; + self.idents.regions[index] = region; Err((original_region, shadow, shadow_symbol)) } @@ -386,8 +426,7 @@ impl Scope { let symbol = Symbol::new(self.home, ident_id); - self.symbols.insert(symbol, region); - self.idents.insert(ident, (symbol, region)); + self.idents.insert_unchecked(ident, symbol, region); symbol } @@ -410,11 +449,10 @@ impl Scope { symbol: Symbol, region: Region, ) -> Result<(), (Symbol, Region)> { - match self.idents.get(&ident) { - Some(shadowed) => Err(*shadowed), + match self.idents.get_symbol_and_region(&ident) { + Some(shadowed) => Err(shadowed), None => { - self.symbols.insert(symbol, region); - self.idents.insert(ident, (symbol, region)); + self.idents.insert_unchecked(ident, symbol, region); Ok(()) } diff --git a/compiler/module/src/ident.rs b/compiler/module/src/ident.rs index 2b4347d3d9..7f52ec7feb 100644 --- a/compiler/module/src/ident.rs +++ b/compiler/module/src/ident.rs @@ -3,7 +3,7 @@ pub use roc_ident::IdentStr; use std::fmt; /// This could be uppercase or lowercase, qualified or unqualified. -#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Default)] pub struct Ident(pub IdentStr); impl Ident { diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 8d25660f64..5756e5c4bd 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -650,13 +650,12 @@ mod test_reporting { Booly : [ Yes, No, Maybe ] - x = - No + x : List Booly + x = [] x "# ), - // Booly is called a "variable" indoc!( r#" ── DUPLICATE NAME ──────────────────────────────────────── /code/proj/Main.roc ─ @@ -673,26 +672,6 @@ mod test_reporting { Since these aliases have the same name, it's easy to use the wrong one on accident. Give one of them a new name. - - ── UNUSED DEFINITION ───────────────────────────────────── /code/proj/Main.roc ─ - - `Booly` is not used anywhere in your code. - - 1│ Booly : [ Yes, No ] - ^^^^^^^^^^^^^^^^^^^ - - If you didn't intend on using `Booly` then remove it so future readers - of your code don't wonder why it is there. - - ── UNUSED DEFINITION ───────────────────────────────────── /code/proj/Main.roc ─ - - `Booly` is not used anywhere in your code. - - 3│ Booly : [ Yes, No, Maybe ] - ^^^^^^^^^^^^^^^^^^^^^^^^^^ - - If you didn't intend on using `Booly` then remove it so future readers - of your code don't wonder why it is there. "# ), ) From b0aafd762a2630dbb43d17ab84287f941fba630e Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 8 Apr 2022 11:59:29 -0400 Subject: [PATCH 425/846] Show more type information in pretty printing --- compiler/types/src/pretty_print.rs | 4 +++- compiler/types/src/subs.rs | 21 +++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/compiler/types/src/pretty_print.rs b/compiler/types/src/pretty_print.rs index d3111cad1d..f9e11471f3 100644 --- a/compiler/types/src/pretty_print.rs +++ b/compiler/types/src/pretty_print.rs @@ -450,7 +450,9 @@ fn write_content<'a>( } // useful for debugging - if false { + if cfg!(debug_assertions) + && std::env::var("ROC_PRETTY_PRINT_ALIAS_CONTENTS").is_ok() + { buf.push_str("[[ but really "); let content = subs.get_content_without_compacting(*_actual); write_content(env, ctx, content, subs, buf, parens); diff --git a/compiler/types/src/subs.rs b/compiler/types/src/subs.rs index 1a327c85c3..a94cca1be6 100644 --- a/compiler/types/src/subs.rs +++ b/compiler/types/src/subs.rs @@ -772,7 +772,15 @@ fn subs_fmt_content(this: &Content, subs: &Subs, f: &mut fmt::Formatter) -> fmt: AliasKind::Opaque => "Opaque", }; - write!(f, "{}({:?}, {:?}, {:?})", wrap, name, slice, actual) + write!( + f, + "{}({:?}, {:?}, <{:?}>{:?})", + wrap, + name, + slice, + actual, + SubsFmtContent(subs.get_content_without_compacting(*actual), subs) + ) } Content::RangedNumber(typ, range) => { let slice = subs.get_subs_slice(*range); @@ -833,7 +841,16 @@ fn subs_fmt_flat_type(this: &FlatType, subs: &Subs, f: &mut fmt::Formatter) -> f let (it, new_ext) = tags.sorted_iterator_and_ext(subs, *ext); for (name, slice) in it { - write!(f, "{:?} {:?}, ", name, slice)?; + write!(f, "{:?} ", name)?; + for var in slice { + write!( + f, + "<{:?}>{:?} ", + var, + SubsFmtContent(subs.get_content_without_compacting(*var), subs) + )?; + } + write!(f, ", ")?; } write!(f, "]<{:?}>", new_ext) From 92dfccedffa925cc2e11489ca3290baeb133e38a Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 8 Apr 2022 11:59:37 -0400 Subject: [PATCH 426/846] Document debugging env variables --- compiler/README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/compiler/README.md b/compiler/README.md index e57984562d..d26c7e862e 100644 --- a/compiler/README.md +++ b/compiler/README.md @@ -167,6 +167,20 @@ For a more detailed understanding of the compilation phases, see the `Phase`, `B ## Debugging intermediate representations +### Debugging the typechecker + +Setting the following environment variables: + +- `ROC_PRINT_UNIFICATIONS` prints all type unifications that are done, + before and after the unification. +- `ROC_PRINT_MISMATCHES` prints all type mismatches hit during unification. +- `ROC_PRETTY_PRINT_ALIAS_CONTENTS` expands the contents of aliases during + pretty-printing of types. + +Note that this is only relevant during debug builds. Eventually we should have +some better debugging tools here, see https://github.com/rtfeldman/roc/issues/2486 +for one. + ### The mono IR If you observe a miscomplication, you may first want to check the generated mono From 02d5cd78856b3fe2ece69f139069d4305b9dc34b Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 8 Apr 2022 12:21:53 -0400 Subject: [PATCH 427/846] Deal with recursive pointers that pass through non-recursive layouts --- compiler/alias_analysis/src/lib.rs | 127 +++++++++++++------- compiler/gen_llvm/src/llvm/refcounting.rs | 34 +++++- compiler/mono/src/layout.rs | 104 +++++++--------- compiler/test_mono/generated/issue_2810.txt | 6 + compiler/test_mono/src/tests.rs | 17 +++ repl_test/src/tests.rs | 20 +++ 6 files changed, 203 insertions(+), 105 deletions(-) create mode 100644 compiler/test_mono/generated/issue_2810.txt diff --git a/compiler/alias_analysis/src/lib.rs b/compiler/alias_analysis/src/lib.rs index d492f3a12a..572a438847 100644 --- a/compiler/alias_analysis/src/lib.rs +++ b/compiler/alias_analysis/src/lib.rs @@ -279,7 +279,8 @@ fn build_entry_point( let block = builder.add_block(); // to the modelling language, the arguments appear out of thin air - let argument_type = build_tuple_type(&mut builder, layout.arguments)?; + let argument_type = + build_tuple_type(&mut builder, layout.arguments, &WhenRecursive::Unreachable)?; // does not make any assumptions about the input // let argument = builder.add_unknown_with(block, &[], argument_type)?; @@ -308,7 +309,11 @@ fn build_entry_point( let block = builder.add_block(); - let type_id = layout_spec(&mut builder, &Layout::struct_no_name_order(layouts))?; + let type_id = layout_spec( + &mut builder, + &Layout::struct_no_name_order(layouts), + &WhenRecursive::Unreachable, + )?; let argument = builder.add_unknown_with(block, &[], type_id)?; @@ -352,8 +357,9 @@ fn proc_spec<'a>(proc: &Proc<'a>) -> Result<(FuncDef, MutSet>)> let arg_type_id = layout_spec( &mut builder, &Layout::struct_no_name_order(&argument_layouts), + &WhenRecursive::Unreachable, )?; - let ret_type_id = layout_spec(&mut builder, &proc.ret_layout)?; + let ret_type_id = layout_spec(&mut builder, &proc.ret_layout, &WhenRecursive::Unreachable)?; let spec = builder.build(arg_type_id, ret_type_id, root)?; @@ -457,10 +463,14 @@ fn stmt_spec<'a>( let mut type_ids = Vec::new(); for p in parameters.iter() { - type_ids.push(layout_spec(builder, &p.layout)?); + type_ids.push(layout_spec( + builder, + &p.layout, + &WhenRecursive::Unreachable, + )?); } - let ret_type_id = layout_spec(builder, layout)?; + let ret_type_id = layout_spec(builder, layout, &WhenRecursive::Unreachable)?; let jp_arg_type_id = builder.add_tuple_type(&type_ids)?; @@ -500,14 +510,14 @@ fn stmt_spec<'a>( builder.add_sub_block(block, BlockExpr(cont_block, cont_value_id)) } Jump(id, symbols) => { - let ret_type_id = layout_spec(builder, layout)?; + let ret_type_id = layout_spec(builder, layout, &WhenRecursive::Unreachable)?; let argument = build_tuple_value(builder, env, block, symbols)?; let jpid = env.join_points[id]; builder.add_jump(block, jpid, argument, ret_type_id) } RuntimeError(_) => { - let type_id = layout_spec(builder, layout)?; + let type_id = layout_spec(builder, layout, &WhenRecursive::Unreachable)?; builder.add_terminate(block, type_id) } @@ -556,11 +566,15 @@ fn build_recursive_tuple_type( builder.add_tuple_type(&field_types) } -fn build_tuple_type(builder: &mut impl TypeContext, layouts: &[Layout]) -> Result { +fn build_tuple_type( + builder: &mut impl TypeContext, + layouts: &[Layout], + when_recursive: &WhenRecursive, +) -> Result { let mut field_types = Vec::new(); for field in layouts.iter() { - field_types.push(layout_spec(builder, field)?); + field_types.push(layout_spec(builder, field, when_recursive)?); } builder.add_tuple_type(&field_types) @@ -691,7 +705,7 @@ fn call_spec( .map(|symbol| env.symbols[symbol]) .collect(); - let result_type = layout_spec(builder, ret_layout)?; + let result_type = layout_spec(builder, ret_layout, &WhenRecursive::Unreachable)?; builder.add_unknown_with(block, &arguments, result_type) } @@ -761,7 +775,8 @@ fn call_spec( }; let state_layout = argument_layouts[0]; - let state_type = layout_spec(builder, &state_layout)?; + let state_type = + layout_spec(builder, &state_layout, &WhenRecursive::Unreachable)?; let init_state = state; add_loop(builder, block, state_type, init_state, loop_body) @@ -782,7 +797,8 @@ fn call_spec( }; let state_layout = argument_layouts[0]; - let state_type = layout_spec(builder, &state_layout)?; + let state_type = + layout_spec(builder, &state_layout, &WhenRecursive::Unreachable)?; let init_state = state; add_loop(builder, block, state_type, init_state, loop_body) @@ -806,7 +822,8 @@ fn call_spec( }; let state_layout = argument_layouts[0]; - let state_type = layout_spec(builder, &state_layout)?; + let state_type = + layout_spec(builder, &state_layout, &WhenRecursive::Unreachable)?; let init_state = state; add_loop(builder, block, state_type, init_state, loop_body) @@ -828,10 +845,12 @@ fn call_spec( list_append(builder, block, update_mode_var, state, new_element) }; - let output_element_type = layout_spec(builder, return_layout)?; + let output_element_type = + layout_spec(builder, return_layout, &WhenRecursive::Unreachable)?; let state_layout = Layout::Builtin(Builtin::List(return_layout)); - let state_type = layout_spec(builder, &state_layout)?; + let state_type = + layout_spec(builder, &state_layout, &WhenRecursive::Unreachable)?; let init_state = new_list(builder, block, output_element_type)?; @@ -851,10 +870,12 @@ fn call_spec( list_append(builder, block, update_mode_var, state, new_element) }; - let output_element_type = layout_spec(builder, return_layout)?; + let output_element_type = + layout_spec(builder, return_layout, &WhenRecursive::Unreachable)?; let state_layout = Layout::Builtin(Builtin::List(return_layout)); - let state_type = layout_spec(builder, &state_layout)?; + let state_type = + layout_spec(builder, &state_layout, &WhenRecursive::Unreachable)?; let init_state = new_list(builder, block, output_element_type)?; @@ -879,7 +900,8 @@ fn call_spec( }; let state_layout = Layout::Builtin(Builtin::List(&argument_layouts[0])); - let state_type = layout_spec(builder, &state_layout)?; + let state_type = + layout_spec(builder, &state_layout, &WhenRecursive::Unreachable)?; let init_state = list; add_loop(builder, block, state_type, init_state, loop_body) @@ -903,10 +925,12 @@ fn call_spec( list_append(builder, block, update_mode_var, state, new_element) }; - let output_element_type = layout_spec(builder, return_layout)?; + let output_element_type = + layout_spec(builder, return_layout, &WhenRecursive::Unreachable)?; let state_layout = Layout::Builtin(Builtin::List(return_layout)); - let state_type = layout_spec(builder, &state_layout)?; + let state_type = + layout_spec(builder, &state_layout, &WhenRecursive::Unreachable)?; let init_state = new_list(builder, block, output_element_type)?; @@ -936,10 +960,12 @@ fn call_spec( list_append(builder, block, update_mode_var, state, new_element) }; - let output_element_type = layout_spec(builder, return_layout)?; + let output_element_type = + layout_spec(builder, return_layout, &WhenRecursive::Unreachable)?; let state_layout = Layout::Builtin(Builtin::List(return_layout)); - let state_type = layout_spec(builder, &state_layout)?; + let state_type = + layout_spec(builder, &state_layout, &WhenRecursive::Unreachable)?; let init_state = new_list(builder, block, output_element_type)?; @@ -975,10 +1001,12 @@ fn call_spec( list_append(builder, block, update_mode_var, state, new_element) }; - let output_element_type = layout_spec(builder, return_layout)?; + let output_element_type = + layout_spec(builder, return_layout, &WhenRecursive::Unreachable)?; let state_layout = Layout::Builtin(Builtin::List(return_layout)); - let state_type = layout_spec(builder, &state_layout)?; + let state_type = + layout_spec(builder, &state_layout, &WhenRecursive::Unreachable)?; let init_state = new_list(builder, block, output_element_type)?; @@ -1010,7 +1038,8 @@ fn call_spec( }; let state_layout = Layout::Builtin(Builtin::List(&argument_layouts[0])); - let state_type = layout_spec(builder, &state_layout)?; + let state_type = + layout_spec(builder, &state_layout, &WhenRecursive::Unreachable)?; let init_state = list; add_loop(builder, block, state_type, init_state, loop_body) @@ -1087,11 +1116,13 @@ fn call_spec( ) }; - let output_element_type = layout_spec(builder, &output_element_layout)?; + let output_element_type = + layout_spec(builder, &output_element_layout, &WhenRecursive::Unreachable)?; let init_state = new_list(builder, block, output_element_type)?; let state_layout = Layout::Builtin(Builtin::List(&output_element_layout)); - let state_type = layout_spec(builder, &state_layout)?; + let state_type = + layout_spec(builder, &state_layout, &WhenRecursive::Unreachable)?; add_loop(builder, block, state_type, init_state, loop_body) } @@ -1108,7 +1139,8 @@ fn call_spec( }; let state_layout = Layout::Builtin(Builtin::Bool); - let state_type = layout_spec(builder, &state_layout)?; + let state_type = + layout_spec(builder, &state_layout, &WhenRecursive::Unreachable)?; let init_state = new_num(builder, block)?; @@ -1127,7 +1159,8 @@ fn call_spec( }; let state_layout = Layout::Builtin(Builtin::Bool); - let state_type = layout_spec(builder, &state_layout)?; + let state_type = + layout_spec(builder, &state_layout, &WhenRecursive::Unreachable)?; let init_state = new_num(builder, block)?; @@ -1139,7 +1172,8 @@ fn call_spec( // ListFindUnsafe returns { value: v, found: Bool=Int1 } let output_layouts = vec![argument_layouts[0], Layout::Builtin(Builtin::Bool)]; let output_layout = Layout::struct_no_name_order(&output_layouts); - let output_type = layout_spec(builder, &output_layout)?; + let output_type = + layout_spec(builder, &output_layout, &WhenRecursive::Unreachable)?; let loop_body = |builder: &mut FuncDefBuilder, block, output| { let bag = builder.add_get_tuple_field(block, list, LIST_BAG_INDEX)?; @@ -1201,7 +1235,7 @@ fn lowlevel_spec( ) -> Result { use LowLevel::*; - let type_id = layout_spec(builder, layout)?; + let type_id = layout_spec(builder, layout, &WhenRecursive::Unreachable)?; let mode = update_mode.to_bytes(); let update_mode_var = UpdateModeVar(&mode); @@ -1323,8 +1357,8 @@ fn lowlevel_spec( } DictEmpty => match layout { Layout::Builtin(Builtin::Dict(key_layout, value_layout)) => { - let key_id = layout_spec(builder, key_layout)?; - let value_id = layout_spec(builder, value_layout)?; + let key_id = layout_spec(builder, key_layout, &WhenRecursive::Unreachable)?; + let value_id = layout_spec(builder, value_layout, &WhenRecursive::Unreachable)?; new_dict(builder, block, key_id, value_id) } _ => unreachable!("empty array does not have a list layout"), @@ -1367,7 +1401,7 @@ fn lowlevel_spec( // TODO overly pessimstic let arguments: Vec<_> = arguments.iter().map(|symbol| env.symbols[symbol]).collect(); - let result_type = layout_spec(builder, layout)?; + let result_type = layout_spec(builder, layout, &WhenRecursive::Unreachable)?; builder.add_unknown_with(block, &arguments, result_type) } @@ -1478,7 +1512,8 @@ fn expr_spec<'a>( let value_id = match tag_layout { UnionLayout::NonRecursive(tags) => { - let variant_types = non_recursive_variant_types(builder, tags)?; + let variant_types = + non_recursive_variant_types(builder, tags, &WhenRecursive::Unreachable)?; let value_id = build_tuple_value(builder, env, block, arguments)?; return builder.add_make_union(block, &variant_types, *tag_id as u32, value_id); } @@ -1592,7 +1627,7 @@ fn expr_spec<'a>( builder.add_get_tuple_field(block, value_id, *index as u32) } Array { elem_layout, elems } => { - let type_id = layout_spec(builder, elem_layout)?; + let type_id = layout_spec(builder, elem_layout, &WhenRecursive::Unreachable)?; let list = new_list(builder, block, type_id)?; @@ -1619,19 +1654,19 @@ fn expr_spec<'a>( EmptyArray => match layout { Layout::Builtin(Builtin::List(element_layout)) => { - let type_id = layout_spec(builder, element_layout)?; + let type_id = layout_spec(builder, element_layout, &WhenRecursive::Unreachable)?; new_list(builder, block, type_id) } _ => unreachable!("empty array does not have a list layout"), }, Reset { symbol, .. } => { - let type_id = layout_spec(builder, layout)?; + let type_id = layout_spec(builder, layout, &WhenRecursive::Unreachable)?; let value_id = env.symbols[symbol]; builder.add_unknown_with(block, &[value_id], type_id) } RuntimeErrorFunction(_) => { - let type_id = layout_spec(builder, layout)?; + let type_id = layout_spec(builder, layout, &WhenRecursive::Unreachable)?; builder.add_terminate(block, type_id) } @@ -1658,18 +1693,24 @@ fn literal_spec( } } -fn layout_spec(builder: &mut impl TypeContext, layout: &Layout) -> Result { - layout_spec_help(builder, layout, &WhenRecursive::Unreachable) +fn layout_spec( + builder: &mut impl TypeContext, + layout: &Layout, + when_recursive: &WhenRecursive, +) -> Result { + layout_spec_help(builder, layout, when_recursive) } fn non_recursive_variant_types( builder: &mut impl TypeContext, tags: &[&[Layout]], + // If there is a recursive pointer latent within this layout, coming from a containing layout. + when_recursive: &WhenRecursive, ) -> Result> { let mut result = Vec::with_capacity(tags.len()); for tag in tags.iter() { - result.push(build_tuple_type(builder, tag)?); + result.push(build_tuple_type(builder, tag, when_recursive)?); } Ok(result) @@ -1701,7 +1742,7 @@ fn layout_spec_help( builder.add_tuple_type(&[]) } UnionLayout::NonRecursive(tags) => { - let variant_types = non_recursive_variant_types(builder, tags)?; + let variant_types = non_recursive_variant_types(builder, tags, when_recursive)?; builder.add_union_type(&variant_types) } UnionLayout::Recursive(_) diff --git a/compiler/gen_llvm/src/llvm/refcounting.rs b/compiler/gen_llvm/src/llvm/refcounting.rs index ce79180f75..504d59b96a 100644 --- a/compiler/gen_llvm/src/llvm/refcounting.rs +++ b/compiler/gen_llvm/src/llvm/refcounting.rs @@ -1809,7 +1809,39 @@ fn modify_refcount_union_help<'a, 'ctx, 'env>( for (i, field_layout) in field_layouts.iter().enumerate() { if let Layout::RecursivePointer = field_layout { - panic!("non-recursive tag unions cannot contain naked recursion pointers!"); + let recursive_union_layout = match when_recursive { + WhenRecursive::Unreachable => { + panic!("non-recursive tag unions cannot contain naked recursion pointers!"); + } + WhenRecursive::Loop(recursive_union_layout) => recursive_union_layout, + }; + + // This field is a pointer to the recursive pointer. + let field_ptr = env + .builder + .build_struct_gep(cast_tag_data_pointer, i as u32, "modify_tag_field") + .unwrap(); + + // This is the actual pointer to the recursive data. + let field_value = env.builder.build_load(field_ptr, "load_recursive_pointer"); + + debug_assert!(field_value.is_pointer_value()); + + // therefore we must cast it to our desired type + let union_type = + basic_type_from_layout(env, &Layout::Union(*recursive_union_layout)); + let recursive_ptr_field_value = + cast_basic_basic(env.builder, field_value, union_type); + + modify_refcount_layout_help( + env, + parent, + layout_ids, + mode.to_call_mode(fn_val), + when_recursive, + recursive_ptr_field_value, + &Layout::RecursivePointer, + ) } else if field_layout.contains_refcounted() { let field_ptr = env .builder diff --git a/compiler/mono/src/layout.rs b/compiler/mono/src/layout.rs index eef312cab3..e21d054ed0 100644 --- a/compiler/mono/src/layout.rs +++ b/compiler/mono/src/layout.rs @@ -78,7 +78,7 @@ impl<'a> RawFunctionLayout<'a> { let structure_content = env.subs.get_content_without_compacting(structure); Self::new_help(env, structure, *structure_content) } - Structure(flat_type) => Self::layout_from_flat_type(env, flat_type), + Structure(flat_type) => Self::layout_from_flat_type(env, var, flat_type), RangedNumber(typ, _) => Self::from_var(env, typ), // Ints @@ -152,6 +152,7 @@ impl<'a> RawFunctionLayout<'a> { fn layout_from_flat_type( env: &mut Env<'a, '_>, + var: Variable, flat_type: FlatType, ) -> Result { use roc_types::subs::FlatType::*; @@ -195,7 +196,7 @@ impl<'a> RawFunctionLayout<'a> { Self::from_var(env, var) } _ => { - let layout = layout_from_flat_type(env, flat_type)?; + let layout = layout_from_flat_type(env, var, flat_type)?; Ok(Self::ZeroArgumentThunk(layout)) } } @@ -959,7 +960,7 @@ impl<'a> Layout<'a> { let structure_content = env.subs.get_content_without_compacting(structure); Self::new_help(env, structure, *structure_content) } - Structure(flat_type) => layout_from_flat_type(env, flat_type), + Structure(flat_type) => layout_from_flat_type(env, var, flat_type), Alias(symbol, _args, actual_var, _) => { if let Some(int_width) = IntWidth::try_from_symbol(symbol) { @@ -1297,6 +1298,8 @@ impl<'a> LayoutCache<'a> { target_info: self.target_info, }; + //if true {panic!()} + Layout::from_var(&mut env, var) } @@ -1570,6 +1573,7 @@ impl<'a> Builtin<'a> { fn layout_from_flat_type<'a>( env: &mut Env<'a, '_>, + var: Variable, flat_type: FlatType, ) -> Result, LayoutProblem> { use roc_types::subs::FlatType::*; @@ -1731,7 +1735,7 @@ fn layout_from_flat_type<'a>( debug_assert!(ext_var_is_empty_tag_union(subs, ext_var)); - Ok(layout_from_tag_union(arena, &tags, subs, env.target_info)) + Ok(layout_from_tag_union(env, &tags)) } FunctionOrTagUnion(tag_name, _, ext_var) => { debug_assert!( @@ -1742,7 +1746,7 @@ fn layout_from_flat_type<'a>( let union_tags = UnionTags::from_tag_name_index(tag_name); let (tags, _) = union_tags.unsorted_tags_and_ext(subs, ext_var); - Ok(layout_from_tag_union(arena, &tags, subs, env.target_info)) + Ok(layout_from_tag_union(env, &tags)) } RecursiveTagUnion(rec_var, tags, ext_var) => { let (tags, ext_var) = tags.unsorted_tags_and_ext(subs, ext_var); @@ -1772,6 +1776,7 @@ fn layout_from_flat_type<'a>( } } + env.insert_seen(var); env.insert_seen(rec_var); for (index, &(_name, variables)) in tags_vec.iter().enumerate() { if matches!(nullable, Some(i) if i == index as TagIdIntType) { @@ -1801,6 +1806,7 @@ fn layout_from_flat_type<'a>( tag_layouts.push(tag_layout.into_bump_slice()); } env.remove_seen(rec_var); + env.insert_seen(var); let union_layout = if let Some(tag_id) = nullable { match tag_layouts.into_bump_slice() { @@ -2071,23 +2077,14 @@ fn is_recursive_tag_union(layout: &Layout) -> bool { } fn union_sorted_tags_help_new<'a>( - arena: &'a Bump, + env: &mut Env<'a, '_>, tags_list: &[(&'_ TagName, &[Variable])], opt_rec_var: Option, - subs: &Subs, - target_info: TargetInfo, ) -> UnionVariant<'a> { // sort up front; make sure the ordering stays intact! - let mut tags_list = Vec::from_iter_in(tags_list.iter(), arena); + let mut tags_list = Vec::from_iter_in(tags_list.iter(), env.arena); tags_list.sort_unstable_by(|(a, _), (b, _)| a.cmp(b)); - let mut env = Env { - arena, - subs, - seen: Vec::new_in(arena), - target_info, - }; - match tags_list.len() { 0 => { // trying to instantiate a type with no values @@ -2098,18 +2095,19 @@ fn union_sorted_tags_help_new<'a>( let tag_name = tag_name.clone(); // just one tag in the union (but with arguments) can be a struct - let mut layouts = Vec::with_capacity_in(tags_list.len(), arena); + let mut layouts = Vec::with_capacity_in(tags_list.len(), env.arena); // special-case NUM_AT_NUM: if its argument is a FlexVar, make it Int match tag_name { TagName::Private(Symbol::NUM_AT_NUM) => { let var = arguments[0]; - layouts - .push(unwrap_num_tag(subs, var, target_info).expect("invalid num layout")); + layouts.push( + unwrap_num_tag(env.subs, var, env.target_info).expect("invalid num layout"), + ); } _ => { for &var in arguments { - match Layout::from_var(&mut env, var) { + match Layout::from_var(env, var) { Ok(layout) => { layouts.push(layout); } @@ -2129,8 +2127,8 @@ fn union_sorted_tags_help_new<'a>( } layouts.sort_by(|layout1, layout2| { - let size1 = layout1.alignment_bytes(target_info); - let size2 = layout2.alignment_bytes(target_info); + let size1 = layout1.alignment_bytes(env.target_info); + let size2 = layout2.alignment_bytes(env.target_info); size2.cmp(&size1) }); @@ -2151,7 +2149,7 @@ fn union_sorted_tags_help_new<'a>( } num_tags => { // default path - let mut answer = Vec::with_capacity_in(tags_list.len(), arena); + let mut answer = Vec::with_capacity_in(tags_list.len(), env.arena); let mut has_any_arguments = false; let mut nullable: Option<(TagIdIntType, TagName)> = None; @@ -2174,17 +2172,19 @@ fn union_sorted_tags_help_new<'a>( continue; } - let mut arg_layouts = Vec::with_capacity_in(arguments.len() + 1, arena); + let mut arg_layouts = Vec::with_capacity_in(arguments.len() + 1, env.arena); for &var in arguments { - match Layout::from_var(&mut env, var) { + match Layout::from_var(env, var) { Ok(layout) => { has_any_arguments = true; // make sure to not unroll recursive types! let self_recursion = opt_rec_var.is_some() - && subs.get_root_key_without_compacting(var) - == subs.get_root_key_without_compacting(opt_rec_var.unwrap()) + && env.subs.get_root_key_without_compacting(var) + == env + .subs + .get_root_key_without_compacting(opt_rec_var.unwrap()) && is_recursive_tag_union(&layout); if self_recursion { @@ -2207,8 +2207,8 @@ fn union_sorted_tags_help_new<'a>( } arg_layouts.sort_by(|layout1, layout2| { - let size1 = layout1.alignment_bytes(target_info); - let size2 = layout2.alignment_bytes(target_info); + let size1 = layout1.alignment_bytes(env.target_info); + let size2 = layout2.alignment_bytes(env.target_info); size2.cmp(&size1) }); @@ -2229,7 +2229,7 @@ fn union_sorted_tags_help_new<'a>( 3..=MAX_ENUM_SIZE if !has_any_arguments => { // type can be stored in a byte // needs the sorted tag names to determine the tag_id - let mut tag_names = Vec::with_capacity_in(answer.len(), arena); + let mut tag_names = Vec::with_capacity_in(answer.len(), env.arena); for (tag_name, _) in answer { tag_names.push(tag_name); @@ -2488,27 +2488,15 @@ pub fn union_sorted_tags_help<'a>( } } -fn layout_from_newtype<'a>( - arena: &'a Bump, - tags: &UnsortedUnionTags, - subs: &Subs, - target_info: TargetInfo, -) -> Layout<'a> { - debug_assert!(tags.is_newtype_wrapper(subs)); +fn layout_from_newtype<'a>(env: &mut Env<'a, '_>, tags: &UnsortedUnionTags) -> Layout<'a> { + debug_assert!(tags.is_newtype_wrapper(env.subs)); - let (tag_name, var) = tags.get_newtype(subs); + let (tag_name, var) = tags.get_newtype(env.subs); if tag_name == &TagName::Private(Symbol::NUM_AT_NUM) { - unwrap_num_tag(subs, var, target_info).expect("invalid Num argument") + unwrap_num_tag(env.subs, var, env.target_info).expect("invalid Num argument") } else { - let mut env = Env { - arena, - subs, - seen: Vec::new_in(arena), - target_info, - }; - - match Layout::from_var(&mut env, var) { + match Layout::from_var(env, var) { Ok(layout) => layout, Err(LayoutProblem::UnresolvedTypeVar(_)) => { // If we encounter an unbound type var (e.g. `Ok *`) @@ -2525,16 +2513,11 @@ fn layout_from_newtype<'a>( } } -fn layout_from_tag_union<'a>( - arena: &'a Bump, - tags: &UnsortedUnionTags, - subs: &Subs, - target_info: TargetInfo, -) -> Layout<'a> { +fn layout_from_tag_union<'a>(env: &mut Env<'a, '_>, tags: &UnsortedUnionTags) -> Layout<'a> { use UnionVariant::*; - if tags.is_newtype_wrapper(subs) { - return layout_from_newtype(arena, tags, subs, target_info); + if tags.is_newtype_wrapper(env.subs) { + return layout_from_newtype(env, tags); } let tags_vec = &tags.tags; @@ -2545,12 +2528,11 @@ fn layout_from_tag_union<'a>( let &var = arguments.iter().next().unwrap(); - unwrap_num_tag(subs, var, target_info).expect("invalid Num argument") + unwrap_num_tag(env.subs, var, env.target_info).expect("invalid Num argument") } _ => { let opt_rec_var = None; - let variant = - union_sorted_tags_help_new(arena, tags_vec, opt_rec_var, subs, target_info); + let variant = union_sorted_tags_help_new(env, tags_vec, opt_rec_var); match variant { Never => Layout::VOID, @@ -2576,7 +2558,7 @@ fn layout_from_tag_union<'a>( NonRecursive { sorted_tag_layouts: tags, } => { - let mut tag_layouts = Vec::with_capacity_in(tags.len(), arena); + let mut tag_layouts = Vec::with_capacity_in(tags.len(), env.arena); tag_layouts.extend(tags.iter().map(|r| r.1)); Layout::Union(UnionLayout::NonRecursive(tag_layouts.into_bump_slice())) @@ -2585,7 +2567,7 @@ fn layout_from_tag_union<'a>( Recursive { sorted_tag_layouts: tags, } => { - let mut tag_layouts = Vec::with_capacity_in(tags.len(), arena); + let mut tag_layouts = Vec::with_capacity_in(tags.len(), env.arena); tag_layouts.extend(tags.iter().map(|r| r.1)); debug_assert!(tag_layouts.len() > 1); @@ -2597,7 +2579,7 @@ fn layout_from_tag_union<'a>( nullable_name: _, sorted_tag_layouts: tags, } => { - let mut tag_layouts = Vec::with_capacity_in(tags.len(), arena); + let mut tag_layouts = Vec::with_capacity_in(tags.len(), env.arena); tag_layouts.extend(tags.iter().map(|r| r.1)); Layout::Union(UnionLayout::NullableWrapped { diff --git a/compiler/test_mono/generated/issue_2810.txt b/compiler/test_mono/generated/issue_2810.txt new file mode 100644 index 0000000000..d5b11bcac2 --- /dev/null +++ b/compiler/test_mono/generated/issue_2810.txt @@ -0,0 +1,6 @@ +procedure Test.0 (): + let Test.16 : [C TODO, C ] = SystemTool ; + let Test.14 : TODO = Job Test.16; + let Test.13 : [C TODO, C ] = FromJob Test.14; + let Test.4 : TODO = Job Test.13; + ret Test.4; diff --git a/compiler/test_mono/src/tests.rs b/compiler/test_mono/src/tests.rs index 86e93346f1..115b5a8ca3 100644 --- a/compiler/test_mono/src/tests.rs +++ b/compiler/test_mono/src/tests.rs @@ -1283,6 +1283,23 @@ fn issue_2583_specialize_errors_behind_unified_branches() { ) } +#[mono_test] +fn issue_2810() { + indoc!( + r#" + Command : [ Command Tool ] + + Job : [ Job Command ] + + Tool : [ SystemTool, FromJob Job ] + + a : Job + a = Job (Command (FromJob (Job (Command SystemTool)))) + a + "# + ) +} + #[mono_test] fn issue_2811() { indoc!( diff --git a/repl_test/src/tests.rs b/repl_test/src/tests.rs index 53b692266c..fe2b90d2ea 100644 --- a/repl_test/src/tests.rs +++ b/repl_test/src/tests.rs @@ -1138,3 +1138,23 @@ fn issue_2818() { r" : {} -> List Str", ) } + +#[test] +fn issue_2810_recursive_layout_inside_nonrecursive() { + expect_success( + indoc!( + r#" + Command : [ Command Tool ] + + Job : [ Job Command ] + + Tool : [ SystemTool, FromJob Job ] + + a : Job + a = Job (Command (FromJob (Job (Command SystemTool)))) + a + "# + ), + "Job (Command (FromJob (Job (Command SystemTool)))) : Job", + ) +} From b61481c6e771f6c3a1969cf00d0d904a9ca852b5 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 8 Apr 2022 17:05:57 -0400 Subject: [PATCH 428/846] Try another strategy - fix recursion vars during typechecking --- compiler/mono/src/layout.rs | 8 ++-- compiler/types/src/subs.rs | 74 +++++++++++++++++++++++++++--------- compiler/unify/src/unify.rs | 76 ++++++++++++++++++++++++++++++++++--- 3 files changed, 131 insertions(+), 27 deletions(-) diff --git a/compiler/mono/src/layout.rs b/compiler/mono/src/layout.rs index e21d054ed0..58fe798d23 100644 --- a/compiler/mono/src/layout.rs +++ b/compiler/mono/src/layout.rs @@ -196,7 +196,7 @@ impl<'a> RawFunctionLayout<'a> { Self::from_var(env, var) } _ => { - let layout = layout_from_flat_type(env, var, flat_type)?; + let layout = layout_from_flat_type(env, flat_type)?; Ok(Self::ZeroArgumentThunk(layout)) } } @@ -960,7 +960,7 @@ impl<'a> Layout<'a> { let structure_content = env.subs.get_content_without_compacting(structure); Self::new_help(env, structure, *structure_content) } - Structure(flat_type) => layout_from_flat_type(env, var, flat_type), + Structure(flat_type) => layout_from_flat_type(env, flat_type), Alias(symbol, _args, actual_var, _) => { if let Some(int_width) = IntWidth::try_from_symbol(symbol) { @@ -1573,7 +1573,6 @@ impl<'a> Builtin<'a> { fn layout_from_flat_type<'a>( env: &mut Env<'a, '_>, - var: Variable, flat_type: FlatType, ) -> Result, LayoutProblem> { use roc_types::subs::FlatType::*; @@ -1776,7 +1775,6 @@ fn layout_from_flat_type<'a>( } } - env.insert_seen(var); env.insert_seen(rec_var); for (index, &(_name, variables)) in tags_vec.iter().enumerate() { if matches!(nullable, Some(i) if i == index as TagIdIntType) { @@ -1793,6 +1791,7 @@ fn layout_from_flat_type<'a>( continue; } + let content = subs.get_content_without_compacting(var); tag_layout.push(Layout::from_var(env, var)?); } @@ -1806,7 +1805,6 @@ fn layout_from_flat_type<'a>( tag_layouts.push(tag_layout.into_bump_slice()); } env.remove_seen(rec_var); - env.insert_seen(var); let union_layout = if let Some(tag_id) = nullable { match tag_layouts.into_bump_slice() { diff --git a/compiler/types/src/subs.rs b/compiler/types/src/subs.rs index a94cca1be6..256e1b7cef 100644 --- a/compiler/types/src/subs.rs +++ b/compiler/types/src/subs.rs @@ -1906,7 +1906,14 @@ impl Subs { } pub fn occurs(&self, var: Variable) -> Result<(), (Variable, Vec)> { - occurs(self, &[], var) + occurs(self, &[], var, false) + } + + pub fn occurs_including_recursion_vars( + &self, + var: Variable, + ) -> Result<(), (Variable, Vec)> { + occurs(self, &[], var, true) } pub fn mark_tag_union_recursive( @@ -2876,6 +2883,7 @@ fn occurs( subs: &Subs, seen: &[Variable], input_var: Variable, + include_recursion_var: bool, ) -> Result<(), (Variable, Vec)> { use self::Content::*; use self::FlatType::*; @@ -2899,47 +2907,77 @@ fn occurs( new_seen.push(root_var); match flat_type { - Apply(_, args) => { - short_circuit(subs, root_var, &new_seen, subs.get_subs_slice(*args).iter()) - } + Apply(_, args) => short_circuit( + subs, + root_var, + &new_seen, + subs.get_subs_slice(*args).iter(), + include_recursion_var, + ), Func(arg_vars, closure_var, ret_var) => { let it = once(ret_var) .chain(once(closure_var)) .chain(subs.get_subs_slice(*arg_vars).iter()); - short_circuit(subs, root_var, &new_seen, it) + short_circuit(subs, root_var, &new_seen, it, include_recursion_var) } Record(vars_by_field, ext_var) => { let slice = SubsSlice::new(vars_by_field.variables_start, vars_by_field.length); let it = once(ext_var).chain(subs.get_subs_slice(slice).iter()); - short_circuit(subs, root_var, &new_seen, it) + short_circuit(subs, root_var, &new_seen, it, include_recursion_var) } TagUnion(tags, ext_var) => { for slice_index in tags.variables() { let slice = subs[slice_index]; for var_index in slice { let var = subs[var_index]; - short_circuit_help(subs, root_var, &new_seen, var)?; + short_circuit_help( + subs, + root_var, + &new_seen, + var, + include_recursion_var, + )?; } } - short_circuit_help(subs, root_var, &new_seen, *ext_var) + short_circuit_help( + subs, + root_var, + &new_seen, + *ext_var, + include_recursion_var, + ) } FunctionOrTagUnion(_, _, ext_var) => { let it = once(ext_var); - short_circuit(subs, root_var, &new_seen, it) + short_circuit(subs, root_var, &new_seen, it, include_recursion_var) } - RecursiveTagUnion(_rec_var, tags, ext_var) => { - // TODO rec_var is excluded here, verify that this is correct + RecursiveTagUnion(rec_var, tags, ext_var) => { + if include_recursion_var { + new_seen.push(*rec_var); + } for slice_index in tags.variables() { let slice = subs[slice_index]; for var_index in slice { let var = subs[var_index]; - short_circuit_help(subs, root_var, &new_seen, var)?; + short_circuit_help( + subs, + root_var, + &new_seen, + var, + include_recursion_var, + )?; } } - short_circuit_help(subs, root_var, &new_seen, *ext_var) + short_circuit_help( + subs, + root_var, + &new_seen, + *ext_var, + include_recursion_var, + ) } EmptyRecord | EmptyTagUnion | Erroneous(_) => Ok(()), } @@ -2950,7 +2988,7 @@ fn occurs( for var_index in args.into_iter() { let var = subs[var_index]; - short_circuit_help(subs, root_var, &new_seen, var)?; + short_circuit_help(subs, root_var, &new_seen, var, include_recursion_var)?; } Ok(()) @@ -2959,7 +2997,7 @@ fn occurs( let mut new_seen = seen.to_owned(); new_seen.push(root_var); - short_circuit_help(subs, root_var, &new_seen, *typ)?; + short_circuit_help(subs, root_var, &new_seen, *typ, include_recursion_var)?; // _range_vars excluded because they are not explicitly part of the type. Ok(()) @@ -2974,12 +3012,13 @@ fn short_circuit<'a, T>( root_key: Variable, seen: &[Variable], iter: T, + include_recursion_var: bool, ) -> Result<(), (Variable, Vec)> where T: Iterator, { for var in iter { - short_circuit_help(subs, root_key, seen, *var)?; + short_circuit_help(subs, root_key, seen, *var, include_recursion_var)?; } Ok(()) @@ -2991,8 +3030,9 @@ fn short_circuit_help( root_key: Variable, seen: &[Variable], var: Variable, + include_recursion_var: bool, ) -> Result<(), (Variable, Vec)> { - if let Err((v, mut vec)) = occurs(subs, seen, var) { + if let Err((v, mut vec)) = occurs(subs, seen, var, include_recursion_var) { vec.push(root_key); return Err((v, vec)); } diff --git a/compiler/unify/src/unify.rs b/compiler/unify/src/unify.rs index 10738f6382..530db674c8 100644 --- a/compiler/unify/src/unify.rs +++ b/compiler/unify/src/unify.rs @@ -5,7 +5,8 @@ use roc_module::symbol::Symbol; use roc_types::subs::Content::{self, *}; use roc_types::subs::{ AliasVariables, Descriptor, ErrorTypeContext, FlatType, GetSubsSlice, Mark, OptVariable, - RecordFields, Subs, SubsIndex, SubsSlice, UnionTags, Variable, VariableSubsSlice, + RecordFields, Subs, SubsFmtContent, SubsIndex, SubsSlice, UnionTags, Variable, + VariableSubsSlice, }; use roc_types::types::{AliasKind, DoesNotImplementAbility, ErrorType, Mismatch, RecordField}; @@ -316,10 +317,10 @@ fn debug_print_unified_types(subs: &mut Subs, ctx: &Context, opt_outcome: Option ctx.first, ctx.second, ctx.first, - roc_types::subs::SubsFmtContent(&content_1, subs), + SubsFmtContent(&content_1, subs), mode, ctx.second, - roc_types::subs::SubsFmtContent(&content_2, subs), + SubsFmtContent(&content_2, subs), ); unsafe { UNIFICATION_DEPTH = new_depth }; @@ -576,7 +577,13 @@ fn unify_structure( RecursionVar { structure, .. } => match flat_type { FlatType::TagUnion(_, _) => { // unify the structure with this unrecursive tag union - unify_pool(subs, pool, ctx.first, *structure, ctx.mode) + let mut problems = unify_pool(subs, pool, ctx.first, *structure, ctx.mode); + + problems.extend(fix_tag_union_recursion_variable( + subs, ctx, ctx.first, other, + )); + + problems } FlatType::RecursiveTagUnion(rec, _, _) => { debug_assert!(is_recursion_var(subs, *rec)); @@ -585,7 +592,13 @@ fn unify_structure( } FlatType::FunctionOrTagUnion(_, _, _) => { // unify the structure with this unrecursive tag union - unify_pool(subs, pool, ctx.first, *structure, ctx.mode) + let mut problems = unify_pool(subs, pool, ctx.first, *structure, ctx.mode); + + problems.extend(fix_tag_union_recursion_variable( + subs, ctx, ctx.first, other, + )); + + problems } // Only tag unions can be recursive; everything else is an error. _ => mismatch!( @@ -643,6 +656,59 @@ fn unify_structure( } } +/// Ensures that a non-recursive tag union, when unified with a recursion var to become a recursive +/// tag union, properly contains a recursion variable that recurses on itself. +// +// When might this not be the case? For example, in the code +// +// Indirect : [ Indirect ConsList ] +// +// ConsList : [ Nil, Cons Indirect ] +// +// l : ConsList +// l = Cons (Indirect (Cons (Indirect Nil))) +// # ^^^^^^^^^^^^^^^~~~~~~~~~~~~~~~~~~~~~^ region-a +// # ~~~~~~~~~~~~~~~~~~~~~ region-b +// l +// +// Suppose `ConsList` has the expanded type `[ Nil, Cons [ Indirect ] ] as `. +// After unifying the tag application annotated "region-b" with the recursion variable ``, +// the tentative total-type of the application annotated "region-a" would be +// ` = [ Nil, Cons [ Indirect ] ] as `. That is, the type of the recursive tag union +// would be inlined at the site "v", rather than passing through the correct recursion variable +// "rec" first. +// +// This is not incorrect from a type perspective, but causes problems later on for e.g. layout +// determination, which expects recursion variables to be placed correctly. Attempting to detect +// this during layout generation does not work so well because it may be that there *are* recursive +// tag unions that should be inlined, and not pass through recursion variables. So instead, try to +// resolve these cases here. +// +// See tests labeled "issue_2810" for more examples. +fn fix_tag_union_recursion_variable( + subs: &mut Subs, + ctx: &Context, + tag_union_promoted_to_recursive: Variable, + recursion_var: &Content, +) -> Outcome { + debug_assert!(matches!( + subs.get_content_without_compacting(tag_union_promoted_to_recursive), + Structure(FlatType::RecursiveTagUnion(..)) + )); + + let f = subs.get_content_without_compacting(tag_union_promoted_to_recursive); + + let has_recursing_recursive_variable = subs + .occurs_including_recursion_vars(tag_union_promoted_to_recursive) + .is_err(); + + if !has_recursing_recursive_variable { + merge(subs, ctx, recursion_var.clone()) + } else { + vec![] + } +} + fn unify_record( subs: &mut Subs, pool: &mut Pool, From 3906c5c2003ba07c8bb0752fc3da47df85e9b37e Mon Sep 17 00:00:00 2001 From: Ayaz <20735482+ayazhafiz@users.noreply.github.com> Date: Fri, 8 Apr 2022 17:31:41 -0400 Subject: [PATCH 429/846] Clippy --- compiler/unify/src/unify.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/compiler/unify/src/unify.rs b/compiler/unify/src/unify.rs index 530db674c8..407974fc4d 100644 --- a/compiler/unify/src/unify.rs +++ b/compiler/unify/src/unify.rs @@ -696,14 +696,12 @@ fn fix_tag_union_recursion_variable( Structure(FlatType::RecursiveTagUnion(..)) )); - let f = subs.get_content_without_compacting(tag_union_promoted_to_recursive); - let has_recursing_recursive_variable = subs .occurs_including_recursion_vars(tag_union_promoted_to_recursive) .is_err(); if !has_recursing_recursive_variable { - merge(subs, ctx, recursion_var.clone()) + merge(subs, ctx, *recursion_var) } else { vec![] } From 5dfe44c72d4c317077708ecd4b5a634559760e70 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 8 Apr 2022 17:56:04 -0400 Subject: [PATCH 430/846] Render nullable wrapped tag unions that pass through aliases --- compiler/mono/src/layout.rs | 50 +++++++++++++++-- repl_eval/src/eval.rs | 104 +++++++++++++++++++++--------------- repl_test/src/tests.rs | 19 +++++++ 3 files changed, 128 insertions(+), 45 deletions(-) diff --git a/compiler/mono/src/layout.rs b/compiler/mono/src/layout.rs index 58fe798d23..77d6a2bc30 100644 --- a/compiler/mono/src/layout.rs +++ b/compiler/mono/src/layout.rs @@ -196,7 +196,7 @@ impl<'a> RawFunctionLayout<'a> { Self::from_var(env, var) } _ => { - let layout = layout_from_flat_type(env, flat_type)?; + let layout = layout_from_flat_type(env, var, flat_type)?; Ok(Self::ZeroArgumentThunk(layout)) } } @@ -312,6 +312,50 @@ impl<'a> UnionLayout<'a> { .append(alloc.intersperse(tags_doc, ", ")) .append(alloc.text("]")) } + Recursive(tags) => { + let tags_doc = tags.iter().map(|fields| { + alloc.text("C ").append(alloc.intersperse( + fields.iter().map(|x| x.to_doc(alloc, Parens::InTypeParam)), + " ", + )) + }); + alloc + .text("[") + .append(alloc.intersperse(tags_doc, ", ")) + .append(alloc.text("]")) + } + NonNullableUnwrapped(fields) => { + let fields_doc = alloc.text("C ").append(alloc.intersperse( + fields.iter().map(|x| x.to_doc(alloc, Parens::InTypeParam)), + " ", + )); + alloc + .text("[") + .append(fields_doc) + .append(alloc.text("]")) + } + NullableUnwrapped { + nullable_id, + other_fields, + } => { + let fields_doc = alloc.text("C ").append( + alloc.intersperse( + other_fields + .iter() + .map(|x| x.to_doc(alloc, Parens::InTypeParam)), + " ", + ), + ); + let tags_doc = if nullable_id { + alloc.concat(vec![alloc.text(", "), fields_doc]) + } else { + alloc.concat(vec![fields_doc, alloc.text(", ")]) + }; + alloc + .text("[") + .append(tags_doc) + .append(alloc.text("]")) + } _ => alloc.text("TODO"), } } @@ -960,7 +1004,7 @@ impl<'a> Layout<'a> { let structure_content = env.subs.get_content_without_compacting(structure); Self::new_help(env, structure, *structure_content) } - Structure(flat_type) => layout_from_flat_type(env, flat_type), + Structure(flat_type) => layout_from_flat_type(env, var, flat_type), Alias(symbol, _args, actual_var, _) => { if let Some(int_width) = IntWidth::try_from_symbol(symbol) { @@ -1573,6 +1617,7 @@ impl<'a> Builtin<'a> { fn layout_from_flat_type<'a>( env: &mut Env<'a, '_>, + _var: Variable, flat_type: FlatType, ) -> Result, LayoutProblem> { use roc_types::subs::FlatType::*; @@ -1791,7 +1836,6 @@ fn layout_from_flat_type<'a>( continue; } - let content = subs.get_content_without_compacting(var); tag_layout.push(Layout::from_var(env, var)?); } diff --git a/repl_eval/src/eval.rs b/repl_eval/src/eval.rs index bc718a7c6c..b1825c7288 100644 --- a/repl_eval/src/eval.rs +++ b/repl_eval/src/eval.rs @@ -86,12 +86,17 @@ enum NewtypeKind<'a> { /// /// The returned list of newtype containers is ordered by increasing depth. As an example, /// `A ({b : C 123})` will have the unrolled list `[Tag(A), RecordField(b), Tag(C)]`. -fn unroll_newtypes<'a>( +/// +/// If we pass through aliases, the top-level alias that should be displayed to the user is passed +/// back as an option. +/// +/// Returns (new type containers, optional alias content, real content). +fn unroll_newtypes_and_aliases<'a>( env: &Env<'a, 'a>, mut content: &'a Content, -) -> (Vec<'a, NewtypeKind<'a>>, &'a Content) { +) -> (Vec<'a, NewtypeKind<'a>>, Option<&'a Content>, &'a Content) { let mut newtype_containers = Vec::with_capacity_in(1, env.arena); - let mut force_alias_content = None; + let mut alias_content = None; loop { match content { Content::Structure(FlatType::TagUnion(tags, _)) @@ -118,18 +123,19 @@ fn unroll_newtypes<'a>( } Content::Alias(_, _, real_var, _) => { // We need to pass through aliases too, because their underlying types may have - // unrolled newtypes. In such cases return the list of unrolled newtypes, but keep - // the content as the alias for readability. For example, + // unrolled newtypes. For example, // T : { a : Str } // v : T // v = { a : "value" } // v - // Here we need the newtype container to be `[RecordField(a)]`, but the content to - // remain as the alias `T`. - force_alias_content = Some(content); + // Here we need the newtype container to be `[RecordField(a)]`. + // + // At the end of the day what we should show to the user is the alias content, not + // what's inside, so keep that around too. + alias_content = Some(content); content = env.subs.get_content_without_compacting(*real_var); } - _ => return (newtype_containers, force_alias_content.unwrap_or(content)), + _ => return (newtype_containers, alias_content, content), } } } @@ -140,8 +146,8 @@ fn apply_newtypes<'a>( mut expr: Expr<'a>, ) -> Expr<'a> { let arena = env.arena; - // Reverse order of what we receieve from `unroll_newtypes` since we want the deepest - // container applied first. + // Reverse order of what we receieve from `unroll_newtypes_and_aliases` since + // we want the deepest container applied first. for container in newtype_containers.into_iter().rev() { match container { NewtypeKind::Tag(tag_name) => { @@ -162,13 +168,6 @@ fn apply_newtypes<'a>( expr } -fn unroll_aliases<'a>(env: &Env<'a, 'a>, mut content: &'a Content) -> &'a Content { - while let Content::Alias(_, _, real, _) = content { - content = env.subs.get_content_without_compacting(*real); - } - content -} - fn unroll_recursion_var<'a>(env: &Env<'a, 'a>, mut content: &'a Content) -> &'a Content { while let Content::RecursionVar { structure, .. } = content { content = env.subs.get_content_without_compacting(*structure); @@ -278,13 +277,18 @@ fn jit_to_ast_help<'a, A: ReplApp<'a>>( layout: &Layout<'a>, content: &'a Content, ) -> Result, ToAstProblem> { - let (newtype_containers, content) = unroll_newtypes(env, content); - let content = unroll_aliases(env, content); + let (newtype_containers, alias_content, raw_content) = + unroll_newtypes_and_aliases(env, content); macro_rules! num_helper { ($ty:ty) => { app.call_function(main_fn_name, |_, num: $ty| { - num_to_ast(env, number_literal_to_ast(env.arena, num), content) + num_to_ast( + env, + number_literal_to_ast(env.arena, num), + // We determine the number from what the alias looks like. + alias_content.unwrap_or(raw_content), + ) }) }; } @@ -292,17 +296,17 @@ fn jit_to_ast_help<'a, A: ReplApp<'a>>( let result = match layout { Layout::Builtin(Builtin::Bool) => Ok(app .call_function(main_fn_name, |mem: &A::Memory, num: bool| { - bool_to_ast(env, mem, num, content) + bool_to_ast(env, mem, num, raw_content) })), Layout::Builtin(Builtin::Int(int_width)) => { use IntWidth::*; - let result = match (content, int_width) { + let result = match (raw_content, int_width) { (Content::Structure(FlatType::Apply(Symbol::NUM_NUM, _)), U8) => num_helper!(u8), (_, U8) => { // This is not a number, it's a tag union or something else app.call_function(main_fn_name, |mem: &A::Memory, num: u8| { - byte_to_ast(env, mem, num, content) + byte_to_ast(env, mem, num, raw_content) }) } // The rest are numbers... for now @@ -344,14 +348,14 @@ fn jit_to_ast_help<'a, A: ReplApp<'a>>( Layout::Builtin(Builtin::List(elem_layout)) => Ok(app.call_function( main_fn_name, |mem: &A::Memory, (addr, len): (usize, usize)| { - list_to_ast(env, mem, addr, len, elem_layout, content) + list_to_ast(env, mem, addr, len, elem_layout, raw_content) }, )), Layout::Builtin(other) => { todo!("add support for rendering builtin {:?} to the REPL", other) } Layout::Struct { field_layouts, .. } => { - let struct_addr_to_ast = |mem: &'a A::Memory, addr: usize| match content { + let struct_addr_to_ast = |mem: &'a A::Memory, addr: usize| match raw_content { Content::Structure(FlatType::Record(fields, _)) => { Ok(struct_to_ast(env, mem, addr, *fields)) } @@ -413,7 +417,14 @@ fn jit_to_ast_help<'a, A: ReplApp<'a>>( main_fn_name, size as usize, |mem: &'a A::Memory, addr: usize| { - addr_to_ast(env, mem, addr, layout, WhenRecursive::Unreachable, content) + addr_to_ast( + env, + mem, + addr, + layout, + WhenRecursive::Unreachable, + raw_content, + ) }, )) } @@ -432,7 +443,7 @@ fn jit_to_ast_help<'a, A: ReplApp<'a>>( addr, layout, WhenRecursive::Loop(*layout), - content, + raw_content, ) }, )) @@ -447,7 +458,14 @@ fn jit_to_ast_help<'a, A: ReplApp<'a>>( main_fn_name, size as usize, |mem: &A::Memory, addr| { - addr_to_ast(env, mem, addr, layout, WhenRecursive::Unreachable, content) + addr_to_ast( + env, + mem, + addr, + layout, + WhenRecursive::Unreachable, + raw_content, + ) }, )) } @@ -493,9 +511,10 @@ fn addr_to_ast<'a, M: ReplAppMemory>( }}; } - let (newtype_containers, content) = unroll_newtypes(env, content); - let content = unroll_aliases(env, content); - let expr = match (content, layout) { + let (newtype_containers, _alias_content, raw_content) = + unroll_newtypes_and_aliases(env, content); + + let expr = match (raw_content, layout) { (Content::Structure(FlatType::Func(_, _, _)), _) | (_, Layout::LambdaSet(_)) => OPAQUE_FUNCTION, (_, Layout::Builtin(Builtin::Bool)) => { @@ -503,7 +522,7 @@ fn addr_to_ast<'a, M: ReplAppMemory>( // num is always false at the moment. let num: bool = mem.deref_bool(addr); - bool_to_ast(env, mem, num, content) + bool_to_ast(env, mem, num, raw_content) } (_, Layout::Builtin(Builtin::Int(int_width))) => { use IntWidth::*; @@ -534,14 +553,14 @@ fn addr_to_ast<'a, M: ReplAppMemory>( let elem_addr = mem.deref_usize(addr); let len = mem.deref_usize(addr + env.target_info.ptr_width() as usize); - list_to_ast(env, mem, elem_addr, len, elem_layout, content) + list_to_ast(env, mem, elem_addr, len, elem_layout, raw_content) } (_, Layout::Builtin(Builtin::Str)) => { let string = mem.deref_str(addr); let arena_str = env.arena.alloc_str(string); Expr::Str(StrLiteral::PlainLine(arena_str)) } - (_, Layout::Struct{field_layouts, ..}) => match content { + (_, Layout::Struct{field_layouts, ..}) => match raw_content { Content::Structure(FlatType::Record(fields, _)) => { struct_to_ast(env, mem, addr, *fields) } @@ -566,7 +585,7 @@ fn addr_to_ast<'a, M: ReplAppMemory>( } }, (_, Layout::RecursivePointer) => { - match (content, when_recursive) { + match (raw_content, when_recursive) { (Content::RecursionVar { structure, opt_name: _, @@ -580,7 +599,7 @@ fn addr_to_ast<'a, M: ReplAppMemory>( (_, Layout::Union(UnionLayout::NonRecursive(union_layouts))) => { let union_layout = UnionLayout::NonRecursive(union_layouts); - let tags = match content { + let tags = match raw_content { Content::Structure(FlatType::TagUnion(tags, _)) => tags, other => unreachable!("Weird content for nonrecursive Union layout: {:?}", other), }; @@ -614,7 +633,7 @@ fn addr_to_ast<'a, M: ReplAppMemory>( ) } (_, Layout::Union(union_layout @ UnionLayout::Recursive(union_layouts))) => { - let (rec_var, tags) = match content { + let (rec_var, tags) = match raw_content { Content::Structure(FlatType::RecursiveTagUnion(rec_var, tags, _)) => (rec_var, tags), _ => unreachable!("any other content would have a different layout"), }; @@ -644,7 +663,7 @@ fn addr_to_ast<'a, M: ReplAppMemory>( ) } (_, Layout::Union(UnionLayout::NonNullableUnwrapped(_))) => { - let (rec_var, tags) = match unroll_recursion_var(env, content) { + let (rec_var, tags) = match unroll_recursion_var(env, raw_content) { Content::Structure(FlatType::RecursiveTagUnion(rec_var, tags, _)) => (rec_var, tags), other => unreachable!("Unexpected content for NonNullableUnwrapped: {:?}", other), }; @@ -672,7 +691,7 @@ fn addr_to_ast<'a, M: ReplAppMemory>( ) } (_, Layout::Union(UnionLayout::NullableUnwrapped { .. })) => { - let (rec_var, tags) = match unroll_recursion_var(env, content) { + let (rec_var, tags) = match unroll_recursion_var(env, raw_content) { Content::Structure(FlatType::RecursiveTagUnion(rec_var, tags, _)) => (rec_var, tags), other => unreachable!("Unexpected content for NonNullableUnwrapped: {:?}", other), }; @@ -706,7 +725,7 @@ fn addr_to_ast<'a, M: ReplAppMemory>( } } (_, Layout::Union(union_layout @ UnionLayout::NullableWrapped { .. })) => { - let (rec_var, tags) = match unroll_recursion_var(env, content) { + let (rec_var, tags) = match unroll_recursion_var(env, raw_content) { Content::Structure(FlatType::RecursiveTagUnion(rec_var, tags, _)) => (rec_var, tags), other => unreachable!("Unexpected content for NonNullableUnwrapped: {:?}", other), }; @@ -803,7 +822,8 @@ fn list_to_ast<'a, M: ReplAppMemory>( for index in 0..len { let offset_bytes = index * elem_size; let elem_addr = addr + offset_bytes; - let (newtype_containers, elem_content) = unroll_newtypes(env, elem_content); + let (newtype_containers, _alias_content, elem_content) = + unroll_newtypes_and_aliases(env, elem_content); let expr = addr_to_ast( env, mem, diff --git a/repl_test/src/tests.rs b/repl_test/src/tests.rs index fe2b90d2ea..17e3418d3c 100644 --- a/repl_test/src/tests.rs +++ b/repl_test/src/tests.rs @@ -1158,3 +1158,22 @@ fn issue_2810_recursive_layout_inside_nonrecursive() { "Job (Command (FromJob (Job (Command SystemTool)))) : Job", ) } + +#[test] +fn render_nullable_unwrapped_passing_through_alias() { + expect_success( + indoc!( + r#" + Deep : [ L DeepList ] + + DeepList : [ Nil, Cons Deep ] + + v : DeepList + v = (Cons (L (Cons (L (Cons (L Nil)))))) + + v + "# + ), + "Cons (L (Cons (L (Cons (L Nil))))) : DeepList", + ) +} From 1e1ffb2f626d43cb934dd5780c4cab9e0d67c810 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Sat, 9 Apr 2022 18:09:48 -0400 Subject: [PATCH 431/846] Bugfix use root var --- compiler/types/src/subs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/types/src/subs.rs b/compiler/types/src/subs.rs index 256e1b7cef..a909fde93d 100644 --- a/compiler/types/src/subs.rs +++ b/compiler/types/src/subs.rs @@ -2955,7 +2955,7 @@ fn occurs( } RecursiveTagUnion(rec_var, tags, ext_var) => { if include_recursion_var { - new_seen.push(*rec_var); + new_seen.push(subs.get_root_key_without_compacting(*rec_var)); } for slice_index in tags.variables() { let slice = subs[slice_index]; From 939f4135692442714952cdd5fbd3c7951bf225fe Mon Sep 17 00:00:00 2001 From: ayazhafiz Date: Sat, 9 Apr 2022 22:42:51 -0400 Subject: [PATCH 432/846] Don't try to fix recursion vars if there are other errors --- compiler/unify/src/unify.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/compiler/unify/src/unify.rs b/compiler/unify/src/unify.rs index 407974fc4d..0c8f8562a5 100644 --- a/compiler/unify/src/unify.rs +++ b/compiler/unify/src/unify.rs @@ -579,9 +579,11 @@ fn unify_structure( // unify the structure with this unrecursive tag union let mut problems = unify_pool(subs, pool, ctx.first, *structure, ctx.mode); - problems.extend(fix_tag_union_recursion_variable( - subs, ctx, ctx.first, other, - )); + if problems.is_empty() { + problems.extend(fix_tag_union_recursion_variable( + subs, ctx, ctx.first, other, + )); + } problems } @@ -594,9 +596,11 @@ fn unify_structure( // unify the structure with this unrecursive tag union let mut problems = unify_pool(subs, pool, ctx.first, *structure, ctx.mode); - problems.extend(fix_tag_union_recursion_variable( - subs, ctx, ctx.first, other, - )); + if problems.is_empty() { + problems.extend(fix_tag_union_recursion_variable( + subs, ctx, ctx.first, other, + )); + } problems } From bb06bcd7f1ffcab75e034570d918cf048463181c Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 21 Apr 2022 10:26:16 -0400 Subject: [PATCH 433/846] Fix compile error --- compiler/unify/src/unify.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/compiler/unify/src/unify.rs b/compiler/unify/src/unify.rs index 0c8f8562a5..88bf2456ca 100644 --- a/compiler/unify/src/unify.rs +++ b/compiler/unify/src/unify.rs @@ -577,15 +577,15 @@ fn unify_structure( RecursionVar { structure, .. } => match flat_type { FlatType::TagUnion(_, _) => { // unify the structure with this unrecursive tag union - let mut problems = unify_pool(subs, pool, ctx.first, *structure, ctx.mode); + let mut outcome = unify_pool(subs, pool, ctx.first, *structure, ctx.mode); - if problems.is_empty() { - problems.extend(fix_tag_union_recursion_variable( + if outcome.mismatches.is_empty() { + outcome.union(fix_tag_union_recursion_variable( subs, ctx, ctx.first, other, )); } - problems + outcome } FlatType::RecursiveTagUnion(rec, _, _) => { debug_assert!(is_recursion_var(subs, *rec)); @@ -594,15 +594,15 @@ fn unify_structure( } FlatType::FunctionOrTagUnion(_, _, _) => { // unify the structure with this unrecursive tag union - let mut problems = unify_pool(subs, pool, ctx.first, *structure, ctx.mode); + let mut outcome = unify_pool(subs, pool, ctx.first, *structure, ctx.mode); - if problems.is_empty() { - problems.extend(fix_tag_union_recursion_variable( + if outcome.mismatches.is_empty() { + outcome.union(fix_tag_union_recursion_variable( subs, ctx, ctx.first, other, )); } - problems + outcome } // Only tag unions can be recursive; everything else is an error. _ => mismatch!( @@ -707,7 +707,7 @@ fn fix_tag_union_recursion_variable( if !has_recursing_recursive_variable { merge(subs, ctx, *recursion_var) } else { - vec![] + Outcome::default() } } From 3eb7824c7afdf52ef242a4e717ca72f00c255cab Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 22 Apr 2022 17:56:54 -0400 Subject: [PATCH 434/846] Typos --- compiler/mono/src/layout.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/compiler/mono/src/layout.rs b/compiler/mono/src/layout.rs index 77d6a2bc30..fd764f069d 100644 --- a/compiler/mono/src/layout.rs +++ b/compiler/mono/src/layout.rs @@ -78,7 +78,7 @@ impl<'a> RawFunctionLayout<'a> { let structure_content = env.subs.get_content_without_compacting(structure); Self::new_help(env, structure, *structure_content) } - Structure(flat_type) => Self::layout_from_flat_type(env, var, flat_type), + Structure(flat_type) => Self::layout_from_flat_type(env, flat_type), RangedNumber(typ, _) => Self::from_var(env, typ), // Ints @@ -152,7 +152,6 @@ impl<'a> RawFunctionLayout<'a> { fn layout_from_flat_type( env: &mut Env<'a, '_>, - var: Variable, flat_type: FlatType, ) -> Result { use roc_types::subs::FlatType::*; @@ -196,7 +195,7 @@ impl<'a> RawFunctionLayout<'a> { Self::from_var(env, var) } _ => { - let layout = layout_from_flat_type(env, var, flat_type)?; + let layout = layout_from_flat_type(env, flat_type)?; Ok(Self::ZeroArgumentThunk(layout)) } } @@ -1004,7 +1003,7 @@ impl<'a> Layout<'a> { let structure_content = env.subs.get_content_without_compacting(structure); Self::new_help(env, structure, *structure_content) } - Structure(flat_type) => layout_from_flat_type(env, var, flat_type), + Structure(flat_type) => layout_from_flat_type(env, flat_type), Alias(symbol, _args, actual_var, _) => { if let Some(int_width) = IntWidth::try_from_symbol(symbol) { @@ -1342,8 +1341,6 @@ impl<'a> LayoutCache<'a> { target_info: self.target_info, }; - //if true {panic!()} - Layout::from_var(&mut env, var) } @@ -1617,7 +1614,6 @@ impl<'a> Builtin<'a> { fn layout_from_flat_type<'a>( env: &mut Env<'a, '_>, - _var: Variable, flat_type: FlatType, ) -> Result, LayoutProblem> { use roc_types::subs::FlatType::*; From 890bec1b0cb147881865c601c12e4d9fcfab46ab Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 23 Apr 2022 13:17:58 +0200 Subject: [PATCH 435/846] refactor --- compiler/can/src/def.rs | 209 ++++++++++++++++++++++------------------ 1 file changed, 115 insertions(+), 94 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 4d764d337e..850bd2bb7e 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -440,18 +440,130 @@ pub fn canonicalize_defs<'a>( ); } - // Now we can go through and resolve all pending abilities, to add them to scope. + // Resolve all pending abilities, to add them to scope. + resolve_abilities( + env, + &mut output, + var_store, + &mut scope, + abilities, + &abilities_in_scope, + pattern_type, + ); + + // Now that we have the scope completely assembled, and shadowing resolved, + // we're ready to canonicalize any body exprs. + + // Canonicalize all the patterns, record shadowing problems, and store + // the ast::Expr values in pending_exprs for further canonicalization + // once we've finished assembling the entire scope. + let mut pending_value_defs = Vec::with_capacity(value_defs.len()); + for loc_def in value_defs.into_iter() { + let mut new_output = Output::default(); + match to_pending_value_def( + env, + var_store, + loc_def.value, + &mut scope, + &mut new_output, + pattern_type, + ) { + None => { /* skip */ } + Some(pending_def) => { + // store the top-level defs, used to ensure that closures won't capture them + if let PatternType::TopLevelDef = pattern_type { + match &pending_def { + PendingValueDef::AnnotationOnly(_, loc_can_pattern, _) + | PendingValueDef::Body(_, loc_can_pattern, _) + | PendingValueDef::TypedBody(_, loc_can_pattern, _, _) => { + env.top_level_symbols.extend( + bindings_from_patterns(std::iter::once(loc_can_pattern)) + .iter() + .map(|t| t.0), + ) + } + } + } + // Record the ast::Expr for later. We'll do another pass through these + // once we have the entire scope assembled. If we were to canonicalize + // the exprs right now, they wouldn't have symbols in scope from defs + // that get would have gotten added later in the defs list! + pending_value_defs.push(pending_def); + output.union(new_output); + } + } + } + + for pending_def in pending_value_defs.into_iter() { + output = canonicalize_pending_value_def( + env, + pending_def, + output, + &mut scope, + &mut can_defs_by_symbol, + var_store, + &mut refs_by_symbol, + &mut aliases, + &abilities_in_scope, + ); + + // TODO we should do something with these references; they include + // things like type annotations. + } + + // Determine which idents we introduced in the course of this process. + let mut symbols_introduced = MutMap::default(); + + for (symbol, region) in scope.symbols() { + if !original_scope.contains_symbol(*symbol) { + symbols_introduced.insert(*symbol, *region); + } + } + + // This returns both the defs info as well as the new scope. + // + // We have to return the new scope because we added defs to it + // (and those lookups shouldn't fail later, e.g. when canonicalizing + // the return expr), but we didn't want to mutate the original scope + // directly because we wanted to keep a clone of it around to diff + // when looking for unused idents. + // + // We have to return the scope separately from the defs, because the + // defs need to get moved later. + ( + CanDefs { + refs_by_symbol, + can_defs_by_symbol, + // The result needs a thread-safe `SendMap` + aliases: aliases.into_iter().collect(), + }, + scope, + output, + symbols_introduced, + ) +} + +/// Resolve all pending abilities, to add them to scope. +fn resolve_abilities<'a>( + env: &mut Env<'a>, + output: &mut Output, + var_store: &mut VarStore, + scope: &mut Scope, + abilities: MutMap, &[AbilityMember])>, + abilities_in_scope: &[Symbol], + pattern_type: PatternType, +) { for (loc_ability_name, members) in abilities.into_values() { let mut can_members = Vec::with_capacity(members.len()); for member in members { let member_annot = canonicalize_annotation( env, - &mut scope, + scope, &member.typ.value, member.typ.region, var_store, - &abilities_in_scope, + abilities_in_scope, ); // Record all the annotation's references in output.references.lookups @@ -570,97 +682,6 @@ pub fn canonicalize_defs<'a>( .abilities_store .register_ability(loc_ability_name.value, can_members); } - - // Now that we have the scope completely assembled, and shadowing resolved, - // we're ready to canonicalize any body exprs. - - // Canonicalize all the patterns, record shadowing problems, and store - // the ast::Expr values in pending_exprs for further canonicalization - // once we've finished assembling the entire scope. - let mut pending_value_defs = Vec::with_capacity(value_defs.len()); - for loc_def in value_defs.into_iter() { - let mut new_output = Output::default(); - match to_pending_value_def( - env, - var_store, - loc_def.value, - &mut scope, - &mut new_output, - pattern_type, - ) { - None => { /* skip */ } - Some(pending_def) => { - // store the top-level defs, used to ensure that closures won't capture them - if let PatternType::TopLevelDef = pattern_type { - match &pending_def { - PendingValueDef::AnnotationOnly(_, loc_can_pattern, _) - | PendingValueDef::Body(_, loc_can_pattern, _) - | PendingValueDef::TypedBody(_, loc_can_pattern, _, _) => { - env.top_level_symbols.extend( - bindings_from_patterns(std::iter::once(loc_can_pattern)) - .iter() - .map(|t| t.0), - ) - } - } - } - // Record the ast::Expr for later. We'll do another pass through these - // once we have the entire scope assembled. If we were to canonicalize - // the exprs right now, they wouldn't have symbols in scope from defs - // that get would have gotten added later in the defs list! - pending_value_defs.push(pending_def); - output.union(new_output); - } - } - } - - for pending_def in pending_value_defs.into_iter() { - output = canonicalize_pending_value_def( - env, - pending_def, - output, - &mut scope, - &mut can_defs_by_symbol, - var_store, - &mut refs_by_symbol, - &mut aliases, - &abilities_in_scope, - ); - - // TODO we should do something with these references; they include - // things like type annotations. - } - - // Determine which idents we introduced in the course of this process. - let mut symbols_introduced = MutMap::default(); - - for (symbol, region) in scope.symbols() { - if !original_scope.contains_symbol(*symbol) { - symbols_introduced.insert(*symbol, *region); - } - } - - // This returns both the defs info as well as the new scope. - // - // We have to return the new scope because we added defs to it - // (and those lookups shouldn't fail later, e.g. when canonicalizing - // the return expr), but we didn't want to mutate the original scope - // directly because we wanted to keep a clone of it around to diff - // when looking for unused idents. - // - // We have to return the scope separately from the defs, because the - // defs need to get moved later. - ( - CanDefs { - refs_by_symbol, - can_defs_by_symbol, - // The result needs a thread-safe `SendMap` - aliases: aliases.into_iter().collect(), - }, - scope, - output, - symbols_introduced, - ) } #[derive(Debug)] From c396ad670523bde7563178c0cf1f819e204c8345 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 23 Apr 2022 13:36:47 +0200 Subject: [PATCH 436/846] set up a def order (unpopulated for now) --- compiler/can/src/def.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 850bd2bb7e..5b57ad4a74 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -82,6 +82,16 @@ enum PendingValueDef<'a> { ), } +impl PendingValueDef<'_> { + fn loc_pattern(&self) -> &Loc { + match self { + PendingValueDef::AnnotationOnly(_, loc_pattern, _) => loc_pattern, + PendingValueDef::Body(_, loc_pattern, _) => loc_pattern, + PendingValueDef::TypedBody(_, loc_pattern, _, _) => loc_pattern, + } + } +} + #[derive(Debug, Clone)] enum PendingTypeDef<'a> { /// A structural or opaque type alias, e.g. `Ints : List Int` or `Age := U32` respectively. @@ -494,6 +504,23 @@ pub fn canonicalize_defs<'a>( } } + let mut symbol_to_id: Vec<(IdentId, u32)> = Vec::with_capacity(pending_value_defs.len()); + + let mut def_count = 0; + for pending_def in pending_value_defs.iter() { + let pattern = &pending_def.loc_pattern().value; + + for s in crate::pattern::symbols_from_pattern(pattern) { + debug_assert_eq!(env.home, s.module_id()); + debug_assert!(!symbol_to_id.iter().any(|(id, _)| *id == s.ident_id())); + + symbol_to_id.push((s.ident_id(), def_count)); + def_count += 1; + } + } + + let mut def_order = DefOrdering::from_symbol_to_id(env.home, symbol_to_id); + for pending_def in pending_value_defs.into_iter() { output = canonicalize_pending_value_def( env, @@ -710,6 +737,18 @@ impl DefOrdering { } } + fn from_symbol_to_id(home: ModuleId, symbol_to_id: Vec<(IdentId, u32)>) -> Self { + let capacity = symbol_to_id.len(); + + Self { + home, + symbol_to_id, + references: ReferenceMatrix::new(capacity), + direct_references: ReferenceMatrix::new(capacity), + length: capacity as u32, + } + } + fn from_defs_by_symbol( env: &Env, can_defs_by_symbol: &MutMap, From 2037133882666332816ace187ad27509627e689d Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 23 Apr 2022 13:49:14 +0200 Subject: [PATCH 437/846] refactor how global defs are registered --- compiler/can/src/def.rs | 37 ++++++++++++------------------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 5b57ad4a74..188f97426c 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -480,20 +480,6 @@ pub fn canonicalize_defs<'a>( ) { None => { /* skip */ } Some(pending_def) => { - // store the top-level defs, used to ensure that closures won't capture them - if let PatternType::TopLevelDef = pattern_type { - match &pending_def { - PendingValueDef::AnnotationOnly(_, loc_can_pattern, _) - | PendingValueDef::Body(_, loc_can_pattern, _) - | PendingValueDef::TypedBody(_, loc_can_pattern, _, _) => { - env.top_level_symbols.extend( - bindings_from_patterns(std::iter::once(loc_can_pattern)) - .iter() - .map(|t| t.0), - ) - } - } - } // Record the ast::Expr for later. We'll do another pass through these // once we have the entire scope assembled. If we were to canonicalize // the exprs right now, they wouldn't have symbols in scope from defs @@ -504,19 +490,20 @@ pub fn canonicalize_defs<'a>( } } + // the bindings by all defs in the current block + let bindings = bindings_from_patterns(pending_value_defs.iter().map(|p| p.loc_pattern())); + let mut symbol_to_id: Vec<(IdentId, u32)> = Vec::with_capacity(pending_value_defs.len()); - - let mut def_count = 0; - for pending_def in pending_value_defs.iter() { - let pattern = &pending_def.loc_pattern().value; - - for s in crate::pattern::symbols_from_pattern(pattern) { - debug_assert_eq!(env.home, s.module_id()); - debug_assert!(!symbol_to_id.iter().any(|(id, _)| *id == s.ident_id())); - - symbol_to_id.push((s.ident_id(), def_count)); - def_count += 1; + for (binding_index, (s, _)) in bindings.into_iter().enumerate() { + // store the top-level defs, used to ensure that closures won't capture them + if let PatternType::TopLevelDef = pattern_type { + env.top_level_symbols.insert(s); } + + debug_assert_eq!(env.home, s.module_id()); + debug_assert!(!symbol_to_id.iter().any(|(id, _)| *id == s.ident_id())); + + symbol_to_id.push((s.ident_id(), binding_index as u32)); } let mut def_order = DefOrdering::from_symbol_to_id(env.home, symbol_to_id); From 32edd55d3deb96b414105765b569c1ed60b9f3c5 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 23 Apr 2022 15:32:15 +0200 Subject: [PATCH 438/846] sanity check --- compiler/can/src/def.rs | 507 +++++++++++++++++++++++- compiler/test_gen/src/gen_primitives.rs | 22 + reporting/tests/test_reporting.rs | 27 +- 3 files changed, 526 insertions(+), 30 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 188f97426c..b8ad318da3 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -235,7 +235,6 @@ pub fn canonicalize_defs<'a>( let mut scope = original_scope.clone(); let num_defs = loc_defs.len(); let mut refs_by_symbol = MutMap::default(); - let mut can_defs_by_symbol = HashMap::with_capacity_and_hasher(num_defs, default_hasher()); let mut type_defs = Vec::with_capacity(num_defs); let mut value_defs = Vec::with_capacity(num_defs); @@ -508,21 +507,55 @@ pub fn canonicalize_defs<'a>( let mut def_order = DefOrdering::from_symbol_to_id(env.home, symbol_to_id); - for pending_def in pending_value_defs.into_iter() { - output = canonicalize_pending_value_def( - env, - pending_def, - output, - &mut scope, - &mut can_defs_by_symbol, - var_store, - &mut refs_by_symbol, - &mut aliases, - &abilities_in_scope, - ); + let mut can_defs_by_symbol = HashMap::with_capacity_and_hasher(num_defs, default_hasher()); - // TODO we should do something with these references; they include - // things like type annotations. + // env.home.register_debug_idents(&env.ident_ids); + + if true { + for pending_def in pending_value_defs.into_iter() { + let region = pending_def.loc_pattern().region; + + let bindings = bindings_from_patterns(std::iter::once(pending_def.loc_pattern())); + + let temp_output = canonicalize_pending_value_def_new( + env, + pending_def, + output, + &mut scope, + &mut can_defs_by_symbol, + var_store, + &mut refs_by_symbol, + &mut aliases, + &abilities_in_scope, + ); + + output = temp_output.output; + + for (symbol, _) in bindings { + can_defs_by_symbol.insert(symbol, temp_output.def.clone()); + refs_by_symbol.insert(symbol, (region, temp_output.references.clone())); + } + + // TODO we should do something with these references; they include + // things like type annotations. + } + } else { + for pending_def in pending_value_defs.into_iter() { + output = canonicalize_pending_value_def( + env, + pending_def, + output, + &mut scope, + &mut can_defs_by_symbol, + var_store, + &mut refs_by_symbol, + &mut aliases, + &abilities_in_scope, + ); + + // TODO we should do something with these references; they include + // things like type annotations. + } } // Determine which idents we introduced in the course of this process. @@ -1203,6 +1236,12 @@ fn add_annotation_aliases( } } +struct TempOutput { + output: Output, + def: Def, + references: References, +} + // TODO trim down these arguments! #[allow(clippy::too_many_arguments)] #[allow(clippy::cognitive_complexity)] @@ -1648,6 +1687,444 @@ fn canonicalize_pending_value_def<'a>( output } +// TODO trim down these arguments! +#[allow(clippy::too_many_arguments)] +#[allow(clippy::cognitive_complexity)] +fn canonicalize_pending_value_def_new<'a>( + env: &mut Env<'a>, + pending_def: PendingValueDef<'a>, + mut output: Output, + scope: &mut Scope, + can_defs_by_symbol: &mut MutMap, + var_store: &mut VarStore, + refs_by_symbol: &mut MutMap, + aliases: &mut ImMap, + abilities_in_scope: &[Symbol], +) -> TempOutput { + use PendingValueDef::*; + + // Make types for the body expr, even if we won't end up having a body. + let expr_var = var_store.fresh(); + let mut vars_by_symbol = SendMap::default(); + + match pending_def { + AnnotationOnly(_, loc_can_pattern, loc_ann) => { + // annotation sans body cannot introduce new rigids that are visible in other annotations + // but the rigids can show up in type error messages, so still register them + let type_annotation = canonicalize_annotation( + env, + scope, + &loc_ann.value, + loc_ann.region, + var_store, + abilities_in_scope, + ); + + // Record all the annotation's references in output.references.lookups + + for symbol in type_annotation.references.iter() { + output.references.insert_type_lookup(*symbol); + } + + add_annotation_aliases(&type_annotation, aliases); + + output + .introduced_variables + .union(&type_annotation.introduced_variables); + + pattern_to_vars_by_symbol(&mut vars_by_symbol, &loc_can_pattern.value, expr_var); + + let arity = type_annotation.typ.arity(); + + let problem = match &loc_can_pattern.value { + Pattern::Identifier(symbol) => RuntimeError::NoImplementationNamed { + def_symbol: *symbol, + }, + Pattern::Shadowed(region, loc_ident, _new_symbol) => RuntimeError::Shadowing { + original_region: *region, + shadow: loc_ident.clone(), + kind: ShadowKind::Variable, + }, + _ => RuntimeError::NoImplementation, + }; + + // Fabricate a body for this annotation, that will error at runtime + let value = Expr::RuntimeError(problem); + let is_closure = arity > 0; + let loc_can_expr = if !is_closure { + Loc { + value, + region: loc_ann.region, + } + } else { + let symbol = env.gen_unique_symbol(); + + // generate a fake pattern for each argument. this makes signatures + // that are functions only crash when they are applied. + let mut underscores = Vec::with_capacity(arity); + + for _ in 0..arity { + let underscore: Loc = Loc { + value: Pattern::Underscore, + region: Region::zero(), + }; + + underscores.push((var_store.fresh(), underscore)); + } + + let body_expr = Loc { + value, + region: loc_ann.region, + }; + + Loc { + value: Closure(ClosureData { + function_type: var_store.fresh(), + closure_type: var_store.fresh(), + closure_ext_var: var_store.fresh(), + return_type: var_store.fresh(), + name: symbol, + captured_symbols: Vec::new(), + recursive: Recursive::NotRecursive, + arguments: underscores, + loc_body: Box::new(body_expr), + }), + region: loc_ann.region, + } + }; + + let def = single_can_def( + loc_can_pattern, + loc_can_expr, + expr_var, + Some(Loc::at(loc_ann.region, type_annotation)), + vars_by_symbol.clone(), + ); + + TempOutput { + output, + references: References::default(), + def, + } + } + + TypedBody(_loc_pattern, loc_can_pattern, loc_ann, loc_expr) => { + let type_annotation = canonicalize_annotation( + env, + scope, + &loc_ann.value, + loc_ann.region, + var_store, + abilities_in_scope, + ); + + // Record all the annotation's references in output.references.lookups + for symbol in type_annotation.references.iter() { + output.references.insert_type_lookup(*symbol); + } + + add_annotation_aliases(&type_annotation, aliases); + + output + .introduced_variables + .union(&type_annotation.introduced_variables); + + // bookkeeping for tail-call detection. If we're assigning to an + // identifier (e.g. `f = \x -> ...`), then this symbol can be tail-called. + let outer_identifier = env.tailcallable_symbol; + + if let Pattern::Identifier(ref defined_symbol) = &loc_can_pattern.value { + env.tailcallable_symbol = Some(*defined_symbol); + }; + + // register the name of this closure, to make sure the closure won't capture it's own name + if let (Pattern::Identifier(ref defined_symbol), &ast::Expr::Closure(_, _)) = + (&loc_can_pattern.value, &loc_expr.value) + { + env.closure_name_symbol = Some(*defined_symbol); + }; + + pattern_to_vars_by_symbol(&mut vars_by_symbol, &loc_can_pattern.value, expr_var); + + let (mut loc_can_expr, can_output) = + canonicalize_expr(env, var_store, scope, loc_expr.region, &loc_expr.value); + + output.references.union_mut(&can_output.references); + + // reset the tailcallable_symbol + env.tailcallable_symbol = outer_identifier; + + // First, make sure we are actually assigning an identifier instead of (for example) a tag. + // + // If we're assigning (UserId userId) = ... then this is certainly not a closure declaration, + // which also implies it's not a self tail call! + // + // Only defs of the form (foo = ...) can be closure declarations or self tail calls. + if let Pattern::Identifier(symbol) + | Pattern::AbilityMemberSpecialization { ident: symbol, .. } = loc_can_pattern.value + { + if let Closure(ClosureData { + function_type, + closure_type, + closure_ext_var, + return_type, + name: ref closure_name, + ref arguments, + loc_body: ref body, + ref captured_symbols, + .. + }) = loc_can_expr.value + { + // Since everywhere in the code it'll be referred to by its defined name, + // remove its generated name from the closure map. (We'll re-insert it later.) + let references = env.closures.remove(closure_name).unwrap_or_else(|| { + panic!( + "Tried to remove symbol {:?} from procedures, but it was not found: {:?}", + closure_name, env.closures + ) + }); + + // Re-insert the closure into the map, under its defined name. + // closures don't have a name, and therefore pick a fresh symbol. But in this + // case, the closure has a proper name (e.g. `foo` in `foo = \x y -> ...` + // and we want to reference it by that name. + env.closures.insert(symbol, references); + + // The closure is self tail recursive iff it tail calls itself (by defined name). + let is_recursive = match can_output.tail_call { + Some(tail_symbol) if tail_symbol == symbol => Recursive::TailRecursive, + _ => Recursive::NotRecursive, + }; + + // Recursion doesn't count as referencing. (If it did, all recursive functions + // would result in circular def errors!) + refs_by_symbol.entry(symbol).and_modify(|(_, refs)| { + refs.remove_value_lookup(&symbol); + }); + + // renamed_closure_def = Some(&symbol); + loc_can_expr.value = Closure(ClosureData { + function_type, + closure_type, + closure_ext_var, + return_type, + name: symbol, + captured_symbols: captured_symbols.clone(), + recursive: is_recursive, + arguments: arguments.clone(), + loc_body: body.clone(), + }); + + // Functions' references don't count in defs. + // See 3d5a2560057d7f25813112dfa5309956c0f9e6a9 and its + // parent commit for the bug this fixed! + // + // NOTE: this is where we lose reference information for closure bodies. + let refs = References::new(); + + let def = single_can_def( + loc_can_pattern, + loc_can_expr, + expr_var, + Some(Loc::at(loc_ann.region, type_annotation)), + vars_by_symbol.clone(), + ); + + output.union(can_output); + + TempOutput { + output, + references: refs, + def, + } + } else { + let refs = can_output.references.clone(); + + let def = single_can_def( + loc_can_pattern, + loc_can_expr, + expr_var, + Some(Loc::at(loc_ann.region, type_annotation)), + vars_by_symbol.clone(), + ); + + output.union(can_output); + + TempOutput { + output, + references: refs, + def, + } + } + } else { + let refs = can_output.references.clone(); + + let def = single_can_def( + loc_can_pattern, + loc_can_expr, + expr_var, + Some(Loc::at(loc_ann.region, type_annotation)), + vars_by_symbol.clone(), + ); + + output.union(can_output); + + TempOutput { + output, + references: refs, + def, + } + } + } + // If we have a pattern, then the def has a body (that is, it's not a + // standalone annotation), so we need to canonicalize the pattern and expr. + Body(loc_pattern, loc_can_pattern, loc_expr) => { + // bookkeeping for tail-call detection. If we're assigning to an + // identifier (e.g. `f = \x -> ...`), then this symbol can be tail-called. + let outer_identifier = env.tailcallable_symbol; + + if let (&ast::Pattern::Identifier(_name), &Pattern::Identifier(ref defined_symbol)) = + (&loc_pattern.value, &loc_can_pattern.value) + { + env.tailcallable_symbol = Some(*defined_symbol); + + // TODO isn't types_by_symbol enough? Do we need vars_by_symbol too? + vars_by_symbol.insert(*defined_symbol, expr_var); + }; + + // register the name of this closure, to make sure the closure won't capture it's own name + if let (Pattern::Identifier(ref defined_symbol), &ast::Expr::Closure(_, _)) = + (&loc_can_pattern.value, &loc_expr.value) + { + env.closure_name_symbol = Some(*defined_symbol); + }; + + let (mut loc_can_expr, can_output) = + canonicalize_expr(env, var_store, scope, loc_expr.region, &loc_expr.value); + + // reset the tailcallable_symbol + env.tailcallable_symbol = outer_identifier; + + // First, make sure we are actually assigning an identifier instead of (for example) a tag. + // + // If we're assigning (UserId userId) = ... then this is certainly not a closure declaration, + // which also implies it's not a self tail call! + // + // Only defs of the form (foo = ...) can be closure declarations or self tail calls. + if let Pattern::Identifier(symbol) = loc_can_pattern.value { + if let Closure(ClosureData { + function_type, + closure_type, + closure_ext_var, + return_type, + name: ref closure_name, + ref arguments, + loc_body: ref body, + ref captured_symbols, + .. + }) = loc_can_expr.value + { + // Since everywhere in the code it'll be referred to by its defined name, + // remove its generated name from the closure map. (We'll re-insert it later.) + let references = env.closures.remove(closure_name).unwrap_or_else(|| { + panic!( + "Tried to remove symbol {:?} from procedures, but it was not found: {:?}", + closure_name, env.closures + ) + }); + + // Re-insert the closure into the map, under its defined name. + // closures don't have a name, and therefore pick a fresh symbol. But in this + // case, the closure has a proper name (e.g. `foo` in `foo = \x y -> ...` + // and we want to reference it by that name. + env.closures.insert(symbol, references); + + // The closure is self tail recursive iff it tail calls itself (by defined name). + let is_recursive = match can_output.tail_call { + Some(tail_symbol) if tail_symbol == symbol => Recursive::TailRecursive, + _ => Recursive::NotRecursive, + }; + + // Recursion doesn't count as referencing. (If it did, all recursive functions + // would result in circular def errors!) + refs_by_symbol.entry(symbol).and_modify(|(_, refs)| { + refs.remove_value_lookup(&symbol); + }); + + loc_can_expr.value = Closure(ClosureData { + function_type, + closure_type, + closure_ext_var, + return_type, + name: symbol, + captured_symbols: captured_symbols.clone(), + recursive: is_recursive, + arguments: arguments.clone(), + loc_body: body.clone(), + }); + + // Functions' references don't count in defs. + // See 3d5a2560057d7f25813112dfa5309956c0f9e6a9 and its + // parent commit for the bug this fixed! + let refs = References::new(); + + let def = single_can_def( + loc_can_pattern, + loc_can_expr, + expr_var, + None, + vars_by_symbol.clone(), + ); + + output.union(can_output); + + TempOutput { + output, + references: refs, + def, + } + } else { + let refs = can_output.references.clone(); + + let def = single_can_def( + loc_can_pattern, + loc_can_expr, + expr_var, + None, + vars_by_symbol.clone(), + ); + + output.union(can_output); + + TempOutput { + output, + references: refs, + def, + } + } + } else { + let refs = can_output.references.clone(); + + let def = single_can_def( + loc_can_pattern, + loc_can_expr, + expr_var, + None, + vars_by_symbol.clone(), + ); + + output.union(can_output); + + TempOutput { + output, + references: refs, + def, + } + } + } + } +} + #[inline(always)] pub fn can_defs_with_return<'a>( env: &mut Env<'a>, diff --git a/compiler/test_gen/src/gen_primitives.rs b/compiler/test_gen/src/gen_primitives.rs index 16f4248dc8..7c32b4aff7 100644 --- a/compiler/test_gen/src/gen_primitives.rs +++ b/compiler/test_gen/src/gen_primitives.rs @@ -593,6 +593,27 @@ fn top_level_constant() { ); } +#[test] +#[ignore] +#[cfg(any(feature = "gen-llvm", feature = "gen-dev", feature = "gen-wasm"))] +fn top_level_destructure() { + assert_evals_to!( + indoc!( + r#" + app "test" provides [ main ] to "./platform" + + {a, b} = { a: 1, b: 2 } + + main = + + a + b + "# + ), + 3, + i64 + ); +} + #[test] #[cfg(any(feature = "gen-llvm"))] fn linked_list_len_0() { @@ -2971,6 +2992,7 @@ fn mix_function_and_closure_level_of_indirection() { } #[test] +#[ignore] #[cfg(any(feature = "gen-llvm"))] fn do_pass_bool_byte_closure_layout() { // see https://github.com/rtfeldman/roc/pull/1706 diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 8d25660f64..83951bd8d9 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -7092,26 +7092,23 @@ I need all branches in an `if` to have the same type! indoc!( r#" ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ - - Something is off with the body of the `f` definition: - - 1│ f : a, b, * -> * - 2│ f = \_, _, x2 -> + + Something is off with the body of the `inner` definition: + 3│ inner : * -> * 4│ inner = \y -> y - 5│ inner x2 - ^^^^^^^^ - - The type annotation on `f` says this `inner` call should have the type: - + ^ + + The type annotation on `inner` says this `y` value should have the type: + * - - However, the type of this `inner` call is connected to another type in a + + However, the type of this `y` value is connected to another type in a way that isn't reflected in this annotation. - + Tip: Any connection between types must use a named type variable, not - a `*`! Maybe the annotation on `f` should have a named type variable in - place of the `*`? + a `*`! Maybe the annotation on `inner` should have a named type variable + in place of the `*`? "# ), ) From 7042584559876650233514fba7ada3336b18b65b Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 23 Apr 2022 15:34:24 +0200 Subject: [PATCH 439/846] clippy --- compiler/can/src/def.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index b8ad318da3..b54ad03138 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -505,7 +505,7 @@ pub fn canonicalize_defs<'a>( symbol_to_id.push((s.ident_id(), binding_index as u32)); } - let mut def_order = DefOrdering::from_symbol_to_id(env.home, symbol_to_id); + // let mut def_order = DefOrdering::from_symbol_to_id(env.home, symbol_to_id); let mut can_defs_by_symbol = HashMap::with_capacity_and_hasher(num_defs, default_hasher()); @@ -757,17 +757,17 @@ impl DefOrdering { } } - fn from_symbol_to_id(home: ModuleId, symbol_to_id: Vec<(IdentId, u32)>) -> Self { - let capacity = symbol_to_id.len(); - - Self { - home, - symbol_to_id, - references: ReferenceMatrix::new(capacity), - direct_references: ReferenceMatrix::new(capacity), - length: capacity as u32, - } - } + // fn from_symbol_to_id(home: ModuleId, symbol_to_id: Vec<(IdentId, u32)>) -> Self { + // let capacity = symbol_to_id.len(); + // + // Self { + // home, + // symbol_to_id, + // references: ReferenceMatrix::new(capacity), + // direct_references: ReferenceMatrix::new(capacity), + // length: capacity as u32, + // } + // } fn from_defs_by_symbol( env: &Env, @@ -1695,7 +1695,7 @@ fn canonicalize_pending_value_def_new<'a>( pending_def: PendingValueDef<'a>, mut output: Output, scope: &mut Scope, - can_defs_by_symbol: &mut MutMap, + _can_defs_by_symbol: &mut MutMap, var_store: &mut VarStore, refs_by_symbol: &mut MutMap, aliases: &mut ImMap, From 7b37727175cbbb64eef8d9176131c519b3f92bb6 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 23 Apr 2022 16:13:26 +0200 Subject: [PATCH 440/846] cleanup the old implementation --- compiler/can/src/def.rs | 539 +++------------------------------------- 1 file changed, 28 insertions(+), 511 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index b54ad03138..1e8b13f49d 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -489,20 +489,20 @@ pub fn canonicalize_defs<'a>( } } - // the bindings by all defs in the current block - let bindings = bindings_from_patterns(pending_value_defs.iter().map(|p| p.loc_pattern())); - let mut symbol_to_id: Vec<(IdentId, u32)> = Vec::with_capacity(pending_value_defs.len()); - for (binding_index, (s, _)) in bindings.into_iter().enumerate() { - // store the top-level defs, used to ensure that closures won't capture them - if let PatternType::TopLevelDef = pattern_type { - env.top_level_symbols.insert(s); + + for (def_index, pending_def) in pending_value_defs.iter().enumerate() { + for (s, _) in bindings_from_patterns(std::iter::once(pending_def.loc_pattern())) { + // store the top-level defs, used to ensure that closures won't capture them + if let PatternType::TopLevelDef = pattern_type { + env.top_level_symbols.insert(s); + } + + debug_assert_eq!(env.home, s.module_id()); + debug_assert!(!symbol_to_id.iter().any(|(id, _)| *id == s.ident_id())); + + symbol_to_id.push((s.ident_id(), def_index as u32)); } - - debug_assert_eq!(env.home, s.module_id()); - debug_assert!(!symbol_to_id.iter().any(|(id, _)| *id == s.ident_id())); - - symbol_to_id.push((s.ident_id(), binding_index as u32)); } // let mut def_order = DefOrdering::from_symbol_to_id(env.home, symbol_to_id); @@ -511,50 +511,26 @@ pub fn canonicalize_defs<'a>( // env.home.register_debug_idents(&env.ident_ids); - if true { - for pending_def in pending_value_defs.into_iter() { - let region = pending_def.loc_pattern().region; + for pending_def in pending_value_defs.into_iter() { + let region = pending_def.loc_pattern().region; - let bindings = bindings_from_patterns(std::iter::once(pending_def.loc_pattern())); + let bindings = bindings_from_patterns(std::iter::once(pending_def.loc_pattern())); - let temp_output = canonicalize_pending_value_def_new( - env, - pending_def, - output, - &mut scope, - &mut can_defs_by_symbol, - var_store, - &mut refs_by_symbol, - &mut aliases, - &abilities_in_scope, - ); + let temp_output = canonicalize_pending_value_def_new( + env, + pending_def, + output, + &mut scope, + var_store, + &mut aliases, + &abilities_in_scope, + ); - output = temp_output.output; + output = temp_output.output; - for (symbol, _) in bindings { - can_defs_by_symbol.insert(symbol, temp_output.def.clone()); - refs_by_symbol.insert(symbol, (region, temp_output.references.clone())); - } - - // TODO we should do something with these references; they include - // things like type annotations. - } - } else { - for pending_def in pending_value_defs.into_iter() { - output = canonicalize_pending_value_def( - env, - pending_def, - output, - &mut scope, - &mut can_defs_by_symbol, - var_store, - &mut refs_by_symbol, - &mut aliases, - &abilities_in_scope, - ); - - // TODO we should do something with these references; they include - // things like type annotations. + for (symbol, _) in bindings { + can_defs_by_symbol.insert(symbol, temp_output.def.clone()); + refs_by_symbol.insert(symbol, (region, temp_output.references.clone())); } } @@ -1242,451 +1218,6 @@ struct TempOutput { references: References, } -// TODO trim down these arguments! -#[allow(clippy::too_many_arguments)] -#[allow(clippy::cognitive_complexity)] -fn canonicalize_pending_value_def<'a>( - env: &mut Env<'a>, - pending_def: PendingValueDef<'a>, - mut output: Output, - scope: &mut Scope, - can_defs_by_symbol: &mut MutMap, - var_store: &mut VarStore, - refs_by_symbol: &mut MutMap, - aliases: &mut ImMap, - abilities_in_scope: &[Symbol], -) -> Output { - use PendingValueDef::*; - - // Make types for the body expr, even if we won't end up having a body. - let expr_var = var_store.fresh(); - let mut vars_by_symbol = SendMap::default(); - - match pending_def { - AnnotationOnly(_, loc_can_pattern, loc_ann) => { - // annotation sans body cannot introduce new rigids that are visible in other annotations - // but the rigids can show up in type error messages, so still register them - let type_annotation = canonicalize_annotation( - env, - scope, - &loc_ann.value, - loc_ann.region, - var_store, - abilities_in_scope, - ); - - // Record all the annotation's references in output.references.lookups - - for symbol in type_annotation.references.iter() { - output.references.insert_type_lookup(*symbol); - } - - add_annotation_aliases(&type_annotation, aliases); - - output - .introduced_variables - .union(&type_annotation.introduced_variables); - - pattern_to_vars_by_symbol(&mut vars_by_symbol, &loc_can_pattern.value, expr_var); - - let arity = type_annotation.typ.arity(); - - let problem = match &loc_can_pattern.value { - Pattern::Identifier(symbol) => RuntimeError::NoImplementationNamed { - def_symbol: *symbol, - }, - Pattern::Shadowed(region, loc_ident, _new_symbol) => RuntimeError::Shadowing { - original_region: *region, - shadow: loc_ident.clone(), - kind: ShadowKind::Variable, - }, - _ => RuntimeError::NoImplementation, - }; - - // Fabricate a body for this annotation, that will error at runtime - let value = Expr::RuntimeError(problem); - let is_closure = arity > 0; - let loc_can_expr = if !is_closure { - Loc { - value, - region: loc_ann.region, - } - } else { - let symbol = env.gen_unique_symbol(); - - // generate a fake pattern for each argument. this makes signatures - // that are functions only crash when they are applied. - let mut underscores = Vec::with_capacity(arity); - - for _ in 0..arity { - let underscore: Loc = Loc { - value: Pattern::Underscore, - region: Region::zero(), - }; - - underscores.push((var_store.fresh(), underscore)); - } - - let body_expr = Loc { - value, - region: loc_ann.region, - }; - - Loc { - value: Closure(ClosureData { - function_type: var_store.fresh(), - closure_type: var_store.fresh(), - closure_ext_var: var_store.fresh(), - return_type: var_store.fresh(), - name: symbol, - captured_symbols: Vec::new(), - recursive: Recursive::NotRecursive, - arguments: underscores, - loc_body: Box::new(body_expr), - }), - region: loc_ann.region, - } - }; - - if let Pattern::Identifier(symbol) - | Pattern::AbilityMemberSpecialization { ident: symbol, .. } = loc_can_pattern.value - { - let def = single_can_def( - loc_can_pattern, - loc_can_expr, - expr_var, - Some(Loc::at(loc_ann.region, type_annotation)), - vars_by_symbol.clone(), - ); - can_defs_by_symbol.insert(symbol, def); - } else { - for (_, (symbol, _)) in scope.idents() { - if !vars_by_symbol.contains_key(symbol) { - continue; - } - - // We could potentially avoid some clones here by using Rc strategically, - // but the total amount of cloning going on here should typically be minimal. - can_defs_by_symbol.insert( - *symbol, - Def { - expr_var, - // TODO try to remove this .clone()! - loc_pattern: loc_can_pattern.clone(), - loc_expr: Loc { - region: loc_can_expr.region, - // TODO try to remove this .clone()! - value: loc_can_expr.value.clone(), - }, - pattern_vars: vars_by_symbol.clone(), - annotation: Some(Annotation { - signature: type_annotation.typ.clone(), - introduced_variables: output.introduced_variables.clone(), - aliases: type_annotation.aliases.clone(), - region: loc_ann.region, - }), - }, - ); - } - } - } - - TypedBody(_loc_pattern, loc_can_pattern, loc_ann, loc_expr) => { - let type_annotation = canonicalize_annotation( - env, - scope, - &loc_ann.value, - loc_ann.region, - var_store, - abilities_in_scope, - ); - - // Record all the annotation's references in output.references.lookups - for symbol in type_annotation.references.iter() { - output.references.insert_type_lookup(*symbol); - } - - add_annotation_aliases(&type_annotation, aliases); - - output - .introduced_variables - .union(&type_annotation.introduced_variables); - - // bookkeeping for tail-call detection. If we're assigning to an - // identifier (e.g. `f = \x -> ...`), then this symbol can be tail-called. - let outer_identifier = env.tailcallable_symbol; - - if let Pattern::Identifier(ref defined_symbol) = &loc_can_pattern.value { - env.tailcallable_symbol = Some(*defined_symbol); - }; - - // register the name of this closure, to make sure the closure won't capture it's own name - if let (Pattern::Identifier(ref defined_symbol), &ast::Expr::Closure(_, _)) = - (&loc_can_pattern.value, &loc_expr.value) - { - env.closure_name_symbol = Some(*defined_symbol); - }; - - pattern_to_vars_by_symbol(&mut vars_by_symbol, &loc_can_pattern.value, expr_var); - - let (mut loc_can_expr, can_output) = - canonicalize_expr(env, var_store, scope, loc_expr.region, &loc_expr.value); - - output.references.union_mut(&can_output.references); - - // reset the tailcallable_symbol - env.tailcallable_symbol = outer_identifier; - - // First, make sure we are actually assigning an identifier instead of (for example) a tag. - // - // If we're assigning (UserId userId) = ... then this is certainly not a closure declaration, - // which also implies it's not a self tail call! - // - // Only defs of the form (foo = ...) can be closure declarations or self tail calls. - if let Pattern::Identifier(symbol) - | Pattern::AbilityMemberSpecialization { ident: symbol, .. } = loc_can_pattern.value - { - if let Closure(ClosureData { - function_type, - closure_type, - closure_ext_var, - return_type, - name: ref closure_name, - ref arguments, - loc_body: ref body, - ref captured_symbols, - .. - }) = loc_can_expr.value - { - // Since everywhere in the code it'll be referred to by its defined name, - // remove its generated name from the closure map. (We'll re-insert it later.) - let references = env.closures.remove(closure_name).unwrap_or_else(|| { - panic!( - "Tried to remove symbol {:?} from procedures, but it was not found: {:?}", - closure_name, env.closures - ) - }); - - // Re-insert the closure into the map, under its defined name. - // closures don't have a name, and therefore pick a fresh symbol. But in this - // case, the closure has a proper name (e.g. `foo` in `foo = \x y -> ...` - // and we want to reference it by that name. - env.closures.insert(symbol, references); - - // The closure is self tail recursive iff it tail calls itself (by defined name). - let is_recursive = match can_output.tail_call { - Some(tail_symbol) if tail_symbol == symbol => Recursive::TailRecursive, - _ => Recursive::NotRecursive, - }; - - // Recursion doesn't count as referencing. (If it did, all recursive functions - // would result in circular def errors!) - refs_by_symbol.entry(symbol).and_modify(|(_, refs)| { - refs.remove_value_lookup(&symbol); - }); - - // renamed_closure_def = Some(&symbol); - loc_can_expr.value = Closure(ClosureData { - function_type, - closure_type, - closure_ext_var, - return_type, - name: symbol, - captured_symbols: captured_symbols.clone(), - recursive: is_recursive, - arguments: arguments.clone(), - loc_body: body.clone(), - }); - - // Functions' references don't count in defs. - // See 3d5a2560057d7f25813112dfa5309956c0f9e6a9 and its - // parent commit for the bug this fixed! - let refs = References::new(); - - refs_by_symbol.insert(symbol, (loc_can_pattern.region, refs)); - } else { - let refs = can_output.references; - refs_by_symbol.insert(symbol, (loc_ann.region, refs)); - } - - let def = single_can_def( - loc_can_pattern, - loc_can_expr, - expr_var, - Some(Loc::at(loc_ann.region, type_annotation)), - vars_by_symbol.clone(), - ); - can_defs_by_symbol.insert(symbol, def); - } else { - for (_, (symbol, region)) in scope.idents() { - if !vars_by_symbol.contains_key(symbol) { - continue; - } - - let refs = can_output.references.clone(); - - refs_by_symbol.insert(*symbol, (*region, refs)); - - can_defs_by_symbol.insert( - *symbol, - Def { - expr_var, - // TODO try to remove this .clone()! - loc_pattern: loc_can_pattern.clone(), - loc_expr: Loc { - region: loc_can_expr.region, - // TODO try to remove this .clone()! - value: loc_can_expr.value.clone(), - }, - pattern_vars: vars_by_symbol.clone(), - annotation: Some(Annotation { - signature: type_annotation.typ.clone(), - introduced_variables: type_annotation.introduced_variables.clone(), - aliases: type_annotation.aliases.clone(), - region: loc_ann.region, - }), - }, - ); - } - } - } - // If we have a pattern, then the def has a body (that is, it's not a - // standalone annotation), so we need to canonicalize the pattern and expr. - Body(loc_pattern, loc_can_pattern, loc_expr) => { - // bookkeeping for tail-call detection. If we're assigning to an - // identifier (e.g. `f = \x -> ...`), then this symbol can be tail-called. - let outer_identifier = env.tailcallable_symbol; - - if let (&ast::Pattern::Identifier(_name), &Pattern::Identifier(ref defined_symbol)) = - (&loc_pattern.value, &loc_can_pattern.value) - { - env.tailcallable_symbol = Some(*defined_symbol); - - // TODO isn't types_by_symbol enough? Do we need vars_by_symbol too? - vars_by_symbol.insert(*defined_symbol, expr_var); - }; - - // register the name of this closure, to make sure the closure won't capture it's own name - if let (Pattern::Identifier(ref defined_symbol), &ast::Expr::Closure(_, _)) = - (&loc_can_pattern.value, &loc_expr.value) - { - env.closure_name_symbol = Some(*defined_symbol); - }; - - let (mut loc_can_expr, can_output) = - canonicalize_expr(env, var_store, scope, loc_expr.region, &loc_expr.value); - - // reset the tailcallable_symbol - env.tailcallable_symbol = outer_identifier; - - // First, make sure we are actually assigning an identifier instead of (for example) a tag. - // - // If we're assigning (UserId userId) = ... then this is certainly not a closure declaration, - // which also implies it's not a self tail call! - // - // Only defs of the form (foo = ...) can be closure declarations or self tail calls. - if let Pattern::Identifier(symbol) = loc_can_pattern.value { - if let Closure(ClosureData { - function_type, - closure_type, - closure_ext_var, - return_type, - name: ref closure_name, - ref arguments, - loc_body: ref body, - ref captured_symbols, - .. - }) = loc_can_expr.value - { - // Since everywhere in the code it'll be referred to by its defined name, - // remove its generated name from the closure map. (We'll re-insert it later.) - let references = env.closures.remove(closure_name).unwrap_or_else(|| { - panic!( - "Tried to remove symbol {:?} from procedures, but it was not found: {:?}", - closure_name, env.closures - ) - }); - - // Re-insert the closure into the map, under its defined name. - // closures don't have a name, and therefore pick a fresh symbol. But in this - // case, the closure has a proper name (e.g. `foo` in `foo = \x y -> ...` - // and we want to reference it by that name. - env.closures.insert(symbol, references); - - // The closure is self tail recursive iff it tail calls itself (by defined name). - let is_recursive = match can_output.tail_call { - Some(tail_symbol) if tail_symbol == symbol => Recursive::TailRecursive, - _ => Recursive::NotRecursive, - }; - - // Recursion doesn't count as referencing. (If it did, all recursive functions - // would result in circular def errors!) - refs_by_symbol.entry(symbol).and_modify(|(_, refs)| { - refs.remove_value_lookup(&symbol); - }); - - loc_can_expr.value = Closure(ClosureData { - function_type, - closure_type, - closure_ext_var, - return_type, - name: symbol, - captured_symbols: captured_symbols.clone(), - recursive: is_recursive, - arguments: arguments.clone(), - loc_body: body.clone(), - }); - - // Functions' references don't count in defs. - // See 3d5a2560057d7f25813112dfa5309956c0f9e6a9 and its - // parent commit for the bug this fixed! - let refs = References::new(); - refs_by_symbol.insert(symbol, (loc_pattern.region, refs)); - } else { - let refs = can_output.references.clone(); - refs_by_symbol.insert(symbol, (loc_pattern.region, refs)); - } - - let def = single_can_def( - loc_can_pattern, - loc_can_expr, - expr_var, - None, - vars_by_symbol.clone(), - ); - can_defs_by_symbol.insert(symbol, def); - } else { - // Store the referenced locals in the refs_by_symbol map, so we can later figure out - // which defined names reference each other. - for (symbol, region) in bindings_from_patterns(std::iter::once(&loc_can_pattern)) { - let refs = can_output.references.clone(); - refs_by_symbol.insert(symbol, (region, refs)); - - can_defs_by_symbol.insert( - symbol, - Def { - expr_var, - // TODO try to remove this .clone()! - loc_pattern: loc_can_pattern.clone(), - loc_expr: Loc { - // TODO try to remove this .clone()! - region: loc_can_expr.region, - value: loc_can_expr.value.clone(), - }, - pattern_vars: vars_by_symbol.clone(), - annotation: None, - }, - ); - } - } - - output.union(can_output); - } - }; - - output -} - // TODO trim down these arguments! #[allow(clippy::too_many_arguments)] #[allow(clippy::cognitive_complexity)] @@ -1695,9 +1226,7 @@ fn canonicalize_pending_value_def_new<'a>( pending_def: PendingValueDef<'a>, mut output: Output, scope: &mut Scope, - _can_defs_by_symbol: &mut MutMap, var_store: &mut VarStore, - refs_by_symbol: &mut MutMap, aliases: &mut ImMap, abilities_in_scope: &[Symbol], ) -> TempOutput { @@ -1896,12 +1425,6 @@ fn canonicalize_pending_value_def_new<'a>( _ => Recursive::NotRecursive, }; - // Recursion doesn't count as referencing. (If it did, all recursive functions - // would result in circular def errors!) - refs_by_symbol.entry(symbol).and_modify(|(_, refs)| { - refs.remove_value_lookup(&symbol); - }); - // renamed_closure_def = Some(&symbol); loc_can_expr.value = Closure(ClosureData { function_type, @@ -2045,12 +1568,6 @@ fn canonicalize_pending_value_def_new<'a>( _ => Recursive::NotRecursive, }; - // Recursion doesn't count as referencing. (If it did, all recursive functions - // would result in circular def errors!) - refs_by_symbol.entry(symbol).and_modify(|(_, refs)| { - refs.remove_value_lookup(&symbol); - }); - loc_can_expr.value = Closure(ClosureData { function_type, closure_type, From 115cd2ba75adcbc3a1f28ec6fc15908bed11d145 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 20 Apr 2022 14:19:09 -0400 Subject: [PATCH 441/846] IsOpen constraints should always open up all nested tag unions --- compiler/solve/src/solve.rs | 49 +++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index dbe6f50c5d..81784b452e 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -1183,26 +1183,39 @@ fn solve( let actual = either_type_index_to_var(constraints, subs, rank, pools, aliases, *type_index); - let mut new_desc = subs.get(actual); - match new_desc.content { - Content::Structure(FlatType::TagUnion(tags, _)) => { - let new_ext = subs.fresh_unnamed_flex_var(); - subs.set_rank(new_ext, new_desc.rank); - let new_union = Content::Structure(FlatType::TagUnion(tags, new_ext)); - new_desc.content = new_union; - subs.set(actual, new_desc); - state - } - _ => { - // Today, an "open" constraint doesn't affect any types - // other than tag unions. Recursive tag unions are constructed - // at a later time (during occurs checks after tag unions are - // resolved), so that's not handled here either. - // NB: Handle record types here if we add presence constraints - // to their type inference as well. - state + let mut stack = vec![actual]; + while let Some(var) = stack.pop() { + let mut desc = subs.get(var); + match desc.content { + Content::Structure(FlatType::TagUnion(tags, ext)) + if matches!( + subs.get_content_without_compacting(ext), + Content::Structure(FlatType::EmptyTagUnion) + ) => + { + let new_ext = subs.fresh_unnamed_flex_var(); + subs.set_rank(new_ext, desc.rank); + let new_union = Content::Structure(FlatType::TagUnion(tags, new_ext)); + desc.content = new_union; + subs.set(var, desc); + + let all_vars = tags.variables().into_iter(); + stack.extend( + all_vars.flat_map(|slice| subs[slice]).map(|var| subs[var]), + ); + } + _ => { + // Today, an "open" constraint doesn't affect any types + // other than tag unions. Recursive tag unions are constructed + // at a later time (during occurs checks after tag unions are + // resolved), so that's not handled here either. + // NB: Handle record types here if we add presence constraints + // to their type inference as well. + } } } + + state } IncludesTag(index) => { let includes_tag = &constraints.includes_tags[index.index()]; From 7b2b41869fef36d0aceef03f34c5570ba238ac92 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 20 Apr 2022 14:20:23 -0400 Subject: [PATCH 442/846] Add a way to view solved types of arbitrary expressions/patterns in a program --- Cargo.lock | 6 +- compiler/can/src/lib.rs | 1 + compiler/can/src/pattern.rs | 25 +++ compiler/can/src/traverse.rs | 186 +++++++++++++++++++++++ compiler/constrain/src/expr.rs | 3 +- compiler/region/src/all.rs | 11 ++ compiler/solve/Cargo.toml | 2 + compiler/solve/tests/solve_expr.rs | 236 +++++++++++++++++++++++------ 8 files changed, 421 insertions(+), 49 deletions(-) create mode 100644 compiler/can/src/traverse.rs diff --git a/Cargo.lock b/Cargo.lock index 0690cc0fb7..c33787a696 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3253,9 +3253,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.5.4" +version = "1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" +checksum = "1a11647b6b25ff05a515cb92c365cec08801e83423a235b51e231e1808747286" dependencies = [ "aho-corasick", "memchr", @@ -3955,7 +3955,9 @@ dependencies = [ "arrayvec 0.7.2", "bumpalo", "indoc", + "lazy_static", "pretty_assertions", + "regex", "roc_builtins", "roc_can", "roc_collections", diff --git a/compiler/can/src/lib.rs b/compiler/can/src/lib.rs index 4e90bf4d4d..d7858bcde1 100644 --- a/compiler/can/src/lib.rs +++ b/compiler/can/src/lib.rs @@ -18,3 +18,4 @@ pub mod procedure; mod reference_matrix; pub mod scope; pub mod string; +pub mod traverse; diff --git a/compiler/can/src/pattern.rs b/compiler/can/src/pattern.rs index 9804707b2c..fac8a67365 100644 --- a/compiler/can/src/pattern.rs +++ b/compiler/can/src/pattern.rs @@ -82,6 +82,31 @@ pub enum Pattern { MalformedPattern(MalformedPatternProblem, Region), } +impl Pattern { + pub fn opt_var(&self) -> Option { + use Pattern::*; + match self { + Identifier(_) => None, + + AppliedTag { whole_var, .. } => Some(*whole_var), + UnwrappedOpaque { whole_var, .. } => Some(*whole_var), + RecordDestructure { whole_var, .. } => Some(*whole_var), + NumLiteral(var, ..) => Some(*var), + IntLiteral(var, ..) => Some(*var), + FloatLiteral(var, ..) => Some(*var), + StrLiteral(_) => None, + SingleQuote(_) => None, + Underscore => None, + + AbilityMemberSpecialization { .. } => None, + + Shadowed(..) | OpaqueNotInScope(..) | UnsupportedPattern(..) | MalformedPattern(..) => { + None + } + } + } +} + #[derive(Clone, Debug)] pub struct RecordDestruct { pub var: Variable, diff --git a/compiler/can/src/traverse.rs b/compiler/can/src/traverse.rs new file mode 100644 index 0000000000..fa65bbc3a2 --- /dev/null +++ b/compiler/can/src/traverse.rs @@ -0,0 +1,186 @@ +//! Traversals over the can ast. + +use roc_region::all::{Loc, Region}; +use roc_types::subs::Variable; + +use crate::{ + def::{Annotation, Declaration, Def}, + expr::{ClosureData, Expr, WhenBranch}, + pattern::Pattern, +}; + +macro_rules! visit_list { + ($visitor:ident, $walk:ident, $list:expr) => { + for elem in $list { + $visitor.$walk(elem) + } + }; +} + +fn walk_decls(visitor: &mut V, decls: &[Declaration]) { + visit_list!(visitor, visit_decl, decls) +} + +fn walk_decl(visitor: &mut V, decl: &Declaration) { + match decl { + Declaration::Declare(def) => { + visitor.visit_def(def); + } + Declaration::DeclareRec(defs) => { + visit_list!(visitor, visit_def, defs) + } + Declaration::Builtin(def) => visitor.visit_def(def), + Declaration::InvalidCycle(_cycles) => { + todo!() + } + } +} + +fn walk_def(visitor: &mut V, def: &Def) { + let Def { + loc_pattern, + loc_expr, + annotation, + expr_var, + .. + } = def; + + visitor.visit_pattern( + &loc_pattern.value, + loc_pattern.region, + loc_pattern.value.opt_var(), + ); + visitor.visit_expr(&loc_expr.value, loc_expr.region, *expr_var); + if let Some(annot) = &annotation { + visitor.visit_annotation(&annot); + } +} + +fn walk_expr(visitor: &mut V, expr: &Expr) { + match expr { + Expr::Closure(closure_data) => walk_closure(visitor, closure_data), + Expr::When { + cond_var, + expr_var, + loc_cond, + branches, + region: _, + } => { + walk_when(visitor, *cond_var, *expr_var, loc_cond, branches); + } + e => todo!("{:?}", e), + } +} + +fn walk_closure(visitor: &mut V, clos: &ClosureData) { + let ClosureData { + arguments, + loc_body, + return_type, + .. + } = clos; + + arguments + .iter() + .for_each(|(var, arg)| visitor.visit_pattern(&arg.value, arg.region, Some(*var))); + + visitor.visit_expr(&loc_body.value, loc_body.region, *return_type); +} + +fn walk_when( + visitor: &mut V, + cond_var: Variable, + expr_var: Variable, + loc_cond: &Loc, + branches: &[WhenBranch], +) { + visitor.visit_expr(&loc_cond.value, loc_cond.region, cond_var); + + branches + .iter() + .for_each(|branch| walk_when_branch(visitor, branch, expr_var)); +} + +fn walk_when_branch(visitor: &mut V, branch: &WhenBranch, expr_var: Variable) { + let WhenBranch { + patterns, + value, + guard, + } = branch; + + patterns + .iter() + .for_each(|pat| visitor.visit_pattern(&pat.value, pat.region, pat.value.opt_var())); + visitor.visit_expr(&value.value, value.region, expr_var); + if let Some(guard) = guard { + visitor.visit_expr(&guard.value, guard.region, Variable::BOOL); + } +} + +fn walk_pattern(_visitor: &mut V, pat: &Pattern) { + match pat { + _ => todo!(), + } +} + +trait Visitor: Sized { + fn visit_decls(&mut self, decls: &[Declaration]) { + walk_decls(self, decls); + } + + fn visit_decl(&mut self, decl: &Declaration) { + walk_decl(self, decl); + } + + fn visit_def(&mut self, def: &Def) { + walk_def(self, def); + } + + fn visit_pattern(&mut self, pat: &Pattern, _region: Region, _opt_var: Option) { + walk_pattern(self, pat) + } + + fn visit_annotation(&mut self, _pat: &Annotation) { + // TODO + } + + fn visit_expr(&mut self, expr: &Expr, _region: Region, _var: Variable) { + walk_expr(self, expr); + } +} + +struct TypeAtVisitor { + region: Region, + typ: Option, +} + +impl Visitor for TypeAtVisitor { + fn visit_expr(&mut self, expr: &Expr, region: Region, var: Variable) { + if region == self.region { + debug_assert!(self.typ.is_none()); + self.typ = Some(var); + return; + } + if region.contains(&self.region) { + walk_expr(self, expr); + } + } + + fn visit_pattern(&mut self, pat: &Pattern, region: Region, opt_var: Option) { + if region == self.region { + debug_assert!(self.typ.is_none()); + self.typ = opt_var; + return; + } + if region.contains(&self.region) { + walk_pattern(self, pat) + } + } +} + +/// Attempts to find the type of an expression at `region`, if it exists. +pub fn find_type_at(region: Region, decls: &[Declaration]) -> Option { + let mut visitor = TypeAtVisitor { region, typ: None }; + visitor.visit_decls(decls); + visitor.typ +} diff --git a/compiler/constrain/src/expr.rs b/compiler/constrain/src/expr.rs index 1b820bf762..89ef36e044 100644 --- a/compiler/constrain/src/expr.rs +++ b/compiler/constrain/src/expr.rs @@ -699,7 +699,8 @@ pub fn constrain_expr( // branch_cons.extend(pattern_cons); // branch_constraints.push(constraints.and_constraint(pattern_cons)); let mut total_cons = Vec::with_capacity(1 + 2 * branches.len() + 1); - total_cons.push(expr_con); + // total_cons.push(expr_con); + pattern_cons.push(expr_con); // Solve all the pattern constraints together, introducing variables in the pattern as // need be before solving the bodies. diff --git a/compiler/region/src/all.rs b/compiler/region/src/all.rs index e273cb2a10..3eed5060d5 100644 --- a/compiler/region/src/all.rs +++ b/compiler/region/src/all.rs @@ -377,6 +377,17 @@ impl LineInfo { end: self.convert_pos(region.end()), } } + + pub fn convert_line_column(&self, lc: LineColumn) -> Position { + let offset = self.line_offsets[lc.line as usize] + lc.column; + Position::new(offset) + } + + pub fn convert_line_column_region(&self, lc_region: LineColumnRegion) -> Region { + let start = self.convert_line_column(lc_region.start); + let end = self.convert_line_column(lc_region.end); + Region::new(start, end) + } } #[test] diff --git a/compiler/solve/Cargo.toml b/compiler/solve/Cargo.toml index b78faa8421..1288c18273 100644 --- a/compiler/solve/Cargo.toml +++ b/compiler/solve/Cargo.toml @@ -28,3 +28,5 @@ pretty_assertions = "1.0.0" indoc = "1.0.3" tempfile = "3.2.0" bumpalo = { version = "3.8.0", features = ["collections"] } +regex = "1.5.5" +lazy_static = "1.4.0" diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index da03df77e2..abbfc0160f 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -10,14 +10,54 @@ mod helpers; #[cfg(test)] mod solve_expr { use crate::helpers::with_larger_debug_stack; + use lazy_static::lazy_static; + use regex::Regex; + use roc_can::traverse::find_type_at; use roc_load::LoadedModule; + use roc_module::symbol::{Interns, ModuleId}; + use roc_problem::can::Problem; + use roc_region::all::{LineColumn, LineColumnRegion, LineInfo, Region}; + use roc_reporting::report::{can_problem, type_problem, RocDocAllocator}; + use roc_solve::solve::TypeError; use roc_types::pretty_print::{content_to_string, name_all_type_vars}; + use std::path::PathBuf; // HELPERS - fn run_load_and_infer(src: &str) -> Result { + lazy_static! { + static ref RE_TYPE_QUERY: Regex = Regex::new(r#"^\s*#\s*(?P\^+)\s*$"#).unwrap(); + } + + #[derive(Debug, Clone, Copy)] + struct TypeQuery(Region); + + fn parse_queries(src: &str) -> Vec { + let line_info = LineInfo::new(src); + let mut queries = vec![]; + for (i, line) in src.lines().enumerate() { + if let Some(capture) = RE_TYPE_QUERY.captures(line) { + let wher = capture.name("where").unwrap(); + let (start, end) = (wher.start() as u32, wher.end() as u32); + let last_line = i as u32 - 1; + let start_lc = LineColumn { + line: last_line, + column: start, + }; + let end_lc = LineColumn { + line: last_line, + column: end, + }; + let lc_region = LineColumnRegion::new(start_lc, end_lc); + let region = line_info.convert_line_column_region(lc_region); + + queries.push(TypeQuery(region)); + } + } + queries + } + + fn run_load_and_infer(src: &str) -> Result<(LoadedModule, String), std::io::Error> { use bumpalo::Bump; - use std::path::PathBuf; use tempfile::tempdir; let arena = &Bump::new(); @@ -54,51 +94,78 @@ mod solve_expr { }; let loaded = loaded.expect("failed to load module"); - Ok(loaded) + Ok((loaded, module_src.to_string())) } - fn infer_eq_help( + fn format_problems( src: &str, - ) -> Result< - ( - Vec, - Vec, - String, - ), - std::io::Error, - > { - let LoadedModule { - module_id: home, - mut can_problems, - mut type_problems, - interns, - mut solved, - exposed_to_host, - .. - } = run_load_and_infer(src)?; + home: ModuleId, + interns: &Interns, + can_problems: Vec, + type_problems: Vec, + ) -> (String, String) { + let filename = PathBuf::from("test.roc"); + let src_lines: Vec<&str> = src.split('\n').collect(); + let lines = LineInfo::new(src); + let alloc = RocDocAllocator::new(&src_lines, home, &interns); + + let mut can_reports = vec![]; + let mut type_reports = vec![]; + + for problem in can_problems { + let report = can_problem(&alloc, &lines, filename.clone(), problem.clone()); + can_reports.push(report.pretty(&alloc)); + } + + for problem in type_problems { + if let Some(report) = type_problem(&alloc, &lines, filename.clone(), problem.clone()) { + type_reports.push(report.pretty(&alloc)); + } + } + + let mut can_reports_buf = String::new(); + let mut type_reports_buf = String::new(); + use roc_reporting::report::CiWrite; + alloc + .stack(can_reports) + .1 + .render_raw(70, &mut CiWrite::new(&mut can_reports_buf)) + .unwrap(); + alloc + .stack(type_reports) + .1 + .render_raw(70, &mut CiWrite::new(&mut type_reports_buf)) + .unwrap(); + + (can_reports_buf, type_reports_buf) + } + + fn infer_eq_help(src: &str) -> Result<(String, String, String), std::io::Error> { + let ( + LoadedModule { + module_id: home, + mut can_problems, + mut type_problems, + interns, + mut solved, + exposed_to_host, + .. + }, + src, + ) = run_load_and_infer(src)?; let mut can_problems = can_problems.remove(&home).unwrap_or_default(); let type_problems = type_problems.remove(&home).unwrap_or_default(); + // Disregard UnusedDef problems, because those are unavoidable when + // returning a function from the test expression. + can_problems.retain(|prob| !matches!(prob, roc_problem::can::Problem::UnusedDef(_, _))); + + let (can_problems, type_problems) = + format_problems(&src, home, &interns, can_problems, type_problems); + let subs = solved.inner_mut(); - // assert!(can_problems.is_empty()); - // assert!(type_problems.is_empty()); - // let CanExprOut { - // output, - // var_store, - // var, - // constraint, - // home, - // interns, - // problems: mut can_problems, - // .. - // } = can_expr(src); - // let mut subs = Subs::new(var_store.into()); - - // TODO fix this - // assert_correct_variable_usage(&constraint); - // name type vars for var in exposed_to_host.values() { name_all_type_vars(*var, subs); @@ -112,10 +179,6 @@ mod solve_expr { let actual_str = content_to_string(content, subs, home, &interns); - // Disregard UnusedDef problems, because those are unavoidable when - // returning a function from the test expression. - can_problems.retain(|prob| !matches!(prob, roc_problem::can::Problem::UnusedDef(_, _))); - Ok((type_problems, can_problems, actual_str)) } @@ -143,7 +206,11 @@ mod solve_expr { fn infer_eq(src: &str, expected: &str) { let (_, can_problems, actual) = infer_eq_help(src).unwrap(); - assert_eq!(can_problems, Vec::new(), "Canonicalization problems: "); + assert!( + can_problems.is_empty(), + "Canonicalization problems: {}", + can_problems + ); assert_eq!(actual, expected.to_string()); } @@ -151,16 +218,66 @@ mod solve_expr { fn infer_eq_without_problem(src: &str, expected: &str) { let (type_problems, can_problems, actual) = infer_eq_help(src).unwrap(); - assert_eq!(can_problems, Vec::new(), "Canonicalization problems: "); + assert!( + can_problems.is_empty(), + "Canonicalization problems: {}", + can_problems + ); if !type_problems.is_empty() { // fail with an assert, but print the problems normally so rust doesn't try to diff // an empty vec with the problems. - panic!("expected:\n{:?}\ninferred:\n{:?}", expected, actual); + panic!( + "expected:\n{:?}\ninferred:\n{:?}\nproblems:\n{}", + expected, actual, type_problems, + ); } assert_eq!(actual, expected.to_string()); } + fn infer_queries(src: &str, expected: &[&'static str]) { + let ( + LoadedModule { + module_id: home, + mut can_problems, + mut type_problems, + mut declarations_by_id, + mut solved, + interns, + .. + }, + src, + ) = run_load_and_infer(src).unwrap(); + + let decls = declarations_by_id.remove(&home).unwrap(); + let subs = solved.inner_mut(); + + let can_problems = can_problems.remove(&home).unwrap_or_default(); + let type_problems = type_problems.remove(&home).unwrap_or_default(); + + assert_eq!(can_problems, Vec::new(), "Canonicalization problems: "); + assert_eq!(type_problems, Vec::new(), "Type problems: "); + + let queries = parse_queries(&src); + assert!(!queries.is_empty(), "No queries provided!"); + + let mut solved_queries = Vec::with_capacity(queries.len()); + for TypeQuery(region) in queries.into_iter() { + let start = region.start().offset; + let end = region.end().offset; + let text = &src[start as usize..end as usize]; + let var = find_type_at(region, &decls).expect(&format!("No type for {}!", &text)); + + name_all_type_vars(var, subs); + let content = subs.get_content_without_compacting(var); + let actual_str = content_to_string(content, subs, home, &interns); + + solved_queries.push(format!("{} : {}", text, actual_str)); + } + + assert_eq!(solved_queries, expected) + } + fn check_inferred_abilities<'a, I>(src: &'a str, expected_specializations: I) where I: IntoIterator, @@ -172,7 +289,7 @@ mod solve_expr { interns, abilities_store, .. - } = run_load_and_infer(src).unwrap(); + } = run_load_and_infer(src).unwrap().0; let can_problems = can_problems.remove(&home).unwrap_or_default(); let type_problems = type_problems.remove(&home).unwrap_or_default(); @@ -6033,4 +6150,31 @@ mod solve_expr { "U64", ) } + + #[test] + fn intermediate_branch_types() { + infer_queries( + indoc!( + r#" + app "test" provides [ foo ] to "./platform" + + foo : Bool -> Str + foo = \ob -> + # ^^ + when ob is + # ^^ + True -> "A" + # ^^^^ + False -> "B" + # ^^^^^ + "# + ), + &[ + "ob : Bool", + "ob : [ False, True ]", + "True : [ False, True ]", + "False : [ False, True ]", + ], + ) + } } From 504c3f9b49864a5cfd87ab06e978e87d5a06acbe Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 20 Apr 2022 15:40:50 -0400 Subject: [PATCH 443/846] Delay add "is open" constraint until we know a type variable --- compiler/constrain/src/expr.rs | 23 ++++++++++++++++++----- compiler/constrain/src/pattern.rs | 8 ++++++-- compiler/solve/src/solve.rs | 4 +++- compiler/solve/tests/solve_expr.rs | 27 +++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 8 deletions(-) diff --git a/compiler/constrain/src/expr.rs b/compiler/constrain/src/expr.rs index 89ef36e044..975369b010 100644 --- a/compiler/constrain/src/expr.rs +++ b/compiler/constrain/src/expr.rs @@ -588,7 +588,7 @@ pub fn constrain_expr( // Infer the condition expression's type. let cond_var = *cond_var; let cond_type = Variable(cond_var); - let expr_con = constrain_expr( + let cond_constraint = constrain_expr( constraints, env, region, @@ -647,7 +647,7 @@ pub fn constrain_expr( // constraints. let mut pattern_vars = Vec::with_capacity(branches.len()); let mut pattern_headers = SendMap::default(); - let mut pattern_cons = Vec::with_capacity(branches.len()); + let mut pattern_cons = Vec::with_capacity(branches.len() + 1); let mut branch_cons = Vec::with_capacity(branches.len()); for (index, when_branch) in branches.iter().enumerate() { @@ -698,9 +698,12 @@ pub fn constrain_expr( // the entire when-expression. // branch_cons.extend(pattern_cons); // branch_constraints.push(constraints.and_constraint(pattern_cons)); - let mut total_cons = Vec::with_capacity(1 + 2 * branches.len() + 1); - // total_cons.push(expr_con); - pattern_cons.push(expr_con); + let mut total_cons = Vec::with_capacity(2 * branches.len() + 1); + + // After solving the condition variable with what's expected from the branch patterns, + // check it against the condition expression. + // This is basically exhaustiveness checking, but doesn't check for redundancy. + pattern_cons.push(cond_constraint); // Solve all the pattern constraints together, introducing variables in the pattern as // need be before solving the bodies. @@ -1143,6 +1146,7 @@ fn constrain_when_branch_help( headers: SendMap::default(), vars: Vec::with_capacity(1), constraints: Vec::with_capacity(1), + delayed_is_open_constriants: Vec::new(), }; // TODO investigate for error messages, is it better to unify all branches with a variable, @@ -1172,11 +1176,17 @@ fn constrain_when_branch_help( ); // must introduce the headers from the pattern before constraining the guard + state + .constraints + .extend(state.delayed_is_open_constriants.drain(..)); let state_constraints = constraints.and_constraint(state.constraints); let inner = constraints.let_constraint([], [], [], guard_constraint, ret_constraint); (state_constraints, inner) } else { + state + .constraints + .extend(state.delayed_is_open_constriants.drain(..)); let state_constraints = constraints.and_constraint(state.constraints); (state_constraints, ret_constraint) }; @@ -1268,6 +1278,7 @@ fn constrain_def_pattern( headers: SendMap::default(), vars: Vec::with_capacity(1), constraints: Vec::with_capacity(1), + delayed_is_open_constriants: vec![], }; constrain_pattern( @@ -1365,6 +1376,7 @@ fn constrain_typed_def( headers: SendMap::default(), vars: Vec::with_capacity(arguments.len()), constraints: Vec::with_capacity(1), + delayed_is_open_constriants: vec![], }; let mut vars = Vec::with_capacity(argument_pattern_state.vars.capacity() + 1); let ret_var = *ret_var; @@ -1844,6 +1856,7 @@ pub fn rec_defs_help( headers: SendMap::default(), vars: Vec::with_capacity(arguments.len()), constraints: Vec::with_capacity(1), + delayed_is_open_constriants: vec![], }; let mut vars = Vec::with_capacity(state.vars.capacity() + 1); let mut pattern_types = Vec::with_capacity(state.vars.capacity()); diff --git a/compiler/constrain/src/pattern.rs b/compiler/constrain/src/pattern.rs index 2672602b7b..99e21a3024 100644 --- a/compiler/constrain/src/pattern.rs +++ b/compiler/constrain/src/pattern.rs @@ -18,6 +18,7 @@ pub struct PatternState { pub headers: SendMap>, pub vars: Vec, pub constraints: Vec, + pub delayed_is_open_constriants: Vec, } /// If there is a type annotation, the pattern state headers can be optimized by putting the @@ -180,7 +181,7 @@ pub fn constrain_pattern( // so, we know that "x" (in this case, a tag union) must be open. if could_be_a_tag_union(expected.get_type_ref()) { state - .constraints + .delayed_is_open_constriants .push(constraints.is_open_type(expected.get_type())); } } @@ -191,7 +192,7 @@ pub fn constrain_pattern( Identifier(symbol) | Shadowed(_, _, symbol) => { if could_be_a_tag_union(expected.get_type_ref()) { state - .constraints + .delayed_is_open_constriants .push(constraints.is_open_type(expected.get_type_ref().clone())); } @@ -494,6 +495,9 @@ pub fn constrain_pattern( state.vars.push(*ext_var); state.constraints.push(whole_con); state.constraints.push(tag_con); + state + .constraints + .extend(state.delayed_is_open_constriants.drain(..)); } UnwrappedOpaque { diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index 81784b452e..9e553c354c 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -1183,6 +1183,8 @@ fn solve( let actual = either_type_index_to_var(constraints, subs, rank, pools, aliases, *type_index); + // let content = subs.get_content_without_compacting(actual); + // let fmt = roc_types::subs::SubsFmtContent(&content, subs); let mut stack = vec![actual]; while let Some(var) = stack.pop() { let mut desc = subs.get(var); @@ -1190,7 +1192,7 @@ fn solve( Content::Structure(FlatType::TagUnion(tags, ext)) if matches!( subs.get_content_without_compacting(ext), - Content::Structure(FlatType::EmptyTagUnion) + _ // Content::Structure(FlatType::EmptyTagUnion) ) => { let new_ext = subs.fresh_unnamed_flex_var(); diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index abbfc0160f..209979e536 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -6177,4 +6177,31 @@ mod solve_expr { ], ) } + + #[test] + fn nested_open_tag_union() { + infer_eq_without_problem( + indoc!( + r#" + app "test" provides [ go ] to "./platform" + + Expr : [ + Wrap Expr, + Val I64, + ] + + go : Expr -> Expr + go = \e -> + when P e is + P (Wrap (Val _)) -> Wrap e + + # This branch should force the first argument to `P` and + # the first argument to `Wrap` to be an open tag union. + # This tests checks that we don't regress on that. + P y1 -> Wrap y1 + "# + ), + indoc!(r#"Expr -> Expr"#), + ) + } } From 7c0c0ef02ace02c60a08a4d34ba38379d1c8d67d Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 20 Apr 2022 15:41:30 -0400 Subject: [PATCH 444/846] Add test from #2899 --- reporting/tests/test_reporting.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 8d25660f64..3e233d97fd 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -9954,4 +9954,21 @@ I need all branches in an `if` to have the same type! ), ) } + + fn issue_2899() { + new_report_problem_as( + indoc!( + r#" + foo : Bool -> Str + foo = \bool -> + when bool is + True -> "true" + False -> "false" + Wat -> "surprise!" + foo + "# + ), + indoc!(""), + ) + } } From 627d73e4c094eda3945102f93045f4f3cf8e81d0 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 20 Apr 2022 15:44:21 -0400 Subject: [PATCH 445/846] Clippy --- compiler/can/src/traverse.rs | 8 +++----- compiler/constrain/src/expr.rs | 4 ++-- compiler/constrain/src/pattern.rs | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/compiler/can/src/traverse.rs b/compiler/can/src/traverse.rs index fa65bbc3a2..a1f338c4ca 100644 --- a/compiler/can/src/traverse.rs +++ b/compiler/can/src/traverse.rs @@ -52,7 +52,7 @@ fn walk_def(visitor: &mut V, def: &Def) { ); visitor.visit_expr(&loc_expr.value, loc_expr.region, *expr_var); if let Some(annot) = &annotation { - visitor.visit_annotation(&annot); + visitor.visit_annotation(annot); } } @@ -117,10 +117,8 @@ fn walk_when_branch(visitor: &mut V, branch: &WhenBranch, expr_var: } } -fn walk_pattern(_visitor: &mut V, pat: &Pattern) { - match pat { - _ => todo!(), - } +fn walk_pattern(_visitor: &mut V, _pat: &Pattern) { + todo!() } trait Visitor: Sized { diff --git a/compiler/constrain/src/expr.rs b/compiler/constrain/src/expr.rs index 975369b010..4f229e23ce 100644 --- a/compiler/constrain/src/expr.rs +++ b/compiler/constrain/src/expr.rs @@ -1178,7 +1178,7 @@ fn constrain_when_branch_help( // must introduce the headers from the pattern before constraining the guard state .constraints - .extend(state.delayed_is_open_constriants.drain(..)); + .append(&mut state.delayed_is_open_constriants); let state_constraints = constraints.and_constraint(state.constraints); let inner = constraints.let_constraint([], [], [], guard_constraint, ret_constraint); @@ -1186,7 +1186,7 @@ fn constrain_when_branch_help( } else { state .constraints - .extend(state.delayed_is_open_constriants.drain(..)); + .append(&mut state.delayed_is_open_constriants); let state_constraints = constraints.and_constraint(state.constraints); (state_constraints, ret_constraint) }; diff --git a/compiler/constrain/src/pattern.rs b/compiler/constrain/src/pattern.rs index 99e21a3024..1bc4e2cc7e 100644 --- a/compiler/constrain/src/pattern.rs +++ b/compiler/constrain/src/pattern.rs @@ -497,7 +497,7 @@ pub fn constrain_pattern( state.constraints.push(tag_con); state .constraints - .extend(state.delayed_is_open_constriants.drain(..)); + .append(&mut state.delayed_is_open_constriants); } UnwrappedOpaque { From fd5b682e489334e22d99be92729d86209d1a0189 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 20 Apr 2022 15:44:37 -0400 Subject: [PATCH 446/846] Disable reporting tests for CI checking --- reporting/tests/test_reporting.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 3e233d97fd..4b7a3e997d 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -6,7 +6,7 @@ extern crate roc_reporting; mod helpers; -#[cfg(test)] +#[cfg(never)] mod test_reporting { use crate::helpers::{can_expr, infer_expr, test_home, CanExprOut, ParseErrOut}; use bumpalo::Bump; From 44aa1fca1c45ff21adc6e968b91dd841491f90c4 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 20 Apr 2022 15:52:09 -0400 Subject: [PATCH 447/846] s/constriants/constraints/g --- compiler/constrain/src/expr.rs | 12 ++++++------ compiler/constrain/src/pattern.rs | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/compiler/constrain/src/expr.rs b/compiler/constrain/src/expr.rs index 4f229e23ce..7f6be7bf0a 100644 --- a/compiler/constrain/src/expr.rs +++ b/compiler/constrain/src/expr.rs @@ -1146,7 +1146,7 @@ fn constrain_when_branch_help( headers: SendMap::default(), vars: Vec::with_capacity(1), constraints: Vec::with_capacity(1), - delayed_is_open_constriants: Vec::new(), + delayed_is_open_constraints: Vec::new(), }; // TODO investigate for error messages, is it better to unify all branches with a variable, @@ -1178,7 +1178,7 @@ fn constrain_when_branch_help( // must introduce the headers from the pattern before constraining the guard state .constraints - .append(&mut state.delayed_is_open_constriants); + .append(&mut state.delayed_is_open_constraints); let state_constraints = constraints.and_constraint(state.constraints); let inner = constraints.let_constraint([], [], [], guard_constraint, ret_constraint); @@ -1186,7 +1186,7 @@ fn constrain_when_branch_help( } else { state .constraints - .append(&mut state.delayed_is_open_constriants); + .append(&mut state.delayed_is_open_constraints); let state_constraints = constraints.and_constraint(state.constraints); (state_constraints, ret_constraint) }; @@ -1278,7 +1278,7 @@ fn constrain_def_pattern( headers: SendMap::default(), vars: Vec::with_capacity(1), constraints: Vec::with_capacity(1), - delayed_is_open_constriants: vec![], + delayed_is_open_constraints: vec![], }; constrain_pattern( @@ -1376,7 +1376,7 @@ fn constrain_typed_def( headers: SendMap::default(), vars: Vec::with_capacity(arguments.len()), constraints: Vec::with_capacity(1), - delayed_is_open_constriants: vec![], + delayed_is_open_constraints: vec![], }; let mut vars = Vec::with_capacity(argument_pattern_state.vars.capacity() + 1); let ret_var = *ret_var; @@ -1856,7 +1856,7 @@ pub fn rec_defs_help( headers: SendMap::default(), vars: Vec::with_capacity(arguments.len()), constraints: Vec::with_capacity(1), - delayed_is_open_constriants: vec![], + delayed_is_open_constraints: vec![], }; let mut vars = Vec::with_capacity(state.vars.capacity() + 1); let mut pattern_types = Vec::with_capacity(state.vars.capacity()); diff --git a/compiler/constrain/src/pattern.rs b/compiler/constrain/src/pattern.rs index 1bc4e2cc7e..9f6cc6c468 100644 --- a/compiler/constrain/src/pattern.rs +++ b/compiler/constrain/src/pattern.rs @@ -18,7 +18,7 @@ pub struct PatternState { pub headers: SendMap>, pub vars: Vec, pub constraints: Vec, - pub delayed_is_open_constriants: Vec, + pub delayed_is_open_constraints: Vec, } /// If there is a type annotation, the pattern state headers can be optimized by putting the @@ -181,7 +181,7 @@ pub fn constrain_pattern( // so, we know that "x" (in this case, a tag union) must be open. if could_be_a_tag_union(expected.get_type_ref()) { state - .delayed_is_open_constriants + .delayed_is_open_constraints .push(constraints.is_open_type(expected.get_type())); } } @@ -192,7 +192,7 @@ pub fn constrain_pattern( Identifier(symbol) | Shadowed(_, _, symbol) => { if could_be_a_tag_union(expected.get_type_ref()) { state - .delayed_is_open_constriants + .delayed_is_open_constraints .push(constraints.is_open_type(expected.get_type_ref().clone())); } @@ -497,7 +497,7 @@ pub fn constrain_pattern( state.constraints.push(tag_con); state .constraints - .append(&mut state.delayed_is_open_constriants); + .append(&mut state.delayed_is_open_constraints); } UnwrappedOpaque { From 101ce7c6e8b480d658680f5146786af15283d954 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 20 Apr 2022 16:16:22 -0400 Subject: [PATCH 448/846] Disable mono test for now --- repl_test/src/tests.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/repl_test/src/tests.rs b/repl_test/src/tests.rs index 53b692266c..e4066db2fe 100644 --- a/repl_test/src/tests.rs +++ b/repl_test/src/tests.rs @@ -901,6 +901,7 @@ fn parse_problem() { #[cfg(not(feature = "wasm"))] // TODO: mismatch is due to terminal control codes! #[test] +#[ignore = "temporary"] fn mono_problem() { expect_failure( r#" From 633bdd5520a1b1249022c34f8063aaf13251173b Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 21 Apr 2022 09:07:43 -0400 Subject: [PATCH 449/846] Fix failing reporting tests --- compiler/can/src/expr.rs | 11 ++ compiler/constrain/src/expr.rs | 53 +++--- compiler/types/src/types.rs | 2 + reporting/src/error/type.rs | 121 ++++++++----- reporting/tests/test_reporting.rs | 270 +++++++++++++++++++----------- 5 files changed, 303 insertions(+), 154 deletions(-) diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index 2dade79cd6..aa899ddeb5 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -293,6 +293,17 @@ pub struct WhenBranch { pub guard: Option>, } +impl WhenBranch { + pub fn region(&self) -> Region { + Region::across_all( + self.patterns + .iter() + .map(|p| &p.region) + .chain([self.value.region].iter()), + ) + } +} + pub fn canonicalize_expr<'a>( env: &mut Env<'a>, var_store: &mut VarStore, diff --git a/compiler/constrain/src/expr.rs b/compiler/constrain/src/expr.rs index 7f6be7bf0a..78f82d13e1 100644 --- a/compiler/constrain/src/expr.rs +++ b/compiler/constrain/src/expr.rs @@ -585,20 +585,21 @@ pub fn constrain_expr( branches, .. } => { - // Infer the condition expression's type. let cond_var = *cond_var; let cond_type = Variable(cond_var); - let cond_constraint = constrain_expr( - constraints, - env, - region, - &loc_cond.value, - NoExpectation(cond_type.clone()), - ); let branch_var = *expr_var; let branch_type = Variable(branch_var); + let branches_region = { + debug_assert!(!branches.is_empty()); + Region::span_across( + &loc_cond.region, + // &branches.first().unwrap().region(), + &branches.last().unwrap().region(), + ) + }; + let branch_expr_reason = |expected: &Expected, index, branch_region| match expected { FromAnnotation(name, arity, ann_source, _typ) => { @@ -654,19 +655,24 @@ pub fn constrain_expr( let pattern_region = Region::across_all(when_branch.patterns.iter().map(|v| &v.region)); + let expected_pattern = |sub_pattern| { + PExpected::ForReason( + PReason::WhenMatch { + index: HumanIndex::zero_based(index), + sub_pattern, + }, + cond_type.clone(), + pattern_region, + ) + }; + let (new_pattern_vars, new_pattern_headers, pattern_con, branch_con) = constrain_when_branch_help( constraints, env, region, when_branch, - PExpected::ForReason( - PReason::WhenMatch { - index: HumanIndex::zero_based(index), - }, - cond_type.clone(), - pattern_region, - ), + expected_pattern, branch_expr_reason( &expected, HumanIndex::zero_based(index), @@ -698,11 +704,18 @@ pub fn constrain_expr( // the entire when-expression. // branch_cons.extend(pattern_cons); // branch_constraints.push(constraints.and_constraint(pattern_cons)); - let mut total_cons = Vec::with_capacity(2 * branches.len() + 1); + let mut total_cons = Vec::with_capacity(2); // After solving the condition variable with what's expected from the branch patterns, // check it against the condition expression. // This is basically exhaustiveness checking, but doesn't check for redundancy. + let cond_constraint = constrain_expr( + constraints, + env, + loc_cond.region, + &loc_cond.value, + Expected::ForReason(Reason::WhenBranches, cond_type, branches_region), + ); pattern_cons.push(cond_constraint); // Solve all the pattern constraints together, introducing variables in the pattern as @@ -1126,7 +1139,7 @@ fn constrain_when_branch_help( env: &Env, region: Region, when_branch: &WhenBranch, - pattern_expected: PExpected, + pattern_expected: impl Fn(HumanIndex) -> PExpected, expr_expected: Expected, ) -> ( Vec, @@ -1151,13 +1164,15 @@ fn constrain_when_branch_help( // TODO investigate for error messages, is it better to unify all branches with a variable, // then unify that variable with the expectation? - for loc_pattern in &when_branch.patterns { + for (i, loc_pattern) in when_branch.patterns.iter().enumerate() { + let pattern_expected = pattern_expected(HumanIndex::zero_based(i)); + constrain_pattern( constraints, env, &loc_pattern.value, loc_pattern.region, - pattern_expected.clone(), + pattern_expected, &mut state, ); } diff --git a/compiler/types/src/types.rs b/compiler/types/src/types.rs index 0f3536cd54..53b78b5d59 100644 --- a/compiler/types/src/types.rs +++ b/compiler/types/src/types.rs @@ -1670,6 +1670,7 @@ pub enum PReason { }, WhenMatch { index: HumanIndex, + sub_pattern: HumanIndex, }, TagArg { tag_name: TagName, @@ -1727,6 +1728,7 @@ pub enum Reason { IntLiteral, NumLiteral, StrInterpolation, + WhenBranches, WhenBranch { index: HumanIndex, }, diff --git a/reporting/src/error/type.rs b/reporting/src/error/type.rs index 3e0a301298..71286b58ac 100644 --- a/reporting/src/error/type.rs +++ b/reporting/src/error/type.rs @@ -1151,6 +1151,35 @@ fn to_expr_report<'b>( ) } + Reason::WhenBranches => report_mismatch( + alloc, + lines, + filename, + &category, + found, + expected_type, + // TODO: these should be flipped but `report_mismatch` takes the wrong arguments to + // `region_with_subregion` + expr_region, + Some(region), + alloc.concat([ + alloc.reflow("The branches of this "), + alloc.keyword("when"), + alloc.reflow(" expression don't match the condition:"), + ]), + alloc.concat([ + alloc.reflow("The "), + alloc.keyword("when"), + alloc.reflow(" condition is"), + ]), + alloc.reflow("But the branch patterns have type:"), + Some(alloc.concat([ + alloc.reflow("The branches must be cases of the "), + alloc.keyword("when"), + alloc.reflow(" condition's type!"), + ])), + ), + Reason::LowLevelOpArg { op, arg_index } => { panic!( "Compiler bug: argument #{} to low-level operation {:?} was the wrong type!", @@ -1594,14 +1623,17 @@ fn to_pattern_report<'b>( severity: Severity::RuntimeError, } } - PReason::WhenMatch { index } => { - if index == HumanIndex::FIRST { - let doc = alloc.stack([ + PReason::WhenMatch { index, sub_pattern } => { + let doc = match (index, sub_pattern) { + (HumanIndex::FIRST, HumanIndex::FIRST) => alloc.stack([ alloc .text("The 1st pattern in this ") .append(alloc.keyword("when")) .append(alloc.text(" is causing a mismatch:")), - alloc.region(lines.convert_region(region)), + alloc.region_with_subregion( + lines.convert_region(region), + lines.convert_region(expr_region), + ), pattern_type_comparison( alloc, found, @@ -1620,44 +1652,55 @@ fn to_pattern_report<'b>( ]), vec![], ), - ]); + ]), + (index, sub_pattern) => { + let (first, index) = match sub_pattern { + HumanIndex::FIRST => { + let doc = alloc + .string(format!("The {} pattern in this ", index.ordinal())) + .append(alloc.keyword("when")) + .append(alloc.text(" does not match the previous ones:")); + (doc, index) + } - Report { - filename, - title: "TYPE MISMATCH".to_string(), - doc, - severity: Severity::RuntimeError, - } - } else { - let doc = alloc.stack([ - alloc - .string(format!("The {} pattern in this ", index.ordinal())) - .append(alloc.keyword("when")) - .append(alloc.text(" does not match the previous ones:")), - alloc.region(lines.convert_region(region)), - pattern_type_comparison( - alloc, - found, - expected_type, - add_pattern_category( - alloc, - alloc.string(format!( - "The {} pattern is trying to match", - index.ordinal() - )), - &category, + _ => { + let doc = alloc.string(format!( + "The {} pattern in this branch does not match the previous ones:", + sub_pattern.ordinal() + )); + (doc, sub_pattern) + } + }; + + alloc.stack([ + first, + alloc.region_with_subregion( + lines.convert_region(region), + lines.convert_region(expr_region), ), - alloc.text("But all the previous branches match:"), - vec![], - ), - ]); - - Report { - filename, - title: "TYPE MISMATCH".to_string(), - doc, - severity: Severity::RuntimeError, + pattern_type_comparison( + alloc, + found, + expected_type, + add_pattern_category( + alloc, + alloc.string(format!( + "The {} pattern is trying to match", + index.ordinal() + )), + &category, + ), + alloc.text("But all the previous branches match:"), + vec![], + ), + ]) } + }; + Report { + filename, + title: "TYPE MISMATCH".to_string(), + doc, + severity: Severity::RuntimeError, } } PReason::TagArg { .. } | PReason::PatternGuard => { diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 4b7a3e997d..f4614df125 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -6,7 +6,7 @@ extern crate roc_reporting; mod helpers; -#[cfg(never)] +#[cfg(test)] mod test_reporting { use crate::helpers::{can_expr, infer_expr, test_home, CanExprOut, ParseErrOut}; use bumpalo::Bump; @@ -1667,18 +1667,20 @@ mod test_reporting { r#" ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ - The 1st pattern in this `when` is causing a mismatch: + The branches of this `when` expression don't match the condition: - 2│ {} -> 42 - ^^ + 1│> when 1 is + 2│ {} -> 42 - The first pattern is trying to match record values of type: + The `when` condition is a number of type: + + Num a + + But the branch patterns have type: {}a - But the expression between `when` and `is` has the type: - - Num a + The branches must be cases of the `when` condition's type! "# ), ) @@ -1728,18 +1730,20 @@ mod test_reporting { r#" ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ - The 1st pattern in this `when` is causing a mismatch: + The branches of this `when` expression don't match the condition: - 2│ { foo: True } -> 42 - ^^^^^^^^^^^^^ + 1│> when { foo: 1 } is + 2│ { foo: True } -> 42 - The first pattern is trying to match record values of type: + The `when` condition is a record of type: + + { foo : Num a } + + But the branch patterns have type: { foo : [ True ] } - But the expression between `when` and `is` has the type: - - { foo : Num a } + The branches must be cases of the `when` condition's type! "# ), ) @@ -1758,18 +1762,20 @@ mod test_reporting { r#" ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ - The 1st pattern in this `when` is causing a mismatch: + The branches of this `when` expression don't match the condition: - 2│ { foo: True } -> 42 - ^^^^^^^^^^^^^ + 1│> when { foo: "" } is + 2│ { foo: True } -> 42 - The first pattern is trying to match record values of type: + The `when` condition is a record of type: + + { foo : Str } + + But the branch patterns have type: { foo : [ True ] } - But the expression between `when` and `is` has the type: - - { foo : Str } + The branches must be cases of the `when` condition's type! "# ), ) @@ -1854,18 +1860,18 @@ mod test_reporting { r#" ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ - The 1st pattern in this `when` is causing a mismatch: + The 2nd pattern in this branch does not match the previous ones: 2│ {} | 1 -> 3 - ^^^^^^ + ^ - The first pattern is trying to match numbers: + The 2nd pattern is trying to match numbers: Num a - But the expression between `when` and `is` has the type: + But all the previous branches match: - { foo : Num a } + {}a "# ), ) @@ -2784,20 +2790,31 @@ mod test_reporting { Red -> 3 "# ), + // TODO(2903): improve tag typo quality indoc!( r#" - ── UNSAFE PATTERN ──────────────────────────────────────── /code/proj/Main.roc ─ + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ - This `when` does not cover all the possibilities: + The branches of this `when` expression don't match the condition: 4│> when x is - 5│> Red -> 3 + 5│ Red -> 3 - Other possibilities include: + This `x` value is a: - Green + [ Green, Red ] - I would have to crash if I saw one of those! Add branches for them! + But the branch patterns have type: + + [ Red ] + + The branches must be cases of the `when` condition's type! + + Tip: Seems like a tag typo. Maybe `Green` should be `Red`? + + Tip: Can more type annotations be added? Type annotations always help + me give more specific messages, and I think they could help a lot in + this case "# ), ) @@ -2816,21 +2833,32 @@ mod test_reporting { Green -> 1 "# ), + // TODO(2903): improve tag typo quality indoc!( r#" - ── UNSAFE PATTERN ──────────────────────────────────────── /code/proj/Main.roc ─ + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ - This `when` does not cover all the possibilities: + The branches of this `when` expression don't match the condition: 4│> when x is - 5│> Red -> 0 - 6│> Green -> 1 + 5│ Red -> 0 + 6│ Green -> 1 - Other possibilities include: + This `x` value is a: - Blue + [ Blue, Green, Red ] - I would have to crash if I saw one of those! Add branches for them! + But the branch patterns have type: + + [ Green, Red ] + + The branches must be cases of the `when` condition's type! + + Tip: Seems like a tag typo. Maybe `Blue` should be `Red`? + + Tip: Can more type annotations be added? Type annotations always help + me give more specific messages, and I think they could help a lot in + this case "# ), ) @@ -2849,22 +2877,31 @@ mod test_reporting { NotAsked -> 3 "# ), + // TODO(2903): improve tag typo quality indoc!( r#" - ── UNSAFE PATTERN ──────────────────────────────────────── /code/proj/Main.roc ─ + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ - This `when` does not cover all the possibilities: + The branches of this `when` expression don't match the condition: 5│> when x is - 6│> NotAsked -> 3 + 6│ NotAsked -> 3 - Other possibilities include: + This `x` value is a: - Failure _ - Loading - Success _ + [ Failure I64, Loading, NotAsked, Success Str ] - I would have to crash if I saw one of those! Add branches for them! + But the branch patterns have type: + + [ NotAsked ] + + The branches must be cases of the `when` condition's type! + + Tip: Seems like a tag typo. Maybe `Success` should be `NotAsked`? + + Tip: Can more type annotations be added? Type annotations always help + me give more specific messages, and I think they could help a lot in + this case "# ), ) @@ -4140,18 +4177,20 @@ mod test_reporting { r#" ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ - The 1st pattern in this `when` is causing a mismatch: + The branches of this `when` expression don't match the condition: - 4│ { x, y } -> x + y - ^^^^^^^^ + 3│> when r is + 4│ { x, y } -> x + y - The first pattern is trying to match record values of type: + This `r` value is a: + + { x : I64, y ? I64 } + + But the branch patterns have type: { x : I64, y : I64 } - But the expression between `when` and `is` has the type: - - { x : I64, y ? I64 } + The branches must be cases of the `when` condition's type! Tip: To extract the `.y` field it must be non-optional, but the type says this field is optional. Learn more about optional fields at TODO. @@ -4248,18 +4287,21 @@ mod test_reporting { r#" ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ - The 1st pattern in this `when` is causing a mismatch: + The branches of this `when` expression don't match the condition: - 4│ { x, y : "foo" } -> x + 0 - ^^^^^^^^^^^^^^^^ + 3│> when r is + 4│ { x, y : "foo" } -> x + 0 + 5│ _ -> 0 - The first pattern is trying to match record values of type: + This `r` value is a: + + { x : I64, y : I64 } + + But the branch patterns have type: { x : I64, y : Str } - But the expression between `when` and `is` has the type: - - { x : I64, y : I64 } + The branches must be cases of the `when` condition's type! "# ), ) @@ -4283,18 +4325,21 @@ mod test_reporting { r#" ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ - The 1st pattern in this `when` is causing a mismatch: + The branches of this `when` expression don't match the condition: - 4│ { x, y ? "foo" } -> (\g, _ -> g) x y - ^^^^^^^^^^^^^^^^ + 3│> when r is + 4│ { x, y ? "foo" } -> (\g, _ -> g) x y + 5│ _ -> 0 - The first pattern is trying to match record values of type: + This `r` value is a: + + { x : I64, y ? I64 } + + But the branch patterns have type: { x : I64, y ? Str } - But the expression between `when` and `is` has the type: - - { x : I64, y ? I64 } + The branches must be cases of the `when` condition's type! "# ), ) @@ -7558,11 +7603,6 @@ I need all branches in an `if` to have the same type! typ.get_mut(0..1).unwrap().make_ascii_uppercase(); let bad_suffix = if $suffix == "u8" { "i8" } else { "u8" }; let bad_type = if $suffix == "u8" { "I8" } else { "U8" }; - let carets = "^".repeat(number.len() + $suffix.len()); - let kind = match $suffix { - "dec"|"f32"|"f64" => "floats", - _ => "integers", - }; report_problem_as( &format!(indoc!( @@ -7576,20 +7616,23 @@ I need all branches in an `if` to have the same type! r#" ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ - The 1st pattern in this `when` is causing a mismatch: + The branches of this `when` expression don't match the condition: - 2│ {}{} -> 1 - {} + 1│> when {}{} is + 2│ {}{} -> 1 + 3│ _ -> 1 - The first pattern is trying to match {}: + The `when` condition is an integer of type: {} - But the expression between `when` and `is` has the type: + But the branch patterns have type: {} + + The branches must be cases of the `when` condition's type! "# - ), number, $suffix, carets, kind, typ, bad_type), + ), number, bad_suffix, number, $suffix, bad_type, typ), ) } )*} @@ -8174,18 +8217,21 @@ I need all branches in an `if` to have the same type! r#" ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ - The 1st pattern in this `when` is causing a mismatch: + The branches of this `when` expression don't match the condition: - 2│ 1u8 -> 1 - ^^^ + 1│> when -1 is + 2│ 1u8 -> 1 + 3│ _ -> 1 - The first pattern is trying to match integers: + The `when` condition is a number of type: + + I8, I16, I32, I64, I128, F32, F64, or Dec + + But the branch patterns have type: U8 - But the expression between `when` and `is` has the type: - - I8, I16, I32, I64, I128, F32, F64, or Dec + The branches must be cases of the `when` condition's type! "# ), ) @@ -8668,21 +8714,32 @@ I need all branches in an `if` to have the same type! $F B -> "" "# ), + // TODO(2903): improve tag typo quality indoc!( r#" - ── UNSAFE PATTERN ──────────────────────────────────────── /code/proj/Main.roc ─ + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ - This `when` does not cover all the possibilities: + The branches of this `when` expression don't match the condition: 5│> when v is - 6│> $F A -> "" - 7│> $F B -> "" + 6│ $F A -> "" + 7│ $F B -> "" - Other possibilities include: + This `v` value is a: - $F C + F [ A, B, C ] - I would have to crash if I saw one of those! Add branches for them! + But the branch patterns have type: + + F [ A, B ] + + The branches must be cases of the `when` condition's type! + + Tip: Seems like a tag typo. Maybe `C` should be `A`? + + Tip: Can more type annotations be added? Type annotations always help + me give more specific messages, and I think they could help a lot in + this case "# ), ) @@ -9955,7 +10012,7 @@ I need all branches in an `if` to have the same type! ) } - fn issue_2899() { + fn branches_have_more_cases_than_condition() { new_report_problem_as( indoc!( r#" @@ -9968,7 +10025,28 @@ I need all branches in an `if` to have the same type! foo "# ), - indoc!(""), + indoc!( + r#" + ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + + The branches of this `when` expression don't match the condition: + + 6│> when bool is + 7│ True -> "true" + 8│ False -> "false" + 9│ Wat -> "surprise!" + + This `bool` value is a: + + Bool + + But the branch patterns have type: + + [ False, True, Wat ] + + The branches must be cases of the `when` condition's type! + "# + ), ) } } From 188bd33f1f9a306bad3b1457b83b966755d02422 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 21 Apr 2022 09:19:17 -0400 Subject: [PATCH 450/846] Make sure we only open up closed tag unions --- compiler/solve/src/solve.rs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index 9e553c354c..f78ff9ce59 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -1183,24 +1183,25 @@ fn solve( let actual = either_type_index_to_var(constraints, subs, rank, pools, aliases, *type_index); - // let content = subs.get_content_without_compacting(actual); - // let fmt = roc_types::subs::SubsFmtContent(&content, subs); let mut stack = vec![actual]; while let Some(var) = stack.pop() { + use {Content::*, FlatType::*}; + let mut desc = subs.get(var); match desc.content { - Content::Structure(FlatType::TagUnion(tags, ext)) - if matches!( - subs.get_content_without_compacting(ext), - _ // Content::Structure(FlatType::EmptyTagUnion) - ) => - { - let new_ext = subs.fresh_unnamed_flex_var(); - subs.set_rank(new_ext, desc.rank); - let new_union = Content::Structure(FlatType::TagUnion(tags, new_ext)); - desc.content = new_union; - subs.set(var, desc); + Structure(TagUnion(tags, ext)) => { + match subs.get_content_without_compacting(ext) { + Structure(FlatType::EmptyTagUnion) => { + let new_ext = subs.fresh_unnamed_flex_var(); + subs.set_rank(new_ext, desc.rank); + let new_union = Structure(TagUnion(tags, new_ext)); + desc.content = new_union; + subs.set(var, desc); + } + _ => {} + } + // Also open up all nested tag unions. let all_vars = tags.variables().into_iter(); stack.extend( all_vars.flat_map(|slice| subs[slice]).map(|var| subs[var]), From 435781aa5b94145666e361525976174d22f11ef8 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 21 Apr 2022 09:19:33 -0400 Subject: [PATCH 451/846] Static assertions that certain types implement `Copy` --- compiler/types/src/subs.rs | 3 +++ error_macros/src/lib.rs | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/compiler/types/src/subs.rs b/compiler/types/src/subs.rs index 1a327c85c3..c8b4c1e8ce 100644 --- a/compiler/types/src/subs.rs +++ b/compiler/types/src/subs.rs @@ -2134,6 +2134,9 @@ roc_error_macros::assert_sizeof_aarch64!((Variable, Option), 4 * 8); roc_error_macros::assert_sizeof_wasm!((Variable, Option), 4 * 4); roc_error_macros::assert_sizeof_default!((Variable, Option), 4 * 8); +roc_error_macros::assert_copyable!(Content); +roc_error_macros::assert_copyable!(Descriptor); + #[derive(Clone, Copy, Debug)] pub enum Content { /// A type variable which the user did not name in an annotation, diff --git a/error_macros/src/lib.rs b/error_macros/src/lib.rs index 2cd1eeb732..41ec7b6172 100644 --- a/error_macros/src/lib.rs +++ b/error_macros/src/lib.rs @@ -66,6 +66,14 @@ macro_rules! assert_sizeof_all { }; } +/// Assert that a type has `Copy` +#[macro_export] +macro_rules! assert_copyable { + ($t: ty) => { + static_assertions::assert_impl_all!($t: Copy); + }; +} + // LARGE SCALE PROJECTS // // This section is for "todo!"-style macros enabled in sections where large-scale changes to the From 935a484c71e7ed03c817e7ca6d19c955a16da73f Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 21 Apr 2022 09:24:48 -0400 Subject: [PATCH 452/846] Fix compile error --- compiler/solve/tests/solve_expr.rs | 11 +++++++++-- reporting/tests/test_reporting.rs | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index 209979e536..2411b13df5 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -255,8 +255,15 @@ mod solve_expr { let can_problems = can_problems.remove(&home).unwrap_or_default(); let type_problems = type_problems.remove(&home).unwrap_or_default(); - assert_eq!(can_problems, Vec::new(), "Canonicalization problems: "); - assert_eq!(type_problems, Vec::new(), "Type problems: "); + let (can_problems, type_problems) = + format_problems(&src, home, &interns, can_problems, type_problems); + + assert!( + can_problems.is_empty(), + "Canonicalization problems: {}", + can_problems + ); + assert!(type_problems.is_empty(), "Type problems: {}", type_problems); let queries = parse_queries(&src); assert!(!queries.is_empty(), "No queries provided!"); diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index f4614df125..6918dfd6d9 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -10012,6 +10012,7 @@ I need all branches in an `if` to have the same type! ) } + #[test] fn branches_have_more_cases_than_condition() { new_report_problem_as( indoc!( From 87245def0a21700f46a0945a90d39c0116171ebc Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 21 Apr 2022 09:30:42 -0400 Subject: [PATCH 453/846] Clippy vs McGregor 2047 --- ast/src/constrain.rs | 46 +++++++++++++++++++++++-------------- compiler/solve/src/solve.rs | 44 +++++++++++++++-------------------- 2 files changed, 47 insertions(+), 43 deletions(-) diff --git a/ast/src/constrain.rs b/ast/src/constrain.rs index bd00bbbda5..547b732c0e 100644 --- a/ast/src/constrain.rs +++ b/ast/src/constrain.rs @@ -683,19 +683,24 @@ pub fn constrain_expr<'a>( // when_branch.patterns.iter(env.pool).map(|v| &v.region), // ); + let patten_expected = |sub_pattern| { + PExpected::ForReason( + PReason::WhenMatch { + index: HumanIndex::zero_based(index), + sub_pattern, + }, + cond_type.shallow_clone(), + pattern_region, + ) + }; + let branch_con = constrain_when_branch( arena, env, // TODO: when_branch.value.region, region, when_branch, - PExpected::ForReason( - PReason::WhenMatch { - index: HumanIndex::zero_based(index), - }, - cond_type.shallow_clone(), - pattern_region, - ), + patten_expected, Expected::FromAnnotation( name.clone(), *arity, @@ -726,18 +731,23 @@ pub fn constrain_expr<'a>( // let pattern_region = // Region::across_all(when_branch.patterns.iter().map(|v| &v.region)); + let patten_expected = |sub_pattern| { + PExpected::ForReason( + PReason::WhenMatch { + index: HumanIndex::zero_based(index), + sub_pattern, + }, + cond_type.shallow_clone(), + pattern_region, + ) + }; + let branch_con = constrain_when_branch( arena, env, region, when_branch, - PExpected::ForReason( - PReason::WhenMatch { - index: HumanIndex::zero_based(index), - }, - cond_type.shallow_clone(), - pattern_region, - ), + patten_expected, Expected::ForReason( Reason::WhenBranch { index: HumanIndex::zero_based(index), @@ -1296,7 +1306,7 @@ fn constrain_when_branch<'a>( env: &mut Env, region: Region, when_branch: &WhenBranch, - pattern_expected: PExpected, + pattern_expected: impl Fn(HumanIndex) -> PExpected, expr_expected: Expected, ) -> Constraint<'a> { let when_expr = env.pool.get(when_branch.body); @@ -1311,16 +1321,18 @@ fn constrain_when_branch<'a>( // TODO investigate for error messages, is it better to unify all branches with a variable, // then unify that variable with the expectation? - for pattern_id in when_branch.patterns.iter_node_ids() { + for (sub_pattern, pattern_id) in when_branch.patterns.iter_node_ids().enumerate() { let pattern = env.pool.get(pattern_id); + let pattern_expected = pattern_expected(HumanIndex::zero_based(sub_pattern)); + constrain_pattern( arena, env, pattern, // loc_pattern.region, region, - pattern_expected.shallow_clone(), + pattern_expected, &mut state, true, ); diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index f78ff9ce59..47addd8f51 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -1188,34 +1188,26 @@ fn solve( use {Content::*, FlatType::*}; let mut desc = subs.get(var); - match desc.content { - Structure(TagUnion(tags, ext)) => { - match subs.get_content_without_compacting(ext) { - Structure(FlatType::EmptyTagUnion) => { - let new_ext = subs.fresh_unnamed_flex_var(); - subs.set_rank(new_ext, desc.rank); - let new_union = Structure(TagUnion(tags, new_ext)); - desc.content = new_union; - subs.set(var, desc); - } - _ => {} - } + if let Structure(TagUnion(tags, ext)) = desc.content { + if let Structure(EmptyTagUnion) = subs.get_content_without_compacting(ext) { + let new_ext = subs.fresh_unnamed_flex_var(); + subs.set_rank(new_ext, desc.rank); + let new_union = Structure(TagUnion(tags, new_ext)); + desc.content = new_union; + subs.set(var, desc); + } - // Also open up all nested tag unions. - let all_vars = tags.variables().into_iter(); - stack.extend( - all_vars.flat_map(|slice| subs[slice]).map(|var| subs[var]), - ); - } - _ => { - // Today, an "open" constraint doesn't affect any types - // other than tag unions. Recursive tag unions are constructed - // at a later time (during occurs checks after tag unions are - // resolved), so that's not handled here either. - // NB: Handle record types here if we add presence constraints - // to their type inference as well. - } + // Also open up all nested tag unions. + let all_vars = tags.variables().into_iter(); + stack.extend(all_vars.flat_map(|slice| subs[slice]).map(|var| subs[var])); } + + // Today, an "open" constraint doesn't affect any types + // other than tag unions. Recursive tag unions are constructed + // at a later time (during occurs checks after tag unions are + // resolved), so that's not handled here either. + // NB: Handle record types here if we add presence constraints + // to their type inference as well. } state From 9a341e3d755a0ef8c565b957375f18ca5e089e65 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 21 Apr 2022 10:10:50 -0400 Subject: [PATCH 454/846] Improve non-exhaustive typechecking errors We will replace this with proper exhaustiveness checking when we have that in the typechecking phase, but for now this should do. --- compiler/constrain/src/expr.rs | 4 +- reporting/src/error/type.rs | 119 +++++++++++++++++++++--------- reporting/tests/test_reporting.rs | 36 +++------ 3 files changed, 99 insertions(+), 60 deletions(-) diff --git a/compiler/constrain/src/expr.rs b/compiler/constrain/src/expr.rs index 78f82d13e1..df3806a872 100644 --- a/compiler/constrain/src/expr.rs +++ b/compiler/constrain/src/expr.rs @@ -708,7 +708,9 @@ pub fn constrain_expr( // After solving the condition variable with what's expected from the branch patterns, // check it against the condition expression. - // This is basically exhaustiveness checking, but doesn't check for redundancy. + // TODO: when we have exhaustiveness checking during the typechecking phase, perform + // exhaustiveness checking when this expectation fails. That will produce better error + // messages. let cond_constraint = constrain_expr( constraints, env, diff --git a/reporting/src/error/type.rs b/reporting/src/error/type.rs index 71286b58ac..ca4d9e8c0c 100644 --- a/reporting/src/error/type.rs +++ b/reporting/src/error/type.rs @@ -1151,34 +1151,50 @@ fn to_expr_report<'b>( ) } - Reason::WhenBranches => report_mismatch( - alloc, - lines, - filename, - &category, - found, - expected_type, - // TODO: these should be flipped but `report_mismatch` takes the wrong arguments to - // `region_with_subregion` - expr_region, - Some(region), - alloc.concat([ - alloc.reflow("The branches of this "), - alloc.keyword("when"), - alloc.reflow(" expression don't match the condition:"), - ]), - alloc.concat([ + Reason::WhenBranches => { + let snippet = alloc.region_with_subregion( + lines.convert_region(region), + lines.convert_region(expr_region), + ); + + let this_is = alloc.concat([ alloc.reflow("The "), alloc.keyword("when"), alloc.reflow(" condition is"), - ]), - alloc.reflow("But the branch patterns have type:"), - Some(alloc.concat([ + ]); + + let wanted = alloc.reflow("But the branch patterns have type:"); + let details = Some(alloc.concat([ alloc.reflow("The branches must be cases of the "), alloc.keyword("when"), alloc.reflow(" condition's type!"), - ])), - ), + ])); + + let lines = [ + alloc.concat([ + alloc.reflow("The branches of this "), + alloc.keyword("when"), + alloc.reflow(" expression don't match the condition:"), + ]), + snippet, + type_comparison( + alloc, + found, + expected_type, + ExpectationContext::WhenCondition, + add_category(alloc, this_is, &category), + wanted, + details, + ), + ]; + + Report { + title: "TYPE MISMATCH".to_string(), + filename, + doc: alloc.stack(lines), + severity: Severity::RuntimeError, + } + } Reason::LowLevelOpArg { op, arg_index } => { panic!( @@ -1253,7 +1269,10 @@ fn count_arguments(tipe: &ErrorType) -> usize { enum ExpectationContext<'a> { /// An expected type was discovered from a type annotation. Corresponds to /// [`Expected::FromAnnotation`](Expected::FromAnnotation). - Annotation { on: RocDocBuilder<'a> }, + Annotation { + on: RocDocBuilder<'a>, + }, + WhenCondition, /// When we don't know the context, or it's not relevant. Arbitrary, } @@ -1262,6 +1281,7 @@ impl<'a> std::fmt::Debug for ExpectationContext<'a> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { ExpectationContext::Annotation { .. } => f.write_str("Annotation"), + ExpectationContext::WhenCondition => f.write_str("WhenCondition"), ExpectationContext::Arbitrary => f.write_str("Arbitrary"), } } @@ -2679,22 +2699,24 @@ fn diff_tag_union<'b>( let all_fields_shared = left.peek().is_none() && right.peek().is_none(); let status = match (ext_has_fixed_fields(&ext1), ext_has_fixed_fields(&ext2)) { - (true, true) => match left.peek() { - Some((f, _, _, _)) => Status::Different(vec![Problem::TagTypo( + (true, true) => match (left.peek(), right.peek()) { + (Some((f, _, _, _)), Some(_)) => Status::Different(vec![Problem::TagTypo( f.clone(), fields2.keys().cloned().collect(), )]), - None => { - if right.peek().is_none() { - Status::Similar - } else { - let result = - Status::Different(vec![Problem::TagsMissing(right.map(|v| v.0).collect())]); - // we just used the values in `right`. in - right = right_keys.iter().map(to_unknown_docs).peekable(); - result - } + (Some(_), None) => { + let status = + Status::Different(vec![Problem::TagsMissing(left.map(|v| v.0).collect())]); + left = left_keys.iter().map(to_unknown_docs).peekable(); + status } + (None, Some(_)) => { + let status = + Status::Different(vec![Problem::TagsMissing(right.map(|v| v.0).collect())]); + right = right_keys.iter().map(to_unknown_docs).peekable(); + status + } + (None, None) => Status::Similar, }, (false, true) => match left.peek() { Some((f, _, _, _)) => Status::Different(vec![Problem::TagTypo( @@ -3294,6 +3316,33 @@ fn type_problem_to_pretty<'b>( alloc.reflow("."), ])), + (TagsMissing(missing), ExpectationContext::WhenCondition) => match missing.split_last() { + None => alloc.nil(), + Some(split) => { + let missing_tags = match split { + (f1, []) => alloc.tag_name(f1.clone()).append(alloc.reflow(" tag.")), + (last, init) => alloc + .intersperse(init.iter().map(|v| alloc.tag_name(v.clone())), ", ") + .append(alloc.reflow(" and ")) + .append(alloc.tag_name(last.clone())) + .append(alloc.reflow(" tags.")), + }; + + let tip1 = alloc + .tip() + .append(alloc.reflow("Looks like the branches are missing coverage of the ")) + .append(missing_tags); + + let tip2 = alloc + .tip() + .append(alloc.reflow("Maybe you need to add a catch-all branch, like ")) + .append(alloc.keyword("_")) + .append(alloc.reflow("?")); + + alloc.stack([tip1, tip2]) + } + }, + (TagsMissing(missing), _) => match missing.split_last() { None => alloc.nil(), Some((f1, [])) => { diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 6918dfd6d9..a1b0e4b69c 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -2740,11 +2740,10 @@ mod test_reporting { [ Left a ] - Tip: Seems like a tag typo. Maybe `Right` should be `Left`? + Tip: Looks like a closed tag union does not have the `Right` tag. - Tip: Can more type annotations be added? Type annotations always help - me give more specific messages, and I think they could help a lot in - this case + Tip: Closed tag unions can't grow, because that might change the size + in memory. Can you use an open tag union? "# ), ) @@ -2790,7 +2789,6 @@ mod test_reporting { Red -> 3 "# ), - // TODO(2903): improve tag typo quality indoc!( r#" ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ @@ -2810,11 +2808,9 @@ mod test_reporting { The branches must be cases of the `when` condition's type! - Tip: Seems like a tag typo. Maybe `Green` should be `Red`? + Tip: Looks like the branches are missing coverage of the `Green` tag. - Tip: Can more type annotations be added? Type annotations always help - me give more specific messages, and I think they could help a lot in - this case + Tip: Maybe you need to add a catch-all branch, like `_`? "# ), ) @@ -2833,7 +2829,6 @@ mod test_reporting { Green -> 1 "# ), - // TODO(2903): improve tag typo quality indoc!( r#" ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ @@ -2854,11 +2849,9 @@ mod test_reporting { The branches must be cases of the `when` condition's type! - Tip: Seems like a tag typo. Maybe `Blue` should be `Red`? + Tip: Looks like the branches are missing coverage of the `Blue` tag. - Tip: Can more type annotations be added? Type annotations always help - me give more specific messages, and I think they could help a lot in - this case + Tip: Maybe you need to add a catch-all branch, like `_`? "# ), ) @@ -2877,7 +2870,6 @@ mod test_reporting { NotAsked -> 3 "# ), - // TODO(2903): improve tag typo quality indoc!( r#" ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ @@ -2897,11 +2889,10 @@ mod test_reporting { The branches must be cases of the `when` condition's type! - Tip: Seems like a tag typo. Maybe `Success` should be `NotAsked`? + Tip: Looks like the branches are missing coverage of the + `Success`, `Failure` and `Loading` tags. - Tip: Can more type annotations be added? Type annotations always help - me give more specific messages, and I think they could help a lot in - this case + Tip: Maybe you need to add a catch-all branch, like `_`? "# ), ) @@ -8714,7 +8705,6 @@ I need all branches in an `if` to have the same type! $F B -> "" "# ), - // TODO(2903): improve tag typo quality indoc!( r#" ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ @@ -8735,11 +8725,9 @@ I need all branches in an `if` to have the same type! The branches must be cases of the `when` condition's type! - Tip: Seems like a tag typo. Maybe `C` should be `A`? + Tip: Looks like the branches are missing coverage of the `C` tag. - Tip: Can more type annotations be added? Type annotations always help - me give more specific messages, and I think they could help a lot in - this case + Tip: Maybe you need to add a catch-all branch, like `_`? "# ), ) From 5840693743e4be4b5b3b2a25955096c02b8aa802 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 23 Apr 2022 16:57:28 +0200 Subject: [PATCH 455/846] use vectors instead of maps --- compiler/can/src/def.rs | 206 ++++++++++++++++++++++++---------------- 1 file changed, 123 insertions(+), 83 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 1e8b13f49d..66b58b866d 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -11,7 +11,7 @@ use crate::reference_matrix::ReferenceMatrix; use crate::reference_matrix::TopologicalSort; use crate::scope::create_alias; use crate::scope::Scope; -use roc_collections::{default_hasher, ImEntry, ImMap, ImSet, MutMap, MutSet, SendMap}; +use roc_collections::{ImEntry, ImMap, ImSet, MutMap, MutSet, SendMap}; use roc_module::ident::Lowercase; use roc_module::symbol::IdentId; use roc_module::symbol::ModuleId; @@ -28,7 +28,6 @@ use roc_types::subs::{VarStore, Variable}; use roc_types::types::AliasKind; use roc_types::types::LambdaSet; use roc_types::types::{Alias, Type}; -use std::collections::HashMap; use std::fmt::Debug; use ven_graph::topological_sort; @@ -50,10 +49,12 @@ pub struct Annotation { } #[derive(Debug)] -pub struct CanDefs { - pub refs_by_symbol: MutMap, - pub can_defs_by_symbol: MutMap, - pub aliases: SendMap, +pub(crate) struct CanDefs { + symbol_to_index: Vec<(IdentId, u32)>, + defs: Vec, + references: Vec<(References, Region)>, + + aliases: SendMap, } /// A Def that has had patterns and type annnotations canonicalized, @@ -205,7 +206,7 @@ fn sort_type_defs_before_introduction( } #[inline(always)] -pub fn canonicalize_defs<'a>( +pub(crate) fn canonicalize_defs<'a>( env: &mut Env<'a>, mut output: Output, var_store: &mut VarStore, @@ -234,7 +235,6 @@ pub fn canonicalize_defs<'a>( // so we can diff them while detecting unused defs. let mut scope = original_scope.clone(); let num_defs = loc_defs.len(); - let mut refs_by_symbol = MutMap::default(); let mut type_defs = Vec::with_capacity(num_defs); let mut value_defs = Vec::with_capacity(num_defs); @@ -489,7 +489,7 @@ pub fn canonicalize_defs<'a>( } } - let mut symbol_to_id: Vec<(IdentId, u32)> = Vec::with_capacity(pending_value_defs.len()); + let mut symbol_to_index: Vec<(IdentId, u32)> = Vec::with_capacity(pending_value_defs.len()); for (def_index, pending_def) in pending_value_defs.iter().enumerate() { for (s, _) in bindings_from_patterns(std::iter::once(pending_def.loc_pattern())) { @@ -499,23 +499,22 @@ pub fn canonicalize_defs<'a>( } debug_assert_eq!(env.home, s.module_id()); - debug_assert!(!symbol_to_id.iter().any(|(id, _)| *id == s.ident_id())); + debug_assert!(!symbol_to_index.iter().any(|(id, _)| *id == s.ident_id())); - symbol_to_id.push((s.ident_id(), def_index as u32)); + symbol_to_index.push((s.ident_id(), def_index as u32)); } } // let mut def_order = DefOrdering::from_symbol_to_id(env.home, symbol_to_id); - let mut can_defs_by_symbol = HashMap::with_capacity_and_hasher(num_defs, default_hasher()); - // env.home.register_debug_idents(&env.ident_ids); + let mut defs = Vec::with_capacity(pending_value_defs.len()); + let mut references = Vec::with_capacity(pending_value_defs.len()); + for pending_def in pending_value_defs.into_iter() { let region = pending_def.loc_pattern().region; - let bindings = bindings_from_patterns(std::iter::once(pending_def.loc_pattern())); - let temp_output = canonicalize_pending_value_def_new( env, pending_def, @@ -528,10 +527,8 @@ pub fn canonicalize_defs<'a>( output = temp_output.output; - for (symbol, _) in bindings { - can_defs_by_symbol.insert(symbol, temp_output.def.clone()); - refs_by_symbol.insert(symbol, (region, temp_output.references.clone())); - } + defs.push(temp_output.def); + references.push((temp_output.references, region)); } // Determine which idents we introduced in the course of this process. @@ -555,8 +552,9 @@ pub fn canonicalize_defs<'a>( // defs need to get moved later. ( CanDefs { - refs_by_symbol, - can_defs_by_symbol, + symbol_to_index, + defs, + references, // The result needs a thread-safe `SendMap` aliases: aliases.into_iter().collect(), }, @@ -723,15 +721,15 @@ struct DefOrdering { } impl DefOrdering { - fn with_capacity(home: ModuleId, capacity: usize) -> Self { - Self { - home, - symbol_to_id: Vec::with_capacity(capacity), - references: ReferenceMatrix::new(capacity), - direct_references: ReferenceMatrix::new(capacity), - length: capacity as u32, - } - } + // fn with_capacity(home: ModuleId, capacity: usize) -> Self { + // Self { + // home, + // symbol_to_id: Vec::with_capacity(capacity), + // references: ReferenceMatrix::new(capacity), + // direct_references: ReferenceMatrix::new(capacity), + // length: capacity as u32, + // } + // } // fn from_symbol_to_id(home: ModuleId, symbol_to_id: Vec<(IdentId, u32)>) -> Self { // let capacity = symbol_to_id.len(); @@ -747,37 +745,59 @@ impl DefOrdering { fn from_defs_by_symbol( env: &Env, - can_defs_by_symbol: &MutMap, - refs_by_symbol: &MutMap, + symbol_to_id: Vec<(IdentId, u32)>, + references: &[(References, Region)], + capacity: usize, ) -> Self { - let mut this = Self::with_capacity(env.home, can_defs_by_symbol.len()); + // because of `Pair a b = someDef` patterns, we can have more symbols than defs + debug_assert!(symbol_to_id.len() >= capacity); - for (i, symbol) in can_defs_by_symbol.keys().enumerate() { - debug_assert_eq!(env.home, symbol.module_id()); + let mut this = Self { + home: env.home, + symbol_to_id, + references: ReferenceMatrix::new(capacity), + direct_references: ReferenceMatrix::new(capacity), + length: capacity as u32, + }; - this.symbol_to_id.push((symbol.ident_id(), i as u32)); - } - - for (symbol, (_, references)) in refs_by_symbol.iter() { - let def_id = this.get_id(*symbol).unwrap(); + for (ident_id, def_id) in this.symbol_to_id.iter() { + let def_id = *def_id; + let references = &references[def_id as usize].0; + let symbol = Symbol::new(this.home, *ident_id); for referenced in references.value_lookups() { - this.register_reference(def_id, *referenced); - this.register_direct_reference(def_id, *referenced); + if let Some(ref_id) = this.get_id(*referenced) { + this.references + .set_row_col(def_id as usize, ref_id as usize, true); + + this.direct_references + .set_row_col(def_id as usize, ref_id as usize, true); + } } for referenced in references.calls() { - this.register_reference(def_id, *referenced); - this.register_direct_reference(def_id, *referenced); + if let Some(ref_id) = this.get_id(*referenced) { + this.references + .set_row_col(def_id as usize, ref_id as usize, true); + + this.direct_references + .set_row_col(def_id as usize, ref_id as usize, true); + } } - if let Some(references) = env.closures.get(symbol) { + if let Some(references) = env.closures.get(&symbol) { for referenced in references.value_lookups() { - this.register_reference(def_id, *referenced); + if let Some(ref_id) = this.get_id(*referenced) { + this.references + .set_row_col(def_id as usize, ref_id as usize, true); + } } for referenced in references.calls() { - this.register_reference(def_id, *referenced); + if let Some(ref_id) = this.get_id(*referenced) { + this.references + .set_row_col(def_id as usize, ref_id as usize, true); + } } } } @@ -785,6 +805,46 @@ impl DefOrdering { this } + // fn from_defs_by_symbol_old( + // env: &Env, + // can_defs_by_symbol: &MutMap, + // refs_by_symbol: &MutMap, + // ) -> Self { + // let mut this = Self::with_capacity(env.home, can_defs_by_symbol.len()); + // + // for (i, symbol) in can_defs_by_symbol.keys().enumerate() { + // debug_assert_eq!(env.home, symbol.module_id()); + // + // this.symbol_to_id.push((symbol.ident_id(), i as u32)); + // } + // + // for (symbol, (_, references)) in refs_by_symbol.iter() { + // let def_id = this.get_id(*symbol).unwrap(); + // + // for referenced in references.value_lookups() { + // this.register_reference(def_id, *referenced); + // this.register_direct_reference(def_id, *referenced); + // } + // + // for referenced in references.calls() { + // this.register_reference(def_id, *referenced); + // this.register_direct_reference(def_id, *referenced); + // } + // + // if let Some(references) = env.closures.get(symbol) { + // for referenced in references.value_lookups() { + // this.register_reference(def_id, *referenced); + // } + // + // for referenced in references.calls() { + // this.register_reference(def_id, *referenced); + // } + // } + // } + // + // this + // } + fn get_id(&self, symbol: Symbol) -> Option { if symbol.module_id() != self.home { return None; @@ -811,20 +871,6 @@ impl DefOrdering { None } - fn register_direct_reference(&mut self, id: u32, referenced: Symbol) { - if let Some(ref_id) = self.get_id(referenced) { - self.direct_references - .set_row_col(id as usize, ref_id as usize, true); - } - } - - fn register_reference(&mut self, id: u32, referenced: Symbol) { - if let Some(ref_id) = self.get_id(referenced) { - self.references - .set_row_col(id as usize, ref_id as usize, true); - } - } - fn is_self_recursive(&self, id: u32) -> bool { debug_assert!(id < self.length); @@ -848,20 +894,20 @@ impl DefOrdering { } #[inline(always)] -pub fn sort_can_defs( +pub(crate) fn sort_can_defs( env: &mut Env<'_>, defs: CanDefs, mut output: Output, ) -> (Result, RuntimeError>, Output) { - let def_ids = - DefOrdering::from_defs_by_symbol(env, &defs.can_defs_by_symbol, &defs.refs_by_symbol); - let CanDefs { - refs_by_symbol, - mut can_defs_by_symbol, + symbol_to_index, + defs, + references, aliases, } = defs; + let def_ids = DefOrdering::from_defs_by_symbol(env, symbol_to_index, &references, defs.len()); + for (symbol, alias) in aliases.into_iter() { output.aliases.insert(symbol, alias); } @@ -874,13 +920,7 @@ pub fn sort_can_defs( // groups are in reversed order for group in groups.into_iter().rev() { - group_to_declaration( - &def_ids, - &group, - &env.closures, - &mut can_defs_by_symbol, - &mut declarations, - ); + group_to_declaration(&def_ids, &group, &env.closures, &defs, &mut declarations); } (Ok(declarations), output) @@ -931,14 +971,14 @@ pub fn sort_can_defs( for def_id in &cycle { let symbol = def_ids.get_symbol(*def_id).unwrap(); - match refs_by_symbol.get(&symbol) { + match references.get(*def_id as usize) { None => unreachable!( - r#"Symbol `{:?}` not found in refs_by_symbol! refs_by_symbol was: {:?}"#, - symbol, refs_by_symbol + r#"Symbol `{:?}` not found in references! references was: {:?}"#, + symbol, references ), - Some((region, _)) => { + Some((_, region)) => { let expr_region = - can_defs_by_symbol.get(&symbol).unwrap().loc_expr.region; + defs.get(*def_id as usize).unwrap().loc_expr.region; let entry = CycleEntry { symbol, @@ -1016,7 +1056,7 @@ pub fn sort_can_defs( &def_ids, group, &env.closures, - &mut can_defs_by_symbol, + &defs, &mut declarations, ); } @@ -1038,7 +1078,7 @@ fn group_to_declaration( def_ids: &DefOrdering, group: &[u32], closures: &MutMap, - can_defs_by_symbol: &mut MutMap, + defs: &[Def], declarations: &mut Vec, ) { use Declaration::*; @@ -1059,7 +1099,7 @@ fn group_to_declaration( let def_id = cycle[0]; let symbol = def_ids.get_symbol(def_id).unwrap(); - match can_defs_by_symbol.remove(&symbol) { + match defs.get(def_id as usize).cloned() { Some(mut new_def) => { // there is only one definition in this cycle, so we only have // to check whether it recurses with itself; there is nobody else @@ -1094,7 +1134,7 @@ fn group_to_declaration( // Topological sort gives us the reverse of the sorting we want! for def_id in cycle.into_iter().rev() { let symbol = def_ids.get_symbol(def_id).unwrap(); - match can_defs_by_symbol.remove(&symbol) { + match defs.get(def_id as usize).cloned() { Some(mut new_def) => { // Determine recursivity of closures that are not tail-recursive if let Closure(ClosureData { From c62496928614c88fedf885cf277cc1d7ab98bd1a Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 21 Apr 2022 10:16:02 -0400 Subject: [PATCH 456/846] Turn repl test back on --- repl_test/src/tests.rs | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/repl_test/src/tests.rs b/repl_test/src/tests.rs index e4066db2fe..dd34a863ac 100644 --- a/repl_test/src/tests.rs +++ b/repl_test/src/tests.rs @@ -901,8 +901,7 @@ fn parse_problem() { #[cfg(not(feature = "wasm"))] // TODO: mismatch is due to terminal control codes! #[test] -#[ignore = "temporary"] -fn mono_problem() { +fn exhautiveness_problem() { expect_failure( r#" t : [A, B, C] @@ -913,22 +912,29 @@ fn mono_problem() { "#, indoc!( r#" - ── UNSAFE PATTERN ────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ──────────────────────────────────────────────────── REPL.roc ─ - This when does not cover all the possibilities: + This expression is used in an unexpected way: - 7│> when t is - 8│> A -> "a" + 7│> when t is + 8│> A -> "a" - Other possibilities include: + This t value is a: - B - C - - I would have to crash if I saw one of those! Add branches for them! - - - Enter an expression, or :help, or :exit/:q."# + [ A, B, C ] + + But you are trying to use it as: + + [ A ] + + Tip: Seems like a tag typo. Maybe C should be A? + + Tip: Can more type annotations be added? Type annotations always help + me give more specific messages, and I think they could help a lot in + this case + + + Enter an expression, or :help, or :exit/:q."# ), ); } From 5ebae63c0f1f835ad430d23c0fb85913e1e22570 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 21 Apr 2022 10:58:40 -0400 Subject: [PATCH 457/846] Fix mono test --- repl_test/src/tests.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/repl_test/src/tests.rs b/repl_test/src/tests.rs index dd34a863ac..d8087e936a 100644 --- a/repl_test/src/tests.rs +++ b/repl_test/src/tests.rs @@ -901,7 +901,7 @@ fn parse_problem() { #[cfg(not(feature = "wasm"))] // TODO: mismatch is due to terminal control codes! #[test] -fn exhautiveness_problem() { +fn exhaustiveness_problem() { expect_failure( r#" t : [A, B, C] @@ -914,24 +914,24 @@ fn exhautiveness_problem() { r#" ── TYPE MISMATCH ──────────────────────────────────────────────────── REPL.roc ─ - This expression is used in an unexpected way: + The branches of this when expression don't match the condition: 7│> when t is - 8│> A -> "a" + 8│ A -> "a" This t value is a: [ A, B, C ] - But you are trying to use it as: + But the branch patterns have type: [ A ] + + The branches must be cases of the when condition's type! - Tip: Seems like a tag typo. Maybe C should be A? + Tip: Looks like the branches are missing coverage of the C and B tags. - Tip: Can more type annotations be added? Type annotations always help - me give more specific messages, and I think they could help a lot in - this case + Tip: Maybe you need to add a catch-all branch, like _? Enter an expression, or :help, or :exit/:q."# From 27a421fce64382480da42c6a9f888c57adf2c785 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 21 Apr 2022 14:18:21 -0400 Subject: [PATCH 458/846] Fix reporting test --- reporting/tests/test_reporting.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index a1b0e4b69c..39d13b4308 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -10003,6 +10003,7 @@ I need all branches in an `if` to have the same type! #[test] fn branches_have_more_cases_than_condition() { new_report_problem_as( + "branches_have_more_cases_than_condition", indoc!( r#" foo : Bool -> Str @@ -10016,7 +10017,7 @@ I need all branches in an `if` to have the same type! ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ The branches of this `when` expression don't match the condition: From 6422c55899ab85c135b75c3433719064b56fb7c8 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 22 Apr 2022 16:02:53 -0400 Subject: [PATCH 459/846] Fix mono test --- repl_test/src/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repl_test/src/tests.rs b/repl_test/src/tests.rs index d8087e936a..a50fb77495 100644 --- a/repl_test/src/tests.rs +++ b/repl_test/src/tests.rs @@ -912,7 +912,7 @@ fn exhaustiveness_problem() { "#, indoc!( r#" - ── TYPE MISMATCH ──────────────────────────────────────────────────── REPL.roc ─ + ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── The branches of this when expression don't match the condition: From 002327e2753b4fdff2f09b40dc3cceb6b34ea80e Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 23 Apr 2022 17:14:02 +0200 Subject: [PATCH 460/846] don't clone the defs --- compiler/can/src/def.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 66b58b866d..b4a055a21e 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -51,7 +51,7 @@ pub struct Annotation { #[derive(Debug)] pub(crate) struct CanDefs { symbol_to_index: Vec<(IdentId, u32)>, - defs: Vec, + defs: Vec>, references: Vec<(References, Region)>, aliases: SendMap, @@ -527,7 +527,7 @@ pub(crate) fn canonicalize_defs<'a>( output = temp_output.output; - defs.push(temp_output.def); + defs.push(Some(temp_output.def)); references.push((temp_output.references, region)); } @@ -901,7 +901,7 @@ pub(crate) fn sort_can_defs( ) -> (Result, RuntimeError>, Output) { let CanDefs { symbol_to_index, - defs, + mut defs, references, aliases, } = defs; @@ -920,7 +920,13 @@ pub(crate) fn sort_can_defs( // groups are in reversed order for group in groups.into_iter().rev() { - group_to_declaration(&def_ids, &group, &env.closures, &defs, &mut declarations); + group_to_declaration( + &def_ids, + &group, + &env.closures, + &mut defs, + &mut declarations, + ); } (Ok(declarations), output) @@ -978,7 +984,7 @@ pub(crate) fn sort_can_defs( ), Some((_, region)) => { let expr_region = - defs.get(*def_id as usize).unwrap().loc_expr.region; + defs[*def_id as usize].as_ref().unwrap().loc_expr.region; let entry = CycleEntry { symbol, @@ -1056,7 +1062,7 @@ pub(crate) fn sort_can_defs( &def_ids, group, &env.closures, - &defs, + &mut defs, &mut declarations, ); } @@ -1078,7 +1084,7 @@ fn group_to_declaration( def_ids: &DefOrdering, group: &[u32], closures: &MutMap, - defs: &[Def], + defs: &mut [Option], declarations: &mut Vec, ) { use Declaration::*; @@ -1099,7 +1105,7 @@ fn group_to_declaration( let def_id = cycle[0]; let symbol = def_ids.get_symbol(def_id).unwrap(); - match defs.get(def_id as usize).cloned() { + match defs[def_id as usize].take() { Some(mut new_def) => { // there is only one definition in this cycle, so we only have // to check whether it recurses with itself; there is nobody else @@ -1134,7 +1140,7 @@ fn group_to_declaration( // Topological sort gives us the reverse of the sorting we want! for def_id in cycle.into_iter().rev() { let symbol = def_ids.get_symbol(def_id).unwrap(); - match defs.get(def_id as usize).cloned() { + match defs[def_id as usize].take() { Some(mut new_def) => { // Determine recursivity of closures that are not tail-recursive if let Closure(ClosureData { From bf4462c79a18f8fbed84a74a0660af86a2e4583b Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 23 Apr 2022 19:16:06 +0200 Subject: [PATCH 461/846] consider `_ = someDef` definitions, where there is no symbol --- compiler/can/src/def.rs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index b4a055a21e..3a41ce3329 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -749,8 +749,8 @@ impl DefOrdering { references: &[(References, Region)], capacity: usize, ) -> Self { - // because of `Pair a b = someDef` patterns, we can have more symbols than defs - debug_assert!(symbol_to_id.len() >= capacity); + // NOTE: because of `Pair a b = someDef` patterns, we can have more symbols than defs + // but because `_ = someDef` we can also have more defs than symbols let mut this = Self { home: env.home, @@ -1103,7 +1103,6 @@ fn group_to_declaration( for cycle in sccs { if cycle.len() == 1 { let def_id = cycle[0]; - let symbol = def_ids.get_symbol(def_id).unwrap(); match defs[def_id as usize].take() { Some(mut new_def) => { @@ -1132,23 +1131,28 @@ fn group_to_declaration( } } } - None => roc_error_macros::internal_error!("def not available {:?}", symbol), + None => { + // NOTE: a `_ = someDef` can mean we don't have a symbol here + let symbol = def_ids.get_symbol(def_id); + + roc_error_macros::internal_error!("def not available {:?}", symbol) + } } } else { let mut can_defs = Vec::new(); // Topological sort gives us the reverse of the sorting we want! for def_id in cycle.into_iter().rev() { - let symbol = def_ids.get_symbol(def_id).unwrap(); match defs[def_id as usize].take() { Some(mut new_def) => { // Determine recursivity of closures that are not tail-recursive if let Closure(ClosureData { recursive: recursive @ Recursive::NotRecursive, + name, .. }) = &mut new_def.loc_expr.value { - *recursive = closure_recursivity(symbol, closures); + *recursive = closure_recursivity(*name, closures); } if !seen_pattern_regions.contains(&new_def.loc_pattern.region) { @@ -1157,7 +1161,12 @@ fn group_to_declaration( can_defs.push(new_def); } } - None => roc_error_macros::internal_error!("def not available {:?}", symbol), + None => { + // NOTE: a `_ = someDef` can mean we don't have a symbol here + let symbol = def_ids.get_symbol(def_id); + + roc_error_macros::internal_error!("def not available {:?}", symbol) + } } } From f7d604f3ef36b8c30ed0eaebacb2b94fd440d9b3 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 23 Apr 2022 20:06:05 +0200 Subject: [PATCH 462/846] move def ordering creation into `canonicalize_defs` --- compiler/can/src/def.rs | 201 +++++++++++++++++++++------------------- 1 file changed, 107 insertions(+), 94 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 3a41ce3329..35d13a40eb 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -50,9 +50,8 @@ pub struct Annotation { #[derive(Debug)] pub(crate) struct CanDefs { - symbol_to_index: Vec<(IdentId, u32)>, defs: Vec>, - references: Vec<(References, Region)>, + def_ordering: DefOrdering, aliases: SendMap, } @@ -489,15 +488,20 @@ pub(crate) fn canonicalize_defs<'a>( } } + // Determine which idents we introduced in the course of this process. + let mut symbols_introduced = MutMap::default(); + let mut symbol_to_index: Vec<(IdentId, u32)> = Vec::with_capacity(pending_value_defs.len()); for (def_index, pending_def) in pending_value_defs.iter().enumerate() { - for (s, _) in bindings_from_patterns(std::iter::once(pending_def.loc_pattern())) { + for (s, r) in bindings_from_patterns(std::iter::once(pending_def.loc_pattern())) { // store the top-level defs, used to ensure that closures won't capture them if let PatternType::TopLevelDef = pattern_type { env.top_level_symbols.insert(s); } + symbols_introduced.insert(s, r); + debug_assert_eq!(env.home, s.module_id()); debug_assert!(!symbol_to_index.iter().any(|(id, _)| *id == s.ident_id())); @@ -505,15 +509,17 @@ pub(crate) fn canonicalize_defs<'a>( } } - // let mut def_order = DefOrdering::from_symbol_to_id(env.home, symbol_to_id); + let capacity = pending_value_defs.len(); + let mut defs = Vec::with_capacity(capacity); + let mut def_ordering = DefOrdering::from_symbol_to_id(env.home, symbol_to_index, capacity); - // env.home.register_debug_idents(&env.ident_ids); - - let mut defs = Vec::with_capacity(pending_value_defs.len()); - let mut references = Vec::with_capacity(pending_value_defs.len()); - - for pending_def in pending_value_defs.into_iter() { - let region = pending_def.loc_pattern().region; + for (def_id, pending_def) in pending_value_defs.into_iter().enumerate() { + // if this def were a function, what would its name be? + let closure_symbol = match pending_def.loc_pattern().value { + Pattern::Identifier(symbol) => Some(symbol), + Pattern::AbilityMemberSpecialization { ident, .. } => Some(ident), + _ => None, + }; let temp_output = canonicalize_pending_value_def_new( env, @@ -528,12 +534,18 @@ pub(crate) fn canonicalize_defs<'a>( output = temp_output.output; defs.push(Some(temp_output.def)); - references.push((temp_output.references, region)); + + let closure_references = closure_symbol.and_then(|s| env.closures.get(&s)); + + def_ordering.insert_symbol_references( + def_id as u32, + &temp_output.references, + closure_references, + ) } - // Determine which idents we introduced in the course of this process. - let mut symbols_introduced = MutMap::default(); - + // this is now mostly responsible for adding type names and ability members + // see if we can do this in a more efficient way for (symbol, region) in scope.symbols() { if !original_scope.contains_symbol(*symbol) { symbols_introduced.insert(*symbol, *region); @@ -552,9 +564,8 @@ pub(crate) fn canonicalize_defs<'a>( // defs need to get moved later. ( CanDefs { - symbol_to_index, defs, - references, + def_ordering, // The result needs a thread-safe `SendMap` aliases: aliases.into_iter().collect(), }, @@ -731,78 +742,90 @@ impl DefOrdering { // } // } - // fn from_symbol_to_id(home: ModuleId, symbol_to_id: Vec<(IdentId, u32)>) -> Self { - // let capacity = symbol_to_id.len(); - // - // Self { - // home, - // symbol_to_id, - // references: ReferenceMatrix::new(capacity), - // direct_references: ReferenceMatrix::new(capacity), - // length: capacity as u32, - // } - // } - - fn from_defs_by_symbol( - env: &Env, + fn from_symbol_to_id( + home: ModuleId, symbol_to_id: Vec<(IdentId, u32)>, - references: &[(References, Region)], capacity: usize, ) -> Self { // NOTE: because of `Pair a b = someDef` patterns, we can have more symbols than defs // but because `_ = someDef` we can also have more defs than symbols - let mut this = Self { - home: env.home, + Self { + home, symbol_to_id, references: ReferenceMatrix::new(capacity), direct_references: ReferenceMatrix::new(capacity), length: capacity as u32, - }; + } + } - for (ident_id, def_id) in this.symbol_to_id.iter() { - let def_id = *def_id; - let references = &references[def_id as usize].0; - let symbol = Symbol::new(this.home, *ident_id); + // fn from_defs_by_symbol( + // env: &Env, + // symbol_to_id: Vec<(IdentId, u32)>, + // references: &[(References, Region)], + // capacity: usize, + // ) -> Self { + // + // let mut this = Self { + // home: env.home, + // symbol_to_id, + // references: ReferenceMatrix::new(capacity), + // direct_references: ReferenceMatrix::new(capacity), + // length: capacity as u32, + // }; + // + // for (ident_id, def_id) in this.symbol_to_id.iter() { + // let def_id = *def_id; + // let references = &references[def_id as usize].0; + // let symbol = Symbol::new(this.home, *ident_id); + // + // this.insert_symbol_references(def_id, symbol, references, &env.closures); + // } + // + // this + // } + fn insert_symbol_references( + &mut self, + def_id: u32, + references: &References, + closure_references: Option<&References>, + ) { + for referenced in references.value_lookups() { + if let Some(ref_id) = self.get_id(*referenced) { + self.references + .set_row_col(def_id as usize, ref_id as usize, true); + + self.direct_references + .set_row_col(def_id as usize, ref_id as usize, true); + } + } + + for referenced in references.calls() { + if let Some(ref_id) = self.get_id(*referenced) { + self.references + .set_row_col(def_id as usize, ref_id as usize, true); + + self.direct_references + .set_row_col(def_id as usize, ref_id as usize, true); + } + } + + if let Some(references) = closure_references { for referenced in references.value_lookups() { - if let Some(ref_id) = this.get_id(*referenced) { - this.references - .set_row_col(def_id as usize, ref_id as usize, true); - - this.direct_references + if let Some(ref_id) = self.get_id(*referenced) { + self.references .set_row_col(def_id as usize, ref_id as usize, true); } } for referenced in references.calls() { - if let Some(ref_id) = this.get_id(*referenced) { - this.references + if let Some(ref_id) = self.get_id(*referenced) { + self.references .set_row_col(def_id as usize, ref_id as usize, true); - - this.direct_references - .set_row_col(def_id as usize, ref_id as usize, true); - } - } - - if let Some(references) = env.closures.get(&symbol) { - for referenced in references.value_lookups() { - if let Some(ref_id) = this.get_id(*referenced) { - this.references - .set_row_col(def_id as usize, ref_id as usize, true); - } - } - - for referenced in references.calls() { - if let Some(ref_id) = this.get_id(*referenced) { - this.references - .set_row_col(def_id as usize, ref_id as usize, true); - } } } } - - this } // fn from_defs_by_symbol_old( @@ -900,28 +923,25 @@ pub(crate) fn sort_can_defs( mut output: Output, ) -> (Result, RuntimeError>, Output) { let CanDefs { - symbol_to_index, mut defs, - references, + def_ordering, aliases, } = defs; - let def_ids = DefOrdering::from_defs_by_symbol(env, symbol_to_index, &references, defs.len()); - for (symbol, alias) in aliases.into_iter() { output.aliases.insert(symbol, alias); } // TODO also do the same `addDirects` check elm/compiler does, so we can // report an error if a recursive definition can't possibly terminate! - match def_ids.references.topological_sort_into_groups() { + match def_ordering.references.topological_sort_into_groups() { TopologicalSort::Groups { groups } => { let mut declarations = Vec::new(); // groups are in reversed order for group in groups.into_iter().rev() { group_to_declaration( - &def_ids, + &def_ordering, &group, &env.closures, &mut defs, @@ -949,7 +969,7 @@ pub(crate) fn sort_can_defs( // // foo = if b then foo else bar - let sccs = def_ids + let sccs = def_ordering .references .strongly_connected_components(&nodes_in_cycle); @@ -964,7 +984,7 @@ pub(crate) fn sort_can_defs( // p = q // q = p let is_invalid_cycle = match cycle.get(0) { - Some(def_id) => def_ids + Some(def_id) => def_ordering .direct_references .references_for(*def_id as usize) .any(|key| cycle.contains(&(key as u32))), @@ -976,25 +996,18 @@ pub(crate) fn sort_can_defs( let mut entries = Vec::new(); for def_id in &cycle { - let symbol = def_ids.get_symbol(*def_id).unwrap(); - match references.get(*def_id as usize) { - None => unreachable!( - r#"Symbol `{:?}` not found in references! references was: {:?}"#, - symbol, references - ), - Some((_, region)) => { - let expr_region = - defs[*def_id as usize].as_ref().unwrap().loc_expr.region; + let symbol = def_ordering.get_symbol(*def_id).unwrap(); + let def = &defs[*def_id as usize]; - let entry = CycleEntry { - symbol, - symbol_region: *region, - expr_region, - }; + let expr_region = defs[*def_id as usize].as_ref().unwrap().loc_expr.region; - entries.push(entry); - } - } + let entry = CycleEntry { + symbol, + symbol_region: def.as_ref().unwrap().loc_pattern.region, + expr_region, + }; + + entries.push(entry); } // Sort them by line number to make the report more helpful. @@ -1035,7 +1048,7 @@ pub(crate) fn sort_can_defs( // for each symbol in this group for symbol in &groups[*group_id] { // find its successors - for succ in def_ids.successors_without_self(*symbol) { + for succ in def_ordering.successors_without_self(*symbol) { // and add its group to the result match symbol_to_group_index.get(&succ) { Some(index) => { @@ -1059,7 +1072,7 @@ pub(crate) fn sort_can_defs( let group = &groups[*group_id]; group_to_declaration( - &def_ids, + &def_ordering, group, &env.closures, &mut defs, From 9bc00321b64d4a987192340867a38a617127b9bb Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 23 Apr 2022 20:07:41 +0200 Subject: [PATCH 463/846] cleanup --- compiler/can/src/def.rs | 76 ----------------------------------------- 1 file changed, 76 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 35d13a40eb..5768449386 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -732,16 +732,6 @@ struct DefOrdering { } impl DefOrdering { - // fn with_capacity(home: ModuleId, capacity: usize) -> Self { - // Self { - // home, - // symbol_to_id: Vec::with_capacity(capacity), - // references: ReferenceMatrix::new(capacity), - // direct_references: ReferenceMatrix::new(capacity), - // length: capacity as u32, - // } - // } - fn from_symbol_to_id( home: ModuleId, symbol_to_id: Vec<(IdentId, u32)>, @@ -759,32 +749,6 @@ impl DefOrdering { } } - // fn from_defs_by_symbol( - // env: &Env, - // symbol_to_id: Vec<(IdentId, u32)>, - // references: &[(References, Region)], - // capacity: usize, - // ) -> Self { - // - // let mut this = Self { - // home: env.home, - // symbol_to_id, - // references: ReferenceMatrix::new(capacity), - // direct_references: ReferenceMatrix::new(capacity), - // length: capacity as u32, - // }; - // - // for (ident_id, def_id) in this.symbol_to_id.iter() { - // let def_id = *def_id; - // let references = &references[def_id as usize].0; - // let symbol = Symbol::new(this.home, *ident_id); - // - // this.insert_symbol_references(def_id, symbol, references, &env.closures); - // } - // - // this - // } - fn insert_symbol_references( &mut self, def_id: u32, @@ -828,46 +792,6 @@ impl DefOrdering { } } - // fn from_defs_by_symbol_old( - // env: &Env, - // can_defs_by_symbol: &MutMap, - // refs_by_symbol: &MutMap, - // ) -> Self { - // let mut this = Self::with_capacity(env.home, can_defs_by_symbol.len()); - // - // for (i, symbol) in can_defs_by_symbol.keys().enumerate() { - // debug_assert_eq!(env.home, symbol.module_id()); - // - // this.symbol_to_id.push((symbol.ident_id(), i as u32)); - // } - // - // for (symbol, (_, references)) in refs_by_symbol.iter() { - // let def_id = this.get_id(*symbol).unwrap(); - // - // for referenced in references.value_lookups() { - // this.register_reference(def_id, *referenced); - // this.register_direct_reference(def_id, *referenced); - // } - // - // for referenced in references.calls() { - // this.register_reference(def_id, *referenced); - // this.register_direct_reference(def_id, *referenced); - // } - // - // if let Some(references) = env.closures.get(symbol) { - // for referenced in references.value_lookups() { - // this.register_reference(def_id, *referenced); - // } - // - // for referenced in references.calls() { - // this.register_reference(def_id, *referenced); - // } - // } - // } - // - // this - // } - fn get_id(&self, symbol: Symbol) -> Option { if symbol.module_id() != self.home { return None; From 5d1dd81e93fa87331f06892a347e2fb1e60ec722 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Sat, 23 Apr 2022 14:37:52 -0400 Subject: [PATCH 464/846] Reuse symbol when opaque type wraps a known symbol Opaques decay immediately into their argument during codegen, so we need to handle something that's effectively variable aliasing correctly. This bug popped up while migrating all current private tags to opaques. --- compiler/mono/src/ir.rs | 27 ++++++++++++------- compiler/test_gen/src/gen_tags.rs | 25 +++++++++++++++++ .../generated/opaque_assign_to_symbol.txt | 10 +++++++ compiler/test_mono/src/tests.rs | 17 ++++++++++++ 4 files changed, 70 insertions(+), 9 deletions(-) create mode 100644 compiler/test_mono/generated/opaque_assign_to_symbol.txt diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 69d1a080f8..72b10cc7f5 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -3499,15 +3499,24 @@ pub fn with_hole<'a>( OpaqueRef { argument, .. } => { let (arg_var, loc_arg_expr) = *argument; - with_hole( - env, - loc_arg_expr.value, - arg_var, - procs, - layout_cache, - assigned, - hole, - ) + + match can_reuse_symbol(env, procs, &loc_arg_expr.value) { + // Opaques decay to their argument. + ReuseSymbol::Value(real_name) => { + let mut result = hole.clone(); + substitute_in_exprs(arena, &mut result, assigned, real_name); + result + } + _ => with_hole( + env, + loc_arg_expr.value, + arg_var, + procs, + layout_cache, + assigned, + hole, + ), + } } Record { diff --git a/compiler/test_gen/src/gen_tags.rs b/compiler/test_gen/src/gen_tags.rs index eefcb272cf..48dc0880d2 100644 --- a/compiler/test_gen/src/gen_tags.rs +++ b/compiler/test_gen/src/gen_tags.rs @@ -1580,3 +1580,28 @@ fn issue_2725_alias_polymorphic_lambda() { i64 ) } + +#[test] +#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] +fn opaque_assign_to_symbol() { + assert_evals_to!( + indoc!( + r#" + app "test" provides [ out ] to "./platform" + + Variable := U8 + + fromUtf8 : U8 -> Result Variable [ InvalidVariableUtf8 ] + fromUtf8 = \char -> + Ok ($Variable char) + + out = + when fromUtf8 98 is + Ok ($Variable n) -> n + _ -> 1 + "# + ), + 98, + u8 + ) +} diff --git a/compiler/test_mono/generated/opaque_assign_to_symbol.txt b/compiler/test_mono/generated/opaque_assign_to_symbol.txt new file mode 100644 index 0000000000..8e0c7fe63b --- /dev/null +++ b/compiler/test_mono/generated/opaque_assign_to_symbol.txt @@ -0,0 +1,10 @@ +procedure : `#UserApp.fromUtf8` [C {}, C U8] +procedure = `#UserApp.fromUtf8` (`#UserApp.char`): + let `#UserApp.3` : [C {}, C U8] = Ok `#UserApp.4`; + ret `#UserApp.3`; + +procedure : `#UserApp.out` [C {}, C U8] +procedure = `#UserApp.out` (): + let `#UserApp.2` : U8 = 98i64; + let `#UserApp.1` : [C {}, C U8] = CallByName `#UserApp.fromUtf8` `#UserApp.2`; + ret `#UserApp.1`; diff --git a/compiler/test_mono/src/tests.rs b/compiler/test_mono/src/tests.rs index 115b5a8ca3..fbb2612793 100644 --- a/compiler/test_mono/src/tests.rs +++ b/compiler/test_mono/src/tests.rs @@ -1330,6 +1330,23 @@ fn specialize_ability_call() { ) } +#[mono_test] +fn opaque_assign_to_symbol() { + indoc!( + r#" + app "test" provides [ out ] to "./platform" + + Variable := U8 + + fromUtf8 : U8 -> Result Variable [ InvalidVariableUtf8 ] + fromUtf8 = \char -> + Ok ($Variable char) + + out = fromUtf8 98 + "# + ) +} + // #[ignore] // #[mono_test] // fn static_str_closure() { From 31fc223517408884d2543b82b01796afb77b1c60 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 23 Apr 2022 20:42:41 +0200 Subject: [PATCH 465/846] add recursivity checker --- compiler/can/src/reference_matrix.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/compiler/can/src/reference_matrix.rs b/compiler/can/src/reference_matrix.rs index eaadee556c..ab858d08c3 100644 --- a/compiler/can/src/reference_matrix.rs +++ b/compiler/can/src/reference_matrix.rs @@ -39,6 +39,31 @@ impl ReferenceMatrix { pub fn get(&self, index: usize) -> bool { self.bitvec[index] } + + pub fn is_recursive(&self, index: usize) -> bool { + let mut scheduled = self.row_slice(index).to_bitvec(); + let mut visited = self.row_slice(index).to_bitvec(); + + // yes this is a bit inefficient because rows are visited repeatedly. + while scheduled.any() { + for one in scheduled.iter_ones() { + if one == index { + return true; + } + + visited |= self.row_slice(one) + } + + // i.e. visited did not change + if visited.count_ones() == scheduled.count_ones() { + break; + } + + scheduled |= &visited; + } + + false + } } // Topological sort and strongly-connected components From 29493d2fd0ece8efcc0c729883819cb2af92c4ea Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 23 Apr 2022 20:43:08 +0200 Subject: [PATCH 466/846] use matrix-based recursivity check --- compiler/can/src/def.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 5768449386..1b44565b24 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1018,7 +1018,7 @@ pub(crate) fn sort_can_defs( } fn group_to_declaration( - def_ids: &DefOrdering, + def_ordering: &DefOrdering, group: &[u32], closures: &MutMap, defs: &mut [Option], @@ -1035,7 +1035,7 @@ fn group_to_declaration( // for a definition, so every definition is only inserted (thus typechecked and emitted) once let mut seen_pattern_regions: Vec = Vec::with_capacity(2); - let sccs = def_ids.references.strongly_connected_components(group); + let sccs = def_ordering.references.strongly_connected_components(group); for cycle in sccs { if cycle.len() == 1 { @@ -1046,7 +1046,7 @@ fn group_to_declaration( // there is only one definition in this cycle, so we only have // to check whether it recurses with itself; there is nobody else // to recurse with, or they would also be in this cycle. - let is_self_recursive = def_ids.is_self_recursive(def_id); + let is_self_recursive = def_ordering.is_self_recursive(def_id); if let Closure(ClosureData { recursive: recursive @ Recursive::NotRecursive, @@ -1070,7 +1070,7 @@ fn group_to_declaration( } None => { // NOTE: a `_ = someDef` can mean we don't have a symbol here - let symbol = def_ids.get_symbol(def_id); + let symbol = def_ordering.get_symbol(def_id); roc_error_macros::internal_error!("def not available {:?}", symbol) } @@ -1085,11 +1085,12 @@ fn group_to_declaration( // Determine recursivity of closures that are not tail-recursive if let Closure(ClosureData { recursive: recursive @ Recursive::NotRecursive, - name, .. }) = &mut new_def.loc_expr.value { - *recursive = closure_recursivity(*name, closures); + if def_ordering.references.is_recursive(def_id as usize) { + *recursive = Recursive::Recursive + } } if !seen_pattern_regions.contains(&new_def.loc_pattern.region) { @@ -1100,7 +1101,7 @@ fn group_to_declaration( } None => { // NOTE: a `_ = someDef` can mean we don't have a symbol here - let symbol = def_ids.get_symbol(def_id); + let symbol = def_ordering.get_symbol(def_id); roc_error_macros::internal_error!("def not available {:?}", symbol) } From 8936cb94638f75ad8b9c040ce9eb8b6a34079bd8 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 23 Apr 2022 20:46:26 +0200 Subject: [PATCH 467/846] remove use of env.closures in later steps --- compiler/can/src/def.rs | 44 +---------------------------------------- 1 file changed, 1 insertion(+), 43 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 1b44565b24..0f6e477217 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -864,13 +864,7 @@ pub(crate) fn sort_can_defs( // groups are in reversed order for group in groups.into_iter().rev() { - group_to_declaration( - &def_ordering, - &group, - &env.closures, - &mut defs, - &mut declarations, - ); + group_to_declaration(&def_ordering, &group, &mut defs, &mut declarations); } (Ok(declarations), output) @@ -998,7 +992,6 @@ pub(crate) fn sort_can_defs( group_to_declaration( &def_ordering, group, - &env.closures, &mut defs, &mut declarations, ); @@ -1020,7 +1013,6 @@ pub(crate) fn sort_can_defs( fn group_to_declaration( def_ordering: &DefOrdering, group: &[u32], - closures: &MutMap, defs: &mut [Option], declarations: &mut Vec, ) { @@ -1707,40 +1699,6 @@ fn decl_to_let(var_store: &mut VarStore, decl: Declaration, loc_ret: Loc) } } -fn closure_recursivity(symbol: Symbol, closures: &MutMap) -> Recursive { - let mut visited = MutSet::default(); - - let mut stack = Vec::new(); - - if let Some(references) = closures.get(&symbol) { - for v in references.calls() { - stack.push(*v); - } - - // while there are symbols left to visit - while let Some(nested_symbol) = stack.pop() { - if nested_symbol == symbol { - return Recursive::Recursive; - } - - // if the called symbol not yet in the graph - if !visited.contains(&nested_symbol) { - // add it to the visited set - // if it calls any functions - if let Some(nested_references) = closures.get(&nested_symbol) { - // add its called to the stack - for v in nested_references.calls() { - stack.push(*v); - } - } - visited.insert(nested_symbol); - } - } - } - - Recursive::NotRecursive -} - fn to_pending_type_def<'a>( env: &mut Env<'a>, def: &'a ast::TypeDef<'a>, From a4ea4acacfd81e3673d1296d5ef87ac8a22a07c0 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 23 Apr 2022 20:59:34 +0200 Subject: [PATCH 468/846] pass closure references along via TempOutput --- compiler/can/src/def.rs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 0f6e477217..c963efbbd8 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -514,13 +514,6 @@ pub(crate) fn canonicalize_defs<'a>( let mut def_ordering = DefOrdering::from_symbol_to_id(env.home, symbol_to_index, capacity); for (def_id, pending_def) in pending_value_defs.into_iter().enumerate() { - // if this def were a function, what would its name be? - let closure_symbol = match pending_def.loc_pattern().value { - Pattern::Identifier(symbol) => Some(symbol), - Pattern::AbilityMemberSpecialization { ident, .. } => Some(ident), - _ => None, - }; - let temp_output = canonicalize_pending_value_def_new( env, pending_def, @@ -535,12 +528,10 @@ pub(crate) fn canonicalize_defs<'a>( defs.push(Some(temp_output.def)); - let closure_references = closure_symbol.and_then(|s| env.closures.get(&s)); - def_ordering.insert_symbol_references( def_id as u32, &temp_output.references, - closure_references, + temp_output.closure_references, ) } @@ -753,7 +744,7 @@ impl DefOrdering { &mut self, def_id: u32, references: &References, - closure_references: Option<&References>, + closure_references: Option, ) { for referenced in references.value_lookups() { if let Some(ref_id) = self.get_id(*referenced) { @@ -1201,6 +1192,7 @@ struct TempOutput { output: Output, def: Def, references: References, + closure_references: Option, } // TODO trim down these arguments! @@ -1318,6 +1310,7 @@ fn canonicalize_pending_value_def_new<'a>( TempOutput { output, references: References::default(), + closure_references: None, def, } } @@ -1398,6 +1391,8 @@ fn canonicalize_pending_value_def_new<'a>( ) }); + let closure_references = references.clone(); + // Re-insert the closure into the map, under its defined name. // closures don't have a name, and therefore pick a fresh symbol. But in this // case, the closure has a proper name (e.g. `foo` in `foo = \x y -> ...` @@ -1443,6 +1438,7 @@ fn canonicalize_pending_value_def_new<'a>( TempOutput { output, references: refs, + closure_references: Some(closure_references), def, } } else { @@ -1461,6 +1457,7 @@ fn canonicalize_pending_value_def_new<'a>( TempOutput { output, references: refs, + closure_references: None, def, } } @@ -1480,6 +1477,7 @@ fn canonicalize_pending_value_def_new<'a>( TempOutput { output, references: refs, + closure_references: None, def, } } @@ -1541,6 +1539,8 @@ fn canonicalize_pending_value_def_new<'a>( ) }); + let closure_references = references.clone(); + // Re-insert the closure into the map, under its defined name. // closures don't have a name, and therefore pick a fresh symbol. But in this // case, the closure has a proper name (e.g. `foo` in `foo = \x y -> ...` @@ -1583,6 +1583,7 @@ fn canonicalize_pending_value_def_new<'a>( TempOutput { output, references: refs, + closure_references: Some(closure_references), def, } } else { @@ -1601,6 +1602,7 @@ fn canonicalize_pending_value_def_new<'a>( TempOutput { output, references: refs, + closure_references: None, def, } } @@ -1620,6 +1622,7 @@ fn canonicalize_pending_value_def_new<'a>( TempOutput { output, references: refs, + closure_references: None, def, } } From 9866feeb5d9148f493c36a7c737689c4acb6e042 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 23 Apr 2022 21:01:50 +0200 Subject: [PATCH 469/846] stop putting the references into the env.closures map with the def name --- compiler/can/src/def.rs | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index c963efbbd8..f63690b713 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1384,21 +1384,13 @@ fn canonicalize_pending_value_def_new<'a>( { // Since everywhere in the code it'll be referred to by its defined name, // remove its generated name from the closure map. (We'll re-insert it later.) - let references = env.closures.remove(closure_name).unwrap_or_else(|| { + let closure_references = env.closures.remove(closure_name).unwrap_or_else(|| { panic!( "Tried to remove symbol {:?} from procedures, but it was not found: {:?}", closure_name, env.closures ) }); - let closure_references = references.clone(); - - // Re-insert the closure into the map, under its defined name. - // closures don't have a name, and therefore pick a fresh symbol. But in this - // case, the closure has a proper name (e.g. `foo` in `foo = \x y -> ...` - // and we want to reference it by that name. - env.closures.insert(symbol, references); - // The closure is self tail recursive iff it tail calls itself (by defined name). let is_recursive = match can_output.tail_call { Some(tail_symbol) if tail_symbol == symbol => Recursive::TailRecursive, @@ -1532,21 +1524,13 @@ fn canonicalize_pending_value_def_new<'a>( { // Since everywhere in the code it'll be referred to by its defined name, // remove its generated name from the closure map. (We'll re-insert it later.) - let references = env.closures.remove(closure_name).unwrap_or_else(|| { + let closure_references = env.closures.remove(closure_name).unwrap_or_else(|| { panic!( "Tried to remove symbol {:?} from procedures, but it was not found: {:?}", closure_name, env.closures ) }); - let closure_references = references.clone(); - - // Re-insert the closure into the map, under its defined name. - // closures don't have a name, and therefore pick a fresh symbol. But in this - // case, the closure has a proper name (e.g. `foo` in `foo = \x y -> ...` - // and we want to reference it by that name. - env.closures.insert(symbol, references); - // The closure is self tail recursive iff it tail calls itself (by defined name). let is_recursive = match can_output.tail_call { Some(tail_symbol) if tail_symbol == symbol => Recursive::TailRecursive, From 4668cf506bbbb5356e7d48dccbe82b4ae239ec40 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 23 Apr 2022 21:15:54 +0200 Subject: [PATCH 470/846] be smarter about returning References --- compiler/can/src/def.rs | 102 +++++++++++++++------------------------- 1 file changed, 38 insertions(+), 64 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index f63690b713..ffafc75820 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -528,11 +528,7 @@ pub(crate) fn canonicalize_defs<'a>( defs.push(Some(temp_output.def)); - def_ordering.insert_symbol_references( - def_id as u32, - &temp_output.references, - temp_output.closure_references, - ) + def_ordering.insert_symbol_references(def_id as u32, &temp_output.references) } // this is now mostly responsible for adding type names and ability members @@ -740,46 +736,34 @@ impl DefOrdering { } } - fn insert_symbol_references( - &mut self, - def_id: u32, - references: &References, - closure_references: Option, - ) { - for referenced in references.value_lookups() { - if let Some(ref_id) = self.get_id(*referenced) { - self.references - .set_row_col(def_id as usize, ref_id as usize, true); + fn insert_symbol_references(&mut self, def_id: u32, def_references: &DefReferences) { + match def_references { + DefReferences::Value(references) => { + let it = references.value_lookups().chain(references.calls()); - self.direct_references - .set_row_col(def_id as usize, ref_id as usize, true); - } - } + for referenced in it { + if let Some(ref_id) = self.get_id(*referenced) { + self.references + .set_row_col(def_id as usize, ref_id as usize, true); - for referenced in references.calls() { - if let Some(ref_id) = self.get_id(*referenced) { - self.references - .set_row_col(def_id as usize, ref_id as usize, true); - - self.direct_references - .set_row_col(def_id as usize, ref_id as usize, true); - } - } - - if let Some(references) = closure_references { - for referenced in references.value_lookups() { - if let Some(ref_id) = self.get_id(*referenced) { - self.references - .set_row_col(def_id as usize, ref_id as usize, true); + self.direct_references + .set_row_col(def_id as usize, ref_id as usize, true); + } } } + DefReferences::Function(references) => { + let it = references.value_lookups().chain(references.calls()); - for referenced in references.calls() { - if let Some(ref_id) = self.get_id(*referenced) { - self.references - .set_row_col(def_id as usize, ref_id as usize, true); + for referenced in it { + if let Some(ref_id) = self.get_id(*referenced) { + self.references + .set_row_col(def_id as usize, ref_id as usize, true); + } } } + DefReferences::Empty => { + // produced by annotations without bodies + } } } @@ -1188,11 +1172,19 @@ fn add_annotation_aliases( } } +// Functions' references don't count in defs. +// See 3d5a2560057d7f25813112dfa5309956c0f9e6a9 and its +// parent commit for the bug this fixed! +enum DefReferences { + Value(References), + Function(References), + Empty, +} + struct TempOutput { output: Output, def: Def, - references: References, - closure_references: Option, + references: DefReferences, } // TODO trim down these arguments! @@ -1309,8 +1301,7 @@ fn canonicalize_pending_value_def_new<'a>( TempOutput { output, - references: References::default(), - closure_references: None, + references: DefReferences::Empty, def, } } @@ -1410,13 +1401,6 @@ fn canonicalize_pending_value_def_new<'a>( loc_body: body.clone(), }); - // Functions' references don't count in defs. - // See 3d5a2560057d7f25813112dfa5309956c0f9e6a9 and its - // parent commit for the bug this fixed! - // - // NOTE: this is where we lose reference information for closure bodies. - let refs = References::new(); - let def = single_can_def( loc_can_pattern, loc_can_expr, @@ -1429,8 +1413,7 @@ fn canonicalize_pending_value_def_new<'a>( TempOutput { output, - references: refs, - closure_references: Some(closure_references), + references: DefReferences::Function(closure_references), def, } } else { @@ -1448,8 +1431,7 @@ fn canonicalize_pending_value_def_new<'a>( TempOutput { output, - references: refs, - closure_references: None, + references: DefReferences::Value(refs), def, } } @@ -1468,8 +1450,7 @@ fn canonicalize_pending_value_def_new<'a>( TempOutput { output, - references: refs, - closure_references: None, + references: DefReferences::Value(refs), def, } } @@ -1549,11 +1530,6 @@ fn canonicalize_pending_value_def_new<'a>( loc_body: body.clone(), }); - // Functions' references don't count in defs. - // See 3d5a2560057d7f25813112dfa5309956c0f9e6a9 and its - // parent commit for the bug this fixed! - let refs = References::new(); - let def = single_can_def( loc_can_pattern, loc_can_expr, @@ -1566,8 +1542,7 @@ fn canonicalize_pending_value_def_new<'a>( TempOutput { output, - references: refs, - closure_references: Some(closure_references), + references: DefReferences::Function(closure_references), def, } } else { @@ -1585,8 +1560,7 @@ fn canonicalize_pending_value_def_new<'a>( TempOutput { output, - references: refs, - closure_references: None, + references: DefReferences::Value(refs), def, } } From 44c08779c3c92c0bf121ea722ec340d0a90f0f9b Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 23 Apr 2022 21:17:05 +0200 Subject: [PATCH 471/846] simplify pattern match --- compiler/can/src/def.rs | 150 ++++++++++++++++------------------------ 1 file changed, 59 insertions(+), 91 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index ffafc75820..bd9ec6cf43 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1358,21 +1358,23 @@ fn canonicalize_pending_value_def_new<'a>( // which also implies it's not a self tail call! // // Only defs of the form (foo = ...) can be closure declarations or self tail calls. - if let Pattern::Identifier(symbol) - | Pattern::AbilityMemberSpecialization { ident: symbol, .. } = loc_can_pattern.value - { - if let Closure(ClosureData { - function_type, - closure_type, - closure_ext_var, - return_type, - name: ref closure_name, - ref arguments, - loc_body: ref body, - ref captured_symbols, - .. - }) = loc_can_expr.value - { + + match (&loc_can_pattern.value, &loc_can_expr.value) { + ( + Pattern::Identifier(symbol) + | Pattern::AbilityMemberSpecialization { ident: symbol, .. }, + Closure(ClosureData { + function_type, + closure_type, + closure_ext_var, + return_type, + name: closure_name, + arguments, + loc_body: body, + captured_symbols, + .. + }), + ) => { // Since everywhere in the code it'll be referred to by its defined name, // remove its generated name from the closure map. (We'll re-insert it later.) let closure_references = env.closures.remove(closure_name).unwrap_or_else(|| { @@ -1384,17 +1386,16 @@ fn canonicalize_pending_value_def_new<'a>( // The closure is self tail recursive iff it tail calls itself (by defined name). let is_recursive = match can_output.tail_call { - Some(tail_symbol) if tail_symbol == symbol => Recursive::TailRecursive, + Some(tail_symbol) if tail_symbol == *symbol => Recursive::TailRecursive, _ => Recursive::NotRecursive, }; - // renamed_closure_def = Some(&symbol); loc_can_expr.value = Closure(ClosureData { - function_type, - closure_type, - closure_ext_var, - return_type, - name: symbol, + function_type: *function_type, + closure_type: *closure_type, + closure_ext_var: *closure_ext_var, + return_type: *return_type, + name: *symbol, captured_symbols: captured_symbols.clone(), recursive: is_recursive, arguments: arguments.clone(), @@ -1416,7 +1417,8 @@ fn canonicalize_pending_value_def_new<'a>( references: DefReferences::Function(closure_references), def, } - } else { + } + _ => { let refs = can_output.references.clone(); let def = single_can_def( @@ -1435,24 +1437,6 @@ fn canonicalize_pending_value_def_new<'a>( def, } } - } else { - let refs = can_output.references.clone(); - - let def = single_can_def( - loc_can_pattern, - loc_can_expr, - expr_var, - Some(Loc::at(loc_ann.region, type_annotation)), - vars_by_symbol.clone(), - ); - - output.union(can_output); - - TempOutput { - output, - references: DefReferences::Value(refs), - def, - } } } // If we have a pattern, then the def has a body (that is, it's not a @@ -1490,40 +1474,42 @@ fn canonicalize_pending_value_def_new<'a>( // which also implies it's not a self tail call! // // Only defs of the form (foo = ...) can be closure declarations or self tail calls. - if let Pattern::Identifier(symbol) = loc_can_pattern.value { - if let Closure(ClosureData { - function_type, - closure_type, - closure_ext_var, - return_type, - name: ref closure_name, - ref arguments, - loc_body: ref body, - ref captured_symbols, - .. - }) = loc_can_expr.value - { - // Since everywhere in the code it'll be referred to by its defined name, - // remove its generated name from the closure map. (We'll re-insert it later.) - let closure_references = env.closures.remove(closure_name).unwrap_or_else(|| { - panic!( - "Tried to remove symbol {:?} from procedures, but it was not found: {:?}", - closure_name, env.closures - ) - }); - - // The closure is self tail recursive iff it tail calls itself (by defined name). - let is_recursive = match can_output.tail_call { - Some(tail_symbol) if tail_symbol == symbol => Recursive::TailRecursive, - _ => Recursive::NotRecursive, - }; - - loc_can_expr.value = Closure(ClosureData { + match (&loc_can_pattern.value, &loc_can_expr.value) { + ( + Pattern::Identifier(symbol), + Closure(ClosureData { function_type, closure_type, closure_ext_var, return_type, - name: symbol, + name: closure_name, + arguments, + loc_body: body, + captured_symbols, + .. + }), + ) => { + // Since everywhere in the code it'll be referred to by its defined name, + // remove its generated name from the closure map. (We'll re-insert it later.) + let closure_references = env.closures.remove(closure_name).unwrap_or_else(|| { + panic!( + "Tried to remove symbol {:?} from procedures, but it was not found: {:?}", + closure_name, env.closures + ) + }); + + // The closure is self tail recursive iff it tail calls itself (by defined name). + let is_recursive = match can_output.tail_call { + Some(tail_symbol) if tail_symbol == *symbol => Recursive::TailRecursive, + _ => Recursive::NotRecursive, + }; + + loc_can_expr.value = Closure(ClosureData { + function_type: *function_type, + closure_type: *closure_type, + closure_ext_var: *closure_ext_var, + return_type: *return_type, + name: *symbol, captured_symbols: captured_symbols.clone(), recursive: is_recursive, arguments: arguments.clone(), @@ -1545,7 +1531,8 @@ fn canonicalize_pending_value_def_new<'a>( references: DefReferences::Function(closure_references), def, } - } else { + } + _ => { let refs = can_output.references.clone(); let def = single_can_def( @@ -1564,25 +1551,6 @@ fn canonicalize_pending_value_def_new<'a>( def, } } - } else { - let refs = can_output.references.clone(); - - let def = single_can_def( - loc_can_pattern, - loc_can_expr, - expr_var, - None, - vars_by_symbol.clone(), - ); - - output.union(can_output); - - TempOutput { - output, - references: refs, - closure_references: None, - def, - } } } } From ea15203ff9fb893693e3b1de2e83b5842e0e68fc Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 23 Apr 2022 21:20:49 +0200 Subject: [PATCH 472/846] clarify --- compiler/can/src/def.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index bd9ec6cf43..812d342fdb 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -761,8 +761,8 @@ impl DefOrdering { } } } - DefReferences::Empty => { - // produced by annotations without bodies + DefReferences::AnnotationWithoutBody => { + // annotatations without bodies don't reference any other definitions } } } @@ -1178,7 +1178,7 @@ fn add_annotation_aliases( enum DefReferences { Value(References), Function(References), - Empty, + AnnotationWithoutBody, } struct TempOutput { @@ -1301,7 +1301,7 @@ fn canonicalize_pending_value_def_new<'a>( TempOutput { output, - references: DefReferences::Empty, + references: DefReferences::AnnotationWithoutBody, def, } } From ed336af17bec95f5627cb8f4b2c9ca1687cd3032 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sat, 23 Apr 2022 15:34:28 -0400 Subject: [PATCH 473/846] Test `roc build` on breakout example --- cli/tests/cli_run.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/tests/cli_run.rs b/cli/tests/cli_run.rs index 649f299edb..cbae982ddb 100644 --- a/cli/tests/cli_run.rs +++ b/cli/tests/cli_run.rs @@ -256,8 +256,8 @@ mod cli_run { return; } } - "hello-gui" => { - // Since this one requires opening a window, we do `roc build` on it but don't run it. + "hello-gui" | "breakout" => { + // Since these require opening a window, we do `roc build` on them but don't run them. build_example(&file_name, &["--optimize"]); return; From adb3c3ca2a4ed1936ca73b461d9c5fc8047a9370 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 18 Apr 2022 12:42:42 -0400 Subject: [PATCH 474/846] Revert breakout back to a working state. This should be un-reverted when enough compiler bugs are fixed that it can run again! --- examples/breakout/breakout.roc | 114 ++++++++------------------------- 1 file changed, 26 insertions(+), 88 deletions(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index d1f6ef6cc4..474d0be36c 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -1,6 +1,6 @@ app "breakout" packages { pf: "platform" } - imports [ pf.Game.{ Bounds, Elem, Event, Rgba } ] + imports [ pf.Game.{ Bounds, Elem, Event } ] provides [ program ] { Model } to pf paddleWidth = 0.2 # width of the paddle, as a % of screen width @@ -11,11 +11,8 @@ blockBorder = 0.025 # border of a block, as a % of its width ballSize = 55 numRows = 4 numCols = 8 -numBlocks = numRows * numCols Model : { - blocks : List Block, - # Screen height and width height : F32, width : F32, @@ -30,20 +27,9 @@ Model : { dBallY : F32, # delta y - how much it moves per tick } -Block : { - left : F32, - top : F32, - color : Rgba, - status : [ Active, Removed, Fading F32 ], -} - init : Bounds -> Model init = \{ width, height } -> - blocks = initBlocks width - { - blocks, - # Screen height and width width, height, @@ -60,31 +46,6 @@ init = \{ width, height } -> dBallY: 4, } -initBlocks : F32 -> List Block -initBlocks = \width -> - blockWidth = width / numCols - - List.map (List.range 0 numBlocks) \index -> - col = - Num.rem index numCols - |> Result.withDefault 0 - |> Num.toF32 - - row = - index // numCols - |> Num.toF32 - - red = col / Num.toF32 numCols - green = row / Num.toF32 numRows - blue = Num.toF32 index / Num.toF32 numBlocks - - color = { r: red * 0.8, g: 0.2 + green * 0.6, b: 0.2 + blue * 0.8, a: 1 } - - left = Num.toF32 col * blockWidth - top = Num.toF32 row * blockHeight - - { left, top, color, status: Active } - update : Model, Event -> Model update = \model, event -> when event is @@ -97,8 +58,7 @@ update = \model, event -> tick : Model -> Model tick = \model -> model - #|> moveBall - #|> updateBlocks + |> moveBall moveBall : Model -> Model moveBall = \model -> @@ -125,71 +85,49 @@ moveBall = \model -> { model & ballX, ballY, dBallX, dBallY } -updateBlocks : Model -> Model -updateBlocks = \model -> - blockWidth = model.width / numCols - blocks = List.map model.blocks \block -> - when block.status is - Removed -> block - Active -> - ballRect = { left: model.ballX, top: model.ballY, width: ballSize, height: ballSize } - blockRect = { left: block.left, top: block.top, height: blockHeight, width: blockWidth } - - if isOverlapping blockRect ballRect then - { block & status: Removed } - else - block - Fading amount -> - if amount <= 0 then - { block & status: Removed } - else - { block & status: Fading (amount - 0.1) } - - { model & blocks } - -isOverlapping = \rect1, rect2 -> - (rect1.left + rect1.width >= rect2.left) - && (rect2.left + rect2.width >= rect1.left) - && (rect1.top + rect1.height >= rect2.top) - && (rect2.top + rect2.height >= rect1.top) - render : Model -> List Elem render = \model -> + + blocks = List.map (List.range 0 numBlocks) \index -> + col = + Num.rem index numCols + |> Result.withDefault 0 + |> Num.toF32 + + row = + index // numCols + |> Num.toF32 + + red = col / Num.toF32 numCols + green = row / Num.toF32 numRows + blue = Num.toF32 index / Num.toF32 numBlocks + + color = { r: red * 0.8, g: 0.2 + green * 0.6, b: 0.2 + blue * 0.8, a: 1 } + + { row, col, color } + blockWidth = model.width / numCols - blocks = - # Drop the conditional to fix the malloc error - if True then - initBlocks model.width - else - model.blocks - rects = - List.joinMap blocks \{ left, top, color, status } -> + List.joinMap blocks \{ row, col, color } -> + left = Num.toF32 col * blockWidth + top = Num.toF32 (row * blockHeight) border = blockBorder * blockWidth - alpha = - when status is - Fading amount -> amount - Active -> 1 - Removed -> 1 # TODO this should be 0, but for some reason Active blocks have this memory. - # This outer rectangle gets drawn first, and will appear to be a border. outer = Rect { left, top, width: blockWidth, height: blockHeight, - color: { r: color.r * 0.8, g: color.g * 0.8, b: color.b * 0.8, a: color.a * alpha }, + color: { r: color.r * 0.8, g: color.g * 0.8, b: color.b * 0.8, a: 1 }, } - # The inner retangle is smaller than the outer one, but gets drawn on top of it, - # such that the outer one appears to be a border. inner = Rect { left: left + border, top: top + border, width: blockWidth - (border * 2), height: blockHeight - (border * 2), - color: { color & a: color.a * alpha }, + color, } [ outer, inner ] From 397d1c1db35856a0a7f79740e96ebb8d6fb06b5f Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 23 Apr 2022 21:57:17 +0200 Subject: [PATCH 475/846] rename --- compiler/can/src/def.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 812d342fdb..8813071ef7 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -514,7 +514,7 @@ pub(crate) fn canonicalize_defs<'a>( let mut def_ordering = DefOrdering::from_symbol_to_id(env.home, symbol_to_index, capacity); for (def_id, pending_def) in pending_value_defs.into_iter().enumerate() { - let temp_output = canonicalize_pending_value_def_new( + let temp_output = canonicalize_pending_value_def( env, pending_def, output, @@ -1190,7 +1190,7 @@ struct TempOutput { // TODO trim down these arguments! #[allow(clippy::too_many_arguments)] #[allow(clippy::cognitive_complexity)] -fn canonicalize_pending_value_def_new<'a>( +fn canonicalize_pending_value_def<'a>( env: &mut Env<'a>, pending_def: PendingValueDef<'a>, mut output: Output, From 91e4a0636f49371163db5123ff7d7c8186aec2d4 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 23 Apr 2022 21:58:36 +0200 Subject: [PATCH 476/846] enable `do_pass_bool_byte_closure_layout` only in release mode --- compiler/test_gen/src/gen_primitives.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/test_gen/src/gen_primitives.rs b/compiler/test_gen/src/gen_primitives.rs index 7c32b4aff7..50f26c84b9 100644 --- a/compiler/test_gen/src/gen_primitives.rs +++ b/compiler/test_gen/src/gen_primitives.rs @@ -2992,7 +2992,7 @@ fn mix_function_and_closure_level_of_indirection() { } #[test] -#[ignore] +#[cfg_if(not(debug_assertions), ignore)] // this test stack-overflows the compiler in debug mode #[cfg(any(feature = "gen-llvm"))] fn do_pass_bool_byte_closure_layout() { // see https://github.com/rtfeldman/roc/pull/1706 From 95ca4d48e5c433325c5e52db99c81e01dc189d12 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sat, 23 Apr 2022 16:12:11 -0400 Subject: [PATCH 477/846] Re-remove divFloor --- compiler/builtins/roc/Num.roc | 3 --- 1 file changed, 3 deletions(-) diff --git a/compiler/builtins/roc/Num.roc b/compiler/builtins/roc/Num.roc index b5b07dfd10..23512eb953 100644 --- a/compiler/builtins/roc/Num.roc +++ b/compiler/builtins/roc/Num.roc @@ -252,9 +252,6 @@ divChecked : Float a, Float a -> Result (Float a) [ DivByZero ]* divCeil : Int a, Int a -> Int a divCeilChecked : Int a, Int a -> Result (Int a) [ DivByZero ]* -divFloor : Int a, Int a -> Int a -divFloorChecked : Int a, Int a -> Result (Int a) [ DivByZero ]* - divTrunc : Int a, Int a -> Int a divTruncChecked : Int a, Int a -> Result (Int a) [ DivByZero ]* From 0f245ba7788d03a992fe55d24293d6a10df3c8c5 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 23 Apr 2022 22:14:50 +0200 Subject: [PATCH 478/846] insert type aliases instead of relying on scope check --- compiler/can/src/def.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 8813071ef7..2a0c4341c9 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -321,6 +321,9 @@ pub(crate) fn canonicalize_defs<'a>( } } + // Determine which idents we introduced in the course of this process. + let mut symbols_introduced = MutMap::default(); + let sorted = sort_type_defs_before_introduction(referenced_type_symbols); let mut aliases = SendMap::default(); let mut abilities = MutMap::default(); @@ -328,6 +331,8 @@ pub(crate) fn canonicalize_defs<'a>( for type_name in sorted { match type_defs.remove(&type_name).unwrap() { TypeDef::AliasLike(name, vars, ann, kind) => { + symbols_introduced.insert(name.value, name.region); + let symbol = name.value; let can_ann = canonicalize_annotation( env, @@ -428,6 +433,8 @@ pub(crate) fn canonicalize_defs<'a>( } TypeDef::Ability(name, members) => { + symbols_introduced.insert(name.value, name.region); + // For now we enforce that aliases cannot reference abilities, so let's wait to // resolve ability definitions until aliases are resolved and in scope below. abilities.insert(name.value, (name, members)); @@ -488,9 +495,6 @@ pub(crate) fn canonicalize_defs<'a>( } } - // Determine which idents we introduced in the course of this process. - let mut symbols_introduced = MutMap::default(); - let mut symbol_to_index: Vec<(IdentId, u32)> = Vec::with_capacity(pending_value_defs.len()); for (def_index, pending_def) in pending_value_defs.iter().enumerate() { From c9d422335f848e66f4936a9489ad2d5692ec7165 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 23 Apr 2022 22:15:09 +0200 Subject: [PATCH 479/846] inline function --- compiler/can/src/def.rs | 5 +++++ compiler/can/src/env.rs | 4 ---- compiler/can/src/expr.rs | 4 +++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 2a0c4341c9..b60784cd87 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1180,8 +1180,13 @@ fn add_annotation_aliases( // See 3d5a2560057d7f25813112dfa5309956c0f9e6a9 and its // parent commit for the bug this fixed! enum DefReferences { + /// A value may not reference itself Value(References), + + /// If the def is a function, different rules apply (it can call itself) Function(References), + + /// An annotation without a body references no other defs AnnotationWithoutBody, } diff --git a/compiler/can/src/env.rs b/compiler/can/src/env.rs index 8c3f3fb8b1..b07cfe0a77 100644 --- a/compiler/can/src/env.rs +++ b/compiler/can/src/env.rs @@ -182,8 +182,4 @@ impl<'a> Env<'a> { pub fn problem(&mut self, problem: Problem) { self.problems.push(problem) } - - pub fn register_closure(&mut self, symbol: Symbol, references: References) { - self.closures.insert(symbol, references); - } } diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index 2dade79cd6..a589b6ca8a 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -699,7 +699,9 @@ pub fn canonicalize_expr<'a>( } } - env.register_closure(symbol, output.references.clone()); + // store the references of this function in the Env. This information is used + // when we canonicalize a surrounding def (if it exists) + env.closures.insert(symbol, output.references.clone()); let mut captured_symbols: Vec<_> = captured_symbols .into_iter() From ca072b6625db41433741295fb82a81ec9c64fba1 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 23 Apr 2022 22:15:17 +0200 Subject: [PATCH 480/846] add function references test --- reporting/tests/test_reporting.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 83951bd8d9..6d0a930545 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -9951,4 +9951,23 @@ I need all branches in an `if` to have the same type! ), ) } + + #[test] + fn always_function() { + // from https://github.com/rtfeldman/roc/commit/1372737f5e53ee5bb96d7e1b9593985e5537023a + // There was a bug where this reported UnusedArgument("val") + // since it was used only in the returned function only. + // + // we want this to not give any warnings/errors! + report_problem_as( + indoc!( + r#" + always = \val -> \_ -> val + + always + "# + ), + "", + ) + } } From 1f824f36640d963b5c55bfc35b8e85842ad6d3d2 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 23 Apr 2022 23:00:20 +0200 Subject: [PATCH 481/846] track exactly when we introduce a symbol in a let-block --- compiler/can/src/def.rs | 98 +++++++++++++++++++++++++++++------------ 1 file changed, 69 insertions(+), 29 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index b60784cd87..b9b035237a 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -110,12 +110,39 @@ enum PendingTypeDef<'a> { /// An invalid alias, that is ignored in the rest of the pipeline /// e.g. a shadowed alias, or a definition like `MyAlias 1 : Int` /// with an incorrect pattern - #[allow(dead_code)] - InvalidAlias { kind: AliasKind }, + InvalidAlias { + #[allow(dead_code)] + kind: AliasKind, + symbol: Symbol, + region: Region, + }, /// An invalid ability, that is ignored in the rest of the pipeline. /// E.g. a shadowed ability, or with a bad definition. - InvalidAbility, + InvalidAbility { + symbol: Symbol, + region: Region, + }, + + AbilityNotOnToplevel, + AbilityShadows, +} + +impl PendingTypeDef<'_> { + fn introduction(&self) -> Option<(Symbol, Region)> { + match self { + PendingTypeDef::Alias { name, ann, .. } => { + let region = Region::span_across(&name.region, &ann.region); + + Some((name.value, region)) + } + PendingTypeDef::Ability { name, .. } => Some((name.value, name.region)), + PendingTypeDef::InvalidAlias { symbol, region, .. } => Some((*symbol, *region)), + PendingTypeDef::InvalidAbility { symbol, region } => Some((*symbol, *region)), + PendingTypeDef::AbilityNotOnToplevel => None, + PendingTypeDef::AbilityShadows => None, + } + } } // See github.com/rtfeldman/roc/issues/800 for discussion of the large_enum_variant check. @@ -280,7 +307,14 @@ pub(crate) fn canonicalize_defs<'a>( let mut referenced_type_symbols = MutMap::default(); + // Determine which idents we introduced in the course of this process. + let mut symbols_introduced = MutMap::default(); + for pending_def in pending_type_defs.into_iter() { + if let Some((symbol, region)) = pending_def.introduction() { + symbols_introduced.insert(symbol, region); + } + match pending_def { PendingTypeDef::Alias { name, @@ -316,14 +350,13 @@ pub(crate) fn canonicalize_defs<'a>( type_defs.insert(name.value, TypeDef::Ability(name, members)); abilities_in_scope.push(name.value); } - PendingTypeDef::InvalidAlias { .. } | PendingTypeDef::InvalidAbility { .. } => { /* ignore */ - } + PendingTypeDef::InvalidAlias { .. } + | PendingTypeDef::InvalidAbility { .. } + | PendingTypeDef::AbilityShadows + | PendingTypeDef::AbilityNotOnToplevel => { /* ignore */ } } } - // Determine which idents we introduced in the course of this process. - let mut symbols_introduced = MutMap::default(); - let sorted = sort_type_defs_before_introduction(referenced_type_symbols); let mut aliases = SendMap::default(); let mut abilities = MutMap::default(); @@ -331,8 +364,6 @@ pub(crate) fn canonicalize_defs<'a>( for type_name in sorted { match type_defs.remove(&type_name).unwrap() { TypeDef::AliasLike(name, vars, ann, kind) => { - symbols_introduced.insert(name.value, name.region); - let symbol = name.value; let can_ann = canonicalize_annotation( env, @@ -433,8 +464,6 @@ pub(crate) fn canonicalize_defs<'a>( } TypeDef::Ability(name, members) => { - symbols_introduced.insert(name.value, name.region); - // For now we enforce that aliases cannot reference abilities, so let's wait to // resolve ability definitions until aliases are resolved and in scope below. abilities.insert(name.value, (name, members)); @@ -461,6 +490,7 @@ pub(crate) fn canonicalize_defs<'a>( &mut output, var_store, &mut scope, + &mut symbols_introduced, abilities, &abilities_in_scope, pattern_type, @@ -535,14 +565,6 @@ pub(crate) fn canonicalize_defs<'a>( def_ordering.insert_symbol_references(def_id as u32, &temp_output.references) } - // this is now mostly responsible for adding type names and ability members - // see if we can do this in a more efficient way - for (symbol, region) in scope.symbols() { - if !original_scope.contains_symbol(*symbol) { - symbols_introduced.insert(*symbol, *region); - } - } - // This returns both the defs info as well as the new scope. // // We have to return the new scope because we added defs to it @@ -550,9 +572,6 @@ pub(crate) fn canonicalize_defs<'a>( // the return expr), but we didn't want to mutate the original scope // directly because we wanted to keep a clone of it around to diff // when looking for unused idents. - // - // We have to return the scope separately from the defs, because the - // defs need to get moved later. ( CanDefs { defs, @@ -567,11 +586,13 @@ pub(crate) fn canonicalize_defs<'a>( } /// Resolve all pending abilities, to add them to scope. +#[allow(clippy::too_many_arguments)] fn resolve_abilities<'a>( env: &mut Env<'a>, output: &mut Output, var_store: &mut VarStore, scope: &mut Scope, + symbols_introduced: &mut MutMap, abilities: MutMap, &[AbilityMember])>, abilities_in_scope: &[Symbol], pattern_type: PatternType, @@ -615,6 +636,8 @@ fn resolve_abilities<'a>( } }; + symbols_introduced.insert(member_sym, name_region); + if pattern_type == PatternType::TopLevelDef { env.top_level_symbols.insert(member_sym); } @@ -1692,7 +1715,11 @@ fn to_pending_type_def<'a>( return Some(( Output::default(), - PendingTypeDef::InvalidAlias { kind }, + PendingTypeDef::InvalidAlias { + kind, + symbol, + region, + }, )); } } @@ -1713,14 +1740,21 @@ fn to_pending_type_def<'a>( Some((Output::default(), pending_def)) } - Err((original_region, loc_shadowed_symbol, _new_symbol)) => { + Err((original_region, loc_shadowed_symbol, new_symbol)) => { env.problem(Problem::Shadowing { original_region, shadow: loc_shadowed_symbol, kind: shadow_kind, }); - Some((Output::default(), PendingTypeDef::InvalidAlias { kind })) + Some(( + Output::default(), + PendingTypeDef::InvalidAlias { + kind, + symbol: new_symbol, + region, + }, + )) } } } @@ -1735,7 +1769,7 @@ fn to_pending_type_def<'a>( ); env.problem(Problem::AbilityNotOnToplevel { region }); - Some((Output::default(), PendingTypeDef::InvalidAbility)) + Some((Output::default(), PendingTypeDef::AbilityNotOnToplevel)) } Ability { @@ -1756,7 +1790,7 @@ fn to_pending_type_def<'a>( shadow: shadowed_symbol, kind: ShadowKind::Ability, }); - return Some((Output::default(), PendingTypeDef::InvalidAbility)); + return Some((Output::default(), PendingTypeDef::AbilityShadows)); } }; @@ -1768,7 +1802,13 @@ fn to_pending_type_def<'a>( name: name.value, variables_region, }); - return Some((Output::default(), PendingTypeDef::InvalidAbility)); + return Some(( + Output::default(), + PendingTypeDef::InvalidAbility { + symbol: name.value, + region: name.region, + }, + )); } let pending_ability = PendingTypeDef::Ability { From 020029138e51968af604d879dc24872c60788775 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 23 Apr 2022 23:02:34 +0200 Subject: [PATCH 482/846] stop always returning an empty output --- compiler/can/src/def.rs | 56 +++++++++++++++-------------------------- 1 file changed, 20 insertions(+), 36 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index b9b035237a..bba41e4c97 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -278,14 +278,7 @@ pub(crate) fn canonicalize_defs<'a>( #[allow(clippy::needless_collect)] let pending_type_defs = type_defs .into_iter() - .filter_map(|loc_def| { - to_pending_type_def(env, loc_def.value, &mut scope, pattern_type).map( - |(new_output, pending_def)| { - output.union(new_output); - pending_def - }, - ) - }) + .filter_map(|loc_def| to_pending_type_def(env, loc_def.value, &mut scope, pattern_type)) .collect::>(); if cfg!(debug_assertions) { @@ -1665,7 +1658,7 @@ fn to_pending_type_def<'a>( def: &'a ast::TypeDef<'a>, scope: &mut Scope, pattern_type: PatternType, -) -> Option<(Output, PendingTypeDef<'a>)> { +) -> Option> { use ast::TypeDef::*; match def { @@ -1713,14 +1706,11 @@ fn to_pending_type_def<'a>( }; env.problems.push(problem); - return Some(( - Output::default(), - PendingTypeDef::InvalidAlias { - kind, - symbol, - region, - }, - )); + return Some(PendingTypeDef::InvalidAlias { + kind, + symbol, + region, + }); } } } @@ -1737,7 +1727,7 @@ fn to_pending_type_def<'a>( kind, }; - Some((Output::default(), pending_def)) + Some(pending_def) } Err((original_region, loc_shadowed_symbol, new_symbol)) => { @@ -1747,14 +1737,11 @@ fn to_pending_type_def<'a>( kind: shadow_kind, }); - Some(( - Output::default(), - PendingTypeDef::InvalidAlias { - kind, - symbol: new_symbol, - region, - }, - )) + Some(PendingTypeDef::InvalidAlias { + kind, + symbol: new_symbol, + region, + }) } } } @@ -1769,7 +1756,7 @@ fn to_pending_type_def<'a>( ); env.problem(Problem::AbilityNotOnToplevel { region }); - Some((Output::default(), PendingTypeDef::AbilityNotOnToplevel)) + Some(PendingTypeDef::AbilityNotOnToplevel) } Ability { @@ -1790,7 +1777,7 @@ fn to_pending_type_def<'a>( shadow: shadowed_symbol, kind: ShadowKind::Ability, }); - return Some((Output::default(), PendingTypeDef::AbilityShadows)); + return Some(PendingTypeDef::AbilityShadows); } }; @@ -1802,13 +1789,10 @@ fn to_pending_type_def<'a>( name: name.value, variables_region, }); - return Some(( - Output::default(), - PendingTypeDef::InvalidAbility { - symbol: name.value, - region: name.region, - }, - )); + return Some(PendingTypeDef::InvalidAbility { + symbol: name.value, + region: name.region, + }); } let pending_ability = PendingTypeDef::Ability { @@ -1817,7 +1801,7 @@ fn to_pending_type_def<'a>( members, }; - Some((Output::default(), pending_ability)) + Some(pending_ability) } } } From 747ff262e03fa332f654fb3eabc182730a710059 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 23 Apr 2022 23:05:54 +0200 Subject: [PATCH 483/846] stop wrapping in an Option --- compiler/can/src/def.rs | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index bba41e4c97..e4cc226eb8 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -278,7 +278,7 @@ pub(crate) fn canonicalize_defs<'a>( #[allow(clippy::needless_collect)] let pending_type_defs = type_defs .into_iter() - .filter_map(|loc_def| to_pending_type_def(env, loc_def.value, &mut scope, pattern_type)) + .map(|loc_def| to_pending_type_def(env, loc_def.value, &mut scope, pattern_type)) .collect::>(); if cfg!(debug_assertions) { @@ -1658,7 +1658,7 @@ fn to_pending_type_def<'a>( def: &'a ast::TypeDef<'a>, scope: &mut Scope, pattern_type: PatternType, -) -> Option> { +) -> PendingTypeDef<'a> { use ast::TypeDef::*; match def { @@ -1706,11 +1706,11 @@ fn to_pending_type_def<'a>( }; env.problems.push(problem); - return Some(PendingTypeDef::InvalidAlias { + return PendingTypeDef::InvalidAlias { kind, symbol, region, - }); + }; } } } @@ -1720,14 +1720,12 @@ fn to_pending_type_def<'a>( value: symbol, }; - let pending_def = PendingTypeDef::Alias { + PendingTypeDef::Alias { name, vars: can_rigids, ann, kind, - }; - - Some(pending_def) + } } Err((original_region, loc_shadowed_symbol, new_symbol)) => { @@ -1737,11 +1735,11 @@ fn to_pending_type_def<'a>( kind: shadow_kind, }); - Some(PendingTypeDef::InvalidAlias { + PendingTypeDef::InvalidAlias { kind, symbol: new_symbol, region, - }) + } } } } @@ -1756,7 +1754,7 @@ fn to_pending_type_def<'a>( ); env.problem(Problem::AbilityNotOnToplevel { region }); - Some(PendingTypeDef::AbilityNotOnToplevel) + PendingTypeDef::AbilityNotOnToplevel } Ability { @@ -1777,7 +1775,7 @@ fn to_pending_type_def<'a>( shadow: shadowed_symbol, kind: ShadowKind::Ability, }); - return Some(PendingTypeDef::AbilityShadows); + return PendingTypeDef::AbilityShadows; } }; @@ -1789,19 +1787,17 @@ fn to_pending_type_def<'a>( name: name.value, variables_region, }); - return Some(PendingTypeDef::InvalidAbility { + return PendingTypeDef::InvalidAbility { symbol: name.value, region: name.region, - }); + }; } - let pending_ability = PendingTypeDef::Ability { + PendingTypeDef::Ability { name, // We'll handle adding the member symbols later on when we do all value defs. members, - }; - - Some(pending_ability) + } } } } From 5c992e49d98b2114d1edffb5a024ccbbd14d0f3d Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 23 Apr 2022 23:33:28 +0200 Subject: [PATCH 484/846] rust is hard sometimes --- compiler/test_gen/src/gen_primitives.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/test_gen/src/gen_primitives.rs b/compiler/test_gen/src/gen_primitives.rs index 50f26c84b9..a9d1691273 100644 --- a/compiler/test_gen/src/gen_primitives.rs +++ b/compiler/test_gen/src/gen_primitives.rs @@ -2992,8 +2992,8 @@ fn mix_function_and_closure_level_of_indirection() { } #[test] -#[cfg_if(not(debug_assertions), ignore)] // this test stack-overflows the compiler in debug mode #[cfg(any(feature = "gen-llvm"))] +#[cfg_attr(debug_assertions, ignore)] // this test stack-overflows the compiler in debug mode fn do_pass_bool_byte_closure_layout() { // see https://github.com/rtfeldman/roc/pull/1706 // the distinction is actually important, dropping that info means some functions just get From a556cccb1eac533f12fd09946802bd323ef9a150 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 23 Apr 2022 23:52:49 +0200 Subject: [PATCH 485/846] populate the matrix --- compiler/can/src/def.rs | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index e4cc226eb8..3cf6ca6e63 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1907,24 +1907,29 @@ fn correct_mutual_recursive_type_alias<'a>( ) -> ImMap { let symbols_introduced: Vec = original_aliases.keys().copied().collect(); - let all_successors_with_self = |symbol: &Symbol| -> Vec { - match original_aliases.get(symbol) { - Some(alias) => { - let mut loc_succ = alias.typ.symbols(); - // remove anything that is not defined in the current block - loc_succ.retain(|key| symbols_introduced.contains(key)); + let mut matrix = ReferenceMatrix::new(original_aliases.len()); - loc_succ + for (index, (_, alias)) in original_aliases.iter().enumerate() { + for referenced in alias.typ.symbols() { + match symbols_introduced.iter().position(|k| referenced == *k) { + None => { /* ignore */ } + Some(ref_id) => matrix.set_row_col(index, ref_id, true), } + } + } + + let all_successors_with_self = |symbol: &Symbol| -> Vec { + match symbols_introduced.iter().position(|k| symbol == k) { + Some(index) => matrix + .references_for(index) + .map(|r| symbols_introduced[r]) + .collect(), None => vec![], } }; - // TODO investigate should this be in a loop? - let defined_symbols: Vec = original_aliases.keys().copied().collect(); - let cycles = - ven_graph::strongly_connected_components(&defined_symbols, all_successors_with_self); + ven_graph::strongly_connected_components(&symbols_introduced, all_successors_with_self); let mut solved_aliases = ImMap::default(); for cycle in cycles { From f7010336bb0c206642a77d8ef05fabab2771345b Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 24 Apr 2022 00:16:26 +0200 Subject: [PATCH 486/846] use vecs more --- compiler/can/src/def.rs | 55 +++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 3cf6ca6e63..bcdde10c17 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1902,15 +1902,25 @@ fn to_pending_value_def<'a>( /// Make aliases recursive fn correct_mutual_recursive_type_alias<'a>( env: &mut Env<'a>, - mut original_aliases: SendMap, + original_aliases: SendMap, var_store: &mut VarStore, ) -> ImMap { - let symbols_introduced: Vec = original_aliases.keys().copied().collect(); + let capacity = original_aliases.len(); + let mut matrix = ReferenceMatrix::new(capacity); - let mut matrix = ReferenceMatrix::new(original_aliases.len()); + let (symbols_introduced, mut aliases): (Vec<_>, Vec<_>) = original_aliases + .into_iter() + .map(|(k, v)| (k, Some(v))) + .unzip(); - for (index, (_, alias)) in original_aliases.iter().enumerate() { - for referenced in alias.typ.symbols() { + for (index, alias) in aliases.iter().enumerate() { + let it = alias + .as_ref() + .map(|a| a.typ.symbols().into_iter()) + .into_iter() + .flatten(); + + for referenced in it { match symbols_introduced.iter().position(|k| referenced == *k) { None => { /* ignore */ } Some(ref_id) => matrix.set_row_col(index, ref_id, true), @@ -1918,26 +1928,23 @@ fn correct_mutual_recursive_type_alias<'a>( } } - let all_successors_with_self = |symbol: &Symbol| -> Vec { - match symbols_introduced.iter().position(|k| symbol == k) { - Some(index) => matrix - .references_for(index) - .map(|r| symbols_introduced[r]) - .collect(), - None => vec![], - } - }; - - let cycles = - ven_graph::strongly_connected_components(&symbols_introduced, all_successors_with_self); let mut solved_aliases = ImMap::default(); + let group: Vec<_> = (0u32..capacity as u32).collect(); + + let cycles = matrix.strongly_connected_components(&group); + for cycle in cycles { debug_assert!(!cycle.is_empty()); let mut pending_aliases: ImMap<_, _> = cycle .iter() - .map(|&sym| (sym, original_aliases.remove(&sym).unwrap())) + .map(|index| { + ( + symbols_introduced[*index as usize], + aliases[*index as usize].take().unwrap(), + ) + }) .collect(); // Make sure we report only one error for the cycle, not an error for every @@ -1952,7 +1959,9 @@ fn correct_mutual_recursive_type_alias<'a>( // NB: ImMap::clone is O(1): https://docs.rs/im/latest/src/im/hash/map.rs.html#1527-1544 let mut to_instantiate = solved_aliases.clone().union(pending_aliases.clone()); - for &rec in cycle.iter() { + for index in cycle.iter() { + let rec = symbols_introduced[*index as usize]; + let alias = pending_aliases.get_mut(&rec).unwrap(); // Don't try to instantiate the alias itself in its definition. let original_alias_def = to_instantiate.remove(&rec).unwrap(); @@ -1992,14 +2001,18 @@ fn correct_mutual_recursive_type_alias<'a>( // The cycle we just instantiated and marked recursive may still be an illegal cycle, if // all the types in the cycle are narrow newtypes. We can't figure this out until now, // because we need all the types to be deeply instantiated. - let all_are_narrow = cycle.iter().all(|sym| { + let all_are_narrow = cycle.iter().all(|index| { + let sym = &symbols_introduced[*index as usize]; let typ = &pending_aliases.get(sym).unwrap().typ; matches!(typ, Type::RecursiveTagUnion(..)) && typ.is_narrow() }); if all_are_narrow { // This cycle is illegal! - let mut rest = cycle; + let mut rest: Vec = cycle + .into_iter() + .map(|i| symbols_introduced[i as usize]) + .collect(); let alias_name = rest.pop().unwrap(); let alias = pending_aliases.get_mut(&alias_name).unwrap(); From b0ceaf037242e981aa38e7128067d8cbdb846b99 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 24 Apr 2022 01:04:59 +0200 Subject: [PATCH 487/846] instantiate aliases with a function --- compiler/can/src/def.rs | 11 +++++------ compiler/types/src/types.rs | 26 ++++++++++++++++---------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index bcdde10c17..04d5a2ccaa 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1966,13 +1966,12 @@ fn correct_mutual_recursive_type_alias<'a>( // Don't try to instantiate the alias itself in its definition. let original_alias_def = to_instantiate.remove(&rec).unwrap(); + let helper = |s| to_instantiate.get(&s); + let mut new_lambda_sets = ImSet::default(); - alias.typ.instantiate_aliases( - alias.region, - &to_instantiate, - var_store, - &mut new_lambda_sets, - ); + alias + .typ + .instantiate_aliases(alias.region, &helper, var_store, &mut new_lambda_sets); for lambda_set_var in new_lambda_sets { alias diff --git a/compiler/types/src/types.rs b/compiler/types/src/types.rs index 0f3536cd54..0e51c2dda4 100644 --- a/compiler/types/src/types.rs +++ b/compiler/types/src/types.rs @@ -120,13 +120,15 @@ impl RecordField { } } - pub fn instantiate_aliases( + pub fn instantiate_aliases<'a, F>( &mut self, region: Region, - aliases: &ImMap, + aliases: &'a F, var_store: &mut VarStore, introduced: &mut ImSet, - ) { + ) where + F: Fn(Symbol) -> Option<&'a Alias>, + { use RecordField::*; match self { @@ -168,13 +170,15 @@ impl LambdaSet { &mut self.0 } - fn instantiate_aliases( + fn instantiate_aliases<'a, F>( &mut self, region: Region, - aliases: &ImMap, + aliases: &'a F, var_store: &mut VarStore, introduced: &mut ImSet, - ) { + ) where + F: Fn(Symbol) -> Option<&'a Alias>, + { self.0 .instantiate_aliases(region, aliases, var_store, introduced) } @@ -1064,13 +1068,15 @@ impl Type { result } - pub fn instantiate_aliases( + pub fn instantiate_aliases<'a, F>( &mut self, region: Region, - aliases: &ImMap, + aliases: &'a F, var_store: &mut VarStore, new_lambda_set_variables: &mut ImSet, - ) { + ) where + F: Fn(Symbol) -> Option<&'a Alias>, + { use Type::*; match self { @@ -1138,7 +1144,7 @@ impl Type { ); } Apply(symbol, args, _) => { - if let Some(alias) = aliases.get(symbol) { + if let Some(alias) = aliases(*symbol) { // TODO switch to this, but we still need to check for recursion with the // `else` branch if false { From 05164aad4be059842224ed1adffc35fb2a0afb2a Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sat, 23 Apr 2022 19:35:15 -0400 Subject: [PATCH 488/846] Use divTruncChecked over divFloorChecked in Deriv --- examples/benchmarks/Deriv.roc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/benchmarks/Deriv.roc b/examples/benchmarks/Deriv.roc index 90e641cb0f..46ae9c73f7 100644 --- a/examples/benchmarks/Deriv.roc +++ b/examples/benchmarks/Deriv.roc @@ -41,7 +41,7 @@ Expr : [ Val I64, Var Str, Add Expr Expr, Mul Expr Expr, Pow Expr Expr, Ln Expr divmod : I64, I64 -> Result { div : I64, mod : I64 } [ DivByZero ]* divmod = \l, r -> - when Pair (Num.divFloorChecked l r) (Num.remChecked l r) is + when Pair (Num.divTruncChecked l r) (Num.remChecked l r) is Pair div (Ok mod) -> Ok { div, mod } From 061b26e90d89d49986e5b883def2e5ea906a50ba Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sat, 23 Apr 2022 16:29:12 -0400 Subject: [PATCH 489/846] Add breakout to examples under test --- cli/tests/cli_run.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cli/tests/cli_run.rs b/cli/tests/cli_run.rs index cbae982ddb..fae6dd7083 100644 --- a/cli/tests/cli_run.rs +++ b/cli/tests/cli_run.rs @@ -394,6 +394,14 @@ mod cli_run { expected_ending: "", use_valgrind: false, }, + breakout:"breakout" => Example { + filename: "breakout.roc", + executable_filename: "breakout", + stdin: &[], + input_file: None, + expected_ending: "", + use_valgrind: false, + }, quicksort:"algorithms" => Example { filename: "quicksort.roc", executable_filename: "quicksort", From 83d08a10c6112bf9ff63227118ff1f0081cf4195 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sat, 23 Apr 2022 20:02:28 -0400 Subject: [PATCH 490/846] Fix type mismatch in Deriv example --- examples/benchmarks/Deriv.roc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/benchmarks/Deriv.roc b/examples/benchmarks/Deriv.roc index 46ae9c73f7..8407d641c2 100644 --- a/examples/benchmarks/Deriv.roc +++ b/examples/benchmarks/Deriv.roc @@ -42,7 +42,7 @@ Expr : [ Val I64, Var Str, Add Expr Expr, Mul Expr Expr, Pow Expr Expr, Ln Expr divmod : I64, I64 -> Result { div : I64, mod : I64 } [ DivByZero ]* divmod = \l, r -> when Pair (Num.divTruncChecked l r) (Num.remChecked l r) is - Pair div (Ok mod) -> + Pair (Ok div) (Ok mod) -> Ok { div, mod } _ -> From 452447232f5b4e52cd56177d0b51b64f1f55617f Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 24 Apr 2022 02:18:43 +0200 Subject: [PATCH 491/846] bitvec all the things --- compiler/can/src/def.rs | 100 ++++++++++++++++----------- compiler/can/src/reference_matrix.rs | 5 ++ reporting/tests/test_reporting.rs | 50 +++++++------- 3 files changed, 88 insertions(+), 67 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 04d5a2ccaa..ed91f77c11 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -467,6 +467,7 @@ pub(crate) fn canonicalize_defs<'a>( // Now that we know the alias dependency graph, we can try to insert recursion variables // where aliases are recursive tag unions, or detect illegal recursions. let mut aliases = correct_mutual_recursive_type_alias(env, aliases, var_store); + for (symbol, alias) in aliases.iter() { scope.add_alias( *symbol, @@ -1908,19 +1909,10 @@ fn correct_mutual_recursive_type_alias<'a>( let capacity = original_aliases.len(); let mut matrix = ReferenceMatrix::new(capacity); - let (symbols_introduced, mut aliases): (Vec<_>, Vec<_>) = original_aliases - .into_iter() - .map(|(k, v)| (k, Some(v))) - .unzip(); + let (symbols_introduced, mut aliases): (Vec<_>, Vec<_>) = original_aliases.into_iter().unzip(); for (index, alias) in aliases.iter().enumerate() { - let it = alias - .as_ref() - .map(|a| a.typ.symbols().into_iter()) - .into_iter() - .flatten(); - - for referenced in it { + for referenced in alias.typ.symbols() { match symbols_introduced.iter().position(|k| referenced == *k) { None => { /* ignore */ } Some(ref_id) => matrix.set_row_col(index, ref_id, true), @@ -1928,7 +1920,8 @@ fn correct_mutual_recursive_type_alias<'a>( } } - let mut solved_aliases = ImMap::default(); + let mut solved_aliases_bitvec = bitvec::vec::BitVec::::repeat(false, capacity); + let mut pending_aliases_bitvec = bitvec::vec::BitVec::repeat(false, capacity); let group: Vec<_> = (0u32..capacity as u32).collect(); @@ -1937,15 +1930,12 @@ fn correct_mutual_recursive_type_alias<'a>( for cycle in cycles { debug_assert!(!cycle.is_empty()); - let mut pending_aliases: ImMap<_, _> = cycle - .iter() - .map(|index| { - ( - symbols_introduced[*index as usize], - aliases[*index as usize].take().unwrap(), - ) - }) - .collect(); + // zero out all the bits + pending_aliases_bitvec.set_elements(0); + + for index in cycle.iter() { + pending_aliases_bitvec.set(*index as usize, true); + } // Make sure we report only one error for the cycle, not an error for every // alias in the cycle. @@ -1955,23 +1945,43 @@ fn correct_mutual_recursive_type_alias<'a>( // depends on. // We only need to worry about symbols in this SCC or any prior one, since the SCCs // were sorted topologically, and we've already instantiated aliases coming from other - // modules. - // NB: ImMap::clone is O(1): https://docs.rs/im/latest/src/im/hash/map.rs.html#1527-1544 - let mut to_instantiate = solved_aliases.clone().union(pending_aliases.clone()); + let mut to_instantiate_bitvec = solved_aliases_bitvec | &pending_aliases_bitvec; for index in cycle.iter() { - let rec = symbols_introduced[*index as usize]; + let index = *index as usize; - let alias = pending_aliases.get_mut(&rec).unwrap(); // Don't try to instantiate the alias itself in its definition. - let original_alias_def = to_instantiate.remove(&rec).unwrap(); + to_instantiate_bitvec.set(index, false); - let helper = |s| to_instantiate.get(&s); + // now we do something sneaky. In `can_instantiate_symbol` we want to be able to + // take a reference to an `Alias` in the `aliases` vec. That would not work if + // we also had a mutable reference to an alias in that vec. So we swap out the + // type. + let alias_region = aliases[index].region; + let mut alias_type = Type::EmptyRec; + + std::mem::swap(&mut alias_type, &mut aliases[index].typ); + + let can_instantiate_symbol = |s| match symbols_introduced.iter().position(|i| *i == s) { + Some(s_index) if to_instantiate_bitvec[s_index] => aliases.get(s_index), + _ => None, + }; let mut new_lambda_sets = ImSet::default(); - alias - .typ - .instantiate_aliases(alias.region, &helper, var_store, &mut new_lambda_sets); + alias_type.instantiate_aliases( + alias_region, + &can_instantiate_symbol, + var_store, + &mut new_lambda_sets, + ); + + // swap the type back + std::mem::swap(&mut alias_type, &mut aliases[index].typ); + + // We can instantiate this alias in future iterations + to_instantiate_bitvec.set(index, true); + + let alias = &mut aliases[index]; for lambda_set_var in new_lambda_sets { alias @@ -1979,10 +1989,9 @@ fn correct_mutual_recursive_type_alias<'a>( .push(LambdaSet(Type::Variable(lambda_set_var))); } - to_instantiate.insert(rec, original_alias_def); - // Now mark the alias recursive, if it needs to be. - let is_self_recursive = alias.typ.contains_symbol(rec); + let rec = symbols_introduced[index]; + let is_self_recursive = cycle.len() == 1 && matrix.get_row_col(index, index); let is_mutually_recursive = cycle.len() > 1; if is_self_recursive || is_mutually_recursive { @@ -2001,20 +2010,24 @@ fn correct_mutual_recursive_type_alias<'a>( // all the types in the cycle are narrow newtypes. We can't figure this out until now, // because we need all the types to be deeply instantiated. let all_are_narrow = cycle.iter().all(|index| { - let sym = &symbols_introduced[*index as usize]; - let typ = &pending_aliases.get(sym).unwrap().typ; + let index = *index as usize; + let typ = &aliases[index].typ; matches!(typ, Type::RecursiveTagUnion(..)) && typ.is_narrow() }); if all_are_narrow { // This cycle is illegal! - let mut rest: Vec = cycle + + let mut cycle = cycle; + let first_index = cycle.pop().unwrap() as usize; + + let rest: Vec = cycle .into_iter() .map(|i| symbols_introduced[i as usize]) .collect(); - let alias_name = rest.pop().unwrap(); - let alias = pending_aliases.get_mut(&alias_name).unwrap(); + let alias_name = symbols_introduced[first_index]; + let alias = aliases.get_mut(first_index).unwrap(); mark_cyclic_alias( env, @@ -2026,11 +2039,14 @@ fn correct_mutual_recursive_type_alias<'a>( ) } - // Now, promote all resolved aliases in this cycle as solved. - solved_aliases.extend(pending_aliases); + // We've instantiated all we could, so all instantiatable aliases are solved now + solved_aliases_bitvec = to_instantiate_bitvec; } - solved_aliases + symbols_introduced + .into_iter() + .zip(aliases.into_iter()) + .collect() } fn make_tag_union_of_alias_recursive<'a>( diff --git a/compiler/can/src/reference_matrix.rs b/compiler/can/src/reference_matrix.rs index ab858d08c3..eef869c3b5 100644 --- a/compiler/can/src/reference_matrix.rs +++ b/compiler/can/src/reference_matrix.rs @@ -40,6 +40,11 @@ impl ReferenceMatrix { self.bitvec[index] } + #[inline(always)] + pub fn get_row_col(&self, row: usize, col: usize) -> bool { + self.bitvec[row * self.length + col] + } + pub fn is_recursive(&self, index: usize) -> bool { let mut scheduled = self.row_slice(index).to_bitvec(); let mut visited = self.row_slice(index).to_bitvec(); diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 6d0a930545..b1929d9919 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -3264,15 +3264,15 @@ mod test_reporting { ── DUPLICATE FIELD NAME ────────────────────────────────── /code/proj/Main.roc ─ This record type defines the `.foo` field twice! - + 1│ a : { foo : Num.I64, bar : {}, foo : Str } ^^^^^^^^^^^^^ ^^^^^^^^^ - + In the rest of the program, I will only use the latter definition: - + 1│ a : { foo : Num.I64, bar : {}, foo : Str } ^^^^^^^^^ - + For clarity, remove the previous `.foo` definitions from this record type. "# @@ -3296,15 +3296,15 @@ mod test_reporting { ── DUPLICATE TAG NAME ──────────────────────────────────── /code/proj/Main.roc ─ This tag union type defines the `Foo` tag twice! - + 1│ a : [ Foo Num.I64, Bar {}, Foo Str ] ^^^^^^^^^^^ ^^^^^^^ - + In the rest of the program, I will only use the latter definition: - + 1│ a : [ Foo Num.I64, Bar {}, Foo Str ] ^^^^^^^ - + For clarity, remove the previous `Foo` definitions from this tag union type. "# @@ -3433,10 +3433,10 @@ mod test_reporting { ── TOO MANY TYPE ARGUMENTS ─────────────────────────────── /code/proj/Main.roc ─ The `Num` alias expects 1 type argument, but it got 2 instead: - + 1│ a : Num.Num Num.I64 Num.F64 ^^^^^^^^^^^^^^^^^^^^^^^ - + Are there missing parentheses? "# ), @@ -3459,10 +3459,10 @@ mod test_reporting { ── TOO MANY TYPE ARGUMENTS ─────────────────────────────── /code/proj/Main.roc ─ The `Num` alias expects 1 type argument, but it got 2 instead: - + 1│ f : Str -> Num.Num Num.I64 Num.F64 ^^^^^^^^^^^^^^^^^^^^^^^ - + Are there missing parentheses? "# ), @@ -3646,8 +3646,8 @@ mod test_reporting { This `ACons` global tag application has the type: [ ACons (Num (Integer Signed64)) [ - BCons (Num (Integer Signed64)) [ ACons Str [ BCons I64 a, BNil ], - ANil ], BNil ], ANil ] + BCons (Num (Integer Signed64)) [ ACons Str [ + BCons I64 (AList I64 I64), BNil ] as a, ANil ], BNil ], ANil ] But the type annotation on `x` says it should be: @@ -7092,20 +7092,20 @@ I need all branches in an `if` to have the same type! indoc!( r#" ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ - + Something is off with the body of the `inner` definition: - + 3│ inner : * -> * 4│ inner = \y -> y ^ - + The type annotation on `inner` says this `y` value should have the type: - + * - + However, the type of this `y` value is connected to another type in a way that isn't reflected in this annotation. - + Tip: Any connection between types must use a named type variable, not a `*`! Maybe the annotation on `inner` should have a named type variable in place of the `*`? @@ -8867,21 +8867,21 @@ I need all branches in an `if` to have the same type! ^^^^^^^^^^^ Did you mean one of these? - + Type True Box Ok - + ── UNRECOGNIZED NAME ───────────────────────────────────── /code/proj/Main.roc ─ I cannot find a `UnknownType` value - + 3│ insertHelper : UnknownType, Type -> Type ^^^^^^^^^^^ - + Did you mean one of these? - + Type True insertHelper From 3e1722ac019ec0408916be6bcde8c06d4ae4940d Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sat, 23 Apr 2022 20:37:23 -0400 Subject: [PATCH 492/846] Fix breakout example --- examples/breakout/breakout.roc | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index 474d0be36c..685af8bda1 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -11,6 +11,7 @@ blockBorder = 0.025 # border of a block, as a % of its width ballSize = 55 numRows = 4 numCols = 8 +numBlocks = numRows * numCols Model : { # Screen height and width From 57b783291763bb2a7fb761b4aabba527197819a2 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sat, 23 Apr 2022 20:51:57 -0400 Subject: [PATCH 493/846] Upgrade target-lexicon --- Cargo.lock | 4 ++-- cli/Cargo.toml | 2 +- compiler/build/Cargo.toml | 2 +- compiler/gen_dev/Cargo.toml | 2 +- compiler/gen_llvm/Cargo.toml | 2 +- compiler/roc_target/Cargo.toml | 2 +- compiler/test_gen/Cargo.toml | 2 +- linker/Cargo.toml | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0690cc0fb7..4be66b0f03 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4489,9 +4489,9 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "target-lexicon" -version = "0.12.2" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9bffcddbc2458fa3e6058414599e3c838a022abae82e5c67b4f7f80298d5bff" +checksum = "d7fa7e55043acb85fca6b3c01485a2eeb6b69c5d21002e273c79e465f43b7ac1" [[package]] name = "tempfile" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 4b5d13d1c1..65921d9495 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -66,7 +66,7 @@ const_format = "0.2.22" bumpalo = { version = "3.8.0", features = ["collections"] } mimalloc = { version = "0.1.26", default-features = false } -target-lexicon = "0.12.2" +target-lexicon = "0.12.3" tempfile = "3.2.0" wasmer-wasi = { version = "2.0.0", optional = true } diff --git a/compiler/build/Cargo.toml b/compiler/build/Cargo.toml index 323a820d46..218f783af5 100644 --- a/compiler/build/Cargo.toml +++ b/compiler/build/Cargo.toml @@ -30,7 +30,7 @@ bumpalo = { version = "3.8.0", features = ["collections"] } libloading = "0.7.1" tempfile = "3.2.0" inkwell = { path = "../../vendor/inkwell", optional = true } -target-lexicon = "0.12.2" +target-lexicon = "0.12.3" [target.'cfg(target_os = "macos")'.dependencies] serde_json = "1.0.69" diff --git a/compiler/gen_dev/Cargo.toml b/compiler/gen_dev/Cargo.toml index 0b5a08fe0d..00b08bd467 100644 --- a/compiler/gen_dev/Cargo.toml +++ b/compiler/gen_dev/Cargo.toml @@ -19,7 +19,7 @@ roc_mono = { path = "../mono" } roc_target = { path = "../roc_target" } roc_error_macros = { path = "../../error_macros" } bumpalo = { version = "3.8.0", features = ["collections"] } -target-lexicon = "0.12.2" +target-lexicon = "0.12.3" # TODO: Deal with the update of object to 0.27. # It looks like it breaks linking the generated objects. # Probably just need to specify an extra field that used to be implicit or something. diff --git a/compiler/gen_llvm/Cargo.toml b/compiler/gen_llvm/Cargo.toml index 26335be9ff..3a1ebe8a57 100644 --- a/compiler/gen_llvm/Cargo.toml +++ b/compiler/gen_llvm/Cargo.toml @@ -18,4 +18,4 @@ roc_std = { path = "../../roc_std", default-features = false } morphic_lib = { path = "../../vendor/morphic_lib" } bumpalo = { version = "3.8.0", features = ["collections"] } inkwell = { path = "../../vendor/inkwell" } -target-lexicon = "0.12.2" +target-lexicon = "0.12.3" diff --git a/compiler/roc_target/Cargo.toml b/compiler/roc_target/Cargo.toml index 28211dbdc9..5ef3aba2d9 100644 --- a/compiler/roc_target/Cargo.toml +++ b/compiler/roc_target/Cargo.toml @@ -6,4 +6,4 @@ license = "UPL-1.0" edition = "2018" [dependencies] -target-lexicon = "0.12.2" +target-lexicon = "0.12.3" diff --git a/compiler/test_gen/Cargo.toml b/compiler/test_gen/Cargo.toml index 203b669d48..e1adaa8ef4 100644 --- a/compiler/test_gen/Cargo.toml +++ b/compiler/test_gen/Cargo.toml @@ -37,7 +37,7 @@ bumpalo = { version = "3.8.0", features = ["collections"] } either = "1.6.1" libc = "0.2.106" inkwell = { path = "../../vendor/inkwell" } -target-lexicon = "0.12.2" +target-lexicon = "0.12.3" libloading = "0.7.1" wasmer-wasi = "2.0.0" tempfile = "3.2.0" diff --git a/linker/Cargo.toml b/linker/Cargo.toml index c95a3ee5e2..d71102aa95 100644 --- a/linker/Cargo.toml +++ b/linker/Cargo.toml @@ -28,5 +28,5 @@ memmap2 = "0.5.3" object = { version = "0.26.2", features = ["read", "write"] } serde = { version = "1.0.130", features = ["derive"] } bincode = "1.3.3" -target-lexicon = "0.12.2" +target-lexicon = "0.12.3" tempfile = "3.2.0" From cae89de3c2e9772d3301af86b1be5515ac8b52d4 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sat, 23 Apr 2022 22:09:34 -0400 Subject: [PATCH 494/846] roc format examples/breakout --- examples/breakout/breakout.roc | 129 ++++++++++-------- examples/breakout/hello.roc | 1 - examples/breakout/platform/Game.roc | 3 +- examples/breakout/platform/Package-Config.roc | 2 +- 4 files changed, 73 insertions(+), 62 deletions(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index 685af8bda1..6c1fd50f5a 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -3,30 +3,30 @@ app "breakout" imports [ pf.Game.{ Bounds, Elem, Event } ] provides [ program ] { Model } to pf -paddleWidth = 0.2 # width of the paddle, as a % of screen width -paddleHeight = 50 # height of the paddle, in pixels -paddleSpeed = 65 # how many pixels the paddle moves per keypress -blockHeight = 80 # height of a block, in pixels -blockBorder = 0.025 # border of a block, as a % of its width +paddleWidth = 0.2# width of the paddle, as a % of screen width +paddleHeight = 50# height of the paddle, in pixels +paddleSpeed = 65# how many pixels the paddle moves per keypress +blockHeight = 80# height of a block, in pixels +blockBorder = 0.025# border of a block, as a % of its width ballSize = 55 numRows = 4 numCols = 8 numBlocks = numRows * numCols Model : { - # Screen height and width - height : F32, - width : F32, - - # Paddle X-coordinate - paddleX : F32, - - # Ball coordinates - ballX : F32, - ballY : F32, - dBallX : F32, # delta x - how much it moves per tick - dBallY : F32, # delta y - how much it moves per tick -} + # Screen height and width + height : F32, + width : F32, + # Paddle X-coordinate + paddleX : F32, + # Ball coordinates + ballX : F32, + ballY : F32, + dBallX : F32, + # delta x - how much it moves per tick + dBallY : F32, + # delta y - how much it moves per tick + } init : Bounds -> Model init = \{ width, height } -> @@ -34,14 +34,11 @@ init = \{ width, height } -> # Screen height and width width, height, - # Paddle X-coordinate paddleX: (width * 0.5) - (paddleWidth * width * 0.5), - # Ball coordinates ballX: width * 0.5, ballY: height * 0.4, - # Delta - how much ball moves in each tick dBallX: 4, dBallY: 4, @@ -50,11 +47,20 @@ init = \{ width, height } -> update : Model, Event -> Model update = \model, event -> when event is - Resize size -> { model & width: size.width, height: size.height } - KeyDown Left -> { model & paddleX: model.paddleX - paddleSpeed } - KeyDown Right -> { model & paddleX: model.paddleX + paddleSpeed } - Tick _ -> tick model - _ -> model + Resize size -> + { model & width: size.width, height: size.height } + + KeyDown Left -> + { model & paddleX: model.paddleX - paddleSpeed } + + KeyDown Right -> + { model & paddleX: model.paddleX + paddleSpeed } + + Tick _ -> + tick model + + _ -> + model tick : Model -> Model tick = \model -> @@ -89,49 +95,56 @@ moveBall = \model -> render : Model -> List Elem render = \model -> - blocks = List.map (List.range 0 numBlocks) \index -> - col = - Num.rem index numCols - |> Result.withDefault 0 - |> Num.toF32 + blocks = List.map + (List.range 0 numBlocks) + \index -> + col = + Num.rem index numCols + |> Result.withDefault 0 + |> Num.toF32 - row = - index // numCols - |> Num.toF32 + row = + index + // numCols + |> Num.toF32 - red = col / Num.toF32 numCols - green = row / Num.toF32 numRows - blue = Num.toF32 index / Num.toF32 numBlocks + red = col / Num.toF32 numCols + green = row / Num.toF32 numRows + blue = Num.toF32 index / Num.toF32 numBlocks - color = { r: red * 0.8, g: 0.2 + green * 0.6, b: 0.2 + blue * 0.8, a: 1 } + color = { r: red * 0.8, g: 0.2 + green * 0.6, b: 0.2 + blue * 0.8, a: 1 } - { row, col, color } + { row, col, color } blockWidth = model.width / numCols rects = - List.joinMap blocks \{ row, col, color } -> - left = Num.toF32 col * blockWidth - top = Num.toF32 (row * blockHeight) - border = blockBorder * blockWidth + List.joinMap + blocks + \{ row, col, color } -> + left = Num.toF32 col * blockWidth + top = Num.toF32 (row * blockHeight) + border = blockBorder * blockWidth - outer = Rect { - left, - top, - width: blockWidth, - height: blockHeight, - color: { r: color.r * 0.8, g: color.g * 0.8, b: color.b * 0.8, a: 1 }, - } + outer = Rect + { + left, + top, + width: blockWidth, + height: blockHeight, + color: { r: color.r * 0.8, g: color.g * 0.8, b: color.b * 0.8, a: 1 }, + } - inner = Rect { - left: left + border, - top: top + border, - width: blockWidth - (border * 2), - height: blockHeight - (border * 2), - color, - } + inner = Rect + { + left: left + border, + top: top + border, + width: blockWidth - (border * 2), + height: blockHeight - (border * 2), + color, + } - [ outer, inner ] + [ outer, inner ] ball = color = { r: 0.7, g: 0.3, b: 0.9, a: 1.0 } diff --git a/examples/breakout/hello.roc b/examples/breakout/hello.roc index 05beac5d8c..f1a486f889 100644 --- a/examples/breakout/hello.roc +++ b/examples/breakout/hello.roc @@ -11,7 +11,6 @@ init = \_ -> { text: "Hello, World!" } update : Model, Event -> Model update = \model, _ -> model - render : Model -> List Elem render = \model -> [ Text model.text ] diff --git a/examples/breakout/platform/Game.roc b/examples/breakout/platform/Game.roc index 5b38203de2..bb270cb299 100644 --- a/examples/breakout/platform/Game.roc +++ b/examples/breakout/platform/Game.roc @@ -4,11 +4,10 @@ interface Game Rgba : { r : F32, g : F32, b : F32, a : F32 } -Bounds : { height : F32, width: F32 } +Bounds : { height : F32, width : F32 } Elem : [ Rect { color : Rgba, left : F32, top : F32, width : F32, height : F32 }, Text Str ] KeyCode : [ Left, Right, Other ] Event : [ Resize { width : F32, height : F32 }, KeyDown KeyCode, KeyUp KeyCode, Tick U128 ] - diff --git a/examples/breakout/platform/Package-Config.roc b/examples/breakout/platform/Package-Config.roc index 3e37292a1c..87004e3735 100644 --- a/examples/breakout/platform/Package-Config.roc +++ b/examples/breakout/platform/Package-Config.roc @@ -9,6 +9,6 @@ platform "gui" programForHost : { init : (Bounds -> Model) as Init, update : (Model, Event -> Model) as Update, - render : (Model -> List Elem) as Render + render : (Model -> List Elem) as Render, } programForHost = program From 5d75be38b6470d24066f7acdf9dca80ce3277d80 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sat, 23 Apr 2022 22:38:05 -0400 Subject: [PATCH 495/846] Num.rem no longer returns a Result --- examples/breakout/breakout.roc | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index 6c1fd50f5a..d06e3ab45f 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -100,7 +100,6 @@ render = \model -> \index -> col = Num.rem index numCols - |> Result.withDefault 0 |> Num.toF32 row = From 43a6b5ca5a00b6416fd87ea865b572fbf2c24e1c Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Sun, 24 Apr 2022 11:15:03 +0200 Subject: [PATCH 496/846] Fix tutorial The example package was moved from `example/cli/platform` to `example/interactive/cli-platform` in https://github.com/rtfeldman/roc/pull/2470 --- TUTORIAL.md | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/TUTORIAL.md b/TUTORIAL.md index 492df1678f..10859e609e 100644 --- a/TUTORIAL.md +++ b/TUTORIAL.md @@ -115,18 +115,19 @@ Create a new file called `Hello.roc` and put this inside it: ```coffee app "hello" - packages { pf: "examples/cli/platform" } + packages { pf: "examples/interactive/cli-platform" } imports [ pf.Stdout ] provides [ main ] to pf main = Stdout.line "I'm a Roc application!" ``` -> **NOTE:** This assumes you've put Hello.roc in the root directory of the -> Roc source code. If you'd like to put it somewhere else, you'll need to replace -> `"examples/cli/"` with the path to the `examples/cli/` folder in -> that source code. In the future, Roc will have the tutorial built in, and this -> aside will no longer be necessary! +> **NOTE:** This assumes you've put Hello.roc in the root directory of the Roc +> source code. If you'd like to put it somewhere else, you'll need to replace +> `"examples/interactive/cli-platform"` with the path to the +> `examples/interactive/cli-platform` folder in that source code. In the future, +> Roc will have the tutorial built in, and this aside will no longer be +> necessary! Try running this with: @@ -1236,7 +1237,7 @@ Let's take a closer look at the part of `Hello.roc` above `main`: ```coffee app "hello" - packages { pf: "examples/cli/platform" } + packages { pf: "examples/interactive/cli-platform" } imports [ pf.Stdout ] provides main to pf ``` @@ -1254,14 +1255,14 @@ without running it by running `roc build Hello.roc`. The remaining lines all involve the *platform* this application is built on: ```coffee -packages { pf: "examples/cli/platform" } +packages { pf: "examples/interactive/cli-platform" } imports [ pf.Stdout ] provides main to pf ``` -The `packages { pf: "examples/cli/platform" }` part says two things: +The `packages { pf: "examples/interactive/cli-platform" }` part says two things: -- We're going to be using a *package* (that is, a collection of modules) called `"examples/cli/platform"` +- We're going to be using a *package* (that is, a collection of modules) called `"examples/interactive/cli-platform"` - We're going to name that package `pf` so we can refer to it more concisely in the future. The `imports [ pf.Stdout ]` line says that we want to import the `Stdout` module @@ -1281,17 +1282,18 @@ calling a function named `line` which is exposed by a module named When we write `imports [ pf.Stdout ]`, it specifies that the `Stdout` module comes from the `pf` package. -Since `pf` was the name we chose for the `examples/cli/platform` package -(when we wrote `packages { pf: "examples/cli/platform" }`), this `imports` line -tells the Roc compiler that when we call `Stdout.line`, it should look for that -`line` function in the `Stdout` module of the `examples/cli/platform` package. +Since `pf` was the name we chose for the `examples/interactive/cli-platform` +package (when we wrote `packages { pf: "examples/interactive/cli-platform" }`), +this `imports` line tells the Roc compiler that when we call `Stdout.line`, it +should look for that `line` function in the `Stdout` module of the +`examples/interactive/cli-platform` package. # Building a Command-Line Interface (CLI) ## Tasks Tasks are technically not part of the Roc language, but they're very common in -platforms. Let's use the CLI platform in `examples/cli` as an example! +platforms. Let's use the CLI platform in `examples/interactive/cli-platform` as an example! In the CLI platform, we have four operations we can do: @@ -1306,7 +1308,7 @@ First, let's do a basic "Hello World" using the tutorial app. ```coffee app "cli-tutorial" - packages { pf: "examples/cli/platform" } + packages { pf: "examples/interactive/cli-platform" } imports [ pf.Stdout ] provides [ main ] to pf @@ -1343,7 +1345,7 @@ Let's change `main` to read a line from `stdin`, and then print it back out agai ```swift app "cli-tutorial" - packages { pf: "examples/cli/platform" } + packages { pf: "examples/interactive/cli-platform" } imports [ pf.Stdout, pf.Stdin, pf.Task ] provides [ main ] to pf @@ -1393,7 +1395,7 @@ This works, but we can make it a little nicer to read. Let's change it to the fo ```haskell app "cli-tutorial" - packages { pf: "examples/cli/platform" } + packages { pf: "examples/interactive/cli-platform" } imports [ pf.Stdout, pf.Stdin, pf.Task.{ await } ] provides [ main ] to pf From e5afb156eb6a18380a3beb84e3ca4f2c6f6e3ea3 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 24 Apr 2022 13:11:55 +0200 Subject: [PATCH 497/846] fix comment --- compiler/can/src/def.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index ed91f77c11..e650bbf3a0 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1943,8 +1943,13 @@ fn correct_mutual_recursive_type_alias<'a>( // We need to instantiate the alias with any symbols in the currrent module it // depends on. - // We only need to worry about symbols in this SCC or any prior one, since the SCCs - // were sorted topologically, and we've already instantiated aliases coming from other + // + // the `strongly_connected_components` returns SCCs in a topologically sorted order: + // SCC_0 has those aliases that don't rely on any other, SCC_1 has only those that rely on SCC_1, etc. + // + // Hence, we only need to worry about symbols in the current SCC or any prior one. + // It cannot be using any of the others, and we've already instantiated aliases coming from other + // modules. let mut to_instantiate_bitvec = solved_aliases_bitvec | &pending_aliases_bitvec; for index in cycle.iter() { From 912d9db29376654ad7ddf9c9cc05763233390e4f Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 24 Apr 2022 13:23:17 +0200 Subject: [PATCH 498/846] use one fewer bitvec --- compiler/can/src/def.rs | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index e650bbf3a0..849109035d 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1921,7 +1921,6 @@ fn correct_mutual_recursive_type_alias<'a>( } let mut solved_aliases_bitvec = bitvec::vec::BitVec::::repeat(false, capacity); - let mut pending_aliases_bitvec = bitvec::vec::BitVec::repeat(false, capacity); let group: Vec<_> = (0u32..capacity as u32).collect(); @@ -1930,17 +1929,6 @@ fn correct_mutual_recursive_type_alias<'a>( for cycle in cycles { debug_assert!(!cycle.is_empty()); - // zero out all the bits - pending_aliases_bitvec.set_elements(0); - - for index in cycle.iter() { - pending_aliases_bitvec.set(*index as usize, true); - } - - // Make sure we report only one error for the cycle, not an error for every - // alias in the cycle. - let mut can_still_report_error = true; - // We need to instantiate the alias with any symbols in the currrent module it // depends on. // @@ -1948,9 +1936,16 @@ fn correct_mutual_recursive_type_alias<'a>( // SCC_0 has those aliases that don't rely on any other, SCC_1 has only those that rely on SCC_1, etc. // // Hence, we only need to worry about symbols in the current SCC or any prior one. - // It cannot be using any of the others, and we've already instantiated aliases coming from other - // modules. - let mut to_instantiate_bitvec = solved_aliases_bitvec | &pending_aliases_bitvec; + // It cannot be using any of the others, and we've already instantiated aliases coming from other modules. + let mut to_instantiate_bitvec = solved_aliases_bitvec; + + for index in cycle.iter() { + to_instantiate_bitvec.set(*index as usize, true); + } + + // Make sure we report only one error for the cycle, not an error for every + // alias in the cycle. + let mut can_still_report_error = true; for index in cycle.iter() { let index = *index as usize; From dbae80507162195dcf1ac711571900ece31750c1 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 24 Apr 2022 13:43:04 +0200 Subject: [PATCH 499/846] minor cleanup to recursive alias creation --- compiler/can/src/def.rs | 49 +++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 849109035d..21e1f79162 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -2055,7 +2055,7 @@ fn make_tag_union_of_alias_recursive<'a>( alias: &mut Alias, others: Vec, var_store: &mut VarStore, - can_report_error: &mut bool, + can_report_cyclic_error: &mut bool, ) -> Result<(), ()> { let alias_args = alias .type_variables @@ -2070,7 +2070,7 @@ fn make_tag_union_of_alias_recursive<'a>( others, &mut alias.typ, var_store, - can_report_error, + can_report_cyclic_error, ); match made_recursive { @@ -2119,22 +2119,25 @@ fn make_tag_union_recursive_help<'a>( others: Vec, typ: &mut Type, var_store: &mut VarStore, - can_report_error: &mut bool, + can_report_cyclic_error: &mut bool, ) -> MakeTagUnionRecursive { use MakeTagUnionRecursive::*; - let Loc { - value: (symbol, args), - region: alias_region, - } = recursive_alias; - let vars = args.iter().map(|(_, t)| t.clone()).collect::>(); + let (symbol, args) = recursive_alias.value; + let alias_region = recursive_alias.region; + match typ { Type::TagUnion(tags, ext) => { let recursion_variable = var_store.fresh(); + let type_arguments = args.iter().map(|(_, t)| t.clone()).collect::>(); + let mut pending_typ = Type::RecursiveTagUnion(recursion_variable, tags.to_vec(), ext.clone()); - let substitution_result = - pending_typ.substitute_alias(symbol, &vars, &Type::Variable(recursion_variable)); + let substitution_result = pending_typ.substitute_alias( + symbol, + &type_arguments, + &Type::Variable(recursion_variable), + ); match substitution_result { Ok(()) => { // We can substitute the alias presence for the variable exactly. @@ -2160,18 +2163,22 @@ fn make_tag_union_recursive_help<'a>( actual, type_arguments, .. - } => make_tag_union_recursive_help( - env, - Loc::at_zero((symbol, type_arguments)), - region, - others, - actual, - var_store, - can_report_error, - ), + } => { + // try to make `actual` recursive + make_tag_union_recursive_help( + env, + Loc::at_zero((symbol, type_arguments)), + region, + others, + actual, + var_store, + can_report_cyclic_error, + ) + } _ => { - mark_cyclic_alias(env, typ, symbol, region, others, *can_report_error); - *can_report_error = false; + // take care to report a cyclic alias only once (not once for each alias in the cycle) + mark_cyclic_alias(env, typ, symbol, region, others, *can_report_cyclic_error); + *can_report_cyclic_error = false; Cyclic } From cf89dd7f8417896a783e23ff52083334451a746a Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 24 Apr 2022 13:50:47 +0200 Subject: [PATCH 500/846] finetuning some comments --- compiler/can/src/def.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 21e1f79162..bd9312985a 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1953,10 +1953,12 @@ fn correct_mutual_recursive_type_alias<'a>( // Don't try to instantiate the alias itself in its definition. to_instantiate_bitvec.set(index, false); - // now we do something sneaky. In `can_instantiate_symbol` we want to be able to - // take a reference to an `Alias` in the `aliases` vec. That would not work if - // we also had a mutable reference to an alias in that vec. So we swap out the - // type. + // we run into a problem here where we want to modify an element in the aliases array, + // but also reference the other elements. The borrow checker, correctly, says no to that. + // + // So we get creative: we swap out the element we want to modify with a dummy. We can + // then freely modify the type we moved out, and the `to_instantiate_bitvec` mask + // prevents our dummy from being used. let alias_region = aliases[index].region; let mut alias_type = Type::EmptyRec; @@ -1981,13 +1983,12 @@ fn correct_mutual_recursive_type_alias<'a>( // We can instantiate this alias in future iterations to_instantiate_bitvec.set(index, true); - let alias = &mut aliases[index]; - - for lambda_set_var in new_lambda_sets { - alias - .lambda_set_variables - .push(LambdaSet(Type::Variable(lambda_set_var))); - } + // add any lambda sets that the instantiation created to the current alias + aliases[index].lambda_set_variables.extend( + new_lambda_sets + .iter() + .map(|var| LambdaSet(Type::Variable(*var))), + ); // Now mark the alias recursive, if it needs to be. let rec = symbols_introduced[index]; @@ -1998,7 +1999,7 @@ fn correct_mutual_recursive_type_alias<'a>( let _made_recursive = make_tag_union_of_alias_recursive( env, rec, - alias, + &mut aliases[index], vec![], var_store, &mut can_still_report_error, From 3d9daed83688343f63a2d9de846a7e582faf6c1c Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sun, 24 Apr 2022 09:09:03 -0400 Subject: [PATCH 501/846] Add Oskar Hahn to AUTHORS --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 554d987aac..2c21c5fb3d 100644 --- a/AUTHORS +++ b/AUTHORS @@ -77,3 +77,4 @@ Cai Bingjun <62678643+C-BJ@users.noreply.github.com> Jared Cone Sean Hagstrom Kas Buunk +Oskar Hahn From d22a4711d42be01f587a717d728f3f62a721faee Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 24 Apr 2022 15:36:00 +0200 Subject: [PATCH 502/846] use VecMap to store aliases --- compiler/can/src/def.rs | 34 ++++++++++++----------------- compiler/collections/src/vec_map.rs | 12 ++++++++++ 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index bd9312985a..6db394514f 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -11,7 +11,8 @@ use crate::reference_matrix::ReferenceMatrix; use crate::reference_matrix::TopologicalSort; use crate::scope::create_alias; use crate::scope::Scope; -use roc_collections::{ImEntry, ImMap, ImSet, MutMap, MutSet, SendMap}; +use roc_collections::VecMap; +use roc_collections::{ImSet, MutMap, MutSet, SendMap}; use roc_module::ident::Lowercase; use roc_module::symbol::IdentId; use roc_module::symbol::ModuleId; @@ -53,7 +54,7 @@ pub(crate) struct CanDefs { defs: Vec>, def_ordering: DefOrdering, - aliases: SendMap, + aliases: VecMap, } /// A Def that has had patterns and type annnotations canonicalized, @@ -351,7 +352,7 @@ pub(crate) fn canonicalize_defs<'a>( } let sorted = sort_type_defs_before_introduction(referenced_type_symbols); - let mut aliases = SendMap::default(); + let mut aliases = VecMap::default(); let mut abilities = MutMap::default(); for type_name in sorted { @@ -571,7 +572,7 @@ pub(crate) fn canonicalize_defs<'a>( defs, def_ordering, // The result needs a thread-safe `SendMap` - aliases: aliases.into_iter().collect(), + aliases, }, scope, output, @@ -1179,16 +1180,11 @@ fn single_can_def( fn add_annotation_aliases( type_annotation: &crate::annotation::Annotation, - aliases: &mut ImMap, + aliases: &mut VecMap, ) { for (name, alias) in type_annotation.aliases.iter() { - match aliases.entry(*name) { - ImEntry::Occupied(_) => { - // do nothing - } - ImEntry::Vacant(vacant) => { - vacant.insert(alias.clone()); - } + if !aliases.contains(name) { + aliases.insert(*name, alias.clone()); } } } @@ -1222,7 +1218,7 @@ fn canonicalize_pending_value_def<'a>( mut output: Output, scope: &mut Scope, var_store: &mut VarStore, - aliases: &mut ImMap, + aliases: &mut VecMap, abilities_in_scope: &[Symbol], ) -> TempOutput { use PendingValueDef::*; @@ -1903,13 +1899,13 @@ fn to_pending_value_def<'a>( /// Make aliases recursive fn correct_mutual_recursive_type_alias<'a>( env: &mut Env<'a>, - original_aliases: SendMap, + original_aliases: VecMap, var_store: &mut VarStore, -) -> ImMap { +) -> VecMap { let capacity = original_aliases.len(); let mut matrix = ReferenceMatrix::new(capacity); - let (symbols_introduced, mut aliases): (Vec<_>, Vec<_>) = original_aliases.into_iter().unzip(); + let (symbols_introduced, mut aliases) = original_aliases.unzip(); for (index, alias) in aliases.iter().enumerate() { for referenced in alias.typ.symbols() { @@ -2044,10 +2040,8 @@ fn correct_mutual_recursive_type_alias<'a>( solved_aliases_bitvec = to_instantiate_bitvec; } - symbols_introduced - .into_iter() - .zip(aliases.into_iter()) - .collect() + // Safety: both vectors are equal lenght and there are no duplicates + unsafe { VecMap::zip(symbols_introduced, aliases) } } fn make_tag_union_of_alias_recursive<'a>( diff --git a/compiler/collections/src/vec_map.rs b/compiler/collections/src/vec_map.rs index 57ab5c31b8..e2da82eb70 100644 --- a/compiler/collections/src/vec_map.rs +++ b/compiler/collections/src/vec_map.rs @@ -76,6 +76,18 @@ impl VecMap { pub fn values(&self) -> impl Iterator { self.values.iter() } + + pub fn unzip(self) -> (Vec, Vec) { + (self.keys, self.values) + } + + /// # Safety + /// + /// keys and values must have the same length, and there must not + /// be any duplicates in the keys vector + pub unsafe fn zip(keys: Vec, values: Vec) -> Self { + Self { keys, values } + } } impl Extend<(K, V)> for VecMap { From 0f4a5bdd74121a1c92b1607025a3babc1b1501d1 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 24 Apr 2022 15:46:17 +0200 Subject: [PATCH 503/846] rename --- compiler/can/src/def.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 6db394514f..97510b8b45 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1203,7 +1203,7 @@ enum DefReferences { AnnotationWithoutBody, } -struct TempOutput { +struct DefOutput { output: Output, def: Def, references: DefReferences, @@ -1220,7 +1220,7 @@ fn canonicalize_pending_value_def<'a>( var_store: &mut VarStore, aliases: &mut VecMap, abilities_in_scope: &[Symbol], -) -> TempOutput { +) -> DefOutput { use PendingValueDef::*; // Make types for the body expr, even if we won't end up having a body. @@ -1321,7 +1321,7 @@ fn canonicalize_pending_value_def<'a>( vars_by_symbol.clone(), ); - TempOutput { + DefOutput { output, references: DefReferences::AnnotationWithoutBody, def, @@ -1434,7 +1434,7 @@ fn canonicalize_pending_value_def<'a>( output.union(can_output); - TempOutput { + DefOutput { output, references: DefReferences::Function(closure_references), def, @@ -1453,7 +1453,7 @@ fn canonicalize_pending_value_def<'a>( output.union(can_output); - TempOutput { + DefOutput { output, references: DefReferences::Value(refs), def, @@ -1548,7 +1548,7 @@ fn canonicalize_pending_value_def<'a>( output.union(can_output); - TempOutput { + DefOutput { output, references: DefReferences::Function(closure_references), def, @@ -1567,7 +1567,7 @@ fn canonicalize_pending_value_def<'a>( output.union(can_output); - TempOutput { + DefOutput { output, references: DefReferences::Value(refs), def, From a7e781ece2348586054050e00062bbd2012d41b3 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 24 Apr 2022 16:19:31 +0200 Subject: [PATCH 504/846] simplify earlier topological sort of abilities/aliases --- compiler/can/src/def.rs | 76 +++++++++-------------------- compiler/collections/src/vec_map.rs | 4 ++ 2 files changed, 27 insertions(+), 53 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 97510b8b45..5d941be248 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -170,66 +170,35 @@ impl Declaration { /// Returns a topologically sorted sequence of alias/opaque names fn sort_type_defs_before_introduction( - mut referenced_symbols: MutMap>, + referenced_symbols: VecMap>, ) -> Vec { - let defined_symbols: Vec = referenced_symbols.keys().copied().collect(); + let capacity = referenced_symbols.len(); + let mut matrix = ReferenceMatrix::new(capacity); - // find the strongly connected components and their relations - let sccs = { - // only retain symbols from the current set of defined symbols; the rest come from other modules - for v in referenced_symbols.iter_mut() { - v.1.retain(|x| defined_symbols.iter().any(|s| s == x)); - } + let (symbols, referenced) = referenced_symbols.unzip(); - let all_successors_with_self = |symbol: &Symbol| referenced_symbols[symbol].iter().copied(); - - ven_graph::strongly_connected_components(&defined_symbols, all_successors_with_self) - }; - - // then sort the strongly connected components - let groups: Vec<_> = (0..sccs.len()).collect(); - let mut group_symbols: Vec> = vec![Vec::new(); groups.len()]; - - let mut symbol_to_group_index = MutMap::default(); - let mut group_to_groups = vec![Vec::new(); groups.len()]; - - for (index, group) in sccs.iter().enumerate() { - for s in group { - symbol_to_group_index.insert(*s, index); - } - } - - for (index, group) in sccs.iter().enumerate() { - for s in group { - let reachable = &referenced_symbols[s]; - for r in reachable { - let new_index = symbol_to_group_index[r]; - - if new_index != index { - group_to_groups[index].push(new_index); - } + for (index, references) in referenced.iter().enumerate() { + for referenced in references { + match symbols.iter().position(|k| k == referenced) { + None => { /* not defined in this scope */ } + Some(ref_index) => matrix.set_row_col(index, ref_index, true), } } } - for v in group_symbols.iter_mut() { - v.sort(); - v.dedup(); + // find the strongly connected components and their relations + let nodes: Vec<_> = (0..capacity as u32).collect(); + let sccs = matrix.strongly_connected_components(&nodes); + + let mut output = Vec::with_capacity(capacity); + + for group in sccs { + for index in group { + output.push(symbols[index as usize]) + } } - let all_successors_with_self = |group: &usize| group_to_groups[*group].iter().copied(); - - // split into self-recursive and mutually recursive - match topological_sort(&groups, all_successors_with_self) { - Ok(result) => result - .iter() - .rev() - .flat_map(|group_index| sccs[*group_index].iter()) - .copied() - .collect(), - - Err(_loop_detected) => unreachable!("the groups cannot recurse"), - } + output } #[inline(always)] @@ -299,7 +268,7 @@ pub(crate) fn canonicalize_defs<'a>( let mut type_defs = MutMap::default(); let mut abilities_in_scope = Vec::new(); - let mut referenced_type_symbols = MutMap::default(); + let mut referenced_type_symbols = VecMap::default(); // Determine which idents we introduced in the course of this process. let mut symbols_introduced = MutMap::default(); @@ -454,7 +423,8 @@ pub(crate) fn canonicalize_defs<'a>( can_ann.typ.clone(), kind, ); - aliases.insert(symbol, alias.clone()); + + aliases.insert(symbol, alias); } TypeDef::Ability(name, members) => { diff --git a/compiler/collections/src/vec_map.rs b/compiler/collections/src/vec_map.rs index e2da82eb70..60b1608737 100644 --- a/compiler/collections/src/vec_map.rs +++ b/compiler/collections/src/vec_map.rs @@ -77,6 +77,10 @@ impl VecMap { self.values.iter() } + pub fn keys(&self) -> impl Iterator { + self.keys.iter() + } + pub fn unzip(self) -> (Vec, Vec) { (self.keys, self.values) } From 1e03ab8fe259d1a9cf0f55328c1b09cb96a3f015 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Sun, 24 Apr 2022 10:19:36 -0400 Subject: [PATCH 505/846] Update regions --- ast/src/constrain.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/ast/src/constrain.rs b/ast/src/constrain.rs index 547b732c0e..8b53fea88a 100644 --- a/ast/src/constrain.rs +++ b/ast/src/constrain.rs @@ -678,19 +678,18 @@ pub fn constrain_expr<'a>( for (index, when_branch_id) in branches.iter_node_ids().enumerate() { let when_branch = env.pool.get(when_branch_id); - let pattern_region = region; // let pattern_region = Region::across_all( // when_branch.patterns.iter(env.pool).map(|v| &v.region), // ); - let patten_expected = |sub_pattern| { + let pattern_expected = |sub_pattern, sub_region| { PExpected::ForReason( PReason::WhenMatch { index: HumanIndex::zero_based(index), sub_pattern, }, cond_type.shallow_clone(), - pattern_region, + sub_region, ) }; @@ -700,7 +699,7 @@ pub fn constrain_expr<'a>( // TODO: when_branch.value.region, region, when_branch, - patten_expected, + pattern_expected, Expected::FromAnnotation( name.clone(), *arity, @@ -727,18 +726,17 @@ pub fn constrain_expr<'a>( for (index, when_branch_id) in branches.iter_node_ids().enumerate() { let when_branch = env.pool.get(when_branch_id); - let pattern_region = region; // let pattern_region = // Region::across_all(when_branch.patterns.iter().map(|v| &v.region)); - let patten_expected = |sub_pattern| { + let pattern_expected = |sub_pattern, sub_region| { PExpected::ForReason( PReason::WhenMatch { index: HumanIndex::zero_based(index), sub_pattern, }, cond_type.shallow_clone(), - pattern_region, + sub_region, ) }; @@ -747,7 +745,7 @@ pub fn constrain_expr<'a>( env, region, when_branch, - patten_expected, + pattern_expected, Expected::ForReason( Reason::WhenBranch { index: HumanIndex::zero_based(index), @@ -1306,7 +1304,7 @@ fn constrain_when_branch<'a>( env: &mut Env, region: Region, when_branch: &WhenBranch, - pattern_expected: impl Fn(HumanIndex) -> PExpected, + pattern_expected: impl Fn(HumanIndex, Region) -> PExpected, expr_expected: Expected, ) -> Constraint<'a> { let when_expr = env.pool.get(when_branch.body); @@ -1324,7 +1322,11 @@ fn constrain_when_branch<'a>( for (sub_pattern, pattern_id) in when_branch.patterns.iter_node_ids().enumerate() { let pattern = env.pool.get(pattern_id); - let pattern_expected = pattern_expected(HumanIndex::zero_based(sub_pattern)); + let pattern_expected = pattern_expected( + HumanIndex::zero_based(sub_pattern), + // TODO: use the proper subpattern region. Not available to us right now. + region, + ); constrain_pattern( arena, From cd89902e7a27d6a0cdc583ecbf225b7eee86f4ce Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Sun, 24 Apr 2022 10:19:47 -0400 Subject: [PATCH 506/846] Smarter about region calculation --- compiler/can/src/expr.rs | 18 ++++++++++++------ compiler/constrain/src/expr.rs | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index aa899ddeb5..4922d07424 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -294,12 +294,18 @@ pub struct WhenBranch { } impl WhenBranch { - pub fn region(&self) -> Region { - Region::across_all( - self.patterns - .iter() - .map(|p| &p.region) - .chain([self.value.region].iter()), + pub fn pattern_region(&self) -> Region { + Region::span_across( + &self + .patterns + .first() + .expect("when branch has no pattern?") + .region, + &self + .patterns + .last() + .expect("when branch has no pattern?") + .region, ) } } diff --git a/compiler/constrain/src/expr.rs b/compiler/constrain/src/expr.rs index df3806a872..0833f9b914 100644 --- a/compiler/constrain/src/expr.rs +++ b/compiler/constrain/src/expr.rs @@ -596,7 +596,7 @@ pub fn constrain_expr( Region::span_across( &loc_cond.region, // &branches.first().unwrap().region(), - &branches.last().unwrap().region(), + &branches.last().unwrap().pattern_region(), ) }; From f94d91b8abc07b92150d55f6040e2da3d39c43b5 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Sun, 24 Apr 2022 10:25:32 -0400 Subject: [PATCH 507/846] Fix region and save an alloc --- compiler/constrain/src/expr.rs | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/compiler/constrain/src/expr.rs b/compiler/constrain/src/expr.rs index 0833f9b914..98ce0e367d 100644 --- a/compiler/constrain/src/expr.rs +++ b/compiler/constrain/src/expr.rs @@ -652,17 +652,14 @@ pub fn constrain_expr( let mut branch_cons = Vec::with_capacity(branches.len()); for (index, when_branch) in branches.iter().enumerate() { - let pattern_region = - Region::across_all(when_branch.patterns.iter().map(|v| &v.region)); - - let expected_pattern = |sub_pattern| { + let expected_pattern = |sub_pattern, sub_region| { PExpected::ForReason( PReason::WhenMatch { index: HumanIndex::zero_based(index), sub_pattern, }, cond_type.clone(), - pattern_region, + sub_region, ) }; @@ -702,9 +699,6 @@ pub fn constrain_expr( // // The return type of each branch must equal the return type of // the entire when-expression. - // branch_cons.extend(pattern_cons); - // branch_constraints.push(constraints.and_constraint(pattern_cons)); - let mut total_cons = Vec::with_capacity(2); // After solving the condition variable with what's expected from the branch patterns, // check it against the condition expression. @@ -731,15 +725,11 @@ pub fn constrain_expr( pattern_constraints, body_constraints, ); - total_cons.push(when_body_con); - total_cons.push(constraints.equal_types_var( - branch_var, - expected, - Category::When, - region, - )); + let result_con = + constraints.equal_types_var(branch_var, expected, Category::When, region); + let total_cons = [when_body_con, result_con]; let branch_constraints = constraints.and_constraint(total_cons); // exhautiveness checking happens when converting to mono::Expr @@ -1141,7 +1131,7 @@ fn constrain_when_branch_help( env: &Env, region: Region, when_branch: &WhenBranch, - pattern_expected: impl Fn(HumanIndex) -> PExpected, + pattern_expected: impl Fn(HumanIndex, Region) -> PExpected, expr_expected: Expected, ) -> ( Vec, @@ -1167,7 +1157,7 @@ fn constrain_when_branch_help( // TODO investigate for error messages, is it better to unify all branches with a variable, // then unify that variable with the expectation? for (i, loc_pattern) in when_branch.patterns.iter().enumerate() { - let pattern_expected = pattern_expected(HumanIndex::zero_based(i)); + let pattern_expected = pattern_expected(HumanIndex::zero_based(i), loc_pattern.region); constrain_pattern( constraints, From b8db6aae8dccd3eb637d2790a84c216fb4216ff3 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 24 Apr 2022 16:51:51 +0200 Subject: [PATCH 508/846] use bitvec to return SCCs --- compiler/can/src/def.rs | 1 - compiler/can/src/reference_matrix.rs | 56 +++++++++++++++++++++++----- 2 files changed, 47 insertions(+), 10 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 5d941be248..14e21aeab8 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -30,7 +30,6 @@ use roc_types::types::AliasKind; use roc_types::types::LambdaSet; use roc_types::types::{Alias, Type}; use std::fmt::Debug; -use ven_graph::topological_sort; #[derive(Clone, Debug)] pub struct Def { diff --git a/compiler/can/src/reference_matrix.rs b/compiler/can/src/reference_matrix.rs index eef869c3b5..32427f2d65 100644 --- a/compiler/can/src/reference_matrix.rs +++ b/compiler/can/src/reference_matrix.rs @@ -1,7 +1,8 @@ // see if we get better performance with different integer types -pub(crate) type Element = usize; -pub(crate) type BitVec = bitvec::vec::BitVec; -pub(crate) type BitSlice = bitvec::prelude::BitSlice; +type Order = bitvec::order::Lsb0; +type Element = usize; +type BitVec = bitvec::vec::BitVec; +type BitSlice = bitvec::prelude::BitSlice; /// A square boolean matrix used to store relations /// @@ -172,7 +173,12 @@ impl ReferenceMatrix { continue 'outer; } - break params.scc; + let mut result = Vec::new(); + for group in params.scc.components() { + result.push(group.map(|v| v as u32).collect()); + } + + break result; } } } @@ -202,7 +208,7 @@ struct Params { c: usize, p: Vec, s: Vec, - scc: Vec>, + scc: Sccs, scca: Vec, } @@ -219,7 +225,10 @@ impl Params { c: 0, s: Vec::new(), p: Vec::new(), - scc: Vec::new(), + scc: Sccs { + matrix: ReferenceMatrix::new(length), + components: 0, + }, scca: Vec::new(), } } @@ -260,15 +269,44 @@ fn recurse_onto(length: usize, bitvec: &BitVec, v: usize, params: &mut Params) { if params.p.last() == Some(&(v as u32)) { params.p.pop(); - let mut component = Vec::new(); while let Some(node) = params.s.pop() { - component.push(node); + params + .scc + .matrix + .set_row_col(params.scc.components, node as usize, true); params.scca.push(node); params.preorders[node as usize] = Preorder::Removed; if node as usize == v { break; } } - params.scc.push(component); + + params.scc.components += 1; + } +} + +#[derive(Debug)] +pub(crate) struct Sccs { + components: usize, + matrix: ReferenceMatrix, +} + +impl Sccs { + fn components(&self) -> impl Iterator + '_> + '_ { + // work around a panic when requesting a chunk size of 0 + let length = if self.matrix.length == 0 { + // the `.take(self.components)` ensures the resulting iterator will be empty + assert!(self.components == 0); + + 1 + } else { + self.matrix.length + }; + + self.matrix + .bitvec + .chunks(length) + .take(self.components) + .map(|row| row.iter_ones()) } } From 0569d2338557c7d6154da51427c2d7b0592572c6 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 24 Apr 2022 17:10:28 +0200 Subject: [PATCH 509/846] add rows helper for Sccs --- compiler/can/src/reference_matrix.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/compiler/can/src/reference_matrix.rs b/compiler/can/src/reference_matrix.rs index 32427f2d65..c422d14038 100644 --- a/compiler/can/src/reference_matrix.rs +++ b/compiler/can/src/reference_matrix.rs @@ -292,7 +292,7 @@ pub(crate) struct Sccs { } impl Sccs { - fn components(&self) -> impl Iterator + '_> + '_ { + pub fn components(&self) -> impl Iterator + '_> + '_ { // work around a panic when requesting a chunk size of 0 let length = if self.matrix.length == 0 { // the `.take(self.components)` ensures the resulting iterator will be empty @@ -309,4 +309,18 @@ impl Sccs { .take(self.components) .map(|row| row.iter_ones()) } + + pub fn rows(&self) -> std::iter::Take> { + // work around a panic when requesting a chunk size of 0 + let length = if self.matrix.length == 0 { + // the `.take(self.components)` ensures the resulting iterator will be empty + assert!(self.components == 0); + + 1 + } else { + self.matrix.length + }; + + self.matrix.bitvec.chunks(length).take(self.components) + } } From 62a80db379e6cdd029c633ee9031199096f66e20 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 24 Apr 2022 17:21:52 +0200 Subject: [PATCH 510/846] move `correct_mutual_recursive_type_alias` over --- compiler/can/src/def.rs | 33 +++++++++------------------- compiler/can/src/reference_matrix.rs | 19 ++++++++++++++++ 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 14e21aeab8..e0e872cf1b 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1889,10 +1889,8 @@ fn correct_mutual_recursive_type_alias<'a>( let group: Vec<_> = (0u32..capacity as u32).collect(); - let cycles = matrix.strongly_connected_components(&group); - - for cycle in cycles { - debug_assert!(!cycle.is_empty()); + for cycle in matrix.strongly_connected_components_prim(&group).rows() { + debug_assert!(cycle.count_ones() > 0); // We need to instantiate the alias with any symbols in the currrent module it // depends on. @@ -1902,19 +1900,13 @@ fn correct_mutual_recursive_type_alias<'a>( // // Hence, we only need to worry about symbols in the current SCC or any prior one. // It cannot be using any of the others, and we've already instantiated aliases coming from other modules. - let mut to_instantiate_bitvec = solved_aliases_bitvec; - - for index in cycle.iter() { - to_instantiate_bitvec.set(*index as usize, true); - } + let mut to_instantiate_bitvec = solved_aliases_bitvec | cycle; // Make sure we report only one error for the cycle, not an error for every // alias in the cycle. let mut can_still_report_error = true; - for index in cycle.iter() { - let index = *index as usize; - + for index in cycle.iter_ones() { // Don't try to instantiate the alias itself in its definition. to_instantiate_bitvec.set(index, false); @@ -1957,8 +1949,8 @@ fn correct_mutual_recursive_type_alias<'a>( // Now mark the alias recursive, if it needs to be. let rec = symbols_introduced[index]; - let is_self_recursive = cycle.len() == 1 && matrix.get_row_col(index, index); - let is_mutually_recursive = cycle.len() > 1; + let is_self_recursive = cycle.count_ones() == 1 && matrix.get_row_col(index, index); + let is_mutually_recursive = cycle.count_ones() > 1; if is_self_recursive || is_mutually_recursive { let _made_recursive = make_tag_union_of_alias_recursive( @@ -1975,22 +1967,17 @@ fn correct_mutual_recursive_type_alias<'a>( // The cycle we just instantiated and marked recursive may still be an illegal cycle, if // all the types in the cycle are narrow newtypes. We can't figure this out until now, // because we need all the types to be deeply instantiated. - let all_are_narrow = cycle.iter().all(|index| { - let index = *index as usize; + let all_are_narrow = cycle.iter_ones().all(|index| { let typ = &aliases[index].typ; matches!(typ, Type::RecursiveTagUnion(..)) && typ.is_narrow() }); if all_are_narrow { // This cycle is illegal! + let mut indices = cycle.iter_ones(); + let first_index = indices.next().unwrap(); - let mut cycle = cycle; - let first_index = cycle.pop().unwrap() as usize; - - let rest: Vec = cycle - .into_iter() - .map(|i| symbols_introduced[i as usize]) - .collect(); + let rest: Vec = indices.map(|i| symbols_introduced[i]).collect(); let alias_name = symbols_introduced[first_index]; let alias = aliases.get_mut(first_index).unwrap(); diff --git a/compiler/can/src/reference_matrix.rs b/compiler/can/src/reference_matrix.rs index c422d14038..a60666e121 100644 --- a/compiler/can/src/reference_matrix.rs +++ b/compiler/can/src/reference_matrix.rs @@ -181,6 +181,25 @@ impl ReferenceMatrix { break result; } } + + /// Get the strongly-connected components of the set of input nodes. + pub fn strongly_connected_components_prim(&self, nodes: &[u32]) -> Sccs { + let mut params = Params::new(self.length, nodes); + + 'outer: loop { + for (node, value) in params.preorders.iter().enumerate() { + if let Preorder::Removed = value { + continue; + } + + recurse_onto(self.length, &self.bitvec, node, &mut params); + + continue 'outer; + } + + break params.scc; + } + } } pub(crate) enum TopologicalSort { From 3d9cda57cc7759f54261c975e6b3ef17e5063904 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 24 Apr 2022 17:28:46 +0200 Subject: [PATCH 511/846] moe the others over --- compiler/can/src/def.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index e0e872cf1b..ba68ca6238 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -187,13 +187,12 @@ fn sort_type_defs_before_introduction( // find the strongly connected components and their relations let nodes: Vec<_> = (0..capacity as u32).collect(); - let sccs = matrix.strongly_connected_components(&nodes); let mut output = Vec::with_capacity(capacity); - for group in sccs { - for index in group { - output.push(symbols[index as usize]) + for group in matrix.strongly_connected_components_prim(&nodes).rows() { + for index in group.iter_ones() { + output.push(symbols[index]) } } @@ -855,9 +854,9 @@ pub(crate) fn sort_can_defs( let sccs = def_ordering .references - .strongly_connected_components(&nodes_in_cycle); + .strongly_connected_components_prim(&nodes_in_cycle); - for cycle in sccs { + for cycle in sccs.rows() { // check whether the cycle is faulty, which is when it has // a direct successor in the current cycle. This catches things like: // @@ -867,11 +866,11 @@ pub(crate) fn sort_can_defs( // // p = q // q = p - let is_invalid_cycle = match cycle.get(0) { + let is_invalid_cycle = match cycle.iter_ones().next() { Some(def_id) => def_ordering .direct_references - .references_for(*def_id as usize) - .any(|key| cycle.contains(&(key as u32))), + .references_for(def_id) + .any(|key| cycle[key]), None => false, }; @@ -879,11 +878,11 @@ pub(crate) fn sort_can_defs( // We want to show the entire cycle in the error message, so expand it out. let mut entries = Vec::new(); - for def_id in &cycle { - let symbol = def_ordering.get_symbol(*def_id).unwrap(); - let def = &defs[*def_id as usize]; + for def_id in cycle.iter_ones() { + let symbol = def_ordering.get_symbol(def_id as u32).unwrap(); + let def = &defs[def_id]; - let expr_region = defs[*def_id as usize].as_ref().unwrap().loc_expr.region; + let expr_region = defs[def_id].as_ref().unwrap().loc_expr.region; let entry = CycleEntry { symbol, @@ -909,6 +908,7 @@ pub(crate) fn sort_can_defs( // // if it's not an invalid cycle, this is slightly inefficient, // because we know this becomes exactly one DeclareRec already + let cycle = cycle.iter_ones().map(|v| v as u32).collect(); groups.push(cycle); } From da9899e7bbaa9d3eb7afc7209d99d1fb54b31c0e Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 24 Apr 2022 17:36:40 +0200 Subject: [PATCH 512/846] use a bitvec-based approach to return the SCCs --- compiler/can/src/def.rs | 26 +++++++------- compiler/can/src/reference_matrix.rs | 53 +++++----------------------- 2 files changed, 22 insertions(+), 57 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index ba68ca6238..fd8dbdd92b 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -190,7 +190,7 @@ fn sort_type_defs_before_introduction( let mut output = Vec::with_capacity(capacity); - for group in matrix.strongly_connected_components_prim(&nodes).rows() { + for group in matrix.strongly_connected_components(&nodes).groups() { for index in group.iter_ones() { output.push(symbols[index]) } @@ -854,9 +854,9 @@ pub(crate) fn sort_can_defs( let sccs = def_ordering .references - .strongly_connected_components_prim(&nodes_in_cycle); + .strongly_connected_components(&nodes_in_cycle); - for cycle in sccs.rows() { + for cycle in sccs.groups() { // check whether the cycle is faulty, which is when it has // a direct successor in the current cycle. This catches things like: // @@ -995,16 +995,16 @@ fn group_to_declaration( let sccs = def_ordering.references.strongly_connected_components(group); - for cycle in sccs { - if cycle.len() == 1 { - let def_id = cycle[0]; + for cycle in sccs.groups() { + if cycle.count_ones() == 1 { + let def_id = cycle.iter_ones().next().unwrap(); - match defs[def_id as usize].take() { + match defs[def_id].take() { Some(mut new_def) => { // there is only one definition in this cycle, so we only have // to check whether it recurses with itself; there is nobody else // to recurse with, or they would also be in this cycle. - let is_self_recursive = def_ordering.is_self_recursive(def_id); + let is_self_recursive = def_ordering.is_self_recursive(def_id as u32); if let Closure(ClosureData { recursive: recursive @ Recursive::NotRecursive, @@ -1028,7 +1028,7 @@ fn group_to_declaration( } None => { // NOTE: a `_ = someDef` can mean we don't have a symbol here - let symbol = def_ordering.get_symbol(def_id); + let symbol = def_ordering.get_symbol(def_id as u32); roc_error_macros::internal_error!("def not available {:?}", symbol) } @@ -1037,7 +1037,7 @@ fn group_to_declaration( let mut can_defs = Vec::new(); // Topological sort gives us the reverse of the sorting we want! - for def_id in cycle.into_iter().rev() { + for def_id in cycle.iter_ones().rev() { match defs[def_id as usize].take() { Some(mut new_def) => { // Determine recursivity of closures that are not tail-recursive @@ -1046,7 +1046,7 @@ fn group_to_declaration( .. }) = &mut new_def.loc_expr.value { - if def_ordering.references.is_recursive(def_id as usize) { + if def_ordering.references.is_recursive(def_id) { *recursive = Recursive::Recursive } } @@ -1059,7 +1059,7 @@ fn group_to_declaration( } None => { // NOTE: a `_ = someDef` can mean we don't have a symbol here - let symbol = def_ordering.get_symbol(def_id); + let symbol = def_ordering.get_symbol(def_id as u32); roc_error_macros::internal_error!("def not available {:?}", symbol) } @@ -1889,7 +1889,7 @@ fn correct_mutual_recursive_type_alias<'a>( let group: Vec<_> = (0u32..capacity as u32).collect(); - for cycle in matrix.strongly_connected_components_prim(&group).rows() { + for cycle in matrix.strongly_connected_components(&group).groups() { debug_assert!(cycle.count_ones() > 0); // We need to instantiate the alias with any symbols in the currrent module it diff --git a/compiler/can/src/reference_matrix.rs b/compiler/can/src/reference_matrix.rs index a60666e121..234340d28b 100644 --- a/compiler/can/src/reference_matrix.rs +++ b/compiler/can/src/reference_matrix.rs @@ -159,31 +159,7 @@ impl ReferenceMatrix { } /// Get the strongly-connected components of the set of input nodes. - pub fn strongly_connected_components(&self, nodes: &[u32]) -> Vec> { - let mut params = Params::new(self.length, nodes); - - 'outer: loop { - for (node, value) in params.preorders.iter().enumerate() { - if let Preorder::Removed = value { - continue; - } - - recurse_onto(self.length, &self.bitvec, node, &mut params); - - continue 'outer; - } - - let mut result = Vec::new(); - for group in params.scc.components() { - result.push(group.map(|v| v as u32).collect()); - } - - break result; - } - } - - /// Get the strongly-connected components of the set of input nodes. - pub fn strongly_connected_components_prim(&self, nodes: &[u32]) -> Sccs { + pub fn strongly_connected_components(&self, nodes: &[u32]) -> Sccs { let mut params = Params::new(self.length, nodes); 'outer: loop { @@ -311,25 +287,14 @@ pub(crate) struct Sccs { } impl Sccs { - pub fn components(&self) -> impl Iterator + '_> + '_ { - // work around a panic when requesting a chunk size of 0 - let length = if self.matrix.length == 0 { - // the `.take(self.components)` ensures the resulting iterator will be empty - assert!(self.components == 0); - - 1 - } else { - self.matrix.length - }; - - self.matrix - .bitvec - .chunks(length) - .take(self.components) - .map(|row| row.iter_ones()) - } - - pub fn rows(&self) -> std::iter::Take> { + /// Iterate over the individual components. Each component is represented as a bit vector where + /// a one indicates that the node is part of the group and a zero that it is not. + /// + /// A good way to get the actual nodes is the `.iter_ones()` method. + /// + /// It is guaranteed that a group is non-empty, and that flattening the groups gives a valid + /// topological ordering. + pub fn groups(&self) -> std::iter::Take> { // work around a panic when requesting a chunk size of 0 let length = if self.matrix.length == 0 { // the `.take(self.components)` ensures the resulting iterator will be empty From 6b0c4b5df0bf291c512d38e54a37456506d30901 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 24 Apr 2022 17:41:01 +0200 Subject: [PATCH 513/846] remove some usize -> u32 casts --- compiler/can/src/def.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index fd8dbdd92b..08f07aac81 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -773,9 +773,9 @@ impl DefOrdering { None } - fn get_symbol(&self, id: u32) -> Option { + fn get_symbol(&self, id: usize) -> Option { for (ident_id, def_id) in self.symbol_to_id.iter() { - if id == *def_id { + if id as u32 == *def_id { return Some(Symbol::new(self.home, *ident_id)); } } @@ -783,13 +783,14 @@ impl DefOrdering { None } - fn is_self_recursive(&self, id: u32) -> bool { - debug_assert!(id < self.length); + fn is_self_recursive(&self, id: usize) -> bool { + let length = self.length as usize; + debug_assert!(id < length); // id'th row, id'th column - let index = (id * self.length) + id; + let index = (id * length) + id; - self.references.get(index as usize) + self.references.get(index) } #[inline(always)] @@ -879,7 +880,7 @@ pub(crate) fn sort_can_defs( let mut entries = Vec::new(); for def_id in cycle.iter_ones() { - let symbol = def_ordering.get_symbol(def_id as u32).unwrap(); + let symbol = def_ordering.get_symbol(def_id).unwrap(); let def = &defs[def_id]; let expr_region = defs[def_id].as_ref().unwrap().loc_expr.region; @@ -1004,7 +1005,7 @@ fn group_to_declaration( // there is only one definition in this cycle, so we only have // to check whether it recurses with itself; there is nobody else // to recurse with, or they would also be in this cycle. - let is_self_recursive = def_ordering.is_self_recursive(def_id as u32); + let is_self_recursive = def_ordering.is_self_recursive(def_id); if let Closure(ClosureData { recursive: recursive @ Recursive::NotRecursive, @@ -1028,7 +1029,7 @@ fn group_to_declaration( } None => { // NOTE: a `_ = someDef` can mean we don't have a symbol here - let symbol = def_ordering.get_symbol(def_id as u32); + let symbol = def_ordering.get_symbol(def_id); roc_error_macros::internal_error!("def not available {:?}", symbol) } @@ -1059,7 +1060,7 @@ fn group_to_declaration( } None => { // NOTE: a `_ = someDef` can mean we don't have a symbol here - let symbol = def_ordering.get_symbol(def_id as u32); + let symbol = def_ordering.get_symbol(def_id); roc_error_macros::internal_error!("def not available {:?}", symbol) } From fe76858e2dbf06cedd015c506e4f9e258b51ee5c Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 24 Apr 2022 17:43:34 +0200 Subject: [PATCH 514/846] an error message that was changed is now what it was again --- reporting/tests/test_reporting.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index b1929d9919..53eac2a4b1 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -3646,8 +3646,8 @@ mod test_reporting { This `ACons` global tag application has the type: [ ACons (Num (Integer Signed64)) [ - BCons (Num (Integer Signed64)) [ ACons Str [ - BCons I64 (AList I64 I64), BNil ] as a, ANil ], BNil ], ANil ] + BCons (Num (Integer Signed64)) [ ACons Str [ BCons I64 a, BNil ], + ANil ], BNil ], ANil ] But the type annotation on `x` says it should be: From b147890b08da1c0d145b422bd60cc5cf304a6d63 Mon Sep 17 00:00:00 2001 From: Sean Hagstrom Date: Sun, 24 Apr 2022 16:35:09 +0100 Subject: [PATCH 515/846] feat(formatter): implement outdent formatting for multiline lists and records --- compiler/fmt/src/def.rs | 26 +- compiler/fmt/src/expr.rs | 92 ++++- compiler/fmt/tests/test_fmt.rs | 497 +++++++++++++++++++++++++- examples/benchmarks/AStar.roc | 13 +- examples/benchmarks/Base64/Decode.roc | 9 +- examples/benchmarks/Bytes/Encode.roc | 9 +- examples/breakout/breakout.roc | 57 ++- examples/gui/Hello.roc | 20 +- examples/interactive/tui.roc | 11 +- 9 files changed, 647 insertions(+), 87 deletions(-) diff --git a/compiler/fmt/src/def.rs b/compiler/fmt/src/def.rs index ca99d19110..72f95b0dab 100644 --- a/compiler/fmt/src/def.rs +++ b/compiler/fmt/src/def.rs @@ -191,12 +191,26 @@ pub fn fmt_body<'a, 'buf>( buf.push_str(" ="); if body.is_multiline() { match body { - Expr::SpaceBefore(_, _) => { - body.format_with_options(buf, Parens::NotNeeded, Newlines::Yes, indent + INDENT); - } - Expr::Record { .. } | Expr::List { .. } => { - buf.newline(); - body.format_with_options(buf, Parens::NotNeeded, Newlines::Yes, indent + INDENT); + Expr::SpaceBefore(sub_def, spaces) => { + let should_outdent = match sub_def { + Expr::Record { .. } | Expr::List { .. } => { + let is_only_newlines = spaces.iter().all(|s| s.is_newline()); + is_only_newlines && sub_def.is_multiline() + } + _ => false, + }; + + if should_outdent { + buf.spaces(1); + sub_def.format_with_options(buf, Parens::NotNeeded, Newlines::Yes, indent); + } else { + body.format_with_options( + buf, + Parens::NotNeeded, + Newlines::Yes, + indent + INDENT, + ); + } } _ => { buf.spaces(1); diff --git a/compiler/fmt/src/expr.rs b/compiler/fmt/src/expr.rs index 70b62b0e13..300e6ac4d4 100644 --- a/compiler/fmt/src/expr.rs +++ b/compiler/fmt/src/expr.rs @@ -186,14 +186,75 @@ impl<'a> Formattable for Expr<'a> { loc_expr.format_with_options(buf, Parens::InApply, Newlines::Yes, indent); let multiline_args = loc_args.iter().any(|loc_arg| loc_arg.is_multiline()); + let last_arg_index = loc_args.len() - 1; - if multiline_args { + let should_outdent_last_arg = + loc_args + .iter() + .enumerate() + .fold(false, |found_multiline_expr, val| { + let (index, loc_arg) = val; + if index == last_arg_index { + match loc_arg.value { + SpaceBefore(sub_expr, spaces) => match sub_expr { + Record { .. } | List { .. } => { + let is_only_newlines = + spaces.iter().all(|s| s.is_newline()); + is_only_newlines + && !found_multiline_expr + && sub_expr.is_multiline() + } + _ => false, + }, + Record { .. } | List { .. } => { + !found_multiline_expr && loc_arg.is_multiline() + } + _ => false, + } + } else { + loc_arg.is_multiline() + } + }); + + if multiline_args && !should_outdent_last_arg { let arg_indent = indent + INDENT; for loc_arg in loc_args.iter() { buf.newline(); loc_arg.format_with_options(buf, Parens::InApply, Newlines::No, arg_indent); } + } else if multiline_args && should_outdent_last_arg { + for (index, loc_arg) in loc_args.iter().enumerate() { + buf.spaces(1); + + if index == last_arg_index { + match loc_arg.value { + SpaceBefore(sub_expr, _) => { + sub_expr.format_with_options( + buf, + Parens::InApply, + Newlines::Yes, + indent, + ); + } + _ => { + loc_arg.format_with_options( + buf, + Parens::InApply, + Newlines::Yes, + indent, + ); + } + } + } else { + loc_arg.format_with_options( + buf, + Parens::InApply, + Newlines::Yes, + indent, + ); + } + } } else { for loc_arg in loc_args.iter() { buf.spaces(1); @@ -846,7 +907,34 @@ fn fmt_closure<'a, 'buf>( } }; - loc_ret.format_with_options(buf, Parens::NotNeeded, Newlines::Yes, body_indent); + if is_multiline { + match &loc_ret.value { + SpaceBefore(sub_expr, spaces) => { + let should_outdent = match sub_expr { + Record { .. } | List { .. } => { + let is_only_newlines = spaces.iter().all(|s| s.is_newline()); + is_only_newlines && sub_expr.is_multiline() + } + _ => false, + }; + + if should_outdent { + buf.spaces(1); + sub_expr.format_with_options(buf, Parens::NotNeeded, Newlines::Yes, indent); + } else { + loc_ret.format_with_options(buf, Parens::NotNeeded, Newlines::Yes, body_indent); + } + } + Record { .. } | List { .. } => { + loc_ret.format_with_options(buf, Parens::NotNeeded, Newlines::Yes, indent); + } + _ => { + loc_ret.format_with_options(buf, Parens::NotNeeded, Newlines::Yes, body_indent); + } + } + } else { + loc_ret.format_with_options(buf, Parens::NotNeeded, Newlines::Yes, body_indent); + } } fn fmt_backpassing<'a, 'buf>( diff --git a/compiler/fmt/tests/test_fmt.rs b/compiler/fmt/tests/test_fmt.rs index c514ff7cf0..b91658ef12 100644 --- a/compiler/fmt/tests/test_fmt.rs +++ b/compiler/fmt/tests/test_fmt.rs @@ -626,6 +626,392 @@ mod test_fmt { )); } + #[test] + fn lambda_returns_record() { + expr_formats_same(indoc!( + r#" + toRecord = \_ -> { + x: 1, + y: 2, + z: 3, + } + + toRecord + "# + )); + + expr_formats_same(indoc!( + r#" + func = \_ -> + { x: 1, y: 2, z: 3 } + + func + "# + )); + + expr_formats_same(indoc!( + r#" + toRecord = \_ -> + val = 0 + + { + x: 1, + y: 2, + z: 3, + } + + toRecord + "# + )); + + expr_formats_to( + indoc!( + r#" + toRecord = \_ -> + { + x: 1, + y: 2, + z: 3, + } + + toRecord + "# + ), + indoc!( + r#" + toRecord = \_ -> { + x: 1, + y: 2, + z: 3, + } + + toRecord + "# + ), + ); + } + + #[test] + fn lambda_returns_list() { + expr_formats_same(indoc!( + r#" + toList = \_ -> [ + 1, + 2, + 3, + ] + + toList + "# + )); + + expr_formats_same(indoc!( + r#" + func = \_ -> + [ 1, 2, 3 ] + + func + "# + )); + + expr_formats_same(indoc!( + r#" + toList = \_ -> + val = 0 + + [ + 1, + 2, + 3, + ] + + toList + "# + )); + + expr_formats_to( + indoc!( + r#" + toList = \_ -> + [ + 1, + 2, + 3, + ] + + toList + "# + ), + indoc!( + r#" + toList = \_ -> [ + 1, + 2, + 3, + ] + + toList + "# + ), + ); + } + + #[test] + fn multiline_list_func_arg() { + expr_formats_same(indoc!( + r#" + result = func arg [ + 1, + 2, + 3, + ] + + result + "# + )); + + expr_formats_to( + indoc!( + r#" + result = func arg + [ 1, 2, 3 ] + + result + "# + ), + indoc!( + r#" + result = func + arg + [ 1, 2, 3 ] + + result + "# + ), + ); + + expr_formats_to( + indoc!( + r#" + result = func arg [ + 1, + 2, + 3, + ] + + result + "# + ), + indoc!( + r#" + result = func arg [ + 1, + 2, + 3, + ] + + result + "# + ), + ); + + expr_formats_to( + indoc!( + r#" + result = func [ + 1, + 2, + 3, + ] + arg + + result + "# + ), + indoc!( + r#" + result = func + [ + 1, + 2, + 3, + ] + arg + + result + "# + ), + ); + + expr_formats_to( + indoc!( + r#" + result = func arg + [ + 1, + 2, + 3, + ] + + result + "# + ), + indoc!( + r#" + result = func arg [ + 1, + 2, + 3, + ] + + result + "# + ), + ); + + expr_formats_same(indoc!( + r#" + result = func + arg + [ + 1, + 2, + 3, + ] + + result + "# + )); + } + + #[test] + fn multiline_record_func_arg() { + expr_formats_same(indoc!( + r#" + result = func arg { + x: 1, + y: 2, + z: 3, + } + + result + "# + )); + + expr_formats_to( + indoc!( + r#" + result = func arg + { x: 1, y: 2, z: 3 } + + result + "# + ), + indoc!( + r#" + result = func + arg + { x: 1, y: 2, z: 3 } + + result + "# + ), + ); + + expr_formats_to( + indoc!( + r#" + result = func arg { + x: 1, + y: 2, + z: 3, + } + + result + "# + ), + indoc!( + r#" + result = func arg { + x: 1, + y: 2, + z: 3, + } + + result + "# + ), + ); + + expr_formats_to( + indoc!( + r#" + result = func { + x: 1, + y: 2, + z: 3, + } + arg + + result + "# + ), + indoc!( + r#" + result = func + { + x: 1, + y: 2, + z: 3, + } + arg + + result + "# + ), + ); + + expr_formats_to( + indoc!( + r#" + result = func arg + { + x: 1, + y: 2, + z: 3, + } + + result + "# + ), + indoc!( + r#" + result = func arg { + x: 1, + y: 2, + z: 3, + } + + result + "# + ), + ); + + expr_formats_same(indoc!( + r#" + result = func + arg + { + x: 1, + y: 2, + z: 3, + } + + result + "# + )); + } + #[test] fn record_updating() { expr_formats_same(indoc!( @@ -1301,6 +1687,27 @@ mod test_fmt { fn multi_line_list_def() { expr_formats_same(indoc!( r#" + l = [ + 1, + 2, + ] + + l + "# + )); + + expr_formats_same(indoc!( + r#" + l = + [ 1, 2 ] + + l + "# + )); + + expr_formats_to( + indoc!( + r#" l = [ 1, @@ -1308,8 +1715,19 @@ mod test_fmt { ] l - "# - )); + "# + ), + indoc!( + r#" + l = [ + 1, + 2, + ] + + l + "# + ), + ); expr_formats_to( indoc!( @@ -1324,11 +1742,10 @@ mod test_fmt { ), indoc!( r#" - results = - [ - Ok 4, - Ok 5, - ] + results = [ + Ok 4, + Ok 5, + ] allOks results "# @@ -1417,18 +1834,69 @@ mod test_fmt { #[test] fn multi_line_record_def() { + expr_formats_same(indoc!( + r#" + pos = { + x: 4, + y: 11, + z: 16, + } + + pos + "# + )); + expr_formats_same(indoc!( r#" pos = + { x: 4, y: 11, z: 16 } + + pos + "# + )); + + expr_formats_same(indoc!( + r#" + myDef = + list = [ + a, + b, + ] + { + c, + d, + } + + myDef + "# + )); + + expr_formats_to( + indoc!( + r#" + pos = + { + x: 4, + y: 11, + z: 16, + } + + pos + "# + ), + indoc!( + r#" + pos = { x: 4, y: 11, z: 16, } - pos - "# - )); + pos + "# + ), + ); expr_formats_to( indoc!( @@ -1443,11 +1911,10 @@ mod test_fmt { ), indoc!( r#" - pos = - { - x: 5, - y: 10, - } + pos = { + x: 5, + y: 10, + } pos "# diff --git a/examples/benchmarks/AStar.roc b/examples/benchmarks/AStar.roc index 4f5a8e0fa1..d6a6ec4c1e 100644 --- a/examples/benchmarks/AStar.roc +++ b/examples/benchmarks/AStar.roc @@ -12,13 +12,12 @@ Model position : } initialModel : position -> Model position -initialModel = \start -> - { - evaluated: Set.empty, - openSet: Set.single start, - costs: Dict.single start 0, - cameFrom: Dict.empty, - } +initialModel = \start -> { + evaluated: Set.empty, + openSet: Set.single start, + costs: Dict.single start 0, + cameFrom: Dict.empty, +} cheapestOpen : (position -> F64), Model position -> Result position {} cheapestOpen = \costFn, model -> diff --git a/examples/benchmarks/Base64/Decode.roc b/examples/benchmarks/Base64/Decode.roc index e78585ad5b..ad5c92ef17 100644 --- a/examples/benchmarks/Base64/Decode.roc +++ b/examples/benchmarks/Base64/Decode.roc @@ -20,11 +20,10 @@ loopHelp = \{ remaining, string } -> c = Num.intCast z combined = Num.bitwiseOr (Num.bitwiseOr (Num.shiftLeftBy 16 a) (Num.shiftLeftBy 8 b)) c - Loop - { - remaining: remaining - 3, - string: Str.concat string (bitsToChars combined 0), - } + Loop { + remaining: remaining - 3, + string: Str.concat string (bitsToChars combined 0), + } else if remaining == 0 then Bytes.Decode.succeed (Done string) else if remaining == 2 then diff --git a/examples/benchmarks/Bytes/Encode.roc b/examples/benchmarks/Bytes/Encode.roc index 37321e8506..195ccd2407 100644 --- a/examples/benchmarks/Bytes/Encode.roc +++ b/examples/benchmarks/Bytes/Encode.roc @@ -132,11 +132,10 @@ encodeHelp = \encoder, offset, output -> List.walk bs { output, offset } - \accum, byte -> - { - offset: accum.offset + 1, - output: List.set accum.output offset byte, - } + \accum, byte -> { + offset: accum.offset + 1, + output: List.set accum.output offset byte, + } Sequence _ encoders -> List.walk diff --git a/examples/breakout/breakout.roc b/examples/breakout/breakout.roc index d06e3ab45f..1625f9b411 100644 --- a/examples/breakout/breakout.roc +++ b/examples/breakout/breakout.roc @@ -29,20 +29,19 @@ Model : { } init : Bounds -> Model -init = \{ width, height } -> - { - # Screen height and width - width, - height, - # Paddle X-coordinate - paddleX: (width * 0.5) - (paddleWidth * width * 0.5), - # Ball coordinates - ballX: width * 0.5, - ballY: height * 0.4, - # Delta - how much ball moves in each tick - dBallX: 4, - dBallY: 4, - } +init = \{ width, height } -> { + # Screen height and width + width, + height, + # Paddle X-coordinate + paddleX: (width * 0.5) - (paddleWidth * width * 0.5), + # Ball coordinates + ballX: width * 0.5, + ballY: height * 0.4, + # Delta - how much ball moves in each tick + dBallX: 4, + dBallY: 4, +} update : Model, Event -> Model update = \model, event -> @@ -125,23 +124,21 @@ render = \model -> top = Num.toF32 (row * blockHeight) border = blockBorder * blockWidth - outer = Rect - { - left, - top, - width: blockWidth, - height: blockHeight, - color: { r: color.r * 0.8, g: color.g * 0.8, b: color.b * 0.8, a: 1 }, - } + outer = Rect { + left, + top, + width: blockWidth, + height: blockHeight, + color: { r: color.r * 0.8, g: color.g * 0.8, b: color.b * 0.8, a: 1 }, + } - inner = Rect - { - left: left + border, - top: top + border, - width: blockWidth - (border * 2), - height: blockHeight - (border * 2), - color, - } + inner = Rect { + left: left + border, + top: top + border, + width: blockWidth - (border * 2), + height: blockHeight - (border * 2), + color, + } [ outer, inner ] diff --git a/examples/gui/Hello.roc b/examples/gui/Hello.roc index 653ccbd8e1..4738b97b11 100644 --- a/examples/gui/Hello.roc +++ b/examples/gui/Hello.roc @@ -8,14 +8,12 @@ render = styles = { bgColor: rgba 100 50 50 1, borderColor: rgba 10 20 30 1, borderWidth: 10, textColor: rgba 220 220 250 1 } - Col - [ - Row - [ - Button (Text "Corner ") styles, - Button (Text "Top Mid ") { styles & bgColor: rgba 100 100 50 1 }, - Button (Text "Top Right ") { styles & bgColor: rgba 50 50 150 1 }, - ], - Button (Text "Mid Left ") { styles & bgColor: rgba 150 100 100 1 }, - Button (Text "Bottom Left") { styles & bgColor: rgba 150 50 50 1 }, - ] + Col [ + Row [ + Button (Text "Corner ") styles, + Button (Text "Top Mid ") { styles & bgColor: rgba 100 100 50 1 }, + Button (Text "Top Right ") { styles & bgColor: rgba 50 50 150 1 }, + ], + Button (Text "Mid Left ") { styles & bgColor: rgba 150 100 100 1 }, + Button (Text "Bottom Left") { styles & bgColor: rgba 150 50 50 1 }, + ] diff --git a/examples/interactive/tui.roc b/examples/interactive/tui.roc index 03b05efc17..3f09cbfdf5 100644 --- a/examples/interactive/tui.roc +++ b/examples/interactive/tui.roc @@ -6,9 +6,8 @@ app "tui" Model : Str main : Program Model -main = - { - init: \{ } -> "Hello World", - update: \model, new -> Str.concat model new, - view: \model -> Str.concat model "!", - } +main = { + init: \{ } -> "Hello World", + update: \model, new -> Str.concat model new, + view: \model -> Str.concat model "!", +} From c5f433ab9498f5b54f586d7af742652692de770d Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 24 Apr 2022 18:39:29 +0200 Subject: [PATCH 516/846] do our sorting using just SSCs --- compiler/can/src/def.rs | 268 +++++++++++++++++++--------------------- 1 file changed, 126 insertions(+), 142 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 08f07aac81..37473ad554 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -8,11 +8,10 @@ use crate::expr::{canonicalize_expr, Output, Recursive}; use crate::pattern::{bindings_from_patterns, canonicalize_def_header_pattern, Pattern}; use crate::procedure::References; use crate::reference_matrix::ReferenceMatrix; -use crate::reference_matrix::TopologicalSort; use crate::scope::create_alias; use crate::scope::Scope; use roc_collections::VecMap; -use roc_collections::{ImSet, MutMap, MutSet, SendMap}; +use roc_collections::{ImSet, MutMap, SendMap}; use roc_module::ident::Lowercase; use roc_module::symbol::IdentId; use roc_module::symbol::ModuleId; @@ -822,159 +821,144 @@ pub(crate) fn sort_can_defs( output.aliases.insert(symbol, alias); } - // TODO also do the same `addDirects` check elm/compiler does, so we can - // report an error if a recursive definition can't possibly terminate! - match def_ordering.references.topological_sort_into_groups() { - TopologicalSort::Groups { groups } => { - let mut declarations = Vec::new(); + let nodes: Vec<_> = (0..defs.len() as u32).collect(); + let sccs = def_ordering + .references + .strongly_connected_components(&nodes); - // groups are in reversed order - for group in groups.into_iter().rev() { - group_to_declaration(&def_ordering, &group, &mut defs, &mut declarations); - } + let mut declarations = Vec::new(); + let mut problems = Vec::new(); - (Ok(declarations), output) - } - TopologicalSort::HasCycles { - mut groups, - nodes_in_cycle, - } => { - let mut declarations = Vec::new(); - let mut problems = Vec::new(); + for group in sccs.groups() { + if group.count_ones() == 1 { + // a group with a single Def, nice and simple + let index = group.iter_ones().next().unwrap(); - // nodes_in_cycle are symbols that form a syntactic cycle. That isn't always a problem, - // and in general it's impossible to decide whether it is. So we use a crude heuristic: - // - // Definitions where the cycle occurs behind a lambda are OK - // - // boom = \_ -> boom {} - // - // But otherwise we report an error, e.g. - // - // foo = if b then foo else bar + let def = match defs[index].take() { + Some(def) => def, + None => { + // NOTE: a `_ = someDef` can mean we don't have a symbol here + let symbol = def_ordering.get_symbol(index); - let sccs = def_ordering - .references - .strongly_connected_components(&nodes_in_cycle); - - for cycle in sccs.groups() { - // check whether the cycle is faulty, which is when it has - // a direct successor in the current cycle. This catches things like: - // - // x = x - // - // or - // - // p = q - // q = p - let is_invalid_cycle = match cycle.iter_ones().next() { - Some(def_id) => def_ordering - .direct_references - .references_for(def_id) - .any(|key| cycle[key]), - None => false, - }; - - if is_invalid_cycle { - // We want to show the entire cycle in the error message, so expand it out. - let mut entries = Vec::new(); - - for def_id in cycle.iter_ones() { - let symbol = def_ordering.get_symbol(def_id).unwrap(); - let def = &defs[def_id]; - - let expr_region = defs[def_id].as_ref().unwrap().loc_expr.region; - - let entry = CycleEntry { - symbol, - symbol_region: def.as_ref().unwrap().loc_pattern.region, - expr_region, - }; - - entries.push(entry); - } - - // Sort them by line number to make the report more helpful. - entries.sort_by_key(|entry| entry.symbol_region); - - problems.push(Problem::RuntimeError(RuntimeError::CircularDef( - entries.clone(), - ))); - - declarations.push(Declaration::InvalidCycle(entries)); + roc_error_macros::internal_error!("def not available {:?}", symbol) } - - // if it's an invalid cycle, other groups may depend on the - // symbols defined here, so also push this cycle onto the groups - // - // if it's not an invalid cycle, this is slightly inefficient, - // because we know this becomes exactly one DeclareRec already - let cycle = cycle.iter_ones().map(|v| v as u32).collect(); - groups.push(cycle); - } - - // now we have a collection of groups whose dependencies are not cyclic. - // They are however not yet topologically sorted. Here we have to get a bit - // creative to get all the definitions in the correct sorted order. - - let mut group_ids = Vec::with_capacity(groups.len()); - let mut symbol_to_group_index = MutMap::default(); - for (i, group) in groups.iter().enumerate() { - for symbol in group { - symbol_to_group_index.insert(*symbol, i); - } - - group_ids.push(i); - } - - let successors_of_group = |group_id: &usize| { - let mut result = MutSet::default(); - - // for each symbol in this group - for symbol in &groups[*group_id] { - // find its successors - for succ in def_ordering.successors_without_self(*symbol) { - // and add its group to the result - match symbol_to_group_index.get(&succ) { - Some(index) => { - result.insert(*index); - } - None => unreachable!("no index for symbol {:?}", succ), - } - } - } - - // don't introduce any cycles to self - result.remove(group_id); - - result }; - match ven_graph::topological_sort_into_groups(&group_ids, successors_of_group) { - Ok(sorted_group_ids) => { - for sorted_group in sorted_group_ids.iter().rev() { - for group_id in sorted_group.iter().rev() { - let group = &groups[*group_id]; + let declaration = if def_ordering.direct_references.get_row_col(index, index) { + // This value references itself in an invalid way, e.g.: + // + // x = x - group_to_declaration( - &def_ordering, - group, - &mut defs, - &mut declarations, - ); - } - } + let symbol = def_ordering.get_symbol(index).unwrap(); + + let entry = CycleEntry { + symbol, + symbol_region: def.loc_pattern.region, + expr_region: def.loc_expr.region, + }; + + let entries = vec![entry]; + + problems.push(Problem::RuntimeError(RuntimeError::CircularDef( + entries.clone(), + ))); + + Declaration::InvalidCycle(entries) + } else if def_ordering.references.get_row_col(index, index) { + // this function calls itself, and must be typechecked as a recursive def + + let mut def = def; + + if let Closure(ClosureData { + recursive: recursive @ Recursive::NotRecursive, + .. + }) = &mut def.loc_expr.value + { + *recursive = Recursive::Recursive } - Err(_) => unreachable!("there should be no cycles now!"), - } - for problem in problems { - env.problem(problem); - } + Declaration::DeclareRec(vec![def]) + } else { + Declaration::Declare(def) + }; - (Ok(declarations), output) + declarations.push(declaration); + } else { + let nodes: Vec<_> = group.iter_ones().map(|v| v as u32).collect(); + let direct_sccs = def_ordering + .direct_references + .strongly_connected_components(&nodes); + + let declaration = if direct_sccs.groups().count() == 1 { + // all defs are part of the same direct cycle. That's invalid + let mut entries = Vec::with_capacity(group.count_ones()); + + for index in group.iter_ones() { + let def = match defs[index].take() { + Some(def) => def, + None => { + // NOTE: a `_ = someDef` can mean we don't have a symbol here + let symbol = def_ordering.get_symbol(index); + + roc_error_macros::internal_error!("def not available {:?}", symbol) + } + }; + + let symbol = def_ordering.get_symbol(index).unwrap(); + + let entry = CycleEntry { + symbol, + symbol_region: def.loc_pattern.region, + expr_region: def.loc_expr.region, + }; + + entries.push(entry) + } + + problems.push(Problem::RuntimeError(RuntimeError::CircularDef( + entries.clone(), + ))); + + Declaration::InvalidCycle(entries) + } else { + let mut rec_defs = Vec::with_capacity(group.count_ones()); + + for index in group.iter_ones() { + let def = match defs[index].take() { + Some(def) => def, + None => { + // NOTE: a `_ = someDef` can mean we don't have a symbol here + let symbol = def_ordering.get_symbol(index); + + roc_error_macros::internal_error!("def not available {:?}", symbol) + } + }; + + let mut def = def; + + if let Closure(ClosureData { + recursive: recursive @ Recursive::NotRecursive, + .. + }) = &mut def.loc_expr.value + { + *recursive = Recursive::Recursive + } + + rec_defs.push(def); + } + + Declaration::DeclareRec(rec_defs) + }; + + declarations.push(declaration); } } + + for problem in problems { + env.problem(problem); + } + + (Ok(declarations), output) } fn group_to_declaration( From 0aa7cb84790f157952781f4715a123a9ab1f062f Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 24 Apr 2022 18:46:16 +0200 Subject: [PATCH 517/846] cleanup --- compiler/can/src/def.rs | 120 --------------------------- compiler/can/src/reference_matrix.rs | 32 +------ 2 files changed, 2 insertions(+), 150 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 37473ad554..3f1e3eec28 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -703,8 +703,6 @@ struct DefOrdering { // references without looking into closure bodies. // Used to spot definitely-wrong recursion direct_references: ReferenceMatrix, - - length: u32, } impl DefOrdering { @@ -721,7 +719,6 @@ impl DefOrdering { symbol_to_id, references: ReferenceMatrix::new(capacity), direct_references: ReferenceMatrix::new(capacity), - length: capacity as u32, } } @@ -781,28 +778,6 @@ impl DefOrdering { None } - - fn is_self_recursive(&self, id: usize) -> bool { - let length = self.length as usize; - debug_assert!(id < length); - - // id'th row, id'th column - let index = (id * length) + id; - - self.references.get(index) - } - - #[inline(always)] - fn successors(&self, id: u32) -> impl Iterator + '_ { - self.references - .references_for(id as usize) - .map(|x| x as u32) - } - - #[inline(always)] - fn successors_without_self(&self, id: u32) -> impl Iterator + '_ { - self.successors(id).filter(move |x| *x != id) - } } #[inline(always)] @@ -961,101 +936,6 @@ pub(crate) fn sort_can_defs( (Ok(declarations), output) } -fn group_to_declaration( - def_ordering: &DefOrdering, - group: &[u32], - defs: &mut [Option], - declarations: &mut Vec, -) { - use Declaration::*; - - // Patterns like - // - // { x, y } = someDef - // - // Can bind multiple symbols. When not incorrectly recursive (which is guaranteed in this function), - // normally `someDef` would be inserted twice. We use the region of the pattern as a unique key - // for a definition, so every definition is only inserted (thus typechecked and emitted) once - let mut seen_pattern_regions: Vec = Vec::with_capacity(2); - - let sccs = def_ordering.references.strongly_connected_components(group); - - for cycle in sccs.groups() { - if cycle.count_ones() == 1 { - let def_id = cycle.iter_ones().next().unwrap(); - - match defs[def_id].take() { - Some(mut new_def) => { - // there is only one definition in this cycle, so we only have - // to check whether it recurses with itself; there is nobody else - // to recurse with, or they would also be in this cycle. - let is_self_recursive = def_ordering.is_self_recursive(def_id); - - if let Closure(ClosureData { - recursive: recursive @ Recursive::NotRecursive, - .. - }) = &mut new_def.loc_expr.value - { - if is_self_recursive { - *recursive = Recursive::Recursive - } - } - - if !seen_pattern_regions.contains(&new_def.loc_pattern.region) { - seen_pattern_regions.push(new_def.loc_pattern.region); - - if is_self_recursive { - declarations.push(DeclareRec(vec![new_def])); - } else { - declarations.push(Declare(new_def)); - } - } - } - None => { - // NOTE: a `_ = someDef` can mean we don't have a symbol here - let symbol = def_ordering.get_symbol(def_id); - - roc_error_macros::internal_error!("def not available {:?}", symbol) - } - } - } else { - let mut can_defs = Vec::new(); - - // Topological sort gives us the reverse of the sorting we want! - for def_id in cycle.iter_ones().rev() { - match defs[def_id as usize].take() { - Some(mut new_def) => { - // Determine recursivity of closures that are not tail-recursive - if let Closure(ClosureData { - recursive: recursive @ Recursive::NotRecursive, - .. - }) = &mut new_def.loc_expr.value - { - if def_ordering.references.is_recursive(def_id) { - *recursive = Recursive::Recursive - } - } - - if !seen_pattern_regions.contains(&new_def.loc_pattern.region) { - seen_pattern_regions.push(new_def.loc_pattern.region); - - can_defs.push(new_def); - } - } - None => { - // NOTE: a `_ = someDef` can mean we don't have a symbol here - let symbol = def_ordering.get_symbol(def_id); - - roc_error_macros::internal_error!("def not available {:?}", symbol) - } - } - } - - declarations.push(DeclareRec(can_defs)); - } - } -} - fn pattern_to_vars_by_symbol( vars_by_symbol: &mut SendMap, pattern: &Pattern, diff --git a/compiler/can/src/reference_matrix.rs b/compiler/can/src/reference_matrix.rs index 234340d28b..13ba3caea2 100644 --- a/compiler/can/src/reference_matrix.rs +++ b/compiler/can/src/reference_matrix.rs @@ -36,40 +36,10 @@ impl ReferenceMatrix { self.bitvec.set(row * self.length + col, value) } - #[inline(always)] - pub fn get(&self, index: usize) -> bool { - self.bitvec[index] - } - #[inline(always)] pub fn get_row_col(&self, row: usize, col: usize) -> bool { self.bitvec[row * self.length + col] } - - pub fn is_recursive(&self, index: usize) -> bool { - let mut scheduled = self.row_slice(index).to_bitvec(); - let mut visited = self.row_slice(index).to_bitvec(); - - // yes this is a bit inefficient because rows are visited repeatedly. - while scheduled.any() { - for one in scheduled.iter_ones() { - if one == index { - return true; - } - - visited |= self.row_slice(one) - } - - // i.e. visited did not change - if visited.count_ones() == scheduled.count_ones() { - break; - } - - scheduled |= &visited; - } - - false - } } // Topological sort and strongly-connected components @@ -81,6 +51,7 @@ impl ReferenceMatrix { // // Thank you, Samuel! impl ReferenceMatrix { + #[allow(dead_code)] pub fn topological_sort_into_groups(&self) -> TopologicalSort { if self.length == 0 { return TopologicalSort::Groups { groups: Vec::new() }; @@ -178,6 +149,7 @@ impl ReferenceMatrix { } } +#[allow(dead_code)] pub(crate) enum TopologicalSort { /// There were no cycles, all nodes have been partitioned into groups Groups { groups: Vec> }, From b1e391304118489d4870bcaf859c39d2a323fa63 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sun, 24 Apr 2022 09:56:53 -0700 Subject: [PATCH 518/846] Allow parsing `if` as part of the right-hand-side of a binary expression --- compiler/parse/src/expr.rs | 5 ++-- .../snapshots/pass/plus_if.expr.result-ast | 25 +++++++++++++++++++ .../tests/snapshots/pass/plus_if.expr.roc | 1 + compiler/parse/tests/test_parse.rs | 13 +++++++++- 4 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 compiler/parse/tests/snapshots/pass/plus_if.expr.result-ast create mode 100644 compiler/parse/tests/snapshots/pass/plus_if.expr.roc diff --git a/compiler/parse/src/expr.rs b/compiler/parse/src/expr.rs index b3e94f2f6d..760e3fb076 100644 --- a/compiler/parse/src/expr.rs +++ b/compiler/parse/src/expr.rs @@ -196,6 +196,7 @@ fn parse_loc_term_or_underscore<'a>( ) -> ParseResult<'a, Loc>, EExpr<'a>> { one_of!( loc_expr_in_parens_etc_help(min_indent), + loc!(specialize(EExpr::If, if_expr_help(min_indent, options))), loc!(specialize(EExpr::Str, string_literal_help())), loc!(specialize(EExpr::SingleQuote, single_quote_literal_help())), loc!(specialize(EExpr::Number, positive_number_literal_help())), @@ -1509,8 +1510,8 @@ fn parse_expr_operator<'a>( } } } - Err((NoProgress, _, _)) => { - todo!() + Err((NoProgress, expr, e)) => { + todo!("{:?} {:?}", expr, e) } }, } diff --git a/compiler/parse/tests/snapshots/pass/plus_if.expr.result-ast b/compiler/parse/tests/snapshots/pass/plus_if.expr.result-ast new file mode 100644 index 0000000000..5ae40d994c --- /dev/null +++ b/compiler/parse/tests/snapshots/pass/plus_if.expr.result-ast @@ -0,0 +1,25 @@ +BinOps( + [ + ( + @0-1 Num( + "1", + ), + @2-3 Star, + ), + ], + @4-25 If( + [ + ( + @7-11 GlobalTag( + "True", + ), + @17-18 Num( + "1", + ), + ), + ], + @24-25 Num( + "1", + ), + ), +) diff --git a/compiler/parse/tests/snapshots/pass/plus_if.expr.roc b/compiler/parse/tests/snapshots/pass/plus_if.expr.roc new file mode 100644 index 0000000000..50a84b0a4d --- /dev/null +++ b/compiler/parse/tests/snapshots/pass/plus_if.expr.roc @@ -0,0 +1 @@ +1 * if True then 1 else 1 diff --git a/compiler/parse/tests/test_parse.rs b/compiler/parse/tests/test_parse.rs index 759276523c..b42245f55b 100644 --- a/compiler/parse/tests/test_parse.rs +++ b/compiler/parse/tests/test_parse.rs @@ -122,6 +122,7 @@ mod test_parse { snapshot_tests! { fail/type_argument_no_arrow.expr, fail/type_double_comma.expr, + pass/plus_if.expr, pass/list_closing_indent_not_enough.expr, pass/ability_single_line.expr, pass/ability_multi_line.expr, @@ -316,7 +317,17 @@ mod test_parse { if std::env::var("ROC_PARSER_SNAPSHOT_TEST_OVERWRITE").is_ok() { std::fs::write(&result_path, actual_result).unwrap(); } else { - let expected_result = std::fs::read_to_string(&result_path).unwrap(); + let expected_result = std::fs::read_to_string(&result_path).unwrap_or_else(|e| { + panic!( + "Error opening test output file {}:\n\ + {:?} + Suppsing the file is missing, consider running the tests with:\n\ + `env ROC_PARSER_SNAPSHOT_TEST_OVERWRITE=1 cargo test ...`\n\ + and committing the file that creates.", + result_path.display(), + e + ); + }); assert_multiline_str_eq!(expected_result, actual_result); } From 41259104b8cb782d7ef2c257cbce8467615f1b2e Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Sun, 24 Apr 2022 13:03:17 -0400 Subject: [PATCH 519/846] Format --- reporting/tests/test_reporting.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 9f4edac47e..3c3f55ffdf 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -10036,7 +10036,7 @@ I need all branches in an `if` to have the same type! ), ) } - + #[test] fn always_function() { // from https://github.com/rtfeldman/roc/commit/1372737f5e53ee5bb96d7e1b9593985e5537023a From 054907a4cb3739c15027f2ee2e69bfb2c8ce167e Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 24 Apr 2022 19:06:08 +0200 Subject: [PATCH 520/846] clean up sorting code --- compiler/can/src/def.rs | 148 +++++++++++++++++----------------------- 1 file changed, 63 insertions(+), 85 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 3f1e3eec28..f38963eeb3 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -796,131 +796,93 @@ pub(crate) fn sort_can_defs( output.aliases.insert(symbol, alias); } + macro_rules! take_def { + ($index:expr) => { + match defs[$index].take() { + Some(def) => def, + None => { + // NOTE: a `_ = someDef` can mean we don't have a symbol here + let symbol = def_ordering.get_symbol($index); + + roc_error_macros::internal_error!("def not available {:?}", symbol) + } + } + }; + } + let nodes: Vec<_> = (0..defs.len() as u32).collect(); + + // We first perform SCC based on any reference, both variable usage and calls + // considering both value definitions and function bodies. This will spot any + // recursive relations between any 2 definitions. let sccs = def_ordering .references .strongly_connected_components(&nodes); let mut declarations = Vec::new(); - let mut problems = Vec::new(); for group in sccs.groups() { if group.count_ones() == 1 { // a group with a single Def, nice and simple let index = group.iter_ones().next().unwrap(); - let def = match defs[index].take() { - Some(def) => def, - None => { - // NOTE: a `_ = someDef` can mean we don't have a symbol here - let symbol = def_ordering.get_symbol(index); - - roc_error_macros::internal_error!("def not available {:?}", symbol) - } - }; + let def = take_def!(index); let declaration = if def_ordering.direct_references.get_row_col(index, index) { - // This value references itself in an invalid way, e.g.: - // - // x = x - + // a definition like `x = x + 1`, which is invalid in roc let symbol = def_ordering.get_symbol(index).unwrap(); - let entry = CycleEntry { - symbol, - symbol_region: def.loc_pattern.region, - expr_region: def.loc_expr.region, - }; + let entries = vec![make_cycle_entry(symbol, &def)]; - let entries = vec![entry]; - - problems.push(Problem::RuntimeError(RuntimeError::CircularDef( - entries.clone(), - ))); + let problem = Problem::RuntimeError(RuntimeError::CircularDef(entries.clone())); + env.problem(problem); Declaration::InvalidCycle(entries) } else if def_ordering.references.get_row_col(index, index) { // this function calls itself, and must be typechecked as a recursive def - - let mut def = def; - - if let Closure(ClosureData { - recursive: recursive @ Recursive::NotRecursive, - .. - }) = &mut def.loc_expr.value - { - *recursive = Recursive::Recursive - } - - Declaration::DeclareRec(vec![def]) + Declaration::DeclareRec(vec![mark_def_recursive(def)]) } else { Declaration::Declare(def) }; declarations.push(declaration); } else { + // There is something recursive going on between the Defs of this group. + // Now we use the direct_references to see if it is clearly invalid recursion, e.g. + // + // x = y + // y = x + // + // We allow indirect recursion (behind a lambda), e.g. + // + // boom = \{} -> boom {} + // + // In general we cannot spot faulty recursion (halting problem) so this is our best attempt let nodes: Vec<_> = group.iter_ones().map(|v| v as u32).collect(); let direct_sccs = def_ordering .direct_references .strongly_connected_components(&nodes); let declaration = if direct_sccs.groups().count() == 1 { - // all defs are part of the same direct cycle. That's invalid + // all defs are part of the same direct cycle, that is invalid! let mut entries = Vec::with_capacity(group.count_ones()); for index in group.iter_ones() { - let def = match defs[index].take() { - Some(def) => def, - None => { - // NOTE: a `_ = someDef` can mean we don't have a symbol here - let symbol = def_ordering.get_symbol(index); - - roc_error_macros::internal_error!("def not available {:?}", symbol) - } - }; - + let def = take_def!(index); let symbol = def_ordering.get_symbol(index).unwrap(); - let entry = CycleEntry { - symbol, - symbol_region: def.loc_pattern.region, - expr_region: def.loc_expr.region, - }; - - entries.push(entry) + entries.push(make_cycle_entry(symbol, &def)) } - problems.push(Problem::RuntimeError(RuntimeError::CircularDef( - entries.clone(), - ))); + let problem = Problem::RuntimeError(RuntimeError::CircularDef(entries.clone())); + env.problem(problem); Declaration::InvalidCycle(entries) } else { - let mut rec_defs = Vec::with_capacity(group.count_ones()); - - for index in group.iter_ones() { - let def = match defs[index].take() { - Some(def) => def, - None => { - // NOTE: a `_ = someDef` can mean we don't have a symbol here - let symbol = def_ordering.get_symbol(index); - - roc_error_macros::internal_error!("def not available {:?}", symbol) - } - }; - - let mut def = def; - - if let Closure(ClosureData { - recursive: recursive @ Recursive::NotRecursive, - .. - }) = &mut def.loc_expr.value - { - *recursive = Recursive::Recursive - } - - rec_defs.push(def); - } + let rec_defs = group + .iter_ones() + .map(|index| mark_def_recursive(take_def!(index))) + .collect(); Declaration::DeclareRec(rec_defs) }; @@ -929,11 +891,27 @@ pub(crate) fn sort_can_defs( } } - for problem in problems { - env.problem(problem); + (Ok(declarations), output) +} + +fn mark_def_recursive(mut def: Def) -> Def { + if let Closure(ClosureData { + recursive: recursive @ Recursive::NotRecursive, + .. + }) = &mut def.loc_expr.value + { + *recursive = Recursive::Recursive } - (Ok(declarations), output) + def +} + +fn make_cycle_entry(symbol: Symbol, def: &Def) -> CycleEntry { + CycleEntry { + symbol, + symbol_region: def.loc_pattern.region, + expr_region: def.loc_expr.region, + } } fn pattern_to_vars_by_symbol( From 6e642a6fca12a949314ea43ed488f01c0e2ab041 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sun, 24 Apr 2022 13:22:41 -0400 Subject: [PATCH 521/846] fix typo --- compiler/parse/tests/test_parse.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/parse/tests/test_parse.rs b/compiler/parse/tests/test_parse.rs index b42245f55b..a9f1b70f5e 100644 --- a/compiler/parse/tests/test_parse.rs +++ b/compiler/parse/tests/test_parse.rs @@ -321,7 +321,7 @@ mod test_parse { panic!( "Error opening test output file {}:\n\ {:?} - Suppsing the file is missing, consider running the tests with:\n\ + Supposing the file is missing, consider running the tests with:\n\ `env ROC_PARSER_SNAPSHOT_TEST_OVERWRITE=1 cargo test ...`\n\ and committing the file that creates.", result_path.display(), From 01dfda29b05eef7603eb15d65900c983b86980c3 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 24 Apr 2022 19:47:55 +0200 Subject: [PATCH 522/846] fix test by swapping definition order --- compiler/solve/tests/solve_expr.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index da03df77e2..18f964cf0c 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -5297,11 +5297,12 @@ mod solve_expr { #[test] fn issue_2458() { + // TODO: the order of the alias definitions matters infer_eq_without_problem( indoc!( r#" - Foo a : [ Blah (Result (Bar a) { val: a }) ] Bar a : Foo a + Foo a : [ Blah (Result (Bar a) { val: a }) ] v : Bar U8 v = Blah (Ok (Blah (Err { val: 1 }))) From 477ed3c5e819a78b747662f0c46adf27c1042cf5 Mon Sep 17 00:00:00 2001 From: Sean Hagstrom Date: Sun, 24 Apr 2022 18:55:57 +0100 Subject: [PATCH 523/846] feat(formatter): allow single-line function call ending with multi-line lambda --- compiler/fmt/src/expr.rs | 2 +- compiler/fmt/tests/test_fmt.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/compiler/fmt/src/expr.rs b/compiler/fmt/src/expr.rs index 300e6ac4d4..64685a54e6 100644 --- a/compiler/fmt/src/expr.rs +++ b/compiler/fmt/src/expr.rs @@ -206,7 +206,7 @@ impl<'a> Formattable for Expr<'a> { } _ => false, }, - Record { .. } | List { .. } => { + Record { .. } | List { .. } | Closure { .. } => { !found_multiline_expr && loc_arg.is_multiline() } _ => false, diff --git a/compiler/fmt/tests/test_fmt.rs b/compiler/fmt/tests/test_fmt.rs index b91658ef12..4dc4e7a6ce 100644 --- a/compiler/fmt/tests/test_fmt.rs +++ b/compiler/fmt/tests/test_fmt.rs @@ -3086,6 +3086,18 @@ mod test_fmt { )); } + #[test] + fn func_call_trailing_multiline_lambda() { + expr_formats_same(indoc!( + r#" + list = List.map [ 1, 2, 3 ] \x -> + x + 1 + + list + "# + )); + } + // MODULES #[test] From c9426e2ed2aa5d9069c96ed2551c0af00a9df0f1 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 24 Apr 2022 20:07:38 +0200 Subject: [PATCH 524/846] fix alias instantiation problem --- compiler/can/src/def.rs | 14 ++++++++++++-- compiler/solve/tests/solve_expr.rs | 19 ++++++++++++++++++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index f38963eeb3..ebac774de2 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1717,7 +1717,15 @@ fn correct_mutual_recursive_type_alias<'a>( let capacity = original_aliases.len(); let mut matrix = ReferenceMatrix::new(capacity); - let (symbols_introduced, mut aliases) = original_aliases.unzip(); + // It is important that we instantiate with the aliases as they occur in the source. + // We must not instantiate A into B, then use the updated B to instantiate into C + // + // That is because B could be used different places. We don't want one place + // to mess with another. + let (symbols_introduced, uninstantiated_aliases) = original_aliases.unzip(); + + // the aliases that we will instantiate into + let mut aliases = uninstantiated_aliases.clone(); for (index, alias) in aliases.iter().enumerate() { for referenced in alias.typ.symbols() { @@ -1765,7 +1773,9 @@ fn correct_mutual_recursive_type_alias<'a>( std::mem::swap(&mut alias_type, &mut aliases[index].typ); let can_instantiate_symbol = |s| match symbols_introduced.iter().position(|i| *i == s) { - Some(s_index) if to_instantiate_bitvec[s_index] => aliases.get(s_index), + Some(s_index) if to_instantiate_bitvec[s_index] => { + uninstantiated_aliases.get(s_index) + } _ => None, }; diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index 18f964cf0c..c04a1cf2a8 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -5297,7 +5297,24 @@ mod solve_expr { #[test] fn issue_2458() { - // TODO: the order of the alias definitions matters + infer_eq_without_problem( + indoc!( + r#" + Foo a : [ Blah (Result (Bar a) { val: a }) ] + Bar a : Foo a + + v : Bar U8 + v = Blah (Ok (Blah (Err { val: 1 }))) + + v + "# + ), + "Bar U8", + ) + } + + #[test] + fn issue_2458_swapped_order() { infer_eq_without_problem( indoc!( r#" From cde4bd3ce0f9b9a1155de92025910296c979f093 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 24 Apr 2022 20:09:28 +0200 Subject: [PATCH 525/846] fix spelling --- compiler/can/src/def.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index ebac774de2..29335b7be3 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1849,7 +1849,7 @@ fn correct_mutual_recursive_type_alias<'a>( solved_aliases_bitvec = to_instantiate_bitvec; } - // Safety: both vectors are equal lenght and there are no duplicates + // Safety: both vectors are equal length and there are no duplicates unsafe { VecMap::zip(symbols_introduced, aliases) } } From 1227f9f40491ebeed6b76a4a7ce87666b82a1164 Mon Sep 17 00:00:00 2001 From: Sean Hagstrom Date: Sun, 24 Apr 2022 19:39:13 +0100 Subject: [PATCH 526/846] fix(formatter): fix potential panic when subtracting from usize --- compiler/fmt/src/expr.rs | 55 ++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/compiler/fmt/src/expr.rs b/compiler/fmt/src/expr.rs index 64685a54e6..c8aafa6cff 100644 --- a/compiler/fmt/src/expr.rs +++ b/compiler/fmt/src/expr.rs @@ -186,35 +186,33 @@ impl<'a> Formattable for Expr<'a> { loc_expr.format_with_options(buf, Parens::InApply, Newlines::Yes, indent); let multiline_args = loc_args.iter().any(|loc_arg| loc_arg.is_multiline()); - let last_arg_index = loc_args.len() - 1; - let should_outdent_last_arg = - loc_args - .iter() - .enumerate() - .fold(false, |found_multiline_expr, val| { - let (index, loc_arg) = val; - if index == last_arg_index { - match loc_arg.value { - SpaceBefore(sub_expr, spaces) => match sub_expr { - Record { .. } | List { .. } => { - let is_only_newlines = - spaces.iter().all(|s| s.is_newline()); - is_only_newlines - && !found_multiline_expr - && sub_expr.is_multiline() - } - _ => false, - }, - Record { .. } | List { .. } | Closure { .. } => { - !found_multiline_expr && loc_arg.is_multiline() - } - _ => false, + let mut found_multiline_expr = false; + let mut iter = loc_args.iter().peekable(); + + while let Some(loc_arg) = iter.next() { + if iter.peek().is_none() { + found_multiline_expr = match loc_arg.value { + SpaceBefore(sub_expr, spaces) => match sub_expr { + Record { .. } | List { .. } => { + let is_only_newlines = spaces.iter().all(|s| s.is_newline()); + is_only_newlines + && !found_multiline_expr + && sub_expr.is_multiline() } - } else { - loc_arg.is_multiline() + _ => false, + }, + Record { .. } | List { .. } | Closure { .. } => { + !found_multiline_expr && loc_arg.is_multiline() } - }); + _ => false, + } + } else { + found_multiline_expr = loc_arg.is_multiline(); + } + } + + let should_outdent_last_arg = found_multiline_expr; if multiline_args && !should_outdent_last_arg { let arg_indent = indent + INDENT; @@ -224,10 +222,11 @@ impl<'a> Formattable for Expr<'a> { loc_arg.format_with_options(buf, Parens::InApply, Newlines::No, arg_indent); } } else if multiline_args && should_outdent_last_arg { - for (index, loc_arg) in loc_args.iter().enumerate() { + let mut iter = loc_args.iter().peekable(); + while let Some(loc_arg) = iter.next() { buf.spaces(1); - if index == last_arg_index { + if iter.peek().is_none() { match loc_arg.value { SpaceBefore(sub_expr, _) => { sub_expr.format_with_options( From 3ec3976781e5482b45ef1888b9d4828a343eb087 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 24 Apr 2022 22:08:11 +0200 Subject: [PATCH 527/846] fix issue with wrong alias being used for instantiation --- compiler/can/src/def.rs | 60 ++++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 29335b7be3..57ce47dd72 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1717,15 +1717,7 @@ fn correct_mutual_recursive_type_alias<'a>( let capacity = original_aliases.len(); let mut matrix = ReferenceMatrix::new(capacity); - // It is important that we instantiate with the aliases as they occur in the source. - // We must not instantiate A into B, then use the updated B to instantiate into C - // - // That is because B could be used different places. We don't want one place - // to mess with another. - let (symbols_introduced, uninstantiated_aliases) = original_aliases.unzip(); - - // the aliases that we will instantiate into - let mut aliases = uninstantiated_aliases.clone(); + let (symbols_introduced, mut aliases) = original_aliases.unzip(); for (index, alias) in aliases.iter().enumerate() { for referenced in alias.typ.symbols() { @@ -1739,8 +1731,17 @@ fn correct_mutual_recursive_type_alias<'a>( let mut solved_aliases_bitvec = bitvec::vec::BitVec::::repeat(false, capacity); let group: Vec<_> = (0u32..capacity as u32).collect(); + let sccs = matrix.strongly_connected_components(&group); - for cycle in matrix.strongly_connected_components(&group).groups() { + // sometimes we need to temporarily move some aliases somewhere + let scratchpad_capacity = sccs + .groups() + .map(|r| r.count_ones()) + .max() + .unwrap_or_default(); + let mut scratchpad = Vec::with_capacity(scratchpad_capacity); + + for cycle in sccs.groups() { debug_assert!(cycle.count_ones() > 0); // We need to instantiate the alias with any symbols in the currrent module it @@ -1761,21 +1762,34 @@ fn correct_mutual_recursive_type_alias<'a>( // Don't try to instantiate the alias itself in its definition. to_instantiate_bitvec.set(index, false); + // Within a recursive group, we must instantiate all aliases like how they came to the + // loop. So we cannot instantiate A into B, then the updated B into C in the same + // iteration. Hence, if we have more than one alias we sadly must clone and store + // the alias off to the side somewhere. After processing the group, we put the + // updated alias into the main `aliases` vector again, because for future groups + // we do need to use the instantiated version. + let alias = if cycle.count_ones() > 1 { + scratchpad.push((index, aliases[index].clone())); + + &mut scratchpad.last_mut().unwrap().1 + } else { + &mut aliases[index] + }; + // we run into a problem here where we want to modify an element in the aliases array, // but also reference the other elements. The borrow checker, correctly, says no to that. // // So we get creative: we swap out the element we want to modify with a dummy. We can // then freely modify the type we moved out, and the `to_instantiate_bitvec` mask // prevents our dummy from being used. - let alias_region = aliases[index].region; + + let alias_region = alias.region; let mut alias_type = Type::EmptyRec; - std::mem::swap(&mut alias_type, &mut aliases[index].typ); + std::mem::swap(&mut alias_type, &mut alias.typ); let can_instantiate_symbol = |s| match symbols_introduced.iter().position(|i| *i == s) { - Some(s_index) if to_instantiate_bitvec[s_index] => { - uninstantiated_aliases.get(s_index) - } + Some(s_index) if to_instantiate_bitvec[s_index] => aliases.get(s_index), _ => None, }; @@ -1787,14 +1801,20 @@ fn correct_mutual_recursive_type_alias<'a>( &mut new_lambda_sets, ); + let alias = if cycle.count_ones() > 1 { + &mut scratchpad.last_mut().unwrap().1 + } else { + &mut aliases[index] + }; + // swap the type back - std::mem::swap(&mut alias_type, &mut aliases[index].typ); + std::mem::swap(&mut alias_type, &mut alias.typ); // We can instantiate this alias in future iterations to_instantiate_bitvec.set(index, true); // add any lambda sets that the instantiation created to the current alias - aliases[index].lambda_set_variables.extend( + alias.lambda_set_variables.extend( new_lambda_sets .iter() .map(|var| LambdaSet(Type::Variable(*var))), @@ -1809,7 +1829,7 @@ fn correct_mutual_recursive_type_alias<'a>( let _made_recursive = make_tag_union_of_alias_recursive( env, rec, - &mut aliases[index], + alias, vec![], var_store, &mut can_still_report_error, @@ -1817,6 +1837,10 @@ fn correct_mutual_recursive_type_alias<'a>( } } + for (index, alias) in scratchpad.drain(..) { + aliases[index] = alias; + } + // The cycle we just instantiated and marked recursive may still be an illegal cycle, if // all the types in the cycle are narrow newtypes. We can't figure this out until now, // because we need all the types to be deeply instantiated. From c055d2536ad70abe393f2e2d470b69abcb40f8b0 Mon Sep 17 00:00:00 2001 From: Jared Cone Date: Sun, 24 Apr 2022 15:15:25 -0700 Subject: [PATCH 528/846] Added typed, hexadecimal, and binary literals to tutorial. --- TUTORIAL.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/TUTORIAL.md b/TUTORIAL.md index 10859e609e..9885bb8e50 100644 --- a/TUTORIAL.md +++ b/TUTORIAL.md @@ -1203,6 +1203,24 @@ and also `Num.cos 1` and have them all work as expected; the number literal `1` `Num *`, which is compatible with the more constrained types `Int` and `Frac`. For the same reason, you can pass number literals to functions expecting even more constrained types, like `I32` or `F64`. +### Typed Number Literals +When writing a number literal in Roc you can specify the numeric type as a suffix of the literal. +`1u8` specifies `1` as an unsigned 8-bit integer, `5i32` specifies `5` as a signed 32-bit integer, etc. +The full list of possible suffixes includes: +`i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `nat`, `f32`, `f64`, `dec` + +### Hexadecimal Integer Literals +Integer literals can be written in hexadecimal form by prefixing with `0x` followed by hexadecimal characters. +`0xFE` evaluates to decimal `254` +The integer type can be specified as a suffix to the hexadecimal literal, +so `0xC8u8` evaluates to decimal `200` as an unsigned 8-bit integer. + +### Binary Integer Literals +Integer literals can be written in binary form by prefixing with `0b` followed by the 1's and 0's representing +each bit. `0b0000_1000` evaluates to decimal `8` +The integer type can be specified as a suffix to the binary literal, +so `0b0100u8` evaluates to decimal `4` as an unsigned 8-bit integer. + ## Interface modules [ This part of the tutorial has not been written yet. Coming soon! ] From f7c110dbc1797f085863cd7e98e26c8bb23dfecd Mon Sep 17 00:00:00 2001 From: Folkert Date: Mon, 25 Apr 2022 16:34:47 +0200 Subject: [PATCH 529/846] comments + renames --- compiler/can/src/def.rs | 69 +++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 20 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 57ce47dd72..d3773a4108 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1728,12 +1728,14 @@ fn correct_mutual_recursive_type_alias<'a>( } } - let mut solved_aliases_bitvec = bitvec::vec::BitVec::::repeat(false, capacity); + let mut solved_aliases = bitvec::vec::BitVec::::repeat(false, capacity); let group: Vec<_> = (0u32..capacity as u32).collect(); let sccs = matrix.strongly_connected_components(&group); - // sometimes we need to temporarily move some aliases somewhere + // scratchpad to store aliases that are modified in the current iteration. + // Only used when there is are more than one alias in a group. See below why + // this is needed. let scratchpad_capacity = sccs .groups() .map(|r| r.count_ones()) @@ -1752,36 +1754,62 @@ fn correct_mutual_recursive_type_alias<'a>( // // Hence, we only need to worry about symbols in the current SCC or any prior one. // It cannot be using any of the others, and we've already instantiated aliases coming from other modules. - let mut to_instantiate_bitvec = solved_aliases_bitvec | cycle; + let mut to_instantiate = solved_aliases | cycle; // Make sure we report only one error for the cycle, not an error for every // alias in the cycle. let mut can_still_report_error = true; for index in cycle.iter_ones() { - // Don't try to instantiate the alias itself in its definition. - to_instantiate_bitvec.set(index, false); + // Don't try to instantiate the alias itself in its own definition. + to_instantiate.set(index, false); // Within a recursive group, we must instantiate all aliases like how they came to the - // loop. So we cannot instantiate A into B, then the updated B into C in the same - // iteration. Hence, if we have more than one alias we sadly must clone and store - // the alias off to the side somewhere. After processing the group, we put the - // updated alias into the main `aliases` vector again, because for future groups - // we do need to use the instantiated version. - let alias = if cycle.count_ones() > 1 { + // loop. e.g. given + // + // A : [ ConsA B, NilA ] + // B : [ ConsB A, NilB ] + // + // Our goal is + // + // A : [ ConsA [ ConsB A, NilB ], NilA ] + // B : [ ConsB [ ConsA B, NilA ], NilB ] + // + // But if we would first instantiate B into A, then use the updated A to instantiate B, + // we get + // + // A : [ ConsA [ ConsB A, NilB ], NilA ] + // B : [ ConsB [ ConsA [ ConsB A, NilB ], NilA ], NilB ] + // + // Which is incorrect. We do need the instantiated version however. + // e.g. if in a next group we have: + // + // C : A + // + // Then we must use the instantiated version + // + // C : [ ConsA [ ConsB A, NilB ], NilA ] + // + // So, we cannot replace the original version of A with its instantiated version + // while we process A's group. We have to store the instantiated version until the + // current group is done, then move it to the `aliases` array. That is what the scratchpad is for. + let alias = if cycle.count_ones() == 1 { + // an optimization: we can modify the alias in the `aliases` list directly + // because it is the only alias in the group. + &mut aliases[index] + } else { scratchpad.push((index, aliases[index].clone())); &mut scratchpad.last_mut().unwrap().1 - } else { - &mut aliases[index] }; - // we run into a problem here where we want to modify an element in the aliases array, - // but also reference the other elements. The borrow checker, correctly, says no to that. + // Now, `alias` is possibly a mutable borrow from the `aliases` vector. But we also want + // to immutably borrow other elements from that vector to instantiate them into `alias`. + // The borrow checker disallows that. // // So we get creative: we swap out the element we want to modify with a dummy. We can - // then freely modify the type we moved out, and the `to_instantiate_bitvec` mask - // prevents our dummy from being used. + // then freely modify the type we moved out, and the `to_instantiate` mask + // makes sure that our dummy is not used. let alias_region = alias.region; let mut alias_type = Type::EmptyRec; @@ -1789,7 +1817,7 @@ fn correct_mutual_recursive_type_alias<'a>( std::mem::swap(&mut alias_type, &mut alias.typ); let can_instantiate_symbol = |s| match symbols_introduced.iter().position(|i| *i == s) { - Some(s_index) if to_instantiate_bitvec[s_index] => aliases.get(s_index), + Some(s_index) if to_instantiate[s_index] => aliases.get(s_index), _ => None, }; @@ -1811,7 +1839,7 @@ fn correct_mutual_recursive_type_alias<'a>( std::mem::swap(&mut alias_type, &mut alias.typ); // We can instantiate this alias in future iterations - to_instantiate_bitvec.set(index, true); + to_instantiate.set(index, true); // add any lambda sets that the instantiation created to the current alias alias.lambda_set_variables.extend( @@ -1837,6 +1865,7 @@ fn correct_mutual_recursive_type_alias<'a>( } } + // the current group has instantiated. Now we can move the updated aliases to the `aliases` vector for (index, alias) in scratchpad.drain(..) { aliases[index] = alias; } @@ -1870,7 +1899,7 @@ fn correct_mutual_recursive_type_alias<'a>( } // We've instantiated all we could, so all instantiatable aliases are solved now - solved_aliases_bitvec = to_instantiate_bitvec; + solved_aliases = to_instantiate; } // Safety: both vectors are equal length and there are no duplicates From 6e7a8f2d3edb77050bf6b55b590e6cd637341e7d Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 22 Apr 2022 16:52:26 -0400 Subject: [PATCH 530/846] Remove private tags from test-gen --- compiler/test_gen/src/gen_primitives.rs | 54 ++++++++++++------------- compiler/test_gen/src/gen_tags.rs | 4 +- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/compiler/test_gen/src/gen_primitives.rs b/compiler/test_gen/src/gen_primitives.rs index a9d1691273..9611df0cc6 100644 --- a/compiler/test_gen/src/gen_primitives.rs +++ b/compiler/test_gen/src/gen_primitives.rs @@ -1134,13 +1134,13 @@ fn io_poc_effect() { r#" app "test" provides [ main ] to "./platform" - Effect a : [ @Effect ({} -> a) ] + Effect a := {} -> a succeed : a -> Effect a - succeed = \x -> @Effect \{} -> x + succeed = \x -> $Effect \{} -> x runEffect : Effect a -> a - runEffect = \@Effect thunk -> thunk {} + runEffect = \$Effect thunk -> thunk {} foo : Effect F64 foo = @@ -1193,10 +1193,10 @@ fn return_wrapped_function_pointer() { r#" app "test" provides [ main ] to "./platform" - Effect a : [ @Effect ({} -> a) ] + Effect a := {} -> a foo : Effect {} - foo = @Effect \{} -> {} + foo = $Effect \{} -> {} main : Effect {} main = foo @@ -1238,13 +1238,13 @@ fn return_wrapped_closure() { r#" app "test" provides [ main ] to "./platform" - Effect a : [ @Effect ({} -> a) ] + Effect a := {} -> a foo : Effect {} foo = x = 5 - @Effect (\{} -> if x > 3 then {} else {}) + $Effect (\{} -> if x > 3 then {} else {}) main : Effect {} main = foo @@ -1864,16 +1864,16 @@ fn task_always_twice() { r#" app "test" provides [ main ] to "./platform" - Effect a : [ @Effect ({} -> a) ] + Effect a := {} -> a effectAlways : a -> Effect a effectAlways = \x -> inner = \{} -> x - @Effect inner + $Effect inner effectAfter : Effect a, (a -> Effect b) -> Effect b - effectAfter = \(@Effect thunk), transform -> transform (thunk {}) + effectAfter = \($Effect thunk), transform -> transform (thunk {}) Task a err : Effect (Result a err) @@ -1909,7 +1909,7 @@ fn wildcard_rigid() { r#" app "test" provides [ main ] to "./platform" - Effect a : [ @Effect ({} -> a) ] + Effect a := {} -> a Task a err : Effect (Result a err) @@ -1918,7 +1918,7 @@ fn wildcard_rigid() { always = \x -> inner = \{} -> (Ok x) - @Effect inner + $Effect inner main : Task {} (Float *) @@ -1939,7 +1939,7 @@ fn alias_of_alias_with_type_arguments() { r#" app "test" provides [ main ] to "./platform" - Effect a : [ @Effect a ] + Effect a := {} -> a Task a err : Effect (Result a err) @@ -1947,7 +1947,7 @@ fn alias_of_alias_with_type_arguments() { always = \x -> inner = (Ok x) - @Effect inner + $Effect inner main : Task {} (Float *) @@ -1969,16 +1969,16 @@ fn todo_bad_error_message() { r#" app "test" provides [ main ] to "./platform" - Effect a : [ @Effect ({} -> a) ] + Effect a := {} -> a effectAlways : a -> Effect a effectAlways = \x -> inner = \{} -> x - @Effect inner + $Effect inner effectAfter : Effect a, (a -> Effect b) -> Effect b - effectAfter = \(@Effect thunk), transform -> transform (thunk {}) + effectAfter = \($Effect thunk), transform -> transform (thunk {}) Task a err : Effect (Result a err) @@ -3101,7 +3101,7 @@ fn nested_rigid_alias() { r#" app "test" provides [ main ] to "./platform" - Identity a : [ @Identity a ] + Identity a := a foo : Identity a -> Identity a foo = \list -> @@ -3111,7 +3111,7 @@ fn nested_rigid_alias() { p2 main = - when foo (@Identity "foo") is + when foo ($Identity "foo") is _ -> "hello world" "# ), @@ -3128,15 +3128,15 @@ fn nested_rigid_tag_union() { r#" app "test" provides [ main ] to "./platform" - foo : [ @Identity a ] -> [ @Identity a ] + foo : [ Identity a ] -> [ Identity a ] foo = \list -> - p2 : [ @Identity a ] + p2 : [ Identity a ] p2 = list p2 main = - when foo (@Identity "foo") is + when foo (Identity "foo") is _ -> "hello world" "# ), @@ -3222,16 +3222,16 @@ fn recursively_build_effect() { always {} |> after \_ -> nestHelp (m - 1) - XEffect a : [ @XEffect ({} -> a) ] + XEffect a := {} -> a always : a -> XEffect a - always = \x -> @XEffect (\{} -> x) + always = \x -> $XEffect (\{} -> x) after : XEffect a, (a -> XEffect b) -> XEffect b - after = \(@XEffect e), toB -> - @XEffect \{} -> + after = \($XEffect e), toB -> + $XEffect \{} -> when toB (e {}) is - @XEffect e2 -> + $XEffect e2 -> e2 {} "# ), diff --git a/compiler/test_gen/src/gen_tags.rs b/compiler/test_gen/src/gen_tags.rs index 48dc0880d2..20c2d2b8d6 100644 --- a/compiler/test_gen/src/gen_tags.rs +++ b/compiler/test_gen/src/gen_tags.rs @@ -1055,10 +1055,10 @@ fn phantom_polymorphic() { r"# Point coordinate : [ Point coordinate I64 I64 ] - World : [ @World ] + World := {} zero : Point World - zero = Point @World 0 0 + zero = Point ($World {}) 0 0 add : Point a -> Point a add = \(Point c x y) -> (Point c x y) From 45eb6d3ff4add1344ff63a3183c88f0c790e7d0f Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 22 Apr 2022 16:57:18 -0400 Subject: [PATCH 531/846] Remove private tags from Bytes --- examples/benchmarks/Bytes/Decode.roc | 30 ++++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/examples/benchmarks/Bytes/Decode.roc b/examples/benchmarks/Bytes/Decode.roc index d5e22e8f78..f5b9605e4b 100644 --- a/examples/benchmarks/Bytes/Decode.roc +++ b/examples/benchmarks/Bytes/Decode.roc @@ -4,10 +4,10 @@ State : { bytes : List U8, cursor : Nat } DecodeProblem : [ OutOfBytes ] -Decoder a : [ @Decoder (State -> [ Good State a, Bad DecodeProblem ]) ] +Decoder a := State -> [ Good State a, Bad DecodeProblem ] decode : List U8, Decoder a -> Result a DecodeProblem -decode = \bytes, @Decoder decoder -> +decode = \bytes, $Decoder decoder -> when decoder { bytes, cursor: 0 } is Good _ value -> Ok value @@ -16,11 +16,11 @@ decode = \bytes, @Decoder decoder -> Err e succeed : a -> Decoder a -succeed = \value -> @Decoder \state -> Good state value +succeed = \value -> $Decoder \state -> Good state value map : Decoder a, (a -> b) -> Decoder b -map = \@Decoder decoder, transform -> - @Decoder +map = \$Decoder decoder, transform -> + $Decoder \state -> when decoder state is Good state1 value -> @@ -30,8 +30,8 @@ map = \@Decoder decoder, transform -> Bad e map2 : Decoder a, Decoder b, (a, b -> c) -> Decoder c -map2 = \@Decoder decoder1, @Decoder decoder2, transform -> - @Decoder +map2 = \$Decoder decoder1, $Decoder decoder2, transform -> + $Decoder \state1 -> when decoder1 state1 is Good state2 a -> @@ -46,8 +46,8 @@ map2 = \@Decoder decoder1, @Decoder decoder2, transform -> Bad e map3 : Decoder a, Decoder b, Decoder c, (a, b, c -> d) -> Decoder d -map3 = \@Decoder decoder1, @Decoder decoder2, @Decoder decoder3, transform -> - @Decoder +map3 = \$Decoder decoder1, $Decoder decoder2, $Decoder decoder3, transform -> + $Decoder \state1 -> when decoder1 state1 is Good state2 a -> @@ -67,12 +67,12 @@ map3 = \@Decoder decoder1, @Decoder decoder2, @Decoder decoder3, transform -> Bad e after : Decoder a, (a -> Decoder b) -> Decoder b -after = \@Decoder decoder, transform -> - @Decoder +after = \$Decoder decoder, transform -> + $Decoder \state -> when decoder state is Good state1 value -> - (@Decoder decoder1) = transform value + ($Decoder decoder1) = transform value decoder1 state1 @@ -80,7 +80,7 @@ after = \@Decoder decoder, transform -> Bad e u8 : Decoder U8 -u8 = @Decoder +u8 = $Decoder \state -> when List.get state.bytes state.cursor is Ok b -> @@ -93,12 +93,12 @@ Step state b : [ Loop state, Done b ] loop : (state -> Decoder (Step state a)), state -> Decoder a loop = \stepper, initial -> - @Decoder + $Decoder \state -> loopHelp stepper initial state loopHelp = \stepper, accum, state -> - (@Decoder stepper1) = stepper accum + ($Decoder stepper1) = stepper accum when stepper1 state is Good newState (Done value) -> From 36014e332d7c8d9e320ec627799b59c0623aab75 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 22 Apr 2022 16:58:05 -0400 Subject: [PATCH 532/846] Remove private tags from false interpreter --- examples/false-interpreter/Variable.roc | 8 ++++---- examples/false-interpreter/platform/File.roc | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/false-interpreter/Variable.roc b/examples/false-interpreter/Variable.roc index c4675c06c9..f6cacbdce5 100644 --- a/examples/false-interpreter/Variable.roc +++ b/examples/false-interpreter/Variable.roc @@ -4,7 +4,7 @@ interface Variable # Variables in False can only be single letters. Thus, the valid variables are "a" to "z". # This opaque type deals with ensure we always have valid variables. -Variable : [ @Variable U8 ] +Variable := U8 totalCount : Nat totalCount = @@ -15,7 +15,7 @@ totalCount = + 1 toStr : Variable -> Str -toStr = \@Variable char -> +toStr = \$Variable char -> when Str.fromUtf8 [ char ] is Ok str -> str @@ -33,11 +33,11 @@ fromUtf8 = \char -> <= 0x7A # "z" then - Ok (@Variable char) + Ok ($Variable char) else Err InvalidVariableUtf8 toIndex : Variable -> Nat -toIndex = \@Variable char -> +toIndex = \$Variable char -> Num.intCast (char - 0x61)# "a" # List.first (Str.toUtf8 "a") diff --git a/examples/false-interpreter/platform/File.roc b/examples/false-interpreter/platform/File.roc index 939f31b7e8..c92cf4e63c 100644 --- a/examples/false-interpreter/platform/File.roc +++ b/examples/false-interpreter/platform/File.roc @@ -2,22 +2,22 @@ interface File exposes [ line, Handle, withOpen, chunk ] imports [ pf.Effect, Task.{ Task } ] -Handle : [ @Handle U64 ] +Handle := U64 line : Handle -> Task.Task Str * -line = \@Handle handle -> Effect.after (Effect.getFileLine handle) Task.succeed +line = \$Handle handle -> Effect.after (Effect.getFileLine handle) Task.succeed chunk : Handle -> Task.Task (List U8) * -chunk = \@Handle handle -> Effect.after (Effect.getFileBytes handle) Task.succeed +chunk = \$Handle handle -> Effect.after (Effect.getFileBytes handle) Task.succeed open : Str -> Task.Task Handle * open = \path -> Effect.openFile path - |> Effect.map (\id -> @Handle id) + |> Effect.map (\id -> $Handle id) |> Effect.after Task.succeed close : Handle -> Task.Task {} * -close = \@Handle handle -> Effect.after (Effect.closeFile handle) Task.succeed +close = \$Handle handle -> Effect.after (Effect.closeFile handle) Task.succeed withOpen : Str, (Handle -> Task {} a) -> Task {} a withOpen = \path, callback -> From abd454276dddae004db1c03cb9f98a55504b8001 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 22 Apr 2022 17:06:02 -0400 Subject: [PATCH 533/846] Remove private tags from Result This matches the actual definition --- compiler/builtins/docs/Result.roc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/builtins/docs/Result.roc b/compiler/builtins/docs/Result.roc index 0139029572..230c5f9fd1 100644 --- a/compiler/builtins/docs/Result.roc +++ b/compiler/builtins/docs/Result.roc @@ -13,7 +13,7 @@ interface Result ## The result of an operation that could fail: either the operation went ## okay, or else there was an error of some sort. -Result ok err : [ @Result ok err ] +Result ok err : [ Ok ok, Err err ] ## Return True if the result indicates a success, else return False ## From 1856b32d7c9a51ef53b4c19d8b89e0a691013e61 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 22 Apr 2022 17:06:42 -0400 Subject: [PATCH 534/846] Remove private tags from List --- compiler/builtins/docs/List.roc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/builtins/docs/List.roc b/compiler/builtins/docs/List.roc index 25ddbc6344..3a57d27235 100644 --- a/compiler/builtins/docs/List.roc +++ b/compiler/builtins/docs/List.roc @@ -187,7 +187,7 @@ interface List ## * Even when copying is faster, other list operations may still be slightly slower with persistent data structures. For example, even if it were a persistent data structure, [List.map], [List.walk], and [List.keepIf] would all need to traverse every element in the list and build up the result from scratch. These operations are all ## * Roc's compiler optimizes many list operations into in-place mutations behind the scenes, depending on how the list is being used. For example, [List.map], [List.keepIf], and [List.set] can all be optimized to perform in-place mutations. ## * If possible, it is usually best for performance to use large lists in a way where the optimizer can turn them into in-place mutations. If this is not possible, a persistent data structure might be faster - but this is a rare enough scenario that it would not be good for the average Roc program's performance if this were the way [List] worked by default. Instead, you can look outside Roc's standard modules for an implementation of a persistent data structure - likely built using [List] under the hood! -List elem : [ @List elem ] +List elem := [ List elem ] ## Initialize From be56cdf78211ccd0414dcae7134cffb88dbf6a91 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 22 Apr 2022 17:07:18 -0400 Subject: [PATCH 535/846] Remove private tags from Str --- compiler/builtins/docs/Str.roc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/builtins/docs/Str.roc b/compiler/builtins/docs/Str.roc index e67e4f234a..0bfa3ca2af 100644 --- a/compiler/builtins/docs/Str.roc +++ b/compiler/builtins/docs/Str.roc @@ -116,7 +116,7 @@ interface Str ## It has many more tools than this module does! ## A [Unicode](https://unicode.org) text value. -Str : [ @Str ] +Str := [ Str ] ## Convert From ee30b85430b2557dfaa262890154037aa938f011 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 22 Apr 2022 17:10:26 -0400 Subject: [PATCH 536/846] Remove private tags from unicode package --- packages/unicode/src/Unicode/CodePoint/Internal.roc | 6 +++--- packages/unicode/src/Unicode/Scalar.roc | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/unicode/src/Unicode/CodePoint/Internal.roc b/packages/unicode/src/Unicode/CodePoint/Internal.roc index 5bac8917c7..27d754e8ca 100644 --- a/packages/unicode/src/Unicode/CodePoint/Internal.roc +++ b/packages/unicode/src/Unicode/CodePoint/Internal.roc @@ -10,12 +10,12 @@ interface Unicode.CodePoint.Internal [] ## This is just here so that both Unicode.Scalar and Unicode.CodePoint can access it. -CodePoint : [ @CodePoint U32 ] +CodePoint := U32 fromU32Unchecked : U32 -> CodePoint -fromU32Unchecked = \u32 -> @CodePoint u32 +fromU32Unchecked = \u32 -> $CodePoint u32 toU32 : CodePoint -> U32 -toU32 = \@CodePoint u32 -> u32 +toU32 = \$CodePoint u32 -> u32 fromU32 : U32 -> Result CodePoint [ BadCodePoint ]* diff --git a/packages/unicode/src/Unicode/Scalar.roc b/packages/unicode/src/Unicode/Scalar.roc index e8a3537d9a..6979d01d04 100644 --- a/packages/unicode/src/Unicode/Scalar.roc +++ b/packages/unicode/src/Unicode/Scalar.roc @@ -18,10 +18,10 @@ interface Unicode.Scalar ] ## A [Unicode Scalar Value](http://www.unicode.org/glossary/#unicode_scalar_value) -Scalar : [ @Scalar U32 ] +Scalar := U32 toStr : Scalar -> Str -toStr = \@Scalar u32 +toStr = \$Scalar u32 when Str.fromScalar u32 is Ok str -> str Err _ -> @@ -29,10 +29,10 @@ toStr = \@Scalar u32 # this Err branch will never run. That's because it only runs # if Str.fromScalar receives an invalid scalar value, and we've # already validated this! - toStr (@Scalar (scalar * 256)) + toStr ($Scalar (scalar * 256)) toCodePt : Scalar -> CodePt -toCodePt = \@Scalar u32 -> Internal.fromU32Unchecked u32 +toCodePt = \$Scalar u32 -> Internal.fromU32Unchecked u32 fromCodePt : CodePt -> Result Scalar [ PointWasSurrogate ]* From f630536f5c88565c6c90169b5f89473b54deb681 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 22 Apr 2022 17:11:01 -0400 Subject: [PATCH 537/846] Remove private tags from parser package --- packages/parser/src/Bytes/Parser.roc | 5 +---- packages/parser/src/Str/Parser.roc | 17 +++++++---------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/packages/parser/src/Bytes/Parser.roc b/packages/parser/src/Bytes/Parser.roc index 31a61654d6..a1dc6648c0 100644 --- a/packages/parser/src/Bytes/Parser.roc +++ b/packages/parser/src/Bytes/Parser.roc @@ -17,10 +17,7 @@ interface Parser exposes [ Parser ] imports [] -Parser a : - [ - @Parser (Bytes -> Result { answer : a, rest : Bytes } Problem) - ] +Parser a := Bytes -> Result { answer : a, rest : Bytes } Problem Problem : [ diff --git a/packages/parser/src/Str/Parser.roc b/packages/parser/src/Str/Parser.roc index 9962b83a14..1e7af10c75 100644 --- a/packages/parser/src/Str/Parser.roc +++ b/packages/parser/src/Str/Parser.roc @@ -19,10 +19,7 @@ interface Parser exposes [ Parser ] imports [] -Parser a : - [ - @Parser (Str -> Result { answer : a, rest : Str } RawProblem), - ] +Parser a := Str -> Result { answer : a, rest : Str } RawProblem Problem : [ @@ -51,16 +48,16 @@ keep : Parser a, (a -> Parser b) -> Parser b skip : Parser *, ({} -> Parser b) -> Parser b symbol : Str -> Parser {} -symbol = \symbol -> @Parser Str.chompStr symbol +symbol = \symbol -> $Parser Str.chompStr symbol u8 : Parser U8 -u8 = @Parser Str.parseU8 +u8 = $Parser Str.parseU8 i8 : Parser I8 -i8 = @Parser Str.parseI8 +i8 = $Parser Str.parseI8 end : Parser {} -end = @Parser \str -> +end = $Parser \str -> if Str.isEmpty str then Ok {} else @@ -68,7 +65,7 @@ end = @Parser \str -> lazy : ({} -> Parser a) -> Parser a lazy = \thunk -> - @Parser \str -> - @Parser parse = thunk {} + $Parser \str -> + $Parser parse = thunk {} parse str From 71a5471bec6c7db67f82b29160fd2f7444c315bf Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 22 Apr 2022 17:13:27 -0400 Subject: [PATCH 538/846] Remove private tags from Set --- compiler/builtins/docs/Set.roc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/builtins/docs/Set.roc b/compiler/builtins/docs/Set.roc index 98b5b3e286..6f7f87e9c4 100644 --- a/compiler/builtins/docs/Set.roc +++ b/compiler/builtins/docs/Set.roc @@ -18,7 +18,7 @@ interface Set imports [] ## A Set is an unordered collection of unique elements. -Set elem : [ @Set elem ] +Set elem := [ Set elem ] ## An empty set. empty : Set * From 1b83b2e9afef6aea1d7bac18a1ecc5bd25ab3823 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 22 Apr 2022 17:13:49 -0400 Subject: [PATCH 539/846] Remove private tags from Dict --- compiler/builtins/docs/Dict.roc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/builtins/docs/Dict.roc b/compiler/builtins/docs/Dict.roc index 0de2d5ad5d..8e0bba0a41 100644 --- a/compiler/builtins/docs/Dict.roc +++ b/compiler/builtins/docs/Dict.roc @@ -93,7 +93,7 @@ interface Dict ## ## The [Dict.hasSameContents] function gives an alternative to `==` which ignores ordering ## and returns `True` if both dictionaries have the same keys and associated values. -Dict k v : [ @Dict k v ] # TODO k should require a hashing and equating constraint +Dict k v := [ Dict k v ] # TODO k should require a hashing and equating constraint ## An empty dictionary. empty : Dict * * From bde722b92faba2b8a7e0d8aefc5b99de7b526df6 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 22 Apr 2022 17:48:16 -0400 Subject: [PATCH 540/846] Remove private tags from effect module --- compiler/can/src/effect_module.rs | 289 +++++++++++++++--------------- 1 file changed, 147 insertions(+), 142 deletions(-) diff --git a/compiler/can/src/effect_module.rs b/compiler/can/src/effect_module.rs index 2e58dc1bd1..b110bfc3da 100644 --- a/compiler/can/src/effect_module.rs +++ b/compiler/can/src/effect_module.rs @@ -6,11 +6,11 @@ use crate::pattern::Pattern; use crate::scope::Scope; use roc_collections::{SendMap, VecSet}; use roc_module::called_via::CalledVia; -use roc_module::ident::TagName; +use roc_module::ident::{Lowercase, TagName}; use roc_module::symbol::Symbol; use roc_region::all::{Loc, Region}; use roc_types::subs::{VarStore, Variable}; -use roc_types::types::{AliasKind, Type, TypeExtension}; +use roc_types::types::{AliasKind, LambdaSet, Type, TypeExtension}; #[derive(Debug, Default, Clone, Copy)] pub(crate) struct HostedGeneratedFunctions { @@ -30,7 +30,7 @@ pub(crate) struct HostedGeneratedFunctions { /// /// The effect alias is implemented as /// -/// Effect a : [ @Effect ({} -> a) ] +/// Effect a := {} -> a /// /// For this alias we implement the functions specified in HostedGeneratedFunctions with the /// standard implementation. @@ -45,13 +45,7 @@ pub(crate) fn build_effect_builtins( ) { macro_rules! helper { ($f:expr) => {{ - let (symbol, def) = $f( - env, - scope, - effect_symbol, - TagName::Private(effect_symbol), - var_store, - ); + let (symbol, def) = $f(env, scope, effect_symbol, var_store); // make the outside world know this symbol exists exposed_symbols.insert(symbol); @@ -114,10 +108,9 @@ fn build_effect_always( env: &mut Env, scope: &mut Scope, effect_symbol: Symbol, - effect_tag_name: TagName, var_store: &mut VarStore, ) -> (Symbol, Def) { - // Effect.always = \value -> @Effect \{} -> value + // Effect.always = \value -> $Effect \{} -> value let value_symbol = { scope @@ -174,14 +167,18 @@ fn build_effect_always( }) }; - // \value -> @Effect \{} -> value + // \value -> $Effect \{} -> value let (function_var, always_closure) = { - // `@Effect \{} -> value` - let body = Expr::Tag { - variant_var: var_store.fresh(), - ext_var: var_store.fresh(), - name: effect_tag_name.clone(), - arguments: vec![(var_store.fresh(), Loc::at_zero(const_closure))], + // `$Effect \{} -> value` + let (specialized_def_type, type_arguments, lambda_set_variables) = + build_fresh_opaque_variables(var_store); + let body = Expr::OpaqueRef { + opaque_var: var_store.fresh(), + name: effect_symbol, + argument: Box::new((var_store.fresh(), Loc::at_zero(const_closure))), + specialized_def_type, + type_arguments, + lambda_set_variables, }; let arguments = vec![( @@ -212,9 +209,8 @@ fn build_effect_always( let var_a = var_store.fresh(); introduced_variables.insert_named("a".into(), Loc::at_zero(var_a)); - let effect_a = build_effect_alias( + let effect_a = build_effect_opaque( effect_symbol, - effect_tag_name, "a", var_a, Type::Variable(var_a), @@ -257,10 +253,9 @@ fn build_effect_map( env: &mut Env, scope: &mut Scope, effect_symbol: Symbol, - effect_tag_name: TagName, var_store: &mut VarStore, ) -> (Symbol, Def) { - // Effect.map = \@Effect thunk, mapper -> @Effect \{} -> mapper (thunk {}) + // Effect.map = \$Effect thunk, mapper -> $Effect \{} -> mapper (thunk {}) let thunk_symbol = { scope @@ -355,17 +350,22 @@ fn build_effect_map( }) }; + // \$Effect thunk, mapper + let (specialized_def_type, type_arguments, lambda_set_variables) = + build_fresh_opaque_variables(var_store); let arguments = vec![ ( var_store.fresh(), - Loc::at_zero(Pattern::AppliedTag { + Loc::at_zero(Pattern::UnwrappedOpaque { + opaque: effect_symbol, whole_var: var_store.fresh(), - ext_var: var_store.fresh(), - tag_name: effect_tag_name.clone(), - arguments: vec![( + argument: Box::new(( var_store.fresh(), Loc::at_zero(Pattern::Identifier(thunk_symbol)), - )], + )), + specialized_def_type, + type_arguments, + lambda_set_variables, }), ), ( @@ -374,12 +374,16 @@ fn build_effect_map( ), ]; - // `@Effect \{} -> (mapper (thunk {}))` - let body = Expr::Tag { - variant_var: var_store.fresh(), - ext_var: var_store.fresh(), - name: effect_tag_name.clone(), - arguments: vec![(var_store.fresh(), Loc::at_zero(inner_closure))], + // `$Effect \{} -> (mapper (thunk {}))` + let (specialized_def_type, type_arguments, lambda_set_variables) = + build_fresh_opaque_variables(var_store); + let body = Expr::OpaqueRef { + opaque_var: var_store.fresh(), + name: effect_symbol, + argument: Box::new((var_store.fresh(), Loc::at_zero(inner_closure))), + specialized_def_type, + type_arguments, + lambda_set_variables, }; let function_var = var_store.fresh(); @@ -405,9 +409,8 @@ fn build_effect_map( introduced_variables.insert_named("a".into(), Loc::at_zero(var_a)); introduced_variables.insert_named("b".into(), Loc::at_zero(var_b)); - let effect_a = build_effect_alias( + let effect_a = build_effect_opaque( effect_symbol, - effect_tag_name.clone(), "a", var_a, Type::Variable(var_a), @@ -415,9 +418,8 @@ fn build_effect_map( &mut introduced_variables, ); - let effect_b = build_effect_alias( + let effect_b = build_effect_opaque( effect_symbol, - effect_tag_name, "b", var_b, Type::Variable(var_b), @@ -469,10 +471,9 @@ fn build_effect_after( env: &mut Env, scope: &mut Scope, effect_symbol: Symbol, - effect_tag_name: TagName, var_store: &mut VarStore, ) -> (Symbol, Def) { - // Effect.after = \@Effect effect, toEffect -> toEffect (effect {}) + // Effect.after = \$Effect effect, toEffect -> toEffect (effect {}) let thunk_symbol = { scope @@ -533,17 +534,22 @@ fn build_effect_after( Expr::Call(Box::new(boxed), arguments, CalledVia::Space) }; + let (specialized_def_type, type_arguments, lambda_set_variables) = + build_fresh_opaque_variables(var_store); + let arguments = vec![ ( var_store.fresh(), - Loc::at_zero(Pattern::AppliedTag { + Loc::at_zero(Pattern::UnwrappedOpaque { + opaque: effect_symbol, whole_var: var_store.fresh(), - ext_var: var_store.fresh(), - tag_name: effect_tag_name.clone(), - arguments: vec![( + argument: Box::new(( var_store.fresh(), Loc::at_zero(Pattern::Identifier(thunk_symbol)), - )], + )), + specialized_def_type, + type_arguments, + lambda_set_variables, }), ), ( @@ -574,9 +580,8 @@ fn build_effect_after( introduced_variables.insert_named("a".into(), Loc::at_zero(var_a)); introduced_variables.insert_named("b".into(), Loc::at_zero(var_b)); - let effect_a = build_effect_alias( + let effect_a = build_effect_opaque( effect_symbol, - effect_tag_name.clone(), "a", var_a, Type::Variable(var_a), @@ -584,9 +589,8 @@ fn build_effect_after( &mut introduced_variables, ); - let effect_b = build_effect_alias( + let effect_b = build_effect_opaque( effect_symbol, - effect_tag_name, "b", var_b, Type::Variable(var_b), @@ -632,10 +636,10 @@ fn build_effect_after( (after_symbol, def) } -/// turn `value` into `@Effect \{} -> value` +/// turn `value` into `$Effect \{} -> value` fn wrap_in_effect_thunk( body: Expr, - effect_tag_name: TagName, + effect_symbol: Symbol, closure_name: Symbol, captured_symbols: Vec, var_store: &mut VarStore, @@ -666,32 +670,39 @@ fn wrap_in_effect_thunk( }) }; - // `@Effect \{} -> value` - Expr::Tag { - variant_var: var_store.fresh(), - ext_var: var_store.fresh(), - name: effect_tag_name, - arguments: vec![(var_store.fresh(), Loc::at_zero(const_closure))], + // `$Effect \{} -> value` + let (specialized_def_type, type_arguments, lambda_set_variables) = + build_fresh_opaque_variables(var_store); + Expr::OpaqueRef { + opaque_var: var_store.fresh(), + name: effect_symbol, + argument: Box::new((var_store.fresh(), Loc::at_zero(const_closure))), + specialized_def_type, + type_arguments, + lambda_set_variables, } } /// given `effect : Effect a`, unwrap the thunk and force it, giving a value of type `a` fn force_effect( effect: Expr, - effect_tag_name: TagName, + effect_symbol: Symbol, thunk_symbol: Symbol, var_store: &mut VarStore, ) -> Expr { let whole_var = var_store.fresh(); - let ext_var = var_store.fresh(); let thunk_var = var_store.fresh(); - let pattern = Pattern::AppliedTag { - ext_var, + let (specialized_def_type, type_arguments, lambda_set_variables) = + build_fresh_opaque_variables(var_store); + let pattern = Pattern::UnwrappedOpaque { whole_var, - tag_name: effect_tag_name, - arguments: vec![(thunk_var, Loc::at_zero(Pattern::Identifier(thunk_symbol)))], + opaque: effect_symbol, + argument: Box::new((thunk_var, Loc::at_zero(Pattern::Identifier(thunk_symbol)))), + specialized_def_type, + type_arguments, + lambda_set_variables, }; let pattern_vars = SendMap::default(); @@ -728,7 +739,6 @@ fn build_effect_forever( env: &mut Env, scope: &mut Scope, effect_symbol: Symbol, - effect_tag_name: TagName, var_store: &mut VarStore, ) -> (Symbol, Def) { // morally @@ -739,14 +749,14 @@ fn build_effect_forever( // // Effect.forever : Effect a -> Effect b // Effect.forever = \effect -> - // @Effect \{} -> - // @Effect thunk1 = effect + // $Effect \{} -> + // $Effect thunk1 = effect // _ = thunk1 {} - // @Effect thunk2 = Effect.forever effect + // $Effect thunk2 = Effect.forever effect // thunk2 {} // // We then rely on our defunctionalization to turn this into a tail-recursive loop. - // First the `@Effect` wrapper melts away + // First the `$Effect` wrapper melts away // // Effect.forever : ({} -> a) -> ({} -> b) // Effect.forever = \effect -> @@ -801,14 +811,8 @@ fn build_effect_forever( .unwrap() }; - let body = build_effect_forever_body( - env, - scope, - effect_tag_name.clone(), - forever_symbol, - effect, - var_store, - ); + let body = + build_effect_forever_body(env, scope, effect_symbol, forever_symbol, effect, var_store); let arguments = vec![(var_store.fresh(), Loc::at_zero(Pattern::Identifier(effect)))]; @@ -834,9 +838,8 @@ fn build_effect_forever( introduced_variables.insert_named("a".into(), Loc::at_zero(var_a)); introduced_variables.insert_named("b".into(), Loc::at_zero(var_b)); - let effect_a = build_effect_alias( + let effect_a = build_effect_opaque( effect_symbol, - effect_tag_name.clone(), "a", var_a, Type::Variable(var_a), @@ -844,9 +847,8 @@ fn build_effect_forever( &mut introduced_variables, ); - let effect_b = build_effect_alias( + let effect_b = build_effect_opaque( effect_symbol, - effect_tag_name, "b", var_b, Type::Variable(var_b), @@ -888,7 +890,7 @@ fn build_effect_forever( fn build_effect_forever_body( env: &mut Env, scope: &mut Scope, - effect_tag_name: TagName, + effect_symbol: Symbol, forever_symbol: Symbol, effect: Symbol, var_store: &mut VarStore, @@ -907,7 +909,7 @@ fn build_effect_forever_body( let inner_body = build_effect_forever_inner_body( env, scope, - effect_tag_name.clone(), + effect_symbol, forever_symbol, effect, var_store, @@ -916,7 +918,7 @@ fn build_effect_forever_body( let captured_symbols = vec![effect]; wrap_in_effect_thunk( inner_body, - effect_tag_name, + effect_symbol, closure_name, captured_symbols, var_store, @@ -926,7 +928,7 @@ fn build_effect_forever_body( fn build_effect_forever_inner_body( env: &mut Env, scope: &mut Scope, - effect_tag_name: TagName, + effect_symbol: Symbol, forever_symbol: Symbol, effect: Symbol, var_store: &mut VarStore, @@ -953,18 +955,21 @@ fn build_effect_forever_inner_body( .unwrap() }; - // Effect thunk1 = effect + // $Effect thunk1 = effect let thunk_from_effect = { let whole_var = var_store.fresh(); - let ext_var = var_store.fresh(); let thunk_var = var_store.fresh(); - let pattern = Pattern::AppliedTag { - ext_var, + let (specialized_def_type, type_arguments, lambda_set_variables) = + build_fresh_opaque_variables(var_store); + let pattern = Pattern::UnwrappedOpaque { whole_var, - tag_name: effect_tag_name.clone(), - arguments: vec![(thunk_var, Loc::at_zero(Pattern::Identifier(thunk1_symbol)))], + opaque: effect, + argument: Box::new((thunk_var, Loc::at_zero(Pattern::Identifier(thunk1_symbol)))), + specialized_def_type, + type_arguments, + lambda_set_variables, }; let pattern_vars = SendMap::default(); @@ -1017,12 +1022,12 @@ fn build_effect_forever_inner_body( }; // ``` - // Effect thunk2 = forever effect + // $Effect thunk2 = forever effect // thunk2 {} // ``` let force_thunk2 = Loc::at_zero(force_effect( forever_effect, - effect_tag_name, + effect_symbol, thunk2_symbol, var_store, )); @@ -1042,7 +1047,6 @@ fn build_effect_loop( env: &mut Env, scope: &mut Scope, effect_symbol: Symbol, - effect_tag_name: TagName, var_store: &mut VarStore, ) -> (Symbol, Def) { let loop_symbol = new_symbol!(scope, env, "loop"); @@ -1052,7 +1056,7 @@ fn build_effect_loop( let body = build_effect_loop_body( env, scope, - effect_tag_name.clone(), + effect_symbol, loop_symbol, state_symbol, step_symbol, @@ -1092,9 +1096,8 @@ fn build_effect_loop( introduced_variables.insert_named("a".into(), Loc::at_zero(var_a)); introduced_variables.insert_named("b".into(), Loc::at_zero(var_b)); - let effect_b = build_effect_alias( + let effect_b = build_effect_opaque( effect_symbol, - effect_tag_name.clone(), "b", var_b, Type::Variable(var_b), @@ -1119,19 +1122,11 @@ fn build_effect_loop( let closure_var = var_store.fresh(); introduced_variables.insert_wildcard(Loc::at_zero(closure_var)); - let actual = { - Type::TagUnion( - vec![( - effect_tag_name, - vec![Type::Function( - vec![Type::EmptyRec], - Box::new(Type::Variable(closure_var)), - Box::new(state_type.clone()), - )], - )], - TypeExtension::Closed, - ) - }; + let actual = Type::Function( + vec![Type::EmptyRec], + Box::new(Type::Variable(closure_var)), + Box::new(state_type.clone()), + ); Type::Alias { symbol: effect_symbol, @@ -1140,7 +1135,7 @@ fn build_effect_loop( closure_var, ))], actual: Box::new(actual), - kind: AliasKind::Structural, + kind: AliasKind::Opaque, } }; @@ -1187,7 +1182,7 @@ fn build_effect_loop( fn build_effect_loop_body( env: &mut Env, scope: &mut Scope, - effect_tag_name: TagName, + effect_symbol: Symbol, loop_symbol: Symbol, state_symbol: Symbol, step_symbol: Symbol, @@ -1207,7 +1202,7 @@ fn build_effect_loop_body( let inner_body = build_effect_loop_inner_body( env, scope, - effect_tag_name.clone(), + effect_symbol, loop_symbol, state_symbol, step_symbol, @@ -1217,7 +1212,7 @@ fn build_effect_loop_body( let captured_symbols = vec![state_symbol, step_symbol]; wrap_in_effect_thunk( inner_body, - effect_tag_name, + effect_symbol, closure_name, captured_symbols, var_store, @@ -1249,7 +1244,7 @@ fn applied_tag_pattern( fn build_effect_loop_inner_body( env: &mut Env, scope: &mut Scope, - effect_tag_name: TagName, + effect_symbol: Symbol, loop_symbol: Symbol, state_symbol: Symbol, step_symbol: Symbol, @@ -1264,15 +1259,18 @@ fn build_effect_loop_inner_body( // Effect thunk1 = step state let thunk_from_effect = { let whole_var = var_store.fresh(); - let ext_var = var_store.fresh(); let thunk_var = var_store.fresh(); - let pattern = Pattern::AppliedTag { - ext_var, + let (specialized_def_type, type_arguments, lambda_set_variables) = + build_fresh_opaque_variables(var_store); + let pattern = Pattern::UnwrappedOpaque { whole_var, - tag_name: effect_tag_name.clone(), - arguments: vec![(thunk_var, Loc::at_zero(Pattern::Identifier(thunk1_symbol)))], + opaque: effect_symbol, + argument: Box::new((thunk_var, Loc::at_zero(Pattern::Identifier(thunk1_symbol)))), + specialized_def_type, + type_arguments, + lambda_set_variables, }; let pattern_vars = SendMap::default(); @@ -1332,15 +1330,10 @@ fn build_effect_loop_inner_body( }; // ``` - // Effect thunk2 = loop effect + // $Effect thunk2 = loop effect // thunk2 {} // ``` - let force_thunk2 = force_effect( - loop_new_state_step, - effect_tag_name, - thunk2_symbol, - var_store, - ); + let force_thunk2 = force_effect(loop_new_state_step, effect_symbol, thunk2_symbol, var_store); let step_branch = { let step_tag_name = TagName::Global("Step".into()); @@ -1549,9 +1542,9 @@ pub fn build_host_exposed_def( } } -fn build_effect_alias( +/// Effect a := {} -> a +fn build_effect_opaque( effect_symbol: Symbol, - effect_tag_name: TagName, a_name: &str, a_var: Variable, a_type: Type, @@ -1561,29 +1554,41 @@ fn build_effect_alias( let closure_var = var_store.fresh(); introduced_variables.insert_wildcard(Loc::at_zero(closure_var)); - let actual = { - Type::TagUnion( - vec![( - effect_tag_name, - vec![Type::Function( - vec![Type::EmptyRec], - Box::new(Type::Variable(closure_var)), - Box::new(a_type), - )], - )], - TypeExtension::Closed, - ) - }; + let actual = Type::Function( + vec![Type::EmptyRec], + Box::new(Type::Variable(closure_var)), + Box::new(a_type), + ); Type::Alias { symbol: effect_symbol, type_arguments: vec![(a_name.into(), Type::Variable(a_var))], lambda_set_variables: vec![roc_types::types::LambdaSet(Type::Variable(closure_var))], actual: Box::new(actual), - kind: AliasKind::Structural, + kind: AliasKind::Opaque, } } +fn build_fresh_opaque_variables( + var_store: &mut VarStore, +) -> (Box, Vec<(Lowercase, Type)>, Vec) { + let closure_var = var_store.fresh(); + + // NB: if there are bugs, check whether not introducing variables is a problem! + // introduced_variables.insert_wildcard(Loc::at_zero(closure_var)); + + let a_var = var_store.fresh(); + let actual = Type::Function( + vec![Type::EmptyRec], + Box::new(Type::Variable(closure_var)), + Box::new(Type::Variable(a_var)), + ); + let type_arguments = vec![("a".into(), Type::Variable(a_var))]; + let lambda_set_variables = vec![roc_types::types::LambdaSet(Type::Variable(closure_var))]; + + (Box::new(actual), type_arguments, lambda_set_variables) +} + pub fn build_effect_actual( effect_tag_name: TagName, a_type: Type, From a53ba3498baf3197d1c5cdd8400e66d794ffaba1 Mon Sep 17 00:00:00 2001 From: ayazhafiz Date: Sat, 23 Apr 2022 20:20:34 -0400 Subject: [PATCH 541/846] Mark introduced variables --- compiler/can/src/annotation.rs | 2 +- compiler/can/src/effect_module.rs | 76 +++++++++++++++++++++---------- 2 files changed, 52 insertions(+), 26 deletions(-) diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index b6bdff3e87..f24742a784 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -125,7 +125,7 @@ impl IntroducedVariables { self.inferred.push(var); } - fn insert_lambda_set(&mut self, var: Variable) { + pub fn insert_lambda_set(&mut self, var: Variable) { self.debug_assert_not_already_present(var); self.lambda_sets.push(var); } diff --git a/compiler/can/src/effect_module.rs b/compiler/can/src/effect_module.rs index b110bfc3da..e9036c4bb7 100644 --- a/compiler/can/src/effect_module.rs +++ b/compiler/can/src/effect_module.rs @@ -167,11 +167,13 @@ fn build_effect_always( }) }; + let mut introduced_variables = IntroducedVariables::default(); + // \value -> $Effect \{} -> value let (function_var, always_closure) = { // `$Effect \{} -> value` let (specialized_def_type, type_arguments, lambda_set_variables) = - build_fresh_opaque_variables(var_store); + build_fresh_opaque_variables(var_store, &mut introduced_variables); let body = Expr::OpaqueRef { opaque_var: var_store.fresh(), name: effect_symbol, @@ -202,8 +204,6 @@ fn build_effect_always( (function_var, closure) }; - let mut introduced_variables = IntroducedVariables::default(); - let signature = { // Effect.always : a -> Effect a let var_a = var_store.fresh(); @@ -327,6 +327,8 @@ fn build_effect_map( .unwrap() }; + let mut introduced_variables = IntroducedVariables::default(); + // \{} -> mapper (thunk {}) let inner_closure = { let arguments = vec![( @@ -352,7 +354,7 @@ fn build_effect_map( // \$Effect thunk, mapper let (specialized_def_type, type_arguments, lambda_set_variables) = - build_fresh_opaque_variables(var_store); + build_fresh_opaque_variables(var_store, &mut introduced_variables); let arguments = vec![ ( var_store.fresh(), @@ -376,7 +378,7 @@ fn build_effect_map( // `$Effect \{} -> (mapper (thunk {}))` let (specialized_def_type, type_arguments, lambda_set_variables) = - build_fresh_opaque_variables(var_store); + build_fresh_opaque_variables(var_store, &mut introduced_variables); let body = Expr::OpaqueRef { opaque_var: var_store.fresh(), name: effect_symbol, @@ -399,8 +401,6 @@ fn build_effect_map( loc_body: Box::new(Loc::at_zero(body)), }); - let mut introduced_variables = IntroducedVariables::default(); - let signature = { // Effect.map : Effect a, (a -> b) -> Effect b let var_a = var_store.fresh(); @@ -534,8 +534,10 @@ fn build_effect_after( Expr::Call(Box::new(boxed), arguments, CalledVia::Space) }; + let mut introduced_variables = IntroducedVariables::default(); + let (specialized_def_type, type_arguments, lambda_set_variables) = - build_fresh_opaque_variables(var_store); + build_fresh_opaque_variables(var_store, &mut introduced_variables); let arguments = vec![ ( @@ -571,8 +573,6 @@ fn build_effect_after( loc_body: Box::new(Loc::at_zero(to_effect_call)), }); - let mut introduced_variables = IntroducedVariables::default(); - let signature = { let var_a = var_store.fresh(); let var_b = var_store.fresh(); @@ -643,6 +643,7 @@ fn wrap_in_effect_thunk( closure_name: Symbol, captured_symbols: Vec, var_store: &mut VarStore, + introduced_variables: &mut IntroducedVariables, ) -> Expr { let captured_symbols: Vec<_> = captured_symbols .into_iter() @@ -672,7 +673,7 @@ fn wrap_in_effect_thunk( // `$Effect \{} -> value` let (specialized_def_type, type_arguments, lambda_set_variables) = - build_fresh_opaque_variables(var_store); + build_fresh_opaque_variables(var_store, introduced_variables); Expr::OpaqueRef { opaque_var: var_store.fresh(), name: effect_symbol, @@ -689,13 +690,14 @@ fn force_effect( effect_symbol: Symbol, thunk_symbol: Symbol, var_store: &mut VarStore, + introduced_variables: &mut IntroducedVariables, ) -> Expr { let whole_var = var_store.fresh(); let thunk_var = var_store.fresh(); let (specialized_def_type, type_arguments, lambda_set_variables) = - build_fresh_opaque_variables(var_store); + build_fresh_opaque_variables(var_store, introduced_variables); let pattern = Pattern::UnwrappedOpaque { whole_var, opaque: effect_symbol, @@ -811,8 +813,17 @@ fn build_effect_forever( .unwrap() }; - let body = - build_effect_forever_body(env, scope, effect_symbol, forever_symbol, effect, var_store); + let mut introduced_variables = IntroducedVariables::default(); + + let body = build_effect_forever_body( + env, + scope, + effect_symbol, + forever_symbol, + effect, + var_store, + &mut introduced_variables, + ); let arguments = vec![(var_store.fresh(), Loc::at_zero(Pattern::Identifier(effect)))]; @@ -829,8 +840,6 @@ fn build_effect_forever( loc_body: Box::new(Loc::at_zero(body)), }); - let mut introduced_variables = IntroducedVariables::default(); - let signature = { let var_a = var_store.fresh(); let var_b = var_store.fresh(); @@ -894,6 +903,7 @@ fn build_effect_forever_body( forever_symbol: Symbol, effect: Symbol, var_store: &mut VarStore, + introduced_variables: &mut IntroducedVariables, ) -> Expr { let closure_name = { scope @@ -913,6 +923,7 @@ fn build_effect_forever_body( forever_symbol, effect, var_store, + introduced_variables, ); let captured_symbols = vec![effect]; @@ -922,6 +933,7 @@ fn build_effect_forever_body( closure_name, captured_symbols, var_store, + introduced_variables, ) } @@ -932,6 +944,7 @@ fn build_effect_forever_inner_body( forever_symbol: Symbol, effect: Symbol, var_store: &mut VarStore, + introduced_variables: &mut IntroducedVariables, ) -> Expr { let thunk1_symbol = { scope @@ -962,7 +975,7 @@ fn build_effect_forever_inner_body( let thunk_var = var_store.fresh(); let (specialized_def_type, type_arguments, lambda_set_variables) = - build_fresh_opaque_variables(var_store); + build_fresh_opaque_variables(var_store, introduced_variables); let pattern = Pattern::UnwrappedOpaque { whole_var, opaque: effect, @@ -1030,6 +1043,7 @@ fn build_effect_forever_inner_body( effect_symbol, thunk2_symbol, var_store, + introduced_variables, )); Expr::LetNonRec( @@ -1053,6 +1067,8 @@ fn build_effect_loop( let state_symbol = new_symbol!(scope, env, "state"); let step_symbol = new_symbol!(scope, env, "step"); + let mut introduced_variables = IntroducedVariables::default(); + let body = build_effect_loop_body( env, scope, @@ -1061,6 +1077,7 @@ fn build_effect_loop( state_symbol, step_symbol, var_store, + &mut introduced_variables, ); let arguments = vec![ @@ -1087,8 +1104,6 @@ fn build_effect_loop( loc_body: Box::new(Loc::at_zero(body)), }); - let mut introduced_variables = IntroducedVariables::default(); - let signature = { let var_a = var_store.fresh(); let var_b = var_store.fresh(); @@ -1187,6 +1202,7 @@ fn build_effect_loop_body( state_symbol: Symbol, step_symbol: Symbol, var_store: &mut VarStore, + introduced_variables: &mut IntroducedVariables, ) -> Expr { let closure_name = { scope @@ -1207,6 +1223,7 @@ fn build_effect_loop_body( state_symbol, step_symbol, var_store, + introduced_variables, ); let captured_symbols = vec![state_symbol, step_symbol]; @@ -1216,6 +1233,7 @@ fn build_effect_loop_body( closure_name, captured_symbols, var_store, + introduced_variables, ) } @@ -1249,6 +1267,7 @@ fn build_effect_loop_inner_body( state_symbol: Symbol, step_symbol: Symbol, var_store: &mut VarStore, + introduced_variables: &mut IntroducedVariables, ) -> Expr { let thunk1_symbol = new_symbol!(scope, env, "thunk3"); let thunk2_symbol = new_symbol!(scope, env, "thunk4"); @@ -1263,7 +1282,7 @@ fn build_effect_loop_inner_body( let thunk_var = var_store.fresh(); let (specialized_def_type, type_arguments, lambda_set_variables) = - build_fresh_opaque_variables(var_store); + build_fresh_opaque_variables(var_store, introduced_variables); let pattern = Pattern::UnwrappedOpaque { whole_var, opaque: effect_symbol, @@ -1333,7 +1352,13 @@ fn build_effect_loop_inner_body( // $Effect thunk2 = loop effect // thunk2 {} // ``` - let force_thunk2 = force_effect(loop_new_state_step, effect_symbol, thunk2_symbol, var_store); + let force_thunk2 = force_effect( + loop_new_state_step, + effect_symbol, + thunk2_symbol, + var_store, + introduced_variables, + ); let step_branch = { let step_tag_name = TagName::Global("Step".into()); @@ -1552,7 +1577,7 @@ fn build_effect_opaque( introduced_variables: &mut IntroducedVariables, ) -> Type { let closure_var = var_store.fresh(); - introduced_variables.insert_wildcard(Loc::at_zero(closure_var)); + introduced_variables.insert_lambda_set(closure_var); let actual = Type::Function( vec![Type::EmptyRec], @@ -1571,13 +1596,14 @@ fn build_effect_opaque( fn build_fresh_opaque_variables( var_store: &mut VarStore, + introduced_variables: &mut IntroducedVariables, ) -> (Box, Vec<(Lowercase, Type)>, Vec) { + let a_var = var_store.fresh(); let closure_var = var_store.fresh(); - // NB: if there are bugs, check whether not introducing variables is a problem! - // introduced_variables.insert_wildcard(Loc::at_zero(closure_var)); + introduced_variables.insert_named("a".into(), Loc::at_zero(a_var)); + introduced_variables.insert_lambda_set(closure_var); - let a_var = var_store.fresh(); let actual = Type::Function( vec![Type::EmptyRec], Box::new(Type::Variable(closure_var)), From 8b291854d300ac3c750231b6c405b3ace945fcf7 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Sun, 24 Apr 2022 12:48:37 -0400 Subject: [PATCH 542/846] Improve alias<->opaque unification logic --- compiler/solve/tests/solve_expr.rs | 23 +++- compiler/unify/src/unify.rs | 182 ++++++++++++++++++++--------- 2 files changed, 148 insertions(+), 57 deletions(-) diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index 2411b13df5..57ffaf6766 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -5759,13 +5759,13 @@ mod solve_expr { r#" app "test" provides [ effectAlways ] to "./platform" - Effect a : [ @Effect ({} -> a) ] + Effect a := {} -> a effectAlways : a -> Effect a effectAlways = \x -> inner = \{} -> x - @Effect inner + $Effect inner "# ), r#"a -> Effect a"#, @@ -6211,4 +6211,23 @@ mod solve_expr { indoc!(r#"Expr -> Expr"#), ) } + + #[test] + fn opaque_and_alias_unify() { + infer_eq_without_problem( + indoc!( + r#" + app "test" provides [ always ] to "./platform" + + Effect a := {} -> a + + Task a err : Effect (Result a err) + + always : a -> Task a * + always = \x -> $Effect (\{} -> Ok x) + "# + ), + "a -> Task a *", + ); + } } diff --git a/compiler/unify/src/unify.rs b/compiler/unify/src/unify.rs index 88bf2456ca..ce62039db3 100644 --- a/compiler/unify/src/unify.rs +++ b/compiler/unify/src/unify.rs @@ -358,8 +358,11 @@ fn unify_context(subs: &mut Subs, pool: &mut Pool, ctx: Context) -> Outcome { Structure(flat_type) => { unify_structure(subs, pool, &ctx, flat_type, &ctx.second_desc.content) } - Alias(symbol, args, real_var, kind) => { - unify_alias(subs, pool, &ctx, *symbol, *args, *real_var, *kind) + Alias(symbol, args, real_var, AliasKind::Structural) => { + unify_alias(subs, pool, &ctx, *symbol, *args, *real_var) + } + Alias(symbol, args, real_var, AliasKind::Opaque) => { + unify_opaque(subs, pool, &ctx, *symbol, *args, *real_var) } &RangedNumber(typ, range_vars) => unify_ranged_number(subs, pool, &ctx, typ, range_vars), Error => { @@ -448,6 +451,56 @@ fn check_valid_range( } } +#[inline(always)] +fn unify_two_aliases( + subs: &mut Subs, + pool: &mut Pool, + ctx: &Context, + symbol: Symbol, + args: AliasVariables, + real_var: Variable, + other_args: AliasVariables, + other_real_var: Variable, + other_content: &Content, +) -> Outcome { + if args.len() == other_args.len() { + let mut outcome = Outcome::default(); + let it = args + .all_variables() + .into_iter() + .zip(other_args.all_variables().into_iter()); + + let args_unification_snapshot = subs.snapshot(); + + for (l, r) in it { + let l_var = subs[l]; + let r_var = subs[r]; + outcome.union(unify_pool(subs, pool, l_var, r_var, ctx.mode)); + } + + if outcome.mismatches.is_empty() { + outcome.union(merge(subs, ctx, *other_content)); + } + + let args_unification_had_changes = !subs + .vars_since_snapshot(&args_unification_snapshot) + .is_empty(); + subs.commit_snapshot(args_unification_snapshot); + + if !args.is_empty() && args_unification_had_changes && outcome.mismatches.is_empty() { + // We need to unify the real vars because unification of type variables + // may have made them larger, which then needs to be reflected in the `real_var`. + outcome.union(unify_pool(subs, pool, real_var, other_real_var, ctx.mode)); + } + + outcome + } else { + dbg!(args.len(), other_args.len()); + mismatch!("{:?}", symbol) + } +} + +// Unifies a structural alias #[inline(always)] fn unify_alias( subs: &mut Subs, @@ -456,72 +509,40 @@ fn unify_alias( symbol: Symbol, args: AliasVariables, real_var: Variable, - kind: AliasKind, ) -> Outcome { let other_content = &ctx.second_desc.content; - let either_is_opaque = - kind == AliasKind::Opaque || matches!(other_content, Alias(_, _, _, AliasKind::Opaque)); + let kind = AliasKind::Structural; match other_content { FlexVar(_) => { // Alias wins merge(subs, ctx, Alias(symbol, args, real_var, kind)) } - RecursionVar { structure, .. } if !either_is_opaque => { - unify_pool(subs, pool, real_var, *structure, ctx.mode) + RecursionVar { structure, .. } => unify_pool(subs, pool, real_var, *structure, ctx.mode), + RigidVar(_) | RigidAbleVar(..) | FlexAbleVar(..) => { + unify_pool(subs, pool, real_var, ctx.second, ctx.mode) } - RigidVar(_) | RigidAbleVar(..) => unify_pool(subs, pool, real_var, ctx.second, ctx.mode), - FlexAbleVar(_, ability) if kind == AliasKind::Opaque && args.is_empty() => { - // Opaque type wins - let mut outcome = merge(subs, ctx, Alias(symbol, args, real_var, kind)); - outcome.must_implement_ability.push(MustImplementAbility { typ: symbol, ability: *ability }); - outcome - } - Alias(other_symbol, other_args, other_real_var, _) - // Opaques types are only equal if the opaque symbols are equal! - if !either_is_opaque || symbol == *other_symbol => - { + Alias(_, _, _, AliasKind::Opaque) => unify_pool(subs, pool, real_var, ctx.second, ctx.mode), + Alias(other_symbol, other_args, other_real_var, AliasKind::Structural) => { if symbol == *other_symbol { - if args.len() == other_args.len() { - let mut outcome = Outcome::default(); - let it = args - .all_variables() - .into_iter() - .zip(other_args.all_variables().into_iter()); - - let args_unification_snapshot = subs.snapshot(); - - for (l, r) in it { - let l_var = subs[l]; - let r_var = subs[r]; - outcome.union(unify_pool(subs, pool, l_var, r_var, ctx.mode)); - } - - if outcome.mismatches.is_empty() { - outcome.union(merge(subs, ctx, *other_content)); - } - - let args_unification_had_changes = !subs.vars_since_snapshot(&args_unification_snapshot).is_empty(); - subs.commit_snapshot(args_unification_snapshot); - - if !args.is_empty() && args_unification_had_changes && outcome.mismatches.is_empty() { - // We need to unify the real vars because unification of type variables - // may have made them larger, which then needs to be reflected in the `real_var`. - outcome.union(unify_pool(subs, pool, real_var, *other_real_var, ctx.mode)); - } - - outcome - } else { - dbg!(args.len(), other_args.len()); - mismatch!("{:?}", symbol) - } + unify_two_aliases( + subs, + pool, + ctx, + symbol, + args, + real_var, + *other_args, + *other_real_var, + other_content, + ) } else { unify_pool(subs, pool, real_var, *other_real_var, ctx.mode) } } - Structure(_) if !either_is_opaque => unify_pool(subs, pool, real_var, ctx.second, ctx.mode), - RangedNumber(other_real_var, other_range_vars) if !either_is_opaque => { + Structure(_) => unify_pool(subs, pool, real_var, ctx.second, ctx.mode), + RangedNumber(other_real_var, other_range_vars) => { let outcome = unify_pool(subs, pool, real_var, *other_real_var, ctx.mode); if outcome.mismatches.is_empty() { check_valid_range(subs, pool, real_var, *other_range_vars, ctx.mode) @@ -530,9 +551,60 @@ fn unify_alias( } } Error => merge(subs, ctx, Error), + } +} + +#[inline(always)] +fn unify_opaque( + subs: &mut Subs, + pool: &mut Pool, + ctx: &Context, + symbol: Symbol, + args: AliasVariables, + real_var: Variable, +) -> Outcome { + let other_content = &ctx.second_desc.content; + + let kind = AliasKind::Opaque; + + match other_content { + FlexVar(_) => { + // Alias wins + merge(subs, ctx, Alias(symbol, args, real_var, kind)) + } + RigidVar(_) | RigidAbleVar(..) => unify_pool(subs, pool, real_var, ctx.second, ctx.mode), + FlexAbleVar(_, ability) if args.is_empty() => { + // Opaque type wins + let mut outcome = merge(subs, ctx, Alias(symbol, args, real_var, kind)); + outcome.must_implement_ability.push(MustImplementAbility { + typ: symbol, + ability: *ability, + }); + outcome + } + Alias(_, _, other_real_var, AliasKind::Structural) => { + unify_pool(subs, pool, ctx.first, *other_real_var, ctx.mode) + } + Alias(other_symbol, other_args, other_real_var, AliasKind::Opaque) => { + // Opaques types are only equal if the opaque symbols are equal! + if symbol == *other_symbol { + unify_two_aliases( + subs, + pool, + ctx, + symbol, + args, + real_var, + *other_args, + *other_real_var, + other_content, + ) + } else { + mismatch!("{:?}", symbol) + } + } other => { - // The type on the left is an alias, but the one on the right is not! - debug_assert!(either_is_opaque); + // The type on the left is an opaque, but the one on the right is not! mismatch!("Cannot unify opaque {:?} with {:?}", symbol, other) } } From e543dd4fe6f33967ef814db49192b0d53a0c8544 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Sun, 24 Apr 2022 13:01:35 -0400 Subject: [PATCH 543/846] Bugfix test gen --- compiler/test_gen/src/gen_primitives.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/test_gen/src/gen_primitives.rs b/compiler/test_gen/src/gen_primitives.rs index 9611df0cc6..0657eb4715 100644 --- a/compiler/test_gen/src/gen_primitives.rs +++ b/compiler/test_gen/src/gen_primitives.rs @@ -1939,7 +1939,7 @@ fn alias_of_alias_with_type_arguments() { r#" app "test" provides [ main ] to "./platform" - Effect a := {} -> a + Effect a := a Task a err : Effect (Result a err) From 23bbe0863b88f4ee3c952486d55ede96cd1e0e30 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Sun, 24 Apr 2022 14:47:07 -0400 Subject: [PATCH 544/846] Fix effect module --- compiler/can/src/effect_module.rs | 77 ++++++++++++++++--------------- compiler/can/src/module.rs | 10 ++-- compiler/types/src/subs.rs | 11 ++++- reporting/src/report.rs | 3 +- 4 files changed, 56 insertions(+), 45 deletions(-) diff --git a/compiler/can/src/effect_module.rs b/compiler/can/src/effect_module.rs index e9036c4bb7..5d673ace45 100644 --- a/compiler/can/src/effect_module.rs +++ b/compiler/can/src/effect_module.rs @@ -978,7 +978,7 @@ fn build_effect_forever_inner_body( build_fresh_opaque_variables(var_store, introduced_variables); let pattern = Pattern::UnwrappedOpaque { whole_var, - opaque: effect, + opaque: effect_symbol, argument: Box::new((thunk_var, Loc::at_zero(Pattern::Identifier(thunk1_symbol)))), specialized_def_type, type_arguments, @@ -1405,7 +1405,7 @@ pub fn build_host_exposed_def( scope: &mut Scope, symbol: Symbol, ident: &str, - effect_tag_name: TagName, + effect_symbol: Symbol, var_store: &mut VarStore, annotation: crate::annotation::Annotation, ) -> Def { @@ -1418,8 +1418,15 @@ pub fn build_host_exposed_def( let mut linked_symbol_arguments: Vec<(Variable, Expr)> = Vec::new(); let mut captured_symbols: Vec<(Symbol, Variable)> = Vec::new(); + let crate::annotation::Annotation { + mut introduced_variables, + typ, + aliases, + .. + } = annotation; + let def_body = { - match annotation.typ.shallow_dealias() { + match typ.shallow_dealias() { Type::Function(args, _, _) => { for i in 0..args.len() { let name = format!("closure_arg_{}_{}", ident, i); @@ -1480,11 +1487,15 @@ pub fn build_host_exposed_def( loc_body: Box::new(Loc::at_zero(low_level_call)), }); - let body = Expr::Tag { - variant_var: var_store.fresh(), - ext_var: var_store.fresh(), - name: effect_tag_name, - arguments: vec![(var_store.fresh(), Loc::at_zero(effect_closure))], + let (specialized_def_type, type_arguments, lambda_set_variables) = + build_fresh_opaque_variables(var_store, &mut introduced_variables); + let body = Expr::OpaqueRef { + opaque_var: var_store.fresh(), + name: effect_symbol, + argument: Box::new((var_store.fresh(), Loc::at_zero(effect_closure))), + specialized_def_type, + type_arguments, + lambda_set_variables, }; Expr::Closure(ClosureData { @@ -1541,20 +1552,24 @@ pub fn build_host_exposed_def( loc_body: Box::new(Loc::at_zero(low_level_call)), }); - Expr::Tag { - variant_var: var_store.fresh(), - ext_var: var_store.fresh(), - name: effect_tag_name, - arguments: vec![(var_store.fresh(), Loc::at_zero(effect_closure))], + let (specialized_def_type, type_arguments, lambda_set_variables) = + build_fresh_opaque_variables(var_store, &mut introduced_variables); + Expr::OpaqueRef { + opaque_var: var_store.fresh(), + name: effect_symbol, + argument: Box::new((var_store.fresh(), Loc::at_zero(effect_closure))), + specialized_def_type, + type_arguments, + lambda_set_variables, } } } }; let def_annotation = crate::def::Annotation { - signature: annotation.typ, - introduced_variables: annotation.introduced_variables, - aliases: annotation.aliases, + signature: typ, + introduced_variables, + aliases, region: Region::zero(), }; @@ -1567,6 +1582,16 @@ pub fn build_host_exposed_def( } } +pub fn build_effect_actual(effect_symbol: Symbol, a_type: Type, var_store: &mut VarStore) -> Type { + let closure_var = var_store.fresh(); + + Type::Function( + vec![Type::EmptyRec], + Box::new(Type::Variable(closure_var)), + Box::new(a_type), + ) +} + /// Effect a := {} -> a fn build_effect_opaque( effect_symbol: Symbol, @@ -1615,26 +1640,6 @@ fn build_fresh_opaque_variables( (Box::new(actual), type_arguments, lambda_set_variables) } -pub fn build_effect_actual( - effect_tag_name: TagName, - a_type: Type, - var_store: &mut VarStore, -) -> Type { - let closure_var = var_store.fresh(); - - Type::TagUnion( - vec![( - effect_tag_name, - vec![Type::Function( - vec![Type::EmptyRec], - Box::new(Type::Variable(closure_var)), - Box::new(a_type), - )], - )], - TypeExtension::Closed, - ) -} - #[inline(always)] fn empty_record_pattern(var_store: &mut VarStore) -> Pattern { Pattern::RecordDestructure { diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index b34aba4fc5..2265dd3742 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -8,8 +8,8 @@ use crate::pattern::Pattern; use crate::scope::Scope; use bumpalo::Bump; use roc_collections::{MutMap, SendMap, VecSet}; +use roc_module::ident::Ident; use roc_module::ident::Lowercase; -use roc_module::ident::{Ident, TagName}; use roc_module::symbol::{IdentIds, ModuleId, ModuleIds, Symbol}; use roc_parse::ast; use roc_parse::header::HeaderFor; @@ -116,13 +116,11 @@ impl GeneratedInfo { ) .unwrap(); - let effect_tag_name = TagName::Private(effect_symbol); - { let a_var = var_store.fresh(); let actual = crate::effect_module::build_effect_actual( - effect_tag_name, + effect_symbol, Type::Variable(a_var), var_store, ); @@ -132,7 +130,7 @@ impl GeneratedInfo { Region::zero(), vec![Loc::at_zero(("a".into(), a_var))], actual, - AliasKind::Structural, + AliasKind::Opaque, ); } @@ -433,7 +431,7 @@ pub fn canonicalize_module_defs<'a>( &mut scope, *symbol, &ident, - TagName::Private(effect_symbol), + effect_symbol, var_store, annotation, ); diff --git a/compiler/types/src/subs.rs b/compiler/types/src/subs.rs index 97a9bf67e9..2952861071 100644 --- a/compiler/types/src/subs.rs +++ b/compiler/types/src/subs.rs @@ -845,9 +845,16 @@ fn subs_fmt_flat_type(this: &FlatType, subs: &Subs, f: &mut fmt::Formatter) -> f for var in slice { write!( f, - "<{:?}>{:?} ", + "<{:?}>{} ", var, - SubsFmtContent(subs.get_content_without_compacting(*var), subs) + if var.index() == 304 { + format!("{}", "*304") + } else { + format!( + "{:?}", + SubsFmtContent(subs.get_content_without_compacting(*var), subs) + ) + } )?; } write!(f, ", ")?; diff --git a/reporting/src/report.rs b/reporting/src/report.rs index 2f26a35c75..d0d8b95bdc 100644 --- a/reporting/src/report.rs +++ b/reporting/src/report.rs @@ -387,7 +387,8 @@ impl<'a> RocDocAllocator<'a> { match tn { TagName::Global(uppercase) => self.global_tag_name(uppercase), TagName::Private(symbol) => self.private_tag_name(symbol), - TagName::Closure(_symbol) => unreachable!("closure tags are internal only"), + TagName::Closure(symbol) => self.private_tag_name(symbol), + // TagName::Closure(_symbol) => unreachable!("closure tags are internal only"), } } From cc507f3abde046575eaedf7e56fb5e48a60923cf Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Sun, 24 Apr 2022 14:51:24 -0400 Subject: [PATCH 545/846] Revert "Mark introduced variables" This reverts commit 02038ea8bf525021f05061e4296749b01a4b9346. --- compiler/can/src/annotation.rs | 2 +- compiler/can/src/effect_module.rs | 76 ++++++++++--------------------- 2 files changed, 26 insertions(+), 52 deletions(-) diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index f24742a784..b6bdff3e87 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -125,7 +125,7 @@ impl IntroducedVariables { self.inferred.push(var); } - pub fn insert_lambda_set(&mut self, var: Variable) { + fn insert_lambda_set(&mut self, var: Variable) { self.debug_assert_not_already_present(var); self.lambda_sets.push(var); } diff --git a/compiler/can/src/effect_module.rs b/compiler/can/src/effect_module.rs index 5d673ace45..a9fb43e0b7 100644 --- a/compiler/can/src/effect_module.rs +++ b/compiler/can/src/effect_module.rs @@ -167,13 +167,11 @@ fn build_effect_always( }) }; - let mut introduced_variables = IntroducedVariables::default(); - // \value -> $Effect \{} -> value let (function_var, always_closure) = { // `$Effect \{} -> value` let (specialized_def_type, type_arguments, lambda_set_variables) = - build_fresh_opaque_variables(var_store, &mut introduced_variables); + build_fresh_opaque_variables(var_store); let body = Expr::OpaqueRef { opaque_var: var_store.fresh(), name: effect_symbol, @@ -204,6 +202,8 @@ fn build_effect_always( (function_var, closure) }; + let mut introduced_variables = IntroducedVariables::default(); + let signature = { // Effect.always : a -> Effect a let var_a = var_store.fresh(); @@ -327,8 +327,6 @@ fn build_effect_map( .unwrap() }; - let mut introduced_variables = IntroducedVariables::default(); - // \{} -> mapper (thunk {}) let inner_closure = { let arguments = vec![( @@ -354,7 +352,7 @@ fn build_effect_map( // \$Effect thunk, mapper let (specialized_def_type, type_arguments, lambda_set_variables) = - build_fresh_opaque_variables(var_store, &mut introduced_variables); + build_fresh_opaque_variables(var_store); let arguments = vec![ ( var_store.fresh(), @@ -378,7 +376,7 @@ fn build_effect_map( // `$Effect \{} -> (mapper (thunk {}))` let (specialized_def_type, type_arguments, lambda_set_variables) = - build_fresh_opaque_variables(var_store, &mut introduced_variables); + build_fresh_opaque_variables(var_store); let body = Expr::OpaqueRef { opaque_var: var_store.fresh(), name: effect_symbol, @@ -401,6 +399,8 @@ fn build_effect_map( loc_body: Box::new(Loc::at_zero(body)), }); + let mut introduced_variables = IntroducedVariables::default(); + let signature = { // Effect.map : Effect a, (a -> b) -> Effect b let var_a = var_store.fresh(); @@ -534,10 +534,8 @@ fn build_effect_after( Expr::Call(Box::new(boxed), arguments, CalledVia::Space) }; - let mut introduced_variables = IntroducedVariables::default(); - let (specialized_def_type, type_arguments, lambda_set_variables) = - build_fresh_opaque_variables(var_store, &mut introduced_variables); + build_fresh_opaque_variables(var_store); let arguments = vec![ ( @@ -573,6 +571,8 @@ fn build_effect_after( loc_body: Box::new(Loc::at_zero(to_effect_call)), }); + let mut introduced_variables = IntroducedVariables::default(); + let signature = { let var_a = var_store.fresh(); let var_b = var_store.fresh(); @@ -643,7 +643,6 @@ fn wrap_in_effect_thunk( closure_name: Symbol, captured_symbols: Vec, var_store: &mut VarStore, - introduced_variables: &mut IntroducedVariables, ) -> Expr { let captured_symbols: Vec<_> = captured_symbols .into_iter() @@ -673,7 +672,7 @@ fn wrap_in_effect_thunk( // `$Effect \{} -> value` let (specialized_def_type, type_arguments, lambda_set_variables) = - build_fresh_opaque_variables(var_store, introduced_variables); + build_fresh_opaque_variables(var_store); Expr::OpaqueRef { opaque_var: var_store.fresh(), name: effect_symbol, @@ -690,14 +689,13 @@ fn force_effect( effect_symbol: Symbol, thunk_symbol: Symbol, var_store: &mut VarStore, - introduced_variables: &mut IntroducedVariables, ) -> Expr { let whole_var = var_store.fresh(); let thunk_var = var_store.fresh(); let (specialized_def_type, type_arguments, lambda_set_variables) = - build_fresh_opaque_variables(var_store, introduced_variables); + build_fresh_opaque_variables(var_store); let pattern = Pattern::UnwrappedOpaque { whole_var, opaque: effect_symbol, @@ -813,17 +811,8 @@ fn build_effect_forever( .unwrap() }; - let mut introduced_variables = IntroducedVariables::default(); - - let body = build_effect_forever_body( - env, - scope, - effect_symbol, - forever_symbol, - effect, - var_store, - &mut introduced_variables, - ); + let body = + build_effect_forever_body(env, scope, effect_symbol, forever_symbol, effect, var_store); let arguments = vec![(var_store.fresh(), Loc::at_zero(Pattern::Identifier(effect)))]; @@ -840,6 +829,8 @@ fn build_effect_forever( loc_body: Box::new(Loc::at_zero(body)), }); + let mut introduced_variables = IntroducedVariables::default(); + let signature = { let var_a = var_store.fresh(); let var_b = var_store.fresh(); @@ -903,7 +894,6 @@ fn build_effect_forever_body( forever_symbol: Symbol, effect: Symbol, var_store: &mut VarStore, - introduced_variables: &mut IntroducedVariables, ) -> Expr { let closure_name = { scope @@ -923,7 +913,6 @@ fn build_effect_forever_body( forever_symbol, effect, var_store, - introduced_variables, ); let captured_symbols = vec![effect]; @@ -933,7 +922,6 @@ fn build_effect_forever_body( closure_name, captured_symbols, var_store, - introduced_variables, ) } @@ -944,7 +932,6 @@ fn build_effect_forever_inner_body( forever_symbol: Symbol, effect: Symbol, var_store: &mut VarStore, - introduced_variables: &mut IntroducedVariables, ) -> Expr { let thunk1_symbol = { scope @@ -975,7 +962,7 @@ fn build_effect_forever_inner_body( let thunk_var = var_store.fresh(); let (specialized_def_type, type_arguments, lambda_set_variables) = - build_fresh_opaque_variables(var_store, introduced_variables); + build_fresh_opaque_variables(var_store); let pattern = Pattern::UnwrappedOpaque { whole_var, opaque: effect_symbol, @@ -1043,7 +1030,6 @@ fn build_effect_forever_inner_body( effect_symbol, thunk2_symbol, var_store, - introduced_variables, )); Expr::LetNonRec( @@ -1067,8 +1053,6 @@ fn build_effect_loop( let state_symbol = new_symbol!(scope, env, "state"); let step_symbol = new_symbol!(scope, env, "step"); - let mut introduced_variables = IntroducedVariables::default(); - let body = build_effect_loop_body( env, scope, @@ -1077,7 +1061,6 @@ fn build_effect_loop( state_symbol, step_symbol, var_store, - &mut introduced_variables, ); let arguments = vec![ @@ -1104,6 +1087,8 @@ fn build_effect_loop( loc_body: Box::new(Loc::at_zero(body)), }); + let mut introduced_variables = IntroducedVariables::default(); + let signature = { let var_a = var_store.fresh(); let var_b = var_store.fresh(); @@ -1202,7 +1187,6 @@ fn build_effect_loop_body( state_symbol: Symbol, step_symbol: Symbol, var_store: &mut VarStore, - introduced_variables: &mut IntroducedVariables, ) -> Expr { let closure_name = { scope @@ -1223,7 +1207,6 @@ fn build_effect_loop_body( state_symbol, step_symbol, var_store, - introduced_variables, ); let captured_symbols = vec![state_symbol, step_symbol]; @@ -1233,7 +1216,6 @@ fn build_effect_loop_body( closure_name, captured_symbols, var_store, - introduced_variables, ) } @@ -1267,7 +1249,6 @@ fn build_effect_loop_inner_body( state_symbol: Symbol, step_symbol: Symbol, var_store: &mut VarStore, - introduced_variables: &mut IntroducedVariables, ) -> Expr { let thunk1_symbol = new_symbol!(scope, env, "thunk3"); let thunk2_symbol = new_symbol!(scope, env, "thunk4"); @@ -1282,7 +1263,7 @@ fn build_effect_loop_inner_body( let thunk_var = var_store.fresh(); let (specialized_def_type, type_arguments, lambda_set_variables) = - build_fresh_opaque_variables(var_store, introduced_variables); + build_fresh_opaque_variables(var_store); let pattern = Pattern::UnwrappedOpaque { whole_var, opaque: effect_symbol, @@ -1352,13 +1333,7 @@ fn build_effect_loop_inner_body( // $Effect thunk2 = loop effect // thunk2 {} // ``` - let force_thunk2 = force_effect( - loop_new_state_step, - effect_symbol, - thunk2_symbol, - var_store, - introduced_variables, - ); + let force_thunk2 = force_effect(loop_new_state_step, effect_symbol, thunk2_symbol, var_store); let step_branch = { let step_tag_name = TagName::Global("Step".into()); @@ -1602,7 +1577,7 @@ fn build_effect_opaque( introduced_variables: &mut IntroducedVariables, ) -> Type { let closure_var = var_store.fresh(); - introduced_variables.insert_lambda_set(closure_var); + introduced_variables.insert_wildcard(Loc::at_zero(closure_var)); let actual = Type::Function( vec![Type::EmptyRec], @@ -1621,14 +1596,13 @@ fn build_effect_opaque( fn build_fresh_opaque_variables( var_store: &mut VarStore, - introduced_variables: &mut IntroducedVariables, ) -> (Box, Vec<(Lowercase, Type)>, Vec) { - let a_var = var_store.fresh(); let closure_var = var_store.fresh(); - introduced_variables.insert_named("a".into(), Loc::at_zero(a_var)); - introduced_variables.insert_lambda_set(closure_var); + // NB: if there are bugs, check whether not introducing variables is a problem! + // introduced_variables.insert_wildcard(Loc::at_zero(closure_var)); + let a_var = var_store.fresh(); let actual = Type::Function( vec![Type::EmptyRec], Box::new(Type::Variable(closure_var)), From caf65ba2f80a07e3d4ec2761acae7410d3148788 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Sun, 24 Apr 2022 15:08:26 -0400 Subject: [PATCH 546/846] Fix codegen of effect symbols --- compiler/can/src/effect_module.rs | 10 +++++----- compiler/can/src/module.rs | 7 ++----- compiler/types/src/types.rs | 13 +++++++++++++ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/compiler/can/src/effect_module.rs b/compiler/can/src/effect_module.rs index a9fb43e0b7..484f0fc223 100644 --- a/compiler/can/src/effect_module.rs +++ b/compiler/can/src/effect_module.rs @@ -1394,14 +1394,14 @@ pub fn build_host_exposed_def( let mut captured_symbols: Vec<(Symbol, Variable)> = Vec::new(); let crate::annotation::Annotation { - mut introduced_variables, + introduced_variables, typ, aliases, .. } = annotation; let def_body = { - match typ.shallow_dealias() { + match typ.shallow_structural_dealias() { Type::Function(args, _, _) => { for i in 0..args.len() { let name = format!("closure_arg_{}_{}", ident, i); @@ -1463,7 +1463,7 @@ pub fn build_host_exposed_def( }); let (specialized_def_type, type_arguments, lambda_set_variables) = - build_fresh_opaque_variables(var_store, &mut introduced_variables); + build_fresh_opaque_variables(var_store); let body = Expr::OpaqueRef { opaque_var: var_store.fresh(), name: effect_symbol, @@ -1528,7 +1528,7 @@ pub fn build_host_exposed_def( }); let (specialized_def_type, type_arguments, lambda_set_variables) = - build_fresh_opaque_variables(var_store, &mut introduced_variables); + build_fresh_opaque_variables(var_store); Expr::OpaqueRef { opaque_var: var_store.fresh(), name: effect_symbol, @@ -1557,7 +1557,7 @@ pub fn build_host_exposed_def( } } -pub fn build_effect_actual(effect_symbol: Symbol, a_type: Type, var_store: &mut VarStore) -> Type { +pub fn build_effect_actual(a_type: Type, var_store: &mut VarStore) -> Type { let closure_var = var_store.fresh(); Type::Function( diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index 2265dd3742..30340b701c 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -119,11 +119,8 @@ impl GeneratedInfo { { let a_var = var_store.fresh(); - let actual = crate::effect_module::build_effect_actual( - effect_symbol, - Type::Variable(a_var), - var_store, - ); + let actual = + crate::effect_module::build_effect_actual(Type::Variable(a_var), var_store); scope.add_alias( effect_symbol, diff --git a/compiler/types/src/types.rs b/compiler/types/src/types.rs index 53b78b5d59..5f83801336 100644 --- a/compiler/types/src/types.rs +++ b/compiler/types/src/types.rs @@ -1064,6 +1064,19 @@ impl Type { result } + pub fn shallow_structural_dealias(&self) -> &Self { + let mut result = self; + while let Type::Alias { + actual, + kind: AliasKind::Structural, + .. + } = result + { + result = actual; + } + result + } + pub fn instantiate_aliases( &mut self, region: Region, From f5b0b0219eb5c2465933c7b8b7cb0810b680ac54 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Sun, 24 Apr 2022 15:12:02 -0400 Subject: [PATCH 547/846] Remove hack --- compiler/types/src/subs.rs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/compiler/types/src/subs.rs b/compiler/types/src/subs.rs index 2952861071..97a9bf67e9 100644 --- a/compiler/types/src/subs.rs +++ b/compiler/types/src/subs.rs @@ -845,16 +845,9 @@ fn subs_fmt_flat_type(this: &FlatType, subs: &Subs, f: &mut fmt::Formatter) -> f for var in slice { write!( f, - "<{:?}>{} ", + "<{:?}>{:?} ", var, - if var.index() == 304 { - format!("{}", "*304") - } else { - format!( - "{:?}", - SubsFmtContent(subs.get_content_without_compacting(*var), subs) - ) - } + SubsFmtContent(subs.get_content_without_compacting(*var), subs) )?; } write!(f, ", ")?; From 969d14dfe93603211005dd4b0365b121ccd7b418 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Sun, 24 Apr 2022 15:18:44 -0400 Subject: [PATCH 548/846] I love 50 arguments --- compiler/unify/src/unify.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/unify/src/unify.rs b/compiler/unify/src/unify.rs index ce62039db3..044ff301fe 100644 --- a/compiler/unify/src/unify.rs +++ b/compiler/unify/src/unify.rs @@ -452,6 +452,7 @@ fn check_valid_range( } #[inline(always)] +#[allow(clippy::too_many_arguments)] fn unify_two_aliases( subs: &mut Subs, pool: &mut Pool, From b6383f81eedebaa7afc56399f4ed059e2957565a Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Mon, 25 Apr 2022 10:58:20 -0400 Subject: [PATCH 549/846] Numbers are opaques --- ast/src/constrain.rs | 50 +-- compiler/builtins/docs/Num.roc | 32 +- compiler/builtins/roc/Num.roc | 34 +- compiler/builtins/src/bitcode.rs | 38 +- compiler/can/src/scope.rs | 10 +- compiler/constrain/src/builtins.rs | 89 ++--- compiler/load_internal/src/file.rs | 86 ++--- compiler/module/src/symbol.rs | 531 +++++++++++++------------- compiler/mono/src/ir.rs | 4 +- compiler/mono/src/layout.rs | 257 ++++++------- compiler/mono/src/layout_soa.rs | 6 +- compiler/solve/src/solve.rs | 149 ++------ compiler/types/src/builtin_aliases.rs | 99 +++-- compiler/types/src/solved_types.rs | 1 + compiler/types/src/subs.rs | 251 ++---------- compiler/unify/src/unify.rs | 28 +- repl_eval/src/eval.rs | 96 +---- reporting/src/error/type.rs | 12 +- 18 files changed, 684 insertions(+), 1089 deletions(-) diff --git a/ast/src/constrain.rs b/ast/src/constrain.rs index 8b53fea88a..09526fb902 100644 --- a/ast/src/constrain.rs +++ b/ast/src/constrain.rs @@ -1895,17 +1895,7 @@ fn num_float(pool: &mut Pool, range: TypeId) -> Type2 { fn num_floatingpoint(pool: &mut Pool, range: TypeId) -> Type2 { let range_type = pool.get(range); - let alias_content = Type2::TagUnion( - PoolVec::new( - vec![( - TagName::Private(Symbol::NUM_AT_FLOATINGPOINT), - PoolVec::new(vec![range_type.shallow_clone()].into_iter(), pool), - )] - .into_iter(), - pool, - ), - pool.add(Type2::EmptyTagUnion), - ); + let alias_content = range_type.shallow_clone(); Type2::Alias( Symbol::NUM_FLOATINGPOINT, @@ -1931,22 +1921,10 @@ fn num_int(pool: &mut Pool, range: TypeId) -> Type2 { #[inline(always)] fn _num_signed64(pool: &mut Pool) -> Type2 { - let alias_content = Type2::TagUnion( - PoolVec::new( - vec![( - TagName::Private(Symbol::NUM_AT_SIGNED64), - PoolVec::empty(pool), - )] - .into_iter(), - pool, - ), - pool.add(Type2::EmptyTagUnion), - ); - Type2::Alias( Symbol::NUM_SIGNED64, PoolVec::empty(pool), - pool.add(alias_content), + pool.add(Type2::EmptyTagUnion), ) } @@ -1974,17 +1952,7 @@ fn num_unsigned32(pool: &mut Pool) -> Type2 { fn _num_integer(pool: &mut Pool, range: TypeId) -> Type2 { let range_type = pool.get(range); - let alias_content = Type2::TagUnion( - PoolVec::new( - vec![( - TagName::Private(Symbol::NUM_AT_INTEGER), - PoolVec::new(vec![range_type.shallow_clone()].into_iter(), pool), - )] - .into_iter(), - pool, - ), - pool.add(Type2::EmptyTagUnion), - ); + let alias_content = range_type.shallow_clone(); Type2::Alias( Symbol::NUM_INTEGER, @@ -1997,17 +1965,7 @@ fn _num_integer(pool: &mut Pool, range: TypeId) -> Type2 { fn num_num(pool: &mut Pool, type_id: TypeId) -> Type2 { let range_type = pool.get(type_id); - let alias_content = Type2::TagUnion( - PoolVec::new( - vec![( - TagName::Private(Symbol::NUM_AT_NUM), - PoolVec::new(vec![range_type.shallow_clone()].into_iter(), pool), - )] - .into_iter(), - pool, - ), - pool.add(Type2::EmptyTagUnion), - ); + let alias_content = range_type.shallow_clone(); Type2::Alias( Symbol::NUM_NUM, diff --git a/compiler/builtins/docs/Num.roc b/compiler/builtins/docs/Num.roc index 75fce0db60..f9174c1bbc 100644 --- a/compiler/builtins/docs/Num.roc +++ b/compiler/builtins/docs/Num.roc @@ -189,7 +189,7 @@ interface Num ## ## In practice, these are rarely needed. It's most common to write ## number literals without any suffix. -Num a : [ @Num a ] +Num a := a ## A decimal number. ## @@ -223,7 +223,7 @@ Num a : [ @Num a ] ## [Dec] typically takes slightly less time than [F64] to perform addition and ## subtraction, but 10-20 times longer to perform multiplication and division. ## [sqrt] and trigonometry are massively slower with [Dec] than with [F64]. -Dec : Float [ @Decimal128 ] +Dec : Num (FloatingPoint Decimal) ## A fixed-size number with a fractional component. ## @@ -292,7 +292,7 @@ Dec : Float [ @Decimal128 ] ## loops and conditionals. If you need to do performance-critical trigonometry ## or square roots, either [F64] or [F32] is probably a better choice than the ## usual default choice of [Dec], despite the precision problems they bring. -Float a : Num [ @Fraction a ] +Float range : Num (FloatingPoint range) ## A fixed-size integer - that is, a number with no fractional component. ## @@ -343,19 +343,19 @@ Float a : Num [ @Fraction a ] ## * Start by deciding if this integer should allow negative numbers, and choose signed or unsigned accordingly. ## * Next, think about the range of numbers you expect this number to hold. Choose the smallest size you will never expect to overflow, no matter the inputs your program receives. (Validating inputs for size, and presenting the user with an error if they are too big, can help guard against overflow.) ## * Finally, if a particular numeric calculation is running too slowly, you can try experimenting with other number sizes. This rarely makes a meaningful difference, but some processors can operate on different number sizes at different speeds. -Int size : Num [ @Integer size ] +Int range : Num (Integer range) ## A signed 8-bit integer, ranging from -128 to 127 -I8 : Int [ @Signed8 ] -U8 : Int [ @Unsigned8 ] -I16 : Int [ @Signed16 ] -U16 : Int [ @Unsigned16 ] -I32 : Int [ @Signed32 ] -U32 : Int [ @Unsigned32 ] -I64 : Int [ @Signed64 ] -U64 : Int [ @Unsigned64 ] -I128 : Int [ @Signed128 ] -U128 : Int [ @Unsigned128 ] +I8 : Int Signed8 +U8 : Int Unsigned8 +I16 : Int Signed16 +U16 : Int Unsigned16 +I32 : Int Signed32 +U32 : Int Unsigned32 +I64 : Int Signed64 +U64 : Int Unsigned64 +I128 : Int Signed128 +U128 : Int Unsigned128 ## A [natural number](https://en.wikipedia.org/wiki/Natural_number) represented ## as a 64-bit unsigned integer on 64-bit systems, a 32-bit unsigned integer @@ -367,7 +367,7 @@ U128 : Int [ @Unsigned128 ] ## a [List] can hold on a 64-bit system fits in a 64-bit unsigned integer, and ## on a 32-bit system it fits in 32-bit unsigned integer. This makes [Nat] a ## good fit for [List.len] regardless of system. -Nat : Int [ @Natural ] +Nat : Num (Integer Natural) ## A 64-bit signed integer. All number literals without decimal points are compatible with #Int values. ## @@ -443,7 +443,7 @@ Nat : Int [ @Natural ] ## ## As such, it's very important to design your code not to exceed these bounds! ## If you need to do math outside these bounds, consider using a larger numeric size. -Int size : Num [ @Int size ] +Int range : Num (Integer range) ## Convert diff --git a/compiler/builtins/roc/Num.roc b/compiler/builtins/roc/Num.roc index 23512eb953..dc0c1a7bd7 100644 --- a/compiler/builtins/roc/Num.roc +++ b/compiler/builtins/roc/Num.roc @@ -158,25 +158,25 @@ interface Num Bool.{ Bool } ] -Num range : [ @Num range ] +Num range := range Int range : Num (Integer range) Float range : Num (FloatingPoint range) -Signed128 : [ @Signed128 ] -Signed64 : [ @Signed64 ] -Signed32 : [ @Signed32 ] -Signed16 : [ @Signed16 ] -Signed8 : [ @Signed8 ] +Signed128 := [] +Signed64 := [] +Signed32 := [] +Signed16 := [] +Signed8 := [] -Unsigned128 : [ @Unsigned128 ] -Unsigned64 : [ @Unsigned64 ] -Unsigned32 : [ @Unsigned32 ] -Unsigned16 : [ @Unsigned16 ] -Unsigned8 : [ @Unsigned8 ] +Unsigned128 := [] +Unsigned64 := [] +Unsigned32 := [] +Unsigned16 := [] +Unsigned8 := [] -Natural : [ @Natural ] +Natural := [] -Integer range : [ @Integer range ] +Integer range := range I128 : Num (Integer Signed128) I64 : Num (Integer Signed64) @@ -192,11 +192,11 @@ U8 : Num (Integer Unsigned8) Nat : Num (Integer Natural) -Decimal : [ @Decimal ] -Binary64 : [ @Binary64 ] -Binary32 : [ @Binary32 ] +Decimal := [] +Binary64 := [] +Binary32 := [] -FloatingPoint range : [ @FloatingPoint range ] +FloatingPoint range := range F64 : Num (FloatingPoint Binary64) F32 : Num (FloatingPoint Binary32) diff --git a/compiler/builtins/src/bitcode.rs b/compiler/builtins/src/bitcode.rs index 70cb7e86d6..6299e5cd35 100644 --- a/compiler/builtins/src/bitcode.rs +++ b/compiler/builtins/src/bitcode.rs @@ -68,13 +68,9 @@ impl FloatWidth { pub const fn try_from_symbol(symbol: Symbol) -> Option { match symbol { - Symbol::NUM_F64 | Symbol::NUM_BINARY64 | Symbol::NUM_AT_BINARY64 => { - Some(FloatWidth::F64) - } + Symbol::NUM_F64 | Symbol::NUM_BINARY64 => Some(FloatWidth::F64), - Symbol::NUM_F32 | Symbol::NUM_BINARY32 | Symbol::NUM_AT_BINARY32 => { - Some(FloatWidth::F32) - } + Symbol::NUM_F32 | Symbol::NUM_BINARY32 => Some(FloatWidth::F32), _ => None, } @@ -136,26 +132,16 @@ impl IntWidth { pub const fn try_from_symbol(symbol: Symbol) -> Option { match symbol { - Symbol::NUM_I128 | Symbol::NUM_SIGNED128 | Symbol::NUM_AT_SIGNED128 => { - Some(IntWidth::I128) - } - Symbol::NUM_I64 | Symbol::NUM_SIGNED64 | Symbol::NUM_AT_SIGNED64 => Some(IntWidth::I64), - Symbol::NUM_I32 | Symbol::NUM_SIGNED32 | Symbol::NUM_AT_SIGNED32 => Some(IntWidth::I32), - Symbol::NUM_I16 | Symbol::NUM_SIGNED16 | Symbol::NUM_AT_SIGNED16 => Some(IntWidth::I16), - Symbol::NUM_I8 | Symbol::NUM_SIGNED8 | Symbol::NUM_AT_SIGNED8 => Some(IntWidth::I8), - Symbol::NUM_U128 | Symbol::NUM_UNSIGNED128 | Symbol::NUM_AT_UNSIGNED128 => { - Some(IntWidth::U128) - } - Symbol::NUM_U64 | Symbol::NUM_UNSIGNED64 | Symbol::NUM_AT_UNSIGNED64 => { - Some(IntWidth::U64) - } - Symbol::NUM_U32 | Symbol::NUM_UNSIGNED32 | Symbol::NUM_AT_UNSIGNED32 => { - Some(IntWidth::U32) - } - Symbol::NUM_U16 | Symbol::NUM_UNSIGNED16 | Symbol::NUM_AT_UNSIGNED16 => { - Some(IntWidth::U16) - } - Symbol::NUM_U8 | Symbol::NUM_UNSIGNED8 | Symbol::NUM_AT_UNSIGNED8 => Some(IntWidth::U8), + Symbol::NUM_I128 | Symbol::NUM_SIGNED128 => Some(IntWidth::I128), + Symbol::NUM_I64 | Symbol::NUM_SIGNED64 => Some(IntWidth::I64), + Symbol::NUM_I32 | Symbol::NUM_SIGNED32 => Some(IntWidth::I32), + Symbol::NUM_I16 | Symbol::NUM_SIGNED16 => Some(IntWidth::I16), + Symbol::NUM_I8 | Symbol::NUM_SIGNED8 => Some(IntWidth::I8), + Symbol::NUM_U128 | Symbol::NUM_UNSIGNED128 => Some(IntWidth::U128), + Symbol::NUM_U64 | Symbol::NUM_UNSIGNED64 => Some(IntWidth::U64), + Symbol::NUM_U32 | Symbol::NUM_UNSIGNED32 => Some(IntWidth::U32), + Symbol::NUM_U16 | Symbol::NUM_UNSIGNED16 => Some(IntWidth::U16), + Symbol::NUM_U8 | Symbol::NUM_UNSIGNED8 => Some(IntWidth::U8), _ => None, } } diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index 76a08d276a..e2bdd50d20 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -36,7 +36,12 @@ fn add_aliases(var_store: &mut VarStore) -> SendMap { let mut aliases = SendMap::default(); for (symbol, builtin_alias) in solved_aliases { - let BuiltinAlias { region, vars, typ } = builtin_alias; + let BuiltinAlias { + region, + vars, + typ, + kind, + } = builtin_alias; let mut free_vars = FreeVars::default(); let typ = roc_types::solved_types::to_type(&typ, &mut free_vars, var_store); @@ -55,8 +60,7 @@ fn add_aliases(var_store: &mut VarStore) -> SendMap { lambda_set_variables: Vec::new(), recursion_variables: MutSet::default(), type_variables: variables, - // TODO(opaques): replace when opaques are included in the stdlib - kind: AliasKind::Structural, + kind, }; aliases.insert(symbol, alias); diff --git a/compiler/constrain/src/builtins.rs b/compiler/constrain/src/builtins.rs index 86a812aa64..dcabe649ab 100644 --- a/compiler/constrain/src/builtins.rs +++ b/compiler/constrain/src/builtins.rs @@ -2,13 +2,13 @@ use arrayvec::ArrayVec; use roc_can::constraint::{Constraint, Constraints}; use roc_can::expected::Expected::{self, *}; use roc_can::num::{FloatBound, FloatWidth, IntBound, IntWidth, NumericBound, SignDemand}; -use roc_module::ident::{Lowercase, TagName}; +use roc_module::ident::Lowercase; use roc_module::symbol::Symbol; use roc_region::all::Region; use roc_types::subs::Variable; +use roc_types::types::Reason; use roc_types::types::Type::{self, *}; use roc_types::types::{AliasKind, Category}; -use roc_types::types::{Reason, TypeExtension}; #[must_use] #[inline(always)] @@ -163,14 +163,14 @@ fn builtin_alias( symbol: Symbol, type_arguments: Vec<(Lowercase, Type)>, actual: Box, + kind: AliasKind, ) -> Type { Type::Alias { symbol, type_arguments, actual, lambda_set_variables: vec![], - // TODO(opaques): revisit later - kind: AliasKind::Structural, + kind, } } @@ -180,49 +180,48 @@ pub fn num_float(range: Type) -> Type { Symbol::NUM_FLOAT, vec![("range".into(), range.clone())], Box::new(num_num(num_floatingpoint(range))), + AliasKind::Structural, ) } #[inline(always)] pub fn num_floatingpoint(range: Type) -> Type { - let alias_content = Type::TagUnion( - vec![( - TagName::Private(Symbol::NUM_AT_FLOATINGPOINT), - vec![range.clone()], - )], - TypeExtension::Closed, - ); - builtin_alias( Symbol::NUM_FLOATINGPOINT, - vec![("range".into(), range)], - Box::new(alias_content), + vec![("range".into(), range.clone())], + Box::new(range), + AliasKind::Opaque, ) } #[inline(always)] pub fn num_u32() -> Type { - builtin_alias(Symbol::NUM_U32, vec![], Box::new(num_int(num_unsigned32()))) + builtin_alias( + Symbol::NUM_U32, + vec![], + Box::new(num_int(num_unsigned32())), + AliasKind::Structural, + ) } #[inline(always)] fn num_unsigned32() -> Type { - let alias_content = Type::TagUnion( - vec![(TagName::Private(Symbol::NUM_AT_UNSIGNED32), vec![])], - TypeExtension::Closed, - ); - - builtin_alias(Symbol::NUM_UNSIGNED32, vec![], Box::new(alias_content)) + builtin_alias( + Symbol::NUM_UNSIGNED32, + vec![], + Box::new(Type::EmptyTagUnion), + AliasKind::Opaque, + ) } #[inline(always)] pub fn num_binary64() -> Type { - let alias_content = Type::TagUnion( - vec![(TagName::Private(Symbol::NUM_AT_BINARY64), vec![])], - TypeExtension::Closed, - ); - - builtin_alias(Symbol::NUM_BINARY64, vec![], Box::new(alias_content)) + builtin_alias( + Symbol::NUM_BINARY64, + vec![], + Box::new(Type::EmptyTagUnion), + AliasKind::Opaque, + ) } #[inline(always)] @@ -231,47 +230,37 @@ pub fn num_int(range: Type) -> Type { Symbol::NUM_INT, vec![("range".into(), range.clone())], Box::new(num_num(num_integer(range))), + AliasKind::Structural, ) } #[inline(always)] pub fn num_signed64() -> Type { - let alias_content = Type::TagUnion( - vec![(TagName::Private(Symbol::NUM_AT_SIGNED64), vec![])], - TypeExtension::Closed, - ); - - builtin_alias(Symbol::NUM_SIGNED64, vec![], Box::new(alias_content)) + builtin_alias( + Symbol::NUM_SIGNED64, + vec![], + Box::new(Type::EmptyTagUnion), + AliasKind::Opaque, + ) } #[inline(always)] pub fn num_integer(range: Type) -> Type { - let alias_content = Type::TagUnion( - vec![( - TagName::Private(Symbol::NUM_AT_INTEGER), - vec![range.clone()], - )], - TypeExtension::Closed, - ); - builtin_alias( Symbol::NUM_INTEGER, - vec![("range".into(), range)], - Box::new(alias_content), + vec![("range".into(), range.clone())], + Box::new(range), + AliasKind::Opaque, ) } #[inline(always)] pub fn num_num(typ: Type) -> Type { - let alias_content = Type::TagUnion( - vec![(TagName::Private(Symbol::NUM_AT_NUM), vec![typ.clone()])], - TypeExtension::Closed, - ); - builtin_alias( Symbol::NUM_NUM, - vec![("range".into(), typ)], - Box::new(alias_content), + vec![("range".into(), typ.clone())], + Box::new(typ), + AliasKind::Opaque, ) } diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index 4af83a07c8..6fcb0785ae 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -39,7 +39,7 @@ use roc_solve::solve; use roc_target::TargetInfo; use roc_types::solved_types::Solved; use roc_types::subs::{Subs, VarStore, Variable}; -use roc_types::types::{Alias, AliasCommon, TypeExtension}; +use roc_types::types::{Alias, AliasCommon, AliasKind, TypeExtension}; use std::collections::hash_map::Entry::{Occupied, Vacant}; use std::collections::HashMap; use std::io; @@ -4715,50 +4715,35 @@ fn default_aliases() -> roc_solve::solve::Aliases { let mut var_store = VarStore::default(); + // Num range := range { let symbol = Symbol::NUM_NUM; let tvar = var_store.fresh(); - let typ = Type::TagUnion( - vec![( - TagName::Private(Symbol::NUM_AT_NUM), - vec![Type::Variable(tvar)], - )], - TypeExtension::Closed, - ); - let alias = Alias { region: Region::zero(), type_variables: vec![Loc::at_zero(("range".into(), tvar))], lambda_set_variables: Default::default(), recursion_variables: Default::default(), - typ, + typ: Type::Variable(tvar), kind: roc_types::types::AliasKind::Structural, }; solve_aliases.insert(symbol, alias); } - // FloatingPoint range : [ @FloatingPoint range ] + // FloatingPoint range := [] { let symbol = Symbol::NUM_FLOATINGPOINT; let tvar = var_store.fresh(); - let typ = Type::TagUnion( - vec![( - TagName::Private(Symbol::NUM_AT_FLOATINGPOINT), - vec![Type::Variable(tvar)], - )], - TypeExtension::Closed, - ); - let alias = Alias { region: Region::zero(), type_variables: vec![Loc::at_zero(("range".into(), tvar))], lambda_set_variables: Default::default(), recursion_variables: Default::default(), - typ, - kind: roc_types::types::AliasKind::Structural, + typ: Type::Variable(tvar), + kind: roc_types::types::AliasKind::Opaque, }; solve_aliases.insert(symbol, alias); @@ -4773,11 +4758,13 @@ fn default_aliases() -> roc_solve::solve::Aliases { symbol: Symbol::NUM_NUM, type_arguments: vec![( "range".into(), - Type::DelayedAlias(AliasCommon { + Type::Alias { symbol: Symbol::NUM_INTEGER, type_arguments: vec![("range".into(), Type::Variable(tvar))], lambda_set_variables: vec![], - }), + actual: Box::new(Type::Variable(tvar)), + kind: AliasKind::Opaque, + }, )], lambda_set_variables: vec![], }); @@ -4794,6 +4781,7 @@ fn default_aliases() -> roc_solve::solve::Aliases { solve_aliases.insert(symbol, alias); } + // Float range : Num (FloatingPoint range) { let symbol = Symbol::NUM_FLOAT; let tvar = var_store.fresh(); @@ -4802,11 +4790,13 @@ fn default_aliases() -> roc_solve::solve::Aliases { symbol: Symbol::NUM_NUM, type_arguments: vec![( "range".into(), - Type::DelayedAlias(AliasCommon { + Type::Alias { symbol: Symbol::NUM_FLOATINGPOINT, type_arguments: vec![("range".into(), Type::Variable(tvar))], lambda_set_variables: vec![], - }), + actual: Box::new(Type::Variable(tvar)), + kind: AliasKind::Opaque, + }, )], lambda_set_variables: vec![], }); @@ -4823,24 +4813,17 @@ fn default_aliases() -> roc_solve::solve::Aliases { solve_aliases.insert(symbol, alias); } + // Integer range := range { let symbol = Symbol::NUM_INTEGER; let tvar = var_store.fresh(); - let typ = Type::TagUnion( - vec![( - TagName::Private(Symbol::NUM_AT_INTEGER), - vec![Type::Variable(tvar)], - )], - TypeExtension::Closed, - ); - let alias = Alias { region: Region::zero(), type_variables: vec![Loc::at_zero(("range".into(), tvar))], lambda_set_variables: Default::default(), recursion_variables: Default::default(), - typ, + typ: Type::Variable(tvar), kind: roc_types::types::AliasKind::Structural, }; @@ -4875,38 +4858,33 @@ fn default_aliases() -> roc_solve::solve::Aliases { solve_aliases.insert(symbol, alias); } - let mut unit_function = |alias_name: Symbol, at_tag_name: Symbol| { - let typ = Type::TagUnion( - vec![(TagName::Private(at_tag_name), vec![])], - TypeExtension::Closed, - ); - + let mut zero_opaque = |alias_name: Symbol| { let alias = Alias { region: Region::zero(), type_variables: vec![], lambda_set_variables: Default::default(), recursion_variables: Default::default(), - typ, - kind: roc_types::types::AliasKind::Structural, + typ: Type::EmptyTagUnion, + kind: AliasKind::Opaque, }; solve_aliases.insert(alias_name, alias); }; - unit_function(Symbol::NUM_SIGNED8, Symbol::NUM_AT_SIGNED8); - unit_function(Symbol::NUM_SIGNED16, Symbol::NUM_AT_SIGNED16); - unit_function(Symbol::NUM_SIGNED32, Symbol::NUM_AT_SIGNED32); - unit_function(Symbol::NUM_SIGNED64, Symbol::NUM_AT_SIGNED64); - unit_function(Symbol::NUM_SIGNED128, Symbol::NUM_AT_SIGNED128); + zero_opaque(Symbol::NUM_SIGNED8); + zero_opaque(Symbol::NUM_SIGNED16); + zero_opaque(Symbol::NUM_SIGNED32); + zero_opaque(Symbol::NUM_SIGNED64); + zero_opaque(Symbol::NUM_SIGNED128); - unit_function(Symbol::NUM_UNSIGNED8, Symbol::NUM_AT_UNSIGNED8); - unit_function(Symbol::NUM_UNSIGNED16, Symbol::NUM_AT_UNSIGNED16); - unit_function(Symbol::NUM_UNSIGNED32, Symbol::NUM_AT_UNSIGNED32); - unit_function(Symbol::NUM_UNSIGNED64, Symbol::NUM_AT_UNSIGNED64); - unit_function(Symbol::NUM_UNSIGNED128, Symbol::NUM_AT_UNSIGNED128); + zero_opaque(Symbol::NUM_UNSIGNED8); + zero_opaque(Symbol::NUM_UNSIGNED16); + zero_opaque(Symbol::NUM_UNSIGNED32); + zero_opaque(Symbol::NUM_UNSIGNED64); + zero_opaque(Symbol::NUM_UNSIGNED128); - unit_function(Symbol::NUM_BINARY32, Symbol::NUM_AT_BINARY32); - unit_function(Symbol::NUM_BINARY64, Symbol::NUM_AT_BINARY64); + zero_opaque(Symbol::NUM_BINARY32); + zero_opaque(Symbol::NUM_BINARY64); solve_aliases } diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index d0aabc2964..391a31600d 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -907,160 +907,143 @@ define_builtins! { } 1 NUM: "Num" => { 0 NUM_NUM: "Num" // the Num.Num type alias - 1 NUM_AT_NUM: "@Num" // the Num.@Num private tag - 2 NUM_I128: "I128" // the Num.I128 type alias - 3 NUM_U128: "U128" // the Num.U128 type alias - 4 NUM_I64: "I64" // the Num.I64 type alias - 5 NUM_U64: "U64" // the Num.U64 type alias - 6 NUM_I32: "I32" // the Num.I32 type alias - 7 NUM_U32: "U32" // the Num.U32 type alias - 8 NUM_I16: "I16" // the Num.I16 type alias - 9 NUM_U16: "U16" // the Num.U16 type alias - 10 NUM_I8: "I8" // the Num.I8 type alias - 11 NUM_U8: "U8" // the Num.U8 type alias - 12 NUM_INTEGER: "Integer" // Int : Num Integer - 13 NUM_AT_INTEGER: "@Integer" // the Int.@Integer private tag - 14 NUM_F64: "F64" // the Num.F64 type alias - 15 NUM_F32: "F32" // the Num.F32 type alias - 16 NUM_FLOATINGPOINT: "FloatingPoint" // Float : Num FloatingPoint - 17 NUM_AT_FLOATINGPOINT: "@FloatingPoint" // the Float.@FloatingPoint private tag - 18 NUM_MAX_FLOAT: "maxFloat" - 19 NUM_MIN_FLOAT: "minFloat" - 20 NUM_ABS: "abs" - 21 NUM_NEG: "neg" - 22 NUM_ADD: "add" - 23 NUM_SUB: "sub" - 24 NUM_MUL: "mul" - 25 NUM_LT: "isLt" - 26 NUM_LTE: "isLte" - 27 NUM_GT: "isGt" - 28 NUM_GTE: "isGte" - 29 NUM_TO_FLOAT: "toFloat" - 30 NUM_SIN: "sin" - 31 NUM_COS: "cos" - 32 NUM_TAN: "tan" - 33 NUM_IS_ZERO: "isZero" - 34 NUM_IS_EVEN: "isEven" - 35 NUM_IS_ODD: "isOdd" - 36 NUM_IS_POSITIVE: "isPositive" - 37 NUM_IS_NEGATIVE: "isNegative" - 38 NUM_REM: "rem" - 39 NUM_REM_CHECKED: "remChecked" - 40 NUM_DIV_FLOAT: "div" - 41 NUM_DIV_FLOAT_CHECKED: "divChecked" - 42 NUM_DIV_TRUNC: "divTrunc" - 43 NUM_DIV_TRUNC_CHECKED: "divTruncChecked" - 44 NUM_SQRT: "sqrt" - 45 NUM_SQRT_CHECKED: "sqrtChecked" - 46 NUM_LOG: "log" - 47 NUM_LOG_CHECKED: "logChecked" - 48 NUM_ROUND: "round" - 49 NUM_COMPARE: "compare" - 50 NUM_POW: "pow" - 51 NUM_CEILING: "ceiling" - 52 NUM_POW_INT: "powInt" - 53 NUM_FLOOR: "floor" - 54 NUM_ADD_WRAP: "addWrap" - 55 NUM_ADD_CHECKED: "addChecked" - 56 NUM_ADD_SATURATED: "addSaturated" - 57 NUM_ATAN: "atan" - 58 NUM_ACOS: "acos" - 59 NUM_ASIN: "asin" - 60 NUM_AT_SIGNED128: "@Signed128" - 61 NUM_SIGNED128: "Signed128" - 62 NUM_AT_SIGNED64: "@Signed64" - 63 NUM_SIGNED64: "Signed64" - 64 NUM_AT_SIGNED32: "@Signed32" - 65 NUM_SIGNED32: "Signed32" - 66 NUM_AT_SIGNED16: "@Signed16" - 67 NUM_SIGNED16: "Signed16" - 68 NUM_AT_SIGNED8: "@Signed8" - 69 NUM_SIGNED8: "Signed8" - 70 NUM_AT_UNSIGNED128: "@Unsigned128" - 71 NUM_UNSIGNED128: "Unsigned128" - 72 NUM_AT_UNSIGNED64: "@Unsigned64" - 73 NUM_UNSIGNED64: "Unsigned64" - 74 NUM_AT_UNSIGNED32: "@Unsigned32" - 75 NUM_UNSIGNED32: "Unsigned32" - 76 NUM_AT_UNSIGNED16: "@Unsigned16" - 77 NUM_UNSIGNED16: "Unsigned16" - 78 NUM_AT_UNSIGNED8: "@Unsigned8" - 79 NUM_UNSIGNED8: "Unsigned8" - 80 NUM_AT_BINARY64: "@Binary64" - 81 NUM_BINARY64: "Binary64" - 82 NUM_AT_BINARY32: "@Binary32" - 83 NUM_BINARY32: "Binary32" - 84 NUM_BITWISE_AND: "bitwiseAnd" - 85 NUM_BITWISE_XOR: "bitwiseXor" - 86 NUM_BITWISE_OR: "bitwiseOr" - 87 NUM_SHIFT_LEFT: "shiftLeftBy" - 88 NUM_SHIFT_RIGHT: "shiftRightBy" - 89 NUM_SHIFT_RIGHT_ZERO_FILL: "shiftRightZfBy" - 90 NUM_SUB_WRAP: "subWrap" - 91 NUM_SUB_CHECKED: "subChecked" - 92 NUM_SUB_SATURATED: "subSaturated" - 93 NUM_MUL_WRAP: "mulWrap" - 94 NUM_MUL_CHECKED: "mulChecked" - 95 NUM_INT: "Int" - 96 NUM_FLOAT: "Float" - 97 NUM_AT_NATURAL: "@Natural" - 98 NUM_NATURAL: "Natural" - 99 NUM_NAT: "Nat" - 100 NUM_INT_CAST: "intCast" - 101 NUM_IS_MULTIPLE_OF: "isMultipleOf" - 102 NUM_AT_DECIMAL: "@Decimal" - 103 NUM_DECIMAL: "Decimal" - 104 NUM_DEC: "Dec" // the Num.Dectype alias - 105 NUM_BYTES_TO_U16: "bytesToU16" - 106 NUM_BYTES_TO_U32: "bytesToU32" - 107 NUM_CAST_TO_NAT: "#castToNat" - 108 NUM_DIV_CEIL: "divCeil" - 109 NUM_DIV_CEIL_CHECKED: "divCeilChecked" - 110 NUM_TO_STR: "toStr" - 111 NUM_MIN_I8: "minI8" - 112 NUM_MAX_I8: "maxI8" - 113 NUM_MIN_U8: "minU8" - 114 NUM_MAX_U8: "maxU8" - 115 NUM_MIN_I16: "minI16" - 116 NUM_MAX_I16: "maxI16" - 117 NUM_MIN_U16: "minU16" - 118 NUM_MAX_U16: "maxU16" - 119 NUM_MIN_I32: "minI32" - 120 NUM_MAX_I32: "maxI32" - 121 NUM_MIN_U32: "minU32" - 122 NUM_MAX_U32: "maxU32" - 123 NUM_MIN_I64: "minI64" - 124 NUM_MAX_I64: "maxI64" - 125 NUM_MIN_U64: "minU64" - 126 NUM_MAX_U64: "maxU64" - 127 NUM_MIN_I128: "minI128" - 128 NUM_MAX_I128: "maxI128" - 129 NUM_TO_I8: "toI8" - 130 NUM_TO_I8_CHECKED: "toI8Checked" - 131 NUM_TO_I16: "toI16" - 132 NUM_TO_I16_CHECKED: "toI16Checked" - 133 NUM_TO_I32: "toI32" - 134 NUM_TO_I32_CHECKED: "toI32Checked" - 135 NUM_TO_I64: "toI64" - 136 NUM_TO_I64_CHECKED: "toI64Checked" - 137 NUM_TO_I128: "toI128" - 138 NUM_TO_I128_CHECKED: "toI128Checked" - 139 NUM_TO_U8: "toU8" - 140 NUM_TO_U8_CHECKED: "toU8Checked" - 141 NUM_TO_U16: "toU16" - 142 NUM_TO_U16_CHECKED: "toU16Checked" - 143 NUM_TO_U32: "toU32" - 144 NUM_TO_U32_CHECKED: "toU32Checked" - 145 NUM_TO_U64: "toU64" - 146 NUM_TO_U64_CHECKED: "toU64Checked" - 147 NUM_TO_U128: "toU128" - 148 NUM_TO_U128_CHECKED: "toU128Checked" - 149 NUM_TO_NAT: "toNat" - 150 NUM_TO_NAT_CHECKED: "toNatChecked" - 151 NUM_TO_F32: "toF32" - 152 NUM_TO_F32_CHECKED: "toF32Checked" - 153 NUM_TO_F64: "toF64" - 154 NUM_TO_F64_CHECKED: "toF64Checked" + 1 NUM_I128: "I128" // the Num.I128 type alias + 2 NUM_U128: "U128" // the Num.U128 type alias + 3 NUM_I64: "I64" // the Num.I64 type alias + 4 NUM_U64: "U64" // the Num.U64 type alias + 5 NUM_I32: "I32" // the Num.I32 type alias + 6 NUM_U32: "U32" // the Num.U32 type alias + 7 NUM_I16: "I16" // the Num.I16 type alias + 8 NUM_U16: "U16" // the Num.U16 type alias + 9 NUM_I8: "I8" // the Num.I8 type alias + 10 NUM_U8: "U8" // the Num.U8 type alias + 11 NUM_INTEGER: "Integer" // Int : Num Integer + 12 NUM_F64: "F64" // the Num.F64 type alias + 13 NUM_F32: "F32" // the Num.F32 type alias + 14 NUM_FLOATINGPOINT: "FloatingPoint" // Float : Num FloatingPoint + 15 NUM_MAX_FLOAT: "maxFloat" + 16 NUM_MIN_FLOAT: "minFloat" + 17 NUM_ABS: "abs" + 18 NUM_NEG: "neg" + 19 NUM_ADD: "add" + 20 NUM_SUB: "sub" + 21 NUM_MUL: "mul" + 22 NUM_LT: "isLt" + 23 NUM_LTE: "isLte" + 24 NUM_GT: "isGt" + 25 NUM_GTE: "isGte" + 26 NUM_TO_FLOAT: "toFloat" + 27 NUM_SIN: "sin" + 28 NUM_COS: "cos" + 29 NUM_TAN: "tan" + 30 NUM_IS_ZERO: "isZero" + 31 NUM_IS_EVEN: "isEven" + 32 NUM_IS_ODD: "isOdd" + 33 NUM_IS_POSITIVE: "isPositive" + 34 NUM_IS_NEGATIVE: "isNegative" + 35 NUM_REM: "rem" + 36 NUM_REM_CHECKED: "remChecked" + 37 NUM_DIV_FLOAT: "div" + 38 NUM_DIV_FLOAT_CHECKED: "divChecked" + 39 NUM_DIV_TRUNC: "divTrunc" + 40 NUM_DIV_TRUNC_CHECKED: "divTruncChecked" + 41 NUM_SQRT: "sqrt" + 42 NUM_SQRT_CHECKED: "sqrtChecked" + 43 NUM_LOG: "log" + 44 NUM_LOG_CHECKED: "logChecked" + 45 NUM_ROUND: "round" + 46 NUM_COMPARE: "compare" + 47 NUM_POW: "pow" + 48 NUM_CEILING: "ceiling" + 49 NUM_POW_INT: "powInt" + 50 NUM_FLOOR: "floor" + 51 NUM_ADD_WRAP: "addWrap" + 52 NUM_ADD_CHECKED: "addChecked" + 53 NUM_ADD_SATURATED: "addSaturated" + 54 NUM_ATAN: "atan" + 55 NUM_ACOS: "acos" + 56 NUM_ASIN: "asin" + 57 NUM_SIGNED128: "Signed128" + 58 NUM_SIGNED64: "Signed64" + 59 NUM_SIGNED32: "Signed32" + 60 NUM_SIGNED16: "Signed16" + 61 NUM_SIGNED8: "Signed8" + 62 NUM_UNSIGNED128: "Unsigned128" + 63 NUM_UNSIGNED64: "Unsigned64" + 64 NUM_UNSIGNED32: "Unsigned32" + 65 NUM_UNSIGNED16: "Unsigned16" + 66 NUM_UNSIGNED8: "Unsigned8" + 67 NUM_BINARY64: "Binary64" + 68 NUM_BINARY32: "Binary32" + 69 NUM_BITWISE_AND: "bitwiseAnd" + 70 NUM_BITWISE_XOR: "bitwiseXor" + 71 NUM_BITWISE_OR: "bitwiseOr" + 72 NUM_SHIFT_LEFT: "shiftLeftBy" + 73 NUM_SHIFT_RIGHT: "shiftRightBy" + 74 NUM_SHIFT_RIGHT_ZERO_FILL: "shiftRightZfBy" + 75 NUM_SUB_WRAP: "subWrap" + 76 NUM_SUB_CHECKED: "subChecked" + 77 NUM_SUB_SATURATED: "subSaturated" + 78 NUM_MUL_WRAP: "mulWrap" + 79 NUM_MUL_CHECKED: "mulChecked" + 80 NUM_INT: "Int" + 81 NUM_FLOAT: "Float" + 82 NUM_NATURAL: "Natural" + 83 NUM_NAT: "Nat" + 84 NUM_INT_CAST: "intCast" + 85 NUM_IS_MULTIPLE_OF: "isMultipleOf" + 86 NUM_DECIMAL: "Decimal" + 87 NUM_DEC: "Dec" // the Num.Dectype alias + 88 NUM_BYTES_TO_U16: "bytesToU16" + 89 NUM_BYTES_TO_U32: "bytesToU32" + 90 NUM_CAST_TO_NAT: "#castToNat" + 91 NUM_DIV_CEIL: "divCeil" + 92 NUM_DIV_CEIL_CHECKED: "divCeilChecked" + 93 NUM_TO_STR: "toStr" + 94 NUM_MIN_I8: "minI8" + 95 NUM_MAX_I8: "maxI8" + 96 NUM_MIN_U8: "minU8" + 97 NUM_MAX_U8: "maxU8" + 98 NUM_MIN_I16: "minI16" + 99 NUM_MAX_I16: "maxI16" + 100 NUM_MIN_U16: "minU16" + 101 NUM_MAX_U16: "maxU16" + 102 NUM_MIN_I32: "minI32" + 103 NUM_MAX_I32: "maxI32" + 104 NUM_MIN_U32: "minU32" + 105 NUM_MAX_U32: "maxU32" + 106 NUM_MIN_I64: "minI64" + 107 NUM_MAX_I64: "maxI64" + 108 NUM_MIN_U64: "minU64" + 109 NUM_MAX_U64: "maxU64" + 110 NUM_MIN_I128: "minI128" + 111 NUM_MAX_I128: "maxI128" + 112 NUM_TO_I8: "toI8" + 113 NUM_TO_I8_CHECKED: "toI8Checked" + 114 NUM_TO_I16: "toI16" + 115 NUM_TO_I16_CHECKED: "toI16Checked" + 116 NUM_TO_I32: "toI32" + 117 NUM_TO_I32_CHECKED: "toI32Checked" + 118 NUM_TO_I64: "toI64" + 119 NUM_TO_I64_CHECKED: "toI64Checked" + 120 NUM_TO_I128: "toI128" + 121 NUM_TO_I128_CHECKED: "toI128Checked" + 122 NUM_TO_U8: "toU8" + 123 NUM_TO_U8_CHECKED: "toU8Checked" + 124 NUM_TO_U16: "toU16" + 125 NUM_TO_U16_CHECKED: "toU16Checked" + 126 NUM_TO_U32: "toU32" + 127 NUM_TO_U32_CHECKED: "toU32Checked" + 128 NUM_TO_U64: "toU64" + 129 NUM_TO_U64_CHECKED: "toU64Checked" + 130 NUM_TO_U128: "toU128" + 131 NUM_TO_U128_CHECKED: "toU128Checked" + 132 NUM_TO_NAT: "toNat" + 133 NUM_TO_NAT_CHECKED: "toNatChecked" + 134 NUM_TO_F32: "toF32" + 135 NUM_TO_F32_CHECKED: "toF32Checked" + 136 NUM_TO_F64: "toF64" + 137 NUM_TO_F64_CHECKED: "toF64Checked" } 2 BOOL: "Bool" => { 0 BOOL_BOOL: "Bool" // the Bool.Bool type alias @@ -1077,101 +1060,99 @@ define_builtins! { } 3 STR: "Str" => { 0 STR_STR: "Str" imported // the Str.Str type alias - 1 STR_AT_STR: "@Str" // the Str.@Str private tag - 2 STR_IS_EMPTY: "isEmpty" - 3 STR_APPEND: "#append" // unused - 4 STR_CONCAT: "concat" - 5 STR_JOIN_WITH: "joinWith" - 6 STR_SPLIT: "split" - 7 STR_COUNT_GRAPHEMES: "countGraphemes" - 8 STR_STARTS_WITH: "startsWith" - 9 STR_ENDS_WITH: "endsWith" - 10 STR_FROM_UTF8: "fromUtf8" - 11 STR_UT8_PROBLEM: "Utf8Problem" // the Utf8Problem type alias - 12 STR_UT8_BYTE_PROBLEM: "Utf8ByteProblem" // the Utf8ByteProblem type alias - 13 STR_TO_UTF8: "toUtf8" - 14 STR_STARTS_WITH_CODE_PT: "startsWithCodePt" - 15 STR_ALIAS_ANALYSIS_STATIC: "#aliasAnalysisStatic" // string with the static lifetime - 16 STR_FROM_UTF8_RANGE: "fromUtf8Range" - 17 STR_REPEAT: "repeat" - 18 STR_TRIM: "trim" - 19 STR_TRIM_LEFT: "trimLeft" - 20 STR_TRIM_RIGHT: "trimRight" - 21 STR_TO_DEC: "toDec" - 22 STR_TO_F64: "toF64" - 23 STR_TO_F32: "toF32" - 24 STR_TO_NAT: "toNat" - 25 STR_TO_U128: "toU128" - 26 STR_TO_I128: "toI128" - 27 STR_TO_U64: "toU64" - 28 STR_TO_I64: "toI64" - 29 STR_TO_U32: "toU32" - 30 STR_TO_I32: "toI32" - 31 STR_TO_U16: "toU16" - 32 STR_TO_I16: "toI16" - 33 STR_TO_U8: "toU8" - 34 STR_TO_I8: "toI8" + 1 STR_IS_EMPTY: "isEmpty" + 2 STR_APPEND: "#append" // unused + 3 STR_CONCAT: "concat" + 4 STR_JOIN_WITH: "joinWith" + 5 STR_SPLIT: "split" + 6 STR_COUNT_GRAPHEMES: "countGraphemes" + 7 STR_STARTS_WITH: "startsWith" + 8 STR_ENDS_WITH: "endsWith" + 9 STR_FROM_UTF8: "fromUtf8" + 10 STR_UT8_PROBLEM: "Utf8Problem" // the Utf8Problem type alias + 11 STR_UT8_BYTE_PROBLEM: "Utf8ByteProblem" // the Utf8ByteProblem type alias + 12 STR_TO_UTF8: "toUtf8" + 13 STR_STARTS_WITH_CODE_PT: "startsWithCodePt" + 14 STR_ALIAS_ANALYSIS_STATIC: "#aliasAnalysisStatic" // string with the static lifetime + 15 STR_FROM_UTF8_RANGE: "fromUtf8Range" + 16 STR_REPEAT: "repeat" + 17 STR_TRIM: "trim" + 18 STR_TRIM_LEFT: "trimLeft" + 19 STR_TRIM_RIGHT: "trimRight" + 20 STR_TO_DEC: "toDec" + 21 STR_TO_F64: "toF64" + 22 STR_TO_F32: "toF32" + 23 STR_TO_NAT: "toNat" + 24 STR_TO_U128: "toU128" + 25 STR_TO_I128: "toI128" + 26 STR_TO_U64: "toU64" + 27 STR_TO_I64: "toI64" + 28 STR_TO_U32: "toU32" + 29 STR_TO_I32: "toI32" + 30 STR_TO_U16: "toU16" + 31 STR_TO_I16: "toI16" + 32 STR_TO_U8: "toU8" + 33 STR_TO_I8: "toI8" } 4 LIST: "List" => { 0 LIST_LIST: "List" imported // the List.List type alias - 1 LIST_AT_LIST: "@List" // the List.@List private tag - 2 LIST_IS_EMPTY: "isEmpty" - 3 LIST_GET: "get" - 4 LIST_SET: "set" - 5 LIST_APPEND: "append" - 6 LIST_MAP: "map" - 7 LIST_LEN: "len" - 8 LIST_WALK_BACKWARDS: "walkBackwards" - 9 LIST_CONCAT: "concat" - 10 LIST_FIRST: "first" - 11 LIST_SINGLE: "single" - 12 LIST_REPEAT: "repeat" - 13 LIST_REVERSE: "reverse" - 14 LIST_PREPEND: "prepend" - 15 LIST_JOIN: "join" - 16 LIST_KEEP_IF: "keepIf" - 17 LIST_CONTAINS: "contains" - 18 LIST_SUM: "sum" - 19 LIST_WALK: "walk" - 20 LIST_LAST: "last" - 21 LIST_KEEP_OKS: "keepOks" - 22 LIST_KEEP_ERRS: "keepErrs" - 23 LIST_MAP_WITH_INDEX: "mapWithIndex" - 24 LIST_MAP2: "map2" - 25 LIST_MAP3: "map3" - 26 LIST_PRODUCT: "product" - 27 LIST_WALK_UNTIL: "walkUntil" - 28 LIST_RANGE: "range" - 29 LIST_SORT_WITH: "sortWith" - 30 LIST_DROP: "drop" - 31 LIST_SWAP: "swap" - 32 LIST_DROP_AT: "dropAt" - 33 LIST_DROP_LAST: "dropLast" - 34 LIST_MIN: "min" - 35 LIST_MIN_LT: "#minlt" - 36 LIST_MAX: "max" - 37 LIST_MAX_GT: "#maxGt" - 38 LIST_MAP4: "map4" - 39 LIST_DROP_FIRST: "dropFirst" - 40 LIST_JOIN_MAP: "joinMap" - 41 LIST_JOIN_MAP_CONCAT: "#joinMapConcat" - 42 LIST_ANY: "any" - 43 LIST_TAKE_FIRST: "takeFirst" - 44 LIST_TAKE_LAST: "takeLast" - 45 LIST_FIND: "find" - 46 LIST_FIND_RESULT: "#find_result" // symbol used in the definition of List.find - 47 LIST_SUBLIST: "sublist" - 48 LIST_INTERSPERSE: "intersperse" - 49 LIST_INTERSPERSE_CLOS: "#intersperseClos" - 50 LIST_SPLIT: "split" - 51 LIST_SPLIT_CLOS: "#splitClos" - 52 LIST_ALL: "all" - 53 LIST_DROP_IF: "dropIf" - 54 LIST_DROP_IF_PREDICATE: "#dropIfPred" - 55 LIST_SORT_ASC: "sortAsc" - 56 LIST_SORT_DESC: "sortDesc" - 57 LIST_SORT_DESC_COMPARE: "#sortDescCompare" - 58 LIST_REPLACE: "replace" + 1 LIST_IS_EMPTY: "isEmpty" + 2 LIST_GET: "get" + 3 LIST_SET: "set" + 4 LIST_APPEND: "append" + 5 LIST_MAP: "map" + 6 LIST_LEN: "len" + 7 LIST_WALK_BACKWARDS: "walkBackwards" + 8 LIST_CONCAT: "concat" + 9 LIST_FIRST: "first" + 10 LIST_SINGLE: "single" + 11 LIST_REPEAT: "repeat" + 12 LIST_REVERSE: "reverse" + 13 LIST_PREPEND: "prepend" + 14 LIST_JOIN: "join" + 15 LIST_KEEP_IF: "keepIf" + 16 LIST_CONTAINS: "contains" + 17 LIST_SUM: "sum" + 18 LIST_WALK: "walk" + 19 LIST_LAST: "last" + 20 LIST_KEEP_OKS: "keepOks" + 21 LIST_KEEP_ERRS: "keepErrs" + 22 LIST_MAP_WITH_INDEX: "mapWithIndex" + 23 LIST_MAP2: "map2" + 24 LIST_MAP3: "map3" + 25 LIST_PRODUCT: "product" + 26 LIST_WALK_UNTIL: "walkUntil" + 27 LIST_RANGE: "range" + 28 LIST_SORT_WITH: "sortWith" + 29 LIST_DROP: "drop" + 30 LIST_SWAP: "swap" + 31 LIST_DROP_AT: "dropAt" + 32 LIST_DROP_LAST: "dropLast" + 33 LIST_MIN: "min" + 34 LIST_MIN_LT: "#minlt" + 35 LIST_MAX: "max" + 36 LIST_MAX_GT: "#maxGt" + 37 LIST_MAP4: "map4" + 38 LIST_DROP_FIRST: "dropFirst" + 39 LIST_JOIN_MAP: "joinMap" + 40 LIST_JOIN_MAP_CONCAT: "#joinMapConcat" + 41 LIST_ANY: "any" + 42 LIST_TAKE_FIRST: "takeFirst" + 43 LIST_TAKE_LAST: "takeLast" + 44 LIST_FIND: "find" + 45 LIST_FIND_RESULT: "#find_result" // symbol used in the definition of List.find + 46 LIST_SUBLIST: "sublist" + 47 LIST_INTERSPERSE: "intersperse" + 48 LIST_INTERSPERSE_CLOS: "#intersperseClos" + 49 LIST_SPLIT: "split" + 50 LIST_SPLIT_CLOS: "#splitClos" + 51 LIST_ALL: "all" + 52 LIST_DROP_IF: "dropIf" + 53 LIST_DROP_IF_PREDICATE: "#dropIfPred" + 54 LIST_SORT_ASC: "sortAsc" + 55 LIST_SORT_DESC: "sortDesc" + 56 LIST_SORT_DESC_COMPARE: "#sortDescCompare" + 57 LIST_REPLACE: "replace" } 5 RESULT: "Result" => { 0 RESULT_RESULT: "Result" // the Result.Result type alias @@ -1188,41 +1169,39 @@ define_builtins! { } 6 DICT: "Dict" => { 0 DICT_DICT: "Dict" imported // the Dict.Dict type alias - 1 DICT_AT_DICT: "@Dict" // the Dict.@Dict private tag - 2 DICT_EMPTY: "empty" - 3 DICT_SINGLE: "single" - 4 DICT_GET: "get" - 5 DICT_GET_RESULT: "#get_result" // symbol used in the definition of Dict.get - 6 DICT_WALK: "walk" - 7 DICT_INSERT: "insert" - 8 DICT_LEN: "len" + 1 DICT_EMPTY: "empty" + 2 DICT_SINGLE: "single" + 3 DICT_GET: "get" + 4 DICT_GET_RESULT: "#get_result" // symbol used in the definition of Dict.get + 5 DICT_WALK: "walk" + 6 DICT_INSERT: "insert" + 7 DICT_LEN: "len" - 9 DICT_REMOVE: "remove" - 10 DICT_CONTAINS: "contains" - 11 DICT_KEYS: "keys" - 12 DICT_VALUES: "values" + 8 DICT_REMOVE: "remove" + 9 DICT_CONTAINS: "contains" + 10 DICT_KEYS: "keys" + 11 DICT_VALUES: "values" - 13 DICT_UNION: "union" - 14 DICT_INTERSECTION: "intersection" - 15 DICT_DIFFERENCE: "difference" + 12 DICT_UNION: "union" + 13 DICT_INTERSECTION: "intersection" + 14 DICT_DIFFERENCE: "difference" } 7 SET: "Set" => { 0 SET_SET: "Set" imported // the Set.Set type alias - 1 SET_AT_SET: "@Set" // the Set.@Set private tag - 2 SET_EMPTY: "empty" - 3 SET_SINGLE: "single" - 4 SET_LEN: "len" - 5 SET_INSERT: "insert" - 6 SET_REMOVE: "remove" - 7 SET_UNION: "union" - 8 SET_DIFFERENCE: "difference" - 9 SET_INTERSECTION: "intersection" - 10 SET_TO_LIST: "toList" - 11 SET_FROM_LIST: "fromList" - 12 SET_WALK: "walk" - 13 SET_WALK_USER_FUNCTION: "#walk_user_function" - 14 SET_CONTAINS: "contains" - 15 SET_TO_DICT: "toDict" + 1 SET_EMPTY: "empty" + 2 SET_SINGLE: "single" + 3 SET_LEN: "len" + 4 SET_INSERT: "insert" + 5 SET_REMOVE: "remove" + 6 SET_UNION: "union" + 7 SET_DIFFERENCE: "difference" + 8 SET_INTERSECTION: "intersection" + 9 SET_TO_LIST: "toList" + 10 SET_FROM_LIST: "fromList" + 11 SET_WALK: "walk" + 12 SET_WALK_USER_FUNCTION: "#walk_user_function" + 13 SET_CONTAINS: "contains" + 14 SET_TO_DICT: "toDict" } 8 BOX: "Box" => { 0 BOX_BOX_TYPE: "Box" imported // the Box.Box opaque type diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 72b10cc7f5..2ed74c3735 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -8640,9 +8640,9 @@ pub fn num_argument_to_int_or_float( num_argument_to_int_or_float(subs, target_info, var, true) } - Symbol::NUM_DECIMAL | Symbol::NUM_AT_DECIMAL => IntOrFloat::DecimalFloatType, + Symbol::NUM_DECIMAL => IntOrFloat::DecimalFloatType, - Symbol::NUM_NAT | Symbol::NUM_NATURAL | Symbol::NUM_AT_NATURAL => { + Symbol::NUM_NAT | Symbol::NUM_NATURAL => { let int_width = match target_info.ptr_width() { roc_target::PtrWidth::Bytes4 => IntWidth::U32, roc_target::PtrWidth::Bytes8 => IntWidth::U64, diff --git a/compiler/mono/src/layout.rs b/compiler/mono/src/layout.rs index fd764f069d..008c2ddf85 100644 --- a/compiler/mono/src/layout.rs +++ b/compiler/mono/src/layout.rs @@ -983,6 +983,16 @@ pub const fn round_up_to_alignment(width: u32, alignment: u32) -> u32 { } } +#[inline(always)] +pub fn is_unresolved_var(subs: &Subs, var: Variable) -> bool { + use Content::*; + let content = subs.get_content_without_compacting(var); + matches!( + content, + FlexVar(..) | RigidVar(..) | FlexAbleVar(..) | RigidAbleVar(..), + ) +} + impl<'a> Layout<'a> { pub const VOID: Self = Layout::Union(UnionLayout::NonRecursive(&[])); pub const UNIT: Self = Layout::Struct { @@ -1015,12 +1025,24 @@ impl<'a> Layout<'a> { } match symbol { - Symbol::NUM_DECIMAL | Symbol::NUM_AT_DECIMAL => { - return Ok(Layout::Builtin(Builtin::Decimal)) + Symbol::NUM_DECIMAL => return Ok(Layout::Builtin(Builtin::Decimal)), + + Symbol::NUM_NAT | Symbol::NUM_NATURAL => { + return Ok(Layout::usize(env.target_info)) } - Symbol::NUM_NAT | Symbol::NUM_NATURAL | Symbol::NUM_AT_NATURAL => { - return Ok(Layout::usize(env.target_info)) + Symbol::NUM_NUM | Symbol::NUM_INT | Symbol::NUM_INTEGER + if is_unresolved_var(env.subs, actual_var) => + { + // default to i64 + return Ok(Layout::i64()); + } + + Symbol::NUM_FLOAT | Symbol::NUM_FLOATINGPOINT + if is_unresolved_var(env.subs, actual_var) => + { + // default to f64 + return Ok(Layout::f64()); } _ => Self::from_var(env, actual_var), @@ -1689,7 +1711,7 @@ fn layout_from_flat_type<'a>( Ok(Layout::f32()) } - Symbol::NUM_NUM | Symbol::NUM_AT_NUM => { + Symbol::NUM_NUM => { // Num.Num should only ever have 1 argument, e.g. Num.Num Int.Integer debug_assert_eq!(args.len(), 1); @@ -2135,31 +2157,20 @@ fn union_sorted_tags_help_new<'a>( // just one tag in the union (but with arguments) can be a struct let mut layouts = Vec::with_capacity_in(tags_list.len(), env.arena); - // special-case NUM_AT_NUM: if its argument is a FlexVar, make it Int - match tag_name { - TagName::Private(Symbol::NUM_AT_NUM) => { - let var = arguments[0]; - layouts.push( - unwrap_num_tag(env.subs, var, env.target_info).expect("invalid num layout"), - ); - } - _ => { - for &var in arguments { - match Layout::from_var(env, var) { - Ok(layout) => { - layouts.push(layout); - } - Err(LayoutProblem::UnresolvedTypeVar(_)) => { - // If we encounter an unbound type var (e.g. `Ok *`) - // then it's zero-sized; In the future we may drop this argument - // completely, but for now we represent it with the empty tag union - layouts.push(Layout::VOID) - } - Err(LayoutProblem::Erroneous) => { - // An erroneous type var will code gen to a runtime - // error, so we don't need to store any data for it. - } - } + for &var in arguments { + match Layout::from_var(env, var) { + Ok(layout) => { + layouts.push(layout); + } + Err(LayoutProblem::UnresolvedTypeVar(_)) => { + // If we encounter an unbound type var (e.g. `Ok *`) + // then it's zero-sized; In the future we may drop this argument + // completely, but for now we represent it with the empty tag union + layouts.push(Layout::VOID) + } + Err(LayoutProblem::Erroneous) => { + // An erroneous type var will code gen to a runtime + // error, so we don't need to store any data for it. } } } @@ -2341,37 +2352,26 @@ pub fn union_sorted_tags_help<'a>( let mut layouts = Vec::with_capacity_in(tags_vec.len(), arena); let mut contains_zero_sized = false; - // special-case NUM_AT_NUM: if its argument is a FlexVar, make it Int - match tag_name { - TagName::Private(Symbol::NUM_AT_NUM) => { - layouts.push( - unwrap_num_tag(subs, arguments[0], target_info) - .expect("invalid num layout"), - ); - } - _ => { - for var in arguments { - match Layout::from_var(&mut env, var) { - Ok(layout) => { - // Drop any zero-sized arguments like {} - if !layout.is_dropped_because_empty() { - layouts.push(layout); - } else { - contains_zero_sized = true; - } - } - Err(LayoutProblem::UnresolvedTypeVar(_)) => { - // If we encounter an unbound type var (e.g. `Ok *`) - // then it's zero-sized; In the future we may drop this argument - // completely, but for now we represent it with the empty tag union - layouts.push(Layout::VOID) - } - Err(LayoutProblem::Erroneous) => { - // An erroneous type var will code gen to a runtime - // error, so we don't need to store any data for it. - } + for var in arguments { + match Layout::from_var(&mut env, var) { + Ok(layout) => { + // Drop any zero-sized arguments like {} + if !layout.is_dropped_because_empty() { + layouts.push(layout); + } else { + contains_zero_sized = true; } } + Err(LayoutProblem::UnresolvedTypeVar(_)) => { + // If we encounter an unbound type var (e.g. `Ok *`) + // then it's zero-sized; In the future we may drop this argument + // completely, but for now we represent it with the empty tag union + layouts.push(Layout::VOID) + } + Err(LayoutProblem::Erroneous) => { + // An erroneous type var will code gen to a runtime + // error, so we don't need to store any data for it. + } } } @@ -2529,24 +2529,20 @@ pub fn union_sorted_tags_help<'a>( fn layout_from_newtype<'a>(env: &mut Env<'a, '_>, tags: &UnsortedUnionTags) -> Layout<'a> { debug_assert!(tags.is_newtype_wrapper(env.subs)); - let (tag_name, var) = tags.get_newtype(env.subs); + let (_tag_name, var) = tags.get_newtype(env.subs); - if tag_name == &TagName::Private(Symbol::NUM_AT_NUM) { - unwrap_num_tag(env.subs, var, env.target_info).expect("invalid Num argument") - } else { - match Layout::from_var(env, var) { - Ok(layout) => layout, - Err(LayoutProblem::UnresolvedTypeVar(_)) => { - // If we encounter an unbound type var (e.g. `Ok *`) - // then it's zero-sized; In the future we may drop this argument - // completely, but for now we represent it with the empty tag union - Layout::VOID - } - Err(LayoutProblem::Erroneous) => { - // An erroneous type var will code gen to a runtime - // error, so we don't need to store any data for it. - todo!() - } + match Layout::from_var(env, var) { + Ok(layout) => layout, + Err(LayoutProblem::UnresolvedTypeVar(_)) => { + // If we encounter an unbound type var (e.g. `Ok *`) + // then it's zero-sized; In the future we may drop this argument + // completely, but for now we represent it with the empty tag union + Layout::VOID + } + Err(LayoutProblem::Erroneous) => { + // An erroneous type var will code gen to a runtime + // error, so we don't need to store any data for it. + todo!() } } } @@ -2560,76 +2556,65 @@ fn layout_from_tag_union<'a>(env: &mut Env<'a, '_>, tags: &UnsortedUnionTags) -> let tags_vec = &tags.tags; - match tags_vec.get(0) { - Some((tag_name, arguments)) if *tag_name == &TagName::Private(Symbol::NUM_AT_NUM) => { - debug_assert_eq!(arguments.len(), 1); + let opt_rec_var = None; + let variant = union_sorted_tags_help_new(env, tags_vec, opt_rec_var); - let &var = arguments.iter().next().unwrap(); + match variant { + Never => Layout::VOID, + Unit | UnitWithArguments => Layout::UNIT, + BoolUnion { .. } => Layout::bool(), + ByteUnion(_) => Layout::u8(), + Newtype { + arguments: field_layouts, + .. + } => { + let answer1 = if field_layouts.len() == 1 { + field_layouts[0] + } else { + Layout::struct_no_name_order(field_layouts.into_bump_slice()) + }; - unwrap_num_tag(env.subs, var, env.target_info).expect("invalid Num argument") + answer1 } - _ => { - let opt_rec_var = None; - let variant = union_sorted_tags_help_new(env, tags_vec, opt_rec_var); + Wrapped(variant) => { + use WrappedVariant::*; match variant { - Never => Layout::VOID, - Unit | UnitWithArguments => Layout::UNIT, - BoolUnion { .. } => Layout::bool(), - ByteUnion(_) => Layout::u8(), - Newtype { - arguments: field_layouts, - .. + NonRecursive { + sorted_tag_layouts: tags, } => { - let answer1 = if field_layouts.len() == 1 { - field_layouts[0] - } else { - Layout::struct_no_name_order(field_layouts.into_bump_slice()) - }; + let mut tag_layouts = Vec::with_capacity_in(tags.len(), env.arena); + tag_layouts.extend(tags.iter().map(|r| r.1)); - answer1 + Layout::Union(UnionLayout::NonRecursive(tag_layouts.into_bump_slice())) } - Wrapped(variant) => { - use WrappedVariant::*; - match variant { - NonRecursive { - sorted_tag_layouts: tags, - } => { - let mut tag_layouts = Vec::with_capacity_in(tags.len(), env.arena); - tag_layouts.extend(tags.iter().map(|r| r.1)); + Recursive { + sorted_tag_layouts: tags, + } => { + let mut tag_layouts = Vec::with_capacity_in(tags.len(), env.arena); + tag_layouts.extend(tags.iter().map(|r| r.1)); - Layout::Union(UnionLayout::NonRecursive(tag_layouts.into_bump_slice())) - } - - Recursive { - sorted_tag_layouts: tags, - } => { - let mut tag_layouts = Vec::with_capacity_in(tags.len(), env.arena); - tag_layouts.extend(tags.iter().map(|r| r.1)); - - debug_assert!(tag_layouts.len() > 1); - Layout::Union(UnionLayout::Recursive(tag_layouts.into_bump_slice())) - } - - NullableWrapped { - nullable_id, - nullable_name: _, - sorted_tag_layouts: tags, - } => { - let mut tag_layouts = Vec::with_capacity_in(tags.len(), env.arena); - tag_layouts.extend(tags.iter().map(|r| r.1)); - - Layout::Union(UnionLayout::NullableWrapped { - nullable_id, - other_tags: tag_layouts.into_bump_slice(), - }) - } - - NullableUnwrapped { .. } => todo!(), - NonNullableUnwrapped { .. } => todo!(), - } + debug_assert!(tag_layouts.len() > 1); + Layout::Union(UnionLayout::Recursive(tag_layouts.into_bump_slice())) } + + NullableWrapped { + nullable_id, + nullable_name: _, + sorted_tag_layouts: tags, + } => { + let mut tag_layouts = Vec::with_capacity_in(tags.len(), env.arena); + tag_layouts.extend(tags.iter().map(|r| r.1)); + + Layout::Union(UnionLayout::NullableWrapped { + nullable_id, + other_tags: tag_layouts.into_bump_slice(), + }) + } + + NullableUnwrapped { .. } => todo!(), + NonNullableUnwrapped { .. } => todo!(), } } } @@ -2727,6 +2712,8 @@ fn layout_from_num_content<'a>( } } +// TODO: removable? +#[allow(dead_code)] fn unwrap_num_tag<'a>( subs: &Subs, var: Variable, diff --git a/compiler/mono/src/layout_soa.rs b/compiler/mono/src/layout_soa.rs index ed813d0c0a..05b7858b20 100644 --- a/compiler/mono/src/layout_soa.rs +++ b/compiler/mono/src/layout_soa.rs @@ -678,11 +678,9 @@ impl Layout { } match symbol { - Symbol::NUM_DECIMAL | Symbol::NUM_AT_DECIMAL => Ok(Layout::Decimal), + Symbol::NUM_DECIMAL => Ok(Layout::Decimal), - Symbol::NUM_NAT | Symbol::NUM_NATURAL | Symbol::NUM_AT_NATURAL => { - Ok(layouts.usize()) - } + Symbol::NUM_NAT | Symbol::NUM_NATURAL => Ok(layouts.usize()), _ => { // at this point we throw away alias information diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index 47addd8f51..f977920b7a 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -5,6 +5,7 @@ use roc_can::constraint::Constraint::{self, *}; use roc_can::constraint::{Constraints, LetConstraint}; use roc_can::expected::{Expected, PExpected}; use roc_collections::all::MutMap; +use roc_error_macros::internal_error; use roc_module::ident::TagName; use roc_module::symbol::Symbol; use roc_region::all::{Loc, Region}; @@ -195,20 +196,20 @@ impl Aliases { register(subs, rank, pools, content) } - /// Instantiate an alias of the form `Foo a : [ @Foo a ]` - fn instantiate_num_at_alias( + /// Build an alias of the form `Num range := range` + fn build_num_opaque( subs: &mut Subs, rank: Rank, pools: &mut Pools, - tag_name_slice: SubsSlice, - range_slice: SubsSlice, + symbol: Symbol, + range_var: Variable, ) -> Variable { - let variable_slices = SubsSlice::extend_new(&mut subs.variable_slices, [range_slice]); - - let union_tags = UnionTags::from_slices(tag_name_slice, variable_slices); - let ext_var = Variable::EMPTY_TAG_UNION; - let flat_type = FlatType::TagUnion(union_tags, ext_var); - let content = Content::Structure(flat_type); + let content = Content::Alias( + symbol, + AliasVariables::insert_into_subs(subs, [range_var], []), + range_var, + AliasKind::Opaque, + ); register(subs, rank, pools, content) } @@ -227,126 +228,46 @@ impl Aliases { Some(var) } - Symbol::NUM_NUM => { - let var = Self::instantiate_num_at_alias( - subs, - rank, - pools, - Subs::NUM_AT_NUM, - SubsSlice::new(alias_variables.variables_start, 1), - ); - - Some(var) - } - Symbol::NUM_FLOATINGPOINT => { - let var = Self::instantiate_num_at_alias( - subs, - rank, - pools, - Subs::NUM_AT_FLOATINGPOINT, - SubsSlice::new(alias_variables.variables_start, 1), - ); - - Some(var) - } - Symbol::NUM_INTEGER => { - let var = Self::instantiate_num_at_alias( - subs, - rank, - pools, - Subs::NUM_AT_INTEGER, - SubsSlice::new(alias_variables.variables_start, 1), - ); - - Some(var) + Symbol::NUM_NUM | Symbol::NUM_FLOATINGPOINT | Symbol::NUM_INTEGER => { + // These are opaque types Num range := range (respectively for FloatingPoint and + // Integer). They should not have been built as DelayedAliases! + internal_error!("Attempting to build delayed instantiation of opaque num"); } Symbol::NUM_INT => { - // [ @Integer range ] - let integer_content_var = Self::instantiate_builtin_aliases( - self, + // Int range : Num (Integer range) + // + // build `Integer range := range` + let integer_content_var = Self::build_num_opaque( subs, rank, pools, Symbol::NUM_INTEGER, - alias_variables, - ) - .unwrap(); - - // Integer range (alias variable is the same as `Int range`) - let integer_alias_variables = alias_variables; - let integer_content = Content::Alias( - Symbol::NUM_INTEGER, - integer_alias_variables, - integer_content_var, - AliasKind::Structural, - ); - let integer_alias_var = register(subs, rank, pools, integer_content); - - // [ @Num (Integer range) ] - let num_alias_variables = - AliasVariables::insert_into_subs(subs, [integer_alias_var], []); - let num_content_var = Self::instantiate_builtin_aliases( - self, - subs, - rank, - pools, - Symbol::NUM_NUM, - num_alias_variables, - ) - .unwrap(); - - let num_content = Content::Alias( - Symbol::NUM_NUM, - num_alias_variables, - num_content_var, - AliasKind::Structural, + subs.variables[alias_variables.variables_start as usize], ); - Some(register(subs, rank, pools, num_content)) + // build `Num (Integer range) := Integer range` + let num_content_var = + Self::build_num_opaque(subs, rank, pools, Symbol::NUM_NUM, integer_content_var); + + Some(num_content_var) } Symbol::NUM_FLOAT => { - // [ @FloatingPoint range ] - let fpoint_content_var = Self::instantiate_builtin_aliases( - self, + // Float range : Num (FloatingPoint range) + // + // build `FloatingPoint range := range` + let fpoint_content_var = Self::build_num_opaque( subs, rank, pools, Symbol::NUM_FLOATINGPOINT, - alias_variables, - ) - .unwrap(); - - // FloatingPoint range (alias variable is the same as `Float range`) - let fpoint_alias_variables = alias_variables; - let fpoint_content = Content::Alias( - Symbol::NUM_FLOATINGPOINT, - fpoint_alias_variables, - fpoint_content_var, - AliasKind::Structural, - ); - let fpoint_alias_var = register(subs, rank, pools, fpoint_content); - - // [ @Num (FloatingPoint range) ] - let num_alias_variables = - AliasVariables::insert_into_subs(subs, [fpoint_alias_var], []); - let num_content_var = Self::instantiate_builtin_aliases( - self, - subs, - rank, - pools, - Symbol::NUM_NUM, - num_alias_variables, - ) - .unwrap(); - - let num_content = Content::Alias( - Symbol::NUM_NUM, - num_alias_variables, - num_content_var, - AliasKind::Structural, + subs.variables[alias_variables.variables_start as usize], ); - Some(register(subs, rank, pools, num_content)) + // build `Num (FloatingPoint range) := FloatingPoint range` + let num_content_var = + Self::build_num_opaque(subs, rank, pools, Symbol::NUM_NUM, fpoint_content_var); + + Some(num_content_var) } _ => None, } diff --git a/compiler/types/src/builtin_aliases.rs b/compiler/types/src/builtin_aliases.rs index 23b3983cc9..63ca184df9 100644 --- a/compiler/types/src/builtin_aliases.rs +++ b/compiler/types/src/builtin_aliases.rs @@ -28,53 +28,58 @@ pub fn aliases() -> MutMap { aliases.insert(symbol, alias); }; - // Int range : [ @Int range ] + // Int range : Num (Integer range) add_alias( Symbol::NUM_INT, BuiltinAlias { region: Region::zero(), vars: vec![Loc::at(Region::zero(), "range".into())], typ: int_alias_content(flex(TVAR1)), + kind: AliasKind::Structural, }, ); - // Float range : [ @Float range ] + // Float range : Num (FloatingPoint range) add_alias( Symbol::NUM_FLOAT, BuiltinAlias { region: Region::zero(), vars: vec![Loc::at(Region::zero(), "range".into())], typ: float_alias_content(flex(TVAR1)), + kind: AliasKind::Structural, }, ); - // Num range : [ @Num range ] + // Num range := range add_alias( Symbol::NUM_NUM, BuiltinAlias { region: Region::zero(), vars: vec![Loc::at(Region::zero(), "range".into())], typ: num_alias_content(flex(TVAR1)), + kind: AliasKind::Opaque, }, ); - // Integer range : [ @Integer range ] + // Integer range := range add_alias( Symbol::NUM_INTEGER, BuiltinAlias { region: Region::zero(), vars: vec![Loc::at(Region::zero(), "range".into())], typ: integer_alias_content(flex(TVAR1)), + kind: AliasKind::Opaque, }, ); - // Natural : [ @Natural ] + // Natural := [] add_alias( Symbol::NUM_NATURAL, BuiltinAlias { region: Region::zero(), vars: vec![], typ: natural_alias_content(), + kind: AliasKind::Opaque, }, ); @@ -85,16 +90,18 @@ pub fn aliases() -> MutMap { region: Region::zero(), vars: Vec::new(), typ: nat_alias_content(), + kind: AliasKind::Structural, }, ); - // Signed128 : [ @Signed128 ] + // Signed128 := [] add_alias( Symbol::NUM_SIGNED128, BuiltinAlias { region: Region::zero(), vars: vec![], typ: signed128_alias_content(), + kind: AliasKind::Opaque, }, ); @@ -105,6 +112,7 @@ pub fn aliases() -> MutMap { region: Region::zero(), vars: Vec::new(), typ: i128_alias_content(), + kind: AliasKind::Structural, }, ); @@ -115,16 +123,18 @@ pub fn aliases() -> MutMap { region: Region::zero(), vars: Vec::new(), typ: u128_alias_content(), + kind: AliasKind::Structural, }, ); - // Signed64 : [ @Signed64 ] + // Signed64 := [] add_alias( Symbol::NUM_SIGNED64, BuiltinAlias { region: Region::zero(), vars: vec![], typ: signed64_alias_content(), + kind: AliasKind::Opaque, }, ); @@ -135,6 +145,7 @@ pub fn aliases() -> MutMap { region: Region::zero(), vars: Vec::new(), typ: i64_alias_content(), + kind: AliasKind::Structural, }, ); @@ -145,16 +156,18 @@ pub fn aliases() -> MutMap { region: Region::zero(), vars: Vec::new(), typ: u64_alias_content(), + kind: AliasKind::Structural, }, ); - // Signed32 : [ @Signed32 ] + // Signed32 := [] add_alias( Symbol::NUM_SIGNED32, BuiltinAlias { region: Region::zero(), vars: vec![], typ: signed32_alias_content(), + kind: AliasKind::Opaque, }, ); @@ -165,6 +178,7 @@ pub fn aliases() -> MutMap { region: Region::zero(), vars: Vec::new(), typ: i32_alias_content(), + kind: AliasKind::Structural, }, ); @@ -175,16 +189,18 @@ pub fn aliases() -> MutMap { region: Region::zero(), vars: Vec::new(), typ: u32_alias_content(), + kind: AliasKind::Structural, }, ); - // Signed16 : [ @Signed16 ] + // Signed16 := [] add_alias( Symbol::NUM_SIGNED16, BuiltinAlias { region: Region::zero(), vars: vec![], typ: signed16_alias_content(), + kind: AliasKind::Opaque, }, ); @@ -195,6 +211,7 @@ pub fn aliases() -> MutMap { region: Region::zero(), vars: Vec::new(), typ: i16_alias_content(), + kind: AliasKind::Structural, }, ); @@ -205,16 +222,18 @@ pub fn aliases() -> MutMap { region: Region::zero(), vars: Vec::new(), typ: u16_alias_content(), + kind: AliasKind::Structural, }, ); - // Signed8 : [ @Signed8 ] + // Signed8 := [] add_alias( Symbol::NUM_SIGNED8, BuiltinAlias { region: Region::zero(), vars: vec![], typ: signed8_alias_content(), + kind: AliasKind::Opaque, }, ); @@ -225,6 +244,7 @@ pub fn aliases() -> MutMap { region: Region::zero(), vars: Vec::new(), typ: i8_alias_content(), + kind: AliasKind::Structural, }, ); @@ -235,46 +255,51 @@ pub fn aliases() -> MutMap { region: Region::zero(), vars: Vec::new(), typ: u8_alias_content(), + kind: AliasKind::Structural, }, ); - // Decimal : [ @Decimal ] + // Decimal := [] add_alias( Symbol::NUM_DECIMAL, BuiltinAlias { region: Region::zero(), vars: vec![], typ: decimal_alias_content(), + kind: AliasKind::Opaque, }, ); - // Binary64 : [ @Binary64 ] + // Binary64 := [] add_alias( Symbol::NUM_BINARY64, BuiltinAlias { region: Region::zero(), vars: vec![], typ: binary64_alias_content(), + kind: AliasKind::Opaque, }, ); - // Binary32 : [ @Binary32 ] + // Binary32 := [] add_alias( Symbol::NUM_BINARY32, BuiltinAlias { region: Region::zero(), vars: vec![], typ: binary32_alias_content(), + kind: AliasKind::Opaque, }, ); - // FloatingPoint range : [ @FloatingPoint range ] + // FloatingPoint range := range add_alias( Symbol::NUM_FLOATINGPOINT, BuiltinAlias { region: Region::zero(), vars: vec![Loc::at(Region::zero(), "range".into())], typ: floatingpoint_alias_content(flex(TVAR1)), + kind: AliasKind::Opaque, }, ); @@ -285,6 +310,7 @@ pub fn aliases() -> MutMap { region: Region::zero(), vars: Vec::new(), typ: dec_alias_content(), + kind: AliasKind::Structural, }, ); @@ -295,6 +321,7 @@ pub fn aliases() -> MutMap { region: Region::zero(), vars: Vec::new(), typ: f64_alias_content(), + kind: AliasKind::Structural, }, ); @@ -305,6 +332,7 @@ pub fn aliases() -> MutMap { region: Region::zero(), vars: Vec::new(), typ: f32_alias_content(), + kind: AliasKind::Structural, }, ); @@ -315,6 +343,7 @@ pub fn aliases() -> MutMap { region: Region::zero(), vars: Vec::new(), typ: bool_alias_content(), + kind: AliasKind::Structural, }, ); @@ -325,6 +354,7 @@ pub fn aliases() -> MutMap { region: Region::zero(), vars: Vec::new(), typ: str_utf8_byte_problem_alias_content(), + kind: AliasKind::Structural, }, ); @@ -335,6 +365,7 @@ pub fn aliases() -> MutMap { region: Region::zero(), vars: Vec::new(), typ: str_utf8_byte_problem_alias_content(), + kind: AliasKind::Structural, }, ); @@ -353,13 +384,13 @@ pub fn num_type(range: SolvedType) -> SolvedType { vec![("range".into(), range.clone())], vec![], Box::new(num_alias_content(range)), - AliasKind::Structural, + AliasKind::Opaque, ) } #[inline(always)] fn num_alias_content(range: SolvedType) -> SolvedType { - single_private_tag(Symbol::NUM_AT_NUM, vec![range]) + range } // FLOATING POINT @@ -371,13 +402,13 @@ pub fn floatingpoint_type(range: SolvedType) -> SolvedType { vec![("range".into(), range.clone())], vec![], Box::new(floatingpoint_alias_content(range)), - AliasKind::Structural, + AliasKind::Opaque, ) } #[inline(always)] fn floatingpoint_alias_content(range: SolvedType) -> SolvedType { - single_private_tag(Symbol::NUM_AT_FLOATINGPOINT, vec![range]) + range } // FLOAT @@ -659,13 +690,13 @@ pub fn integer_type(range: SolvedType) -> SolvedType { vec![("range".into(), range.clone())], vec![], Box::new(integer_alias_content(range)), - AliasKind::Structural, + AliasKind::Opaque, ) } #[inline(always)] fn integer_alias_content(range: SolvedType) -> SolvedType { - single_private_tag(Symbol::NUM_AT_INTEGER, vec![range]) + range } #[inline(always)] @@ -681,7 +712,7 @@ pub fn binary64_type() -> SolvedType { #[inline(always)] pub fn binary64_alias_content() -> SolvedType { - single_private_tag(Symbol::NUM_AT_BINARY64, vec![]) + SolvedType::EmptyTagUnion } #[inline(always)] @@ -697,7 +728,7 @@ pub fn binary32_type() -> SolvedType { #[inline(always)] fn binary32_alias_content() -> SolvedType { - single_private_tag(Symbol::NUM_AT_BINARY32, vec![]) + SolvedType::EmptyTagUnion } #[inline(always)] @@ -713,7 +744,7 @@ pub fn natural_type() -> SolvedType { #[inline(always)] fn natural_alias_content() -> SolvedType { - single_private_tag(Symbol::NUM_AT_NATURAL, vec![]) + SolvedType::EmptyTagUnion } #[inline(always)] @@ -729,7 +760,7 @@ pub fn signed128_type() -> SolvedType { #[inline(always)] fn signed128_alias_content() -> SolvedType { - single_private_tag(Symbol::NUM_AT_SIGNED128, vec![]) + SolvedType::EmptyTagUnion } #[inline(always)] @@ -745,7 +776,7 @@ pub fn signed64_type() -> SolvedType { #[inline(always)] fn signed64_alias_content() -> SolvedType { - single_private_tag(Symbol::NUM_AT_SIGNED64, vec![]) + SolvedType::EmptyTagUnion } #[inline(always)] @@ -761,7 +792,7 @@ pub fn signed32_type() -> SolvedType { #[inline(always)] fn signed32_alias_content() -> SolvedType { - single_private_tag(Symbol::NUM_AT_SIGNED32, vec![]) + SolvedType::EmptyTagUnion } #[inline(always)] @@ -777,7 +808,7 @@ pub fn signed16_type() -> SolvedType { #[inline(always)] fn signed16_alias_content() -> SolvedType { - single_private_tag(Symbol::NUM_AT_SIGNED16, vec![]) + SolvedType::EmptyTagUnion } #[inline(always)] @@ -793,7 +824,7 @@ pub fn signed8_type() -> SolvedType { #[inline(always)] fn signed8_alias_content() -> SolvedType { - single_private_tag(Symbol::NUM_AT_SIGNED8, vec![]) + SolvedType::EmptyTagUnion } #[inline(always)] @@ -809,7 +840,7 @@ pub fn unsigned128_type() -> SolvedType { #[inline(always)] fn unsigned128_alias_content() -> SolvedType { - single_private_tag(Symbol::NUM_AT_UNSIGNED128, vec![]) + SolvedType::EmptyTagUnion } #[inline(always)] @@ -825,7 +856,7 @@ pub fn unsigned64_type() -> SolvedType { #[inline(always)] fn unsigned64_alias_content() -> SolvedType { - single_private_tag(Symbol::NUM_AT_UNSIGNED64, vec![]) + SolvedType::EmptyTagUnion } #[inline(always)] @@ -841,7 +872,7 @@ pub fn unsigned32_type() -> SolvedType { #[inline(always)] fn unsigned32_alias_content() -> SolvedType { - single_private_tag(Symbol::NUM_AT_UNSIGNED32, vec![]) + SolvedType::EmptyTagUnion } #[inline(always)] @@ -857,7 +888,7 @@ pub fn unsigned16_type() -> SolvedType { #[inline(always)] fn unsigned16_alias_content() -> SolvedType { - single_private_tag(Symbol::NUM_AT_UNSIGNED16, vec![]) + SolvedType::EmptyTagUnion } #[inline(always)] @@ -873,12 +904,12 @@ pub fn unsigned8_type() -> SolvedType { #[inline(always)] fn unsigned8_alias_content() -> SolvedType { - single_private_tag(Symbol::NUM_AT_UNSIGNED8, vec![]) + SolvedType::EmptyTagUnion } #[inline(always)] fn decimal_alias_content() -> SolvedType { - single_private_tag(Symbol::NUM_AT_DECIMAL, vec![]) + SolvedType::EmptyTagUnion } // Dec diff --git a/compiler/types/src/solved_types.rs b/compiler/types/src/solved_types.rs index a9acc39cfa..76fd39ecab 100644 --- a/compiler/types/src/solved_types.rs +++ b/compiler/types/src/solved_types.rs @@ -78,6 +78,7 @@ pub struct BuiltinAlias { pub region: Region, pub vars: Vec>, pub typ: SolvedType, + pub kind: AliasKind, } #[derive(Debug, Clone, Default)] diff --git a/compiler/types/src/subs.rs b/compiler/types/src/subs.rs index 97a9bf67e9..3a9888c8c5 100644 --- a/compiler/types/src/subs.rs +++ b/compiler/types/src/subs.rs @@ -1009,22 +1009,7 @@ define_const_var! { ORDER_ENUM, :pub ORDER, - // [ @Signed8 ] - AT_SIGNED8, - AT_SIGNED16, - AT_SIGNED32, - AT_SIGNED64, - AT_SIGNED128, - - AT_UNSIGNED8, - AT_UNSIGNED16, - AT_UNSIGNED32, - AT_UNSIGNED64, - AT_UNSIGNED128, - - AT_NATURAL, - - // Signed8 : [ @Signed8 ] + // Signed8 := [] :pub SIGNED8, :pub SIGNED16, :pub SIGNED32, @@ -1039,22 +1024,7 @@ define_const_var! { :pub NATURAL, - // [ @Integer Signed8 ] - AT_INTEGER_SIGNED8, - AT_INTEGER_SIGNED16, - AT_INTEGER_SIGNED32, - AT_INTEGER_SIGNED64, - AT_INTEGER_SIGNED128, - - AT_INTEGER_UNSIGNED8, - AT_INTEGER_UNSIGNED16, - AT_INTEGER_UNSIGNED32, - AT_INTEGER_UNSIGNED64, - AT_INTEGER_UNSIGNED128, - - AT_INTEGER_NATURAL, - - // Integer Signed8 : [ @Integer Signed8 ] + // Integer Signed8 := Signed8 INTEGER_SIGNED8, INTEGER_SIGNED16, INTEGER_SIGNED32, @@ -1069,22 +1039,7 @@ define_const_var! { INTEGER_NATURAL, - // [ @Num (Integer Signed8) ] - AT_NUM_INTEGER_SIGNED8, - AT_NUM_INTEGER_SIGNED16, - AT_NUM_INTEGER_SIGNED32, - AT_NUM_INTEGER_SIGNED64, - AT_NUM_INTEGER_SIGNED128, - - AT_NUM_INTEGER_UNSIGNED8, - AT_NUM_INTEGER_UNSIGNED16, - AT_NUM_INTEGER_UNSIGNED32, - AT_NUM_INTEGER_UNSIGNED64, - AT_NUM_INTEGER_UNSIGNED128, - - AT_NUM_INTEGER_NATURAL, - - // Num (Integer Signed8) + // Num (Integer Signed8) := Integer Signed8 NUM_INTEGER_SIGNED8, NUM_INTEGER_SIGNED16, NUM_INTEGER_SIGNED32, @@ -1114,32 +1069,17 @@ define_const_var! { :pub NAT, - // [ @Binary32 ] - AT_BINARY32, - AT_BINARY64, - AT_DECIMAL, - - // Binary32 : [ @Binary32 ] + // Binary32 : [] BINARY32, BINARY64, DECIMAL, - // [ @Float Binary32 ] - AT_FLOAT_BINARY32, - AT_FLOAT_BINARY64, - AT_FLOAT_DECIMAL, - - // Float Binary32 : [ @Float Binary32 ] + // Float Binary32 := Binary32 FLOAT_BINARY32, FLOAT_BINARY64, FLOAT_DECIMAL, - // [ @Num (Float Binary32) ] - AT_NUM_FLOAT_BINARY32, - AT_NUM_FLOAT_BINARY64, - AT_NUM_FLOAT_DECIMAL, - - // Num (Float Binary32) + // Num (Float Binary32) := Float Binary32 NUM_FLOAT_BINARY32, NUM_FLOAT_BINARY64, NUM_FLOAT_DECIMAL, @@ -1273,80 +1213,47 @@ impl fmt::Debug for VarId { fn integer_type( subs: &mut Subs, - num_at_signed64: Symbol, num_signed64: Symbol, num_i64: Symbol, - at_signed64: Variable, signed64: Variable, - at_integer_signed64: Variable, integer_signed64: Variable, - at_num_integer_signed64: Variable, num_integer_signed64: Variable, var_i64: Variable, ) { - // define the type Signed64 (which is an alias for [ @Signed64 ]) + // define the type Signed64 := [] { - let tags = UnionTags::insert_into_subs(subs, [(TagName::Private(num_at_signed64), [])]); - - subs.set_content(at_signed64, { - Content::Structure(FlatType::TagUnion(tags, Variable::EMPTY_TAG_UNION)) - }); - subs.set_content(signed64, { Content::Alias( num_signed64, AliasVariables::default(), - at_signed64, - AliasKind::Structural, + Variable::EMPTY_TAG_UNION, + AliasKind::Opaque, ) }); } - // define the type `Num.Integer Num.Signed64` + // define the type `Num.Integer Num.Signed64 := Num.Signed64` { - let tags = UnionTags::insert_into_subs( - subs, - [(TagName::Private(Symbol::NUM_AT_INTEGER), [signed64])], - ); - subs.set_content(at_integer_signed64, { - Content::Structure(FlatType::TagUnion(tags, Variable::EMPTY_TAG_UNION)) - }); - let vars = AliasVariables::insert_into_subs(subs, [signed64], []); subs.set_content(integer_signed64, { - Content::Alias( - Symbol::NUM_INTEGER, - vars, - at_signed64, - AliasKind::Structural, - ) + Content::Alias(Symbol::NUM_INTEGER, vars, signed64, AliasKind::Opaque) }); } - // define the type `Num.Num (Num.Integer Num.Signed64)` + // define the type `Num.Num (Num.Integer Num.Signed64) := Num.Integer Num.Signed64` { - let tags = UnionTags::insert_into_subs( - subs, - [(TagName::Private(Symbol::NUM_AT_NUM), [integer_signed64])], - ); - subs.set_content(at_num_integer_signed64, { - Content::Structure(FlatType::TagUnion(tags, Variable::EMPTY_TAG_UNION)) - }); - let vars = AliasVariables::insert_into_subs(subs, [integer_signed64], []); subs.set_content(num_integer_signed64, { - Content::Alias( - Symbol::NUM_NUM, - vars, - at_num_integer_signed64, - AliasKind::Structural, - ) + Content::Alias(Symbol::NUM_NUM, vars, integer_signed64, AliasKind::Opaque) }); + } + // define the type `Num.I64 : Num.Num (Num.Integer Num.Signed64)` + { subs.set_content(var_i64, { Content::Alias( num_i64, @@ -1361,154 +1268,110 @@ fn integer_type( fn define_integer_types(subs: &mut Subs) { integer_type( subs, - Symbol::NUM_AT_SIGNED128, Symbol::NUM_SIGNED128, Symbol::NUM_I128, - Variable::AT_SIGNED128, Variable::SIGNED128, - Variable::AT_INTEGER_SIGNED128, Variable::INTEGER_SIGNED128, - Variable::AT_NUM_INTEGER_SIGNED128, Variable::NUM_INTEGER_SIGNED128, Variable::I128, ); integer_type( subs, - Symbol::NUM_AT_SIGNED64, Symbol::NUM_SIGNED64, Symbol::NUM_I64, - Variable::AT_SIGNED64, Variable::SIGNED64, - Variable::AT_INTEGER_SIGNED64, Variable::INTEGER_SIGNED64, - Variable::AT_NUM_INTEGER_SIGNED64, Variable::NUM_INTEGER_SIGNED64, Variable::I64, ); integer_type( subs, - Symbol::NUM_AT_SIGNED32, Symbol::NUM_SIGNED32, Symbol::NUM_I32, - Variable::AT_SIGNED32, Variable::SIGNED32, - Variable::AT_INTEGER_SIGNED32, Variable::INTEGER_SIGNED32, - Variable::AT_NUM_INTEGER_SIGNED32, Variable::NUM_INTEGER_SIGNED32, Variable::I32, ); integer_type( subs, - Symbol::NUM_AT_SIGNED16, Symbol::NUM_SIGNED16, Symbol::NUM_I16, - Variable::AT_SIGNED16, Variable::SIGNED16, - Variable::AT_INTEGER_SIGNED16, Variable::INTEGER_SIGNED16, - Variable::AT_NUM_INTEGER_SIGNED16, Variable::NUM_INTEGER_SIGNED16, Variable::I16, ); integer_type( subs, - Symbol::NUM_AT_SIGNED8, Symbol::NUM_SIGNED8, Symbol::NUM_I8, - Variable::AT_SIGNED8, Variable::SIGNED8, - Variable::AT_INTEGER_SIGNED8, Variable::INTEGER_SIGNED8, - Variable::AT_NUM_INTEGER_SIGNED8, Variable::NUM_INTEGER_SIGNED8, Variable::I8, ); integer_type( subs, - Symbol::NUM_AT_UNSIGNED128, Symbol::NUM_UNSIGNED128, Symbol::NUM_U128, - Variable::AT_UNSIGNED128, Variable::UNSIGNED128, - Variable::AT_INTEGER_UNSIGNED128, Variable::INTEGER_UNSIGNED128, - Variable::AT_NUM_INTEGER_UNSIGNED128, Variable::NUM_INTEGER_UNSIGNED128, Variable::U128, ); integer_type( subs, - Symbol::NUM_AT_UNSIGNED64, Symbol::NUM_UNSIGNED64, Symbol::NUM_U64, - Variable::AT_UNSIGNED64, Variable::UNSIGNED64, - Variable::AT_INTEGER_UNSIGNED64, Variable::INTEGER_UNSIGNED64, - Variable::AT_NUM_INTEGER_UNSIGNED64, Variable::NUM_INTEGER_UNSIGNED64, Variable::U64, ); integer_type( subs, - Symbol::NUM_AT_UNSIGNED32, Symbol::NUM_UNSIGNED32, Symbol::NUM_U32, - Variable::AT_UNSIGNED32, Variable::UNSIGNED32, - Variable::AT_INTEGER_UNSIGNED32, Variable::INTEGER_UNSIGNED32, - Variable::AT_NUM_INTEGER_UNSIGNED32, Variable::NUM_INTEGER_UNSIGNED32, Variable::U32, ); integer_type( subs, - Symbol::NUM_AT_UNSIGNED16, Symbol::NUM_UNSIGNED16, Symbol::NUM_U16, - Variable::AT_UNSIGNED16, Variable::UNSIGNED16, - Variable::AT_INTEGER_UNSIGNED16, Variable::INTEGER_UNSIGNED16, - Variable::AT_NUM_INTEGER_UNSIGNED16, Variable::NUM_INTEGER_UNSIGNED16, Variable::U16, ); integer_type( subs, - Symbol::NUM_AT_UNSIGNED8, Symbol::NUM_UNSIGNED8, Symbol::NUM_U8, - Variable::AT_UNSIGNED8, Variable::UNSIGNED8, - Variable::AT_INTEGER_UNSIGNED8, Variable::INTEGER_UNSIGNED8, - Variable::AT_NUM_INTEGER_UNSIGNED8, Variable::NUM_INTEGER_UNSIGNED8, Variable::U8, ); integer_type( subs, - Symbol::NUM_AT_NATURAL, Symbol::NUM_NATURAL, Symbol::NUM_NAT, - Variable::AT_NATURAL, Variable::NATURAL, - Variable::AT_INTEGER_NATURAL, Variable::INTEGER_NATURAL, - Variable::AT_NUM_INTEGER_NATURAL, Variable::NUM_INTEGER_NATURAL, Variable::NAT, ); @@ -1518,80 +1381,47 @@ fn define_integer_types(subs: &mut Subs) { fn float_type( subs: &mut Subs, - num_at_binary64: Symbol, num_binary64: Symbol, num_f64: Symbol, - at_binary64: Variable, binary64: Variable, - at_float_binary64: Variable, float_binary64: Variable, - at_num_float_binary64: Variable, num_float_binary64: Variable, var_f64: Variable, ) { - // define the type Binary64 (which is an alias for [ @Binary64 ]) + // define the type Binary64 := [] { - let tags = UnionTags::insert_into_subs(subs, [(TagName::Private(num_at_binary64), [])]); - - subs.set_content(at_binary64, { - Content::Structure(FlatType::TagUnion(tags, Variable::EMPTY_TAG_UNION)) - }); - subs.set_content(binary64, { Content::Alias( num_binary64, AliasVariables::default(), - at_binary64, + Variable::EMPTY_TAG_UNION, AliasKind::Structural, ) }); } - // define the type `Num.Float Num.Binary64` + // define the type `Num.Float Num.Binary64 := Num.Binary64` { - let tags = UnionTags::insert_into_subs( - subs, - [(TagName::Private(Symbol::NUM_AT_FLOATINGPOINT), [binary64])], - ); - subs.set_content(at_float_binary64, { - Content::Structure(FlatType::TagUnion(tags, Variable::EMPTY_TAG_UNION)) - }); - let vars = AliasVariables::insert_into_subs(subs, [binary64], []); subs.set_content(float_binary64, { - Content::Alias( - Symbol::NUM_FLOATINGPOINT, - vars, - at_binary64, - AliasKind::Structural, - ) + Content::Alias(Symbol::NUM_FLOATINGPOINT, vars, binary64, AliasKind::Opaque) + }); + } + + // define the type `Num.Num (Num.Float Num.Binary64) := Num.Float Num.Binary64` + { + let vars = AliasVariables::insert_into_subs(subs, [float_binary64], []); + subs.set_content(num_float_binary64, { + Content::Alias(Symbol::NUM_NUM, vars, float_binary64, AliasKind::Opaque) }); } // define the type `F64: Num.Num (Num.Float Num.Binary64)` { - let tags = UnionTags::insert_into_subs( - subs, - [(TagName::Private(Symbol::NUM_AT_NUM), [float_binary64])], - ); - subs.set_content(at_num_float_binary64, { - Content::Structure(FlatType::TagUnion(tags, Variable::EMPTY_TAG_UNION)) - }); - - let vars = AliasVariables::insert_into_subs(subs, [float_binary64], []); - subs.set_content(num_float_binary64, { - Content::Alias( - Symbol::NUM_NUM, - vars, - at_num_float_binary64, - AliasKind::Structural, - ) - }); - subs.set_content(var_f64, { Content::Alias( num_f64, @@ -1606,42 +1436,30 @@ fn float_type( fn define_float_types(subs: &mut Subs) { float_type( subs, - Symbol::NUM_AT_BINARY32, Symbol::NUM_BINARY32, Symbol::NUM_F32, - Variable::AT_BINARY32, Variable::BINARY32, - Variable::AT_FLOAT_BINARY32, Variable::FLOAT_BINARY32, - Variable::AT_NUM_FLOAT_BINARY32, Variable::NUM_FLOAT_BINARY32, Variable::F32, ); float_type( subs, - Symbol::NUM_AT_BINARY64, Symbol::NUM_BINARY64, Symbol::NUM_F64, - Variable::AT_BINARY64, Variable::BINARY64, - Variable::AT_FLOAT_BINARY64, Variable::FLOAT_BINARY64, - Variable::AT_NUM_FLOAT_BINARY64, Variable::NUM_FLOAT_BINARY64, Variable::F64, ); float_type( subs, - Symbol::NUM_AT_DECIMAL, Symbol::NUM_DECIMAL, Symbol::NUM_DEC, - Variable::AT_DECIMAL, Variable::DECIMAL, - Variable::AT_FLOAT_DECIMAL, Variable::FLOAT_DECIMAL, - Variable::AT_NUM_FLOAT_DECIMAL, Variable::NUM_FLOAT_DECIMAL, Variable::DEC, ); @@ -1651,12 +1469,9 @@ impl Subs { pub const RESULT_TAG_NAMES: SubsSlice = SubsSlice::new(0, 2); pub const TAG_NAME_ERR: SubsIndex = SubsIndex::new(0); pub const TAG_NAME_OK: SubsIndex = SubsIndex::new(1); - pub const NUM_AT_NUM: SubsSlice = SubsSlice::new(2, 1); - pub const NUM_AT_INTEGER: SubsSlice = SubsSlice::new(3, 1); - pub const NUM_AT_FLOATINGPOINT: SubsSlice = SubsSlice::new(4, 1); - pub const TAG_NAME_INVALID_NUM_STR: SubsIndex = SubsIndex::new(5); - pub const TAG_NAME_BAD_UTF_8: SubsIndex = SubsIndex::new(6); - pub const TAG_NAME_OUT_OF_BOUNDS: SubsIndex = SubsIndex::new(7); + pub const TAG_NAME_INVALID_NUM_STR: SubsIndex = SubsIndex::new(2); + pub const TAG_NAME_BAD_UTF_8: SubsIndex = SubsIndex::new(3); + pub const TAG_NAME_OUT_OF_BOUNDS: SubsIndex = SubsIndex::new(4); pub fn new() -> Self { Self::with_capacity(0) @@ -1670,10 +1485,6 @@ impl Subs { tag_names.push(TagName::Global("Err".into())); tag_names.push(TagName::Global("Ok".into())); - tag_names.push(TagName::Private(Symbol::NUM_AT_NUM)); - tag_names.push(TagName::Private(Symbol::NUM_AT_INTEGER)); - tag_names.push(TagName::Private(Symbol::NUM_AT_FLOATINGPOINT)); - tag_names.push(TagName::Global("InvalidNumStr".into())); tag_names.push(TagName::Global("BadUtf8".into())); tag_names.push(TagName::Global("OutOfBounds".into())); diff --git a/compiler/unify/src/unify.rs b/compiler/unify/src/unify.rs index 044ff301fe..06a4f7e399 100644 --- a/compiler/unify/src/unify.rs +++ b/compiler/unify/src/unify.rs @@ -120,6 +120,21 @@ impl Mode { fn as_eq(self) -> Self { (self - Mode::PRESENT) | Mode::EQ } + + #[cfg(debug_assertions)] + fn pretty_print(&self) -> &str { + if self.contains(Mode::EQ | Mode::RIGID_AS_FLEX) { + "~*" + } else if self.contains(Mode::PRESENT | Mode::RIGID_AS_FLEX) { + "+=*" + } else if self.contains(Mode::EQ) { + "~" + } else if self.contains(Mode::PRESENT) { + "+=" + } else { + unreachable!("Bad mode!") + } + } } #[derive(Debug)] @@ -309,7 +324,7 @@ fn debug_print_unified_types(subs: &mut Subs, ctx: &Context, opt_outcome: Option // println!("\n --------------- \n"); let content_1 = subs.get(ctx.first).content; let content_2 = subs.get(ctx.second).content; - let mode = if ctx.mode.is_eq() { "~" } else { "+=" }; + let mode = ctx.mode.pretty_print(); eprintln!( "{}{}({:?}-{:?}): {:?} {:?} {} {:?} {:?}", " ".repeat(use_depth), @@ -573,7 +588,7 @@ fn unify_opaque( // Alias wins merge(subs, ctx, Alias(symbol, args, real_var, kind)) } - RigidVar(_) | RigidAbleVar(..) => unify_pool(subs, pool, real_var, ctx.second, ctx.mode), + // RigidVar(_) | RigidAbleVar(..) => unify_pool(subs, pool, real_var, ctx.second, ctx.mode), FlexAbleVar(_, ability) if args.is_empty() => { // Opaque type wins let mut outcome = merge(subs, ctx, Alias(symbol, args, real_var, kind)); @@ -604,6 +619,15 @@ fn unify_opaque( mismatch!("{:?}", symbol) } } + RangedNumber(other_real_var, other_range_vars) => { + // This opaque might be a number, check if it unifies with the target ranged number var. + let outcome = unify_pool(subs, pool, ctx.first, *other_real_var, ctx.mode); + if outcome.mismatches.is_empty() { + check_valid_range(subs, pool, ctx.first, *other_range_vars, ctx.mode) + } else { + outcome + } + } other => { // The type on the left is an opaque, but the one on the right is not! mismatch!("Cannot unify opaque {:?} with {:?}", symbol, other) diff --git a/repl_eval/src/eval.rs b/repl_eval/src/eval.rs index b1825c7288..2079678fa2 100644 --- a/repl_eval/src/eval.rs +++ b/repl_eval/src/eval.rs @@ -283,12 +283,7 @@ fn jit_to_ast_help<'a, A: ReplApp<'a>>( macro_rules! num_helper { ($ty:ty) => { app.call_function(main_fn_name, |_, num: $ty| { - num_to_ast( - env, - number_literal_to_ast(env.arena, num), - // We determine the number from what the alias looks like. - alias_content.unwrap_or(raw_content), - ) + number_literal_to_ast(env.arena, num) }) }; } @@ -299,10 +294,11 @@ fn jit_to_ast_help<'a, A: ReplApp<'a>>( bool_to_ast(env, mem, num, raw_content) })), Layout::Builtin(Builtin::Int(int_width)) => { + use Content::*; use IntWidth::*; - let result = match (raw_content, int_width) { - (Content::Structure(FlatType::Apply(Symbol::NUM_NUM, _)), U8) => num_helper!(u8), + let result = match (alias_content, int_width) { + (Some(Alias(Symbol::NUM_UNSIGNED8, ..)), U8) => num_helper!(u8), (_, U8) => { // This is not a number, it's a tag union or something else app.call_function(main_fn_name, |mem: &A::Memory, num: u8| { @@ -507,7 +503,7 @@ fn addr_to_ast<'a, M: ReplAppMemory>( ($method: ident, $ty: ty) => {{ let num: $ty = mem.$method(addr); - num_to_ast(env, number_literal_to_ast(env.arena, num), content) + number_literal_to_ast(env.arena, num) }}; } @@ -1137,12 +1133,6 @@ fn byte_to_ast<'a, M: ReplAppMemory>( FlatType::TagUnion(tags, _) if tags.len() == 1 => { let (tag_name, payload_vars) = unpack_single_element_tag_union(env.subs, *tags); - // If this tag union represents a number, skip right to - // returning it as an Expr::Num - if let TagName::Private(Symbol::NUM_AT_NUM) = &tag_name { - return Expr::Num(env.arena.alloc_str(&value.to_string())); - } - let loc_tag_expr = { let tag_name = &tag_name.as_ident_str(env.interns, env.home); let tag_expr = if tag_name.starts_with('@') { @@ -1203,7 +1193,7 @@ fn byte_to_ast<'a, M: ReplAppMemory>( } } other => { - unreachable!("Unexpected FlatType {:?} in bool_to_ast", other); + unreachable!("Unexpected FlatType {:?} in byte_to_ast", other); } } } @@ -1213,79 +1203,7 @@ fn byte_to_ast<'a, M: ReplAppMemory>( byte_to_ast(env, mem, value, content) } other => { - unreachable!("Unexpected FlatType {:?} in bool_to_ast", other); - } - } -} - -fn num_to_ast<'a>(env: &Env<'a, '_>, num_expr: Expr<'a>, content: &Content) -> Expr<'a> { - use Content::*; - - let arena = env.arena; - - match content { - Structure(flat_type) => { - match flat_type { - FlatType::Apply(Symbol::NUM_NUM, _) => num_expr, - FlatType::TagUnion(tags, _) => { - // This was a single-tag union that got unwrapped at runtime. - debug_assert_eq!(tags.len(), 1); - - let (tag_name, payload_vars) = unpack_single_element_tag_union(env.subs, *tags); - - // If this tag union represents a number, skip right to - // returning it as an Expr::Num - if let TagName::Private(Symbol::NUM_AT_NUM) = &tag_name { - return num_expr; - } - - let loc_tag_expr = { - let tag_name = &tag_name.as_ident_str(env.interns, env.home); - let tag_expr = if tag_name.starts_with('@') { - Expr::PrivateTag(arena.alloc_str(tag_name)) - } else { - Expr::GlobalTag(arena.alloc_str(tag_name)) - }; - - &*arena.alloc(Loc { - value: tag_expr, - region: Region::zero(), - }) - }; - - let payload = { - // Since this has the layout of a number, there should be - // exactly one payload in this tag. - debug_assert_eq!(payload_vars.len(), 1); - - let var = *payload_vars.iter().next().unwrap(); - let content = env.subs.get_content_without_compacting(var); - - let loc_payload = &*arena.alloc(Loc { - value: num_to_ast(env, num_expr, content), - region: Region::zero(), - }); - - arena.alloc([loc_payload]) - }; - - Expr::Apply(loc_tag_expr, payload, CalledVia::Space) - } - other => { - panic!("Unexpected FlatType {:?} in num_to_ast", other); - } - } - } - Alias(_, _, var, _) => { - let content = env.subs.get_content_without_compacting(*var); - - num_to_ast(env, num_expr, content) - } - RangedNumber(typ, _) => { - num_to_ast(env, num_expr, env.subs.get_content_without_compacting(*typ)) - } - other => { - panic!("Unexpected FlatType {:?} in num_to_ast", other); + unreachable!("Unexpected FlatType {:?} in byte_to_ast", other); } } } diff --git a/reporting/src/error/type.rs b/reporting/src/error/type.rs index ca4d9e8c0c..d9e3fb198b 100644 --- a/reporting/src/error/type.rs +++ b/reporting/src/error/type.rs @@ -16,6 +16,12 @@ use ven_pretty::DocAllocator; const DUPLICATE_NAME: &str = "DUPLICATE NAME"; const ADD_ANNOTATIONS: &str = r#"Can more type annotations be added? Type annotations always help me give more specific messages, and I think they could help a lot in this case"#; +const OPAQUE_NUM_SYMBOLS: &[Symbol] = &[ + Symbol::NUM_NUM, + Symbol::NUM_INTEGER, + Symbol::NUM_FLOATINGPOINT, +]; + pub fn type_problem<'b>( alloc: &'b RocDocAllocator<'b>, lines: &LineInfo, @@ -2318,7 +2324,11 @@ fn to_diff<'b>( } } - (Alias(_, _, _, AliasKind::Opaque), _) | (_, Alias(_, _, _, AliasKind::Opaque)) => { + (Alias(sym, _, _, AliasKind::Opaque), _) | (_, Alias(sym, _, _, AliasKind::Opaque)) + // Skip the hint for numbers; it's not as useful as saying "this type is not a number" + if !OPAQUE_NUM_SYMBOLS.contains(&sym) => + { + dbg!(&type1, &type2); let (left, left_able) = to_doc(alloc, Parens::InFn, type1); let (right, right_able) = to_doc(alloc, Parens::InFn, type2); From b796b68df70259e8c788eded147a2cd358742825 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Mon, 25 Apr 2022 11:00:50 -0400 Subject: [PATCH 550/846] Remove dead code --- compiler/mono/src/layout.rs | 84 ------------------------------------- 1 file changed, 84 deletions(-) diff --git a/compiler/mono/src/layout.rs b/compiler/mono/src/layout.rs index 008c2ddf85..ddc5aadfa6 100644 --- a/compiler/mono/src/layout.rs +++ b/compiler/mono/src/layout.rs @@ -2712,90 +2712,6 @@ fn layout_from_num_content<'a>( } } -// TODO: removable? -#[allow(dead_code)] -fn unwrap_num_tag<'a>( - subs: &Subs, - var: Variable, - target_info: TargetInfo, -) -> Result, LayoutProblem> { - match subs.get_content_without_compacting(var) { - Content::Alias(Symbol::NUM_INTEGER, args, _, _) => { - debug_assert!(args.len() == 1); - - let precision_var = subs[args.all_variables().into_iter().next().unwrap()]; - - let precision = subs.get_content_without_compacting(precision_var); - - match precision { - Content::Alias(symbol, args, _, _) => { - debug_assert!(args.is_empty()); - - let layout = match *symbol { - Symbol::NUM_SIGNED128 => Layout::i128(), - Symbol::NUM_SIGNED64 => Layout::i64(), - Symbol::NUM_SIGNED32 => Layout::i32(), - Symbol::NUM_SIGNED16 => Layout::i16(), - Symbol::NUM_SIGNED8 => Layout::i8(), - Symbol::NUM_UNSIGNED128 => Layout::u128(), - Symbol::NUM_UNSIGNED64 => Layout::u64(), - Symbol::NUM_UNSIGNED32 => Layout::u32(), - Symbol::NUM_UNSIGNED16 => Layout::u16(), - Symbol::NUM_UNSIGNED8 => Layout::u8(), - Symbol::NUM_NATURAL => Layout::usize(target_info), - - _ => unreachable!("not a valid int variant: {:?} {:?}", symbol, args), - }; - - Ok(layout) - } - Content::FlexVar(_) | Content::RigidVar(_) => { - // default to i64 - Ok(Layout::i64()) - } - _ => unreachable!("not a valid int variant: {:?}", precision), - } - } - Content::Alias(Symbol::NUM_FLOATINGPOINT, args, _, _) => { - debug_assert!(args.len() == 1); - - let precision_var = subs[args.all_variables().into_iter().next().unwrap()]; - - let precision = subs.get_content_without_compacting(precision_var); - - match precision { - Content::Alias(Symbol::NUM_BINARY32, args, _, _) => { - debug_assert!(args.is_empty()); - - Ok(Layout::f32()) - } - Content::Alias(Symbol::NUM_BINARY64, args, _, _) => { - debug_assert!(args.is_empty()); - - Ok(Layout::f64()) - } - Content::Alias(Symbol::NUM_DECIMAL, args, _, _) => { - debug_assert!(args.is_empty()); - - Ok(Layout::Builtin(Builtin::Decimal)) - } - Content::FlexVar(_) | Content::RigidVar(_) => { - // default to f64 - Ok(Layout::f64()) - } - _ => unreachable!("not a valid float variant: {:?}", precision), - } - } - Content::FlexVar(_) | Content::RigidVar(_) => { - // If this was still a (Num *) then default to compiling it to i64 - Ok(Layout::default_integer()) - } - other => { - todo!("TODO non structure Num.@Num flat_type {:?}", other); - } - } -} - fn dict_layout_from_key_value<'a>( env: &mut Env<'a, '_>, key_var: Variable, From 7facfd0922c5137bb3a4c33ca7c20d4b9fadb993 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Mon, 25 Apr 2022 11:12:05 -0400 Subject: [PATCH 551/846] Remove private tags from solve tests --- compiler/solve/tests/solve_expr.rs | 62 ------------------------------ 1 file changed, 62 deletions(-) diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index 57ffaf6766..a8ee55ee26 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -1507,18 +1507,6 @@ mod solve_expr { ); } - #[test] - fn single_private_tag_pattern() { - infer_eq( - indoc!( - r#" - \@Foo -> 42 - "# - ), - "[ @Foo ] -> Num *", - ); - } - #[test] fn two_tag_pattern() { infer_eq( @@ -1546,18 +1534,6 @@ mod solve_expr { ); } - #[test] - fn private_tag_application() { - infer_eq( - indoc!( - r#" - @Foo "happy" 2020 - "# - ), - "[ @Foo Str (Num *) ]*", - ); - } - #[test] fn record_extraction() { infer_eq( @@ -1624,19 +1600,6 @@ mod solve_expr { ); } - #[test] - fn private_tag_with_field() { - infer_eq( - indoc!( - r#" - when @Foo "blah" is - @Foo x -> x - "# - ), - "Str", - ); - } - #[test] fn qualified_annotation_num_integer() { infer_eq( @@ -4239,31 +4202,6 @@ mod solve_expr { ); } - #[test] - fn double_tag_application_pattern_private() { - infer_eq_without_problem( - indoc!( - r#" - app "test" provides [ main ] to "./platform" - - Foo : [ @Foo [ @Bar ] I64, @Empty ] - - foo : Foo - foo = @Foo @Bar 1 - - main = - when foo is - @Foo @Bar 1 -> - @Foo @Bar 2 - - x -> - x - "# - ), - "[ @Empty, @Foo [ @Bar ] I64 ]", - ); - } - #[test] fn recursive_function_with_rigid() { infer_eq_without_problem( From 7ea4d7171be246bb1ed2f1623c18cf7e5d51d383 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Mon, 25 Apr 2022 11:12:16 -0400 Subject: [PATCH 552/846] Remove private tags reporting tests --- reporting/tests/test_reporting.rs | 120 +++--------------------------- 1 file changed, 9 insertions(+), 111 deletions(-) diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 3c3f55ffdf..9606694ccc 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -4527,30 +4527,6 @@ mod test_reporting { ) } - #[test] - fn qualified_private_tag() { - report_problem_as( - indoc!( - r#" - @Foo.Bar - "# - ), - indoc!( - r#" - ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ - - I am very confused by this expression: - - 1│ @Foo.Bar - ^^^^ - - Looks like a private tag is treated like a module name. Maybe you - wanted a qualified name, like Json.Decode.string? - "# - ), - ) - } - #[test] fn type_annotation_double_colon() { report_problem_as( @@ -5215,36 +5191,6 @@ mod test_reporting { ) } - #[test] - fn invalid_private_tag_name() { - // TODO could do better by pointing out we're parsing a function type - report_problem_as( - indoc!( - r#" - f : [ @Foo Str, @100 I64 ] - f = 0 - - f - "# - ), - indoc!( - r#" - ── WEIRD TAG NAME ──────────────────────────────────────── /code/proj/Main.roc ─ - - I am partway through parsing a tag union type, but I got stuck here: - - 1│ f : [ @Foo Str, @100 I64 ] - ^ - - I was expecting to see a private tag name. - - Hint: Private tag names start with an `@` symbol followed by an - uppercase letter, like @UID or @SecretKey. - "# - ), - ) - } - #[test] fn dict_type_formatting() { // TODO could do better by pointing out we're parsing a function type @@ -6027,54 +5973,6 @@ I need all branches in an `if` to have the same type! ) } - #[test] - fn private_tag_not_uppercase() { - report_problem_as( - indoc!( - r#" - Num.add @foo 23 - "# - ), - indoc!( - r#" - ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ - - I am trying to parse a private tag here: - - 1│ Num.add @foo 23 - ^ - - But after the `@` symbol I found a lowercase letter. All tag names - (global and private) must start with an uppercase letter, like @UUID - or @Secrets. - "# - ), - ) - } - - #[test] - fn private_tag_field_access() { - report_problem_as( - indoc!( - r#" - @UUID.bar - "# - ), - indoc!( - r#" - ── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─ - - I am very confused by this field access: - - 1│ @UUID.bar - ^^^^ - - It looks like a record field access on a private tag. - "# - ), - ) - } - #[test] fn opaque_ref_field_access() { report_problem_as( @@ -7385,10 +7283,10 @@ I need all branches in an `if` to have the same type! report_problem_as( indoc!( r#" - Job : [ @Job { inputs : List Str } ] + Job : [ Job { inputs : List Str } ] job : { inputs ? List Str } -> Job job = \{ inputs } -> - @Job { inputs } + Job { inputs } job { inputs: [ "build", "test" ] } "# @@ -7423,11 +7321,11 @@ I need all branches in an `if` to have the same type! report_problem_as( indoc!( r#" - Job : [ @Job { inputs : List Job } ] + Job : [ Job { inputs : List Job } ] job : { inputs : List Str } -> Job job = \{ inputs } -> - @Job { inputs } + Job { inputs } job { inputs: [ "build", "test" ] } "# @@ -7440,16 +7338,16 @@ I need all branches in an `if` to have the same type! 3│ job : { inputs : List Str } -> Job 4│ job = \{ inputs } -> - 5│ @Job { inputs } - ^^^^^^^^^^^^^^^ + 5│ Job { inputs } + ^^^^^^^^^^^^^^ - This `@Job` private tag application has the type: + This `Job` global tag application has the type: - [ @Job { inputs : List Str } ] + [ Job { inputs : List Str } ] But the type annotation on `job` says it should be: - [ @Job { inputs : List a } ] as a + [ Job { inputs : List a } ] as a "# ), ) From 67eb4b9faa30990dde12f6990ec2d5df99f6d1e3 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Mon, 25 Apr 2022 11:13:30 -0400 Subject: [PATCH 553/846] Remove private tags from idents --- compiler/parse/src/ast.rs | 1 - compiler/parse/src/expr.rs | 1 - compiler/parse/src/ident.rs | 49 ++------ compiler/parse/src/pattern.rs | 8 +- .../pass/apply_private_tag.expr.result-ast | 14 --- .../snapshots/pass/apply_private_tag.expr.roc | 1 - .../pass/basic_private_tag.expr.result-ast | 3 - .../snapshots/pass/basic_private_tag.expr.roc | 1 - .../private_qualified_tag.expr.result-ast | 6 - .../pass/private_qualified_tag.expr.roc | 1 - compiler/parse/tests/test_parse.rs | 111 ------------------ 11 files changed, 11 insertions(+), 185 deletions(-) delete mode 100644 compiler/parse/tests/snapshots/pass/apply_private_tag.expr.result-ast delete mode 100644 compiler/parse/tests/snapshots/pass/apply_private_tag.expr.roc delete mode 100644 compiler/parse/tests/snapshots/pass/basic_private_tag.expr.result-ast delete mode 100644 compiler/parse/tests/snapshots/pass/basic_private_tag.expr.roc delete mode 100644 compiler/parse/tests/snapshots/pass/private_qualified_tag.expr.result-ast delete mode 100644 compiler/parse/tests/snapshots/pass/private_qualified_tag.expr.roc diff --git a/compiler/parse/src/ast.rs b/compiler/parse/src/ast.rs index 83d3bbfe34..4c3a299fdf 100644 --- a/compiler/parse/src/ast.rs +++ b/compiler/parse/src/ast.rs @@ -579,7 +579,6 @@ impl<'a> Pattern<'a> { pub fn from_ident(arena: &'a Bump, ident: Ident<'a>) -> Pattern<'a> { match ident { Ident::GlobalTag(string) => Pattern::GlobalTag(string), - Ident::PrivateTag(string) => Pattern::PrivateTag(string), Ident::OpaqueRef(string) => Pattern::OpaqueRef(string), Ident::Access { module_name, parts } => { if parts.len() == 1 { diff --git a/compiler/parse/src/expr.rs b/compiler/parse/src/expr.rs index 760e3fb076..cf28dc2a41 100644 --- a/compiler/parse/src/expr.rs +++ b/compiler/parse/src/expr.rs @@ -2438,7 +2438,6 @@ where fn ident_to_expr<'a>(arena: &'a Bump, src: Ident<'a>) -> Expr<'a> { match src { Ident::GlobalTag(string) => Expr::GlobalTag(string), - Ident::PrivateTag(string) => Expr::PrivateTag(string), Ident::OpaqueRef(string) => Expr::OpaqueRef(string), Ident::Access { module_name, parts } => { let mut iter = parts.iter(); diff --git a/compiler/parse/src/ident.rs b/compiler/parse/src/ident.rs index c2afb90038..c7e917ec4d 100644 --- a/compiler/parse/src/ident.rs +++ b/compiler/parse/src/ident.rs @@ -36,8 +36,6 @@ impl<'a> From<&'a UppercaseIdent<'a>> for &'a str { pub enum Ident<'a> { /// Foo or Bar GlobalTag(&'a str), - /// @Foo or @Bar - PrivateTag(&'a str), /// $Foo or $Bar // TODO(opaques): $->@ in the above comment OpaqueRef(&'a str), @@ -57,7 +55,7 @@ impl<'a> Ident<'a> { use self::Ident::*; match self { - GlobalTag(string) | PrivateTag(string) | OpaqueRef(string) => string.len(), + GlobalTag(string) | OpaqueRef(string) => string.len(), Access { module_name, parts } => { let mut len = if module_name.is_empty() { 0 @@ -101,24 +99,7 @@ pub fn lowercase_ident<'a>() -> impl Parser<'a, &'a str, ()> { } pub fn tag_name<'a>() -> impl Parser<'a, &'a str, ()> { - move |arena, state: State<'a>| { - if state.bytes().starts_with(b"@") { - match chomp_private_tag_or_opaque( - /* private tag */ true, - state.bytes(), - state.pos(), - ) { - Err(BadIdent::Start(_)) => Err((NoProgress, (), state)), - Err(_) => Err((MadeProgress, (), state)), - Ok(ident) => { - let width = ident.len(); - Ok((MadeProgress, ident, state.advance(width))) - } - } - } else { - uppercase_ident().parse(arena, state) - } - } + move |arena, state: State<'a>| uppercase_ident().parse(arena, state) } /// This could be: @@ -311,21 +292,13 @@ fn chomp_accessor(buffer: &[u8], pos: Position) -> Result<&str, BadIdent> { } } -/// a `@Token` private tag -fn chomp_private_tag_or_opaque( - private_tag: bool, // If false, opaque - buffer: &[u8], - pos: Position, -) -> Result<&str, BadIdent> { - // assumes the leading `@` has NOT been chomped already - debug_assert_eq!(buffer.get(0), Some(if private_tag { &b'@' } else { &b'$' })); +/// a `$Token` opaque +fn chomp_opaque_ref(buffer: &[u8], pos: Position) -> Result<&str, BadIdent> { + // assumes the leading `$` has NOT been chomped already + debug_assert_eq!(buffer.get(0), Some(&b'$')); use encode_unicode::CharExt; - let bad_ident = if private_tag { - BadIdent::BadPrivateTag - } else { - BadIdent::BadOpaqueRef - }; + let bad_ident = BadIdent::BadOpaqueRef; match chomp_uppercase_part(&buffer[1..]) { Ok(name) => { @@ -362,15 +335,11 @@ fn chomp_identifier_chain<'a>( } Err(fail) => return Err((1, fail)), }, - c @ ('@' | '$') => match chomp_private_tag_or_opaque(c == '@', buffer, pos) { + '$' => match chomp_opaque_ref(buffer, pos) { Ok(tagname) => { let bytes_parsed = tagname.len(); - let ident = if c == '@' { - Ident::PrivateTag - } else { - Ident::OpaqueRef - }; + let ident = Ident::OpaqueRef; return Ok((bytes_parsed as u32, ident(tagname))); } diff --git a/compiler/parse/src/pattern.rs b/compiler/parse/src/pattern.rs index 09e676075f..b535522614 100644 --- a/compiler/parse/src/pattern.rs +++ b/compiler/parse/src/pattern.rs @@ -240,14 +240,10 @@ fn loc_ident_pattern_help<'a>( Ok((MadeProgress, loc_tag, state)) } } - Ident::PrivateTag(name) | Ident::OpaqueRef(name) => { + Ident::OpaqueRef(name) => { let loc_pat = Loc { region: loc_ident.region, - value: if matches!(loc_ident.value, Ident::PrivateTag(..)) { - Pattern::PrivateTag(name) - } else { - Pattern::OpaqueRef(name) - }, + value: Pattern::OpaqueRef(name), }; // Make sure `@Foo Bar 1` is parsed as `@Foo (Bar) 1`, and not `@Foo (Bar 1)` diff --git a/compiler/parse/tests/snapshots/pass/apply_private_tag.expr.result-ast b/compiler/parse/tests/snapshots/pass/apply_private_tag.expr.result-ast deleted file mode 100644 index 185e681f5b..0000000000 --- a/compiler/parse/tests/snapshots/pass/apply_private_tag.expr.result-ast +++ /dev/null @@ -1,14 +0,0 @@ -Apply( - @0-5 PrivateTag( - "@Whee", - ), - [ - @6-8 Num( - "12", - ), - @9-11 Num( - "34", - ), - ], - Space, -) diff --git a/compiler/parse/tests/snapshots/pass/apply_private_tag.expr.roc b/compiler/parse/tests/snapshots/pass/apply_private_tag.expr.roc deleted file mode 100644 index ba23819345..0000000000 --- a/compiler/parse/tests/snapshots/pass/apply_private_tag.expr.roc +++ /dev/null @@ -1 +0,0 @@ -@Whee 12 34 \ No newline at end of file diff --git a/compiler/parse/tests/snapshots/pass/basic_private_tag.expr.result-ast b/compiler/parse/tests/snapshots/pass/basic_private_tag.expr.result-ast deleted file mode 100644 index 1761f76aa1..0000000000 --- a/compiler/parse/tests/snapshots/pass/basic_private_tag.expr.result-ast +++ /dev/null @@ -1,3 +0,0 @@ -PrivateTag( - "@Whee", -) diff --git a/compiler/parse/tests/snapshots/pass/basic_private_tag.expr.roc b/compiler/parse/tests/snapshots/pass/basic_private_tag.expr.roc deleted file mode 100644 index 476a77dfc2..0000000000 --- a/compiler/parse/tests/snapshots/pass/basic_private_tag.expr.roc +++ /dev/null @@ -1 +0,0 @@ -@Whee \ No newline at end of file diff --git a/compiler/parse/tests/snapshots/pass/private_qualified_tag.expr.result-ast b/compiler/parse/tests/snapshots/pass/private_qualified_tag.expr.result-ast deleted file mode 100644 index b770fe6077..0000000000 --- a/compiler/parse/tests/snapshots/pass/private_qualified_tag.expr.result-ast +++ /dev/null @@ -1,6 +0,0 @@ -MalformedIdent( - "@One.Two.Whee", - BadPrivateTag( - @4, - ), -) diff --git a/compiler/parse/tests/snapshots/pass/private_qualified_tag.expr.roc b/compiler/parse/tests/snapshots/pass/private_qualified_tag.expr.roc deleted file mode 100644 index e5c825a346..0000000000 --- a/compiler/parse/tests/snapshots/pass/private_qualified_tag.expr.roc +++ /dev/null @@ -1 +0,0 @@ -@One.Two.Whee \ No newline at end of file diff --git a/compiler/parse/tests/test_parse.rs b/compiler/parse/tests/test_parse.rs index a9f1b70f5e..daf87904b0 100644 --- a/compiler/parse/tests/test_parse.rs +++ b/compiler/parse/tests/test_parse.rs @@ -134,7 +134,6 @@ mod test_parse { pass/annotated_tag_destructure.expr, pass/apply_global_tag.expr, pass/apply_parenthetical_global_tag_args.expr, - pass/apply_private_tag.expr, pass/apply_three_args.expr, pass/apply_two_args.expr, pass/apply_unary_negation.expr, @@ -143,7 +142,6 @@ mod test_parse { pass/basic_docs.expr, pass/basic_field.expr, pass/basic_global_tag.expr, - pass/basic_private_tag.expr, pass/basic_var.expr, pass/closure_with_underscores.expr, pass/comment_after_def.module, @@ -233,7 +231,6 @@ mod test_parse { pass/pos_inf_float.expr, pass/positive_float.expr, pass/positive_int.expr, - pass/private_qualified_tag.expr, pass/provides_type.header, pass/qualified_field.expr, pass/qualified_global_tag.expr, @@ -656,114 +653,6 @@ mod test_parse { // ); // } - // #[test] - // fn ann_private_open_union() { - // let arena = Bump::new(); - // let newline = bumpalo::vec![in &arena; Newline]; - // let newlines = bumpalo::vec![in &arena; Newline, Newline]; - // let tag1 = Tag::Private { - // name: Located::new(0, 0, 8, 13, "@True"), - // args: &[], - // }; - // let tag2arg1 = Located::new(0, 0, 24, 27, TypeAnnotation::Apply("", "Two", &[])); - // let tag2arg2 = Located::new(0, 0, 28, 34, TypeAnnotation::Apply("", "Things", &[])); - // let tag2args = bumpalo::vec![in &arena; tag2arg1, tag2arg2]; - // let tag2 = Tag::Private { - // name: Located::new(0, 0, 15, 23, "@Perhaps"), - // args: tag2args.into_bump_slice(), - // }; - // let tags = bumpalo::vec![in &arena; - // Located::new(0, 0, 8, 13, tag1), - // Located::new(0, 0, 15, 34, tag2) - // ]; - // let loc_wildcard = Located::new(0, 0, 36, 37, TypeAnnotation::Wildcard); - // let applied_ann = TypeAnnotation::TagUnion { - // tags: tags.into_bump_slice(), - // ext: Some(arena.alloc(loc_wildcard)), - // }; - // let signature = Def::Annotation( - // Located::new(0, 0, 0, 3, Identifier("foo")), - // Located::new(0, 0, 6, 37, applied_ann), - // ); - // let def = Def::Body( - // arena.alloc(Located::new(1, 1, 0, 3, Identifier("foo"))), - // arena.alloc(Located::new(1, 1, 6, 10, Expr::GlobalTag("True"))), - // ); - // let spaced_def = Def::SpaceBefore(arena.alloc(def), newline.into_bump_slice()); - // let loc_def = &*arena.alloc(Located::new(1, 1, 0, 10, spaced_def)); - - // let loc_ann = &*arena.alloc(Located::new(0, 0, 0, 3, signature)); - // let defs = &[loc_ann, loc_def]; - // let ret = Expr::SpaceBefore(arena.alloc(Num("42")), newlines.into_bump_slice()); - // let loc_ret = Located::new(3, 3, 0, 2, ret); - // let expected = Defs(defs, arena.alloc(loc_ret)); - - // assert_parses_to( - // indoc!( - // r#" - // foo : [ @True, @Perhaps Two Things ]* - // foo = True - - // 42 - // "# - // ), - // expected, - // ); - // } - - // #[test] - // fn ann_private_closed_union() { - // let arena = Bump::new(); - // let newline = bumpalo::vec![in &arena; Newline]; - // let newlines = bumpalo::vec![in &arena; Newline, Newline]; - // let tag1 = Tag::Private { - // name: Located::new(0, 0, 8, 13, "@True"), - // args: &[], - // }; - // let tag2arg = Located::new(0, 0, 24, 29, TypeAnnotation::Apply("", "Thing", &[])); - // let tag2args = bumpalo::vec![in &arena; tag2arg]; - // let tag2 = Tag::Private { - // name: Located::new(0, 0, 15, 23, "@Perhaps"), - // args: tag2args.into_bump_slice(), - // }; - // let tags = bumpalo::vec![in &arena; - // Located::new(0, 0, 8, 13, tag1), - // Located::new(0, 0, 15, 29, tag2) - // ]; - // let applied_ann = TypeAnnotation::TagUnion { - // tags: tags.into_bump_slice(), - // ext: None, - // }; - // let signature = Def::Annotation( - // Located::new(0, 0, 0, 3, Identifier("foo")), - // Located::new(0, 0, 6, 31, applied_ann), - // ); - // let def = Def::Body( - // arena.alloc(Located::new(1, 1, 0, 3, Identifier("foo"))), - // arena.alloc(Located::new(1, 1, 6, 10, Expr::GlobalTag("True"))), - // ); - // let spaced_def = Def::SpaceBefore(arena.alloc(def), newline.into_bump_slice()); - // let loc_def = &*arena.alloc(Located::new(1, 1, 0, 10, spaced_def)); - - // let loc_ann = &*arena.alloc(Located::new(0, 0, 0, 3, signature)); - // let defs = &[loc_ann, loc_def]; - // let ret = Expr::SpaceBefore(arena.alloc(Num("42")), newlines.into_bump_slice()); - // let loc_ret = Located::new(3, 3, 0, 2, ret); - // let expected = Defs(defs, arena.alloc(loc_ret)); - - // assert_parses_to( - // indoc!( - // r#" - // foo : [ @True, @Perhaps Thing ] - // foo = True - - // 42 - // "# - // ), - // expected, - // ); - // } - // #[test] // fn ann_global_open_union() { // let arena = Bump::new(); From 1ed9cf551a43ec358e5ab25f3471bfd6a6e8b14b Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Mon, 25 Apr 2022 11:20:37 -0400 Subject: [PATCH 554/846] Remove private tags from Ast --- ast/src/lang/core/expr/expr_to_expr2.rs | 25 ----------------------- ast/src/lang/core/pattern.rs | 21 ------------------- ast/src/lang/core/types.rs | 15 -------------- cli/src/format.rs | 6 ------ compiler/can/src/annotation.rs | 27 +------------------------ compiler/can/src/expr.rs | 17 ---------------- compiler/can/src/operator.rs | 1 - compiler/can/src/pattern.rs | 22 -------------------- compiler/fmt/src/annotation.rs | 22 +------------------- compiler/fmt/src/expr.rs | 3 +-- compiler/fmt/src/pattern.rs | 3 +-- compiler/load_internal/src/docs.rs | 4 +--- compiler/parse/src/ast.rs | 10 +-------- compiler/parse/src/expr.rs | 1 - compiler/parse/src/type_annotation.rs | 13 +++--------- repl_eval/src/eval.rs | 18 +++-------------- 16 files changed, 12 insertions(+), 196 deletions(-) diff --git a/ast/src/lang/core/expr/expr_to_expr2.rs b/ast/src/lang/core/expr/expr_to_expr2.rs index 126f885499..f19b5a7dfc 100644 --- a/ast/src/lang/core/expr/expr_to_expr2.rs +++ b/ast/src/lang/core/expr/expr_to_expr2.rs @@ -185,20 +185,6 @@ pub fn expr_to_expr2<'a>( Output::default(), ) } - PrivateTag(name) => { - // a private tag without any arguments - let ident_id = env.ident_ids.get_or_insert(&(*name).into()); - let name = Symbol::new(env.home, ident_id); - ( - Expr2::PrivateTag { - name, - variant_var: env.var_store.fresh(), - ext_var: env.var_store.fresh(), - arguments: PoolVec::empty(env.pool), - }, - Output::default(), - ) - } RecordUpdate { fields, @@ -568,17 +554,6 @@ pub fn expr_to_expr2<'a>( name, arguments: args, }, - Expr2::PrivateTag { - variant_var, - ext_var, - name, - .. - } => Expr2::PrivateTag { - variant_var, - ext_var, - name, - arguments: args, - }, _ => { // This could be something like ((if True then fn1 else fn2) arg1 arg2). let fn_expr_id = env.add(fn_expr, fn_region); diff --git a/ast/src/lang/core/pattern.rs b/ast/src/lang/core/pattern.rs index 13d91a9850..9e10ba62e3 100644 --- a/ast/src/lang/core/pattern.rs +++ b/ast/src/lang/core/pattern.rs @@ -280,17 +280,6 @@ pub fn to_pattern2<'a>( arguments: PoolVec::empty(env.pool), } } - PrivateTag(name) => { - let ident_id = env.ident_ids.get_or_insert(&(*name).into()); - - // Canonicalize the tag's name. - Pattern2::PrivateTag { - whole_var: env.var_store.fresh(), - ext_var: env.var_store.fresh(), - tag_name: Symbol::new(env.home, ident_id), - arguments: PoolVec::empty(env.pool), - } - } OpaqueRef(..) => todo_opaques!(), @@ -319,16 +308,6 @@ pub fn to_pattern2<'a>( tag_name: PoolStr::new(name, env.pool), arguments: can_patterns, }, - PrivateTag(name) => { - let ident_id = env.ident_ids.get_or_insert(&name.into()); - - Pattern2::PrivateTag { - whole_var: env.var_store.fresh(), - ext_var: env.var_store.fresh(), - tag_name: Symbol::new(env.home, ident_id), - arguments: can_patterns, - } - } _ => unreachable!("Other patterns cannot be applied"), } } diff --git a/ast/src/lang/core/types.rs b/ast/src/lang/core/types.rs index 59f727d2f7..d65d2bb059 100644 --- a/ast/src/lang/core/types.rs +++ b/ast/src/lang/core/types.rs @@ -702,21 +702,6 @@ fn can_tags<'a>( break 'inner tag_name; } - Tag::Private { name, args } => { - let ident_id = env.ident_ids.get_or_insert(&name.value.into()); - let symbol = Symbol::new(env.home, ident_id); - - let arg_types = PoolVec::with_capacity(args.len() as u32, env.pool); - - for (type_id, loc_arg) in arg_types.iter_node_ids().zip(args.iter()) { - as_type_id(env, scope, rigids, type_id, &loc_arg.value, loc_arg.region); - } - - let tag_name = TagName::Private(symbol); - tag_types.push((tag_name.clone(), arg_types)); - - break 'inner tag_name; - } Tag::SpaceBefore(nested, _) | Tag::SpaceAfter(nested, _) => { // check the nested tag instead tag = nested; diff --git a/cli/src/format.rs b/cli/src/format.rs index ea77c5f1dc..3913838f85 100644 --- a/cli/src/format.rs +++ b/cli/src/format.rs @@ -618,7 +618,6 @@ impl<'a> RemoveSpaces<'a> for Expr<'a> { Expr::Var { module_name, ident } => Expr::Var { module_name, ident }, Expr::Underscore(a) => Expr::Underscore(a), Expr::GlobalTag(a) => Expr::GlobalTag(a), - Expr::PrivateTag(a) => Expr::PrivateTag(a), Expr::OpaqueRef(a) => Expr::OpaqueRef(a), Expr::Closure(a, b) => Expr::Closure( arena.alloc(a.remove_spaces(arena)), @@ -670,7 +669,6 @@ impl<'a> RemoveSpaces<'a> for Pattern<'a> { match *self { Pattern::Identifier(a) => Pattern::Identifier(a), Pattern::GlobalTag(a) => Pattern::GlobalTag(a), - Pattern::PrivateTag(a) => Pattern::PrivateTag(a), Pattern::OpaqueRef(a) => Pattern::OpaqueRef(a), Pattern::Apply(a, b) => Pattern::Apply( arena.alloc(a.remove_spaces(arena)), @@ -757,10 +755,6 @@ impl<'a> RemoveSpaces<'a> for Tag<'a> { name: name.remove_spaces(arena), args: args.remove_spaces(arena), }, - Tag::Private { name, args } => Tag::Private { - name: name.remove_spaces(arena), - args: args.remove_spaces(arena), - }, Tag::Malformed(a) => Tag::Malformed(a), Tag::SpaceBefore(a, _) => a.remove_spaces(arena), Tag::SpaceAfter(a, _) => a.remove_spaces(arena), diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index b6bdff3e87..fe07bccbab 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -365,7 +365,7 @@ pub fn find_type_def_symbols( while let Some(tag) = inner_stack.pop() { match tag { - Tag::Global { args, .. } | Tag::Private { args, .. } => { + Tag::Global { args, .. } => { for t in args.iter() { stack.push(&t.value); } @@ -1253,31 +1253,6 @@ fn can_tags<'a>( break 'inner tag_name; } - Tag::Private { name, args } => { - let ident_id = env.ident_ids.get_or_insert(&name.value.into()); - let symbol = Symbol::new(env.home, ident_id); - let mut arg_types = Vec::with_capacity(args.len()); - - for arg in args.iter() { - let ann = can_annotation_help( - env, - &arg.value, - arg.region, - scope, - var_store, - introduced_variables, - local_aliases, - references, - ); - - arg_types.push(ann); - } - - let tag_name = TagName::Private(symbol); - tag_types.push((tag_name.clone(), arg_types)); - - break 'inner tag_name; - } Tag::SpaceBefore(nested, _) | Tag::SpaceAfter(nested, _) => { // check the nested tag instead tag = nested; diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index c8e85d3166..31d476d2b8 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -830,23 +830,6 @@ pub fn canonicalize_expr<'a>( Output::default(), ) } - ast::Expr::PrivateTag(tag) => { - let variant_var = var_store.fresh(); - let ext_var = var_store.fresh(); - let tag_ident = env.ident_ids.get_or_insert(&(*tag).into()); - let symbol = Symbol::new(env.home, tag_ident); - let lambda_set_symbol = env.gen_unique_symbol(); - - ( - ZeroArgumentTag { - name: TagName::Private(symbol), - variant_var, - ext_var, - closure_name: lambda_set_symbol, - }, - Output::default(), - ) - } ast::Expr::OpaqueRef(opaque_ref) => { // If we're here, the opaque reference is definitely not wrapping an argument - wrapped // arguments are handled in the Apply branch. diff --git a/compiler/can/src/operator.rs b/compiler/can/src/operator.rs index 5b1facf5b5..85a5bc1c5f 100644 --- a/compiler/can/src/operator.rs +++ b/compiler/can/src/operator.rs @@ -151,7 +151,6 @@ pub fn desugar_expr<'a>(arena: &'a Bump, loc_expr: &'a Loc>) -> &'a Loc | MalformedClosure | PrecedenceConflict { .. } | GlobalTag(_) - | PrivateTag(_) | OpaqueRef(_) => loc_expr, Access(sub_expr, paths) => { diff --git a/compiler/can/src/pattern.rs b/compiler/can/src/pattern.rs index fac8a67365..7fb54af2ea 100644 --- a/compiler/can/src/pattern.rs +++ b/compiler/can/src/pattern.rs @@ -269,17 +269,6 @@ pub fn canonicalize_pattern<'a>( arguments: vec![], } } - PrivateTag(name) => { - let ident_id = env.ident_ids.get_or_insert(&(*name).into()); - - // Canonicalize the tag's name. - Pattern::AppliedTag { - whole_var: var_store.fresh(), - ext_var: var_store.fresh(), - tag_name: TagName::Private(Symbol::new(env.home, ident_id)), - arguments: vec![], - } - } OpaqueRef(name) => { // If this opaque ref had an argument, we would be in the "Apply" branch. let loc_name = Loc::at(region, (*name).into()); @@ -314,17 +303,6 @@ pub fn canonicalize_pattern<'a>( arguments: can_patterns, } } - PrivateTag(name) => { - let ident_id = env.ident_ids.get_or_insert(&name.into()); - let tag_name = TagName::Private(Symbol::new(env.home, ident_id)); - - Pattern::AppliedTag { - whole_var: var_store.fresh(), - ext_var: var_store.fresh(), - tag_name, - arguments: can_patterns, - } - } OpaqueRef(name) => match scope.lookup_opaque_ref(name, tag.region) { Ok((opaque, opaque_def)) => { diff --git a/compiler/fmt/src/annotation.rs b/compiler/fmt/src/annotation.rs index 8a6184f944..d28868ccf8 100644 --- a/compiler/fmt/src/annotation.rs +++ b/compiler/fmt/src/annotation.rs @@ -468,9 +468,7 @@ impl<'a> Formattable for Tag<'a> { use self::Tag::*; match self { - Global { args, .. } | Private { args, .. } => { - args.iter().any(|arg| (&arg.value).is_multiline()) - } + Global { args, .. } => args.iter().any(|arg| (&arg.value).is_multiline()), Tag::SpaceBefore(_, _) | Tag::SpaceAfter(_, _) => true, Malformed(text) => text.chars().any(|c| c == '\n'), } @@ -503,24 +501,6 @@ impl<'a> Formattable for Tag<'a> { } } } - Tag::Private { name, args } => { - debug_assert!(name.value.starts_with('@')); - buf.indent(indent); - buf.push_str(name.value); - if is_multiline { - let arg_indent = indent + INDENT; - - for arg in *args { - buf.newline(); - arg.format_with_options(buf, Parens::InApply, Newlines::No, arg_indent); - } - } else { - for arg in *args { - buf.spaces(1); - arg.format_with_options(buf, Parens::InApply, Newlines::No, indent); - } - } - } Tag::SpaceBefore(_, _) | Tag::SpaceAfter(_, _) => unreachable!(), Tag::Malformed(raw) => { buf.indent(indent); diff --git a/compiler/fmt/src/expr.rs b/compiler/fmt/src/expr.rs index c8aafa6cff..c6d059237d 100644 --- a/compiler/fmt/src/expr.rs +++ b/compiler/fmt/src/expr.rs @@ -38,7 +38,6 @@ impl<'a> Formattable for Expr<'a> { | MalformedIdent(_, _) | MalformedClosure | GlobalTag(_) - | PrivateTag(_) | OpaqueRef(_) => false, // These expressions always have newlines @@ -273,7 +272,7 @@ impl<'a> Formattable for Expr<'a> { buf.indent(indent); buf.push_str(string); } - GlobalTag(string) | PrivateTag(string) | OpaqueRef(string) => { + GlobalTag(string) | OpaqueRef(string) => { buf.indent(indent); buf.push_str(string) } diff --git a/compiler/fmt/src/pattern.rs b/compiler/fmt/src/pattern.rs index c903ad9596..2d4d5357a8 100644 --- a/compiler/fmt/src/pattern.rs +++ b/compiler/fmt/src/pattern.rs @@ -29,7 +29,6 @@ impl<'a> Formattable for Pattern<'a> { Pattern::Identifier(_) | Pattern::GlobalTag(_) - | Pattern::PrivateTag(_) | Pattern::OpaqueRef(_) | Pattern::Apply(_, _) | Pattern::NumLiteral(..) @@ -58,7 +57,7 @@ impl<'a> Formattable for Pattern<'a> { buf.indent(indent); buf.push_str(string) } - GlobalTag(name) | PrivateTag(name) | OpaqueRef(name) => { + GlobalTag(name) | OpaqueRef(name) => { buf.indent(indent); buf.push_str(name); } diff --git a/compiler/load_internal/src/docs.rs b/compiler/load_internal/src/docs.rs index 0400a53533..42dc9d4c77 100644 --- a/compiler/load_internal/src/docs.rs +++ b/compiler/load_internal/src/docs.rs @@ -404,8 +404,7 @@ fn record_field_to_doc( } } -// The Option here represents if it is private. Private tags -// evaluate to `None`. +// The Option here represents if it is malformed. fn tag_to_doc(in_func_ann: bool, tag: ast::Tag) -> Option { match tag { ast::Tag::Global { name, args } => Some(Tag { @@ -420,7 +419,6 @@ fn tag_to_doc(in_func_ann: bool, tag: ast::Tag) -> Option { type_vars }, }), - ast::Tag::Private { .. } => None, ast::Tag::SpaceBefore(&sub_tag, _) => tag_to_doc(in_func_ann, sub_tag), ast::Tag::SpaceAfter(&sub_tag, _) => tag_to_doc(in_func_ann, sub_tag), ast::Tag::Malformed(_) => None, diff --git a/compiler/parse/src/ast.rs b/compiler/parse/src/ast.rs index 4c3a299fdf..6880e42086 100644 --- a/compiler/parse/src/ast.rs +++ b/compiler/parse/src/ast.rs @@ -189,7 +189,6 @@ pub enum Expr<'a> { // Tags GlobalTag(&'a str), - PrivateTag(&'a str), // Reference to an opaque type, e.g. $Opaq // TODO(opaques): $->@ in the above comment @@ -446,11 +445,6 @@ pub enum Tag<'a> { args: &'a [Loc>], }, - Private { - name: Loc<&'a str>, - args: &'a [Loc>], - }, - // We preserve this for the formatter; canonicalization ignores it. SpaceBefore(&'a Tag<'a>, &'a [CommentOrNewline<'a>]), SpaceAfter(&'a Tag<'a>, &'a [CommentOrNewline<'a>]), @@ -523,7 +517,6 @@ pub enum Pattern<'a> { Identifier(&'a str), GlobalTag(&'a str), - PrivateTag(&'a str), OpaqueRef(&'a str), @@ -628,7 +621,6 @@ impl<'a> Pattern<'a> { match (self, other) { (Identifier(x), Identifier(y)) => x == y, (GlobalTag(x), GlobalTag(y)) => x == y, - (PrivateTag(x), PrivateTag(y)) => x == y, (Apply(constructor_x, args_x), Apply(constructor_y, args_y)) => { let equivalent_args = args_x .iter() @@ -926,7 +918,7 @@ impl<'a> Expr<'a> { } pub fn is_tag(&self) -> bool { - matches!(self, Expr::GlobalTag(_) | Expr::PrivateTag(_)) + matches!(self, Expr::GlobalTag(_)) } } diff --git a/compiler/parse/src/expr.rs b/compiler/parse/src/expr.rs index cf28dc2a41..04074aa9fb 100644 --- a/compiler/parse/src/expr.rs +++ b/compiler/parse/src/expr.rs @@ -1764,7 +1764,6 @@ fn expr_to_pattern_help<'a>(arena: &'a Bump, expr: &Expr<'a>) -> Result Ok(Pattern::Underscore(opt_name)), Expr::GlobalTag(value) => Ok(Pattern::GlobalTag(value)), - Expr::PrivateTag(value) => Ok(Pattern::PrivateTag(value)), Expr::OpaqueRef(value) => Ok(Pattern::OpaqueRef(value)), Expr::Apply(loc_val, loc_args, _) => { let region = loc_val.region; diff --git a/compiler/parse/src/type_annotation.rs b/compiler/parse/src/type_annotation.rs index 45b34b7157..45b1d39216 100644 --- a/compiler/parse/src/type_annotation.rs +++ b/compiler/parse/src/type_annotation.rs @@ -214,16 +214,9 @@ fn tag_type<'a>(min_indent: u32) -> impl Parser<'a, Tag<'a>, ETypeTagUnion<'a>> let (_, args, state) = specialize_ref(ETypeTagUnion::Type, loc_applied_args_e(min_indent)) .parse(arena, state)?; - let result = if name.value.starts_with('@') { - Tag::Private { - name, - args: args.into_bump_slice(), - } - } else { - Tag::Global { - name, - args: args.into_bump_slice(), - } + let result = Tag::Global { + name, + args: args.into_bump_slice(), }; Ok((MadeProgress, result, state)) diff --git a/repl_eval/src/eval.rs b/repl_eval/src/eval.rs index 2079678fa2..44acb07ae9 100644 --- a/repl_eval/src/eval.rs +++ b/repl_eval/src/eval.rs @@ -475,11 +475,7 @@ fn tag_name_to_expr<'a>(env: &Env<'a, '_>, tag_name: &TagName) -> Expr<'a> { env.arena .alloc_str(&tag_name.as_ident_str(env.interns, env.home)), ), - TagName::Private(_) => Expr::PrivateTag( - env.arena - .alloc_str(&tag_name.as_ident_str(env.interns, env.home)), - ), - TagName::Closure(_) => unreachable!("User cannot type this"), + TagName::Private(_) | TagName::Closure(_) => unreachable!("User cannot type this"), } } @@ -1052,11 +1048,7 @@ fn bool_to_ast<'a, M: ReplAppMemory>( let loc_tag_expr = { let tag_name = &tag_name.as_ident_str(env.interns, env.home); - let tag_expr = if tag_name.starts_with('@') { - Expr::PrivateTag(arena.alloc_str(tag_name)) - } else { - Expr::GlobalTag(arena.alloc_str(tag_name)) - }; + let tag_expr = Expr::GlobalTag(arena.alloc_str(tag_name)); &*arena.alloc(Loc { value: tag_expr, @@ -1135,11 +1127,7 @@ fn byte_to_ast<'a, M: ReplAppMemory>( let loc_tag_expr = { let tag_name = &tag_name.as_ident_str(env.interns, env.home); - let tag_expr = if tag_name.starts_with('@') { - Expr::PrivateTag(arena.alloc_str(tag_name)) - } else { - Expr::GlobalTag(arena.alloc_str(tag_name)) - }; + let tag_expr = Expr::GlobalTag(arena.alloc_str(tag_name)); &*arena.alloc(Loc { value: tag_expr, From 37b9a34448ab2f7a57a4216705712926f24a1476 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Mon, 25 Apr 2022 11:22:32 -0400 Subject: [PATCH 555/846] Remove private tags from Ast2 --- ast/src/constrain.rs | 51 +-------------------------------- ast/src/lang/core/expr/expr2.rs | 6 ---- ast/src/lang/core/pattern.rs | 10 ++----- 3 files changed, 3 insertions(+), 64 deletions(-) diff --git a/ast/src/constrain.rs b/ast/src/constrain.rs index 09526fb902..5bfc97131f 100644 --- a/ast/src/constrain.rs +++ b/ast/src/constrain.rs @@ -264,25 +264,6 @@ pub fn constrain_expr<'a>( *variant_var, ) } - Expr2::PrivateTag { - name, - arguments, - ext_var, - variant_var, - } => { - let tag_name = TagName::Private(*name); - - constrain_tag( - arena, - env, - expected, - region, - tag_name, - arguments, - *ext_var, - *variant_var, - ) - } Expr2::Call { args, expr_var, @@ -1631,27 +1612,6 @@ pub fn constrain_pattern<'a>( } => { let tag_name = TagName::Global(name.as_str(env.pool).into()); - constrain_tag_pattern( - arena, - env, - region, - expected, - state, - *whole_var, - *ext_var, - arguments, - tag_name, - destruct_position, - ); - } - PrivateTag { - whole_var, - ext_var, - tag_name: name, - arguments, - } => { - let tag_name = TagName::Private(*name); - constrain_tag_pattern( arena, env, @@ -1930,16 +1890,7 @@ fn _num_signed64(pool: &mut Pool) -> Type2 { #[inline(always)] fn num_unsigned32(pool: &mut Pool) -> Type2 { - let alias_content = Type2::TagUnion( - PoolVec::new( - std::iter::once(( - TagName::Private(Symbol::NUM_UNSIGNED32), - PoolVec::empty(pool), - )), - pool, - ), - pool.add(Type2::EmptyTagUnion), - ); + let alias_content = Type2::EmptyTagUnion; Type2::Alias( Symbol::NUM_UNSIGNED32, diff --git a/ast/src/lang/core/expr/expr2.rs b/ast/src/lang/core/expr/expr2.rs index de03d27dde..f7326d85b8 100644 --- a/ast/src/lang/core/expr/expr2.rs +++ b/ast/src/lang/core/expr/expr2.rs @@ -154,12 +154,6 @@ pub enum Expr2 { ext_var: Variable, // 4B arguments: PoolVec<(Variable, ExprId)>, // 8B }, - PrivateTag { - name: Symbol, // 8B - variant_var: Variable, // 4B - ext_var: Variable, // 4B - arguments: PoolVec<(Variable, ExprId)>, // 8B - }, Blank, // Rendered as empty box in editor // Compiles, but will crash if reached diff --git a/ast/src/lang/core/pattern.rs b/ast/src/lang/core/pattern.rs index 9e10ba62e3..9ae9c5db9b 100644 --- a/ast/src/lang/core/pattern.rs +++ b/ast/src/lang/core/pattern.rs @@ -47,12 +47,6 @@ pub enum Pattern2 { tag_name: PoolStr, // 8B arguments: PoolVec<(Variable, PatternId)>, // 8B }, - PrivateTag { - whole_var: Variable, // 4B - ext_var: Variable, // 4B - tag_name: Symbol, // 8B - arguments: PoolVec<(Variable, PatternId)>, // 8B - }, RecordDestructure { whole_var: Variable, // 4B ext_var: Variable, // 4B @@ -485,7 +479,7 @@ pub fn symbols_from_pattern(pool: &Pool, initial: &Pattern2) -> Vec { symbols.push(*symbol); } - GlobalTag { arguments, .. } | PrivateTag { arguments, .. } => { + GlobalTag { arguments, .. } => { for (_, pat_id) in arguments.iter(pool) { let pat = pool.get(*pat_id); stack.push(pat); @@ -546,7 +540,7 @@ pub fn symbols_and_variables_from_pattern( symbols.push((*symbol, variable)); } - GlobalTag { arguments, .. } | PrivateTag { arguments, .. } => { + GlobalTag { arguments, .. } => { for (var, pat_id) in arguments.iter(pool) { let pat = pool.get(*pat_id); stack.push((*var, pat)); From cf8409dfaa1801dc4056966455ee2456def15640 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Mon, 25 Apr 2022 11:38:54 -0400 Subject: [PATCH 556/846] Remove private tag variants --- compiler/exhaustive/src/lib.rs | 26 +++++++++++++++++--- compiler/gen_dev/src/lib.rs | 3 --- compiler/module/src/ident.rs | 7 ------ compiler/mono/src/decision_tree.rs | 35 ++++++++++++++------------- compiler/mono/src/exhaustive.rs | 10 ++++---- compiler/mono/src/ir.rs | 28 ++++++++++----------- compiler/mono/src/layout_soa.rs | 1 - compiler/types/src/builtin_aliases.rs | 7 ------ compiler/types/src/subs.rs | 15 ++++-------- repl_eval/src/eval.rs | 2 +- reporting/src/error/mono.rs | 24 +++++++++--------- reporting/src/error/type.rs | 22 ----------------- reporting/src/report.rs | 4 +-- 13 files changed, 76 insertions(+), 108 deletions(-) diff --git a/compiler/exhaustive/src/lib.rs b/compiler/exhaustive/src/lib.rs index 644af3add0..c94b98aaa0 100644 --- a/compiler/exhaustive/src/lib.rs +++ b/compiler/exhaustive/src/lib.rs @@ -2,7 +2,10 @@ //! http://moscova.inria.fr/~maranget/papers/warn/warn.pdf use roc_collections::all::{HumanIndex, MutMap}; -use roc_module::ident::{Lowercase, TagIdIntType, TagName}; +use roc_module::{ + ident::{Lowercase, TagIdIntType, TagName}, + symbol::Symbol, +}; use roc_region::all::Region; use roc_std::RocDec; @@ -15,9 +18,9 @@ pub struct Union { } impl Union { - pub fn newtype_wrapper(tag_name: TagName, arity: usize) -> Self { + pub fn newtype_wrapper(name: CtorName, arity: usize) -> Self { let alternatives = vec![Ctor { - name: tag_name, + name, tag_id: TagId(0), arity, }]; @@ -40,9 +43,24 @@ pub enum RenderAs { #[derive(Clone, Debug, PartialEq, Eq, Hash, Copy)] pub struct TagId(pub TagIdIntType); +#[derive(Clone, Debug, PartialEq, Eq, Hash)] +pub enum CtorName { + Tag(TagName), + Opaque(Symbol), +} + +impl CtorName { + pub fn is_tag(&self, tag_name: &TagName) -> bool { + match self { + Self::Tag(test) => test == tag_name, + _ => false, + } + } +} + #[derive(Clone, Debug, PartialEq, Eq, Hash)] pub struct Ctor { - pub name: TagName, + pub name: CtorName, pub tag_id: TagId, pub arity: usize, } diff --git a/compiler/gen_dev/src/lib.rs b/compiler/gen_dev/src/lib.rs index 1d6fe2ea2c..04e79d5831 100644 --- a/compiler/gen_dev/src/lib.rs +++ b/compiler/gen_dev/src/lib.rs @@ -913,9 +913,6 @@ trait Backend<'a> { TagName::Closure(sym) => { self.set_last_seen(*sym, stmt); } - TagName::Private(sym) => { - self.set_last_seen(*sym, stmt); - } TagName::Global(_) => {} } for sym in *arguments { diff --git a/compiler/module/src/ident.rs b/compiler/module/src/ident.rs index 2b4347d3d9..5335cad281 100644 --- a/compiler/module/src/ident.rs +++ b/compiler/module/src/ident.rs @@ -53,10 +53,6 @@ pub enum TagName { /// into integers. (Record field labels work the same way, for the same reason.) Global(Uppercase), - /// Private tags are associated with a specific module, and as such use a - /// Symbol just like all other module-specific identifiers. - Private(Symbol), - /// Used to connect the closure size to the function it corresponds to Closure(Symbol), } @@ -69,9 +65,6 @@ impl TagName { pub fn as_ident_str(&self, interns: &Interns, home: ModuleId) -> IdentStr { match self { TagName::Global(uppercase) => uppercase.as_ident_str().clone(), - TagName::Private(symbol) => { - symbol.fully_qualified(interns, home).as_ident_str().clone() - } TagName::Closure(symbol) => { symbol.fully_qualified(interns, home).as_ident_str().clone() } diff --git a/compiler/mono/src/decision_tree.rs b/compiler/mono/src/decision_tree.rs index 2d9718c417..2295d307a7 100644 --- a/compiler/mono/src/decision_tree.rs +++ b/compiler/mono/src/decision_tree.rs @@ -4,7 +4,7 @@ use crate::ir::{ use crate::layout::{Builtin, Layout, LayoutCache, TagIdIntType, UnionLayout}; use roc_builtins::bitcode::{FloatWidth, IntWidth}; use roc_collections::all::{MutMap, MutSet}; -use roc_exhaustive::{Ctor, RenderAs, TagId, Union}; +use roc_exhaustive::{Ctor, CtorName, RenderAs, TagId, Union}; use roc_module::ident::TagName; use roc_module::low_level::LowLevel; use roc_module::symbol::Symbol; @@ -82,7 +82,7 @@ enum GuardedTest<'a> { enum Test<'a> { IsCtor { tag_id: TagIdIntType, - tag_name: TagName, + ctor_name: CtorName, union: roc_exhaustive::Union, arguments: Vec<(Pattern<'a>, Layout<'a>)>, }, @@ -512,7 +512,7 @@ fn test_at_path<'a>( render_as: RenderAs::Tag, alternatives: vec![Ctor { tag_id: TagId(0), - name: TagName::Global(RECORD_TAG_NAME.into()), + name: CtorName::Tag(TagName::Global(RECORD_TAG_NAME.into())), arity: destructs.len(), }], }; @@ -532,7 +532,7 @@ fn test_at_path<'a>( IsCtor { tag_id: 0, - tag_name: TagName::Global(RECORD_TAG_NAME.into()), + ctor_name: CtorName::Tag(TagName::Global(RECORD_TAG_NAME.into())), union, arguments, } @@ -543,11 +543,12 @@ fn test_at_path<'a>( arguments, } => { let tag_id = 0; - let union = Union::newtype_wrapper(tag_name.clone(), arguments.len()); + let union = + Union::newtype_wrapper(CtorName::Tag(tag_name.clone()), arguments.len()); IsCtor { tag_id, - tag_name: tag_name.clone(), + ctor_name: CtorName::Tag(tag_name.clone()), union, arguments: arguments.to_vec(), } @@ -561,7 +562,7 @@ fn test_at_path<'a>( .. } => IsCtor { tag_id: *tag_id, - tag_name: tag_name.clone(), + ctor_name: CtorName::Tag(tag_name.clone()), union: union.clone(), arguments: arguments.to_vec(), }, @@ -571,14 +572,14 @@ fn test_at_path<'a>( render_as: RenderAs::Tag, alternatives: vec![Ctor { tag_id: TagId(0), - name: TagName::Private(*opaque), + name: CtorName::Opaque(*opaque), arity: 1, }], }; IsCtor { tag_id: 0, - tag_name: TagName::Private(*opaque), + ctor_name: CtorName::Opaque(*opaque), union, arguments: vec![(**argument).clone()], } @@ -680,11 +681,11 @@ fn to_relevant_branch_help<'a>( RecordDestructure(destructs, _) => match test { IsCtor { - tag_name: test_name, + ctor_name: test_name, tag_id, .. } => { - debug_assert!(test_name == &TagName::Global(RECORD_TAG_NAME.into())); + debug_assert!(test_name == &CtorName::Tag(TagName::Global(RECORD_TAG_NAME.into()))); let sub_positions = destructs.into_iter().enumerate().map(|(index, destruct)| { let pattern = match destruct.typ { DestructType::Guard(guard) => guard.clone(), @@ -713,11 +714,11 @@ fn to_relevant_branch_help<'a>( OpaqueUnwrap { opaque, argument } => match test { IsCtor { - tag_name: test_opaque_tag_name, + ctor_name: test_opaque_tag_name, tag_id, .. } => { - debug_assert_eq!(test_opaque_tag_name, &TagName::Private(opaque)); + debug_assert_eq!(test_opaque_tag_name, &CtorName::Opaque(opaque)); let (argument, _) = *argument; @@ -744,10 +745,10 @@ fn to_relevant_branch_help<'a>( .. } => match test { IsCtor { - tag_name: test_name, + ctor_name: test_name, tag_id: test_id, .. - } if &tag_name == test_name => { + } if test_name.is_tag(&tag_name) => { let tag_id = 0; debug_assert_eq!(tag_id, *test_id); @@ -785,10 +786,10 @@ fn to_relevant_branch_help<'a>( } => { match test { IsCtor { - tag_name: test_name, + ctor_name: test_name, tag_id: test_id, .. - } if &tag_name == test_name => { + } if test_name.is_tag(&tag_name) => { debug_assert_eq!(tag_id, *test_id); // the test matches the constructor of this pattern diff --git a/compiler/mono/src/exhaustive.rs b/compiler/mono/src/exhaustive.rs index bfcb3b3e90..514cdf3f2d 100644 --- a/compiler/mono/src/exhaustive.rs +++ b/compiler/mono/src/exhaustive.rs @@ -1,7 +1,7 @@ use crate::ir::DestructType; use roc_collections::all::HumanIndex; use roc_exhaustive::{ - is_useful, Context, Ctor, Error, Guard, Literal, Pattern, RenderAs, TagId, Union, + is_useful, Context, Ctor, CtorName, Error, Guard, Literal, Pattern, RenderAs, TagId, Union, }; use roc_module::ident::{TagIdIntType, TagName}; use roc_region::all::{Loc, Region}; @@ -45,7 +45,7 @@ fn simplify(pattern: &crate::ir::Pattern) -> Pattern { let union = Union { render_as: RenderAs::Record(field_names), alternatives: vec![Ctor { - name: TagName::Global("#Record".into()), + name: CtorName::Tag(TagName::Global("#Record".into())), tag_id, arity: destructures.len(), }], @@ -62,7 +62,7 @@ fn simplify(pattern: &crate::ir::Pattern) -> Pattern { let simplified_args: std::vec::Vec<_> = arguments.iter().map(|v| simplify(&v.0)).collect(); Ctor( - Union::newtype_wrapper(tag_name.clone(), arguments.len()), + Union::newtype_wrapper(CtorName::Tag(tag_name.clone()), arguments.len()), TagId(tag_id), simplified_args, ) @@ -87,7 +87,7 @@ fn simplify(pattern: &crate::ir::Pattern) -> Pattern { let union = Union { render_as: RenderAs::Opaque, alternatives: vec![Ctor { - name: TagName::Private(*opaque), + name: CtorName::Opaque(*opaque), tag_id, arity: 1, }], @@ -169,7 +169,7 @@ fn to_nonredundant_rows( render_as: RenderAs::Guard, alternatives: vec![Ctor { tag_id, - name: TagName::Global("#Guard".into()), + name: CtorName::Tag(TagName::Global("#Guard".into())), arity: 2, }], }; diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 2ed74c3735..f98b26370f 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -10,7 +10,7 @@ use roc_builtins::bitcode::{FloatWidth, IntWidth}; use roc_can::abilities::AbilitiesStore; use roc_can::expr::{ClosureData, IntValue}; use roc_collections::all::{default_hasher, BumpMap, BumpMapDefault, MutMap}; -use roc_exhaustive::{Ctor, Guard, RenderAs, TagId}; +use roc_exhaustive::{Ctor, CtorName, Guard, RenderAs, TagId}; use roc_module::ident::{ForeignSymbol, Lowercase, TagName}; use roc_module::low_level::LowLevel; use roc_module::symbol::{IdentIds, ModuleId, Symbol}; @@ -1656,7 +1656,6 @@ impl<'a> Expr<'a> { } => { let doc_tag = match tag_name { TagName::Global(s) => alloc.text(s.as_str()), - TagName::Private(s) => symbol_to_doc(alloc, *s), TagName::Closure(s) => alloc .text("ClosureTag(") .append(symbol_to_doc(alloc, *s)) @@ -1678,7 +1677,6 @@ impl<'a> Expr<'a> { } => { let doc_tag = match tag_name { TagName::Global(s) => alloc.text(s.as_str()), - TagName::Private(s) => alloc.text(format!("{}", s)), TagName::Closure(s) => alloc .text("ClosureTag(") .append(symbol_to_doc(alloc, *s)) @@ -8039,7 +8037,7 @@ fn from_can_pattern_help<'a>( render_as: RenderAs::Tag, alternatives: vec![Ctor { tag_id: TagId(0), - name: tag_name.clone(), + name: CtorName::Tag(tag_name.clone()), arity: 0, }], }, @@ -8052,12 +8050,12 @@ fn from_can_pattern_help<'a>( alternatives: vec![ Ctor { tag_id: TagId(0), - name: ffalse, + name: CtorName::Tag(ffalse), arity: 0, }, Ctor { tag_id: TagId(1), - name: ttrue, + name: CtorName::Tag(ttrue), arity: 0, }, ], @@ -8073,7 +8071,7 @@ fn from_can_pattern_help<'a>( for (i, tag_name) in tag_names.into_iter().enumerate() { ctors.push(Ctor { tag_id: TagId(i as _), - name: tag_name, + name: CtorName::Tag(tag_name), arity: 0, }) } @@ -8164,7 +8162,7 @@ fn from_can_pattern_help<'a>( for (i, (tag_name, args)) in tags.iter().enumerate() { ctors.push(Ctor { tag_id: TagId(i as _), - name: tag_name.clone(), + name: CtorName::Tag(tag_name.clone()), arity: args.len(), }) } @@ -8215,7 +8213,7 @@ fn from_can_pattern_help<'a>( for (i, (tag_name, args)) in tags.iter().enumerate() { ctors.push(Ctor { tag_id: TagId(i as _), - name: tag_name.clone(), + name: CtorName::Tag(tag_name.clone()), // don't include tag discriminant in arity arity: args.len() - 1, }) @@ -8260,7 +8258,7 @@ fn from_can_pattern_help<'a>( ctors.push(Ctor { tag_id: TagId(0), - name: tag_name.clone(), + name: CtorName::Tag(tag_name.clone()), arity: fields.len(), }); @@ -8307,7 +8305,7 @@ fn from_can_pattern_help<'a>( if i == nullable_id as usize { ctors.push(Ctor { tag_id: TagId(i as _), - name: nullable_name.clone(), + name: CtorName::Tag(nullable_name.clone()), // don't include tag discriminant in arity arity: 0, }); @@ -8317,7 +8315,7 @@ fn from_can_pattern_help<'a>( ctors.push(Ctor { tag_id: TagId(i as _), - name: tag_name.clone(), + name: CtorName::Tag(tag_name.clone()), // don't include tag discriminant in arity arity: args.len() - 1, }); @@ -8328,7 +8326,7 @@ fn from_can_pattern_help<'a>( if i == nullable_id as usize { ctors.push(Ctor { tag_id: TagId(i as _), - name: nullable_name.clone(), + name: CtorName::Tag(nullable_name.clone()), // don't include tag discriminant in arity arity: 0, }); @@ -8378,13 +8376,13 @@ fn from_can_pattern_help<'a>( ctors.push(Ctor { tag_id: TagId(nullable_id as _), - name: nullable_name.clone(), + name: CtorName::Tag(nullable_name.clone()), arity: 0, }); ctors.push(Ctor { tag_id: TagId(!nullable_id as _), - name: nullable_name.clone(), + name: CtorName::Tag(nullable_name.clone()), // FIXME drop tag arity: other_fields.len() - 1, }); diff --git a/compiler/mono/src/layout_soa.rs b/compiler/mono/src/layout_soa.rs index 05b7858b20..85bd46553f 100644 --- a/compiler/mono/src/layout_soa.rs +++ b/compiler/mono/src/layout_soa.rs @@ -344,7 +344,6 @@ impl LambdaSet { layouts.symbols.push(*symbol); } TagName::Global(_) => unreachable!("lambda set tags must be closure tags"), - TagName::Private(_) => unreachable!("lambda set tags must be closure tags"), } } diff --git a/compiler/types/src/builtin_aliases.rs b/compiler/types/src/builtin_aliases.rs index 63ca184df9..b638cad6e4 100644 --- a/compiler/types/src/builtin_aliases.rs +++ b/compiler/types/src/builtin_aliases.rs @@ -1076,10 +1076,3 @@ pub fn set_type(a: SolvedType) -> SolvedType { pub fn dict_type(key: SolvedType, value: SolvedType) -> SolvedType { SolvedType::Apply(Symbol::DICT_DICT, vec![key, value]) } - -pub fn single_private_tag(symbol: Symbol, type_arguments: Vec) -> SolvedType { - SolvedType::TagUnion( - vec![(TagName::Private(symbol), type_arguments)], - Box::new(SolvedType::EmptyTagUnion), - ) -} diff --git a/compiler/types/src/subs.rs b/compiler/types/src/subs.rs index 3a9888c8c5..c5ddade386 100644 --- a/compiler/types/src/subs.rs +++ b/compiler/types/src/subs.rs @@ -114,7 +114,6 @@ fn round_to_multiple_of(value: usize, base: usize) -> usize { enum SerializedTagName { Global(SubsSlice), - Private(Symbol), Closure(Symbol), } @@ -211,7 +210,6 @@ impl Subs { ); SerializedTagName::Global(slice) } - TagName::Private(symbol) => SerializedTagName::Private(*symbol), TagName::Closure(symbol) => SerializedTagName::Closure(*symbol), }; @@ -354,7 +352,6 @@ impl Subs { TagName::Global(string.into()) } - SerializedTagName::Private(symbol) => TagName::Private(*symbol), SerializedTagName::Closure(symbol) => TagName::Closure(*symbol), }; @@ -410,12 +407,10 @@ impl TagNameCache { None => None, } } - TagName::Private(symbol) | TagName::Closure(symbol) => { - match self.symbols.iter().position(|s| s == symbol) { - Some(index) => Some(&mut self.symbols_slices[index]), - None => None, - } - } + TagName::Closure(symbol) => match self.symbols.iter().position(|s| s == symbol) { + Some(index) => Some(&mut self.symbols_slices[index]), + None => None, + }, } } @@ -425,7 +420,7 @@ impl TagNameCache { self.globals.push(uppercase.clone()); self.globals_slices.push(slice); } - TagName::Private(symbol) | TagName::Closure(symbol) => { + TagName::Closure(symbol) => { self.symbols.push(*symbol); self.symbols_slices.push(slice); } diff --git a/repl_eval/src/eval.rs b/repl_eval/src/eval.rs index 44acb07ae9..f50622043a 100644 --- a/repl_eval/src/eval.rs +++ b/repl_eval/src/eval.rs @@ -475,7 +475,7 @@ fn tag_name_to_expr<'a>(env: &Env<'a, '_>, tag_name: &TagName) -> Expr<'a> { env.arena .alloc_str(&tag_name.as_ident_str(env.interns, env.home)), ), - TagName::Private(_) | TagName::Closure(_) => unreachable!("User cannot type this"), + TagName::Closure(_) => unreachable!("User cannot type this"), } } diff --git a/reporting/src/error/mono.rs b/reporting/src/error/mono.rs index 7ca6608c7d..8215b05b1a 100644 --- a/reporting/src/error/mono.rs +++ b/reporting/src/error/mono.rs @@ -145,7 +145,7 @@ fn pattern_to_doc_help<'b>( ) -> RocDocBuilder<'b> { use roc_exhaustive::Literal::*; use roc_exhaustive::Pattern::*; - use roc_exhaustive::RenderAs; + use roc_exhaustive::{CtorName, RenderAs}; match pattern { Anything => alloc.text("_"), @@ -163,10 +163,9 @@ fn pattern_to_doc_help<'b>( match union.render_as { RenderAs::Guard => { // #Guard - debug_assert_eq!( - union.alternatives[tag_id.0 as usize].name, - TagName::Global("#Guard".into()) - ); + debug_assert!(union.alternatives[tag_id.0 as usize] + .name + .is_tag(&TagName::Global("#Guard".into())),); debug_assert!(args.len() == 2); let tag = pattern_to_doc_help(alloc, args[1].clone(), in_type_param); alloc.concat([ @@ -207,18 +206,17 @@ fn pattern_to_doc_help<'b>( .into_iter() .map(|v| pattern_to_doc_help(alloc, v, true)); - let tag = &union.alternatives[tag_id.0 as usize]; - let tag_name = match union.render_as { - RenderAs::Tag => alloc.tag_name(tag.name.clone()), - RenderAs::Opaque => match tag.name { - TagName::Private(opaque) => alloc.wrapped_opaque_name(opaque), - _ => unreachable!(), - }, + let ctor = &union.alternatives[tag_id.0 as usize]; + let tag_name = match (union.render_as, &ctor.name) { + (RenderAs::Tag, CtorName::Tag(tag)) => alloc.tag_name(tag.clone()), + (RenderAs::Opaque, CtorName::Opaque(opaque)) => { + alloc.wrapped_opaque_name(*opaque) + } _ => unreachable!(), }; // We assume the alternatives are sorted. If not, this assert will trigger - debug_assert!(tag_id == tag.tag_id); + debug_assert!(tag_id == ctor.tag_id); let docs = std::iter::once(tag_name).chain(arg_docs); diff --git a/reporting/src/error/type.rs b/reporting/src/error/type.rs index d9e3fb198b..90e7ad15b9 100644 --- a/reporting/src/error/type.rs +++ b/reporting/src/error/type.rs @@ -1449,17 +1449,6 @@ fn format_category<'b>( ]), alloc.text(" has the type:"), ), - TagApply { - tag_name: TagName::Private(name), - args_count: 0, - } => ( - alloc.concat([ - alloc.text(format!("{}his ", t)), - alloc.private_tag_name(*name), - alloc.text(" private tag"), - ]), - alloc.text(" has the type:"), - ), TagApply { tag_name: TagName::Global(name), @@ -1472,17 +1461,6 @@ fn format_category<'b>( ]), alloc.text(" has the type:"), ), - TagApply { - tag_name: TagName::Private(name), - args_count: _, - } => ( - alloc.concat([ - alloc.text("This "), - alloc.private_tag_name(*name), - alloc.text(" private tag application"), - ]), - alloc.text(" has the type:"), - ), TagApply { tag_name: TagName::Closure(_name), args_count: _, diff --git a/reporting/src/report.rs b/reporting/src/report.rs index d0d8b95bdc..4d0a655a2f 100644 --- a/reporting/src/report.rs +++ b/reporting/src/report.rs @@ -386,9 +386,7 @@ impl<'a> RocDocAllocator<'a> { pub fn tag_name(&'a self, tn: TagName) -> DocBuilder<'a, Self, Annotation> { match tn { TagName::Global(uppercase) => self.global_tag_name(uppercase), - TagName::Private(symbol) => self.private_tag_name(symbol), - TagName::Closure(symbol) => self.private_tag_name(symbol), - // TagName::Closure(_symbol) => unreachable!("closure tags are internal only"), + TagName::Closure(_symbol) => unreachable!("closure tags are internal only"), } } From 2ab01107d3477ea9bfc348fa3ca97cba978f2ab6 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Mon, 25 Apr 2022 11:43:55 -0400 Subject: [PATCH 557/846] Removing extra private tag references --- ast/src/constrain.rs | 12 ------------ compiler/parse/src/ident.rs | 1 - reporting/src/error/canonicalize.rs | 11 ++++------- reporting/src/error/parse.rs | 28 ---------------------------- 4 files changed, 4 insertions(+), 48 deletions(-) diff --git a/ast/src/constrain.rs b/ast/src/constrain.rs index 5bfc97131f..561da5c644 100644 --- a/ast/src/constrain.rs +++ b/ast/src/constrain.rs @@ -2209,18 +2209,6 @@ pub mod test_constrain { ) } - #[test] - fn constrain_private_tag() { - infer_eq( - indoc!( - r#" - @Foo - "# - ), - "[ @Foo ]*", - ) - } - #[test] fn constrain_call_and_accessor() { infer_eq( diff --git a/compiler/parse/src/ident.rs b/compiler/parse/src/ident.rs index c7e917ec4d..e871563d9e 100644 --- a/compiler/parse/src/ident.rs +++ b/compiler/parse/src/ident.rs @@ -223,7 +223,6 @@ pub enum BadIdent { WeirdDotAccess(Position), WeirdDotQualified(Position), StrayDot(Position), - BadPrivateTag(Position), BadOpaqueRef(Position), } diff --git a/reporting/src/error/canonicalize.rs b/reporting/src/error/canonicalize.rs index 9d755bee9c..eadcd1e07b 100644 --- a/reporting/src/error/canonicalize.rs +++ b/reporting/src/error/canonicalize.rs @@ -925,13 +925,10 @@ fn to_bad_ident_expr_report<'b>( ]) } - BadPrivateTag(pos) | BadOpaqueRef(pos) => { + BadOpaqueRef(pos) => { use BadIdentNext::*; - let kind = if matches!(bad_ident, BadPrivateTag(..)) { - "a private tag" - } else { - "an opaque reference" - }; + let kind = "an opaque reference"; + match what_is_next(alloc.src_lines, lines.convert_pos(pos)) { LowercaseAccess(width) => { let region = Region::new(pos, pos.bump_column(width)); @@ -983,7 +980,7 @@ fn to_bad_ident_expr_report<'b>( alloc.reflow(r"But after the "), alloc.keyword("@"), alloc.reflow(r" symbol I found a lowercase letter. "), - alloc.reflow(r"All tag names (global and private)"), + alloc.reflow(r"All opaque references "), alloc.reflow(r" must start with an uppercase letter, like "), alloc.parser_suggestion("@UUID"), alloc.reflow(" or "), diff --git a/reporting/src/error/parse.rs b/reporting/src/error/parse.rs index b03c5d0826..922ef4cf38 100644 --- a/reporting/src/error/parse.rs +++ b/reporting/src/error/parse.rs @@ -38,17 +38,6 @@ fn hint_for_tag_name<'a>(alloc: &'a RocDocAllocator<'a>) -> RocDocBuilder<'a> { ]) } -fn hint_for_private_tag_name<'a>(alloc: &'a RocDocAllocator<'a>) -> RocDocBuilder<'a> { - alloc.concat([ - alloc.hint("Private tag names "), - alloc.reflow("start with an `@` symbol followed by an uppercase letter, like "), - alloc.parser_suggestion("@UID"), - alloc.text(" or "), - alloc.parser_suggestion("@SecretKey"), - alloc.text("."), - ]) -} - fn record_patterns_look_like<'a>(alloc: &'a RocDocAllocator<'a>) -> RocDocBuilder<'a> { alloc.concat([ alloc.reflow(r"Record pattern look like "), @@ -2475,23 +2464,6 @@ fn to_ttag_union_report<'a>( severity: Severity::RuntimeError, } } - Next::Other(Some('@')) => { - let doc = alloc.stack([ - alloc.reflow( - r"I am partway through parsing a tag union type, but I got stuck here:", - ), - alloc.region_with_subregion(lines.convert_region(surroundings), region), - alloc.reflow(r"I was expecting to see a private tag name."), - hint_for_private_tag_name(alloc), - ]); - - Report { - filename, - doc, - title: "WEIRD TAG NAME".to_string(), - severity: Severity::RuntimeError, - } - } _ => { let doc = alloc.stack([ alloc.reflow(r"I am partway through parsing a tag union type, but I got stuck here:"), From 55706ae5c478100fd15db2e772b8c7bec7e8b3da Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Mon, 25 Apr 2022 11:50:00 -0400 Subject: [PATCH 558/846] Remove other references to private tags in code --- compiler/builtins/docs/Bool.roc | 7 ++- compiler/can/src/env.rs | 2 +- compiler/load_internal/src/docs.rs | 72 ++++++++--------------------- compiler/types/src/subs.rs | 2 +- highlight/src/tokenizer.rs | 12 ----- highlight/tests/peg_grammar.rs | 5 +- reporting/src/error/canonicalize.rs | 6 +-- reporting/src/report.rs | 25 ++-------- 8 files changed, 32 insertions(+), 99 deletions(-) diff --git a/compiler/builtins/docs/Bool.roc b/compiler/builtins/docs/Bool.roc index 29d8dbbc90..06b2d09025 100644 --- a/compiler/builtins/docs/Bool.roc +++ b/compiler/builtins/docs/Bool.roc @@ -70,10 +70,9 @@ xor : Bool, Bool -> Bool ## Structural equality works as follows: ## ## 1. Global tags are equal if they are the same tag, and also their contents (if any) are equal. -## 2. Private tags are equal if they are the same tag, in the same module, and also their contents (if any) are equal. -## 3. Records are equal if all their fields are equal. -## 4. Collections ([Str], [List], [Dict], and [Set]) are equal if they are the same length, and also all their corresponding elements are equal. -## 5. [Num] values are equal if their numbers are equal, with one exception: if both arguments to `isEq` are *NaN*, then `isEq` returns `False`. See `Num.isNaN` for more about *NaN*. +## 2. Records are equal if all their fields are equal. +## 3. Collections ([Str], [List], [Dict], and [Set]) are equal if they are the same length, and also all their corresponding elements are equal. +## 4. [Num] values are equal if their numbers are equal, with one exception: if both arguments to `isEq` are *NaN*, then `isEq` returns `False`. See `Num.isNaN` for more about *NaN*. ## ## Note that `isEq` takes `'val` instead of `val`, which means `isEq` does not ## accept arguments whose types contain functions. diff --git a/compiler/can/src/env.rs b/compiler/can/src/env.rs index b07cfe0a77..40523b2fb7 100644 --- a/compiler/can/src/env.rs +++ b/compiler/can/src/env.rs @@ -7,7 +7,7 @@ use roc_region::all::{Loc, Region}; /// The canonicalization environment for a particular module. pub struct Env<'a> { - /// The module's path. Private tags and unqualified references to identifiers + /// The module's path. Opaques and unqualified references to identifiers /// are assumed to be relative to this path. pub home: ModuleId, diff --git a/compiler/load_internal/src/docs.rs b/compiler/load_internal/src/docs.rs index 42dc9d4c77..96fed09873 100644 --- a/compiler/load_internal/src/docs.rs +++ b/compiler/load_internal/src/docs.rs @@ -1,7 +1,5 @@ use crate::docs::DocEntry::DetachedDoc; -use crate::docs::TypeAnnotation::{ - Apply, BoundVariable, Function, NoTypeAnn, ObscuredRecord, ObscuredTagUnion, Record, TagUnion, -}; +use crate::docs::TypeAnnotation::{Apply, BoundVariable, Function, NoTypeAnn, Record, TagUnion}; use crate::file::LoadedModule; use roc_can::scope::Scope; use roc_error_macros::todo_abilities; @@ -274,36 +272,20 @@ fn type_to_docs(in_func_type_ann: bool, type_annotation: ast::TypeAnnotation) -> ast::TypeAnnotation::TagUnion { tags, ext } => { let mut tags_to_render: Vec = Vec::new(); - let mut any_tags_are_private = false; - for tag in tags.iter() { - match tag_to_doc(in_func_type_ann, tag.value) { - None => { - any_tags_are_private = true; - break; - } - Some(tag_ann) => { - tags_to_render.push(tag_ann); - } + if let Some(tag_ann) = tag_to_doc(in_func_type_ann, tag.value) { + tags_to_render.push(tag_ann); } } - if any_tags_are_private { - if in_func_type_ann { - ObscuredTagUnion - } else { - NoTypeAnn - } - } else { - let extension = match ext { - None => NoTypeAnn, - Some(ext_type_ann) => type_to_docs(in_func_type_ann, ext_type_ann.value), - }; + let extension = match ext { + None => NoTypeAnn, + Some(ext_type_ann) => type_to_docs(in_func_type_ann, ext_type_ann.value), + }; - TagUnion { - tags: tags_to_render, - extension: Box::new(extension), - } + TagUnion { + tags: tags_to_render, + extension: Box::new(extension), } } ast::TypeAnnotation::BoundVariable(var_name) => BoundVariable(var_name.to_string()), @@ -328,35 +310,19 @@ fn type_to_docs(in_func_type_ann: bool, type_annotation: ast::TypeAnnotation) -> ast::TypeAnnotation::Record { fields, ext } => { let mut doc_fields = Vec::new(); - let mut any_fields_include_private_tags = false; - for field in fields.items { - match record_field_to_doc(in_func_type_ann, field.value) { - None => { - any_fields_include_private_tags = true; - break; - } - Some(doc_field) => { - doc_fields.push(doc_field); - } + if let Some(doc_field) = record_field_to_doc(in_func_type_ann, field.value) { + doc_fields.push(doc_field); } } - if any_fields_include_private_tags { - if in_func_type_ann { - ObscuredRecord - } else { - NoTypeAnn - } - } else { - let extension = match ext { - None => NoTypeAnn, - Some(ext_type_ann) => type_to_docs(in_func_type_ann, ext_type_ann.value), - }; + let extension = match ext { + None => NoTypeAnn, + Some(ext_type_ann) => type_to_docs(in_func_type_ann, ext_type_ann.value), + }; - Record { - fields: doc_fields, - extension: Box::new(extension), - } + Record { + fields: doc_fields, + extension: Box::new(extension), } } ast::TypeAnnotation::SpaceBefore(&sub_type_ann, _) => { diff --git a/compiler/types/src/subs.rs b/compiler/types/src/subs.rs index c5ddade386..8905a9aa58 100644 --- a/compiler/types/src/subs.rs +++ b/compiler/types/src/subs.rs @@ -392,7 +392,7 @@ pub struct Subs { pub struct TagNameCache { globals: Vec, globals_slices: Vec>, - /// Currently private tags and closure tags; in the future just closure tags + /// Just closure tags symbols: Vec, symbols_slices: Vec>, } diff --git a/highlight/src/tokenizer.rs b/highlight/src/tokenizer.rs index 7cb486cd6d..95f8a9fb12 100644 --- a/highlight/src/tokenizer.rs +++ b/highlight/src/tokenizer.rs @@ -70,8 +70,6 @@ pub enum Token { Malformed, MalformedOperator, - PrivateTag, - String, NumberBase, @@ -149,7 +147,6 @@ fn consume_all_tokens(state: &mut LexState, bytes: &[u8], consumer: &mut impl Co b']' => (Token::CloseSquare, 1), b',' => (Token::Comma, 1), b'_' => lex_underscore(bytes), - b'@' => lex_private_tag(bytes), b'a'..=b'z' => lex_ident(false, bytes), b'A'..=b'Z' => lex_ident(true, bytes), b'0'..=b'9' => lex_number(bytes), @@ -408,15 +405,6 @@ fn is_ident_continue(ch: u8) -> bool { matches!(ch, b'a'..=b'z'|b'A'..=b'Z'|b'0'..=b'9'|b'_') } -fn lex_private_tag(bytes: &[u8]) -> (Token, usize) { - debug_assert!(bytes[0] == b'@'); - let mut i = 1; - while i < bytes.len() && is_ident_continue(bytes[i]) { - i += 1; - } - (Token::PrivateTag, i) -} - fn lex_ident(uppercase: bool, bytes: &[u8]) -> (Token, usize) { let mut i = 0; while i < bytes.len() && is_ident_continue(bytes[i]) { diff --git a/highlight/tests/peg_grammar.rs b/highlight/tests/peg_grammar.rs index f28b9af74c..f8e052f22f 100644 --- a/highlight/tests/peg_grammar.rs +++ b/highlight/tests/peg_grammar.rs @@ -72,10 +72,7 @@ mod test_peg_grammar { rule tag() = - private_tag() - / [T::UppercaseIdent] - - rule private_tag() = [T::PrivateTag] {} + [T::UppercaseIdent] rule list() = empty_list() diff --git a/reporting/src/error/canonicalize.rs b/reporting/src/error/canonicalize.rs index eadcd1e07b..8f231f8f44 100644 --- a/reporting/src/error/canonicalize.rs +++ b/reporting/src/error/canonicalize.rs @@ -1253,9 +1253,9 @@ fn pretty_runtime_error<'b>( EmptySingleQuote | MultipleCharsInSingleQuote | Unknown | BadIdent(_) => { alloc.nil() } - QualifiedIdentifier => alloc.tip().append( - alloc.reflow("In patterns, only private and global tags can be qualified"), - ), + QualifiedIdentifier => alloc + .tip() + .append(alloc.reflow("In patterns, only global tags can be qualified")), }; doc = alloc.stack([ diff --git a/reporting/src/report.rs b/reporting/src/report.rs index 4d0a655a2f..840054cacc 100644 --- a/reporting/src/report.rs +++ b/reporting/src/report.rs @@ -417,21 +417,6 @@ impl<'a> RocDocAllocator<'a> { .annotate(Annotation::Symbol) } - pub fn private_tag_name(&'a self, symbol: Symbol) -> DocBuilder<'a, Self, Annotation> { - if symbol.module_id() == self.home { - // Render it unqualified if it's in the current module. - self.text(format!("{}", symbol.ident_str(self.interns))) - .annotate(Annotation::PrivateTag) - } else { - self.text(format!( - "{}.{}", - symbol.module_string(self.interns), - symbol.ident_str(self.interns), - )) - .annotate(Annotation::PrivateTag) - } - } - pub fn global_tag_name(&'a self, uppercase: Uppercase) -> DocBuilder<'a, Self, Annotation> { self.text(format!("{}", uppercase)) .annotate(Annotation::GlobalTag) @@ -807,7 +792,6 @@ pub enum Annotation { Url, Keyword, GlobalTag, - PrivateTag, RecordField, TypeVariable, Alias, @@ -899,8 +883,7 @@ where Url => { self.write_str("<")?; } - GlobalTag | PrivateTag | Keyword | RecordField | Symbol | Typo | TypoSuggestion - | TypeVariable + GlobalTag | Keyword | RecordField | Symbol | Typo | TypoSuggestion | TypeVariable if !self.in_type_block && !self.in_code_block => { self.write_str("`")?; @@ -930,7 +913,7 @@ where Url => { self.write_str(">")?; } - GlobalTag | PrivateTag | Keyword | RecordField | Symbol | Typo | TypoSuggestion + GlobalTag | Keyword | RecordField | Symbol | Typo | TypoSuggestion | TypeVariable if !self.in_type_block && !self.in_code_block => { @@ -1023,7 +1006,7 @@ where ParserSuggestion => { self.write_str(self.palette.parser_suggestion)?; } - TypeBlock | GlobalTag | PrivateTag | RecordField => { /* nothing yet */ } + TypeBlock | GlobalTag | RecordField => { /* nothing yet */ } } self.style_stack.push(*annotation); Ok(()) @@ -1041,7 +1024,7 @@ where self.write_str(self.palette.reset)?; } - TypeBlock | GlobalTag | PrivateTag | Opaque | RecordField => { /* nothing yet */ } + TypeBlock | GlobalTag | Opaque | RecordField => { /* nothing yet */ } }, } Ok(()) From 0d24e279f14c44e07aa99f17584b2b338996f435 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Mon, 25 Apr 2022 12:07:31 -0400 Subject: [PATCH 559/846] Fix Ast2 constraining of opaques --- ast/src/constrain.rs | 6 +++--- ast/src/lang/core/types.rs | 6 +++++- ast/src/solve_type.rs | 11 ++++++++--- compiler/solve/tests/solve_expr.rs | 13 +++++++++++++ editor/src/editor/mvc/ed_update.rs | 2 +- 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/ast/src/constrain.rs b/ast/src/constrain.rs index 561da5c644..1b1eded9c9 100644 --- a/ast/src/constrain.rs +++ b/ast/src/constrain.rs @@ -1857,7 +1857,7 @@ fn num_floatingpoint(pool: &mut Pool, range: TypeId) -> Type2 { let alias_content = range_type.shallow_clone(); - Type2::Alias( + Type2::Opaque( Symbol::NUM_FLOATINGPOINT, PoolVec::new(vec![(PoolStr::new("range", pool), range)].into_iter(), pool), pool.add(alias_content), @@ -1905,7 +1905,7 @@ fn _num_integer(pool: &mut Pool, range: TypeId) -> Type2 { let alias_content = range_type.shallow_clone(); - Type2::Alias( + Type2::Opaque( Symbol::NUM_INTEGER, PoolVec::new(vec![(PoolStr::new("range", pool), range)].into_iter(), pool), pool.add(alias_content), @@ -1918,7 +1918,7 @@ fn num_num(pool: &mut Pool, type_id: TypeId) -> Type2 { let alias_content = range_type.shallow_clone(); - Type2::Alias( + Type2::Opaque( Symbol::NUM_NUM, PoolVec::new( vec![(PoolStr::new("range", pool), type_id)].into_iter(), diff --git a/ast/src/lang/core/types.rs b/ast/src/lang/core/types.rs index d65d2bb059..53d7b33314 100644 --- a/ast/src/lang/core/types.rs +++ b/ast/src/lang/core/types.rs @@ -24,6 +24,7 @@ pub enum Type2 { Variable(Variable), // 4B Alias(Symbol, PoolVec<(PoolStr, TypeId)>, TypeId), // 24B = 8B + 8B + 4B + pad + Opaque(Symbol, PoolVec<(PoolStr, TypeId)>, TypeId), // 24B = 8B + 8B + 4B + pad AsAlias(Symbol, PoolVec<(PoolStr, TypeId)>, TypeId), // 24B = 8B + 8B + 4B + pad // 24B @@ -74,6 +75,9 @@ impl ShallowClone for Type2 { Self::Alias(symbol, args, alias_type_id) => { Self::Alias(*symbol, args.shallow_clone(), alias_type_id.clone()) } + Self::Opaque(symbol, args, alias_type_id) => { + Self::Opaque(*symbol, args.shallow_clone(), alias_type_id.clone()) + } Self::Record(fields, ext_id) => Self::Record(fields.shallow_clone(), ext_id.clone()), Self::Function(args, closure_type_id, ret_type_id) => Self::Function( args.shallow_clone(), @@ -101,7 +105,7 @@ impl Type2 { Variable(v) => { result.insert(*v); } - Alias(_, _, actual) | AsAlias(_, _, actual) => { + Alias(_, _, actual) | AsAlias(_, _, actual) | Opaque(_, _, actual) => { stack.push(pool.get(*actual)); } HostExposedAlias { diff --git a/ast/src/solve_type.rs b/ast/src/solve_type.rs index 096a405d5c..eac6ae712e 100644 --- a/ast/src/solve_type.rs +++ b/ast/src/solve_type.rs @@ -3,6 +3,7 @@ use bumpalo::Bump; use roc_can::expected::{Expected, PExpected}; use roc_collections::all::{BumpMap, BumpMapDefault, MutMap}; +use roc_error_macros::internal_error; use roc_module::ident::TagName; use roc_module::symbol::Symbol; use roc_region::all::{Loc, Region}; @@ -868,7 +869,7 @@ fn type_to_variable<'a>( register(subs, rank, pools, content) } - Alias(symbol, args, alias_type_id) => { + Alias(symbol, args, alias_type_id) | Opaque(symbol, args, alias_type_id) => { // TODO cache in uniqueness inference gives problems! all Int's get the same uniqueness var! // Cache aliases without type arguments. Commonly used aliases like `Int` would otherwise get O(n) // different variables (once for each occurrence). The recursion restriction is required @@ -910,8 +911,12 @@ fn type_to_variable<'a>( let alias_var = type_to_variable(arena, mempool, subs, rank, pools, cached, alias_type); - // TODO(opaques): take opaques into account - let content = Content::Alias(*symbol, arg_vars, alias_var, AliasKind::Structural); + let kind = match typ { + Alias(..) => AliasKind::Structural, + Opaque(..) => AliasKind::Opaque, + _ => internal_error!(), + }; + let content = Content::Alias(*symbol, arg_vars, alias_var, kind); let result = register(subs, rank, pools, content); diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index a8ee55ee26..8fe7a6622b 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -6168,4 +6168,17 @@ mod solve_expr { "a -> Task a *", ); } + + #[test] + fn list_with_num_and_str() { + infer_eq_without_problem( + indoc!( + r#" + val = [ 1, "abc" ] + val + "# + ), + "", + ) + } } diff --git a/editor/src/editor/mvc/ed_update.rs b/editor/src/editor/mvc/ed_update.rs index ba546e85d1..bbe05560c6 100644 --- a/editor/src/editor/mvc/ed_update.rs +++ b/editor/src/editor/mvc/ed_update.rs @@ -3169,7 +3169,7 @@ pub mod test_ed_update { assert_type_tooltips_clean( ovec!["val = [ [ 0, 1, \"2\" ], [ 3, 4, 5 ┃] ]"], - ovec!["List (Num *)", "List (List )"], + ovec!["List (Num *)", "List "], )?; Ok(()) From 3fd345e99ddcc593568872b045260efeca6ca8e5 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Mon, 25 Apr 2022 12:18:46 -0400 Subject: [PATCH 560/846] Switch private tags to opaque types in docs --- roc-for-elm-programmers.md | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/roc-for-elm-programmers.md b/roc-for-elm-programmers.md index d2847ed720..5d4cd52569 100644 --- a/roc-for-elm-programmers.md +++ b/roc-for-elm-programmers.md @@ -677,17 +677,19 @@ includes in its union." The tags discussed in the previous section are globally available, which means they cannot be used to create opaque types. -*Private tags* let you create opaque types. They work just like the *global tags* -from the previous section, except: +Opaque types are like aliases, but with the following differences: -* Private tags begin with an `@` (e.g. `@Foo` instead of `Foo`) -* Private tags are scoped to the current module, rather than globally scoped -* Private tags can only be instantiated in the current module +* Opaque type are defined with `:=` (e.g. `Username := Str` instead of `Username : Str`) +* You can create an instance of an opaque by wrapping it with the `@` syntax (e.g. `@Username "sasha"`) +* You can unwrap opaque types to get their payload with the `@` syntax (e.g. `@Username nameStr = user`) +* Opaque types can only be wrapped and unwrapped in the current module +* Opaque type names can be imported by other modules, but not wrapped and unwrapped there +* Opaque types are only equal if their qualified name (defining module name + type name) are equivalent For example, suppose I define these inside the `Username` module: ```elm -Username : [ @Username Str ] +Username := Str fromStr : Str -> Username fromStr = \str -> @@ -699,14 +701,16 @@ toStr = \@Username str -> ``` I can now expose the `Username` type alias, which other modules can use as an opaque type. -It's not even syntactically possible for me to expose the `@Username` tag, -because `@` tags are not allowed in the exposing list. Only code written in this -`Username` module can instantiate a `@Username` value. +It's not even syntactically possible for me to expose `@Username`, +because `@`s allowed in the exposing list. Only code written in this +`Username` module can use the `@Username` wrapper syntax. -> If I were to write `@Username` inside another module (e.g. `Main`), it would compile, -> but that `@Username` would be type-incompatible with the one created inside the `Username` module. +> If I were to define `Username := Str` inside another module (e.g. `Main`) and use `@Username`, +> it would compile, but that `Username` opaque type would have the qualified name `Main.Username`. +> That means it would be type-incompatible with the one created inside the `Username` module, which +> has the qualified name `Username.Username`. > Even trying to use `==` on them would be a type mismatch, because I would be comparing -> a `[ Username.@Username Str ]*` with a `[ Main.@Username Str ]*`, which are incompatible. +> a `Username.Username` with a `Main.Username`, which are incompatible. ## Modules and Shadowing From e43994530f1ecb5e8e51870a4d03a07b491bb144 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Mon, 25 Apr 2022 12:19:33 -0400 Subject: [PATCH 561/846] Remove temp test --- compiler/solve/tests/solve_expr.rs | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index 8fe7a6622b..a8ee55ee26 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -6168,17 +6168,4 @@ mod solve_expr { "a -> Task a *", ); } - - #[test] - fn list_with_num_and_str() { - infer_eq_without_problem( - indoc!( - r#" - val = [ 1, "abc" ] - val - "# - ), - "", - ) - } } From f1dc9c8298d9a2aea1d36b567de1c36b5874ed7d Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Mon, 25 Apr 2022 12:26:38 -0400 Subject: [PATCH 562/846] Opaques take @ : %s/\$\([A-Z]\)/@\1/g --- compiler/can/src/effect_module.rs | 32 +++--- compiler/can/src/expr.rs | 3 +- compiler/can/src/scope.rs | 5 +- compiler/load_internal/tests/test_load.rs | 8 +- compiler/parse/src/ast.rs | 3 +- compiler/parse/src/ident.rs | 11 +-- compiler/solve/tests/solve_expr.rs | 90 ++++++++--------- compiler/test_gen/src/gen_abilities.rs | 40 ++++---- compiler/test_gen/src/gen_primitives.rs | 30 +++--- compiler/test_gen/src/gen_tags.rs | 6 +- compiler/test_mono/src/tests.rs | 6 +- examples/benchmarks/Bytes/Decode.roc | 28 +++--- examples/false-interpreter/Variable.roc | 6 +- examples/false-interpreter/platform/File.roc | 8 +- packages/parser/src/Str/Parser.roc | 12 +-- .../src/Unicode/CodePoint/Internal.roc | 4 +- packages/unicode/src/Unicode/Scalar.roc | 6 +- repl_test/src/tests.rs | 8 +- reporting/src/report.rs | 3 +- reporting/tests/test_reporting.rs | 98 +++++++++---------- 20 files changed, 201 insertions(+), 206 deletions(-) diff --git a/compiler/can/src/effect_module.rs b/compiler/can/src/effect_module.rs index 484f0fc223..d2f6e61c5d 100644 --- a/compiler/can/src/effect_module.rs +++ b/compiler/can/src/effect_module.rs @@ -110,7 +110,7 @@ fn build_effect_always( effect_symbol: Symbol, var_store: &mut VarStore, ) -> (Symbol, Def) { - // Effect.always = \value -> $Effect \{} -> value + // Effect.always = \value -> @Effect \{} -> value let value_symbol = { scope @@ -167,9 +167,9 @@ fn build_effect_always( }) }; - // \value -> $Effect \{} -> value + // \value -> @Effect \{} -> value let (function_var, always_closure) = { - // `$Effect \{} -> value` + // `@Effect \{} -> value` let (specialized_def_type, type_arguments, lambda_set_variables) = build_fresh_opaque_variables(var_store); let body = Expr::OpaqueRef { @@ -255,7 +255,7 @@ fn build_effect_map( effect_symbol: Symbol, var_store: &mut VarStore, ) -> (Symbol, Def) { - // Effect.map = \$Effect thunk, mapper -> $Effect \{} -> mapper (thunk {}) + // Effect.map = \@Effect thunk, mapper -> @Effect \{} -> mapper (thunk {}) let thunk_symbol = { scope @@ -350,7 +350,7 @@ fn build_effect_map( }) }; - // \$Effect thunk, mapper + // \@Effect thunk, mapper let (specialized_def_type, type_arguments, lambda_set_variables) = build_fresh_opaque_variables(var_store); let arguments = vec![ @@ -374,7 +374,7 @@ fn build_effect_map( ), ]; - // `$Effect \{} -> (mapper (thunk {}))` + // `@Effect \{} -> (mapper (thunk {}))` let (specialized_def_type, type_arguments, lambda_set_variables) = build_fresh_opaque_variables(var_store); let body = Expr::OpaqueRef { @@ -473,7 +473,7 @@ fn build_effect_after( effect_symbol: Symbol, var_store: &mut VarStore, ) -> (Symbol, Def) { - // Effect.after = \$Effect effect, toEffect -> toEffect (effect {}) + // Effect.after = \@Effect effect, toEffect -> toEffect (effect {}) let thunk_symbol = { scope @@ -636,7 +636,7 @@ fn build_effect_after( (after_symbol, def) } -/// turn `value` into `$Effect \{} -> value` +/// turn `value` into `@Effect \{} -> value` fn wrap_in_effect_thunk( body: Expr, effect_symbol: Symbol, @@ -670,7 +670,7 @@ fn wrap_in_effect_thunk( }) }; - // `$Effect \{} -> value` + // `@Effect \{} -> value` let (specialized_def_type, type_arguments, lambda_set_variables) = build_fresh_opaque_variables(var_store); Expr::OpaqueRef { @@ -749,14 +749,14 @@ fn build_effect_forever( // // Effect.forever : Effect a -> Effect b // Effect.forever = \effect -> - // $Effect \{} -> - // $Effect thunk1 = effect + // @Effect \{} -> + // @Effect thunk1 = effect // _ = thunk1 {} - // $Effect thunk2 = Effect.forever effect + // @Effect thunk2 = Effect.forever effect // thunk2 {} // // We then rely on our defunctionalization to turn this into a tail-recursive loop. - // First the `$Effect` wrapper melts away + // First the `@Effect` wrapper melts away // // Effect.forever : ({} -> a) -> ({} -> b) // Effect.forever = \effect -> @@ -955,7 +955,7 @@ fn build_effect_forever_inner_body( .unwrap() }; - // $Effect thunk1 = effect + // @Effect thunk1 = effect let thunk_from_effect = { let whole_var = var_store.fresh(); @@ -1022,7 +1022,7 @@ fn build_effect_forever_inner_body( }; // ``` - // $Effect thunk2 = forever effect + // @Effect thunk2 = forever effect // thunk2 {} // ``` let force_thunk2 = Loc::at_zero(force_effect( @@ -1330,7 +1330,7 @@ fn build_effect_loop_inner_body( }; // ``` - // $Effect thunk2 = loop effect + // @Effect thunk2 = loop effect // thunk2 {} // ``` let force_thunk2 = force_effect(loop_new_state_step, effect_symbol, thunk2_symbol, var_store); diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index 31d476d2b8..15301c832a 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -163,8 +163,7 @@ pub enum Expr { name: TagName, }, - /// A wrapping of an opaque type, like `$Age 21` - // TODO(opaques): $->@ above when opaques land + /// A wrapping of an opaque type, like `@Age 21` OpaqueRef { opaque_var: Variable, name: Symbol, diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index e2bdd50d20..b45b7eea6c 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -134,15 +134,14 @@ impl Scope { } /// Check if there is an opaque type alias referenced by `opaque_ref` referenced in the - /// current scope. E.g. `$Age` must reference an opaque `Age` declared in this module, not any + /// current scope. E.g. `@Age` must reference an opaque `Age` declared in this module, not any /// other! - // TODO(opaques): $->@ in the above comment pub fn lookup_opaque_ref( &self, opaque_ref: &str, lookup_region: Region, ) -> Result<(Symbol, &Alias), RuntimeError> { - debug_assert!(opaque_ref.starts_with('$')); + debug_assert!(opaque_ref.starts_with('@')); let opaque = opaque_ref[1..].into(); match self.idents.get(&opaque) { diff --git a/compiler/load_internal/tests/test_load.rs b/compiler/load_internal/tests/test_load.rs index 6f1bfffee3..769eafc8af 100644 --- a/compiler/load_internal/tests/test_load.rs +++ b/compiler/load_internal/tests/test_load.rs @@ -757,9 +757,9 @@ mod test_load { r#" interface Main exposes [ twenty, readAge ] imports [ Age.{ Age } ] - twenty = $Age 20 + twenty = @Age 20 - readAge = \$Age n -> n + readAge = \@Age n -> n "# ), ), @@ -775,7 +775,7 @@ mod test_load { The unwrapped opaque type Age referenced here: - 3│ twenty = $Age 20 + 3│ twenty = @Age 20 ^^^^ is imported from another module: @@ -789,7 +789,7 @@ mod test_load { The unwrapped opaque type Age referenced here: - 5│ readAge = \$Age n -> n + 5│ readAge = \@Age n -> n ^^^^ is imported from another module: diff --git a/compiler/parse/src/ast.rs b/compiler/parse/src/ast.rs index 6880e42086..1b985756c8 100644 --- a/compiler/parse/src/ast.rs +++ b/compiler/parse/src/ast.rs @@ -190,8 +190,7 @@ pub enum Expr<'a> { // Tags GlobalTag(&'a str), - // Reference to an opaque type, e.g. $Opaq - // TODO(opaques): $->@ in the above comment + // Reference to an opaque type, e.g. @Opaq OpaqueRef(&'a str), // Pattern Matching diff --git a/compiler/parse/src/ident.rs b/compiler/parse/src/ident.rs index e871563d9e..82854e2acb 100644 --- a/compiler/parse/src/ident.rs +++ b/compiler/parse/src/ident.rs @@ -36,8 +36,7 @@ impl<'a> From<&'a UppercaseIdent<'a>> for &'a str { pub enum Ident<'a> { /// Foo or Bar GlobalTag(&'a str), - /// $Foo or $Bar - // TODO(opaques): $->@ in the above comment + /// @Foo or @Bar OpaqueRef(&'a str), /// foo or foo.bar or Foo.Bar.baz.qux Access { @@ -291,10 +290,10 @@ fn chomp_accessor(buffer: &[u8], pos: Position) -> Result<&str, BadIdent> { } } -/// a `$Token` opaque +/// a `@Token` opaque fn chomp_opaque_ref(buffer: &[u8], pos: Position) -> Result<&str, BadIdent> { - // assumes the leading `$` has NOT been chomped already - debug_assert_eq!(buffer.get(0), Some(&b'$')); + // assumes the leading `@` has NOT been chomped already + debug_assert_eq!(buffer.get(0), Some(&b'@')); use encode_unicode::CharExt; let bad_ident = BadIdent::BadOpaqueRef; @@ -334,7 +333,7 @@ fn chomp_identifier_chain<'a>( } Err(fail) => return Err((1, fail)), }, - '$' => match chomp_opaque_ref(buffer, pos) { + '@' => match chomp_opaque_ref(buffer, pos) { Ok(tagname) => { let bytes_parsed = tagname.len(); diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index a8ee55ee26..1f42973aaf 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -5462,7 +5462,7 @@ mod solve_expr { r#" Age := U32 - $Age 21 + @Age 21 "# ), r#"Age"#, @@ -5477,7 +5477,7 @@ mod solve_expr { Age := U32 a : Age - a = $Age 21 + a = @Age 21 a "# @@ -5493,7 +5493,7 @@ mod solve_expr { r#" Id n := [ Id U32 n ] - $Id (Id 21 "sasha") + @Id (Id 21 "sasha") "# ), r#"Id Str"#, @@ -5508,7 +5508,7 @@ mod solve_expr { Id n := [ Id U32 n ] a : Id Str - a = $Id (Id 21 "sasha") + a = @Id (Id 21 "sasha") a "# @@ -5526,8 +5526,8 @@ mod solve_expr { condition : Bool if condition - then $Id (Id 21 (Y "sasha")) - else $Id (Id 21 (Z "felix")) + then @Id (Id 21 (Y "sasha")) + else @Id (Id 21 (Z "felix")) "# ), r#"Id [ Y Str, Z Str ]*"#, @@ -5545,8 +5545,8 @@ mod solve_expr { v : Id [ Y Str, Z Str ] v = if condition - then $Id (Id 21 (Y "sasha")) - else $Id (Id 21 (Z "felix")) + then @Id (Id 21 (Y "sasha")) + else @Id (Id 21 (Z "felix")) v "# @@ -5562,7 +5562,7 @@ mod solve_expr { r#" Age := U32 - \$Age n -> n + \@Age n -> n "# ), r#"Age -> U32"#, @@ -5577,7 +5577,7 @@ mod solve_expr { Age := U32 v : Age -> U32 - v = \$Age n -> n + v = \@Age n -> n v "# ), @@ -5592,7 +5592,7 @@ mod solve_expr { r#" Id n := [ Id U32 n ] - \$Id (Id _ n) -> n + \@Id (Id _ n) -> n "# ), r#"Id a -> a"#, @@ -5607,7 +5607,7 @@ mod solve_expr { Id n := [ Id U32 n ] v : Id a -> a - v = \$Id (Id _ n) -> n + v = \@Id (Id _ n) -> n v "# @@ -5625,7 +5625,7 @@ mod solve_expr { strToBool : Str -> Bool - \$Id (Id _ n) -> strToBool n + \@Id (Id _ n) -> strToBool n "# ), r#"Id Str -> Bool"#, @@ -5642,7 +5642,7 @@ mod solve_expr { strToBool : Str -> Bool v : Id Str -> Bool - v = \$Id (Id _ n) -> strToBool n + v = \@Id (Id _ n) -> strToBool n v "# @@ -5660,9 +5660,9 @@ mod solve_expr { \id -> when id is - $Id (Id _ A) -> "" - $Id (Id _ B) -> "" - $Id (Id _ (C { a: "" })) -> "" + @Id (Id _ A) -> "" + @Id (Id _ B) -> "" + @Id (Id _ (C { a: "" })) -> "" "# ), r#"Id [ A, B, C { a : Str }* ] -> Str"#, @@ -5679,9 +5679,9 @@ mod solve_expr { f : Id [ A, B, C { a : Str }e ] -> Str f = \id -> when id is - $Id (Id _ A) -> "" - $Id (Id _ B) -> "" - $Id (Id _ (C { a: "" })) -> "" + @Id (Id _ A) -> "" + @Id (Id _ B) -> "" + @Id (Id _ (C { a: "" })) -> "" f "# @@ -5703,7 +5703,7 @@ mod solve_expr { effectAlways = \x -> inner = \{} -> x - $Effect inner + @Effect inner "# ), r#"a -> Effect a"#, @@ -5765,8 +5765,8 @@ mod solve_expr { insert : Outer k, k -> Outer k insert = \m, var -> when m is - $Outer Empty -> $Outer (Wrapped var) - $Outer (Wrapped _) -> $Outer (Wrapped var) + @Outer Empty -> @Outer (Wrapped var) + @Outer (Wrapped _) -> @Outer (Wrapped var) insert "# @@ -5782,9 +5782,9 @@ mod solve_expr { r#" Outer k := [ Empty, Wrapped k ] - when ($Outer Empty) is - $Outer Empty -> $Outer (Wrapped "") - $Outer (Wrapped k) -> $Outer (Wrapped k) + when (@Outer Empty) is + @Outer Empty -> @Outer (Wrapped "") + @Outer (Wrapped k) -> @Outer (Wrapped k) "# ), r#"Outer Str"#, @@ -5798,9 +5798,9 @@ mod solve_expr { r#" Outer := [ A, B ] - when ($Outer A) is - $Outer A -> $Outer A - $Outer B -> $Outer B + when (@Outer A) is + @Outer A -> @Outer A + @Outer B -> @Outer B "# ), r#"Outer"#, @@ -5857,7 +5857,7 @@ mod solve_expr { Id := U64 - hash = \$Id n -> n + hash = \@Id n -> n "# ), [("Hash:hash", "Id")], @@ -5877,8 +5877,8 @@ mod solve_expr { Id := U64 - hash = \$Id n -> n - hash32 = \$Id n -> Num.toU32 n + hash = \@Id n -> n + hash32 = \@Id n -> Num.toU32 n "# ), [("Hash:hash", "Id"), ("Hash:hash32", "Id")], @@ -5902,11 +5902,11 @@ mod solve_expr { Id := U64 - hash = \$Id n -> n - hash32 = \$Id n -> Num.toU32 n + hash = \@Id n -> n + hash32 = \@Id n -> Num.toU32 n - eq = \$Id m, $Id n -> m == n - le = \$Id m, $Id n -> m < n + eq = \@Id m, @Id n -> m == n + le = \@Id m, @Id n -> m < n "# ), [ @@ -5931,7 +5931,7 @@ mod solve_expr { Id := U64 hash : Id -> U64 - hash = \$Id n -> n + hash = \@Id n -> n "# ), [("Hash:hash", "Id")], @@ -5969,9 +5969,9 @@ mod solve_expr { Id := U64 - hash = \$Id n -> n + hash = \@Id n -> n - zero = hash ($Id 0) + zero = hash (@Id 0) "# ), "U64", @@ -6062,9 +6062,9 @@ mod solve_expr { hashEq = \x, y -> hash x == hash y Id := U64 - hash = \$Id n -> n + hash = \@Id n -> n - result = hashEq ($Id 100) ($Id 101) + result = hashEq (@Id 100) (@Id 101) "# ), "Bool", @@ -6084,12 +6084,12 @@ mod solve_expr { mulHashes = \x, y -> hash x * hash y Id := U64 - hash = \$Id n -> n + hash = \@Id n -> n Three := {} - hash = \$Three _ -> 3 + hash = \@Three _ -> 3 - result = mulHashes ($Id 100) ($Three {}) + result = mulHashes (@Id 100) (@Three {}) "# ), "U64", @@ -6162,7 +6162,7 @@ mod solve_expr { Task a err : Effect (Result a err) always : a -> Task a * - always = \x -> $Effect (\{} -> Ok x) + always = \x -> @Effect (\{} -> Ok x) "# ), "a -> Task a *", diff --git a/compiler/test_gen/src/gen_abilities.rs b/compiler/test_gen/src/gen_abilities.rs index f268f0ae2b..4da1464de1 100644 --- a/compiler/test_gen/src/gen_abilities.rs +++ b/compiler/test_gen/src/gen_abilities.rs @@ -23,9 +23,9 @@ fn hash_specialization() { Id := U64 - hash = \$Id n -> n + hash = \@Id n -> n - main = hash ($Id 1234) + main = hash (@Id 1234) "# ), 1234, @@ -46,13 +46,13 @@ fn hash_specialization_multiple_add() { Id := U64 - hash = \$Id n -> n + hash = \@Id n -> n One := {} - hash = \$One _ -> 1 + hash = \@One _ -> 1 - main = hash ($Id 1234) + hash ($One {}) + main = hash (@Id 1234) + hash (@One {}) "# ), 1235, @@ -73,11 +73,11 @@ fn alias_member_specialization() { Id := U64 - hash = \$Id n -> n + hash = \@Id n -> n main = aliasedHash = hash - aliasedHash ($Id 1234) + aliasedHash (@Id 1234) "# ), 1234, @@ -100,9 +100,9 @@ fn ability_constrained_in_non_member_usage() { mulHashes = \x, y -> hash x * hash y Id := U64 - hash = \$Id n -> n + hash = \@Id n -> n - result = mulHashes ($Id 5) ($Id 7) + result = mulHashes (@Id 5) (@Id 7) "# ), 35, @@ -124,9 +124,9 @@ fn ability_constrained_in_non_member_usage_inferred() { mulHashes = \x, y -> hash x * hash y Id := U64 - hash = \$Id n -> n + hash = \@Id n -> n - result = mulHashes ($Id 5) ($Id 7) + result = mulHashes (@Id 5) (@Id 7) "# ), 35, @@ -149,12 +149,12 @@ fn ability_constrained_in_non_member_multiple_specializations() { mulHashes = \x, y -> hash x * hash y Id := U64 - hash = \$Id n -> n + hash = \@Id n -> n Three := {} - hash = \$Three _ -> 3 + hash = \@Three _ -> 3 - result = mulHashes ($Id 100) ($Three {}) + result = mulHashes (@Id 100) (@Three {}) "# ), 300, @@ -176,12 +176,12 @@ fn ability_constrained_in_non_member_multiple_specializations_inferred() { mulHashes = \x, y -> hash x * hash y Id := U64 - hash = \$Id n -> n + hash = \@Id n -> n Three := {} - hash = \$Three _ -> 3 + hash = \@Three _ -> 3 - result = mulHashes ($Id 100) ($Three {}) + result = mulHashes (@Id 100) (@Three {}) "# ), 300, @@ -204,12 +204,12 @@ fn ability_used_as_type_still_compiles() { mulHashes = \x, y -> hash x * hash y Id := U64 - hash = \$Id n -> n + hash = \@Id n -> n Three := {} - hash = \$Three _ -> 3 + hash = \@Three _ -> 3 - result = mulHashes ($Id 100) ($Three {}) + result = mulHashes (@Id 100) (@Three {}) "# ), 300, diff --git a/compiler/test_gen/src/gen_primitives.rs b/compiler/test_gen/src/gen_primitives.rs index 0657eb4715..3ef5d89e8f 100644 --- a/compiler/test_gen/src/gen_primitives.rs +++ b/compiler/test_gen/src/gen_primitives.rs @@ -1137,10 +1137,10 @@ fn io_poc_effect() { Effect a := {} -> a succeed : a -> Effect a - succeed = \x -> $Effect \{} -> x + succeed = \x -> @Effect \{} -> x runEffect : Effect a -> a - runEffect = \$Effect thunk -> thunk {} + runEffect = \@Effect thunk -> thunk {} foo : Effect F64 foo = @@ -1196,7 +1196,7 @@ fn return_wrapped_function_pointer() { Effect a := {} -> a foo : Effect {} - foo = $Effect \{} -> {} + foo = @Effect \{} -> {} main : Effect {} main = foo @@ -1244,7 +1244,7 @@ fn return_wrapped_closure() { foo = x = 5 - $Effect (\{} -> if x > 3 then {} else {}) + @Effect (\{} -> if x > 3 then {} else {}) main : Effect {} main = foo @@ -1870,10 +1870,10 @@ fn task_always_twice() { effectAlways = \x -> inner = \{} -> x - $Effect inner + @Effect inner effectAfter : Effect a, (a -> Effect b) -> Effect b - effectAfter = \($Effect thunk), transform -> transform (thunk {}) + effectAfter = \(@Effect thunk), transform -> transform (thunk {}) Task a err : Effect (Result a err) @@ -1918,7 +1918,7 @@ fn wildcard_rigid() { always = \x -> inner = \{} -> (Ok x) - $Effect inner + @Effect inner main : Task {} (Float *) @@ -1947,7 +1947,7 @@ fn alias_of_alias_with_type_arguments() { always = \x -> inner = (Ok x) - $Effect inner + @Effect inner main : Task {} (Float *) @@ -1975,10 +1975,10 @@ fn todo_bad_error_message() { effectAlways = \x -> inner = \{} -> x - $Effect inner + @Effect inner effectAfter : Effect a, (a -> Effect b) -> Effect b - effectAfter = \($Effect thunk), transform -> transform (thunk {}) + effectAfter = \(@Effect thunk), transform -> transform (thunk {}) Task a err : Effect (Result a err) @@ -3111,7 +3111,7 @@ fn nested_rigid_alias() { p2 main = - when foo ($Identity "foo") is + when foo (@Identity "foo") is _ -> "hello world" "# ), @@ -3225,13 +3225,13 @@ fn recursively_build_effect() { XEffect a := {} -> a always : a -> XEffect a - always = \x -> $XEffect (\{} -> x) + always = \x -> @XEffect (\{} -> x) after : XEffect a, (a -> XEffect b) -> XEffect b - after = \($XEffect e), toB -> - $XEffect \{} -> + after = \(@XEffect e), toB -> + @XEffect \{} -> when toB (e {}) is - $XEffect e2 -> + @XEffect e2 -> e2 {} "# ), diff --git a/compiler/test_gen/src/gen_tags.rs b/compiler/test_gen/src/gen_tags.rs index 20c2d2b8d6..43bcdb05c8 100644 --- a/compiler/test_gen/src/gen_tags.rs +++ b/compiler/test_gen/src/gen_tags.rs @@ -1058,7 +1058,7 @@ fn phantom_polymorphic() { World := {} zero : Point World - zero = Point ($World {}) 0 0 + zero = Point (@World {}) 0 0 add : Point a -> Point a add = \(Point c x y) -> (Point c x y) @@ -1593,11 +1593,11 @@ fn opaque_assign_to_symbol() { fromUtf8 : U8 -> Result Variable [ InvalidVariableUtf8 ] fromUtf8 = \char -> - Ok ($Variable char) + Ok (@Variable char) out = when fromUtf8 98 is - Ok ($Variable n) -> n + Ok (@Variable n) -> n _ -> 1 "# ), diff --git a/compiler/test_mono/src/tests.rs b/compiler/test_mono/src/tests.rs index fbb2612793..f0c2c51f01 100644 --- a/compiler/test_mono/src/tests.rs +++ b/compiler/test_mono/src/tests.rs @@ -1323,9 +1323,9 @@ fn specialize_ability_call() { Id := U64 hash : Id -> U64 - hash = \$Id n -> n + hash = \@Id n -> n - main = hash ($Id 1234) + main = hash (@Id 1234) "# ) } @@ -1340,7 +1340,7 @@ fn opaque_assign_to_symbol() { fromUtf8 : U8 -> Result Variable [ InvalidVariableUtf8 ] fromUtf8 = \char -> - Ok ($Variable char) + Ok (@Variable char) out = fromUtf8 98 "# diff --git a/examples/benchmarks/Bytes/Decode.roc b/examples/benchmarks/Bytes/Decode.roc index f5b9605e4b..6a5df2c8f3 100644 --- a/examples/benchmarks/Bytes/Decode.roc +++ b/examples/benchmarks/Bytes/Decode.roc @@ -7,7 +7,7 @@ DecodeProblem : [ OutOfBytes ] Decoder a := State -> [ Good State a, Bad DecodeProblem ] decode : List U8, Decoder a -> Result a DecodeProblem -decode = \bytes, $Decoder decoder -> +decode = \bytes, @Decoder decoder -> when decoder { bytes, cursor: 0 } is Good _ value -> Ok value @@ -16,11 +16,11 @@ decode = \bytes, $Decoder decoder -> Err e succeed : a -> Decoder a -succeed = \value -> $Decoder \state -> Good state value +succeed = \value -> @Decoder \state -> Good state value map : Decoder a, (a -> b) -> Decoder b -map = \$Decoder decoder, transform -> - $Decoder +map = \@Decoder decoder, transform -> + @Decoder \state -> when decoder state is Good state1 value -> @@ -30,8 +30,8 @@ map = \$Decoder decoder, transform -> Bad e map2 : Decoder a, Decoder b, (a, b -> c) -> Decoder c -map2 = \$Decoder decoder1, $Decoder decoder2, transform -> - $Decoder +map2 = \@Decoder decoder1, @Decoder decoder2, transform -> + @Decoder \state1 -> when decoder1 state1 is Good state2 a -> @@ -46,8 +46,8 @@ map2 = \$Decoder decoder1, $Decoder decoder2, transform -> Bad e map3 : Decoder a, Decoder b, Decoder c, (a, b, c -> d) -> Decoder d -map3 = \$Decoder decoder1, $Decoder decoder2, $Decoder decoder3, transform -> - $Decoder +map3 = \@Decoder decoder1, @Decoder decoder2, @Decoder decoder3, transform -> + @Decoder \state1 -> when decoder1 state1 is Good state2 a -> @@ -67,12 +67,12 @@ map3 = \$Decoder decoder1, $Decoder decoder2, $Decoder decoder3, transform -> Bad e after : Decoder a, (a -> Decoder b) -> Decoder b -after = \$Decoder decoder, transform -> - $Decoder +after = \@Decoder decoder, transform -> + @Decoder \state -> when decoder state is Good state1 value -> - ($Decoder decoder1) = transform value + (@Decoder decoder1) = transform value decoder1 state1 @@ -80,7 +80,7 @@ after = \$Decoder decoder, transform -> Bad e u8 : Decoder U8 -u8 = $Decoder +u8 = @Decoder \state -> when List.get state.bytes state.cursor is Ok b -> @@ -93,12 +93,12 @@ Step state b : [ Loop state, Done b ] loop : (state -> Decoder (Step state a)), state -> Decoder a loop = \stepper, initial -> - $Decoder + @Decoder \state -> loopHelp stepper initial state loopHelp = \stepper, accum, state -> - ($Decoder stepper1) = stepper accum + (@Decoder stepper1) = stepper accum when stepper1 state is Good newState (Done value) -> diff --git a/examples/false-interpreter/Variable.roc b/examples/false-interpreter/Variable.roc index f6cacbdce5..866ec789b1 100644 --- a/examples/false-interpreter/Variable.roc +++ b/examples/false-interpreter/Variable.roc @@ -15,7 +15,7 @@ totalCount = + 1 toStr : Variable -> Str -toStr = \$Variable char -> +toStr = \@Variable char -> when Str.fromUtf8 [ char ] is Ok str -> str @@ -33,11 +33,11 @@ fromUtf8 = \char -> <= 0x7A # "z" then - Ok ($Variable char) + Ok (@Variable char) else Err InvalidVariableUtf8 toIndex : Variable -> Nat -toIndex = \$Variable char -> +toIndex = \@Variable char -> Num.intCast (char - 0x61)# "a" # List.first (Str.toUtf8 "a") diff --git a/examples/false-interpreter/platform/File.roc b/examples/false-interpreter/platform/File.roc index c92cf4e63c..e64efe749a 100644 --- a/examples/false-interpreter/platform/File.roc +++ b/examples/false-interpreter/platform/File.roc @@ -5,19 +5,19 @@ interface File Handle := U64 line : Handle -> Task.Task Str * -line = \$Handle handle -> Effect.after (Effect.getFileLine handle) Task.succeed +line = \@Handle handle -> Effect.after (Effect.getFileLine handle) Task.succeed chunk : Handle -> Task.Task (List U8) * -chunk = \$Handle handle -> Effect.after (Effect.getFileBytes handle) Task.succeed +chunk = \@Handle handle -> Effect.after (Effect.getFileBytes handle) Task.succeed open : Str -> Task.Task Handle * open = \path -> Effect.openFile path - |> Effect.map (\id -> $Handle id) + |> Effect.map (\id -> @Handle id) |> Effect.after Task.succeed close : Handle -> Task.Task {} * -close = \$Handle handle -> Effect.after (Effect.closeFile handle) Task.succeed +close = \@Handle handle -> Effect.after (Effect.closeFile handle) Task.succeed withOpen : Str, (Handle -> Task {} a) -> Task {} a withOpen = \path, callback -> diff --git a/packages/parser/src/Str/Parser.roc b/packages/parser/src/Str/Parser.roc index 1e7af10c75..7dc755f4c0 100644 --- a/packages/parser/src/Str/Parser.roc +++ b/packages/parser/src/Str/Parser.roc @@ -48,16 +48,16 @@ keep : Parser a, (a -> Parser b) -> Parser b skip : Parser *, ({} -> Parser b) -> Parser b symbol : Str -> Parser {} -symbol = \symbol -> $Parser Str.chompStr symbol +symbol = \symbol -> @Parser Str.chompStr symbol u8 : Parser U8 -u8 = $Parser Str.parseU8 +u8 = @Parser Str.parseU8 i8 : Parser I8 -i8 = $Parser Str.parseI8 +i8 = @Parser Str.parseI8 end : Parser {} -end = $Parser \str -> +end = @Parser \str -> if Str.isEmpty str then Ok {} else @@ -65,7 +65,7 @@ end = $Parser \str -> lazy : ({} -> Parser a) -> Parser a lazy = \thunk -> - $Parser \str -> - $Parser parse = thunk {} + @Parser \str -> + @Parser parse = thunk {} parse str diff --git a/packages/unicode/src/Unicode/CodePoint/Internal.roc b/packages/unicode/src/Unicode/CodePoint/Internal.roc index 27d754e8ca..5ff40f9513 100644 --- a/packages/unicode/src/Unicode/CodePoint/Internal.roc +++ b/packages/unicode/src/Unicode/CodePoint/Internal.roc @@ -13,9 +13,9 @@ interface Unicode.CodePoint.Internal CodePoint := U32 fromU32Unchecked : U32 -> CodePoint -fromU32Unchecked = \u32 -> $CodePoint u32 +fromU32Unchecked = \u32 -> @CodePoint u32 toU32 : CodePoint -> U32 -toU32 = \$CodePoint u32 -> u32 +toU32 = \@CodePoint u32 -> u32 fromU32 : U32 -> Result CodePoint [ BadCodePoint ]* diff --git a/packages/unicode/src/Unicode/Scalar.roc b/packages/unicode/src/Unicode/Scalar.roc index 6979d01d04..b6a06d3e38 100644 --- a/packages/unicode/src/Unicode/Scalar.roc +++ b/packages/unicode/src/Unicode/Scalar.roc @@ -21,7 +21,7 @@ interface Unicode.Scalar Scalar := U32 toStr : Scalar -> Str -toStr = \$Scalar u32 +toStr = \@Scalar u32 when Str.fromScalar u32 is Ok str -> str Err _ -> @@ -29,10 +29,10 @@ toStr = \$Scalar u32 # this Err branch will never run. That's because it only runs # if Str.fromScalar receives an invalid scalar value, and we've # already validated this! - toStr ($Scalar (scalar * 256)) + toStr (@Scalar (scalar * 256)) toCodePt : Scalar -> CodePt -toCodePt = \$Scalar u32 -> Internal.fromU32Unchecked u32 +toCodePt = \@Scalar u32 -> Internal.fromU32Unchecked u32 fromCodePt : CodePt -> Result Scalar [ PointWasSurrogate ]* diff --git a/repl_test/src/tests.rs b/repl_test/src/tests.rs index eb3b1bf6f9..29c43a10a3 100644 --- a/repl_test/src/tests.rs +++ b/repl_test/src/tests.rs @@ -1026,7 +1026,7 @@ fn opaque_apply() { r#" Age := U32 - $Age 23 + @Age 23 "# ), "23 : Age", @@ -1040,7 +1040,7 @@ fn opaque_apply_polymorphic() { r#" F t u := [ Package t u ] - $F (Package "" { a: "" }) + @F (Package "" { a: "" }) "# ), r#"Package "" { a: "" } : F Str { a : Str }"#, @@ -1054,9 +1054,9 @@ fn opaque_pattern_and_call() { r#" F t u := [ Package t u ] - f = \$F (Package A {}) -> $F (Package {} A) + f = \@F (Package A {}) -> @F (Package {} A) - f ($F (Package A {})) + f (@F (Package A {})) "# ), r#"Package {} A : F {} [ A ]*"#, diff --git a/reporting/src/report.rs b/reporting/src/report.rs index 840054cacc..1fa222c813 100644 --- a/reporting/src/report.rs +++ b/reporting/src/report.rs @@ -440,8 +440,7 @@ impl<'a> RocDocAllocator<'a> { pub fn wrapped_opaque_name(&'a self, opaque: Symbol) -> DocBuilder<'a, Self, Annotation> { debug_assert_eq!(opaque.module_id(), self.home, "Opaque wrappings can only be defined in the same module they're defined in, but this one is defined elsewhere: {:?}", opaque); - // TODO(opaques): $->@ - self.text(format!("${}", opaque.ident_str(self.interns))) + self.text(format!("@{}", opaque.ident_str(self.interns))) .annotate(Annotation::Opaque) } diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 9606694ccc..e4f2ddf47c 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -5978,7 +5978,7 @@ I need all branches in an `if` to have the same type! report_problem_as( indoc!( r#" - $UUID.bar + @UUID.bar "# ), indoc!( @@ -5987,7 +5987,7 @@ I need all branches in an `if` to have the same type! I am very confused by this field access: - 1│ $UUID.bar + 1│ @UUID.bar ^^^^ It looks like a record field access on an opaque reference. @@ -8237,7 +8237,7 @@ I need all branches in an `if` to have the same type! report_problem_as( indoc!( r#" - $Age 21 + @Age 21 "# ), indoc!( @@ -8246,7 +8246,7 @@ I need all branches in an `if` to have the same type! The opaque type Age referenced here is not defined: - 1│ $Age 21 + 1│ @Age 21 ^^^^ Note: It looks like there are no opaque types declared in this scope yet! @@ -8262,7 +8262,7 @@ I need all branches in an `if` to have the same type! r#" Age : Num.U8 - $Age 21 + @Age 21 "# ), indoc!( @@ -8271,7 +8271,7 @@ I need all branches in an `if` to have the same type! The opaque type Age referenced here is not defined: - 3│ $Age 21 + 3│ @Age 21 ^^^^ Note: There is an alias of the same name: @@ -8300,19 +8300,19 @@ I need all branches in an `if` to have the same type! report_problem_as( indoc!( r#" - OtherModule.$Age 21 + OtherModule.@Age 21 "# ), - // TODO: get rid of the first error. Consider parsing OtherModule.$Age to completion + // TODO: get rid of the first error. Consider parsing OtherModule.@Age to completion // and checking it during can. The reason the error appears is because it is parsed as - // Apply(Error(OtherModule), [ $Age, 21 ]) + // Apply(Error(OtherModule), [ @Age, 21 ]) indoc!( r#" ── OPAQUE TYPE NOT APPLIED ─────────────────────────────── /code/proj/Main.roc ─ This opaque type is not applied to an argument: - 1│ OtherModule.$Age 21 + 1│ OtherModule.@Age 21 ^^^^ Note: Opaque types always wrap exactly one argument! @@ -8321,7 +8321,7 @@ I need all branches in an `if` to have the same type! I am trying to parse a qualified name here: - 1│ OtherModule.$Age 21 + 1│ OtherModule.@Age 21 ^ I was expecting to see an identifier next, like height. A complete @@ -8340,11 +8340,11 @@ I need all branches in an `if` to have the same type! Age := Num.U8 21u8 - $Age age + @Age age "# ), // TODO(opaques): there is a potential for a better error message here, if the usage of - // `$Age` can be linked to the declaration of `Age` inside `age`, and a suggestion to + // `@Age` can be linked to the declaration of `Age` inside `age`, and a suggestion to // raise that declaration to the outer scope. indoc!( r#" @@ -8362,7 +8362,7 @@ I need all branches in an `if` to have the same type! The opaque type Age referenced here is not defined: - 5│ $Age age + 5│ @Age age ^^^^ Note: It looks like there are no opaque types declared in this scope yet! @@ -8410,7 +8410,7 @@ I need all branches in an `if` to have the same type! Age := Num.U8 n : Age - n = $Age "" + n = @Age "" n "# @@ -8423,7 +8423,7 @@ I need all branches in an `if` to have the same type! This expression is used in an unexpected way: - 4│ n = $Age "" + 4│ n = @Age "" ^^ This argument to an opaque type has type: @@ -8446,8 +8446,8 @@ I need all branches in an `if` to have the same type! F n := n if True - then $F "" - else $F {} + then @F "" + else @F {} "# ), indoc!( @@ -8456,7 +8456,7 @@ I need all branches in an `if` to have the same type! This expression is used in an unexpected way: - 5│ else $F {} + 5│ else @F {} ^^ This argument to an opaque type has type: @@ -8561,8 +8561,8 @@ I need all branches in an `if` to have the same type! \x -> when x is - $F A -> "" - $F {} -> "" + @F A -> "" + @F {} -> "" "# ), indoc!( @@ -8571,7 +8571,7 @@ I need all branches in an `if` to have the same type! The 2nd pattern in this `when` does not match the previous ones: - 6│ $F {} -> "" + 6│ @F {} -> "" ^^^^^ The 2nd pattern is trying to matchF unwrappings of type: @@ -8596,8 +8596,8 @@ I need all branches in an `if` to have the same type! v : F [ A, B, C ] when v is - $F A -> "" - $F B -> "" + @F A -> "" + @F B -> "" "# ), indoc!( @@ -8607,8 +8607,8 @@ I need all branches in an `if` to have the same type! The branches of this `when` expression don't match the condition: 5│> when v is - 6│ $F A -> "" - 7│ $F B -> "" + 6│ @F A -> "" + 7│ @F B -> "" This `v` value is a: @@ -8638,8 +8638,8 @@ I need all branches in an `if` to have the same type! v : F Num.U8 when v is - $F 1 -> "" - $F 2 -> "" + @F 1 -> "" + @F 2 -> "" "# ), indoc!( @@ -8649,12 +8649,12 @@ I need all branches in an `if` to have the same type! This `when` does not cover all the possibilities: 5│> when v is - 6│> $F 1 -> "" - 7│> $F 2 -> "" + 6│> @F 1 -> "" + 7│> @F 2 -> "" Other possibilities include: - $F _ + @F _ I would have to crash if I saw one of those! Add branches for them! "# @@ -9490,7 +9490,7 @@ I need all branches in an `if` to have the same type! Id := U32 - hash = \$Id n -> n + hash = \@Id n -> n "# ), indoc!( @@ -9499,7 +9499,7 @@ I need all branches in an `if` to have the same type! Something is off with this specialization of `hash`: - 7│ hash = \$Id n -> n + 7│ hash = \@Id n -> n ^^^^ This value is a declared specialization of type: @@ -9528,7 +9528,7 @@ I need all branches in an `if` to have the same type! Id := U64 - eq = \$Id m, $Id n -> m == n + eq = \@Id m, @Id n -> m == n "# ), indoc!( @@ -9547,7 +9547,7 @@ I need all branches in an `if` to have the same type! `eq`, specialized here: - 9│ eq = \$Id m, $Id n -> m == n + 9│ eq = \@Id m, @Id n -> m == n ^^ "# ), @@ -9610,7 +9610,7 @@ I need all branches in an `if` to have the same type! You := {} AndI := {} - eq = \$You {}, $AndI {} -> False + eq = \@You {}, @AndI {} -> False "# ), indoc!( @@ -9619,7 +9619,7 @@ I need all branches in an `if` to have the same type! Something is off with this specialization of `eq`: - 9│ eq = \$You {}, $AndI {} -> False + 9│ eq = \@You {}, @AndI {} -> False ^^ This value is a declared specialization of type: @@ -9653,7 +9653,7 @@ I need all branches in an `if` to have the same type! Id := U64 hash : Id -> U32 - hash = \$Id n -> n + hash = \@Id n -> n "# ), indoc!( @@ -9663,7 +9663,7 @@ I need all branches in an `if` to have the same type! Something is off with the body of this definition: 8│ hash : Id -> U32 - 9│ hash = \$Id n -> n + 9│ hash = \@Id n -> n ^ This `n` value is a: @@ -9678,7 +9678,7 @@ I need all branches in an `if` to have the same type! Something is off with this specialization of `hash`: - 9│ hash = \$Id n -> n + 9│ hash = \@Id n -> n ^^^^ This value is a declared specialization of type: @@ -9706,13 +9706,13 @@ I need all branches in an `if` to have the same type! Id := U64 - hash = \$Id n -> n + hash = \@Id n -> n User := {} noGoodVeryBadTerrible = { - nope: hash ($User {}), + nope: hash (@User {}), notYet: hash (A 1), } "# @@ -9738,7 +9738,7 @@ I need all branches in an `if` to have the same type! This expression has a type that does not implement the abilities it's expected to: - 14│ nope: hash ($User {}), + 14│ nope: hash (@User {}), ^^^^^^^^ This User opaque wrapping has the type: @@ -9804,10 +9804,10 @@ I need all branches in an `if` to have the same type! hash : a -> U64 | a has Hash Id := U64 - hash = \$Id n -> n + hash = \@Id n -> n hashable : a | a has Hash - hashable = $Id 15 + hashable = @Id 15 "# ), indoc!( @@ -9817,7 +9817,7 @@ I need all branches in an `if` to have the same type! Something is off with the body of the `hashable` definition: 9│ hashable : a | a has Hash - 10│ hashable = $Id 15 + 10│ hashable = @Id 15 ^^^^^^ This Id opaque wrapping has the type: @@ -9853,12 +9853,12 @@ I need all branches in an `if` to have the same type! mulHashes = \x, y -> hash x * hash y Id := U64 - hash = \$Id n -> n + hash = \@Id n -> n Three := {} - hash = \$Three _ -> 3 + hash = \@Three _ -> 3 - result = mulHashes ($Id 100) ($Three {}) + result = mulHashes (@Id 100) (@Three {}) "# ), indoc!( From 2020d5f30fb89e6ca78b81a57af2c8012b362d05 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Mon, 25 Apr 2022 13:16:44 -0400 Subject: [PATCH 563/846] Format --- compiler/types/src/types.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/types/src/types.rs b/compiler/types/src/types.rs index 9b1d695bc3..b9c3a9a261 100644 --- a/compiler/types/src/types.rs +++ b/compiler/types/src/types.rs @@ -1080,7 +1080,7 @@ impl Type { } result } - + pub fn instantiate_aliases<'a, F>( &mut self, region: Region, From ce407168a96b41e308bcb0126a91eaf55ca57437 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Mon, 25 Apr 2022 13:59:57 -0400 Subject: [PATCH 564/846] Update opaque parse tests --- .../tests/snapshots/pass/opaque_reference_expr.expr.result-ast | 2 +- .../parse/tests/snapshots/pass/opaque_reference_expr.expr.roc | 2 +- .../pass/opaque_reference_expr_with_arguments.expr.result-ast | 2 +- .../pass/opaque_reference_expr_with_arguments.expr.roc | 2 +- .../snapshots/pass/opaque_reference_pattern.expr.result-ast | 2 +- .../tests/snapshots/pass/opaque_reference_pattern.expr.roc | 2 +- .../opaque_reference_pattern_with_arguments.expr.result-ast | 2 +- .../pass/opaque_reference_pattern_with_arguments.expr.roc | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/compiler/parse/tests/snapshots/pass/opaque_reference_expr.expr.result-ast b/compiler/parse/tests/snapshots/pass/opaque_reference_expr.expr.result-ast index 10d11945aa..4dfbe2dc65 100644 --- a/compiler/parse/tests/snapshots/pass/opaque_reference_expr.expr.result-ast +++ b/compiler/parse/tests/snapshots/pass/opaque_reference_expr.expr.result-ast @@ -1,3 +1,3 @@ OpaqueRef( - "$Age", + "@Age", ) diff --git a/compiler/parse/tests/snapshots/pass/opaque_reference_expr.expr.roc b/compiler/parse/tests/snapshots/pass/opaque_reference_expr.expr.roc index fd75aeaae1..6783cae16a 100644 --- a/compiler/parse/tests/snapshots/pass/opaque_reference_expr.expr.roc +++ b/compiler/parse/tests/snapshots/pass/opaque_reference_expr.expr.roc @@ -1 +1 @@ -$Age +@Age diff --git a/compiler/parse/tests/snapshots/pass/opaque_reference_expr_with_arguments.expr.result-ast b/compiler/parse/tests/snapshots/pass/opaque_reference_expr_with_arguments.expr.result-ast index b9db6ccfa8..c42661df16 100644 --- a/compiler/parse/tests/snapshots/pass/opaque_reference_expr_with_arguments.expr.result-ast +++ b/compiler/parse/tests/snapshots/pass/opaque_reference_expr_with_arguments.expr.result-ast @@ -1,6 +1,6 @@ Apply( @0-4 OpaqueRef( - "$Age", + "@Age", ), [ @5-6 Var { diff --git a/compiler/parse/tests/snapshots/pass/opaque_reference_expr_with_arguments.expr.roc b/compiler/parse/tests/snapshots/pass/opaque_reference_expr_with_arguments.expr.roc index e8b6053bba..c7a719c935 100644 --- a/compiler/parse/tests/snapshots/pass/opaque_reference_expr_with_arguments.expr.roc +++ b/compiler/parse/tests/snapshots/pass/opaque_reference_expr_with_arguments.expr.roc @@ -1 +1 @@ -$Age m n +@Age m n diff --git a/compiler/parse/tests/snapshots/pass/opaque_reference_pattern.expr.result-ast b/compiler/parse/tests/snapshots/pass/opaque_reference_pattern.expr.result-ast index 41f8660339..0dd1a3462e 100644 --- a/compiler/parse/tests/snapshots/pass/opaque_reference_pattern.expr.result-ast +++ b/compiler/parse/tests/snapshots/pass/opaque_reference_pattern.expr.result-ast @@ -8,7 +8,7 @@ When( patterns: [ @12-16 SpaceBefore( OpaqueRef( - "$Age", + "@Age", ), [ Newline, diff --git a/compiler/parse/tests/snapshots/pass/opaque_reference_pattern.expr.roc b/compiler/parse/tests/snapshots/pass/opaque_reference_pattern.expr.roc index 49693af6b1..c18631c5fc 100644 --- a/compiler/parse/tests/snapshots/pass/opaque_reference_pattern.expr.roc +++ b/compiler/parse/tests/snapshots/pass/opaque_reference_pattern.expr.roc @@ -1,2 +1,2 @@ when n is - $Age -> 1 + @Age -> 1 diff --git a/compiler/parse/tests/snapshots/pass/opaque_reference_pattern_with_arguments.expr.result-ast b/compiler/parse/tests/snapshots/pass/opaque_reference_pattern_with_arguments.expr.result-ast index 6f159172e8..a572677762 100644 --- a/compiler/parse/tests/snapshots/pass/opaque_reference_pattern_with_arguments.expr.result-ast +++ b/compiler/parse/tests/snapshots/pass/opaque_reference_pattern_with_arguments.expr.result-ast @@ -9,7 +9,7 @@ When( @12-20 SpaceBefore( Apply( @12-16 OpaqueRef( - "$Add", + "@Add", ), [ @17-18 Identifier( diff --git a/compiler/parse/tests/snapshots/pass/opaque_reference_pattern_with_arguments.expr.roc b/compiler/parse/tests/snapshots/pass/opaque_reference_pattern_with_arguments.expr.roc index d5fcf3be4b..8ee3928e79 100644 --- a/compiler/parse/tests/snapshots/pass/opaque_reference_pattern_with_arguments.expr.roc +++ b/compiler/parse/tests/snapshots/pass/opaque_reference_pattern_with_arguments.expr.roc @@ -1,2 +1,2 @@ when n is - $Add n m -> n + m + @Add n m -> n + m From a0d688bfb75a3863b3b44a80530fe43d1b0ce913 Mon Sep 17 00:00:00 2001 From: Folkert Date: Mon, 25 Apr 2022 20:45:38 +0200 Subject: [PATCH 565/846] stop reporting unused ability members --- compiler/can/src/def.rs | 4 --- reporting/tests/test_reporting.rs | 50 ------------------------------- 2 files changed, 54 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index d3773a4108..d17e51ecec 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -452,7 +452,6 @@ pub(crate) fn canonicalize_defs<'a>( &mut output, var_store, &mut scope, - &mut symbols_introduced, abilities, &abilities_in_scope, pattern_type, @@ -554,7 +553,6 @@ fn resolve_abilities<'a>( output: &mut Output, var_store: &mut VarStore, scope: &mut Scope, - symbols_introduced: &mut MutMap, abilities: MutMap, &[AbilityMember])>, abilities_in_scope: &[Symbol], pattern_type: PatternType, @@ -598,8 +596,6 @@ fn resolve_abilities<'a>( } }; - symbols_introduced.insert(member_sym, name_region); - if pattern_type == PatternType::TopLevelDef { env.top_level_symbols.insert(member_sym); } diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 4a091caa06..ca0517e652 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -9305,16 +9305,6 @@ I need all branches in an `if` to have the same type! | a has Ability at the end of the type. - - ── UNUSED DEFINITION ───────────────────────────────────── /code/proj/Main.roc ─ - - `ab` is not used anywhere in your code. - - 3│ Ability has ab : a -> {} | a has Ability - ^^ - - If you didn't intend on using `ab` then remove it so future readers of - your code don't wonder why it is there. "# ), ) @@ -9391,16 +9381,6 @@ I need all branches in an `if` to have the same type! If you didn't intend on using `Ability` then remove it so future readers of your code don't wonder why it is there. - - ── UNUSED DEFINITION ───────────────────────────────────── /code/proj/Main.roc ─ - - `ab` is not used anywhere in your code. - - 3│ Ability has ab : {} -> {} - ^^ - - If you didn't intend on using `ab` then remove it so future readers of - your code don't wonder why it is there. "# ), ) @@ -9432,16 +9412,6 @@ I need all branches in an `if` to have the same type! are a part of. Hint: Did you mean to bind the `Hash` ability instead? - - ── UNUSED DEFINITION ───────────────────────────────────── /code/proj/Main.roc ─ - - `hash` is not used anywhere in your code. - - 4│ Hash has hash : a, b -> Num.U64 | a has Eq, b has Hash - ^^^^ - - If you didn't intend on using `hash` then remove it so future readers of - your code don't wonder why it is there. "# ), ) @@ -9473,16 +9443,6 @@ I need all branches in an `if` to have the same type! looking at specializations! Hint: Did you mean to only bind `a` to `Eq`? - - ── UNUSED DEFINITION ───────────────────────────────────── /code/proj/Main.roc ─ - - `eq` is not used anywhere in your code. - - 3│ Eq has eq : a, b -> Bool.Bool | a has Eq, b has Eq - ^^ - - If you didn't intend on using `eq` then remove it so future readers of - your code don't wonder why it is there. "# ), ) @@ -9526,16 +9486,6 @@ I need all branches in an `if` to have the same type! a has Hash Otherwise, the function does not need to be part of the ability! - - ── UNUSED DEFINITION ───────────────────────────────────── /code/proj/Main.roc ─ - - `hash` is not used anywhere in your code. - - 3│ Hash has hash : (a | a has Hash) -> Num.U64 - ^^^^ - - If you didn't intend on using `hash` then remove it so future readers of - your code don't wonder why it is there. "# ), ) From 945305fc2ba593b89ba2952c316e85a8c0feb166 Mon Sep 17 00:00:00 2001 From: Folkert Date: Mon, 25 Apr 2022 20:50:26 +0200 Subject: [PATCH 566/846] take scope by-value now --- compiler/can/src/def.rs | 8 ++------ compiler/can/src/module.rs | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index d17e51ecec..1da31ccc16 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -203,7 +203,7 @@ pub(crate) fn canonicalize_defs<'a>( env: &mut Env<'a>, mut output: Output, var_store: &mut VarStore, - original_scope: &Scope, + mut scope: Scope, loc_defs: &'a [&'a Loc>], pattern_type: PatternType, ) -> (CanDefs, Scope, Output, MutMap) { @@ -224,11 +224,7 @@ pub(crate) fn canonicalize_defs<'a>( // This naturally handles recursion too, because a given expr which refers // to itself won't be processed until after its def has been added to scope. - // Record both the original and final idents from the scope, - // so we can diff them while detecting unused defs. - let mut scope = original_scope.clone(); let num_defs = loc_defs.len(); - let mut type_defs = Vec::with_capacity(num_defs); let mut value_defs = Vec::with_capacity(num_defs); @@ -1398,7 +1394,7 @@ pub fn can_defs_with_return<'a>( env, Output::default(), var_store, - &scope, + scope, loc_defs, PatternType::DefExpr, ); diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index b34aba4fc5..51c6c47208 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -294,7 +294,7 @@ pub fn canonicalize_module_defs<'a>( &mut env, Output::default(), var_store, - &scope, + scope, &desugared, PatternType::TopLevelDef, ); From a26fa4559aacd84ea1314b237e16e9456f127407 Mon Sep 17 00:00:00 2001 From: Folkert Date: Mon, 25 Apr 2022 21:02:45 +0200 Subject: [PATCH 567/846] prevent intermediate allocation --- compiler/can/src/def.rs | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 1da31ccc16..982f88068a 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -225,25 +225,18 @@ pub(crate) fn canonicalize_defs<'a>( // to itself won't be processed until after its def has been added to scope. let num_defs = loc_defs.len(); - let mut type_defs = Vec::with_capacity(num_defs); + let mut pending_type_defs = Vec::with_capacity(num_defs); let mut value_defs = Vec::with_capacity(num_defs); for loc_def in loc_defs { match loc_def.value.unroll_def() { - Ok(type_def) => type_defs.push(Loc::at(loc_def.region, type_def)), + Ok(type_def) => { + pending_type_defs.push(to_pending_type_def(env, type_def, &mut scope, pattern_type)) + } Err(value_def) => value_defs.push(Loc::at(loc_def.region, value_def)), } } - // We need to canonicalize all the type defs first. - // Clippy is wrong - we do need the collect, otherwise "env" and "scope" are captured for - // longer than we'd like. - #[allow(clippy::needless_collect)] - let pending_type_defs = type_defs - .into_iter() - .map(|loc_def| to_pending_type_def(env, loc_def.value, &mut scope, pattern_type)) - .collect::>(); - if cfg!(debug_assertions) { env.home.register_debug_idents(&env.ident_ids); } From 5a5324f27e23b0ef1ef51fe0622fd31d921f877d Mon Sep 17 00:00:00 2001 From: Folkert Date: Mon, 25 Apr 2022 21:44:44 +0200 Subject: [PATCH 568/846] make IdentIds expose an iterator of &str --- ast/src/lang/env.rs | 8 ++++---- ast/src/lang/scope.rs | 4 ++-- compiler/can/src/env.rs | 8 ++++---- compiler/module/src/symbol.rs | 10 ++++++---- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/ast/src/lang/env.rs b/ast/src/lang/env.rs index 7e7f5a1670..0af9303543 100644 --- a/ast/src/lang/env.rs +++ b/ast/src/lang/env.rs @@ -129,8 +129,8 @@ impl<'a> Env<'a> { region, }, self.ident_ids - .idents() - .map(|(_, string)| string.as_ref().into()) + .ident_strs() + .map(|(_, string)| string.into()) .collect(), )), } @@ -146,9 +146,9 @@ impl<'a> Env<'a> { } None => { let exposed_values = exposed_ids - .idents() + .ident_strs() .filter(|(_, ident)| { - ident.as_ref().starts_with(|c: char| c.is_lowercase()) + ident.starts_with(|c: char| c.is_lowercase()) }) .map(|(_, ident)| Lowercase::from(ident.as_ref())) .collect(); diff --git a/ast/src/lang/scope.rs b/ast/src/lang/scope.rs index b01c818064..26b82b25d7 100644 --- a/ast/src/lang/scope.rs +++ b/ast/src/lang/scope.rs @@ -327,9 +327,9 @@ impl Scope { ) -> ASTResult<()> { let ident_ids = get_module_ident_ids(all_ident_ids, &env.home)?.clone(); - for (_, ident_ref) in ident_ids.idents() { + for (_, ident_ref) in ident_ids.ident_strs() { self.introduce( - ident_ref.as_inline_str().as_str().into(), + ident_ref.into(), &env.exposed_ident_ids, get_module_ident_ids_mut(all_ident_ids, &env.home)?, Region::zero(), diff --git a/compiler/can/src/env.rs b/compiler/can/src/env.rs index 40523b2fb7..2c7a28ad69 100644 --- a/compiler/can/src/env.rs +++ b/compiler/can/src/env.rs @@ -104,8 +104,8 @@ impl<'a> Env<'a> { region, }, self.ident_ids - .idents() - .map(|(_, string)| string.as_ref().into()) + .ident_strs() + .map(|(_, string)| string.into()) .collect(), ); Err(error) @@ -127,9 +127,9 @@ impl<'a> Env<'a> { } None => { let exposed_values = exposed_ids - .idents() + .ident_strs() .filter(|(_, ident)| { - ident.as_ref().starts_with(|c: char| c.is_lowercase()) + ident.starts_with(|c: char| c.is_lowercase()) }) .map(|(_, ident)| Lowercase::from(ident.as_ref())) .collect(); diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index 391a31600d..86648dc9b9 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -542,11 +542,11 @@ pub struct IdentIds { } impl IdentIds { - pub fn idents(&self) -> impl Iterator { + pub fn ident_strs(&self) -> impl Iterator { self.by_id .iter() .enumerate() - .map(|(index, ident)| (IdentId(index as u32), ident)) + .map(|(index, ident)| (IdentId(index as u32), ident.as_inline_str().as_str())) } pub fn add(&mut self, ident_name: Ident) -> IdentId { @@ -639,8 +639,10 @@ impl IdentIds { #[inline(always)] pub fn get_id(&self, ident_name: &Ident) -> Option { - for (id, ident) in self.idents() { - if ident_name == ident { + let ident_name = ident_name.as_inline_str().as_str(); + + for (id, ident_str) in self.ident_strs() { + if ident_name == ident_str { return Some(id); } } From 470dddc17bb15e6b0aedf3d33a84053a9b208a2a Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 25 Apr 2022 15:31:20 -0400 Subject: [PATCH 569/846] Revise roc-for-elm-programmers.md --- roc-for-elm-programmers.md | 45 +++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/roc-for-elm-programmers.md b/roc-for-elm-programmers.md index 5d4cd52569..3c2b09c8d1 100644 --- a/roc-for-elm-programmers.md +++ b/roc-for-elm-programmers.md @@ -674,19 +674,21 @@ includes in its union." ## Opaque Types -The tags discussed in the previous section are globally available, which means -they cannot be used to create opaque types. +In Elm, you can choose to expose (or not) custom types' constructors in order to create [opaque types](http://sporto.github.io/elm-patterns/advanced/opaque-types.html). +Since Roc's _tags_ can be constructed in any module without importing anything, Roc has a separate +_opaque type_ language feature to enable information hiding. -Opaque types are like aliases, but with the following differences: +Opaque types in Roc have some similarities to type aliases, but also some important differences. * Opaque type are defined with `:=` (e.g. `Username := Str` instead of `Username : Str`) -* You can create an instance of an opaque by wrapping it with the `@` syntax (e.g. `@Username "sasha"`) -* You can unwrap opaque types to get their payload with the `@` syntax (e.g. `@Username nameStr = user`) -* Opaque types can only be wrapped and unwrapped in the current module -* Opaque type names can be imported by other modules, but not wrapped and unwrapped there -* Opaque types are only equal if their qualified name (defining module name + type name) are equivalent +* You can get an _opaque wrapper_ by writing an `@` symbol before the name of an opaque type. For example, `@Username` would be an opaque wrapper for the opaque type `Username`. +* Applying an _opaque wrapper_ to another value creates an _opaque value_, whose type is the one referred to by the opaque wrapper. So the expression `@Username "Sasha"` has the type `Username`. +* Applying and destructuring opaque wrappers works like tags; you can write `@Username str = user` to unwrap an opaque wrapper's payload, just like you would with a tag payload. +* Opaque types can only be wrapped and unwrapped in the same module where the opaque type itself is defined. +* You can export opaque type names (e.g. `Username`) to other modules, allowing them to be used in type annotations, but there is no way to export the opaque wrappers themselves. This means that an opaque type can only be wrapped and unwrapped (using `@` syntax) in the same module where it was defined. +* Opaque types are only equal if their names are the same _and_ they were defined in the same module. -For example, suppose I define these inside the `Username` module: +As an example, suppose I define these inside the `Username` module: ```elm Username := Str @@ -699,18 +701,17 @@ toStr : Username -> Str toStr = \@Username str -> str ``` -I can now expose the `Username` type alias, which other modules can use as an opaque type. -It's not even syntactically possible for me to expose `@Username`, -because `@`s allowed in the exposing list. Only code written in this -`Username` module can use the `@Username` wrapper syntax. +I can now expose the `Username` opaque type, which other modules can use in type annotations. +However, it's not even syntactically possible for me to expose the `@Username` opaque wrapper, +because `@` is not allowed in the `exposing` list. Only code written in this `Username` module +can use the `@Username` wrapper. > If I were to define `Username := Str` inside another module (e.g. `Main`) and use `@Username`, -> it would compile, but that `Username` opaque type would have the qualified name `Main.Username`. -> That means it would be type-incompatible with the one created inside the `Username` module, which -> has the qualified name `Username.Username`. -> Even trying to use `==` on them would be a type mismatch, because I would be comparing -> a `Username.Username` with a `Main.Username`, which are incompatible. +> it would compile, but that `Username` opaque type would not be considered equal to the one defined in +> the `Username` module. Although both opaque types have the name `Username`, they were defined in +> different modules. That means the two `Username` types would be type-incompatible with each other, +> and even attempting to use `==` to compare them would be a type mismatch. ## Modules and Shadowing @@ -748,9 +749,9 @@ these expose is very important. All imports and exports in Roc are enumerated explicitly; there is no `..` syntax. -> Since neither global tags nor private tags have a notion of "importing variants" -> (global tags are always available in all modules, and private tags are -> never available in other modules), there's also no `exposing (Foo(..))` equivalent. +> Since tags are available in all modules, Roc does not have a notion of +> "importing variants", and there's also no `exposing (Foo(..))` equivalent. +> (Later on, we'll talk about how opaque types work in Roc.) Like Elm, Roc does not allow shadowing. @@ -1278,7 +1279,7 @@ Roc's standard library has these modules: Some differences to note: -* All these standard modules are imported by default into every module. They also expose all their types (e.g. `Bool`, `List`, `Result`) but they do not expose any values - not even `negate` or `not`. (`True`, `False`, `Ok`, and `Err` are all global tags, so they do not need to be exposed; they are globally available regardless!) +* All these standard modules are imported by default into every module. They also expose all their types (e.g. `Bool`, `List`, `Result`) but they do not expose any values - not even `negate` or `not`. (`True`, `False`, `Ok`, and `Err` are all tags, so they do not need to be exposed; they are globally available regardless!) * In Roc it's called `Str` instead of `String`. * `List` refers to something more like Elm's `Array`, as noted earlier. * No `Char`. This is by design. What most people think of as a "character" is a rendered glyph. However, rendered glyphs are comprised of [grapheme clusters](https://stackoverflow.com/a/27331885), which are a variable number of Unicode code points - and there's no upper bound on how many code points there can be in a single cluster. In a world of emoji, I think this makes `Char` error-prone and it's better to have `Str` be the only first-class unit. For convenience when working with unicode code points (e.g. for performance-critical tasks like parsing), the single-quote syntax is sugar for the corresponding `U32` code point - for example, writing `'鹏'` is exactly the same as writing `40527`. Like Rust, you get a compiler error if you put something in single quotes that's not a valid [Unicode scalar value](http://www.unicode.org/glossary/#unicode_scalar_value). From 85e7969c2d021b91c8c571a544460e51f6d62289 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 25 Apr 2022 15:46:32 -0400 Subject: [PATCH 570/846] Replace references to "global tag" with "tag" --- ast/src/constrain.rs | 10 +++--- ast/src/lang/core/expr/expr2.rs | 2 +- ast/src/lang/core/expr/expr_to_expr2.rs | 10 +++--- ast/src/lang/core/pattern.rs | 12 +++---- ast/src/lang/core/types.rs | 4 +-- cli/src/format.rs | 6 ++-- code_markup/src/markup/convert/from_expr2.rs | 2 +- compiler/builtins/docs/Bool.roc | 2 +- compiler/builtins/src/std.rs | 36 +++++++++---------- compiler/can/src/annotation.rs | 6 ++-- compiler/can/src/builtins.rs | 34 +++++++++--------- compiler/can/src/effect_module.rs | 8 ++--- compiler/can/src/expr.rs | 4 +-- compiler/can/src/operator.rs | 2 +- compiler/can/src/pattern.rs | 8 ++--- compiler/fmt/src/annotation.rs | 4 +-- compiler/fmt/src/expr.rs | 4 +-- compiler/fmt/src/pattern.rs | 4 +-- compiler/gen_dev/src/lib.rs | 2 +- compiler/load_internal/src/docs.rs | 2 +- compiler/load_internal/src/file.rs | 4 +-- compiler/module/src/ident.rs | 10 +++--- compiler/module/src/symbol.rs | 8 ++--- compiler/mono/src/decision_tree.rs | 6 ++-- compiler/mono/src/exhaustive.rs | 4 +-- compiler/mono/src/ir.rs | 4 +-- compiler/mono/src/layout_soa.rs | 2 +- compiler/parse/src/ast.rs | 12 +++---- compiler/parse/src/expr.rs | 20 +++++------ compiler/parse/src/ident.rs | 14 ++++---- compiler/parse/src/pattern.rs | 4 +-- compiler/parse/src/type_annotation.rs | 2 +- .../annotated_tag_destructure.expr.result-ast | 8 ++--- ...ly_parenthetical_tag_args.expr.result-ast} | 2 +- ... => apply_parenthetical_tag_args.expr.roc} | 0 ...r.result-ast => apply_tag.expr.result-ast} | 2 +- ...global_tag.expr.roc => apply_tag.expr.roc} | 0 ...r.result-ast => basic_tag.expr.result-ast} | 2 +- ...global_tag.expr.roc => basic_tag.expr.roc} | 0 ...destructure_tag_assignment.expr.result-ast | 4 +-- ...ttern_with_space_in_parens.expr.result-ast | 14 ++++---- .../snapshots/pass/plus_if.expr.result-ast | 2 +- ...sult-ast => qualified_tag.expr.result-ast} | 0 ...al_tag.expr.roc => qualified_tag.expr.roc} | 0 .../pass/record_with_if.expr.result-ast | 2 +- .../pass/tag_pattern.expr.result-ast | 2 +- .../pass/when_if_guard.expr.result-ast | 2 +- .../pass/when_in_parens.expr.result-ast | 2 +- .../when_in_parens_indented.expr.result-ast | 2 +- compiler/parse/tests/test_parse.rs | 24 ++++++------- compiler/solve/src/solve.rs | 2 +- compiler/solve/tests/solve_expr.rs | 6 ++-- compiler/types/src/builtin_aliases.rs | 26 +++++++------- compiler/types/src/subs.rs | 28 +++++++-------- docs/src/lib.rs | 4 +-- repl_eval/src/eval.rs | 8 ++--- reporting/src/error/canonicalize.rs | 2 +- reporting/src/error/mono.rs | 2 +- reporting/src/error/type.rs | 24 ++++++------- reporting/src/report.rs | 17 +++++---- reporting/tests/test_reporting.rs | 20 +++++------ 61 files changed, 229 insertions(+), 230 deletions(-) rename compiler/parse/tests/snapshots/pass/{apply_parenthetical_global_tag_args.expr.result-ast => apply_parenthetical_tag_args.expr.result-ast} (92%) rename compiler/parse/tests/snapshots/pass/{apply_parenthetical_global_tag_args.expr.roc => apply_parenthetical_tag_args.expr.roc} (100%) rename compiler/parse/tests/snapshots/pass/{apply_global_tag.expr.result-ast => apply_tag.expr.result-ast} (88%) rename compiler/parse/tests/snapshots/pass/{apply_global_tag.expr.roc => apply_tag.expr.roc} (100%) rename compiler/parse/tests/snapshots/pass/{basic_global_tag.expr.result-ast => basic_tag.expr.result-ast} (56%) rename compiler/parse/tests/snapshots/pass/{basic_global_tag.expr.roc => basic_tag.expr.roc} (100%) rename compiler/parse/tests/snapshots/pass/{qualified_global_tag.expr.result-ast => qualified_tag.expr.result-ast} (100%) rename compiler/parse/tests/snapshots/pass/{qualified_global_tag.expr.roc => qualified_tag.expr.roc} (100%) diff --git a/ast/src/constrain.rs b/ast/src/constrain.rs index 1b1eded9c9..de68e4b6cb 100644 --- a/ast/src/constrain.rs +++ b/ast/src/constrain.rs @@ -245,13 +245,13 @@ pub fn constrain_expr<'a>( exists(arena, field_vars, And(constraints)) } } - Expr2::GlobalTag { + Expr2::Tag { variant_var, ext_var, name, arguments, } => { - let tag_name = TagName::Global(name.as_str(env.pool).into()); + let tag_name = TagName::Tag(name.as_str(env.pool).into()); constrain_tag( arena, @@ -1604,13 +1604,13 @@ pub fn constrain_pattern<'a>( state.constraints.push(whole_con); state.constraints.push(record_con); } - GlobalTag { + Tag { whole_var, ext_var, tag_name: name, arguments, } => { - let tag_name = TagName::Global(name.as_str(env.pool).into()); + let tag_name = TagName::Tag(name.as_str(env.pool).into()); constrain_tag_pattern( arena, @@ -2198,7 +2198,7 @@ pub mod test_constrain { } #[test] - fn constrain_global_tag() { + fn constrain_tag() { infer_eq( indoc!( r#" diff --git a/ast/src/lang/core/expr/expr2.rs b/ast/src/lang/core/expr/expr2.rs index f7326d85b8..c6e5068b26 100644 --- a/ast/src/lang/core/expr/expr2.rs +++ b/ast/src/lang/core/expr/expr2.rs @@ -148,7 +148,7 @@ pub enum Expr2 { }, // Sum Types - GlobalTag { + Tag { name: PoolStr, // 4B variant_var: Variable, // 4B ext_var: Variable, // 4B diff --git a/ast/src/lang/core/expr/expr_to_expr2.rs b/ast/src/lang/core/expr/expr_to_expr2.rs index f19b5a7dfc..3d7230589d 100644 --- a/ast/src/lang/core/expr/expr_to_expr2.rs +++ b/ast/src/lang/core/expr/expr_to_expr2.rs @@ -173,10 +173,10 @@ pub fn expr_to_expr2<'a>( (expr, output) } - GlobalTag(tag) => { - // a global tag without any arguments + Tag(tag) => { + // a tag without any arguments ( - Expr2::GlobalTag { + Expr2::Tag { name: PoolStr::new(tag, env.pool), variant_var: env.var_store.fresh(), ext_var: env.var_store.fresh(), @@ -543,12 +543,12 @@ pub fn expr_to_expr2<'a>( // We can't call a runtime error; bail out by propagating it! return (fn_expr, output); } - Expr2::GlobalTag { + Expr2::Tag { variant_var, ext_var, name, .. - } => Expr2::GlobalTag { + } => Expr2::Tag { variant_var, ext_var, name, diff --git a/ast/src/lang/core/pattern.rs b/ast/src/lang/core/pattern.rs index 9ae9c5db9b..80b956ab87 100644 --- a/ast/src/lang/core/pattern.rs +++ b/ast/src/lang/core/pattern.rs @@ -41,7 +41,7 @@ pub enum Pattern2 { StrLiteral(PoolStr), // 8B CharacterLiteral(char), // 4B Underscore, // 0B - GlobalTag { + Tag { whole_var: Variable, // 4B ext_var: Variable, // 4B tag_name: PoolStr, // 8B @@ -265,9 +265,9 @@ pub fn to_pattern2<'a>( ptype => unsupported_pattern(env, ptype, region), }, - GlobalTag(name) => { + Tag(name) => { // Canonicalize the tag's name. - Pattern2::GlobalTag { + Pattern2::Tag { whole_var: env.var_store.fresh(), ext_var: env.var_store.fresh(), tag_name: PoolStr::new(name, env.pool), @@ -296,7 +296,7 @@ pub fn to_pattern2<'a>( } match tag.value { - GlobalTag(name) => Pattern2::GlobalTag { + Tag(name) => Pattern2::Tag { whole_var: env.var_store.fresh(), ext_var: env.var_store.fresh(), tag_name: PoolStr::new(name, env.pool), @@ -479,7 +479,7 @@ pub fn symbols_from_pattern(pool: &Pool, initial: &Pattern2) -> Vec { symbols.push(*symbol); } - GlobalTag { arguments, .. } => { + Tag { arguments, .. } => { for (_, pat_id) in arguments.iter(pool) { let pat = pool.get(*pat_id); stack.push(pat); @@ -540,7 +540,7 @@ pub fn symbols_and_variables_from_pattern( symbols.push((*symbol, variable)); } - GlobalTag { arguments, .. } => { + Tag { arguments, .. } => { for (var, pat_id) in arguments.iter(pool) { let pat = pool.get(*pat_id); stack.push((*var, pat)); diff --git a/ast/src/lang/core/types.rs b/ast/src/lang/core/types.rs index 53d7b33314..3536222bf5 100644 --- a/ast/src/lang/core/types.rs +++ b/ast/src/lang/core/types.rs @@ -694,14 +694,14 @@ fn can_tags<'a>( // a duplicate let new_name = 'inner: loop { match tag { - Tag::Global { name, args } => { + Tag::Apply { name, args } => { let arg_types = PoolVec::with_capacity(args.len() as u32, env.pool); for (type_id, loc_arg) in arg_types.iter_node_ids().zip(args.iter()) { as_type_id(env, scope, rigids, type_id, &loc_arg.value, loc_arg.region); } - let tag_name = TagName::Global(name.value.into()); + let tag_name = TagName::Tag(name.value.into()); tag_types.push((tag_name.clone(), arg_types)); break 'inner tag_name; diff --git a/cli/src/format.rs b/cli/src/format.rs index 3913838f85..28da7a3735 100644 --- a/cli/src/format.rs +++ b/cli/src/format.rs @@ -617,7 +617,7 @@ impl<'a> RemoveSpaces<'a> for Expr<'a> { Expr::Record(a) => Expr::Record(a.remove_spaces(arena)), Expr::Var { module_name, ident } => Expr::Var { module_name, ident }, Expr::Underscore(a) => Expr::Underscore(a), - Expr::GlobalTag(a) => Expr::GlobalTag(a), + Expr::Tag(a) => Expr::Tag(a), Expr::OpaqueRef(a) => Expr::OpaqueRef(a), Expr::Closure(a, b) => Expr::Closure( arena.alloc(a.remove_spaces(arena)), @@ -668,7 +668,7 @@ impl<'a> RemoveSpaces<'a> for Pattern<'a> { fn remove_spaces(&self, arena: &'a Bump) -> Self { match *self { Pattern::Identifier(a) => Pattern::Identifier(a), - Pattern::GlobalTag(a) => Pattern::GlobalTag(a), + Pattern::Tag(a) => Pattern::Tag(a), Pattern::OpaqueRef(a) => Pattern::OpaqueRef(a), Pattern::Apply(a, b) => Pattern::Apply( arena.alloc(a.remove_spaces(arena)), @@ -751,7 +751,7 @@ impl<'a> RemoveSpaces<'a> for HasClause<'a> { impl<'a> RemoveSpaces<'a> for Tag<'a> { fn remove_spaces(&self, arena: &'a Bump) -> Self { match *self { - Tag::Global { name, args } => Tag::Global { + Tag::Apply { name, args } => Tag::Apply { name: name.remove_spaces(arena), args: args.remove_spaces(arena), }, diff --git a/code_markup/src/markup/convert/from_expr2.rs b/code_markup/src/markup/convert/from_expr2.rs index 5987541868..c859e5b8af 100644 --- a/code_markup/src/markup/convert/from_expr2.rs +++ b/code_markup/src/markup/convert/from_expr2.rs @@ -88,7 +88,7 @@ pub fn expr2_to_markup<'a>( mark_id_ast_id_map, ) } - Expr2::GlobalTag { name, .. } => new_markup_node( + Expr2::Tag { name, .. } => new_markup_node( with_indent(indent_level, &get_string(env, name)), ast_node_id, HighlightStyle::Type, diff --git a/compiler/builtins/docs/Bool.roc b/compiler/builtins/docs/Bool.roc index 06b2d09025..5ac3f4e394 100644 --- a/compiler/builtins/docs/Bool.roc +++ b/compiler/builtins/docs/Bool.roc @@ -69,7 +69,7 @@ xor : Bool, Bool -> Bool ## ## Structural equality works as follows: ## -## 1. Global tags are equal if they are the same tag, and also their contents (if any) are equal. +## 1. Tags are equal if they have the same tag name, and also their contents (if any) are equal. ## 2. Records are equal if all their fields are equal. ## 3. Collections ([Str], [List], [Dict], and [Set]) are equal if they are the same length, and also all their corresponding elements are equal. ## 4. [Num] values are equal if their numbers are equal, with one exception: if both arguments to `isEq` are *NaN*, then `isEq` returns `False`. See `Num.isNaN` for more about *NaN*. diff --git a/compiler/builtins/src/std.rs b/compiler/builtins/src/std.rs index 6bfab4321c..8f5299aba6 100644 --- a/compiler/builtins/src/std.rs +++ b/compiler/builtins/src/std.rs @@ -131,7 +131,7 @@ pub fn types() -> MutMap { fn overflow() -> SolvedType { SolvedType::TagUnion( - vec![(TagName::Global("Overflow".into()), vec![])], + vec![(TagName::Tag("Overflow".into()), vec![])], Box::new(SolvedType::Wildcard), ) } @@ -312,7 +312,7 @@ pub fn types() -> MutMap { ); let div_by_zero = SolvedType::TagUnion( - vec![(TagName::Global("DivByZero".into()), vec![])], + vec![(TagName::Tag("DivByZero".into()), vec![])], Box::new(SolvedType::Wildcard), ); @@ -476,7 +476,7 @@ pub fn types() -> MutMap { ); let out_of_bounds = SolvedType::TagUnion( - vec![(TagName::Global("OutOfBounds".into()), vec![])], + vec![(TagName::Tag("OutOfBounds".into()), vec![])], Box::new(SolvedType::Wildcard), ); @@ -551,7 +551,7 @@ pub fn types() -> MutMap { ); let out_of_bounds = SolvedType::TagUnion( - vec![(TagName::Global("OutOfBounds".into()), vec![])], + vec![(TagName::Tag("OutOfBounds".into()), vec![])], Box::new(SolvedType::Wildcard), ); @@ -692,7 +692,7 @@ pub fn types() -> MutMap { // sqrtChecked : Float a -> Result (Float a) [ SqrtOfNegative ]* let sqrt_of_negative = SolvedType::TagUnion( - vec![(TagName::Global("SqrtOfNegative".into()), vec![])], + vec![(TagName::Tag("SqrtOfNegative".into()), vec![])], Box::new(SolvedType::Wildcard), ); @@ -711,7 +711,7 @@ pub fn types() -> MutMap { // logChecked : Float a -> Result (Float a) [ LogNeedsPositive ]* let log_needs_positive = SolvedType::TagUnion( - vec![(TagName::Global("LogNeedsPositive".into()), vec![])], + vec![(TagName::Tag("LogNeedsPositive".into()), vec![])], Box::new(SolvedType::Wildcard), ); @@ -807,7 +807,7 @@ pub fn types() -> MutMap { // bytesToU16 : List U8, Nat -> Result U16 [ OutOfBounds ] { let position_out_of_bounds = SolvedType::TagUnion( - vec![(TagName::Global("OutOfBounds".into()), vec![])], + vec![(TagName::Tag("OutOfBounds".into()), vec![])], Box::new(SolvedType::Wildcard), ); add_top_level_function_type!( @@ -820,7 +820,7 @@ pub fn types() -> MutMap { // bytesToU32 : List U8, Nat -> Result U32 [ OutOfBounds ] { let position_out_of_bounds = SolvedType::TagUnion( - vec![(TagName::Global("OutOfBounds".into()), vec![])], + vec![(TagName::Tag("OutOfBounds".into()), vec![])], Box::new(SolvedType::Wildcard), ); add_top_level_function_type!( @@ -942,7 +942,7 @@ pub fn types() -> MutMap { { let bad_utf8 = SolvedType::TagUnion( vec![( - TagName::Global("BadUtf8".into()), + TagName::Tag("BadUtf8".into()), vec![str_utf8_byte_problem_type(), nat_type()], )], Box::new(SolvedType::Wildcard), @@ -960,10 +960,10 @@ pub fn types() -> MutMap { let bad_utf8 = SolvedType::TagUnion( vec![ ( - TagName::Global("BadUtf8".into()), + TagName::Tag("BadUtf8".into()), vec![str_utf8_byte_problem_type(), nat_type()], ), - (TagName::Global("OutOfBounds".into()), vec![]), + (TagName::Tag("OutOfBounds".into()), vec![]), ], Box::new(SolvedType::Wildcard), ); @@ -999,7 +999,7 @@ pub fn types() -> MutMap { // `str_to_num` in can `builtins.rs` let invalid_str = || { SolvedType::TagUnion( - vec![(TagName::Global("InvalidNumStr".into()), vec![])], + vec![(TagName::Tag("InvalidNumStr".into()), vec![])], Box::new(SolvedType::Wildcard), ) }; @@ -1106,7 +1106,7 @@ pub fn types() -> MutMap { // get : List elem, Nat -> Result elem [ OutOfBounds ]* let index_out_of_bounds = SolvedType::TagUnion( - vec![(TagName::Global("OutOfBounds".into()), vec![])], + vec![(TagName::Tag("OutOfBounds".into()), vec![])], Box::new(SolvedType::Wildcard), ); @@ -1118,7 +1118,7 @@ pub fn types() -> MutMap { // first : List elem -> Result elem [ ListWasEmpty ]* let list_was_empty = SolvedType::TagUnion( - vec![(TagName::Global("ListWasEmpty".into()), vec![])], + vec![(TagName::Tag("ListWasEmpty".into()), vec![])], Box::new(SolvedType::Wildcard), ); @@ -1223,8 +1223,8 @@ pub fn types() -> MutMap { // [ LT, EQ, GT ] SolvedType::TagUnion( vec![ - (TagName::Global("Continue".into()), vec![content.clone()]), - (TagName::Global("Stop".into()), vec![content]), + (TagName::Tag("Continue".into()), vec![content.clone()]), + (TagName::Tag("Stop".into()), vec![content]), ], Box::new(SolvedType::EmptyTagUnion), ) @@ -1585,7 +1585,7 @@ pub fn types() -> MutMap { // find : List elem, (elem -> Bool) -> Result elem [ NotFound ]* { let not_found = SolvedType::TagUnion( - vec![(TagName::Global("NotFound".into()), vec![])], + vec![(TagName::Tag("NotFound".into()), vec![])], Box::new(SolvedType::Wildcard), ); let (elem, cvar) = (TVAR1, TVAR2); @@ -1627,7 +1627,7 @@ pub fn types() -> MutMap { // get : Dict k v, k -> Result v [ KeyNotFound ]* let key_not_found = SolvedType::TagUnion( - vec![(TagName::Global("KeyNotFound".into()), vec![])], + vec![(TagName::Tag("KeyNotFound".into()), vec![])], Box::new(SolvedType::Wildcard), ); diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index fe07bccbab..c5e9548c40 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -365,7 +365,7 @@ pub fn find_type_def_symbols( while let Some(tag) = inner_stack.pop() { match tag { - Tag::Global { args, .. } => { + Tag::Apply { args, .. } => { for t in args.iter() { stack.push(&t.value); } @@ -1229,7 +1229,7 @@ fn can_tags<'a>( // a duplicate let new_name = 'inner: loop { match tag { - Tag::Global { name, args } => { + Tag::Apply { name, args } => { let name = name.value.into(); let mut arg_types = Vec::with_capacity(args.len()); @@ -1248,7 +1248,7 @@ fn can_tags<'a>( arg_types.push(ann); } - let tag_name = TagName::Global(name); + let tag_name = TagName::Tag(name); tag_types.push((tag_name.clone(), arg_types)); break 'inner tag_name; diff --git a/compiler/can/src/builtins.rs b/compiler/can/src/builtins.rs index 446a32a194..e2fea78b27 100644 --- a/compiler/can/src/builtins.rs +++ b/compiler/can/src/builtins.rs @@ -4662,7 +4662,7 @@ fn result_map(symbol: Symbol, var_store: &mut VarStore) -> Def { CalledVia::Space, ); - let tag_name = TagName::Global("Ok".into()); + let tag_name = TagName::Tag("Ok".into()); // ok branch let ok = Tag { @@ -4693,7 +4693,7 @@ fn result_map(symbol: Symbol, var_store: &mut VarStore) -> Def { { // err branch - let tag_name = TagName::Global("Err".into()); + let tag_name = TagName::Tag("Err".into()); let err = Tag { variant_var: var_store.fresh(), @@ -4759,7 +4759,7 @@ fn result_map_err(symbol: Symbol, var_store: &mut VarStore) -> Def { CalledVia::Space, ); - let tag_name = TagName::Global("Err".into()); + let tag_name = TagName::Tag("Err".into()); // ok branch let ok = Tag { @@ -4790,7 +4790,7 @@ fn result_map_err(symbol: Symbol, var_store: &mut VarStore) -> Def { { // err branch - let tag_name = TagName::Global("Ok".into()); + let tag_name = TagName::Tag("Ok".into()); let err = Tag { variant_var: var_store.fresh(), @@ -4843,7 +4843,7 @@ fn result_with_default(symbol: Symbol, var_store: &mut VarStore) -> Def { { // ok branch - let tag_name = TagName::Global("Ok".into()); + let tag_name = TagName::Tag("Ok".into()); let pattern = Pattern::AppliedTag { whole_var: result_var, @@ -4863,7 +4863,7 @@ fn result_with_default(symbol: Symbol, var_store: &mut VarStore) -> Def { { // err branch - let tag_name = TagName::Global("Err".into()); + let tag_name = TagName::Tag("Err".into()); let pattern = Pattern::AppliedTag { whole_var: result_var, @@ -4906,7 +4906,7 @@ fn result_is_err(symbol: Symbol, var_store: &mut VarStore) -> Def { { // ok branch - let tag_name = TagName::Global("Ok".into()); + let tag_name = TagName::Tag("Ok".into()); let pattern = Pattern::AppliedTag { whole_var: result_var, @@ -4918,7 +4918,7 @@ fn result_is_err(symbol: Symbol, var_store: &mut VarStore) -> Def { let false_expr = Tag { variant_var: var_store.fresh(), ext_var: var_store.fresh(), - name: TagName::Global("False".into()), + name: TagName::Tag("False".into()), arguments: vec![], }; @@ -4933,7 +4933,7 @@ fn result_is_err(symbol: Symbol, var_store: &mut VarStore) -> Def { { // err branch - let tag_name = TagName::Global("Err".into()); + let tag_name = TagName::Tag("Err".into()); let pattern = Pattern::AppliedTag { whole_var: result_var, @@ -4945,7 +4945,7 @@ fn result_is_err(symbol: Symbol, var_store: &mut VarStore) -> Def { let true_expr = Tag { variant_var: var_store.fresh(), ext_var: var_store.fresh(), - name: TagName::Global("True".into()), + name: TagName::Tag("True".into()), arguments: vec![], }; @@ -4983,7 +4983,7 @@ fn result_is_ok(symbol: Symbol, var_store: &mut VarStore) -> Def { { // ok branch - let tag_name = TagName::Global("Ok".into()); + let tag_name = TagName::Tag("Ok".into()); let pattern = Pattern::AppliedTag { whole_var: result_var, @@ -4995,7 +4995,7 @@ fn result_is_ok(symbol: Symbol, var_store: &mut VarStore) -> Def { let true_expr = Tag { variant_var: var_store.fresh(), ext_var: var_store.fresh(), - name: TagName::Global("True".into()), + name: TagName::Tag("True".into()), arguments: vec![], }; @@ -5010,7 +5010,7 @@ fn result_is_ok(symbol: Symbol, var_store: &mut VarStore) -> Def { { // err branch - let tag_name = TagName::Global("Err".into()); + let tag_name = TagName::Tag("Err".into()); let pattern = Pattern::AppliedTag { whole_var: result_var, @@ -5022,7 +5022,7 @@ fn result_is_ok(symbol: Symbol, var_store: &mut VarStore) -> Def { let false_expr = Tag { variant_var: var_store.fresh(), ext_var: var_store.fresh(), - name: TagName::Global("False".into()), + name: TagName::Tag("False".into()), arguments: vec![], }; @@ -5073,7 +5073,7 @@ fn result_after(symbol: Symbol, var_store: &mut VarStore) -> Def { CalledVia::Space, ); - let tag_name = TagName::Global("Ok".into()); + let tag_name = TagName::Tag("Ok".into()); // ok branch let ok = call_func; @@ -5099,7 +5099,7 @@ fn result_after(symbol: Symbol, var_store: &mut VarStore) -> Def { { // err branch - let tag_name = TagName::Global("Err".into()); + let tag_name = TagName::Tag("Err".into()); let err = Tag { variant_var: var_store.fresh(), @@ -5157,7 +5157,7 @@ fn tag(name: &'static str, args: Vec, var_store: &mut VarStore) -> Expr { Expr::Tag { variant_var: var_store.fresh(), ext_var: var_store.fresh(), - name: TagName::Global(name.into()), + name: TagName::Tag(name.into()), arguments: args .into_iter() .map(|expr| (var_store.fresh(), no_region(expr))) diff --git a/compiler/can/src/effect_module.rs b/compiler/can/src/effect_module.rs index d2f6e61c5d..9fe4cff52d 100644 --- a/compiler/can/src/effect_module.rs +++ b/compiler/can/src/effect_module.rs @@ -1106,8 +1106,8 @@ fn build_effect_loop( ); let state_type = { - let step_tag_name = TagName::Global("Step".into()); - let done_tag_name = TagName::Global("Done".into()); + let step_tag_name = TagName::Tag("Step".into()); + let done_tag_name = TagName::Tag("Done".into()); Type::TagUnion( vec![ @@ -1336,7 +1336,7 @@ fn build_effect_loop_inner_body( let force_thunk2 = force_effect(loop_new_state_step, effect_symbol, thunk2_symbol, var_store); let step_branch = { - let step_tag_name = TagName::Global("Step".into()); + let step_tag_name = TagName::Tag("Step".into()); let step_pattern = applied_tag_pattern(step_tag_name, &[new_state_symbol], var_store); @@ -1348,7 +1348,7 @@ fn build_effect_loop_inner_body( }; let done_branch = { - let done_tag_name = TagName::Global("Done".into()); + let done_tag_name = TagName::Tag("Done".into()); let done_pattern = applied_tag_pattern(done_tag_name, &[done_symbol], var_store); crate::expr::WhenBranch { diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index 15301c832a..c64fd8faf8 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -813,7 +813,7 @@ pub fn canonicalize_expr<'a>( }), Output::default(), ), - ast::Expr::GlobalTag(tag) => { + ast::Expr::Tag(tag) => { let variant_var = var_store.fresh(); let ext_var = var_store.fresh(); @@ -821,7 +821,7 @@ pub fn canonicalize_expr<'a>( ( ZeroArgumentTag { - name: TagName::Global((*tag).into()), + name: TagName::Tag((*tag).into()), variant_var, closure_name: symbol, ext_var, diff --git a/compiler/can/src/operator.rs b/compiler/can/src/operator.rs index 85a5bc1c5f..271e33ff0a 100644 --- a/compiler/can/src/operator.rs +++ b/compiler/can/src/operator.rs @@ -150,7 +150,7 @@ pub fn desugar_expr<'a>(arena: &'a Bump, loc_expr: &'a Loc>) -> &'a Loc | MalformedIdent(_, _) | MalformedClosure | PrecedenceConflict { .. } - | GlobalTag(_) + | Tag(_) | OpaqueRef(_) => loc_expr, Access(sub_expr, paths) => { diff --git a/compiler/can/src/pattern.rs b/compiler/can/src/pattern.rs index 7fb54af2ea..c35d214645 100644 --- a/compiler/can/src/pattern.rs +++ b/compiler/can/src/pattern.rs @@ -260,12 +260,12 @@ pub fn canonicalize_pattern<'a>( Pattern::Shadowed(original_region, shadow, new_symbol) } }, - GlobalTag(name) => { + Tag(name) => { // Canonicalize the tag's name. Pattern::AppliedTag { whole_var: var_store.fresh(), ext_var: var_store.fresh(), - tag_name: TagName::Global((*name).into()), + tag_name: TagName::Tag((*name).into()), arguments: vec![], } } @@ -294,8 +294,8 @@ pub fn canonicalize_pattern<'a>( } match tag.value { - GlobalTag(name) => { - let tag_name = TagName::Global(name.into()); + Tag(name) => { + let tag_name = TagName::Tag(name.into()); Pattern::AppliedTag { whole_var: var_store.fresh(), ext_var: var_store.fresh(), diff --git a/compiler/fmt/src/annotation.rs b/compiler/fmt/src/annotation.rs index d28868ccf8..99220a4043 100644 --- a/compiler/fmt/src/annotation.rs +++ b/compiler/fmt/src/annotation.rs @@ -468,7 +468,7 @@ impl<'a> Formattable for Tag<'a> { use self::Tag::*; match self { - Global { args, .. } => args.iter().any(|arg| (&arg.value).is_multiline()), + Apply { args, .. } => args.iter().any(|arg| (&arg.value).is_multiline()), Tag::SpaceBefore(_, _) | Tag::SpaceAfter(_, _) => true, Malformed(text) => text.chars().any(|c| c == '\n'), } @@ -484,7 +484,7 @@ impl<'a> Formattable for Tag<'a> { let is_multiline = self.is_multiline(); match self { - Tag::Global { name, args } => { + Tag::Apply { name, args } => { buf.indent(indent); buf.push_str(name.value); if is_multiline { diff --git a/compiler/fmt/src/expr.rs b/compiler/fmt/src/expr.rs index c6d059237d..65e1773e34 100644 --- a/compiler/fmt/src/expr.rs +++ b/compiler/fmt/src/expr.rs @@ -37,7 +37,7 @@ impl<'a> Formattable for Expr<'a> { | Underscore { .. } | MalformedIdent(_, _) | MalformedClosure - | GlobalTag(_) + | Tag(_) | OpaqueRef(_) => false, // These expressions always have newlines @@ -272,7 +272,7 @@ impl<'a> Formattable for Expr<'a> { buf.indent(indent); buf.push_str(string); } - GlobalTag(string) | OpaqueRef(string) => { + Tag(string) | OpaqueRef(string) => { buf.indent(indent); buf.push_str(string) } diff --git a/compiler/fmt/src/pattern.rs b/compiler/fmt/src/pattern.rs index 2d4d5357a8..e4f53fc47c 100644 --- a/compiler/fmt/src/pattern.rs +++ b/compiler/fmt/src/pattern.rs @@ -28,7 +28,7 @@ impl<'a> Formattable for Pattern<'a> { Pattern::OptionalField(_, expr) => expr.is_multiline(), Pattern::Identifier(_) - | Pattern::GlobalTag(_) + | Pattern::Tag(_) | Pattern::OpaqueRef(_) | Pattern::Apply(_, _) | Pattern::NumLiteral(..) @@ -57,7 +57,7 @@ impl<'a> Formattable for Pattern<'a> { buf.indent(indent); buf.push_str(string) } - GlobalTag(name) | OpaqueRef(name) => { + Tag(name) | OpaqueRef(name) => { buf.indent(indent); buf.push_str(name); } diff --git a/compiler/gen_dev/src/lib.rs b/compiler/gen_dev/src/lib.rs index 04e79d5831..73bcd5c7df 100644 --- a/compiler/gen_dev/src/lib.rs +++ b/compiler/gen_dev/src/lib.rs @@ -913,7 +913,7 @@ trait Backend<'a> { TagName::Closure(sym) => { self.set_last_seen(*sym, stmt); } - TagName::Global(_) => {} + TagName::Tag(_) => {} } for sym in *arguments { self.set_last_seen(*sym, stmt); diff --git a/compiler/load_internal/src/docs.rs b/compiler/load_internal/src/docs.rs index 96fed09873..de45d9f0c0 100644 --- a/compiler/load_internal/src/docs.rs +++ b/compiler/load_internal/src/docs.rs @@ -373,7 +373,7 @@ fn record_field_to_doc( // The Option here represents if it is malformed. fn tag_to_doc(in_func_ann: bool, tag: ast::Tag) -> Option { match tag { - ast::Tag::Global { name, args } => Some(Tag { + ast::Tag::Apply { name, args } => Some(Tag { name: name.value.to_string(), values: { let mut type_vars = Vec::new(); diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index 6fcb0785ae..e0a8543c76 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -4837,8 +4837,8 @@ fn default_aliases() -> roc_solve::solve::Aliases { let typ = Type::TagUnion( vec![ - (TagName::Global("Ok".into()), vec![Type::Variable(tvar1)]), - (TagName::Global("Err".into()), vec![Type::Variable(tvar2)]), + (TagName::Tag("Ok".into()), vec![Type::Variable(tvar1)]), + (TagName::Tag("Err".into()), vec![Type::Variable(tvar2)]), ], TypeExtension::Closed, ); diff --git a/compiler/module/src/ident.rs b/compiler/module/src/ident.rs index 5335cad281..1ce0bbb9f8 100644 --- a/compiler/module/src/ident.rs +++ b/compiler/module/src/ident.rs @@ -44,14 +44,14 @@ pub type TagIdIntType = u16; #[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] pub enum TagName { - /// Global tags have no module, but tend to be short strings (since they're + /// Tags have no module, but tend to be short strings (since they're /// never qualified), so we store them as ident strings. /// /// This is allows canonicalization to happen in parallel without locks. - /// If global tags had a Symbol representation, then each module would have to - /// deal with contention on a global mutex around translating global tag strings + /// If tags had a Symbol representation, then each module would have to + /// deal with contention on a global mutex around translating tag strings /// into integers. (Record field labels work the same way, for the same reason.) - Global(Uppercase), + Tag(Uppercase), /// Used to connect the closure size to the function it corresponds to Closure(Symbol), @@ -64,7 +64,7 @@ roc_error_macros::assert_sizeof_default!(TagName, 24); impl TagName { pub fn as_ident_str(&self, interns: &Interns, home: ModuleId) -> IdentStr { match self { - TagName::Global(uppercase) => uppercase.as_ident_str().clone(), + TagName::Tag(uppercase) => uppercase.as_ident_str().clone(), TagName::Closure(symbol) => { symbol.fully_qualified(interns, home).as_ident_str().clone() } diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index 391a31600d..a3492ae84b 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -1048,9 +1048,9 @@ define_builtins! { 2 BOOL: "Bool" => { 0 BOOL_BOOL: "Bool" // the Bool.Bool type alias 1 BOOL_FALSE: "False" imported // Bool.Bool = [ False, True ] - // NB: not strictly needed; used for finding global tag names in error suggestions + // NB: not strictly needed; used for finding tag names in error suggestions 2 BOOL_TRUE: "True" imported // Bool.Bool = [ False, True ] - // NB: not strictly needed; used for finding global tag names in error suggestions + // NB: not strictly needed; used for finding tag names in error suggestions 3 BOOL_AND: "and" 4 BOOL_OR: "or" 5 BOOL_NOT: "not" @@ -1157,9 +1157,9 @@ define_builtins! { 5 RESULT: "Result" => { 0 RESULT_RESULT: "Result" // the Result.Result type alias 1 RESULT_OK: "Ok" imported // Result.Result a e = [ Ok a, Err e ] - // NB: not strictly needed; used for finding global tag names in error suggestions + // NB: not strictly needed; used for finding tag names in error suggestions 2 RESULT_ERR: "Err" imported // Result.Result a e = [ Ok a, Err e ] - // NB: not strictly needed; used for finding global tag names in error suggestions + // NB: not strictly needed; used for finding tag names in error suggestions 3 RESULT_MAP: "map" 4 RESULT_MAP_ERR: "mapErr" 5 RESULT_WITH_DEFAULT: "withDefault" diff --git a/compiler/mono/src/decision_tree.rs b/compiler/mono/src/decision_tree.rs index 2295d307a7..8e3f3816b8 100644 --- a/compiler/mono/src/decision_tree.rs +++ b/compiler/mono/src/decision_tree.rs @@ -512,7 +512,7 @@ fn test_at_path<'a>( render_as: RenderAs::Tag, alternatives: vec![Ctor { tag_id: TagId(0), - name: CtorName::Tag(TagName::Global(RECORD_TAG_NAME.into())), + name: CtorName::Tag(TagName::Tag(RECORD_TAG_NAME.into())), arity: destructs.len(), }], }; @@ -532,7 +532,7 @@ fn test_at_path<'a>( IsCtor { tag_id: 0, - ctor_name: CtorName::Tag(TagName::Global(RECORD_TAG_NAME.into())), + ctor_name: CtorName::Tag(TagName::Tag(RECORD_TAG_NAME.into())), union, arguments, } @@ -685,7 +685,7 @@ fn to_relevant_branch_help<'a>( tag_id, .. } => { - debug_assert!(test_name == &CtorName::Tag(TagName::Global(RECORD_TAG_NAME.into()))); + debug_assert!(test_name == &CtorName::Tag(TagName::Tag(RECORD_TAG_NAME.into()))); let sub_positions = destructs.into_iter().enumerate().map(|(index, destruct)| { let pattern = match destruct.typ { DestructType::Guard(guard) => guard.clone(), diff --git a/compiler/mono/src/exhaustive.rs b/compiler/mono/src/exhaustive.rs index 514cdf3f2d..3d7ba6257d 100644 --- a/compiler/mono/src/exhaustive.rs +++ b/compiler/mono/src/exhaustive.rs @@ -45,7 +45,7 @@ fn simplify(pattern: &crate::ir::Pattern) -> Pattern { let union = Union { render_as: RenderAs::Record(field_names), alternatives: vec![Ctor { - name: CtorName::Tag(TagName::Global("#Record".into())), + name: CtorName::Tag(TagName::Tag("#Record".into())), tag_id, arity: destructures.len(), }], @@ -169,7 +169,7 @@ fn to_nonredundant_rows( render_as: RenderAs::Guard, alternatives: vec![Ctor { tag_id, - name: CtorName::Tag(TagName::Global("#Guard".into())), + name: CtorName::Tag(TagName::Tag("#Guard".into())), arity: 2, }], }; diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index f98b26370f..11eb3508fb 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -1655,7 +1655,7 @@ impl<'a> Expr<'a> { .. } => { let doc_tag = match tag_name { - TagName::Global(s) => alloc.text(s.as_str()), + TagName::Tag(s) => alloc.text(s.as_str()), TagName::Closure(s) => alloc .text("ClosureTag(") .append(symbol_to_doc(alloc, *s)) @@ -1676,7 +1676,7 @@ impl<'a> Expr<'a> { .. } => { let doc_tag = match tag_name { - TagName::Global(s) => alloc.text(s.as_str()), + TagName::Tag(s) => alloc.text(s.as_str()), TagName::Closure(s) => alloc .text("ClosureTag(") .append(symbol_to_doc(alloc, *s)) diff --git a/compiler/mono/src/layout_soa.rs b/compiler/mono/src/layout_soa.rs index 85bd46553f..f5477a5976 100644 --- a/compiler/mono/src/layout_soa.rs +++ b/compiler/mono/src/layout_soa.rs @@ -343,7 +343,7 @@ impl LambdaSet { TagName::Closure(symbol) => { layouts.symbols.push(*symbol); } - TagName::Global(_) => unreachable!("lambda set tags must be closure tags"), + TagName::Tag(_) => unreachable!("lambda set tags must be closure tags"), } } diff --git a/compiler/parse/src/ast.rs b/compiler/parse/src/ast.rs index 1b985756c8..a47f2da392 100644 --- a/compiler/parse/src/ast.rs +++ b/compiler/parse/src/ast.rs @@ -188,7 +188,7 @@ pub enum Expr<'a> { Underscore(&'a str), // Tags - GlobalTag(&'a str), + Tag(&'a str), // Reference to an opaque type, e.g. @Opaq OpaqueRef(&'a str), @@ -439,7 +439,7 @@ pub enum TypeAnnotation<'a> { #[derive(Debug, Clone, Copy, PartialEq)] pub enum Tag<'a> { - Global { + Apply { name: Loc<&'a str>, args: &'a [Loc>], }, @@ -515,7 +515,7 @@ pub enum Pattern<'a> { // Identifier Identifier(&'a str), - GlobalTag(&'a str), + Tag(&'a str), OpaqueRef(&'a str), @@ -570,7 +570,7 @@ pub enum Base { impl<'a> Pattern<'a> { pub fn from_ident(arena: &'a Bump, ident: Ident<'a>) -> Pattern<'a> { match ident { - Ident::GlobalTag(string) => Pattern::GlobalTag(string), + Ident::Tag(string) => Pattern::Tag(string), Ident::OpaqueRef(string) => Pattern::OpaqueRef(string), Ident::Access { module_name, parts } => { if parts.len() == 1 { @@ -619,7 +619,7 @@ impl<'a> Pattern<'a> { match (self, other) { (Identifier(x), Identifier(y)) => x == y, - (GlobalTag(x), GlobalTag(y)) => x == y, + (Tag(x), Tag(y)) => x == y, (Apply(constructor_x, args_x), Apply(constructor_y, args_y)) => { let equivalent_args = args_x .iter() @@ -917,7 +917,7 @@ impl<'a> Expr<'a> { } pub fn is_tag(&self) -> bool { - matches!(self, Expr::GlobalTag(_)) + matches!(self, Expr::Tag(_)) } } diff --git a/compiler/parse/src/expr.rs b/compiler/parse/src/expr.rs index 04074aa9fb..2ede367506 100644 --- a/compiler/parse/src/expr.rs +++ b/compiler/parse/src/expr.rs @@ -604,7 +604,7 @@ fn append_body_definition<'a>( // UserId x = UserId 42 // We optimistically parsed the first line as an alias; we now turn it // into an annotation. - let loc_name = arena.alloc(header.name.map(|x| Pattern::GlobalTag(x))); + let loc_name = arena.alloc(header.name.map(|x| Pattern::Tag(x))); let ann_pattern = Pattern::Apply(loc_name, header.vars); let vars_region = Region::across_all(header.vars.iter().map(|v| &v.region)); let region_ann_pattern = Region::span_across(&loc_name.region, &vars_region); @@ -698,7 +698,7 @@ fn append_annotation_definition<'a>( match &loc_pattern.value { Pattern::Apply( Loc { - value: Pattern::GlobalTag(name), + value: Pattern::Tag(name), .. }, alias_arguments, @@ -712,7 +712,7 @@ fn append_annotation_definition<'a>( loc_ann, kind, ), - Pattern::GlobalTag(name) => append_type_definition( + Pattern::Tag(name) => append_type_definition( arena, defs, region, @@ -873,12 +873,12 @@ fn parse_defs_end<'a>( { Pattern::Apply( Loc { - value: Pattern::GlobalTag(name), + value: Pattern::Tag(name), region, }, args, ) => Some((name, *region, args)), - Pattern::GlobalTag(name) => Some((name, loc_pattern.region, &[])), + Pattern::Tag(name) => Some((name, loc_pattern.region, &[])), _ => None, }; @@ -1020,7 +1020,7 @@ fn finish_parsing_alias_or_opaque<'a>( .map_err(|fail| (MadeProgress, fail, state.clone()))?; let (loc_def, state) = match &expr.value { - Expr::GlobalTag(name) => { + Expr::Tag(name) => { let mut type_arguments = Vec::with_capacity_in(arguments.len(), arena); for argument in arguments { @@ -1543,11 +1543,11 @@ fn parse_expr_end<'a>( .. }, state, - )) if matches!(expr_state.expr.value, Expr::GlobalTag(..)) => { + )) if matches!(expr_state.expr.value, Expr::Tag(..)) => { // This is an ability definition, `Ability arg1 ... has ...`. let name = expr_state.expr.map_owned(|e| match e { - Expr::GlobalTag(name) => name, + Expr::Tag(name) => name, _ => unreachable!(), }); @@ -1763,7 +1763,7 @@ fn expr_to_pattern_help<'a>(arena: &'a Bump, expr: &Expr<'a>) -> Result Ok(Pattern::Underscore(opt_name)), - Expr::GlobalTag(value) => Ok(Pattern::GlobalTag(value)), + Expr::Tag(value) => Ok(Pattern::Tag(value)), Expr::OpaqueRef(value) => Ok(Pattern::OpaqueRef(value)), Expr::Apply(loc_val, loc_args, _) => { let region = loc_val.region; @@ -2436,7 +2436,7 @@ where fn ident_to_expr<'a>(arena: &'a Bump, src: Ident<'a>) -> Expr<'a> { match src { - Ident::GlobalTag(string) => Expr::GlobalTag(string), + Ident::Tag(string) => Expr::Tag(string), Ident::OpaqueRef(string) => Expr::OpaqueRef(string), Ident::Access { module_name, parts } => { let mut iter = parts.iter(); diff --git a/compiler/parse/src/ident.rs b/compiler/parse/src/ident.rs index 82854e2acb..131cf4c465 100644 --- a/compiler/parse/src/ident.rs +++ b/compiler/parse/src/ident.rs @@ -5,7 +5,7 @@ use bumpalo::collections::vec::Vec; use bumpalo::Bump; use roc_region::all::Position; -/// A global tag, for example. Must start with an uppercase letter +/// A tag, for example. Must start with an uppercase letter /// and then contain only letters and numbers afterwards - no dots allowed! #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub struct UppercaseIdent<'a>(&'a str); @@ -35,7 +35,7 @@ impl<'a> From<&'a UppercaseIdent<'a>> for &'a str { #[derive(Debug, Clone, PartialEq, Eq)] pub enum Ident<'a> { /// Foo or Bar - GlobalTag(&'a str), + Tag(&'a str), /// @Foo or @Bar OpaqueRef(&'a str), /// foo or foo.bar or Foo.Bar.baz.qux @@ -54,7 +54,7 @@ impl<'a> Ident<'a> { use self::Ident::*; match self { - GlobalTag(string) | OpaqueRef(string) => string.len(), + Tag(string) | OpaqueRef(string) => string.len(), Access { module_name, parts } => { let mut len = if module_name.is_empty() { 0 @@ -105,7 +105,7 @@ pub fn tag_name<'a>() -> impl Parser<'a, &'a str, ()> { /// /// * A module name /// * A type name -/// * A global tag +/// * A tag pub fn uppercase<'a>() -> impl Parser<'a, UppercaseIdent<'a>, ()> { move |_, state: State<'a>| match chomp_uppercase_part(state.bytes()) { Err(progress) => Err((progress, (), state)), @@ -120,7 +120,7 @@ pub fn uppercase<'a>() -> impl Parser<'a, UppercaseIdent<'a>, ()> { /// /// * A module name /// * A type name -/// * A global tag +/// * A tag pub fn uppercase_ident<'a>() -> impl Parser<'a, &'a str, ()> { move |_, state: State<'a>| match chomp_uppercase_part(state.bytes()) { Err(progress) => Err((progress, (), state)), @@ -418,9 +418,9 @@ fn chomp_identifier_chain<'a>( BadIdent::Underscore(pos.bump_column(chomped as u32 + 1)), )) } else if first_is_uppercase { - // just one segment, starting with an uppercase letter; that's a global tag + // just one segment, starting with an uppercase letter; that's a tag let value = unsafe { std::str::from_utf8_unchecked(&buffer[..chomped]) }; - Ok((chomped as u32, Ident::GlobalTag(value))) + Ok((chomped as u32, Ident::Tag(value))) } else { // just one segment, starting with a lowercase letter; that's a normal identifier let value = unsafe { std::str::from_utf8_unchecked(&buffer[..chomped]) }; diff --git a/compiler/parse/src/pattern.rs b/compiler/parse/src/pattern.rs index b535522614..df09c1cb73 100644 --- a/compiler/parse/src/pattern.rs +++ b/compiler/parse/src/pattern.rs @@ -213,10 +213,10 @@ fn loc_ident_pattern_help<'a>( specialize(|_, pos| EPattern::Start(pos), loc!(parse_ident)).parse(arena, state)?; match loc_ident.value { - Ident::GlobalTag(tag) => { + Ident::Tag(tag) => { let loc_tag = Loc { region: loc_ident.region, - value: Pattern::GlobalTag(tag), + value: Pattern::Tag(tag), }; // Make sure `Foo Bar 1` is parsed as `Foo (Bar) 1`, and not `Foo (Bar 1)` diff --git a/compiler/parse/src/type_annotation.rs b/compiler/parse/src/type_annotation.rs index 45b1d39216..61d5a50a22 100644 --- a/compiler/parse/src/type_annotation.rs +++ b/compiler/parse/src/type_annotation.rs @@ -214,7 +214,7 @@ fn tag_type<'a>(min_indent: u32) -> impl Parser<'a, Tag<'a>, ETypeTagUnion<'a>> let (_, args, state) = specialize_ref(ETypeTagUnion::Type, loc_applied_args_e(min_indent)) .parse(arena, state)?; - let result = Tag::Global { + let result = Tag::Apply { name, args: args.into_bump_slice(), }; diff --git a/compiler/parse/tests/snapshots/pass/annotated_tag_destructure.expr.result-ast b/compiler/parse/tests/snapshots/pass/annotated_tag_destructure.expr.result-ast index 54d3d56502..eec49d33ac 100644 --- a/compiler/parse/tests/snapshots/pass/annotated_tag_destructure.expr.result-ast +++ b/compiler/parse/tests/snapshots/pass/annotated_tag_destructure.expr.result-ast @@ -3,7 +3,7 @@ Defs( @26-46 Value( AnnotatedBody { ann_pattern: @0-8 Apply( - @0-6 GlobalTag( + @0-6 Tag( "UserId", ), [ @@ -15,7 +15,7 @@ Defs( ann_type: @11-25 TagUnion { ext: None, tags: [ - @13-23 Global { + @13-23 Apply { name: @13-19 "UserId", args: [ @20-23 Apply( @@ -29,7 +29,7 @@ Defs( }, comment: None, body_pattern: @26-34 Apply( - @26-32 GlobalTag( + @26-32 Tag( "UserId", ), [ @@ -39,7 +39,7 @@ Defs( ], ), body_expr: @37-46 Apply( - @37-43 GlobalTag( + @37-43 Tag( "UserId", ), [ diff --git a/compiler/parse/tests/snapshots/pass/apply_parenthetical_global_tag_args.expr.result-ast b/compiler/parse/tests/snapshots/pass/apply_parenthetical_tag_args.expr.result-ast similarity index 92% rename from compiler/parse/tests/snapshots/pass/apply_parenthetical_global_tag_args.expr.result-ast rename to compiler/parse/tests/snapshots/pass/apply_parenthetical_tag_args.expr.result-ast index 483292bdcf..af657692b6 100644 --- a/compiler/parse/tests/snapshots/pass/apply_parenthetical_global_tag_args.expr.result-ast +++ b/compiler/parse/tests/snapshots/pass/apply_parenthetical_tag_args.expr.result-ast @@ -1,5 +1,5 @@ Apply( - @0-4 GlobalTag( + @0-4 Tag( "Whee", ), [ diff --git a/compiler/parse/tests/snapshots/pass/apply_parenthetical_global_tag_args.expr.roc b/compiler/parse/tests/snapshots/pass/apply_parenthetical_tag_args.expr.roc similarity index 100% rename from compiler/parse/tests/snapshots/pass/apply_parenthetical_global_tag_args.expr.roc rename to compiler/parse/tests/snapshots/pass/apply_parenthetical_tag_args.expr.roc diff --git a/compiler/parse/tests/snapshots/pass/apply_global_tag.expr.result-ast b/compiler/parse/tests/snapshots/pass/apply_tag.expr.result-ast similarity index 88% rename from compiler/parse/tests/snapshots/pass/apply_global_tag.expr.result-ast rename to compiler/parse/tests/snapshots/pass/apply_tag.expr.result-ast index f939664412..6557b3805f 100644 --- a/compiler/parse/tests/snapshots/pass/apply_global_tag.expr.result-ast +++ b/compiler/parse/tests/snapshots/pass/apply_tag.expr.result-ast @@ -1,5 +1,5 @@ Apply( - @0-4 GlobalTag( + @0-4 Tag( "Whee", ), [ diff --git a/compiler/parse/tests/snapshots/pass/apply_global_tag.expr.roc b/compiler/parse/tests/snapshots/pass/apply_tag.expr.roc similarity index 100% rename from compiler/parse/tests/snapshots/pass/apply_global_tag.expr.roc rename to compiler/parse/tests/snapshots/pass/apply_tag.expr.roc diff --git a/compiler/parse/tests/snapshots/pass/basic_global_tag.expr.result-ast b/compiler/parse/tests/snapshots/pass/basic_tag.expr.result-ast similarity index 56% rename from compiler/parse/tests/snapshots/pass/basic_global_tag.expr.result-ast rename to compiler/parse/tests/snapshots/pass/basic_tag.expr.result-ast index 8c0a66666f..bed3b6ff1d 100644 --- a/compiler/parse/tests/snapshots/pass/basic_global_tag.expr.result-ast +++ b/compiler/parse/tests/snapshots/pass/basic_tag.expr.result-ast @@ -1,3 +1,3 @@ -GlobalTag( +Tag( "Whee", ) diff --git a/compiler/parse/tests/snapshots/pass/basic_global_tag.expr.roc b/compiler/parse/tests/snapshots/pass/basic_tag.expr.roc similarity index 100% rename from compiler/parse/tests/snapshots/pass/basic_global_tag.expr.roc rename to compiler/parse/tests/snapshots/pass/basic_tag.expr.roc diff --git a/compiler/parse/tests/snapshots/pass/destructure_tag_assignment.expr.result-ast b/compiler/parse/tests/snapshots/pass/destructure_tag_assignment.expr.result-ast index 4cdfd0b739..95c8fc9192 100644 --- a/compiler/parse/tests/snapshots/pass/destructure_tag_assignment.expr.result-ast +++ b/compiler/parse/tests/snapshots/pass/destructure_tag_assignment.expr.result-ast @@ -3,7 +3,7 @@ Defs( @0-36 Value( Body( @0-5 Apply( - @0-5 GlobalTag( + @0-5 Tag( "Email", ), [ @@ -13,7 +13,7 @@ Defs( ], ), @12-36 Apply( - @12-17 GlobalTag( + @12-17 Tag( "Email", ), [ diff --git a/compiler/parse/tests/snapshots/pass/pattern_with_space_in_parens.expr.result-ast b/compiler/parse/tests/snapshots/pass/pattern_with_space_in_parens.expr.result-ast index d45bbdf656..9395ab1ab7 100644 --- a/compiler/parse/tests/snapshots/pass/pattern_with_space_in_parens.expr.result-ast +++ b/compiler/parse/tests/snapshots/pass/pattern_with_space_in_parens.expr.result-ast @@ -1,12 +1,12 @@ When( @5-22 Apply( - @5-11 GlobalTag( + @5-11 Tag( "Delmin", ), [ @13-19 ParensAround( Apply( - @13-16 GlobalTag( + @13-16 Tag( "Del", ), [ @@ -29,12 +29,12 @@ When( patterns: [ @30-48 SpaceBefore( Apply( - @30-36 GlobalTag( + @30-36 Tag( "Delmin", ), [ @38-44 Apply( - @38-41 GlobalTag( + @38-41 Tag( "Del", ), [ @@ -54,17 +54,17 @@ When( ), ], value: @52-73 Apply( - @52-56 GlobalTag( + @52-56 Tag( "Node", ), [ - @57-62 GlobalTag( + @57-62 Tag( "Black", ), @63-64 Num( "0", ), - @65-70 GlobalTag( + @65-70 Tag( "False", ), @71-73 Var { diff --git a/compiler/parse/tests/snapshots/pass/plus_if.expr.result-ast b/compiler/parse/tests/snapshots/pass/plus_if.expr.result-ast index 5ae40d994c..e8a3539470 100644 --- a/compiler/parse/tests/snapshots/pass/plus_if.expr.result-ast +++ b/compiler/parse/tests/snapshots/pass/plus_if.expr.result-ast @@ -10,7 +10,7 @@ BinOps( @4-25 If( [ ( - @7-11 GlobalTag( + @7-11 Tag( "True", ), @17-18 Num( diff --git a/compiler/parse/tests/snapshots/pass/qualified_global_tag.expr.result-ast b/compiler/parse/tests/snapshots/pass/qualified_tag.expr.result-ast similarity index 100% rename from compiler/parse/tests/snapshots/pass/qualified_global_tag.expr.result-ast rename to compiler/parse/tests/snapshots/pass/qualified_tag.expr.result-ast diff --git a/compiler/parse/tests/snapshots/pass/qualified_global_tag.expr.roc b/compiler/parse/tests/snapshots/pass/qualified_tag.expr.roc similarity index 100% rename from compiler/parse/tests/snapshots/pass/qualified_global_tag.expr.roc rename to compiler/parse/tests/snapshots/pass/qualified_tag.expr.roc diff --git a/compiler/parse/tests/snapshots/pass/record_with_if.expr.result-ast b/compiler/parse/tests/snapshots/pass/record_with_if.expr.result-ast index 1776ed2ff8..5301d17702 100644 --- a/compiler/parse/tests/snapshots/pass/record_with_if.expr.result-ast +++ b/compiler/parse/tests/snapshots/pass/record_with_if.expr.result-ast @@ -6,7 +6,7 @@ Record( @5-26 If( [ ( - @8-12 GlobalTag( + @8-12 Tag( "True", ), @18-19 Num( diff --git a/compiler/parse/tests/snapshots/pass/tag_pattern.expr.result-ast b/compiler/parse/tests/snapshots/pass/tag_pattern.expr.result-ast index 93bc481021..0b8a1d1b48 100644 --- a/compiler/parse/tests/snapshots/pass/tag_pattern.expr.result-ast +++ b/compiler/parse/tests/snapshots/pass/tag_pattern.expr.result-ast @@ -1,6 +1,6 @@ Closure( [ - @1-6 GlobalTag( + @1-6 Tag( "Thing", ), ], diff --git a/compiler/parse/tests/snapshots/pass/when_if_guard.expr.result-ast b/compiler/parse/tests/snapshots/pass/when_if_guard.expr.result-ast index e0f8d41ece..bdd18adf88 100644 --- a/compiler/parse/tests/snapshots/pass/when_if_guard.expr.result-ast +++ b/compiler/parse/tests/snapshots/pass/when_if_guard.expr.result-ast @@ -50,7 +50,7 @@ When( WhenBranch { patterns: [ @54-56 SpaceBefore( - GlobalTag( + Tag( "Ok", ), [ diff --git a/compiler/parse/tests/snapshots/pass/when_in_parens.expr.result-ast b/compiler/parse/tests/snapshots/pass/when_in_parens.expr.result-ast index 9192d1f1b6..2844887e56 100644 --- a/compiler/parse/tests/snapshots/pass/when_in_parens.expr.result-ast +++ b/compiler/parse/tests/snapshots/pass/when_in_parens.expr.result-ast @@ -8,7 +8,7 @@ ParensAround( WhenBranch { patterns: [ @15-17 SpaceBefore( - GlobalTag( + Tag( "Ok", ), [ diff --git a/compiler/parse/tests/snapshots/pass/when_in_parens_indented.expr.result-ast b/compiler/parse/tests/snapshots/pass/when_in_parens_indented.expr.result-ast index 6f74fb5e4d..419e8c07ad 100644 --- a/compiler/parse/tests/snapshots/pass/when_in_parens_indented.expr.result-ast +++ b/compiler/parse/tests/snapshots/pass/when_in_parens_indented.expr.result-ast @@ -9,7 +9,7 @@ ParensAround( WhenBranch { patterns: [ @15-17 SpaceBefore( - GlobalTag( + Tag( "Ok", ), [ diff --git a/compiler/parse/tests/test_parse.rs b/compiler/parse/tests/test_parse.rs index daf87904b0..fd67275667 100644 --- a/compiler/parse/tests/test_parse.rs +++ b/compiler/parse/tests/test_parse.rs @@ -132,8 +132,8 @@ mod test_parse { pass/add_with_spaces.expr, pass/annotated_record_destructure.expr, pass/annotated_tag_destructure.expr, - pass/apply_global_tag.expr, - pass/apply_parenthetical_global_tag_args.expr, + pass/apply_tag.expr, + pass/apply_parenthetical_tag_args.expr, pass/apply_three_args.expr, pass/apply_two_args.expr, pass/apply_unary_negation.expr, @@ -141,7 +141,7 @@ mod test_parse { pass/basic_apply.expr, pass/basic_docs.expr, pass/basic_field.expr, - pass/basic_global_tag.expr, + pass/basic_tag.expr, pass/basic_var.expr, pass/closure_with_underscores.expr, pass/comment_after_def.module, @@ -233,7 +233,7 @@ mod test_parse { pass/positive_int.expr, pass/provides_type.header, pass/qualified_field.expr, - pass/qualified_global_tag.expr, + pass/qualified_tag.expr, pass/qualified_var.expr, pass/record_destructure_def.expr, pass/record_func_type_decl.expr, @@ -654,17 +654,17 @@ mod test_parse { // } // #[test] - // fn ann_global_open_union() { + // fn ann_open_union() { // let arena = Bump::new(); // let newline = bumpalo::vec![in &arena; Newline]; // let newlines = bumpalo::vec![in &arena; Newline, Newline]; - // let tag1 = Tag::Global { + // let tag1 = Tag::Apply { // name: Located::new(0, 0, 8, 12, "True"), // args: &[], // }; // let tag2arg = Located::new(0, 0, 22, 27, TypeAnnotation::Apply("", "Thing", &[])); // let tag2args = bumpalo::vec![in &arena; tag2arg]; - // let tag2 = Tag::Global { + // let tag2 = Tag::Apply { // name: Located::new(0, 0, 14, 21, "Perhaps"), // args: tag2args.into_bump_slice(), // }; @@ -683,7 +683,7 @@ mod test_parse { // ); // let def = Def::Body( // arena.alloc(Located::new(1, 1, 0, 3, Identifier("foo"))), - // arena.alloc(Located::new(1, 1, 6, 10, Expr::GlobalTag("True"))), + // arena.alloc(Located::new(1, 1, 6, 10, Expr::Tag("True"))), // ); // let spaced_def = Def::SpaceBefore(arena.alloc(def), newline.into_bump_slice()); // let loc_def = &*arena.alloc(Located::new(1, 1, 0, 10, spaced_def)); @@ -708,17 +708,17 @@ mod test_parse { // } // #[test] - // fn ann_global_closed_union() { + // fn ann_closed_union() { // let arena = Bump::new(); // let newline = bumpalo::vec![in &arena; Newline]; // let newlines = bumpalo::vec![in &arena; Newline, Newline]; - // let tag1 = Tag::Global { + // let tag1 = Tag::Apply { // name: Located::new(0, 0, 8, 12, "True"), // args: &[], // }; // let tag2arg = Located::new(0, 0, 22, 27, TypeAnnotation::Apply("", "Thing", &[])); // let tag2args = bumpalo::vec![in &arena; tag2arg]; - // let tag2 = Tag::Global { + // let tag2 = Tag::Apply { // name: Located::new(0, 0, 14, 21, "Perhaps"), // args: tag2args.into_bump_slice(), // }; @@ -736,7 +736,7 @@ mod test_parse { // ); // let def = Def::Body( // arena.alloc(Located::new(1, 1, 0, 3, Identifier("foo"))), - // arena.alloc(Located::new(1, 1, 6, 10, Expr::GlobalTag("True"))), + // arena.alloc(Located::new(1, 1, 6, 10, Expr::Tag("True"))), // ); // let spaced_def = Def::SpaceBefore(arena.alloc(def), newline.into_bump_slice()); // let loc_def = &*arena.alloc(Located::new(1, 1, 0, 10, spaced_def)); diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index f977920b7a..1d833a210c 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -2048,7 +2048,7 @@ fn insert_tags_fast_path<'a>( tags: &'a [(TagName, Vec)], stack: &mut bumpalo::collections::Vec<'_, TypeToVar<'a>>, ) -> UnionTags { - if let [(TagName::Global(tag_name), arguments)] = tags { + if let [(TagName::Tag(tag_name), arguments)] = tags { let variable_slice = register_tag_arguments(subs, rank, pools, arena, stack, arguments); let new_variable_slices = SubsSlice::extend_new(&mut subs.variable_slices, [variable_slice]); diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index ecf4ea4058..f5f8bb9651 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -185,7 +185,7 @@ mod solve_expr { fn promote_expr_to_module(src: &str) -> String { let mut buffer = String::from(indoc!( r#" - app "test" + app "test" imports [] provides [ main ] to "./platform" @@ -1588,7 +1588,7 @@ mod solve_expr { } #[test] - fn global_tag_with_field() { + fn tag_with_field() { infer_eq( indoc!( r#" @@ -4177,7 +4177,7 @@ mod solve_expr { } #[test] - fn double_tag_application_pattern_global() { + fn double_tag_application_pattern() { infer_eq_without_problem( indoc!( r#" diff --git a/compiler/types/src/builtin_aliases.rs b/compiler/types/src/builtin_aliases.rs index b638cad6e4..6be002465c 100644 --- a/compiler/types/src/builtin_aliases.rs +++ b/compiler/types/src/builtin_aliases.rs @@ -955,8 +955,8 @@ pub fn bool_type() -> SolvedType { fn bool_alias_content() -> SolvedType { SolvedType::TagUnion( vec![ - (TagName::Global("False".into()), vec![]), - (TagName::Global("True".into()), vec![]), + (TagName::Tag("False".into()), vec![]), + (TagName::Tag("True".into()), vec![]), ], Box::new(SolvedType::EmptyTagUnion), ) @@ -967,9 +967,9 @@ pub fn ordering_type() -> SolvedType { // [ LT, EQ, GT ] SolvedType::TagUnion( vec![ - (TagName::Global("EQ".into()), vec![]), - (TagName::Global("GT".into()), vec![]), - (TagName::Global("LT".into()), vec![]), + (TagName::Tag("EQ".into()), vec![]), + (TagName::Tag("GT".into()), vec![]), + (TagName::Tag("LT".into()), vec![]), ], Box::new(SolvedType::EmptyTagUnion), ) @@ -995,8 +995,8 @@ pub fn box_type(a: SolvedType) -> SolvedType { fn result_alias_content(a: SolvedType, e: SolvedType) -> SolvedType { SolvedType::TagUnion( vec![ - (TagName::Global("Err".into()), vec![e]), - (TagName::Global("Ok".into()), vec![a]), + (TagName::Tag("Err".into()), vec![e]), + (TagName::Tag("Ok".into()), vec![a]), ], Box::new(SolvedType::EmptyTagUnion), ) @@ -1056,12 +1056,12 @@ pub fn str_utf8_byte_problem_alias_content() -> SolvedType { // [ CodepointTooLarge, EncodesSurrogateHalf, OverlongEncoding, InvalidStartByte, UnexpectedEndOfSequence, ExpectedContinuation ] SolvedType::TagUnion( vec![ - (TagName::Global("CodepointTooLarge".into()), vec![]), - (TagName::Global("EncodesSurrogateHalf".into()), vec![]), - (TagName::Global("ExpectedContinuation".into()), vec![]), - (TagName::Global("InvalidStartByte".into()), vec![]), - (TagName::Global("OverlongEncoding".into()), vec![]), - (TagName::Global("UnexpectedEndOfSequence".into()), vec![]), + (TagName::Tag("CodepointTooLarge".into()), vec![]), + (TagName::Tag("EncodesSurrogateHalf".into()), vec![]), + (TagName::Tag("ExpectedContinuation".into()), vec![]), + (TagName::Tag("InvalidStartByte".into()), vec![]), + (TagName::Tag("OverlongEncoding".into()), vec![]), + (TagName::Tag("UnexpectedEndOfSequence".into()), vec![]), ], Box::new(SolvedType::EmptyTagUnion), ) diff --git a/compiler/types/src/subs.rs b/compiler/types/src/subs.rs index 8905a9aa58..b0d447e5c2 100644 --- a/compiler/types/src/subs.rs +++ b/compiler/types/src/subs.rs @@ -203,7 +203,7 @@ impl Subs { for tag_name in tag_names { let serialized = match tag_name { - TagName::Global(uppercase) => { + TagName::Tag(uppercase) => { let slice = SubsSlice::extend_new( &mut buf, uppercase.as_str().as_bytes().iter().copied(), @@ -350,7 +350,7 @@ impl Subs { offset += bytes.len(); let string = unsafe { std::str::from_utf8_unchecked(bytes) }; - TagName::Global(string.into()) + TagName::Tag(string.into()) } SerializedTagName::Closure(symbol) => TagName::Closure(*symbol), }; @@ -400,7 +400,7 @@ pub struct TagNameCache { impl TagNameCache { pub fn get_mut(&mut self, tag_name: &TagName) -> Option<&mut SubsSlice> { match tag_name { - TagName::Global(uppercase) => { + TagName::Tag(uppercase) => { // force into block match self.globals.iter().position(|u| u == uppercase) { Some(index) => Some(&mut self.globals_slices[index]), @@ -416,7 +416,7 @@ impl TagNameCache { pub fn push(&mut self, tag_name: &TagName, slice: SubsSlice) { match tag_name { - TagName::Global(uppercase) => { + TagName::Tag(uppercase) => { self.globals.push(uppercase.clone()); self.globals_slices.push(slice); } @@ -642,7 +642,7 @@ impl SubsSlice { let start = subs.tag_names.len() as u32; subs.tag_names - .extend(std::iter::repeat(TagName::Global(Uppercase::default())).take(length)); + .extend(std::iter::repeat(TagName::Tag(Uppercase::default())).take(length)); Self::new(start, length as u16) } @@ -1477,12 +1477,12 @@ impl Subs { let mut tag_names = Vec::with_capacity(32); - tag_names.push(TagName::Global("Err".into())); - tag_names.push(TagName::Global("Ok".into())); + tag_names.push(TagName::Tag("Err".into())); + tag_names.push(TagName::Tag("Ok".into())); - tag_names.push(TagName::Global("InvalidNumStr".into())); - tag_names.push(TagName::Global("BadUtf8".into())); - tag_names.push(TagName::Global("OutOfBounds".into())); + tag_names.push(TagName::Tag("InvalidNumStr".into())); + tag_names.push(TagName::Tag("BadUtf8".into())); + tag_names.push(TagName::Tag("OutOfBounds".into())); let mut subs = Subs { utable: UnificationTable::default(), @@ -1522,8 +1522,8 @@ impl Subs { let bool_union_tags = UnionTags::insert_into_subs( &mut subs, [ - (TagName::Global("False".into()), []), - (TagName::Global("True".into()), []), + (TagName::Tag("False".into()), []), + (TagName::Tag("True".into()), []), ], ); @@ -2211,10 +2211,10 @@ impl UnionTags { slice.length == 1 } - pub fn is_newtype_wrapper_of_global_tag(&self, subs: &Subs) -> bool { + pub fn is_newtype_wrapper_of_tag(&self, subs: &Subs) -> bool { self.is_newtype_wrapper(subs) && { let tags = &subs.tag_names[self.tag_names().indices()]; - matches!(tags[0], TagName::Global(_)) + matches!(tags[0], TagName::Tag(_)) } } diff --git a/docs/src/lib.rs b/docs/src/lib.rs index d09134d98d..e853a68e35 100644 --- a/docs/src/lib.rs +++ b/docs/src/lib.rs @@ -844,8 +844,8 @@ fn markdown_to_html( } } } - Ok((_, Ident::GlobalTag(type_name), _)) => { - // This looks like a global tag name, but it could + Ok((_, Ident::Tag(type_name), _)) => { + // This looks like a tag name, but it could // be a type alias that's in scope, e.g. [I64] let DocUrl { url, title } = doc_url( loaded_module.module_id, diff --git a/repl_eval/src/eval.rs b/repl_eval/src/eval.rs index f50622043a..8189250917 100644 --- a/repl_eval/src/eval.rs +++ b/repl_eval/src/eval.rs @@ -100,7 +100,7 @@ fn unroll_newtypes_and_aliases<'a>( loop { match content { Content::Structure(FlatType::TagUnion(tags, _)) - if tags.is_newtype_wrapper_of_global_tag(env.subs) => + if tags.is_newtype_wrapper_of_tag(env.subs) => { let (tag_name, vars): (&TagName, &[Variable]) = tags .unsorted_iterator(env.subs, Variable::EMPTY_TAG_UNION) @@ -471,7 +471,7 @@ fn jit_to_ast_help<'a, A: ReplApp<'a>>( fn tag_name_to_expr<'a>(env: &Env<'a, '_>, tag_name: &TagName) -> Expr<'a> { match tag_name { - TagName::Global(_) => Expr::GlobalTag( + TagName::Tag(_) => Expr::Tag( env.arena .alloc_str(&tag_name.as_ident_str(env.interns, env.home)), ), @@ -1048,7 +1048,7 @@ fn bool_to_ast<'a, M: ReplAppMemory>( let loc_tag_expr = { let tag_name = &tag_name.as_ident_str(env.interns, env.home); - let tag_expr = Expr::GlobalTag(arena.alloc_str(tag_name)); + let tag_expr = Expr::Tag(arena.alloc_str(tag_name)); &*arena.alloc(Loc { value: tag_expr, @@ -1127,7 +1127,7 @@ fn byte_to_ast<'a, M: ReplAppMemory>( let loc_tag_expr = { let tag_name = &tag_name.as_ident_str(env.interns, env.home); - let tag_expr = Expr::GlobalTag(arena.alloc_str(tag_name)); + let tag_expr = Expr::Tag(arena.alloc_str(tag_name)); &*arena.alloc(Loc { value: tag_expr, diff --git a/reporting/src/error/canonicalize.rs b/reporting/src/error/canonicalize.rs index 8f231f8f44..73fd7d7ec2 100644 --- a/reporting/src/error/canonicalize.rs +++ b/reporting/src/error/canonicalize.rs @@ -1255,7 +1255,7 @@ fn pretty_runtime_error<'b>( } QualifiedIdentifier => alloc .tip() - .append(alloc.reflow("In patterns, only global tags can be qualified")), + .append(alloc.reflow("In patterns, only tags can be qualified")), }; doc = alloc.stack([ diff --git a/reporting/src/error/mono.rs b/reporting/src/error/mono.rs index 8215b05b1a..5326e1379b 100644 --- a/reporting/src/error/mono.rs +++ b/reporting/src/error/mono.rs @@ -165,7 +165,7 @@ fn pattern_to_doc_help<'b>( // #Guard debug_assert!(union.alternatives[tag_id.0 as usize] .name - .is_tag(&TagName::Global("#Guard".into())),); + .is_tag(&TagName::Tag("#Guard".into())),); debug_assert!(args.len() == 2); let tag = pattern_to_doc_help(alloc, args[1].clone(), in_type_param); alloc.concat([ diff --git a/reporting/src/error/type.rs b/reporting/src/error/type.rs index 90e7ad15b9..d26e3e9b8e 100644 --- a/reporting/src/error/type.rs +++ b/reporting/src/error/type.rs @@ -637,9 +637,9 @@ fn to_expr_report<'b>( alloc.reflow(" condition to evaluate to a "), alloc.type_str("Bool"), alloc.reflow("—either "), - alloc.global_tag_name("True".into()), + alloc.tag("True".into()), alloc.reflow(" or "), - alloc.global_tag_name("False".into()), + alloc.tag("False".into()), alloc.reflow("."), ]), // Note: Elm has a hint here about truthiness. I think that @@ -676,9 +676,9 @@ fn to_expr_report<'b>( alloc.reflow(" condition to evaluate to a "), alloc.type_str("Bool"), alloc.reflow("—either "), - alloc.global_tag_name("True".into()), + alloc.tag("True".into()), alloc.reflow(" or "), - alloc.global_tag_name("False".into()), + alloc.tag("False".into()), alloc.reflow("."), ]), // Note: Elm has a hint here about truthiness. I think that @@ -714,9 +714,9 @@ fn to_expr_report<'b>( alloc.reflow(" guard condition to evaluate to a "), alloc.type_str("Bool"), alloc.reflow("—either "), - alloc.global_tag_name("True".into()), + alloc.tag("True".into()), alloc.reflow(" or "), - alloc.global_tag_name("False".into()), + alloc.tag("False".into()), alloc.reflow("."), ]), ) @@ -1435,29 +1435,29 @@ fn format_category<'b>( ), TagApply { - tag_name: TagName::Global(name), + tag_name: TagName::Tag(name), args_count: 0, } => ( alloc.concat([ alloc.text(format!("{}his ", t)), - alloc.global_tag_name(name.to_owned()), + alloc.tag(name.to_owned()), if name.as_str() == "True" || name.as_str() == "False" { alloc.text(" boolean") } else { - alloc.text(" global tag") + alloc.text(" tag") }, ]), alloc.text(" has the type:"), ), TagApply { - tag_name: TagName::Global(name), + tag_name: TagName::Tag(name), args_count: _, } => ( alloc.concat([ alloc.text(format!("{}his ", t)), - alloc.global_tag_name(name.to_owned()), - alloc.text(" global tag application"), + alloc.tag(name.to_owned()), + alloc.text(" tag application"), ]), alloc.text(" has the type:"), ), diff --git a/reporting/src/report.rs b/reporting/src/report.rs index 1fa222c813..bc5caae36b 100644 --- a/reporting/src/report.rs +++ b/reporting/src/report.rs @@ -385,7 +385,7 @@ impl<'a> RocDocAllocator<'a> { pub fn tag_name(&'a self, tn: TagName) -> DocBuilder<'a, Self, Annotation> { match tn { - TagName::Global(uppercase) => self.global_tag_name(uppercase), + TagName::Tag(uppercase) => self.tag(uppercase), TagName::Closure(_symbol) => unreachable!("closure tags are internal only"), } } @@ -417,9 +417,9 @@ impl<'a> RocDocAllocator<'a> { .annotate(Annotation::Symbol) } - pub fn global_tag_name(&'a self, uppercase: Uppercase) -> DocBuilder<'a, Self, Annotation> { + pub fn tag(&'a self, uppercase: Uppercase) -> DocBuilder<'a, Self, Annotation> { self.text(format!("{}", uppercase)) - .annotate(Annotation::GlobalTag) + .annotate(Annotation::Tag) } pub fn opaque_name(&'a self, opaque: Symbol) -> DocBuilder<'a, Self, Annotation> { @@ -790,7 +790,7 @@ pub enum Annotation { Emphasized, Url, Keyword, - GlobalTag, + Tag, RecordField, TypeVariable, Alias, @@ -882,7 +882,7 @@ where Url => { self.write_str("<")?; } - GlobalTag | Keyword | RecordField | Symbol | Typo | TypoSuggestion | TypeVariable + Tag | Keyword | RecordField | Symbol | Typo | TypoSuggestion | TypeVariable if !self.in_type_block && !self.in_code_block => { self.write_str("`")?; @@ -912,8 +912,7 @@ where Url => { self.write_str(">")?; } - GlobalTag | Keyword | RecordField | Symbol | Typo | TypoSuggestion - | TypeVariable + Tag | Keyword | RecordField | Symbol | Typo | TypoSuggestion | TypeVariable if !self.in_type_block && !self.in_code_block => { self.write_str("`")?; @@ -1005,7 +1004,7 @@ where ParserSuggestion => { self.write_str(self.palette.parser_suggestion)?; } - TypeBlock | GlobalTag | RecordField => { /* nothing yet */ } + TypeBlock | Tag | RecordField => { /* nothing yet */ } } self.style_stack.push(*annotation); Ok(()) @@ -1023,7 +1022,7 @@ where self.write_str(self.palette.reset)?; } - TypeBlock | GlobalTag | Opaque | RecordField => { /* nothing yet */ } + TypeBlock | Tag | Opaque | RecordField => { /* nothing yet */ } }, } Ok(()) diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index a918bdeda0..2caac8bbba 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -1408,7 +1408,7 @@ mod test_reporting { 4│ f Blue ^^^^ - This `Blue` global tag has the type: + This `Blue` tag has the type: [ Blue ]a @@ -1446,7 +1446,7 @@ mod test_reporting { 4│ f (Blue 3.14) ^^^^^^^^^ - This `Blue` global tag application has the type: + This `Blue` tag application has the type: [ Blue (Float a) ]b @@ -2179,7 +2179,7 @@ mod test_reporting { 2│ f = \_ -> Foo ^^^ - This `Foo` global tag has the type: + This `Foo` tag has the type: [ Foo ]a @@ -2306,7 +2306,7 @@ mod test_reporting { 5│ Ok ^^ - This `Ok` global tag has the type: + This `Ok` tag has the type: [ Ok ]a @@ -3630,7 +3630,7 @@ mod test_reporting { 4│ x = Cons {} (Cons "foo" Nil) ^^^^^^^^^^^^^^^^^^^^^^^^ - This `Cons` global tag application has the type: + This `Cons` tag application has the type: [ Cons {} [ Cons Str [ Cons {} a, Nil ] as a, Nil ], Nil ] @@ -3671,7 +3671,7 @@ mod test_reporting { 5│ x = ACons 0 (BCons 1 (ACons "foo" BNil )) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - This `ACons` global tag application has the type: + This `ACons` tag application has the type: [ ACons (Num (Integer Signed64)) [ BCons (Num (Integer Signed64)) [ ACons Str [ BCons I64 a, BNil ], @@ -4456,7 +4456,7 @@ mod test_reporting { } #[test] - fn qualified_global_tag() { + fn qualified_tag() { report_problem_as( indoc!( r#" @@ -7141,7 +7141,7 @@ I need all branches in an `if` to have the same type! 6│ isEmpty (Name "boo") ^^^^^^^^^^ - This `Name` global tag application has the type: + This `Name` tag application has the type: [ Name Str ]a @@ -7341,7 +7341,7 @@ I need all branches in an `if` to have the same type! 5│ Job { inputs } ^^^^^^^^^^^^^^ - This `Job` global tag application has the type: + This `Job` tag application has the type: [ Job { inputs : List Str } ] @@ -9676,7 +9676,7 @@ I need all branches in an `if` to have the same type! 15│ notYet: hash (A 1), ^^^ - This `A` global tag application has the type: + This `A` tag application has the type: [ A (Num a) ]b From 893bd4f7ab842b2f313fc8c99091db0662587033 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 25 Apr 2022 17:04:25 -0400 Subject: [PATCH 571/846] Improve error message in test_parse --- compiler/parse/tests/test_parse.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/parse/tests/test_parse.rs b/compiler/parse/tests/test_parse.rs index fd67275667..1fc6341287 100644 --- a/compiler/parse/tests/test_parse.rs +++ b/compiler/parse/tests/test_parse.rs @@ -77,7 +77,7 @@ mod test_parse { let pass_or_fail_names = list(&base); let mut extra_test_files = std::collections::HashSet::new(); for res in pass_or_fail_names { - assert!(res == "pass" || res == "fail"); + assert!(res == "pass" || res == "fail", "a pass or fail filename was neither \"pass\" nor \"fail\", but rather: {:?}", res); let res_dir = base.join(&res); for file in list(&res_dir) { let test = if let Some(test) = file.strip_suffix(".roc") { From 724fdb666de7878a7d630bf099609b732e75679c Mon Sep 17 00:00:00 2001 From: Folkert Date: Mon, 25 Apr 2022 23:09:18 +0200 Subject: [PATCH 572/846] Improved IdentIds --- ast/src/lang/core/pattern.rs | 2 +- ast/src/lang/scope.rs | 4 +- compiler/can/src/pattern.rs | 2 +- compiler/can/src/scope.rs | 8 +- compiler/gen_wasm/src/backend.rs | 2 +- compiler/load_internal/src/file.rs | 2 +- compiler/module/src/ident.rs | 4 + compiler/module/src/symbol.rs | 219 +++++++++++----------- compiler/mono/src/code_gen_help/mod.rs | 2 +- compiler/mono/src/layout.rs | 2 +- compiler/types/src/pretty_print.rs | 4 +- compiler/types/src/types.rs | 2 +- docs/src/lib.rs | 2 +- editor/src/editor/mvc/let_update.rs | 4 +- editor/src/editor/mvc/tld_value_update.rs | 12 +- reporting/src/report.rs | 14 +- 16 files changed, 142 insertions(+), 143 deletions(-) diff --git a/ast/src/lang/core/pattern.rs b/ast/src/lang/core/pattern.rs index 9ae9c5db9b..41eb8b17be 100644 --- a/ast/src/lang/core/pattern.rs +++ b/ast/src/lang/core/pattern.rs @@ -516,7 +516,7 @@ pub fn symbols_from_pattern(pool: &Pool, initial: &Pattern2) -> Vec { pub fn get_identifier_string(pattern: &Pattern2, interns: &Interns) -> ASTResult { match pattern { - Pattern2::Identifier(symbol) => Ok(symbol.ident_str(interns).to_string()), + Pattern2::Identifier(symbol) => Ok(symbol.as_str(interns).to_string()), other => UnexpectedPattern2Variant { required_pattern2: "Identifier".to_string(), encountered_pattern2: format!("{:?}", other), diff --git a/ast/src/lang/scope.rs b/ast/src/lang/scope.rs index 26b82b25d7..90046e4b40 100644 --- a/ast/src/lang/scope.rs +++ b/ast/src/lang/scope.rs @@ -245,7 +245,7 @@ impl Scope { // use that existing IdentId. Otherwise, create a fresh one. let ident_id = match exposed_ident_ids.get_id(&ident) { Some(ident_id) => ident_id, - None => all_ident_ids.add(ident.clone().into()), + None => all_ident_ids.add(&ident), }; let symbol = Symbol::new(self.home, ident_id); @@ -262,7 +262,7 @@ impl Scope { /// /// Used for record guards like { x: Just _ } pub fn ignore(&mut self, ident: Ident, all_ident_ids: &mut IdentIds) -> Symbol { - let ident_id = all_ident_ids.add(ident.into()); + let ident_id = all_ident_ids.add(&ident); Symbol::new(self.home, ident_id) } diff --git a/compiler/can/src/pattern.rs b/compiler/can/src/pattern.rs index 7fb54af2ea..d3ebcf3118 100644 --- a/compiler/can/src/pattern.rs +++ b/compiler/can/src/pattern.rs @@ -501,7 +501,7 @@ pub fn canonicalize_pattern<'a>( RequiredField(label, loc_guard) => { // a guard does not introduce the label into scope! - let symbol = scope.ignore(label.into(), &mut env.ident_ids); + let symbol = scope.ignore(&Ident::from(label), &mut env.ident_ids); let can_guard = canonicalize_pattern( env, var_store, diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index b45b7eea6c..2798957571 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -225,7 +225,7 @@ impl Scope { region, }; - let ident_id = all_ident_ids.add(ident.clone()); + let ident_id = all_ident_ids.add(&ident); let symbol = Symbol::new(self.home, ident_id); self.symbols.insert(symbol, region); @@ -273,7 +273,7 @@ impl Scope { ) -> Result<(Symbol, Option), (Region, Loc, Symbol)> { match self.idents.get(&ident) { Some(&(original_symbol, original_region)) => { - let shadow_ident_id = all_ident_ids.add(ident.clone()); + let shadow_ident_id = all_ident_ids.add(&ident); let shadow_symbol = Symbol::new(self.home, shadow_ident_id); self.symbols.insert(shadow_symbol, region); @@ -315,7 +315,7 @@ impl Scope { // use that existing IdentId. Otherwise, create a fresh one. let ident_id = match exposed_ident_ids.get_id(&ident) { Some(ident_id) => ident_id, - None => all_ident_ids.add(ident.clone()), + None => all_ident_ids.add(&ident), }; let symbol = Symbol::new(self.home, ident_id); @@ -329,7 +329,7 @@ impl Scope { /// Ignore an identifier. /// /// Used for record guards like { x: Just _ } - pub fn ignore(&mut self, ident: Ident, all_ident_ids: &mut IdentIds) -> Symbol { + pub fn ignore(&mut self, ident: &Ident, all_ident_ids: &mut IdentIds) -> Symbol { let ident_id = all_ident_ids.add(ident); Symbol::new(self.home, ident_id) } diff --git a/compiler/gen_wasm/src/backend.rs b/compiler/gen_wasm/src/backend.rs index 0ad99742cb..7b5162c8b1 100644 --- a/compiler/gen_wasm/src/backend.rs +++ b/compiler/gen_wasm/src/backend.rs @@ -183,7 +183,7 @@ impl<'a> WasmBackend<'a> { .get_mut(&self.env.module_id) .unwrap(); - let ident_id = ident_ids.add(Ident::from(debug_name)); + let ident_id = ident_ids.add(&Ident::from(debug_name)); Symbol::new(self.env.module_id, ident_id) } diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index 6fcb0785ae..20584442b3 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -446,7 +446,7 @@ impl LoadedModule { pub fn exposed_values_str(&self) -> Vec<&str> { self.exposed_values .iter() - .map(|symbol| symbol.ident_str(&self.interns).as_str()) + .map(|symbol| symbol.as_str(&self.interns)) .collect() } } diff --git a/compiler/module/src/ident.rs b/compiler/module/src/ident.rs index 5335cad281..0af20224ee 100644 --- a/compiler/module/src/ident.rs +++ b/compiler/module/src/ident.rs @@ -10,6 +10,10 @@ impl Ident { pub fn as_inline_str(&self) -> &IdentStr { &self.0 } + + pub fn as_str(&self) -> &str { + self.0.as_str() + } } pub struct QualifiedModuleName<'a> { diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index 86648dc9b9..1b36f1b2da 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -68,10 +68,6 @@ impl Symbol { } pub fn as_str(self, interns: &Interns) -> &str { - self.ident_str(interns).as_str() - } - - pub fn ident_str(self, interns: &Interns) -> &IdentStr { let ident_ids = interns .all_ident_ids .get(&self.module_id()) @@ -83,16 +79,13 @@ impl Symbol { ) }); - ident_ids - .get_name(self.ident_id()) - .unwrap_or_else(|| { - panic!( - "ident_string's IdentIds did not contain an entry for {} in module {:?}", - self.ident_id().0, - self.module_id() - ) - }) - .into() + ident_ids.get_name(self.ident_id()).unwrap_or_else(|| { + panic!( + "ident_string's IdentIds did not contain an entry for {} in module {:?}", + self.ident_id().0, + self.module_id() + ) + }) } pub fn as_u64(self) -> u64 { @@ -103,13 +96,13 @@ impl Symbol { let module_id = self.module_id(); if module_id == home { - self.ident_str(interns).clone().into() + ModuleName::from(self.as_str(interns)) } else { // TODO do this without format! to avoid allocation for short strings format!( "{}.{}", self.module_string(interns).as_str(), - self.ident_str(interns) + self.as_str(interns) ) .into() } @@ -535,25 +528,50 @@ pub struct IdentId(u32); /// Since these are interned strings, this shouldn't result in many total allocations in practice. #[derive(Clone, Debug, Default, PartialEq, Eq)] pub struct IdentIds { - /// Each IdentId is an index into this Vec - by_id: Vec, + buffer: String, - next_generated_name: u32, + lengths: Vec, + offsets: Vec, } impl IdentIds { - pub fn ident_strs(&self) -> impl Iterator { - self.by_id - .iter() - .enumerate() - .map(|(index, ident)| (IdentId(index as u32), ident.as_inline_str().as_str())) + fn with_capacity(capacity: usize) -> Self { + Self { + // guess: the average symbol length is 3 + buffer: String::with_capacity(3 * capacity), + + lengths: Vec::with_capacity(capacity), + offsets: Vec::with_capacity(capacity), + } } - pub fn add(&mut self, ident_name: Ident) -> IdentId { - let by_id = &mut self.by_id; - let ident_id = IdentId(by_id.len() as u32); + fn strs(&self) -> impl Iterator { + self.offsets + .iter() + .zip(self.lengths.iter()) + .map(move |(offset, length)| &self.buffer[*offset as usize..][..*length as usize]) + } - by_id.push(ident_name); + pub fn ident_strs(&self) -> impl Iterator { + self.strs() + .enumerate() + .map(|(index, ident)| (IdentId(index as u32), ident)) + } + + pub fn add(&mut self, ident_name: &Ident) -> IdentId { + self.add_str(ident_name.as_inline_str().as_str()) + } + + fn add_str(&mut self, string: &str) -> IdentId { + let offset = self.buffer.len() as u32; + let length = string.len() as u16; + + let ident_id = IdentId(self.lengths.len() as u32); + + self.lengths.push(length); + self.offsets.push(offset); + + self.buffer.push_str(string); ident_id } @@ -561,13 +579,7 @@ impl IdentIds { pub fn get_or_insert(&mut self, name: &Ident) -> IdentId { match self.get_id(name) { Some(id) => id, - None => { - let ident_id = IdentId(self.by_id.len() as u32); - - self.by_id.push(name.clone()); - - ident_id - } + None => self.add(name), } } @@ -586,31 +598,26 @@ impl IdentIds { Some(ident_id_ref) => { let ident_id = ident_id_ref; - let by_id = &mut self.by_id; - let key_index_opt = by_id.iter().position(|x| *x == old_ident); + match self.find_index(old_ident_name) { + Some(key_index) => { + let length = new_ident_name.len(); + let offset = self.buffer.len(); + self.buffer.push_str(new_ident_name); - if let Some(key_index) = key_index_opt { - if let Some(vec_elt) = by_id.get_mut(key_index) { - *vec_elt = new_ident_name.into(); - } else { - // we get the index from by_id - unreachable!() + self.lengths[key_index] = length as u16; + self.offsets[key_index] = offset as u32; + + Ok(ident_id) } - - Ok(ident_id) - } else { - Err( - format!( - "Tried to find position of key {:?} in IdentIds.by_id but I could not find the key. IdentIds.by_id: {:?}", - old_ident_name, - self.by_id - ) - ) + None => Err(format!( + r"Tried to find position of key {:?} in IdentIds.by_id but I could not find the key", + old_ident_name + )), } } None => Err(format!( - "Tried to update key in IdentIds ({:?}) but I could not find the key ({}).", - self.by_id, old_ident_name + "Tried to update key in IdentIds, but I could not find the key ({}).", + old_ident_name )), } } @@ -625,44 +632,60 @@ impl IdentIds { pub fn gen_unique(&mut self) -> IdentId { use std::fmt::Write; - let index: u32 = self.next_generated_name; - self.next_generated_name += 1; + let index = self.lengths.len(); - // "4294967296" is 10 characters - let mut buffer: arrayvec::ArrayString<10> = arrayvec::ArrayString::new(); + let offset = self.buffer.len(); + write!(self.buffer, "{}", index).unwrap(); + let length = self.buffer.len() - offset; - write!(buffer, "{}", index).unwrap(); - let ident = Ident(IdentStr::from_str(buffer.as_str())); + self.lengths.push(length as u16); + self.offsets.push(offset as u32); - self.add(ident) + IdentId(index as u32) } #[inline(always)] pub fn get_id(&self, ident_name: &Ident) -> Option { - let ident_name = ident_name.as_inline_str().as_str(); + self.find_index(ident_name.as_inline_str().as_str()) + .map(|i| IdentId(i as u32)) + } - for (id, ident_str) in self.ident_strs() { - if ident_name == ident_str { - return Some(id); + #[inline(always)] + fn find_index(&self, string: &str) -> Option { + let target_length = string.len() as u16; + + for (index, length) in self.lengths.iter().enumerate() { + if *length == target_length { + let offset = self.offsets[index] as usize; + let ident = &self.buffer[offset..][..*length as usize]; + + // skip the length check + if string.bytes().eq(ident.bytes()) { + return Some(index); + } } } None } - pub fn get_name(&self, id: IdentId) -> Option<&Ident> { - self.by_id.get(id.0 as usize) + pub fn get_name(&self, id: IdentId) -> Option<&str> { + let index = id.0 as usize; + + match self.lengths.get(index) { + None => None, + Some(length) => { + let offset = self.offsets[index] as usize; + Some(&self.buffer[offset..][..*length as usize]) + } + } } pub fn get_name_str_res(&self, ident_id: IdentId) -> ModuleResult<&str> { - Ok(self - .get_name(ident_id) - .with_context(|| IdentIdNotFound { - ident_id, - ident_ids_str: format!("{:?}", self), - })? - .as_inline_str() - .as_str()) + Ok(self.get_name(ident_id).with_context(|| IdentIdNotFound { + ident_id, + ident_ids_str: format!("{:?}", self), + })?) } } @@ -686,45 +709,18 @@ macro_rules! define_builtins { $( debug_assert!(!exposed_idents_by_module.contains_key(&ModuleId($module_id)), "Error setting up Builtins: when setting up module {} {:?} - the module ID {} is already present in the map. Check the map for duplicate module IDs!", $module_id, $module_name, $module_id); - let mut by_id : Vec = Vec::new(); - let ident_ids = { - $( - debug_assert!(by_id.len() == $ident_id, "Error setting up Builtins: when inserting {} …: {:?} into module {} …: {:?} - this entry was assigned an ID of {}, but based on insertion order, it should have had an ID of {} instead! To fix this, change it from {} …: {:?} to {} …: {:?} instead.", $ident_id, $ident_name, $module_id, $module_name, $ident_id, by_id.len(), $ident_id, $ident_name, by_id.len(), $ident_name); + let ident_indexes = [ $($ident_id),+ ]; + let ident_names = [ $($ident_name),+ ]; - by_id.push($ident_name.into()); - )+ + let mut ident_ids = IdentIds::with_capacity(ident_names.len()); - #[cfg(debug_assertions)] - { - let mut cloned = by_id.clone(); - let before = cloned.len(); - cloned.sort(); - cloned.dedup(); - let after = cloned.len(); + for (_expected_id, name) in ident_indexes.iter().zip(ident_names.iter()) { + debug_assert!(!ident_ids.strs().any(|s| s == *name), "The Ident {} is already in IdentIds", name); + let _actual_id = ident_ids.add_str(name); - if before != after { - let mut duplicates : Vec<&Ident> = Vec::new(); - let mut temp : Vec<&Ident> = Vec::new(); - - for symbol in cloned.iter() { - if temp.contains(&&symbol) { - duplicates.push(symbol); - } - - temp.push(&symbol); - } - - - panic!("duplicate symbols in IdentIds for module {:?}: {:?}", $module_name, duplicates); - } - } - - IdentIds { - by_id, - next_generated_name: 0, - } - }; + debug_assert_eq!(*_expected_id, _actual_id.0 as usize, "Error setting up Builtins: when inserting {} …: {} into module {} …: {} - this entry was assigned an ID of {}, but based on insertion order, it should have had an ID of {} instead! To fix this, change it from {} …: {} to {} …: {} instead.", _expected_id, name, $module_id, $module_name, _expected_id, _actual_id.0, _expected_id, name, _actual_id.0, name ); + } if cfg!(debug_assertions) { let module_id = ModuleId($module_id); @@ -734,6 +730,7 @@ macro_rules! define_builtins { module_id.register_debug_idents(&ident_ids); } + exposed_idents_by_module.insert( ModuleId($module_id), ident_ids diff --git a/compiler/mono/src/code_gen_help/mod.rs b/compiler/mono/src/code_gen_help/mod.rs index 3244e04fbb..d2d864ff37 100644 --- a/compiler/mono/src/code_gen_help/mod.rs +++ b/compiler/mono/src/code_gen_help/mod.rs @@ -396,7 +396,7 @@ impl<'a> CodeGenHelp<'a> { } fn create_symbol(&self, ident_ids: &mut IdentIds, debug_name: &str) -> Symbol { - let ident_id = ident_ids.add(Ident::from(debug_name)); + let ident_id = ident_ids.add(&Ident::from(debug_name)); Symbol::new(self.home, ident_id) } diff --git a/compiler/mono/src/layout.rs b/compiler/mono/src/layout.rs index ddc5aadfa6..79e193e1e5 100644 --- a/compiler/mono/src/layout.rs +++ b/compiler/mono/src/layout.rs @@ -2774,7 +2774,7 @@ impl LayoutId { // Returns something like "foo#1" when given a symbol that interns to "foo" // and a LayoutId of 1. pub fn to_symbol_string(self, symbol: Symbol, interns: &Interns) -> String { - let ident_string = symbol.ident_str(interns); + let ident_string = symbol.as_str(interns); let module_string = interns.module_ids.get_name(symbol.module_id()).unwrap(); format!("{}_{}_{}", module_string, ident_string, self.0) } diff --git a/compiler/types/src/pretty_print.rs b/compiler/types/src/pretty_print.rs index f9e11471f3..917e4a33e0 100644 --- a/compiler/types/src/pretty_print.rs +++ b/compiler/types/src/pretty_print.rs @@ -994,7 +994,7 @@ fn write_fn<'a>( fn write_symbol(env: &Env, symbol: Symbol, buf: &mut String) { let interns = &env.interns; - let ident = symbol.ident_str(interns); + let ident_str = symbol.as_str(interns); let module_id = symbol.module_id(); // Don't qualify the symbol if it's in our home module, @@ -1004,5 +1004,5 @@ fn write_symbol(env: &Env, symbol: Symbol, buf: &mut String) { buf.push('.'); } - buf.push_str(ident.as_str()); + buf.push_str(ident_str); } diff --git a/compiler/types/src/types.rs b/compiler/types/src/types.rs index b9c3a9a261..2f92a8fcb8 100644 --- a/compiler/types/src/types.rs +++ b/compiler/types/src/types.rs @@ -2011,7 +2011,7 @@ fn write_error_type_help( if write_parens { buf.push('('); } - buf.push_str(symbol.ident_str(interns).as_str()); + buf.push_str(symbol.as_str(interns)); for arg in arguments { buf.push(' '); diff --git a/docs/src/lib.rs b/docs/src/lib.rs index d09134d98d..a2c01973c7 100644 --- a/docs/src/lib.rs +++ b/docs/src/lib.rs @@ -71,7 +71,7 @@ pub fn generate_docs_html(filenames: Vec, build_dir: &Path) { let exposed_values = loaded_module .exposed_values .iter() - .map(|symbol| symbol.ident_str(&loaded_module.interns).to_string()) + .map(|symbol| symbol.as_str(&loaded_module.interns).to_string()) .collect::>(); (exposed_values, d) diff --git a/editor/src/editor/mvc/let_update.rs b/editor/src/editor/mvc/let_update.rs index de59fbf901..585aa6c5dd 100644 --- a/editor/src/editor/mvc/let_update.rs +++ b/editor/src/editor/mvc/let_update.rs @@ -1,6 +1,7 @@ use roc_ast::lang::core::expr::expr2::Expr2; use roc_ast::lang::core::pattern::Pattern2; use roc_ast::lang::core::val_def::ValueDef; +use roc_module::ident::Ident; use roc_module::symbol::Symbol; use crate::editor::ed_error::EdResult; @@ -25,7 +26,8 @@ pub fn start_new_let_value(ed_model: &mut EdModel, new_char: &char) -> EdResult< let val_expr2_node = Expr2::Blank; let val_expr_id = ed_model.module.env.pool.add(val_expr2_node); - let ident_id = ed_model.module.env.ident_ids.add(val_name_string.into()); + let ident = Ident::from(val_name_string); + let ident_id = ed_model.module.env.ident_ids.add(&ident); let var_symbol = Symbol::new(ed_model.module.env.home, ident_id); let body = Expr2::Var(var_symbol); let body_id = ed_model.module.env.pool.add(body); diff --git a/editor/src/editor/mvc/tld_value_update.rs b/editor/src/editor/mvc/tld_value_update.rs index e548dd2e25..27e85ffe31 100644 --- a/editor/src/editor/mvc/tld_value_update.rs +++ b/editor/src/editor/mvc/tld_value_update.rs @@ -1,5 +1,6 @@ use roc_ast::lang::core::{def::def2::Def2, expr::expr2::Expr2}; use roc_code_markup::slow_pool::MarkNodeId; +use roc_module::ident::Ident; use crate::{ editor::ed_error::{EdResult, FailedToUpdateIdentIdName, KeyNotFound}, @@ -26,13 +27,8 @@ pub fn start_new_tld_value(ed_model: &mut EdModel, new_char: &char) -> EdResult< let val_expr_node = Expr2::Blank; let val_expr_id = ed_model.module.env.pool.add(val_expr_node); - let val_name_string = new_char.to_string(); - - let ident_id = ed_model - .module - .env - .ident_ids - .add(val_name_string.clone().into()); + let ident = Ident::from(new_char.to_string().as_str()); + let ident_id = ed_model.module.env.ident_ids.add(&ident); let module_ident_ids_opt = ed_model .loaded_module @@ -42,7 +38,7 @@ pub fn start_new_tld_value(ed_model: &mut EdModel, new_char: &char) -> EdResult< if let Some(module_ident_ids_ref) = module_ident_ids_opt { // this might create different IdentId for interns and env.ident_ids which may be a problem - module_ident_ids_ref.add(val_name_string.into()); + module_ident_ids_ref.add(&ident); } else { KeyNotFound { key_str: format!("{:?}", ed_model.module.env.home), diff --git a/reporting/src/report.rs b/reporting/src/report.rs index 1fa222c813..e86e16b798 100644 --- a/reporting/src/report.rs +++ b/reporting/src/report.rs @@ -391,19 +391,19 @@ impl<'a> RocDocAllocator<'a> { } pub fn symbol_unqualified(&'a self, symbol: Symbol) -> DocBuilder<'a, Self, Annotation> { - self.text(format!("{}", symbol.ident_str(self.interns))) + self.text(symbol.as_str(self.interns)) .annotate(Annotation::Symbol) } pub fn symbol_foreign_qualified(&'a self, symbol: Symbol) -> DocBuilder<'a, Self, Annotation> { if symbol.module_id() == self.home || symbol.module_id().is_builtin() { // Render it unqualified if it's in the current module or a builtin - self.text(format!("{}", symbol.ident_str(self.interns))) + self.text(symbol.as_str(self.interns)) .annotate(Annotation::Symbol) } else { self.text(format!( "{}.{}", symbol.module_string(self.interns), - symbol.ident_str(self.interns), + symbol.as_str(self.interns), )) .annotate(Annotation::Symbol) } @@ -412,7 +412,7 @@ impl<'a> RocDocAllocator<'a> { self.text(format!( "{}.{}", symbol.module_string(self.interns), - symbol.ident_str(self.interns), + symbol.as_str(self.interns), )) .annotate(Annotation::Symbol) } @@ -425,12 +425,12 @@ impl<'a> RocDocAllocator<'a> { pub fn opaque_name(&'a self, opaque: Symbol) -> DocBuilder<'a, Self, Annotation> { let fmt = if opaque.module_id() == self.home { // Render it unqualified if it's in the current module. - format!("{}", opaque.ident_str(self.interns)) + opaque.as_str(self.interns).to_string() } else { format!( "{}.{}", opaque.module_string(self.interns), - opaque.ident_str(self.interns), + opaque.as_str(self.interns), ) }; @@ -440,7 +440,7 @@ impl<'a> RocDocAllocator<'a> { pub fn wrapped_opaque_name(&'a self, opaque: Symbol) -> DocBuilder<'a, Self, Annotation> { debug_assert_eq!(opaque.module_id(), self.home, "Opaque wrappings can only be defined in the same module they're defined in, but this one is defined elsewhere: {:?}", opaque); - self.text(format!("@{}", opaque.ident_str(self.interns))) + self.text(format!("@{}", opaque.as_str(self.interns))) .annotate(Annotation::Opaque) } From ae04887cb1738a8b09213234505ac16fb2affb17 Mon Sep 17 00:00:00 2001 From: Folkert Date: Mon, 25 Apr 2022 21:44:44 +0200 Subject: [PATCH 573/846] make IdentIds expose an iterator of &str --- ast/src/lang/env.rs | 8 ++++---- ast/src/lang/scope.rs | 4 ++-- compiler/can/src/env.rs | 8 ++++---- compiler/module/src/symbol.rs | 10 ++++++---- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/ast/src/lang/env.rs b/ast/src/lang/env.rs index 7e7f5a1670..0af9303543 100644 --- a/ast/src/lang/env.rs +++ b/ast/src/lang/env.rs @@ -129,8 +129,8 @@ impl<'a> Env<'a> { region, }, self.ident_ids - .idents() - .map(|(_, string)| string.as_ref().into()) + .ident_strs() + .map(|(_, string)| string.into()) .collect(), )), } @@ -146,9 +146,9 @@ impl<'a> Env<'a> { } None => { let exposed_values = exposed_ids - .idents() + .ident_strs() .filter(|(_, ident)| { - ident.as_ref().starts_with(|c: char| c.is_lowercase()) + ident.starts_with(|c: char| c.is_lowercase()) }) .map(|(_, ident)| Lowercase::from(ident.as_ref())) .collect(); diff --git a/ast/src/lang/scope.rs b/ast/src/lang/scope.rs index b01c818064..26b82b25d7 100644 --- a/ast/src/lang/scope.rs +++ b/ast/src/lang/scope.rs @@ -327,9 +327,9 @@ impl Scope { ) -> ASTResult<()> { let ident_ids = get_module_ident_ids(all_ident_ids, &env.home)?.clone(); - for (_, ident_ref) in ident_ids.idents() { + for (_, ident_ref) in ident_ids.ident_strs() { self.introduce( - ident_ref.as_inline_str().as_str().into(), + ident_ref.into(), &env.exposed_ident_ids, get_module_ident_ids_mut(all_ident_ids, &env.home)?, Region::zero(), diff --git a/compiler/can/src/env.rs b/compiler/can/src/env.rs index 40523b2fb7..2c7a28ad69 100644 --- a/compiler/can/src/env.rs +++ b/compiler/can/src/env.rs @@ -104,8 +104,8 @@ impl<'a> Env<'a> { region, }, self.ident_ids - .idents() - .map(|(_, string)| string.as_ref().into()) + .ident_strs() + .map(|(_, string)| string.into()) .collect(), ); Err(error) @@ -127,9 +127,9 @@ impl<'a> Env<'a> { } None => { let exposed_values = exposed_ids - .idents() + .ident_strs() .filter(|(_, ident)| { - ident.as_ref().starts_with(|c: char| c.is_lowercase()) + ident.starts_with(|c: char| c.is_lowercase()) }) .map(|(_, ident)| Lowercase::from(ident.as_ref())) .collect(); diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index 391a31600d..86648dc9b9 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -542,11 +542,11 @@ pub struct IdentIds { } impl IdentIds { - pub fn idents(&self) -> impl Iterator { + pub fn ident_strs(&self) -> impl Iterator { self.by_id .iter() .enumerate() - .map(|(index, ident)| (IdentId(index as u32), ident)) + .map(|(index, ident)| (IdentId(index as u32), ident.as_inline_str().as_str())) } pub fn add(&mut self, ident_name: Ident) -> IdentId { @@ -639,8 +639,10 @@ impl IdentIds { #[inline(always)] pub fn get_id(&self, ident_name: &Ident) -> Option { - for (id, ident) in self.idents() { - if ident_name == ident { + let ident_name = ident_name.as_inline_str().as_str(); + + for (id, ident_str) in self.ident_strs() { + if ident_name == ident_str { return Some(id); } } From af6c3231f3bfd1df8c385e9e716072d4beed88fc Mon Sep 17 00:00:00 2001 From: Folkert Date: Mon, 25 Apr 2022 23:09:18 +0200 Subject: [PATCH 574/846] Improved IdentIds --- ast/src/lang/core/pattern.rs | 2 +- ast/src/lang/scope.rs | 4 +- compiler/can/src/pattern.rs | 2 +- compiler/can/src/scope.rs | 8 +- compiler/gen_wasm/src/backend.rs | 2 +- compiler/load_internal/src/file.rs | 2 +- compiler/module/src/ident.rs | 4 + compiler/module/src/symbol.rs | 219 +++++++++++----------- compiler/mono/src/code_gen_help/mod.rs | 2 +- compiler/mono/src/layout.rs | 2 +- compiler/types/src/pretty_print.rs | 4 +- compiler/types/src/types.rs | 2 +- docs/src/lib.rs | 2 +- editor/src/editor/mvc/let_update.rs | 4 +- editor/src/editor/mvc/tld_value_update.rs | 12 +- reporting/src/report.rs | 14 +- 16 files changed, 142 insertions(+), 143 deletions(-) diff --git a/ast/src/lang/core/pattern.rs b/ast/src/lang/core/pattern.rs index 9ae9c5db9b..41eb8b17be 100644 --- a/ast/src/lang/core/pattern.rs +++ b/ast/src/lang/core/pattern.rs @@ -516,7 +516,7 @@ pub fn symbols_from_pattern(pool: &Pool, initial: &Pattern2) -> Vec { pub fn get_identifier_string(pattern: &Pattern2, interns: &Interns) -> ASTResult { match pattern { - Pattern2::Identifier(symbol) => Ok(symbol.ident_str(interns).to_string()), + Pattern2::Identifier(symbol) => Ok(symbol.as_str(interns).to_string()), other => UnexpectedPattern2Variant { required_pattern2: "Identifier".to_string(), encountered_pattern2: format!("{:?}", other), diff --git a/ast/src/lang/scope.rs b/ast/src/lang/scope.rs index 26b82b25d7..90046e4b40 100644 --- a/ast/src/lang/scope.rs +++ b/ast/src/lang/scope.rs @@ -245,7 +245,7 @@ impl Scope { // use that existing IdentId. Otherwise, create a fresh one. let ident_id = match exposed_ident_ids.get_id(&ident) { Some(ident_id) => ident_id, - None => all_ident_ids.add(ident.clone().into()), + None => all_ident_ids.add(&ident), }; let symbol = Symbol::new(self.home, ident_id); @@ -262,7 +262,7 @@ impl Scope { /// /// Used for record guards like { x: Just _ } pub fn ignore(&mut self, ident: Ident, all_ident_ids: &mut IdentIds) -> Symbol { - let ident_id = all_ident_ids.add(ident.into()); + let ident_id = all_ident_ids.add(&ident); Symbol::new(self.home, ident_id) } diff --git a/compiler/can/src/pattern.rs b/compiler/can/src/pattern.rs index 7fb54af2ea..d3ebcf3118 100644 --- a/compiler/can/src/pattern.rs +++ b/compiler/can/src/pattern.rs @@ -501,7 +501,7 @@ pub fn canonicalize_pattern<'a>( RequiredField(label, loc_guard) => { // a guard does not introduce the label into scope! - let symbol = scope.ignore(label.into(), &mut env.ident_ids); + let symbol = scope.ignore(&Ident::from(label), &mut env.ident_ids); let can_guard = canonicalize_pattern( env, var_store, diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index b45b7eea6c..2798957571 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -225,7 +225,7 @@ impl Scope { region, }; - let ident_id = all_ident_ids.add(ident.clone()); + let ident_id = all_ident_ids.add(&ident); let symbol = Symbol::new(self.home, ident_id); self.symbols.insert(symbol, region); @@ -273,7 +273,7 @@ impl Scope { ) -> Result<(Symbol, Option), (Region, Loc, Symbol)> { match self.idents.get(&ident) { Some(&(original_symbol, original_region)) => { - let shadow_ident_id = all_ident_ids.add(ident.clone()); + let shadow_ident_id = all_ident_ids.add(&ident); let shadow_symbol = Symbol::new(self.home, shadow_ident_id); self.symbols.insert(shadow_symbol, region); @@ -315,7 +315,7 @@ impl Scope { // use that existing IdentId. Otherwise, create a fresh one. let ident_id = match exposed_ident_ids.get_id(&ident) { Some(ident_id) => ident_id, - None => all_ident_ids.add(ident.clone()), + None => all_ident_ids.add(&ident), }; let symbol = Symbol::new(self.home, ident_id); @@ -329,7 +329,7 @@ impl Scope { /// Ignore an identifier. /// /// Used for record guards like { x: Just _ } - pub fn ignore(&mut self, ident: Ident, all_ident_ids: &mut IdentIds) -> Symbol { + pub fn ignore(&mut self, ident: &Ident, all_ident_ids: &mut IdentIds) -> Symbol { let ident_id = all_ident_ids.add(ident); Symbol::new(self.home, ident_id) } diff --git a/compiler/gen_wasm/src/backend.rs b/compiler/gen_wasm/src/backend.rs index 0ad99742cb..7b5162c8b1 100644 --- a/compiler/gen_wasm/src/backend.rs +++ b/compiler/gen_wasm/src/backend.rs @@ -183,7 +183,7 @@ impl<'a> WasmBackend<'a> { .get_mut(&self.env.module_id) .unwrap(); - let ident_id = ident_ids.add(Ident::from(debug_name)); + let ident_id = ident_ids.add(&Ident::from(debug_name)); Symbol::new(self.env.module_id, ident_id) } diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index 6fcb0785ae..20584442b3 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -446,7 +446,7 @@ impl LoadedModule { pub fn exposed_values_str(&self) -> Vec<&str> { self.exposed_values .iter() - .map(|symbol| symbol.ident_str(&self.interns).as_str()) + .map(|symbol| symbol.as_str(&self.interns)) .collect() } } diff --git a/compiler/module/src/ident.rs b/compiler/module/src/ident.rs index 5335cad281..0af20224ee 100644 --- a/compiler/module/src/ident.rs +++ b/compiler/module/src/ident.rs @@ -10,6 +10,10 @@ impl Ident { pub fn as_inline_str(&self) -> &IdentStr { &self.0 } + + pub fn as_str(&self) -> &str { + self.0.as_str() + } } pub struct QualifiedModuleName<'a> { diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index 86648dc9b9..1b36f1b2da 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -68,10 +68,6 @@ impl Symbol { } pub fn as_str(self, interns: &Interns) -> &str { - self.ident_str(interns).as_str() - } - - pub fn ident_str(self, interns: &Interns) -> &IdentStr { let ident_ids = interns .all_ident_ids .get(&self.module_id()) @@ -83,16 +79,13 @@ impl Symbol { ) }); - ident_ids - .get_name(self.ident_id()) - .unwrap_or_else(|| { - panic!( - "ident_string's IdentIds did not contain an entry for {} in module {:?}", - self.ident_id().0, - self.module_id() - ) - }) - .into() + ident_ids.get_name(self.ident_id()).unwrap_or_else(|| { + panic!( + "ident_string's IdentIds did not contain an entry for {} in module {:?}", + self.ident_id().0, + self.module_id() + ) + }) } pub fn as_u64(self) -> u64 { @@ -103,13 +96,13 @@ impl Symbol { let module_id = self.module_id(); if module_id == home { - self.ident_str(interns).clone().into() + ModuleName::from(self.as_str(interns)) } else { // TODO do this without format! to avoid allocation for short strings format!( "{}.{}", self.module_string(interns).as_str(), - self.ident_str(interns) + self.as_str(interns) ) .into() } @@ -535,25 +528,50 @@ pub struct IdentId(u32); /// Since these are interned strings, this shouldn't result in many total allocations in practice. #[derive(Clone, Debug, Default, PartialEq, Eq)] pub struct IdentIds { - /// Each IdentId is an index into this Vec - by_id: Vec, + buffer: String, - next_generated_name: u32, + lengths: Vec, + offsets: Vec, } impl IdentIds { - pub fn ident_strs(&self) -> impl Iterator { - self.by_id - .iter() - .enumerate() - .map(|(index, ident)| (IdentId(index as u32), ident.as_inline_str().as_str())) + fn with_capacity(capacity: usize) -> Self { + Self { + // guess: the average symbol length is 3 + buffer: String::with_capacity(3 * capacity), + + lengths: Vec::with_capacity(capacity), + offsets: Vec::with_capacity(capacity), + } } - pub fn add(&mut self, ident_name: Ident) -> IdentId { - let by_id = &mut self.by_id; - let ident_id = IdentId(by_id.len() as u32); + fn strs(&self) -> impl Iterator { + self.offsets + .iter() + .zip(self.lengths.iter()) + .map(move |(offset, length)| &self.buffer[*offset as usize..][..*length as usize]) + } - by_id.push(ident_name); + pub fn ident_strs(&self) -> impl Iterator { + self.strs() + .enumerate() + .map(|(index, ident)| (IdentId(index as u32), ident)) + } + + pub fn add(&mut self, ident_name: &Ident) -> IdentId { + self.add_str(ident_name.as_inline_str().as_str()) + } + + fn add_str(&mut self, string: &str) -> IdentId { + let offset = self.buffer.len() as u32; + let length = string.len() as u16; + + let ident_id = IdentId(self.lengths.len() as u32); + + self.lengths.push(length); + self.offsets.push(offset); + + self.buffer.push_str(string); ident_id } @@ -561,13 +579,7 @@ impl IdentIds { pub fn get_or_insert(&mut self, name: &Ident) -> IdentId { match self.get_id(name) { Some(id) => id, - None => { - let ident_id = IdentId(self.by_id.len() as u32); - - self.by_id.push(name.clone()); - - ident_id - } + None => self.add(name), } } @@ -586,31 +598,26 @@ impl IdentIds { Some(ident_id_ref) => { let ident_id = ident_id_ref; - let by_id = &mut self.by_id; - let key_index_opt = by_id.iter().position(|x| *x == old_ident); + match self.find_index(old_ident_name) { + Some(key_index) => { + let length = new_ident_name.len(); + let offset = self.buffer.len(); + self.buffer.push_str(new_ident_name); - if let Some(key_index) = key_index_opt { - if let Some(vec_elt) = by_id.get_mut(key_index) { - *vec_elt = new_ident_name.into(); - } else { - // we get the index from by_id - unreachable!() + self.lengths[key_index] = length as u16; + self.offsets[key_index] = offset as u32; + + Ok(ident_id) } - - Ok(ident_id) - } else { - Err( - format!( - "Tried to find position of key {:?} in IdentIds.by_id but I could not find the key. IdentIds.by_id: {:?}", - old_ident_name, - self.by_id - ) - ) + None => Err(format!( + r"Tried to find position of key {:?} in IdentIds.by_id but I could not find the key", + old_ident_name + )), } } None => Err(format!( - "Tried to update key in IdentIds ({:?}) but I could not find the key ({}).", - self.by_id, old_ident_name + "Tried to update key in IdentIds, but I could not find the key ({}).", + old_ident_name )), } } @@ -625,44 +632,60 @@ impl IdentIds { pub fn gen_unique(&mut self) -> IdentId { use std::fmt::Write; - let index: u32 = self.next_generated_name; - self.next_generated_name += 1; + let index = self.lengths.len(); - // "4294967296" is 10 characters - let mut buffer: arrayvec::ArrayString<10> = arrayvec::ArrayString::new(); + let offset = self.buffer.len(); + write!(self.buffer, "{}", index).unwrap(); + let length = self.buffer.len() - offset; - write!(buffer, "{}", index).unwrap(); - let ident = Ident(IdentStr::from_str(buffer.as_str())); + self.lengths.push(length as u16); + self.offsets.push(offset as u32); - self.add(ident) + IdentId(index as u32) } #[inline(always)] pub fn get_id(&self, ident_name: &Ident) -> Option { - let ident_name = ident_name.as_inline_str().as_str(); + self.find_index(ident_name.as_inline_str().as_str()) + .map(|i| IdentId(i as u32)) + } - for (id, ident_str) in self.ident_strs() { - if ident_name == ident_str { - return Some(id); + #[inline(always)] + fn find_index(&self, string: &str) -> Option { + let target_length = string.len() as u16; + + for (index, length) in self.lengths.iter().enumerate() { + if *length == target_length { + let offset = self.offsets[index] as usize; + let ident = &self.buffer[offset..][..*length as usize]; + + // skip the length check + if string.bytes().eq(ident.bytes()) { + return Some(index); + } } } None } - pub fn get_name(&self, id: IdentId) -> Option<&Ident> { - self.by_id.get(id.0 as usize) + pub fn get_name(&self, id: IdentId) -> Option<&str> { + let index = id.0 as usize; + + match self.lengths.get(index) { + None => None, + Some(length) => { + let offset = self.offsets[index] as usize; + Some(&self.buffer[offset..][..*length as usize]) + } + } } pub fn get_name_str_res(&self, ident_id: IdentId) -> ModuleResult<&str> { - Ok(self - .get_name(ident_id) - .with_context(|| IdentIdNotFound { - ident_id, - ident_ids_str: format!("{:?}", self), - })? - .as_inline_str() - .as_str()) + Ok(self.get_name(ident_id).with_context(|| IdentIdNotFound { + ident_id, + ident_ids_str: format!("{:?}", self), + })?) } } @@ -686,45 +709,18 @@ macro_rules! define_builtins { $( debug_assert!(!exposed_idents_by_module.contains_key(&ModuleId($module_id)), "Error setting up Builtins: when setting up module {} {:?} - the module ID {} is already present in the map. Check the map for duplicate module IDs!", $module_id, $module_name, $module_id); - let mut by_id : Vec = Vec::new(); - let ident_ids = { - $( - debug_assert!(by_id.len() == $ident_id, "Error setting up Builtins: when inserting {} …: {:?} into module {} …: {:?} - this entry was assigned an ID of {}, but based on insertion order, it should have had an ID of {} instead! To fix this, change it from {} …: {:?} to {} …: {:?} instead.", $ident_id, $ident_name, $module_id, $module_name, $ident_id, by_id.len(), $ident_id, $ident_name, by_id.len(), $ident_name); + let ident_indexes = [ $($ident_id),+ ]; + let ident_names = [ $($ident_name),+ ]; - by_id.push($ident_name.into()); - )+ + let mut ident_ids = IdentIds::with_capacity(ident_names.len()); - #[cfg(debug_assertions)] - { - let mut cloned = by_id.clone(); - let before = cloned.len(); - cloned.sort(); - cloned.dedup(); - let after = cloned.len(); + for (_expected_id, name) in ident_indexes.iter().zip(ident_names.iter()) { + debug_assert!(!ident_ids.strs().any(|s| s == *name), "The Ident {} is already in IdentIds", name); + let _actual_id = ident_ids.add_str(name); - if before != after { - let mut duplicates : Vec<&Ident> = Vec::new(); - let mut temp : Vec<&Ident> = Vec::new(); - - for symbol in cloned.iter() { - if temp.contains(&&symbol) { - duplicates.push(symbol); - } - - temp.push(&symbol); - } - - - panic!("duplicate symbols in IdentIds for module {:?}: {:?}", $module_name, duplicates); - } - } - - IdentIds { - by_id, - next_generated_name: 0, - } - }; + debug_assert_eq!(*_expected_id, _actual_id.0 as usize, "Error setting up Builtins: when inserting {} …: {} into module {} …: {} - this entry was assigned an ID of {}, but based on insertion order, it should have had an ID of {} instead! To fix this, change it from {} …: {} to {} …: {} instead.", _expected_id, name, $module_id, $module_name, _expected_id, _actual_id.0, _expected_id, name, _actual_id.0, name ); + } if cfg!(debug_assertions) { let module_id = ModuleId($module_id); @@ -734,6 +730,7 @@ macro_rules! define_builtins { module_id.register_debug_idents(&ident_ids); } + exposed_idents_by_module.insert( ModuleId($module_id), ident_ids diff --git a/compiler/mono/src/code_gen_help/mod.rs b/compiler/mono/src/code_gen_help/mod.rs index 3244e04fbb..d2d864ff37 100644 --- a/compiler/mono/src/code_gen_help/mod.rs +++ b/compiler/mono/src/code_gen_help/mod.rs @@ -396,7 +396,7 @@ impl<'a> CodeGenHelp<'a> { } fn create_symbol(&self, ident_ids: &mut IdentIds, debug_name: &str) -> Symbol { - let ident_id = ident_ids.add(Ident::from(debug_name)); + let ident_id = ident_ids.add(&Ident::from(debug_name)); Symbol::new(self.home, ident_id) } diff --git a/compiler/mono/src/layout.rs b/compiler/mono/src/layout.rs index ddc5aadfa6..79e193e1e5 100644 --- a/compiler/mono/src/layout.rs +++ b/compiler/mono/src/layout.rs @@ -2774,7 +2774,7 @@ impl LayoutId { // Returns something like "foo#1" when given a symbol that interns to "foo" // and a LayoutId of 1. pub fn to_symbol_string(self, symbol: Symbol, interns: &Interns) -> String { - let ident_string = symbol.ident_str(interns); + let ident_string = symbol.as_str(interns); let module_string = interns.module_ids.get_name(symbol.module_id()).unwrap(); format!("{}_{}_{}", module_string, ident_string, self.0) } diff --git a/compiler/types/src/pretty_print.rs b/compiler/types/src/pretty_print.rs index f9e11471f3..917e4a33e0 100644 --- a/compiler/types/src/pretty_print.rs +++ b/compiler/types/src/pretty_print.rs @@ -994,7 +994,7 @@ fn write_fn<'a>( fn write_symbol(env: &Env, symbol: Symbol, buf: &mut String) { let interns = &env.interns; - let ident = symbol.ident_str(interns); + let ident_str = symbol.as_str(interns); let module_id = symbol.module_id(); // Don't qualify the symbol if it's in our home module, @@ -1004,5 +1004,5 @@ fn write_symbol(env: &Env, symbol: Symbol, buf: &mut String) { buf.push('.'); } - buf.push_str(ident.as_str()); + buf.push_str(ident_str); } diff --git a/compiler/types/src/types.rs b/compiler/types/src/types.rs index b9c3a9a261..2f92a8fcb8 100644 --- a/compiler/types/src/types.rs +++ b/compiler/types/src/types.rs @@ -2011,7 +2011,7 @@ fn write_error_type_help( if write_parens { buf.push('('); } - buf.push_str(symbol.ident_str(interns).as_str()); + buf.push_str(symbol.as_str(interns)); for arg in arguments { buf.push(' '); diff --git a/docs/src/lib.rs b/docs/src/lib.rs index d09134d98d..a2c01973c7 100644 --- a/docs/src/lib.rs +++ b/docs/src/lib.rs @@ -71,7 +71,7 @@ pub fn generate_docs_html(filenames: Vec, build_dir: &Path) { let exposed_values = loaded_module .exposed_values .iter() - .map(|symbol| symbol.ident_str(&loaded_module.interns).to_string()) + .map(|symbol| symbol.as_str(&loaded_module.interns).to_string()) .collect::>(); (exposed_values, d) diff --git a/editor/src/editor/mvc/let_update.rs b/editor/src/editor/mvc/let_update.rs index de59fbf901..585aa6c5dd 100644 --- a/editor/src/editor/mvc/let_update.rs +++ b/editor/src/editor/mvc/let_update.rs @@ -1,6 +1,7 @@ use roc_ast::lang::core::expr::expr2::Expr2; use roc_ast::lang::core::pattern::Pattern2; use roc_ast::lang::core::val_def::ValueDef; +use roc_module::ident::Ident; use roc_module::symbol::Symbol; use crate::editor::ed_error::EdResult; @@ -25,7 +26,8 @@ pub fn start_new_let_value(ed_model: &mut EdModel, new_char: &char) -> EdResult< let val_expr2_node = Expr2::Blank; let val_expr_id = ed_model.module.env.pool.add(val_expr2_node); - let ident_id = ed_model.module.env.ident_ids.add(val_name_string.into()); + let ident = Ident::from(val_name_string); + let ident_id = ed_model.module.env.ident_ids.add(&ident); let var_symbol = Symbol::new(ed_model.module.env.home, ident_id); let body = Expr2::Var(var_symbol); let body_id = ed_model.module.env.pool.add(body); diff --git a/editor/src/editor/mvc/tld_value_update.rs b/editor/src/editor/mvc/tld_value_update.rs index e548dd2e25..27e85ffe31 100644 --- a/editor/src/editor/mvc/tld_value_update.rs +++ b/editor/src/editor/mvc/tld_value_update.rs @@ -1,5 +1,6 @@ use roc_ast::lang::core::{def::def2::Def2, expr::expr2::Expr2}; use roc_code_markup::slow_pool::MarkNodeId; +use roc_module::ident::Ident; use crate::{ editor::ed_error::{EdResult, FailedToUpdateIdentIdName, KeyNotFound}, @@ -26,13 +27,8 @@ pub fn start_new_tld_value(ed_model: &mut EdModel, new_char: &char) -> EdResult< let val_expr_node = Expr2::Blank; let val_expr_id = ed_model.module.env.pool.add(val_expr_node); - let val_name_string = new_char.to_string(); - - let ident_id = ed_model - .module - .env - .ident_ids - .add(val_name_string.clone().into()); + let ident = Ident::from(new_char.to_string().as_str()); + let ident_id = ed_model.module.env.ident_ids.add(&ident); let module_ident_ids_opt = ed_model .loaded_module @@ -42,7 +38,7 @@ pub fn start_new_tld_value(ed_model: &mut EdModel, new_char: &char) -> EdResult< if let Some(module_ident_ids_ref) = module_ident_ids_opt { // this might create different IdentId for interns and env.ident_ids which may be a problem - module_ident_ids_ref.add(val_name_string.into()); + module_ident_ids_ref.add(&ident); } else { KeyNotFound { key_str: format!("{:?}", ed_model.module.env.home), diff --git a/reporting/src/report.rs b/reporting/src/report.rs index 1fa222c813..e86e16b798 100644 --- a/reporting/src/report.rs +++ b/reporting/src/report.rs @@ -391,19 +391,19 @@ impl<'a> RocDocAllocator<'a> { } pub fn symbol_unqualified(&'a self, symbol: Symbol) -> DocBuilder<'a, Self, Annotation> { - self.text(format!("{}", symbol.ident_str(self.interns))) + self.text(symbol.as_str(self.interns)) .annotate(Annotation::Symbol) } pub fn symbol_foreign_qualified(&'a self, symbol: Symbol) -> DocBuilder<'a, Self, Annotation> { if symbol.module_id() == self.home || symbol.module_id().is_builtin() { // Render it unqualified if it's in the current module or a builtin - self.text(format!("{}", symbol.ident_str(self.interns))) + self.text(symbol.as_str(self.interns)) .annotate(Annotation::Symbol) } else { self.text(format!( "{}.{}", symbol.module_string(self.interns), - symbol.ident_str(self.interns), + symbol.as_str(self.interns), )) .annotate(Annotation::Symbol) } @@ -412,7 +412,7 @@ impl<'a> RocDocAllocator<'a> { self.text(format!( "{}.{}", symbol.module_string(self.interns), - symbol.ident_str(self.interns), + symbol.as_str(self.interns), )) .annotate(Annotation::Symbol) } @@ -425,12 +425,12 @@ impl<'a> RocDocAllocator<'a> { pub fn opaque_name(&'a self, opaque: Symbol) -> DocBuilder<'a, Self, Annotation> { let fmt = if opaque.module_id() == self.home { // Render it unqualified if it's in the current module. - format!("{}", opaque.ident_str(self.interns)) + opaque.as_str(self.interns).to_string() } else { format!( "{}.{}", opaque.module_string(self.interns), - opaque.ident_str(self.interns), + opaque.as_str(self.interns), ) }; @@ -440,7 +440,7 @@ impl<'a> RocDocAllocator<'a> { pub fn wrapped_opaque_name(&'a self, opaque: Symbol) -> DocBuilder<'a, Self, Annotation> { debug_assert_eq!(opaque.module_id(), self.home, "Opaque wrappings can only be defined in the same module they're defined in, but this one is defined elsewhere: {:?}", opaque); - self.text(format!("@{}", opaque.ident_str(self.interns))) + self.text(format!("@{}", opaque.as_str(self.interns))) .annotate(Annotation::Opaque) } From e73ebfba3e62f8a4d394904b3fd42053596ba496 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 20 Apr 2022 14:20:23 -0400 Subject: [PATCH 575/846] Add a way to view solved types of arbitrary expressions/patterns in a program --- compiler/can/src/traverse.rs | 11 +++++++++++ compiler/constrain/src/expr.rs | 8 ++++++-- compiler/solve/tests/solve_expr.rs | 5 +++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/compiler/can/src/traverse.rs b/compiler/can/src/traverse.rs index a1f338c4ca..046b329dd4 100644 --- a/compiler/can/src/traverse.rs +++ b/compiler/can/src/traverse.rs @@ -52,7 +52,11 @@ fn walk_def(visitor: &mut V, def: &Def) { ); visitor.visit_expr(&loc_expr.value, loc_expr.region, *expr_var); if let Some(annot) = &annotation { +<<<<<<< HEAD visitor.visit_annotation(annot); +======= + visitor.visit_annotation(&annot); +>>>>>>> 1c2489622 (Add a way to view solved types of arbitrary expressions/patterns in a program) } } @@ -117,8 +121,15 @@ fn walk_when_branch(visitor: &mut V, branch: &WhenBranch, expr_var: } } +<<<<<<< HEAD fn walk_pattern(_visitor: &mut V, _pat: &Pattern) { todo!() +======= +fn walk_pattern(_visitor: &mut V, pat: &Pattern) { + match pat { + _ => todo!(), + } +>>>>>>> 1c2489622 (Add a way to view solved types of arbitrary expressions/patterns in a program) } trait Visitor: Sized { diff --git a/compiler/constrain/src/expr.rs b/compiler/constrain/src/expr.rs index 98ce0e367d..12c2fd89b1 100644 --- a/compiler/constrain/src/expr.rs +++ b/compiler/constrain/src/expr.rs @@ -705,14 +705,18 @@ pub fn constrain_expr( // TODO: when we have exhaustiveness checking during the typechecking phase, perform // exhaustiveness checking when this expectation fails. That will produce better error // messages. - let cond_constraint = constrain_expr( + let expr_con = constrain_expr( constraints, env, loc_cond.region, &loc_cond.value, Expected::ForReason(Reason::WhenBranches, cond_type, branches_region), ); - pattern_cons.push(cond_constraint); + // branch_cons.extend(pattern_cons); + // branch_constraints.push(constraints.and_constraint(pattern_cons)); + let mut total_cons = Vec::with_capacity(1 + 2 * branches.len() + 1); + // total_cons.push(expr_con); + pattern_cons.push(expr_con); // Solve all the pattern constraints together, introducing variables in the pattern as // need be before solving the bodies. diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index ecf4ea4058..0b1a03af36 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -255,6 +255,7 @@ mod solve_expr { let can_problems = can_problems.remove(&home).unwrap_or_default(); let type_problems = type_problems.remove(&home).unwrap_or_default(); +<<<<<<< HEAD let (can_problems, type_problems) = format_problems(&src, home, &interns, can_problems, type_problems); @@ -264,6 +265,10 @@ mod solve_expr { can_problems ); assert!(type_problems.is_empty(), "Type problems: {}", type_problems); +======= + assert_eq!(can_problems, Vec::new(), "Canonicalization problems: "); + assert_eq!(type_problems, Vec::new(), "Type problems: "); +>>>>>>> 1c2489622 (Add a way to view solved types of arbitrary expressions/patterns in a program) let queries = parse_queries(&src); assert!(!queries.is_empty(), "No queries provided!"); From 43bff0b59d7260a6cacda96b67914da37afb8149 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 21 Apr 2022 10:16:02 -0400 Subject: [PATCH 576/846] Turn repl test back on --- compiler/can/src/traverse.rs | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/compiler/can/src/traverse.rs b/compiler/can/src/traverse.rs index 046b329dd4..a1f338c4ca 100644 --- a/compiler/can/src/traverse.rs +++ b/compiler/can/src/traverse.rs @@ -52,11 +52,7 @@ fn walk_def(visitor: &mut V, def: &Def) { ); visitor.visit_expr(&loc_expr.value, loc_expr.region, *expr_var); if let Some(annot) = &annotation { -<<<<<<< HEAD visitor.visit_annotation(annot); -======= - visitor.visit_annotation(&annot); ->>>>>>> 1c2489622 (Add a way to view solved types of arbitrary expressions/patterns in a program) } } @@ -121,15 +117,8 @@ fn walk_when_branch(visitor: &mut V, branch: &WhenBranch, expr_var: } } -<<<<<<< HEAD fn walk_pattern(_visitor: &mut V, _pat: &Pattern) { todo!() -======= -fn walk_pattern(_visitor: &mut V, pat: &Pattern) { - match pat { - _ => todo!(), - } ->>>>>>> 1c2489622 (Add a way to view solved types of arbitrary expressions/patterns in a program) } trait Visitor: Sized { From 9602b3634c74c612574e01e5008e4f84beeb7200 Mon Sep 17 00:00:00 2001 From: ayazhafiz Date: Fri, 22 Apr 2022 22:44:38 -0400 Subject: [PATCH 577/846] Fix repl test --- repl_test/src/tests.rs | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/repl_test/src/tests.rs b/repl_test/src/tests.rs index 29c43a10a3..7e3f2aa4c2 100644 --- a/repl_test/src/tests.rs +++ b/repl_test/src/tests.rs @@ -903,38 +903,31 @@ fn parse_problem() { #[test] fn exhaustiveness_problem() { expect_failure( - r#" + indoc!( + r#" t : [A, B, C] t = A when t is A -> "a" - "#, + "# + ), indoc!( r#" - ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── + ── UNSAFE PATTERN ────────────────────────────────────────────────────────────── - The branches of this when expression don't match the condition: - - 7│> when t is - 8│ A -> "a" - - This t value is a: - - [ A, B, C ] + This when does not cover all the possibilities: - But the branch patterns have type: + 7│> when t is + 8│> A -> "a" - [ A ] - - The branches must be cases of the when condition's type! + Other possibilities include: - Tip: Looks like the branches are missing coverage of the C and B tags. + B + C - Tip: Maybe you need to add a catch-all branch, like _? - - - Enter an expression, or :help, or :exit/:q."# + I would have to crash if I saw one of those! Add branches for them! + "# ), ); } From 356616d83442154407c56c356bbcb812c21b9629 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 22 Apr 2022 10:22:49 -0400 Subject: [PATCH 578/846] Move exhaustiveness checking to type solving phase with solve tests --- Cargo.lock | 2 + compiler/can/Cargo.toml | 1 + compiler/can/src/constraint.rs | 17 +- compiler/can/src/exhaustive.rs | 337 +++++++++++++++++++++++++++++ compiler/can/src/lib.rs | 1 + compiler/constrain/src/expr.rs | 6 + compiler/exhaustive/src/lib.rs | 5 +- compiler/mono/src/exhaustive.rs | 2 +- compiler/solve/Cargo.toml | 1 + compiler/solve/src/solve.rs | 11 + compiler/solve/tests/solve_expr.rs | 96 +++++--- compiler/types/src/subs.rs | 5 +- reporting/src/error/type.rs | 236 ++++++++++++++++++++ 13 files changed, 678 insertions(+), 42 deletions(-) create mode 100644 compiler/can/src/exhaustive.rs diff --git a/Cargo.lock b/Cargo.lock index d12ff57f39..fcbcb4e2da 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3453,6 +3453,7 @@ dependencies = [ "roc_builtins", "roc_collections", "roc_error_macros", + "roc_exhaustive", "roc_module", "roc_parse", "roc_problem", @@ -3962,6 +3963,7 @@ dependencies = [ "roc_can", "roc_collections", "roc_error_macros", + "roc_exhaustive", "roc_load", "roc_module", "roc_parse", diff --git a/compiler/can/Cargo.toml b/compiler/can/Cargo.toml index b1d092053e..b7b1851465 100644 --- a/compiler/can/Cargo.toml +++ b/compiler/can/Cargo.toml @@ -8,6 +8,7 @@ edition = "2018" [dependencies] roc_collections = { path = "../collections" } roc_error_macros = { path = "../../error_macros" } +roc_exhaustive = { path = "../exhaustive" } roc_region = { path = "../region" } roc_module = { path = "../module" } roc_parse = { path = "../parse" } diff --git a/compiler/can/src/constraint.rs b/compiler/can/src/constraint.rs index c858834263..e28ff8f229 100644 --- a/compiler/can/src/constraint.rs +++ b/compiler/can/src/constraint.rs @@ -1,3 +1,4 @@ +use crate::exhaustive::{ExhaustiveContext, SketchedRows}; use crate::expected::{Expected, PExpected}; use roc_collections::soa::{EitherIndex, Index, Slice}; use roc_module::ident::TagName; @@ -19,6 +20,7 @@ pub struct Constraints { pub pattern_expectations: Vec>, pub includes_tags: Vec, pub strings: Vec<&'static str>, + pub sketched_rows: Vec, } impl Default for Constraints { @@ -40,6 +42,7 @@ impl Constraints { let pattern_expectations = Vec::new(); let includes_tags = Vec::new(); let strings = Vec::new(); + let sketched_rows = Vec::new(); types.extend([ Type::EmptyRec, @@ -90,6 +93,7 @@ impl Constraints { pattern_expectations, includes_tags, strings, + sketched_rows, } } @@ -570,6 +574,7 @@ impl Constraints { Constraint::IsOpenType(_) => false, Constraint::IncludesTag(_) => false, Constraint::PatternPresence(_, _, _, _) => false, + Constraint::Exhaustive(_, _) => false, } } @@ -597,11 +602,17 @@ impl Constraints { Constraint::Store(type_index, variable, string_index, line_number) } + + pub fn exhaustive(&mut self, rows: SketchedRows, context: ExhaustiveContext) -> Constraint { + let rows_index = Index::push_new(&mut self.sketched_rows, rows); + + Constraint::Exhaustive(rows_index, context) + } } roc_error_macros::assert_sizeof_default!(Constraint, 3 * 8); -#[derive(Clone)] +#[derive(Clone, Copy)] pub enum Constraint { Eq( EitherIndex, @@ -641,6 +652,7 @@ pub enum Constraint { Index, Region, ), + Exhaustive(Index, ExhaustiveContext), } #[derive(Debug, Clone, Copy, Default)] @@ -695,6 +707,9 @@ impl std::fmt::Debug for Constraint { arg0, arg1, arg2, arg3 ) } + Self::Exhaustive(arg0, arg1) => { + write!(f, "Exhaustive({:?}, {:?})", arg0, arg1) + } } } } diff --git a/compiler/can/src/exhaustive.rs b/compiler/can/src/exhaustive.rs new file mode 100644 index 0000000000..060c688d06 --- /dev/null +++ b/compiler/can/src/exhaustive.rs @@ -0,0 +1,337 @@ +use crate::expr::{IntValue, WhenBranch}; +use crate::pattern::DestructType; +use roc_collections::all::HumanIndex; +use roc_error_macros::internal_error; +use roc_exhaustive::{is_useful, Ctor, Error, Guard, Literal, Pattern, RenderAs, TagId, Union}; +use roc_module::ident::{TagIdIntType, TagName}; +use roc_region::all::{Loc, Region}; +use roc_types::subs::{Content, FlatType, Subs, SubsFmtContent, Variable}; + +pub use roc_exhaustive::Context as ExhaustiveContext; + +pub fn check( + subs: &Subs, + sketched_rows: SketchedRows, + context: ExhaustiveContext, +) -> Result<(), Vec> { + let overall_region = sketched_rows.overall_region; + // TODO: can we keep going even if we had redundant rows? + let matrix = sketched_rows + .reify_to_non_redundant(subs) + .map_err(|e| vec![e])?; + roc_exhaustive::check(overall_region, context, matrix) +} + +#[derive(Clone, Debug, PartialEq)] +enum SketchedPattern { + Anything, + Literal(Literal), + Ctor(Variable, TagName, std::vec::Vec), + KnownCtor(Union, TagId, std::vec::Vec), +} + +impl SketchedPattern { + fn reify(self, subs: &Subs) -> Pattern { + match self { + Self::Anything => Pattern::Anything, + Self::Literal(lit) => Pattern::Literal(lit), + Self::KnownCtor(union, tag_id, patterns) => Pattern::Ctor( + union, + tag_id, + patterns.into_iter().map(|pat| pat.reify(subs)).collect(), + ), + Self::Ctor(var, tag_name, patterns) => { + let (union, tag_id) = convert_tag(subs, var, &tag_name); + Pattern::Ctor( + union, + tag_id, + patterns.into_iter().map(|pat| pat.reify(subs)).collect(), + ) + } + } + } +} + +#[derive(Clone, Debug, PartialEq)] +struct SketchedRow { + patterns: Vec, + region: Region, + guard: Guard, +} + +#[derive(Clone, Debug, PartialEq)] +pub struct SketchedRows { + rows: Vec, + overall_region: Region, +} + +impl SketchedRows { + pub fn reify_to_non_redundant(self, subs: &Subs) -> Result>, Error> { + to_nonredundant_rows(subs, self) + } +} + +fn sketch_pattern(var: Variable, pattern: &crate::pattern::Pattern) -> SketchedPattern { + use crate::pattern::Pattern::*; + use SketchedPattern as SP; + + match pattern { + &NumLiteral(_, _, IntValue::I128(n), _) | &IntLiteral(_, _, _, IntValue::I128(n), _) => { + SP::Literal(Literal::Int(n)) + } + &NumLiteral(_, _, IntValue::U128(n), _) | &IntLiteral(_, _, _, IntValue::U128(n), _) => { + SP::Literal(Literal::U128(n)) + } + &FloatLiteral(_, _, _, f, _) => SP::Literal(Literal::Float(f64::to_bits(f))), + StrLiteral(v) => SP::Literal(Literal::Str(v.clone())), + &SingleQuote(c) => SP::Literal(Literal::Byte(c as u8)), + RecordDestructure { destructs, .. } => { + let tag_id = TagId(0); + let mut patterns = std::vec::Vec::with_capacity(destructs.len()); + let mut field_names = std::vec::Vec::with_capacity(destructs.len()); + + for Loc { + value: destruct, + region: _, + } in destructs + { + field_names.push(destruct.label.clone()); + + match &destruct.typ { + DestructType::Required | DestructType::Optional(..) => { + patterns.push(SP::Anything) + } + DestructType::Guard(_, guard) => { + patterns.push(sketch_pattern(destruct.var, &guard.value)) + } + } + } + + let union = Union { + render_as: RenderAs::Record(field_names), + alternatives: vec![Ctor { + name: TagName::Global("#Record".into()), + tag_id, + arity: destructs.len(), + }], + }; + + SP::KnownCtor(union, tag_id, patterns) + } + + AppliedTag { + tag_name, + arguments, + .. + } => { + let simplified_args: std::vec::Vec<_> = arguments + .iter() + .map(|(var, arg)| sketch_pattern(*var, &arg.value)) + .collect(); + + SP::Ctor(var, tag_name.clone(), simplified_args) + } + + UnwrappedOpaque { + opaque, argument, .. + } => { + let (arg_var, argument) = &(**argument); + + let tag_id = TagId(0); + + let union = Union { + render_as: RenderAs::Opaque, + alternatives: vec![Ctor { + name: TagName::Private(*opaque), + tag_id, + arity: 1, + }], + }; + + SP::KnownCtor( + union, + tag_id, + vec![sketch_pattern(*arg_var, &argument.value)], + ) + } + + Underscore + | Identifier(_) + | AbilityMemberSpecialization { .. } + | Shadowed(..) + | OpaqueNotInScope(..) + | UnsupportedPattern(..) + | MalformedPattern(..) => SP::Anything, + } +} + +pub fn sketch_rows(target_var: Variable, region: Region, patterns: &[WhenBranch]) -> SketchedRows { + let mut rows: Vec = Vec::with_capacity(patterns.len()); + + // If any of the branches has a guard, e.g. + // + // when x is + // y if y < 10 -> "foo" + // _ -> "bar" + // + // then we treat it as a pattern match on the pattern and a boolean, wrapped in the #Guard + // constructor. We can use this special constructor name to generate better error messages. + // This transformation of the pattern match only works because we only report exhaustiveness + // errors: the Pattern created in this file is not used for code gen. + // + // when x is + // #Guard y True -> "foo" + // #Guard _ _ -> "bar" + let any_has_guard = patterns.iter().any(|branch| branch.guard.is_some()); + + use SketchedPattern as SP; + for WhenBranch { + patterns, + guard, + value: _, + } in patterns + { + let guard = if guard.is_some() { + Guard::HasGuard + } else { + Guard::NoGuard + }; + + for loc_pat in patterns { + // Decompose each pattern in the branch into its own row. + + let patterns = if any_has_guard { + let guard_pattern = match guard { + Guard::HasGuard => SP::Literal(Literal::Bit(true)), + Guard::NoGuard => SP::Anything, + }; + + let tag_id = TagId(0); + + let union = Union { + render_as: RenderAs::Guard, + alternatives: vec![Ctor { + tag_id, + name: TagName::Global("#Guard".into()), + arity: 2, + }], + }; + + vec![SP::KnownCtor( + union, + tag_id, + // NB: ordering the guard pattern first seems to be better at catching + // non-exhaustive constructors in the second argument; see the paper to see if + // there is a way to improve this in general. + vec![guard_pattern, sketch_pattern(target_var, &loc_pat.value)], + )] + } else { + // Simple case + vec![sketch_pattern(target_var, &loc_pat.value)] + }; + + let row = SketchedRow { + patterns, + region, + guard, + }; + rows.push(row); + } + } + + SketchedRows { + rows, + overall_region: region, + } +} + +/// REDUNDANT PATTERNS + +/// INVARIANT: Produces a list of rows where (forall row. length row == 1) +fn to_nonredundant_rows(subs: &Subs, rows: SketchedRows) -> Result>, Error> { + let SketchedRows { + rows, + overall_region, + } = rows; + let mut checked_rows = Vec::with_capacity(rows.len()); + + for SketchedRow { + patterns, + guard, + region, + } in rows.into_iter() + { + let next_row: Vec = patterns + .into_iter() + .map(|pattern| pattern.reify(subs)) + .collect(); + + if matches!(guard, Guard::HasGuard) || is_useful(checked_rows.clone(), next_row.clone()) { + checked_rows.push(next_row); + } else { + return Err(Error::Redundant { + overall_region, + branch_region: region, + index: HumanIndex::zero_based(checked_rows.len()), + }); + } + } + + Ok(checked_rows) +} + +fn convert_tag(subs: &Subs, whole_var: Variable, this_tag: &TagName) -> (Union, TagId) { + let content = subs.get_content_without_compacting(whole_var); + + use {Content::*, FlatType::*}; + + match content { + Structure(TagUnion(tags, ext) | RecursiveTagUnion(_, tags, ext)) => { + let (sorted_tags, ext) = tags.sorted_iterator_and_ext(subs, *ext); + + let mut num_tags = sorted_tags.len(); + + // DEVIATION: model openness by attaching a #Open constructor, that can never + // be matched unless there's an `Anything` pattern. + let opt_openness_tag = match subs.get_content_without_compacting(ext) { + FlexVar(_) | RigidVar(_) => { + let openness_tag = TagName::Global("#Open".into()); + num_tags += 1; + Some((openness_tag, &[] as _)) + } + Structure(EmptyTagUnion) => None, + // Anything else is erroneous and we ignore + _ => None, + }; + + // High tag ID if we're out-of-bounds. + let mut my_tag_id = TagId(num_tags as TagIdIntType); + + let mut alternatives = Vec::with_capacity(num_tags); + let alternatives_iter = sorted_tags.into_iter().chain(opt_openness_tag.into_iter()); + + for (index, (tag, args)) in alternatives_iter.enumerate() { + let tag_id = TagId(index as TagIdIntType); + if this_tag == &tag { + my_tag_id = tag_id; + } + alternatives.push(Ctor { + name: tag, + tag_id, + arity: args.len(), + }); + } + + let union = Union { + alternatives, + render_as: RenderAs::Tag, + }; + + (union, my_tag_id) + } + _ => internal_error!( + "Content is not a tag union: {:?}", + SubsFmtContent(content, subs) + ), + } +} diff --git a/compiler/can/src/lib.rs b/compiler/can/src/lib.rs index d7858bcde1..b2dc3f4aa1 100644 --- a/compiler/can/src/lib.rs +++ b/compiler/can/src/lib.rs @@ -8,6 +8,7 @@ pub mod constraint; pub mod def; pub mod effect_module; pub mod env; +pub mod exhaustive; pub mod expected; pub mod expr; pub mod module; diff --git a/compiler/constrain/src/expr.rs b/compiler/constrain/src/expr.rs index 12c2fd89b1..178c151a4c 100644 --- a/compiler/constrain/src/expr.rs +++ b/compiler/constrain/src/expr.rs @@ -5,6 +5,7 @@ use crate::pattern::{constrain_pattern, PatternState}; use roc_can::annotation::IntroducedVariables; use roc_can::constraint::{Constraint, Constraints}; use roc_can::def::{Declaration, Def}; +use roc_can::exhaustive::{sketch_rows, ExhaustiveContext}; use roc_can::expected::Expected::{self, *}; use roc_can::expected::PExpected; use roc_can::expr::Expr::{self, *}; @@ -718,6 +719,11 @@ pub fn constrain_expr( // total_cons.push(expr_con); pattern_cons.push(expr_con); + let sketched_rows = sketch_rows(cond_var, branches_region, &branches); + let exhaustiveness_constraint = + constraints.exhaustive(sketched_rows, ExhaustiveContext::BadCase); + pattern_cons.push(exhaustiveness_constraint); + // Solve all the pattern constraints together, introducing variables in the pattern as // need be before solving the bodies. let pattern_constraints = constraints.and_constraint(pattern_cons); diff --git a/compiler/exhaustive/src/lib.rs b/compiler/exhaustive/src/lib.rs index c94b98aaa0..19638404a4 100644 --- a/compiler/exhaustive/src/lib.rs +++ b/compiler/exhaustive/src/lib.rs @@ -78,6 +78,7 @@ pub enum Literal { U128(u128), Bit(bool), Byte(u8), + /// Stores the float bits Float(u64), Decimal(RocDec), Str(Box), @@ -95,14 +96,14 @@ pub enum Error { }, } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, PartialEq)] pub enum Context { BadArg, BadDestruct, BadCase, } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, PartialEq)] pub enum Guard { HasGuard, NoGuard, diff --git a/compiler/mono/src/exhaustive.rs b/compiler/mono/src/exhaustive.rs index 514cdf3f2d..461daba358 100644 --- a/compiler/mono/src/exhaustive.rs +++ b/compiler/mono/src/exhaustive.rs @@ -113,7 +113,7 @@ pub fn check( } } -pub fn check_patterns<'a>( +fn check_patterns<'a>( region: Region, context: Context, patterns: &[(Loc>, Guard)], diff --git a/compiler/solve/Cargo.toml b/compiler/solve/Cargo.toml index 1288c18273..6b32bc14a8 100644 --- a/compiler/solve/Cargo.toml +++ b/compiler/solve/Cargo.toml @@ -8,6 +8,7 @@ edition = "2018" [dependencies] roc_collections = { path = "../collections" } roc_error_macros = { path = "../../error_macros" } +roc_exhaustive = { path = "../exhaustive" } roc_region = { path = "../region" } roc_module = { path = "../module" } roc_types = { path = "../types" } diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index f977920b7a..e25c82dded 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -100,6 +100,7 @@ pub enum TypeError { ErrorType, Vec, ), + Exhaustive(roc_exhaustive::Error), } use roc_types::types::Alias; @@ -1196,6 +1197,16 @@ fn solve( } } } + Exhaustive(rows_index, context) => { + let sketched_rows = constraints.sketched_rows[rows_index.index()].clone(); + + let checked = roc_can::exhaustive::check(&subs, sketched_rows, *context); + if let Err(errors) = checked { + problems.extend(errors.into_iter().map(TypeError::Exhaustive)); + } + + state + } }; } diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index 0b1a03af36..6a5d90d3c7 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -255,7 +255,6 @@ mod solve_expr { let can_problems = can_problems.remove(&home).unwrap_or_default(); let type_problems = type_problems.remove(&home).unwrap_or_default(); -<<<<<<< HEAD let (can_problems, type_problems) = format_problems(&src, home, &interns, can_problems, type_problems); @@ -265,10 +264,6 @@ mod solve_expr { can_problems ); assert!(type_problems.is_empty(), "Type problems: {}", type_problems); -======= - assert_eq!(can_problems, Vec::new(), "Canonicalization problems: "); - assert_eq!(type_problems, Vec::new(), "Type problems: "); ->>>>>>> 1c2489622 (Add a way to view solved types of arbitrary expressions/patterns in a program) let queries = parse_queries(&src); assert!(!queries.is_empty(), "No queries provided!"); @@ -2565,11 +2560,10 @@ mod solve_expr { } // this test is related to a bug where ext_var would have an incorrect rank. - // This match has duplicate cases, but that's not important because exhaustiveness happens - // after inference. + // This match has duplicate cases, but we ignore that. #[test] fn to_bit_record() { - infer_eq_without_problem( + infer_eq( indoc!( r#" foo = \rec -> @@ -5266,95 +5260,123 @@ mod solve_expr { { u8: (\n -> when n is - 123u8 -> n), + 123u8 -> n + _ -> n), u16: (\n -> when n is - 123u16 -> n), + 123u16 -> n + _ -> n), u32: (\n -> when n is - 123u32 -> n), + 123u32 -> n + _ -> n), u64: (\n -> when n is - 123u64 -> n), + 123u64 -> n + _ -> n), u128: (\n -> when n is - 123u128 -> n), + 123u128 -> n + _ -> n), i8: (\n -> when n is - 123i8 -> n), + 123i8 -> n + _ -> n), i16: (\n -> when n is - 123i16 -> n), + 123i16 -> n + _ -> n), i32: (\n -> when n is - 123i32 -> n), + 123i32 -> n + _ -> n), i64: (\n -> when n is - 123i64 -> n), + 123i64 -> n + _ -> n), i128: (\n -> when n is - 123i128 -> n), + 123i128 -> n + _ -> n), nat: (\n -> when n is - 123nat -> n), + 123nat -> n + _ -> n), bu8: (\n -> when n is - 0b11u8 -> n), + 0b11u8 -> n + _ -> n), bu16: (\n -> when n is - 0b11u16 -> n), + 0b11u16 -> n + _ -> n), bu32: (\n -> when n is - 0b11u32 -> n), + 0b11u32 -> n + _ -> n), bu64: (\n -> when n is - 0b11u64 -> n), + 0b11u64 -> n + _ -> n), bu128: (\n -> when n is - 0b11u128 -> n), + 0b11u128 -> n + _ -> n), bi8: (\n -> when n is - 0b11i8 -> n), + 0b11i8 -> n + _ -> n), bi16: (\n -> when n is - 0b11i16 -> n), + 0b11i16 -> n + _ -> n), bi32: (\n -> when n is - 0b11i32 -> n), + 0b11i32 -> n + _ -> n), bi64: (\n -> when n is - 0b11i64 -> n), + 0b11i64 -> n + _ -> n), bi128: (\n -> when n is - 0b11i128 -> n), + 0b11i128 -> n + _ -> n), bnat: (\n -> when n is - 0b11nat -> n), + 0b11nat -> n + _ -> n), dec: (\n -> when n is - 123.0dec -> n), + 123.0dec -> n + _ -> n), f32: (\n -> when n is - 123.0f32 -> n), + 123.0f32 -> n + _ -> n), f64: (\n -> when n is - 123.0f64 -> n), + 123.0f64 -> n + _ -> n), fdec: (\n -> when n is - 123dec -> n), + 123dec -> n + _ -> n), ff32: (\n -> when n is - 123f32 -> n), + 123f32 -> n + _ -> n), ff64: (\n -> when n is - 123f64 -> n), + 123f64 -> n + _ -> n), } "# ), @@ -5686,6 +5708,7 @@ mod solve_expr { @Id (Id _ A) -> "" @Id (Id _ B) -> "" @Id (Id _ (C { a: "" })) -> "" + @Id (Id _ (C { a: _ })) -> "" # any other string, for exhautiveness "# ), r#"Id [ A, B, C { a : Str }* ] -> Str"#, @@ -5705,6 +5728,7 @@ mod solve_expr { @Id (Id _ A) -> "" @Id (Id _ B) -> "" @Id (Id _ (C { a: "" })) -> "" + @Id (Id _ (C { a: _ })) -> "" # any other string, for exhautiveness f "# diff --git a/compiler/types/src/subs.rs b/compiler/types/src/subs.rs index 8905a9aa58..1d9a181c67 100644 --- a/compiler/types/src/subs.rs +++ b/compiler/types/src/subs.rs @@ -2333,7 +2333,8 @@ impl UnionTags { pub fn iter_all( &self, - ) -> impl Iterator, SubsIndex)> { + ) -> impl Iterator, SubsIndex)> + ExactSizeIterator + { self.tag_names() .into_iter() .zip(self.variables().into_iter()) @@ -2436,7 +2437,7 @@ impl<'a> UnsortedUnionTags<'a> { } } -pub type SortedTagsIterator<'a> = Box + 'a>; +pub type SortedTagsIterator<'a> = Box + 'a>; pub type SortedTagsSlicesIterator<'a> = Box + 'a>; pub fn is_empty_tag_union(subs: &Subs, mut var: Variable) -> bool { diff --git a/reporting/src/error/type.rs b/reporting/src/error/type.rs index 90e7ad15b9..97a0d27a24 100644 --- a/reporting/src/error/type.rs +++ b/reporting/src/error/type.rs @@ -198,6 +198,7 @@ pub fn type_problem<'b>( }; Some(report) } + Exhaustive(problem) => Some(exhaustive_problem(alloc, lines, filename, problem)), } } @@ -3484,3 +3485,238 @@ fn report_record_field_typo<'b>( severity: Severity::RuntimeError, } } + +fn exhaustive_problem<'a>( + alloc: &'a RocDocAllocator<'a>, + lines: &LineInfo, + filename: PathBuf, + problem: roc_exhaustive::Error, +) -> Report<'a> { + use roc_exhaustive::Context::*; + use roc_exhaustive::Error::*; + + match problem { + Incomplete(region, context, missing) => match context { + BadArg => { + let doc = alloc.stack([ + alloc.reflow("This pattern does not cover all the possibilities:"), + alloc.region(lines.convert_region(region)), + alloc.reflow("Other possibilities include:"), + unhandled_patterns_to_doc_block(alloc, missing), + alloc.concat([ + alloc.reflow( + "I would have to crash if I saw one of those! \ + So rather than pattern matching in function arguments, put a ", + ), + alloc.keyword("when"), + alloc.reflow(" in the function body to account for all possibilities."), + ]), + ]); + + Report { + filename, + title: "UNSAFE PATTERN".to_string(), + doc, + severity: Severity::RuntimeError, + } + } + BadDestruct => { + let doc = alloc.stack([ + alloc.reflow("This pattern does not cover all the possibilities:"), + alloc.region(lines.convert_region(region)), + alloc.reflow("Other possibilities include:"), + unhandled_patterns_to_doc_block(alloc, missing), + alloc.concat([ + alloc.reflow( + "I would have to crash if I saw one of those! \ + You can use a binding to deconstruct a value if there is only ONE possibility. \ + Use a " + ), + alloc.keyword("when"), + alloc.reflow(" to account for all possibilities."), + ]), + ]); + + Report { + filename, + title: "UNSAFE PATTERN".to_string(), + doc, + severity: Severity::RuntimeError, + } + } + BadCase => { + let doc = alloc.stack([ + alloc.concat([ + alloc.reflow("This "), + alloc.keyword("when"), + alloc.reflow(" does not cover all the possibilities:"), + ]), + alloc.region(lines.convert_region(region)), + alloc.reflow("Other possibilities include:"), + unhandled_patterns_to_doc_block(alloc, missing), + alloc.reflow( + "I would have to crash if I saw one of those! \ + Add branches for them!", + ), + // alloc.hint().append(alloc.reflow("or use a hole.")), + ]); + + Report { + filename, + title: "UNSAFE PATTERN".to_string(), + doc, + severity: Severity::RuntimeError, + } + } + }, + Redundant { + overall_region, + branch_region, + index, + } => { + let doc = alloc.stack([ + alloc.concat([ + alloc.reflow("The "), + alloc.string(index.ordinal()), + alloc.reflow(" pattern is redundant:"), + ]), + alloc.region_with_subregion( + lines.convert_region(overall_region), + lines.convert_region(branch_region), + ), + alloc.reflow( + "Any value of this shape will be handled by \ + a previous pattern, so this one should be removed.", + ), + ]); + + Report { + filename, + title: "REDUNDANT PATTERN".to_string(), + doc, + severity: Severity::Warning, + } + } + } +} + +pub fn unhandled_patterns_to_doc_block<'b>( + alloc: &'b RocDocAllocator<'b>, + patterns: Vec, +) -> RocDocBuilder<'b> { + alloc + .vcat( + patterns + .into_iter() + .map(|v| exhaustive_pattern_to_doc(alloc, v)), + ) + .indent(4) + .annotate(Annotation::TypeBlock) +} + +fn exhaustive_pattern_to_doc<'b>( + alloc: &'b RocDocAllocator<'b>, + pattern: roc_exhaustive::Pattern, +) -> RocDocBuilder<'b> { + pattern_to_doc_help(alloc, pattern, false) +} + +const AFTER_TAG_INDENT: &str = " "; + +fn pattern_to_doc_help<'b>( + alloc: &'b RocDocAllocator<'b>, + pattern: roc_exhaustive::Pattern, + in_type_param: bool, +) -> RocDocBuilder<'b> { + use roc_exhaustive::Literal::*; + use roc_exhaustive::Pattern::*; + use roc_exhaustive::RenderAs; + + match pattern { + Anything => alloc.text("_"), + Literal(l) => match l { + Int(i) => alloc.text(i.to_string()), + U128(i) => alloc.text(i.to_string()), + Bit(true) => alloc.text("True"), + Bit(false) => alloc.text("False"), + Byte(b) => alloc.text(b.to_string()), + Float(f) => alloc.text(f.to_string()), + Decimal(d) => alloc.text(d.to_string()), + Str(s) => alloc.string(s.into()), + }, + Ctor(union, tag_id, args) => { + match union.render_as { + RenderAs::Guard => { + // #Guard + debug_assert_eq!( + union.alternatives[tag_id.0 as usize].name, + TagName::Global("#Guard".into()) + ); + debug_assert!(args.len() == 2); + let tag = pattern_to_doc_help(alloc, args[1].clone(), in_type_param); + alloc.concat([ + tag, + alloc.text(AFTER_TAG_INDENT), + alloc.text("(note the lack of an "), + alloc.keyword("if"), + alloc.text(" clause)"), + ]) + } + RenderAs::Record(field_names) => { + let mut arg_docs = Vec::with_capacity(args.len()); + + for (label, v) in field_names.into_iter().zip(args.into_iter()) { + match &v { + Anything => { + arg_docs.push(alloc.text(label.to_string())); + } + Literal(_) | Ctor(_, _, _) => { + arg_docs.push( + alloc + .text(label.to_string()) + .append(alloc.reflow(": ")) + .append(pattern_to_doc_help(alloc, v, false)), + ); + } + } + } + + alloc + .text("{ ") + .append(alloc.intersperse(arg_docs, alloc.reflow(", "))) + .append(" }") + } + RenderAs::Tag | RenderAs::Opaque => { + let has_args = !args.is_empty(); + let arg_docs = args + .into_iter() + .map(|v| pattern_to_doc_help(alloc, v, true)); + + let tag = &union.alternatives[tag_id.0 as usize]; + let tag_name = match union.render_as { + RenderAs::Tag => alloc.tag_name(tag.name.clone()), + RenderAs::Opaque => match tag.name { + TagName::Private(opaque) => alloc.wrapped_opaque_name(opaque), + _ => unreachable!(), + }, + _ => unreachable!(), + }; + + // We assume the alternatives are sorted. If not, this assert will trigger + debug_assert!(tag_id == tag.tag_id); + + let docs = std::iter::once(tag_name).chain(arg_docs); + + if in_type_param && has_args { + alloc + .text("(") + .append(alloc.intersperse(docs, alloc.space())) + .append(")") + } else { + alloc.intersperse(docs, alloc.space()) + } + } + } + } + } +} From f7e04490c09f1610352f3e17cd0bd73e25c95eae Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 22 Apr 2022 10:43:08 -0400 Subject: [PATCH 579/846] Remove stale comment --- compiler/constrain/src/expr.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/compiler/constrain/src/expr.rs b/compiler/constrain/src/expr.rs index 178c151a4c..2d39f196a6 100644 --- a/compiler/constrain/src/expr.rs +++ b/compiler/constrain/src/expr.rs @@ -742,8 +742,6 @@ pub fn constrain_expr( let total_cons = [when_body_con, result_con]; let branch_constraints = constraints.and_constraint(total_cons); - // exhautiveness checking happens when converting to mono::Expr - // ...for now constraints.exists([cond_var, *expr_var], branch_constraints) } Access { From 85e3373d8b34593eb06da19ebead5eb1f59e99de Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 22 Apr 2022 15:23:56 -0400 Subject: [PATCH 580/846] Move exhaustiveness checking to type checking --- compiler/can/src/builtins.rs | 6 ++ compiler/can/src/constraint.rs | 49 ++++++++-- compiler/can/src/effect_module.rs | 1 + compiler/can/src/exhaustive.rs | 32 +++++-- compiler/can/src/expr.rs | 47 +++++++++- compiler/can/src/traverse.rs | 1 + compiler/constrain/src/expr.rs | 49 ++++++---- compiler/exhaustive/src/lib.rs | 6 +- compiler/mono/src/ir.rs | 3 + compiler/solve/src/solve.rs | 143 ++++++++++++++++++++++++++++- compiler/solve/tests/solve_expr.rs | 2 +- compiler/types/src/subs.rs | 12 +++ compiler/types/src/types.rs | 3 + reporting/src/error/type.rs | 6 +- reporting/tests/test_reporting.rs | 80 ++++++---------- 15 files changed, 346 insertions(+), 94 deletions(-) diff --git a/compiler/can/src/builtins.rs b/compiler/can/src/builtins.rs index 446a32a194..d7de1a8748 100644 --- a/compiler/can/src/builtins.rs +++ b/compiler/can/src/builtins.rs @@ -4727,6 +4727,7 @@ fn result_map(symbol: Symbol, var_store: &mut VarStore) -> Def { region: Region::zero(), loc_cond: Box::new(no_region(Var(Symbol::ARG_1))), branches, + branches_cond_var: var_store.fresh(), }; defn( @@ -4824,6 +4825,7 @@ fn result_map_err(symbol: Symbol, var_store: &mut VarStore) -> Def { region: Region::zero(), loc_cond: Box::new(no_region(Var(Symbol::ARG_1))), branches, + branches_cond_var: var_store.fresh(), }; defn( @@ -4887,6 +4889,7 @@ fn result_with_default(symbol: Symbol, var_store: &mut VarStore) -> Def { region: Region::zero(), loc_cond: Box::new(no_region(Var(Symbol::ARG_1))), branches, + branches_cond_var: var_store.fresh(), }; defn( @@ -4964,6 +4967,7 @@ fn result_is_err(symbol: Symbol, var_store: &mut VarStore) -> Def { region: Region::zero(), loc_cond: Box::new(no_region(Var(Symbol::ARG_1))), branches, + branches_cond_var: var_store.fresh(), }; defn( @@ -5041,6 +5045,7 @@ fn result_is_ok(symbol: Symbol, var_store: &mut VarStore) -> Def { region: Region::zero(), loc_cond: Box::new(no_region(Var(Symbol::ARG_1))), branches, + branches_cond_var: var_store.fresh(), }; defn( @@ -5133,6 +5138,7 @@ fn result_after(symbol: Symbol, var_store: &mut VarStore) -> Def { region: Region::zero(), loc_cond: Box::new(no_region(Var(Symbol::ARG_1))), branches, + branches_cond_var: var_store.fresh(), }; defn( diff --git a/compiler/can/src/constraint.rs b/compiler/can/src/constraint.rs index e28ff8f229..6927268108 100644 --- a/compiler/can/src/constraint.rs +++ b/compiler/can/src/constraint.rs @@ -574,7 +574,7 @@ impl Constraints { Constraint::IsOpenType(_) => false, Constraint::IncludesTag(_) => false, Constraint::PatternPresence(_, _, _, _) => false, - Constraint::Exhaustive(_, _) => false, + Constraint::Exhaustive { .. } => false, } } @@ -603,10 +603,27 @@ impl Constraints { Constraint::Store(type_index, variable, string_index, line_number) } - pub fn exhaustive(&mut self, rows: SketchedRows, context: ExhaustiveContext) -> Constraint { - let rows_index = Index::push_new(&mut self.sketched_rows, rows); + pub fn exhaustive( + &mut self, + real_var: Variable, + real_region: Region, + real_category: Category, + expected_branches: Expected, + sketched_rows: SketchedRows, + context: ExhaustiveContext, + ) -> Constraint { + let real_category = Index::push_new(&mut self.categories, real_category); + let expected_branches = Index::push_new(&mut self.expectations, expected_branches); + let sketched_rows = Index::push_new(&mut self.sketched_rows, sketched_rows); - Constraint::Exhaustive(rows_index, context) + Constraint::Exhaustive { + real_var, + real_region, + real_category, + expected_branches, + sketched_rows, + context, + } } } @@ -652,7 +669,14 @@ pub enum Constraint { Index, Region, ), - Exhaustive(Index, ExhaustiveContext), + Exhaustive { + real_var: Variable, + real_region: Region, + real_category: Index, + expected_branches: Index>, + sketched_rows: Index, + context: ExhaustiveContext, + }, } #[derive(Debug, Clone, Copy, Default)] @@ -707,8 +731,19 @@ impl std::fmt::Debug for Constraint { arg0, arg1, arg2, arg3 ) } - Self::Exhaustive(arg0, arg1) => { - write!(f, "Exhaustive({:?}, {:?})", arg0, arg1) + Self::Exhaustive { + real_var: arg0, + real_region: arg1, + real_category: arg2, + expected_branches: arg3, + sketched_rows: arg4, + context: arg5, + } => { + write!( + f, + "Exhaustive({:?}, {:?}, {:?}, {:?}, {:?}, {:?})", + arg0, arg1, arg2, arg3, arg4, arg5 + ) } } } diff --git a/compiler/can/src/effect_module.rs b/compiler/can/src/effect_module.rs index d2f6e61c5d..e7ff812d5d 100644 --- a/compiler/can/src/effect_module.rs +++ b/compiler/can/src/effect_module.rs @@ -1366,6 +1366,7 @@ fn build_effect_loop_inner_body( region: Region::zero(), loc_cond: Box::new(force_thunk_call), branches, + branches_cond_var: var_store.fresh(), }; Expr::LetNonRec( diff --git a/compiler/can/src/exhaustive.rs b/compiler/can/src/exhaustive.rs index 060c688d06..e69f445cfd 100644 --- a/compiler/can/src/exhaustive.rs +++ b/compiler/can/src/exhaustive.rs @@ -6,6 +6,7 @@ use roc_exhaustive::{is_useful, Ctor, Error, Guard, Literal, Pattern, RenderAs, use roc_module::ident::{TagIdIntType, TagName}; use roc_region::all::{Loc, Region}; use roc_types::subs::{Content, FlatType, Subs, SubsFmtContent, Variable}; +use roc_types::types::AliasKind; pub use roc_exhaustive::Context as ExhaustiveContext; @@ -22,7 +23,7 @@ pub fn check( roc_exhaustive::check(overall_region, context, matrix) } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] enum SketchedPattern { Anything, Literal(Literal), @@ -52,14 +53,14 @@ impl SketchedPattern { } } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] struct SketchedRow { patterns: Vec, region: Region, guard: Guard, } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct SketchedRows { rows: Vec, overall_region: Region, @@ -155,13 +156,15 @@ fn sketch_pattern(var: Variable, pattern: &crate::pattern::Pattern) -> SketchedP ) } + // Treat this like a literal so we mark it as non-exhaustive + MalformedPattern(..) => SP::Literal(Literal::Byte(1)), + Underscore | Identifier(_) | AbilityMemberSpecialization { .. } | Shadowed(..) | OpaqueNotInScope(..) - | UnsupportedPattern(..) - | MalformedPattern(..) => SP::Anything, + | UnsupportedPattern(..) => SP::Anything, } } @@ -232,7 +235,7 @@ pub fn sketch_rows(target_var: Variable, region: Region, patterns: &[WhenBranch] let row = SketchedRow { patterns, - region, + region: loc_pat.region, guard, }; rows.push(row); @@ -285,7 +288,7 @@ fn convert_tag(subs: &Subs, whole_var: Variable, this_tag: &TagName) -> (Union, use {Content::*, FlatType::*}; - match content { + match dealias_tag(subs, content) { Structure(TagUnion(tags, ext) | RecursiveTagUnion(_, tags, ext)) => { let (sorted_tags, ext) = tags.sorted_iterator_and_ext(subs, *ext); @@ -335,3 +338,18 @@ fn convert_tag(subs: &Subs, whole_var: Variable, this_tag: &TagName) -> (Union, ), } } + +pub fn dealias_tag<'a>(subs: &'a Subs, content: &'a Content) -> &'a Content { + use Content::*; + let mut result = content; + loop { + match result { + Alias(_, _, real_var, AliasKind::Structural) + | RecursionVar { + structure: real_var, + .. + } => result = subs.get_content_without_compacting(*real_var), + _ => return result, + } + } +} diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index 15301c832a..19d1b946d3 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -19,7 +19,7 @@ use roc_parse::pattern::PatternType::*; use roc_problem::can::{PrecedenceProblem, Problem, RuntimeError}; use roc_region::all::{Loc, Region}; use roc_types::subs::{VarStore, Variable}; -use roc_types::types::{Alias, LambdaSet, Type}; +use roc_types::types::{Alias, Category, LambdaSet, Type}; use std::fmt::{Debug, Display}; use std::{char, u32}; @@ -89,6 +89,7 @@ pub enum Expr { region: Region, loc_cond: Box>, branches: Vec, + branches_cond_var: Variable, }, If { cond_var: Variable, @@ -193,6 +194,47 @@ pub enum Expr { // Compiles, but will crash if reached RuntimeError(RuntimeError), } + +impl Expr { + pub fn category(&self) -> Category { + match self { + Self::Num(..) => Category::Num, + Self::Int(..) => Category::Int, + Self::Float(..) => Category::Float, + Self::Str(..) => Category::Str, + Self::SingleQuote(..) => Category::Character, + Self::List { .. } => Category::List, + &Self::Var(sym) => Category::Lookup(sym), + Self::When { .. } => Category::When, + Self::If { .. } => Category::If, + Self::LetRec(_, expr, _) => expr.value.category(), + Self::LetNonRec(_, expr, _) => expr.value.category(), + &Self::Call(_, _, called_via) => Category::CallResult(None, called_via), + &Self::RunLowLevel { op, .. } => Category::LowLevelOpResult(op), + Self::ForeignCall { .. } => Category::ForeignCall, + Self::Closure(..) => Category::Lambda, + Self::Record { .. } => Category::Record, + Self::EmptyRecord => Category::Record, + Self::Access { field, .. } => Category::Access(field.clone()), + Self::Accessor(data) => Category::Accessor(data.field.clone()), + Self::Update { .. } => Category::Record, + Self::Tag { + name, arguments, .. + } => Category::TagApply { + tag_name: name.clone(), + args_count: arguments.len(), + }, + Self::ZeroArgumentTag { name, .. } => Category::TagApply { + tag_name: name.clone(), + args_count: 0, + }, + &Self::OpaqueRef { name, .. } => Category::OpaqueWrap(name), + Self::Expect(..) => Category::Expect, + Self::RuntimeError(..) => Category::Unknown, + } + } +} + #[derive(Clone, Debug)] pub struct ClosureData { pub function_type: Variable, @@ -782,6 +824,7 @@ pub fn canonicalize_expr<'a>( region, loc_cond: Box::new(can_cond), branches: can_branches, + branches_cond_var: var_store.fresh(), }; (expr, output) @@ -1298,6 +1341,7 @@ pub fn inline_calls(var_store: &mut VarStore, scope: &mut Scope, expr: Expr) -> region, loc_cond, branches, + branches_cond_var, } => { let loc_cond = Box::new(Loc { region: loc_cond.region, @@ -1333,6 +1377,7 @@ pub fn inline_calls(var_store: &mut VarStore, scope: &mut Scope, expr: Expr) -> region, loc_cond, branches: new_branches, + branches_cond_var, } } If { diff --git a/compiler/can/src/traverse.rs b/compiler/can/src/traverse.rs index a1f338c4ca..d45f7f3a87 100644 --- a/compiler/can/src/traverse.rs +++ b/compiler/can/src/traverse.rs @@ -65,6 +65,7 @@ fn walk_expr(visitor: &mut V, expr: &Expr) { loc_cond, branches, region: _, + branches_cond_var: _, } => { walk_when(visitor, *cond_var, *expr_var, loc_cond, branches); } diff --git a/compiler/constrain/src/expr.rs b/compiler/constrain/src/expr.rs index 2d39f196a6..ddb094cf38 100644 --- a/compiler/constrain/src/expr.rs +++ b/compiler/constrain/src/expr.rs @@ -580,17 +580,18 @@ pub fn constrain_expr( } } When { - cond_var, + cond_var: real_cond_var, expr_var, loc_cond, branches, + branches_cond_var, .. } => { - let cond_var = *cond_var; - let cond_type = Variable(cond_var); + let branches_cond_var = *branches_cond_var; + let branches_cond_type = Variable(branches_cond_var); - let branch_var = *expr_var; - let branch_type = Variable(branch_var); + let body_var = *expr_var; + let body_type = Variable(body_var); let branches_region = { debug_assert!(!branches.is_empty()); @@ -615,13 +616,13 @@ pub fn constrain_expr( index, region: ann_source.region(), }, - branch_type.clone(), + body_type.clone(), ) } _ => ForReason( Reason::WhenBranch { index }, - branch_type.clone(), + body_type.clone(), branch_region, ), }; @@ -659,7 +660,7 @@ pub fn constrain_expr( index: HumanIndex::zero_based(index), sub_pattern, }, - cond_type.clone(), + branches_cond_type.clone(), sub_region, ) }; @@ -703,15 +704,16 @@ pub fn constrain_expr( // After solving the condition variable with what's expected from the branch patterns, // check it against the condition expression. - // TODO: when we have exhaustiveness checking during the typechecking phase, perform - // exhaustiveness checking when this expectation fails. That will produce better error - // messages. - let expr_con = constrain_expr( + // + // First, solve the condition type. + let real_cond_var = *real_cond_var; + let real_cond_type = Type::Variable(real_cond_var); + let cond_constraint = constrain_expr( constraints, env, loc_cond.region, &loc_cond.value, - Expected::ForReason(Reason::WhenBranches, cond_type, branches_region), + Expected::NoExpectation(real_cond_type), ); // branch_cons.extend(pattern_cons); // branch_constraints.push(constraints.and_constraint(pattern_cons)); @@ -719,10 +721,18 @@ pub fn constrain_expr( // total_cons.push(expr_con); pattern_cons.push(expr_con); - let sketched_rows = sketch_rows(cond_var, branches_region, &branches); - let exhaustiveness_constraint = - constraints.exhaustive(sketched_rows, ExhaustiveContext::BadCase); - pattern_cons.push(exhaustiveness_constraint); + // Now check the condition against the type expected by the branches. + let sketched_rows = sketch_rows(real_cond_var, branches_region, &branches); + // let exhaustive_reason = Reason::Exhaustive(sketched_rows, ExhaustiveContext::BadCase); + let cond_matches_branches_constraint = constraints.exhaustive( + real_cond_var, + loc_cond.region, + loc_cond.value.category(), + Expected::ForReason(Reason::WhenBranches, branches_cond_type, branches_region), + sketched_rows, + ExhaustiveContext::BadCase, + ); + pattern_cons.push(cond_matches_branches_constraint); // Solve all the pattern constraints together, introducing variables in the pattern as // need be before solving the bodies. @@ -742,7 +752,10 @@ pub fn constrain_expr( let total_cons = [when_body_con, result_con]; let branch_constraints = constraints.and_constraint(total_cons); - constraints.exists([cond_var, *expr_var], branch_constraints) + constraints.exists( + [branches_cond_var, real_cond_var, *expr_var], + branch_constraints, + ) } Access { record_var, diff --git a/compiler/exhaustive/src/lib.rs b/compiler/exhaustive/src/lib.rs index 19638404a4..a01e0a7033 100644 --- a/compiler/exhaustive/src/lib.rs +++ b/compiler/exhaustive/src/lib.rs @@ -72,7 +72,7 @@ pub enum Pattern { Ctor(Union, TagId, std::vec::Vec), } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub enum Literal { Int(i128), U128(u128), @@ -96,14 +96,14 @@ pub enum Error { }, } -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum Context { BadArg, BadDestruct, BadCase, } -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum Guard { HasGuard, NoGuard, diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index f98b26370f..4f4b2accfe 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -2091,6 +2091,7 @@ fn pattern_to_when<'a>( value: body, guard: None, }], + branches_cond_var: pattern_var, }; (symbol, Loc::at_zero(wrapped_body)) @@ -3753,6 +3754,7 @@ pub fn with_hole<'a>( region, loc_cond, branches, + branches_cond_var: _, } => { let cond_symbol = possible_reuse_symbol(env, procs, &loc_cond.value); @@ -5443,6 +5445,7 @@ pub fn from_can<'a>( region, loc_cond, branches, + branches_cond_var: _, } => { let cond_symbol = possible_reuse_symbol(env, procs, &loc_cond.value); diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index e25c82dded..3ce187c1e7 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -1197,12 +1197,116 @@ fn solve( } } } - Exhaustive(rows_index, context) => { - let sketched_rows = constraints.sketched_rows[rows_index.index()].clone(); + &Exhaustive { + real_var, + real_region, + real_category, + expected_branches, + sketched_rows, + context, + } => { + // A few cases: + // 1. Either condition or branch types already have a type error. In this case just + // propogate it. + // 2. Types are correct, but there are redundancies. In this case we want + // exhaustiveness checking to pull those out. + // 3. Condition and branch types are "almost equal", that is one or the other is + // only missing a few more tags. In this case we want to run + // exhaustiveness checking both ways, to see which one is missing tags. + // 4. Condition and branch types aren't "almost equal", this is just a normal type + // error. - let checked = roc_can::exhaustive::check(&subs, sketched_rows, *context); - if let Err(errors) = checked { - problems.extend(errors.into_iter().map(TypeError::Exhaustive)); + let expected_branches = &constraints.expectations[expected_branches.index()]; + let branches_var = + type_to_var(subs, rank, pools, aliases, expected_branches.get_type_ref()); + + let real_content = subs.get_content_without_compacting(real_var); + let branches_content = subs.get_content_without_compacting(branches_var); + let already_have_error = match (real_content, branches_content) { + (Content::Error | Content::Structure(FlatType::Erroneous(_)), _) => true, + (_, Content::Error | Content::Structure(FlatType::Erroneous(_))) => true, + _ => false, + }; + + let snapshot = subs.snapshot(); + let outcome = unify(subs, real_var, branches_var, Mode::EQ); + + let should_check_exhaustiveness; + match outcome { + Success { + vars, + must_implement_ability, + } => { + subs.commit_snapshot(snapshot); + + introduce(subs, rank, pools, &vars); + if !must_implement_ability.is_empty() { + internal_error!("Didn't expect ability vars to land here"); + } + + // Case 1: unify error types, but don't check exhaustiveness. + // Case 2: run exhaustiveness to check for redundant branches. + should_check_exhaustiveness = !already_have_error; + } + Failure(..) => { + // Rollback and check for almost-equality. + subs.rollback_to(snapshot); + + let almost_eq_snapshot = subs.snapshot(); + // TODO: turn this on for bidirectional exhaustiveness checking + // open_tag_union(subs, real_var); + open_tag_union(subs, branches_var); + let almost_eq = matches!( + unify(subs, real_var, branches_var, Mode::EQ), + Success { .. } + ); + + subs.rollback_to(almost_eq_snapshot); + + if almost_eq { + // Case 3: almost equal, check exhaustiveness. + should_check_exhaustiveness = true; + } else { + // Case 4: incompatible types, report type error. + // Re-run first failed unification to get the type diff. + match unify(subs, real_var, branches_var, Mode::EQ) { + Failure(vars, actual_type, expected_type, _bad_impls) => { + introduce(subs, rank, pools, &vars); + + let real_category = + constraints.categories[real_category.index()].clone(); + let problem = TypeError::BadExpr( + real_region, + real_category, + actual_type, + expected_branches.replace_ref(expected_type), + ); + + problems.push(problem); + should_check_exhaustiveness = false; + } + _ => internal_error!("Must be failure"), + } + } + } + BadType(vars, problem) => { + subs.commit_snapshot(snapshot); + + introduce(subs, rank, pools, &vars); + + problems.push(TypeError::BadType(problem)); + + should_check_exhaustiveness = false; + } + } + + let sketched_rows = constraints.sketched_rows[sketched_rows.index()].clone(); + + if should_check_exhaustiveness { + let checked = roc_can::exhaustive::check(&subs, sketched_rows, context); + if let Err(errors) = checked { + problems.extend(errors.into_iter().map(TypeError::Exhaustive)); + } } state @@ -1213,6 +1317,35 @@ fn solve( state } +fn open_tag_union(subs: &mut Subs, var: Variable) { + let mut stack = vec![var]; + while let Some(var) = stack.pop() { + use {Content::*, FlatType::*}; + + let mut desc = subs.get(var); + if let Structure(TagUnion(tags, ext)) = desc.content { + if let Structure(EmptyTagUnion) = subs.get_content_without_compacting(ext) { + let new_ext = subs.fresh_unnamed_flex_var(); + subs.set_rank(new_ext, desc.rank); + let new_union = Structure(TagUnion(tags, new_ext)); + desc.content = new_union; + subs.set(var, desc); + } + + // Also open up all nested tag unions. + let all_vars = tags.variables().into_iter(); + stack.extend(all_vars.flat_map(|slice| subs[slice]).map(|var| subs[var])); + } + + // Today, an "open" constraint doesn't affect any types + // other than tag unions. Recursive tag unions are constructed + // at a later time (during occurs checks after tag unions are + // resolved), so that's not handled here either. + // NB: Handle record types here if we add presence constraints + // to their type inference as well. + } +} + /// If a symbol claims to specialize an ability member, check that its solved type in fact /// does specialize the ability, and record the specialization. #[allow(clippy::too_many_arguments)] diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index 6a5d90d3c7..76013dee4c 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -6163,7 +6163,7 @@ mod solve_expr { ), &[ "ob : Bool", - "ob : [ False, True ]", + "ob : Bool", "True : [ False, True ]", "False : [ False, True ]", ], diff --git a/compiler/types/src/subs.rs b/compiler/types/src/subs.rs index 1d9a181c67..f9c129693a 100644 --- a/compiler/types/src/subs.rs +++ b/compiler/types/src/subs.rs @@ -2118,6 +2118,18 @@ impl Content { self } + + pub fn unroll_structural_alias<'a>(&'a self, subs: &'a Subs) -> &'a Self { + let mut result = self; + loop { + match result { + Self::Alias(_, _, real_var, AliasKind::Structural) => { + result = subs.get_content_without_compacting(*real_var) + } + _ => return result, + } + } + } } #[derive(Clone, Copy, Debug)] diff --git a/compiler/types/src/types.rs b/compiler/types/src/types.rs index b9c3a9a261..96994d3d20 100644 --- a/compiler/types/src/types.rs +++ b/compiler/types/src/types.rs @@ -1815,6 +1815,9 @@ pub enum Category { DefaultValue(Lowercase), // for setting optional fields AbilityMemberSpecialization(Symbol), + + Expect, + Unknown, } #[derive(Debug, Clone, PartialEq, Eq)] diff --git a/reporting/src/error/type.rs b/reporting/src/error/type.rs index 97a0d27a24..71230ab115 100644 --- a/reporting/src/error/type.rs +++ b/reporting/src/error/type.rs @@ -1528,7 +1528,7 @@ fn format_category<'b>( alloc.concat([this_is, alloc.text(" an uniqueness attribute")]), alloc.text(" of type:"), ), - Storage(_file, _line) => ( + Storage(..) | Unknown => ( alloc.concat([this_is, alloc.text(" a value")]), alloc.text(" of type:"), ), @@ -1540,6 +1540,10 @@ fn format_category<'b>( alloc.concat([this_is, alloc.text(" a declared specialization")]), alloc.text(" of type:"), ), + Expect => ( + alloc.concat([this_is, alloc.text(" an expectation")]), + alloc.text(" of type:"), + ), } } diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index a918bdeda0..c8f1741887 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -1197,6 +1197,7 @@ mod test_reporting { when 1 is 2 -> "foo" 3 -> {} + _ -> "" "# ), indoc!( @@ -1205,10 +1206,10 @@ mod test_reporting { The 2nd branch of this `when` does not match all the previous branches: - 1│ when 1 is - 2│ 2 -> "foo" - 3│ 3 -> {} - ^^ + 1│ when 1 is + 2│ 2 -> "foo" + 3│> 3 -> {} + 4│ _ -> "" The 2nd branch is a record of type: @@ -1788,7 +1789,7 @@ mod test_reporting { indoc!( r#" when { foo: 1 } is - { foo: 2 } -> foo + { foo: _ } -> foo "# ), indoc!( @@ -1797,7 +1798,7 @@ mod test_reporting { I cannot find a `foo` value - 2│ { foo: 2 } -> foo + 2│ { foo: _ } -> foo ^^^ Did you mean one of these? @@ -2791,26 +2792,18 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ + ── UNSAFE PATTERN ──────────────────────────────────────── /code/proj/Main.roc ─ - The branches of this `when` expression don't match the condition: + This `when` does not cover all the possibilities: 4│> when x is - 5│ Red -> 3 + 5│> Red -> 3 - This `x` value is a: + Other possibilities include: - [ Green, Red ] + Green - But the branch patterns have type: - - [ Red ] - - The branches must be cases of the `when` condition's type! - - Tip: Looks like the branches are missing coverage of the `Green` tag. - - Tip: Maybe you need to add a catch-all branch, like `_`? + I would have to crash if I saw one of those! Add branches for them! "# ), ) @@ -2831,27 +2824,19 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ + ── UNSAFE PATTERN ──────────────────────────────────────── /code/proj/Main.roc ─ - The branches of this `when` expression don't match the condition: + This `when` does not cover all the possibilities: 4│> when x is - 5│ Red -> 0 - 6│ Green -> 1 + 5│> Red -> 0 + 6│> Green -> 1 - This `x` value is a: + Other possibilities include: - [ Blue, Green, Red ] + Blue - But the branch patterns have type: - - [ Green, Red ] - - The branches must be cases of the `when` condition's type! - - Tip: Looks like the branches are missing coverage of the `Blue` tag. - - Tip: Maybe you need to add a catch-all branch, like `_`? + I would have to crash if I saw one of those! Add branches for them! "# ), ) @@ -2872,27 +2857,20 @@ mod test_reporting { ), indoc!( r#" - ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ + ── UNSAFE PATTERN ──────────────────────────────────────── /code/proj/Main.roc ─ - The branches of this `when` expression don't match the condition: + This `when` does not cover all the possibilities: 5│> when x is - 6│ NotAsked -> 3 + 6│> NotAsked -> 3 - This `x` value is a: + Other possibilities include: - [ Failure I64, Loading, NotAsked, Success Str ] + Failure _ + Loading + Success _ - But the branch patterns have type: - - [ NotAsked ] - - The branches must be cases of the `when` condition's type! - - Tip: Looks like the branches are missing coverage of the - `Success`, `Failure` and `Loading` tags. - - Tip: Maybe you need to add a catch-all branch, like `_`? + I would have to crash if I saw one of those! Add branches for them! "# ), ) @@ -2955,7 +2933,7 @@ mod test_reporting { Other possibilities include: - { a: Just _, b } + { a: Just _ } I would have to crash if I saw one of those! Add branches for them! "# From 372b12bec96a4f1d2ebd565972b3894f16ec56d4 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 22 Apr 2022 15:27:08 -0400 Subject: [PATCH 581/846] Typo --- compiler/solve/src/solve.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index 3ce187c1e7..6784a10082 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -1207,7 +1207,7 @@ fn solve( } => { // A few cases: // 1. Either condition or branch types already have a type error. In this case just - // propogate it. + // propagate it. // 2. Types are correct, but there are redundancies. In this case we want // exhaustiveness checking to pull those out. // 3. Condition and branch types are "almost equal", that is one or the other is From 7d908dc99c763e377062895ac6789bd5877fc123 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 22 Apr 2022 15:28:06 -0400 Subject: [PATCH 582/846] Remove unused line --- compiler/constrain/src/expr.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/constrain/src/expr.rs b/compiler/constrain/src/expr.rs index ddb094cf38..4cc62269f5 100644 --- a/compiler/constrain/src/expr.rs +++ b/compiler/constrain/src/expr.rs @@ -723,7 +723,6 @@ pub fn constrain_expr( // Now check the condition against the type expected by the branches. let sketched_rows = sketch_rows(real_cond_var, branches_region, &branches); - // let exhaustive_reason = Reason::Exhaustive(sketched_rows, ExhaustiveContext::BadCase); let cond_matches_branches_constraint = constraints.exhaustive( real_cond_var, loc_cond.region, From 17e7b10267197022dec6767319921031face3e90 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 22 Apr 2022 15:30:55 -0400 Subject: [PATCH 583/846] Fought against clippy and lost --- compiler/constrain/src/expr.rs | 2 +- compiler/mono/src/ir.rs | 4 ++-- compiler/solve/src/solve.rs | 17 +++++++++++------ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/compiler/constrain/src/expr.rs b/compiler/constrain/src/expr.rs index 4cc62269f5..86c01a56c2 100644 --- a/compiler/constrain/src/expr.rs +++ b/compiler/constrain/src/expr.rs @@ -722,7 +722,7 @@ pub fn constrain_expr( pattern_cons.push(expr_con); // Now check the condition against the type expected by the branches. - let sketched_rows = sketch_rows(real_cond_var, branches_region, &branches); + let sketched_rows = sketch_rows(real_cond_var, branches_region, branches); let cond_matches_branches_constraint = constraints.exhaustive( real_cond_var, loc_cond.region, diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 4f4b2accfe..1a78f24f3c 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -5847,7 +5847,7 @@ fn to_opt_branches<'a>( Ok((mono_pattern, assignments)) => { loc_branches.push(( Loc::at(loc_pattern.region, mono_pattern.clone()), - exhaustive_guard.clone(), + exhaustive_guard, )); let mut loc_expr = when_branch.value.clone(); @@ -5877,7 +5877,7 @@ fn to_opt_branches<'a>( Err(runtime_error) => { loc_branches.push(( Loc::at(loc_pattern.region, Pattern::Underscore), - exhaustive_guard.clone(), + exhaustive_guard, )); // TODO remove clone? diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index 6784a10082..7b9d8d65ef 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -1222,11 +1222,16 @@ fn solve( let real_content = subs.get_content_without_compacting(real_var); let branches_content = subs.get_content_without_compacting(branches_var); - let already_have_error = match (real_content, branches_content) { - (Content::Error | Content::Structure(FlatType::Erroneous(_)), _) => true, - (_, Content::Error | Content::Structure(FlatType::Erroneous(_))) => true, - _ => false, - }; + let already_have_error = matches!( + (real_content, branches_content), + ( + Content::Error | Content::Structure(FlatType::Erroneous(_)), + _ + ) | ( + _, + Content::Error | Content::Structure(FlatType::Erroneous(_)) + ) + ); let snapshot = subs.snapshot(); let outcome = unify(subs, real_var, branches_var, Mode::EQ); @@ -1303,7 +1308,7 @@ fn solve( let sketched_rows = constraints.sketched_rows[sketched_rows.index()].clone(); if should_check_exhaustiveness { - let checked = roc_can::exhaustive::check(&subs, sketched_rows, context); + let checked = roc_can::exhaustive::check(subs, sketched_rows, context); if let Err(errors) = checked { problems.extend(errors.into_iter().map(TypeError::Exhaustive)); } From 1de67fe19a3b93dcb7c88cef127b082affc0f6ad Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 22 Apr 2022 16:00:42 -0400 Subject: [PATCH 584/846] Nested Eq constraint in Exhaustive behind SoA --- compiler/can/src/constraint.rs | 67 +++++++++++++--------------------- compiler/solve/src/solve.rs | 21 ++++++----- 2 files changed, 38 insertions(+), 50 deletions(-) diff --git a/compiler/can/src/constraint.rs b/compiler/can/src/constraint.rs index 6927268108..7a8857a413 100644 --- a/compiler/can/src/constraint.rs +++ b/compiler/can/src/constraint.rs @@ -21,6 +21,7 @@ pub struct Constraints { pub includes_tags: Vec, pub strings: Vec<&'static str>, pub sketched_rows: Vec, + pub eq: Vec, } impl Default for Constraints { @@ -43,6 +44,7 @@ impl Constraints { let includes_tags = Vec::new(); let strings = Vec::new(); let sketched_rows = Vec::new(); + let eq = Vec::new(); types.extend([ Type::EmptyRec, @@ -94,6 +96,7 @@ impl Constraints { includes_tags, strings, sketched_rows, + eq, } } @@ -229,7 +232,7 @@ impl Constraints { let expected_index = Index::push_new(&mut self.expectations, expected); let category_index = Self::push_category(self, category); - Constraint::Eq(type_index, expected_index, category_index, region) + Constraint::Eq(Eq(type_index, expected_index, category_index, region)) } #[inline(always)] @@ -244,7 +247,7 @@ impl Constraints { let expected_index = Index::push_new(&mut self.expectations, expected); let category_index = Self::push_category(self, category); - Constraint::Eq(type_index, expected_index, category_index, region) + Constraint::Eq(Eq(type_index, expected_index, category_index, region)) } #[inline(always)] @@ -260,17 +263,17 @@ impl Constraints { let expected_index = Index::push_new(&mut self.expectations, expected); let category_index = Self::push_category(self, category); - let equal = Constraint::Eq(type_index, expected_index, category_index, region); + let equal = Constraint::Eq(Eq(type_index, expected_index, category_index, region)); let storage_type_index = Self::push_type_variable(storage_var); let storage_category = Category::Storage(std::file!(), std::line!()); let storage_category_index = Self::push_category(self, storage_category); - let storage = Constraint::Eq( + let storage = Constraint::Eq(Eq( storage_type_index, expected_index, storage_category_index, region, - ); + )); self.and_constraint([equal, storage]) } @@ -612,31 +615,31 @@ impl Constraints { sketched_rows: SketchedRows, context: ExhaustiveContext, ) -> Constraint { + let real_var = Self::push_type_variable(real_var); let real_category = Index::push_new(&mut self.categories, real_category); let expected_branches = Index::push_new(&mut self.expectations, expected_branches); + let equality = Eq(real_var, expected_branches, real_category, real_region); + let equality = Index::push_new(&mut self.eq, equality); let sketched_rows = Index::push_new(&mut self.sketched_rows, sketched_rows); - Constraint::Exhaustive { - real_var, - real_region, - real_category, - expected_branches, - sketched_rows, - context, - } + Constraint::Exhaustive(equality, sketched_rows, context) } } roc_error_macros::assert_sizeof_default!(Constraint, 3 * 8); +roc_error_macros::assert_sizeof_aarch64!(Constraint, 3 * 8); + +#[derive(Clone, Copy, Debug)] +pub struct Eq( + pub EitherIndex, + pub Index>, + pub Index, + pub Region, +); #[derive(Clone, Copy)] pub enum Constraint { - Eq( - EitherIndex, - Index>, - Index, - Region, - ), + Eq(Eq), Store( EitherIndex, Variable, @@ -669,14 +672,7 @@ pub enum Constraint { Index, Region, ), - Exhaustive { - real_var: Variable, - real_region: Region, - real_category: Index, - expected_branches: Index>, - sketched_rows: Index, - context: ExhaustiveContext, - }, + Exhaustive(Index, Index, ExhaustiveContext), } #[derive(Debug, Clone, Copy, Default)] @@ -706,7 +702,7 @@ pub struct IncludesTag { impl std::fmt::Debug for Constraint { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Self::Eq(arg0, arg1, arg2, arg3) => { + Self::Eq(Eq(arg0, arg1, arg2, arg3)) => { write!(f, "Eq({:?}, {:?}, {:?}, {:?})", arg0, arg1, arg2, arg3) } Self::Store(arg0, arg1, arg2, arg3) => { @@ -731,19 +727,8 @@ impl std::fmt::Debug for Constraint { arg0, arg1, arg2, arg3 ) } - Self::Exhaustive { - real_var: arg0, - real_region: arg1, - real_category: arg2, - expected_branches: arg3, - sketched_rows: arg4, - context: arg5, - } => { - write!( - f, - "Exhaustive({:?}, {:?}, {:?}, {:?}, {:?}, {:?})", - arg0, arg1, arg2, arg3, arg4, arg5 - ) + Self::Exhaustive(arg0, arg1, arg2) => { + write!(f, "Exhaustive({:?}, {:?}, {:?})", arg0, arg1, arg2) } } } diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index 7b9d8d65ef..72930cd335 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -776,7 +776,7 @@ fn solve( copy } - Eq(type_index, expectation_index, category_index, region) => { + Eq(roc_can::constraint::Eq(type_index, expectation_index, category_index, region)) => { let category = &constraints.categories[category_index.index()]; let actual = @@ -1197,14 +1197,7 @@ fn solve( } } } - &Exhaustive { - real_var, - real_region, - real_category, - expected_branches, - sketched_rows, - context, - } => { + &Exhaustive(eq, sketched_rows, context) => { // A few cases: // 1. Either condition or branch types already have a type error. In this case just // propagate it. @@ -1216,6 +1209,16 @@ fn solve( // 4. Condition and branch types aren't "almost equal", this is just a normal type // error. + let roc_can::constraint::Eq( + real_var, + expected_branches, + real_category, + real_region, + ) = constraints.eq[eq.index()]; + + let real_var = + either_type_index_to_var(constraints, subs, rank, pools, aliases, real_var); + let expected_branches = &constraints.expectations[expected_branches.index()]; let branches_var = type_to_var(subs, rank, pools, aliases, expected_branches.get_type_ref()); From fe8eb38d8960c0e8c901d6eecdcbbe934fc72263 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 22 Apr 2022 16:12:04 -0400 Subject: [PATCH 585/846] Catch non-exhaustive open unions --- reporting/src/error/type.rs | 21 +++++++++++++++----- reporting/tests/test_reporting.rs | 33 +++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/reporting/src/error/type.rs b/reporting/src/error/type.rs index 71230ab115..d52f69bfdc 100644 --- a/reporting/src/error/type.rs +++ b/reporting/src/error/type.rs @@ -3691,12 +3691,18 @@ fn pattern_to_doc_help<'b>( .append(" }") } RenderAs::Tag | RenderAs::Opaque => { - let has_args = !args.is_empty(); - let arg_docs = args - .into_iter() - .map(|v| pattern_to_doc_help(alloc, v, true)); - let tag = &union.alternatives[tag_id.0 as usize]; + match &tag.name { + TagName::Global(name) if name.as_str() == "#Open" => { + return pattern_to_doc_help( + alloc, + roc_exhaustive::Pattern::Anything, + in_type_param, + ) + } + _ => {} + } + let tag_name = match union.render_as { RenderAs::Tag => alloc.tag_name(tag.name.clone()), RenderAs::Opaque => match tag.name { @@ -3706,6 +3712,11 @@ fn pattern_to_doc_help<'b>( _ => unreachable!(), }; + let has_args = !args.is_empty(); + let arg_docs = args + .into_iter() + .map(|v| pattern_to_doc_help(alloc, v, true)); + // We assume the alternatives are sorted. If not, this assert will trigger debug_assert!(tag_id == tag.tag_id); diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index c8f1741887..76ec6596f8 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -9881,4 +9881,37 @@ I need all branches in an `if` to have the same type! "", ) } + + #[test] + fn not_enough_cases_for_open_union() { + new_report_problem_as( + "branches_have_more_cases_than_condition", + indoc!( + r#" + foo : [A, B]a -> Str + foo = \it -> + when it is + A -> "" + foo + "# + ), + indoc!( + r#" + ── UNSAFE PATTERN ──────────────────────────────────────── /code/proj/Main.roc ─ + + This `when` does not cover all the possibilities: + + 6│> when it is + 7│> A -> "" + + Other possibilities include: + + B + _ + + I would have to crash if I saw one of those! Add branches for them! + "# + ), + ) + } } From 03deec23c363e81b882dfc613282ed47000ed96f Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 22 Apr 2022 16:16:21 -0400 Subject: [PATCH 586/846] Constants --- compiler/can/src/exhaustive.rs | 7 +++++-- compiler/types/src/subs.rs | 12 ------------ reporting/src/error/type.rs | 5 +++-- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/compiler/can/src/exhaustive.rs b/compiler/can/src/exhaustive.rs index e69f445cfd..235e347772 100644 --- a/compiler/can/src/exhaustive.rs +++ b/compiler/can/src/exhaustive.rs @@ -10,6 +10,9 @@ use roc_types::types::AliasKind; pub use roc_exhaustive::Context as ExhaustiveContext; +pub const GUARD_CTOR: &'static str = "#Guard"; +pub const NONEXHAUSIVE_CTOR: &'static str = "#Open"; + pub fn check( subs: &Subs, sketched_rows: SketchedRows, @@ -215,7 +218,7 @@ pub fn sketch_rows(target_var: Variable, region: Region, patterns: &[WhenBranch] render_as: RenderAs::Guard, alternatives: vec![Ctor { tag_id, - name: TagName::Global("#Guard".into()), + name: TagName::Global(GUARD_CTOR.into()), arity: 2, }], }; @@ -298,7 +301,7 @@ fn convert_tag(subs: &Subs, whole_var: Variable, this_tag: &TagName) -> (Union, // be matched unless there's an `Anything` pattern. let opt_openness_tag = match subs.get_content_without_compacting(ext) { FlexVar(_) | RigidVar(_) => { - let openness_tag = TagName::Global("#Open".into()); + let openness_tag = TagName::Global(NONEXHAUSIVE_CTOR.into()); num_tags += 1; Some((openness_tag, &[] as _)) } diff --git a/compiler/types/src/subs.rs b/compiler/types/src/subs.rs index f9c129693a..1d9a181c67 100644 --- a/compiler/types/src/subs.rs +++ b/compiler/types/src/subs.rs @@ -2118,18 +2118,6 @@ impl Content { self } - - pub fn unroll_structural_alias<'a>(&'a self, subs: &'a Subs) -> &'a Self { - let mut result = self; - loop { - match result { - Self::Alias(_, _, real_var, AliasKind::Structural) => { - result = subs.get_content_without_compacting(*real_var) - } - _ => return result, - } - } - } } #[derive(Clone, Copy, Debug)] diff --git a/reporting/src/error/type.rs b/reporting/src/error/type.rs index d52f69bfdc..3d1d6f58d6 100644 --- a/reporting/src/error/type.rs +++ b/reporting/src/error/type.rs @@ -3632,6 +3632,7 @@ fn pattern_to_doc_help<'b>( pattern: roc_exhaustive::Pattern, in_type_param: bool, ) -> RocDocBuilder<'b> { + use roc_can::exhaustive::{GUARD_CTOR, NONEXHAUSIVE_CTOR}; use roc_exhaustive::Literal::*; use roc_exhaustive::Pattern::*; use roc_exhaustive::RenderAs; @@ -3654,7 +3655,7 @@ fn pattern_to_doc_help<'b>( // #Guard debug_assert_eq!( union.alternatives[tag_id.0 as usize].name, - TagName::Global("#Guard".into()) + TagName::Global(GUARD_CTOR.into()) ); debug_assert!(args.len() == 2); let tag = pattern_to_doc_help(alloc, args[1].clone(), in_type_param); @@ -3693,7 +3694,7 @@ fn pattern_to_doc_help<'b>( RenderAs::Tag | RenderAs::Opaque => { let tag = &union.alternatives[tag_id.0 as usize]; match &tag.name { - TagName::Global(name) if name.as_str() == "#Open" => { + TagName::Global(name) if name.as_str() == NONEXHAUSIVE_CTOR => { return pattern_to_doc_help( alloc, roc_exhaustive::Pattern::Anything, From 1ff18af8f630beadcff8833b0a91985723aa3b3a Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 22 Apr 2022 17:53:10 -0400 Subject: [PATCH 587/846] Nothing is static in this world --- compiler/can/src/exhaustive.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/can/src/exhaustive.rs b/compiler/can/src/exhaustive.rs index 235e347772..0bd99a0060 100644 --- a/compiler/can/src/exhaustive.rs +++ b/compiler/can/src/exhaustive.rs @@ -10,8 +10,8 @@ use roc_types::types::AliasKind; pub use roc_exhaustive::Context as ExhaustiveContext; -pub const GUARD_CTOR: &'static str = "#Guard"; -pub const NONEXHAUSIVE_CTOR: &'static str = "#Open"; +pub const GUARD_CTOR: &str = "#Guard"; +pub const NONEXHAUSIVE_CTOR: &str = "#Open"; pub fn check( subs: &Subs, From 752b3ee042c733d35406bad5320edb02e7d45aec Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Mon, 25 Apr 2022 08:37:52 -0400 Subject: [PATCH 588/846] Bugfix merge conflicts --- compiler/constrain/src/expr.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/compiler/constrain/src/expr.rs b/compiler/constrain/src/expr.rs index 86c01a56c2..bf08238fc5 100644 --- a/compiler/constrain/src/expr.rs +++ b/compiler/constrain/src/expr.rs @@ -715,11 +715,7 @@ pub fn constrain_expr( &loc_cond.value, Expected::NoExpectation(real_cond_type), ); - // branch_cons.extend(pattern_cons); - // branch_constraints.push(constraints.and_constraint(pattern_cons)); - let mut total_cons = Vec::with_capacity(1 + 2 * branches.len() + 1); - // total_cons.push(expr_con); - pattern_cons.push(expr_con); + pattern_cons.push(cond_constraint); // Now check the condition against the type expected by the branches. let sketched_rows = sketch_rows(real_cond_var, branches_region, branches); @@ -746,7 +742,7 @@ pub fn constrain_expr( ); let result_con = - constraints.equal_types_var(branch_var, expected, Category::When, region); + constraints.equal_types_var(body_var, expected, Category::When, region); let total_cons = [when_body_con, result_con]; let branch_constraints = constraints.and_constraint(total_cons); From 07e69c786039004dad518c179d6cff53ef6201ed Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Mon, 25 Apr 2022 14:09:29 -0400 Subject: [PATCH 589/846] Style fixes --- compiler/can/src/constraint.rs | 18 +++++++++--------- compiler/can/src/exhaustive.rs | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/compiler/can/src/constraint.rs b/compiler/can/src/constraint.rs index 7a8857a413..7ef3cceaaf 100644 --- a/compiler/can/src/constraint.rs +++ b/compiler/can/src/constraint.rs @@ -551,11 +551,6 @@ impl Constraints { pub fn contains_save_the_environment(&self, constraint: &Constraint) -> bool { match constraint { - Constraint::Eq(..) => false, - Constraint::Store(..) => false, - Constraint::Lookup(..) => false, - Constraint::Pattern(..) => false, - Constraint::True => false, Constraint::SaveTheEnvironment => true, Constraint::Let(index, _) => { let let_constraint = &self.let_constraints[index.index()]; @@ -574,10 +569,15 @@ impl Constraints { .iter() .any(|c| self.contains_save_the_environment(c)) } - Constraint::IsOpenType(_) => false, - Constraint::IncludesTag(_) => false, - Constraint::PatternPresence(_, _, _, _) => false, - Constraint::Exhaustive { .. } => false, + Constraint::Eq(..) + | Constraint::Store(..) + | Constraint::Lookup(..) + | Constraint::Pattern(..) + | Constraint::True + | Constraint::IsOpenType(_) + | Constraint::IncludesTag(_) + | Constraint::PatternPresence(_, _, _, _) + | Constraint::Exhaustive { .. } => false, } } diff --git a/compiler/can/src/exhaustive.rs b/compiler/can/src/exhaustive.rs index 0bd99a0060..d11df7aaee 100644 --- a/compiler/can/src/exhaustive.rs +++ b/compiler/can/src/exhaustive.rs @@ -30,8 +30,8 @@ pub fn check( enum SketchedPattern { Anything, Literal(Literal), - Ctor(Variable, TagName, std::vec::Vec), - KnownCtor(Union, TagId, std::vec::Vec), + Ctor(Variable, TagName, Vec), + KnownCtor(Union, TagId, Vec), } impl SketchedPattern { From 19233e08c2341856c30d69ec20f2b4568c36cdb5 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Mon, 25 Apr 2022 14:10:32 -0400 Subject: [PATCH 590/846] Consolidate IsOpen solve --- compiler/solve/src/solve.rs | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index 72930cd335..7bbf7d5751 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -1105,32 +1105,7 @@ fn solve( let actual = either_type_index_to_var(constraints, subs, rank, pools, aliases, *type_index); - let mut stack = vec![actual]; - while let Some(var) = stack.pop() { - use {Content::*, FlatType::*}; - - let mut desc = subs.get(var); - if let Structure(TagUnion(tags, ext)) = desc.content { - if let Structure(EmptyTagUnion) = subs.get_content_without_compacting(ext) { - let new_ext = subs.fresh_unnamed_flex_var(); - subs.set_rank(new_ext, desc.rank); - let new_union = Structure(TagUnion(tags, new_ext)); - desc.content = new_union; - subs.set(var, desc); - } - - // Also open up all nested tag unions. - let all_vars = tags.variables().into_iter(); - stack.extend(all_vars.flat_map(|slice| subs[slice]).map(|var| subs[var])); - } - - // Today, an "open" constraint doesn't affect any types - // other than tag unions. Recursive tag unions are constructed - // at a later time (during occurs checks after tag unions are - // resolved), so that's not handled here either. - // NB: Handle record types here if we add presence constraints - // to their type inference as well. - } + open_tag_union(subs, actual); state } From 909331c1b1b0574b0d3de0814d8f03566c401312 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Mon, 25 Apr 2022 19:07:57 -0400 Subject: [PATCH 591/846] Bugfix compile error --- compiler/can/src/exhaustive.rs | 12 +++++++----- reporting/src/error/type.rs | 29 +++++++++++++++-------------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/compiler/can/src/exhaustive.rs b/compiler/can/src/exhaustive.rs index d11df7aaee..65ced4608a 100644 --- a/compiler/can/src/exhaustive.rs +++ b/compiler/can/src/exhaustive.rs @@ -2,7 +2,9 @@ use crate::expr::{IntValue, WhenBranch}; use crate::pattern::DestructType; use roc_collections::all::HumanIndex; use roc_error_macros::internal_error; -use roc_exhaustive::{is_useful, Ctor, Error, Guard, Literal, Pattern, RenderAs, TagId, Union}; +use roc_exhaustive::{ + is_useful, Ctor, CtorName, Error, Guard, Literal, Pattern, RenderAs, TagId, Union, +}; use roc_module::ident::{TagIdIntType, TagName}; use roc_region::all::{Loc, Region}; use roc_types::subs::{Content, FlatType, Subs, SubsFmtContent, Variable}; @@ -114,7 +116,7 @@ fn sketch_pattern(var: Variable, pattern: &crate::pattern::Pattern) -> SketchedP let union = Union { render_as: RenderAs::Record(field_names), alternatives: vec![Ctor { - name: TagName::Global("#Record".into()), + name: CtorName::Tag(TagName::Global("#Record".into())), tag_id, arity: destructs.len(), }], @@ -146,7 +148,7 @@ fn sketch_pattern(var: Variable, pattern: &crate::pattern::Pattern) -> SketchedP let union = Union { render_as: RenderAs::Opaque, alternatives: vec![Ctor { - name: TagName::Private(*opaque), + name: CtorName::Opaque(*opaque), tag_id, arity: 1, }], @@ -218,7 +220,7 @@ pub fn sketch_rows(target_var: Variable, region: Region, patterns: &[WhenBranch] render_as: RenderAs::Guard, alternatives: vec![Ctor { tag_id, - name: TagName::Global(GUARD_CTOR.into()), + name: CtorName::Tag(TagName::Global(GUARD_CTOR.into())), arity: 2, }], }; @@ -322,7 +324,7 @@ fn convert_tag(subs: &Subs, whole_var: Variable, this_tag: &TagName) -> (Union, my_tag_id = tag_id; } alternatives.push(Ctor { - name: tag, + name: CtorName::Tag(tag), tag_id, arity: args.len(), }); diff --git a/reporting/src/error/type.rs b/reporting/src/error/type.rs index 3d1d6f58d6..a71bce5847 100644 --- a/reporting/src/error/type.rs +++ b/reporting/src/error/type.rs @@ -1,6 +1,7 @@ use crate::report::{Annotation, Report, RocDocAllocator, RocDocBuilder, Severity}; use roc_can::expected::{Expected, PExpected}; use roc_collections::all::{HumanIndex, MutSet, SendMap}; +use roc_exhaustive::CtorName; use roc_module::called_via::{BinOp, CalledVia}; use roc_module::ident::{Ident, IdentStr, Lowercase, TagName}; use roc_module::symbol::Symbol; @@ -3653,10 +3654,9 @@ fn pattern_to_doc_help<'b>( match union.render_as { RenderAs::Guard => { // #Guard - debug_assert_eq!( - union.alternatives[tag_id.0 as usize].name, - TagName::Global(GUARD_CTOR.into()) - ); + debug_assert!(union.alternatives[tag_id.0 as usize] + .name + .is_tag(&TagName::Global(GUARD_CTOR.into()))); debug_assert!(args.len() == 2); let tag = pattern_to_doc_help(alloc, args[1].clone(), in_type_param); alloc.concat([ @@ -3692,9 +3692,11 @@ fn pattern_to_doc_help<'b>( .append(" }") } RenderAs::Tag | RenderAs::Opaque => { - let tag = &union.alternatives[tag_id.0 as usize]; - match &tag.name { - TagName::Global(name) if name.as_str() == NONEXHAUSIVE_CTOR => { + let ctor = &union.alternatives[tag_id.0 as usize]; + match &ctor.name { + CtorName::Tag(TagName::Global(name)) + if name.as_str() == NONEXHAUSIVE_CTOR => + { return pattern_to_doc_help( alloc, roc_exhaustive::Pattern::Anything, @@ -3704,12 +3706,11 @@ fn pattern_to_doc_help<'b>( _ => {} } - let tag_name = match union.render_as { - RenderAs::Tag => alloc.tag_name(tag.name.clone()), - RenderAs::Opaque => match tag.name { - TagName::Private(opaque) => alloc.wrapped_opaque_name(opaque), - _ => unreachable!(), - }, + let tag_name = match (union.render_as, &ctor.name) { + (RenderAs::Tag, CtorName::Tag(tag)) => alloc.tag_name(tag.clone()), + (RenderAs::Opaque, CtorName::Opaque(opaque)) => { + alloc.wrapped_opaque_name(*opaque) + } _ => unreachable!(), }; @@ -3719,7 +3720,7 @@ fn pattern_to_doc_help<'b>( .map(|v| pattern_to_doc_help(alloc, v, true)); // We assume the alternatives are sorted. If not, this assert will trigger - debug_assert!(tag_id == tag.tag_id); + debug_assert!(tag_id == ctor.tag_id); let docs = std::iter::once(tag_name).chain(arg_docs); From ab2333b0fc779e32792214dd125fde361357d4f2 Mon Sep 17 00:00:00 2001 From: Jared Cone Date: Mon, 25 Apr 2022 21:52:54 -0700 Subject: [PATCH 592/846] Replaced a few more references to "global tag" with "tag" --- compiler/can/src/exhaustive.rs | 6 +++--- reporting/src/error/type.rs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/can/src/exhaustive.rs b/compiler/can/src/exhaustive.rs index 65ced4608a..40d80df0df 100644 --- a/compiler/can/src/exhaustive.rs +++ b/compiler/can/src/exhaustive.rs @@ -116,7 +116,7 @@ fn sketch_pattern(var: Variable, pattern: &crate::pattern::Pattern) -> SketchedP let union = Union { render_as: RenderAs::Record(field_names), alternatives: vec![Ctor { - name: CtorName::Tag(TagName::Global("#Record".into())), + name: CtorName::Tag(TagName::Tag("#Record".into())), tag_id, arity: destructs.len(), }], @@ -220,7 +220,7 @@ pub fn sketch_rows(target_var: Variable, region: Region, patterns: &[WhenBranch] render_as: RenderAs::Guard, alternatives: vec![Ctor { tag_id, - name: CtorName::Tag(TagName::Global(GUARD_CTOR.into())), + name: CtorName::Tag(TagName::Tag(GUARD_CTOR.into())), arity: 2, }], }; @@ -303,7 +303,7 @@ fn convert_tag(subs: &Subs, whole_var: Variable, this_tag: &TagName) -> (Union, // be matched unless there's an `Anything` pattern. let opt_openness_tag = match subs.get_content_without_compacting(ext) { FlexVar(_) | RigidVar(_) => { - let openness_tag = TagName::Global(NONEXHAUSIVE_CTOR.into()); + let openness_tag = TagName::Tag(NONEXHAUSIVE_CTOR.into()); num_tags += 1; Some((openness_tag, &[] as _)) } diff --git a/reporting/src/error/type.rs b/reporting/src/error/type.rs index c6953210af..c72e624b01 100644 --- a/reporting/src/error/type.rs +++ b/reporting/src/error/type.rs @@ -3656,7 +3656,7 @@ fn pattern_to_doc_help<'b>( // #Guard debug_assert!(union.alternatives[tag_id.0 as usize] .name - .is_tag(&TagName::Global(GUARD_CTOR.into()))); + .is_tag(&TagName::Tag(GUARD_CTOR.into()))); debug_assert!(args.len() == 2); let tag = pattern_to_doc_help(alloc, args[1].clone(), in_type_param); alloc.concat([ @@ -3694,7 +3694,7 @@ fn pattern_to_doc_help<'b>( RenderAs::Tag | RenderAs::Opaque => { let ctor = &union.alternatives[tag_id.0 as usize]; match &ctor.name { - CtorName::Tag(TagName::Global(name)) + CtorName::Tag(TagName::Tag(name)) if name.as_str() == NONEXHAUSIVE_CTOR => { return pattern_to_doc_help( From a95aa6117f60c8bb68c081e35fe4fad67ff4de7c Mon Sep 17 00:00:00 2001 From: Jared Cone Date: Mon, 25 Apr 2022 21:57:56 -0700 Subject: [PATCH 593/846] Formatting fix --- reporting/src/error/type.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/reporting/src/error/type.rs b/reporting/src/error/type.rs index c72e624b01..0a63726159 100644 --- a/reporting/src/error/type.rs +++ b/reporting/src/error/type.rs @@ -3694,9 +3694,7 @@ fn pattern_to_doc_help<'b>( RenderAs::Tag | RenderAs::Opaque => { let ctor = &union.alternatives[tag_id.0 as usize]; match &ctor.name { - CtorName::Tag(TagName::Tag(name)) - if name.as_str() == NONEXHAUSIVE_CTOR => - { + CtorName::Tag(TagName::Tag(name)) if name.as_str() == NONEXHAUSIVE_CTOR => { return pattern_to_doc_help( alloc, roc_exhaustive::Pattern::Anything, From 4164dcc3da1dd545664e940bddf9fd03cf357eec Mon Sep 17 00:00:00 2001 From: Folkert Date: Tue, 26 Apr 2022 09:14:29 +0200 Subject: [PATCH 594/846] more debug info --- compiler/can/src/def.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 982f88068a..a5413def46 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -487,7 +487,11 @@ pub(crate) fn canonicalize_defs<'a>( symbols_introduced.insert(s, r); debug_assert_eq!(env.home, s.module_id()); - debug_assert!(!symbol_to_index.iter().any(|(id, _)| *id == s.ident_id())); + debug_assert!( + !symbol_to_index.iter().any(|(id, _)| *id == s.ident_id()), + "{:?}", + s + ); symbol_to_index.push((s.ident_id(), def_index as u32)); } From b6e8509e890fcbcd6b474efb54aaee1a0e3eebab Mon Sep 17 00:00:00 2001 From: Folkert Date: Tue, 26 Apr 2022 09:14:44 +0200 Subject: [PATCH 595/846] more inline --- compiler/ident/src/lib.rs | 2 ++ compiler/module/src/ident.rs | 1 + 2 files changed, 3 insertions(+) diff --git a/compiler/ident/src/lib.rs b/compiler/ident/src/lib.rs index 5b5dbefcdf..f5c37713d1 100644 --- a/compiler/ident/src/lib.rs +++ b/compiler/ident/src/lib.rs @@ -145,6 +145,7 @@ impl IdentStr { } } + #[inline(always)] pub fn as_slice(&self) -> &[u8] { use core::slice::from_raw_parts; @@ -157,6 +158,7 @@ impl IdentStr { } } + #[inline(always)] pub fn as_str(&self) -> &str { let slice = self.as_slice(); diff --git a/compiler/module/src/ident.rs b/compiler/module/src/ident.rs index 0af20224ee..3e28569626 100644 --- a/compiler/module/src/ident.rs +++ b/compiler/module/src/ident.rs @@ -11,6 +11,7 @@ impl Ident { &self.0 } + #[inline(always)] pub fn as_str(&self) -> &str { self.0.as_str() } From 3e0b598bc7f68284852f5d0a42e0e5e6a0f81080 Mon Sep 17 00:00:00 2001 From: Folkert Date: Tue, 26 Apr 2022 09:15:51 +0200 Subject: [PATCH 596/846] switch to Vec --- compiler/module/src/symbol.rs | 171 +++++++++++++++++++++++++++------- 1 file changed, 137 insertions(+), 34 deletions(-) diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index 1b36f1b2da..f74f07802d 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -528,28 +528,34 @@ pub struct IdentId(u32); /// Since these are interned strings, this shouldn't result in many total allocations in practice. #[derive(Clone, Debug, Default, PartialEq, Eq)] pub struct IdentIds { - buffer: String, + buffer: Vec, lengths: Vec, offsets: Vec, } impl IdentIds { - fn with_capacity(capacity: usize) -> Self { + pub fn with_capacity(capacity: usize) -> Self { Self { // guess: the average symbol length is 3 - buffer: String::with_capacity(3 * capacity), + buffer: Vec::with_capacity(3 * capacity), lengths: Vec::with_capacity(capacity), offsets: Vec::with_capacity(capacity), } } + fn get_str(&self, index: usize) -> &str { + let length = self.lengths[index] as usize; + let offset = self.offsets[index] as usize; + + let bytes = &self.buffer[offset..][..length]; + + unsafe { std::str::from_utf8_unchecked(bytes) } + } + fn strs(&self) -> impl Iterator { - self.offsets - .iter() - .zip(self.lengths.iter()) - .map(move |(offset, length)| &self.buffer[*offset as usize..][..*length as usize]) + (0..self.offsets.len()).map(move |index| self.get_str(index)) } pub fn ident_strs(&self) -> impl Iterator { @@ -571,7 +577,7 @@ impl IdentIds { self.lengths.push(length); self.offsets.push(offset); - self.buffer.push_str(string); + self.buffer.extend(string.bytes()); ident_id } @@ -602,7 +608,10 @@ impl IdentIds { Some(key_index) => { let length = new_ident_name.len(); let offset = self.buffer.len(); - self.buffer.push_str(new_ident_name); + + // future optimization idea: if the current name bytes are at the end of + // `buffer`, we can update them in-place + self.buffer.extend(new_ident_name.bytes()); self.lengths[key_index] = length as u16; self.offsets[key_index] = offset as u32; @@ -634,9 +643,14 @@ impl IdentIds { let index = self.lengths.len(); + // "4294967296" is 10 characters + let mut buffer: arrayvec::ArrayString<10> = arrayvec::ArrayString::new(); + write!(buffer, "{}", index).unwrap(); + let offset = self.buffer.len(); - write!(self.buffer, "{}", index).unwrap(); - let length = self.buffer.len() - offset; + let length = buffer.len(); + + self.buffer.extend(buffer.bytes()); self.lengths.push(length as u16); self.offsets.push(offset as u32); @@ -646,7 +660,7 @@ impl IdentIds { #[inline(always)] pub fn get_id(&self, ident_name: &Ident) -> Option { - self.find_index(ident_name.as_inline_str().as_str()) + self.find_index(ident_name.as_str()) .map(|i| IdentId(i as u32)) } @@ -654,16 +668,17 @@ impl IdentIds { fn find_index(&self, string: &str) -> Option { let target_length = string.len() as u16; + let mut offset = 0; for (index, length) in self.lengths.iter().enumerate() { if *length == target_length { - let offset = self.offsets[index] as usize; - let ident = &self.buffer[offset..][..*length as usize]; + let slice = &self.buffer[offset..][..*length as usize]; - // skip the length check - if string.bytes().eq(ident.bytes()) { + if string.as_bytes() == slice { return Some(index); } } + + offset += *length as usize; } None @@ -672,25 +687,90 @@ impl IdentIds { pub fn get_name(&self, id: IdentId) -> Option<&str> { let index = id.0 as usize; - match self.lengths.get(index) { - None => None, - Some(length) => { - let offset = self.offsets[index] as usize; - Some(&self.buffer[offset..][..*length as usize]) - } + if index < self.lengths.len() { + Some(self.get_str(index)) + } else { + None } } pub fn get_name_str_res(&self, ident_id: IdentId) -> ModuleResult<&str> { - Ok(self.get_name(ident_id).with_context(|| IdentIdNotFound { + self.get_name(ident_id).with_context(|| IdentIdNotFound { ident_id, ident_ids_str: format!("{:?}", self), - })?) + }) } } // BUILTINS +const fn offset_helper(mut array: [u32; N]) -> [u32; N] { + let mut sum = 0u32; + + let mut i = 0; + while i < N { + let temp = array[i]; + array[i] = sum; + sum += temp; + + i += 1; + } + + array +} + +const fn string_equality(a: &str, b: &str) -> bool { + let a = a.as_bytes(); + let b = b.as_bytes(); + + if a.len() != b.len() { + return false; + } + + let mut i = 0; + while i < a.len() { + if a[i] != b[i] { + return false; + } + + i += 1; + } + + true +} + +const fn find_duplicates(array: [&str; N]) -> Option<(usize, usize)> { + let mut i = 0; + while i < N { + let needle = array[i]; + let mut j = i + 1; + while j < N { + if !string_equality(needle, array[i]) { + return Some((i, j)); + } + + j += 1; + } + + i += 1; + } + + None +} + +const fn check_indices(array: [u32; N]) -> Option<(u32, usize)> { + let mut i = 0; + while i < N { + if array[i] as usize != i { + return Some((array[i], i)); + } + + i += 1; + } + + None +} + macro_rules! define_builtins { { $( @@ -707,20 +787,44 @@ macro_rules! define_builtins { let mut exposed_idents_by_module = HashMap::with_capacity_and_hasher(extra_capacity + $total, default_hasher()); $( - debug_assert!(!exposed_idents_by_module.contains_key(&ModuleId($module_id)), "Error setting up Builtins: when setting up module {} {:?} - the module ID {} is already present in the map. Check the map for duplicate module IDs!", $module_id, $module_name, $module_id); + debug_assert!(!exposed_idents_by_module.contains_key(&ModuleId($module_id)), r"Error setting up Builtins: when setting up module {} {:?} - the module ID {} is already present in the map. Check the map for duplicate module IDs!", $module_id, $module_name, $module_id); - let ident_indexes = [ $($ident_id),+ ]; - let ident_names = [ $($ident_name),+ ]; + let ident_ids = { + const TOTAL : usize = [ $($ident_name),+ ].len(); + const NAMES : [ &str; TOTAL] = [ $($ident_name),+ ]; + const LENGTHS: [ u16; TOTAL] = [ $($ident_name.len() as u16),+ ]; + const OFFSETS: [ u32; TOTAL] = offset_helper([ $($ident_name.len() as u32),+ ]); + const BUFFER: &str = concat!($($ident_name),+); - let mut ident_ids = IdentIds::with_capacity(ident_names.len()); + const LENGTH_CHECK: Option<(u32, usize)> = check_indices([ $($ident_id),+ ]); + const DUPLICATE_CHECK: Option<(usize, usize)> = find_duplicates(NAMES); - for (_expected_id, name) in ident_indexes.iter().zip(ident_names.iter()) { - debug_assert!(!ident_ids.strs().any(|s| s == *name), "The Ident {} is already in IdentIds", name); + if cfg!(debug_assertions) { + match LENGTH_CHECK { + None => (), + Some((given, expected)) => panic!( + "Symbol {} : {} should have index {} based on the insertion order", + given, NAMES[expected], expected + ), + } + }; - let _actual_id = ident_ids.add_str(name); + if cfg!(debug_assertions) { + match DUPLICATE_CHECK { + None => (), + Some((first, second)) => panic!( + "Symbol {} : {} is duplicated at position {}", + first, NAMES[first], second + ), + } + }; - debug_assert_eq!(*_expected_id, _actual_id.0 as usize, "Error setting up Builtins: when inserting {} …: {} into module {} …: {} - this entry was assigned an ID of {}, but based on insertion order, it should have had an ID of {} instead! To fix this, change it from {} …: {} to {} …: {} instead.", _expected_id, name, $module_id, $module_name, _expected_id, _actual_id.0, _expected_id, name, _actual_id.0, name ); - } + IdentIds { + buffer: BUFFER.as_bytes().to_vec(), + lengths: LENGTHS.to_vec(), + offsets: OFFSETS.to_vec(), + } + }; if cfg!(debug_assertions) { let module_id = ModuleId($module_id); @@ -730,7 +834,6 @@ macro_rules! define_builtins { module_id.register_debug_idents(&ident_ids); } - exposed_idents_by_module.insert( ModuleId($module_id), ident_ids From b761890f47e3ddda20df9f1006c781aecb8102ac Mon Sep 17 00:00:00 2001 From: Folkert Date: Tue, 26 Apr 2022 09:17:09 +0200 Subject: [PATCH 597/846] use std::io::Write to write bytes --- compiler/module/src/symbol.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index f74f07802d..41d5b2d87d 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -639,18 +639,13 @@ impl IdentIds { /// This is used, for example, during canonicalization of an Expr::Closure /// to generate a unique symbol to refer to that closure. pub fn gen_unique(&mut self) -> IdentId { - use std::fmt::Write; + use std::io::Write; let index = self.lengths.len(); - // "4294967296" is 10 characters - let mut buffer: arrayvec::ArrayString<10> = arrayvec::ArrayString::new(); - write!(buffer, "{}", index).unwrap(); - let offset = self.buffer.len(); - let length = buffer.len(); - - self.buffer.extend(buffer.bytes()); + write!(self.buffer, "{}", index).unwrap(); + let length = self.buffer.len() - offset; self.lengths.push(length as u16); self.offsets.push(offset as u32); From d3ef35d935711f840403eee8273a66319cc3021c Mon Sep 17 00:00:00 2001 From: Folkert Date: Tue, 26 Apr 2022 11:33:26 +0200 Subject: [PATCH 598/846] rename --- ast/src/lang/scope.rs | 4 ++-- compiler/can/src/scope.rs | 8 ++++---- compiler/gen_wasm/src/backend.rs | 2 +- compiler/module/src/symbol.rs | 6 +++--- compiler/mono/src/code_gen_help/mod.rs | 2 +- editor/src/editor/mvc/let_update.rs | 2 +- editor/src/editor/mvc/tld_value_update.rs | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ast/src/lang/scope.rs b/ast/src/lang/scope.rs index 90046e4b40..1f57b4360b 100644 --- a/ast/src/lang/scope.rs +++ b/ast/src/lang/scope.rs @@ -245,7 +245,7 @@ impl Scope { // use that existing IdentId. Otherwise, create a fresh one. let ident_id = match exposed_ident_ids.get_id(&ident) { Some(ident_id) => ident_id, - None => all_ident_ids.add(&ident), + None => all_ident_ids.add_ident(&ident), }; let symbol = Symbol::new(self.home, ident_id); @@ -262,7 +262,7 @@ impl Scope { /// /// Used for record guards like { x: Just _ } pub fn ignore(&mut self, ident: Ident, all_ident_ids: &mut IdentIds) -> Symbol { - let ident_id = all_ident_ids.add(&ident); + let ident_id = all_ident_ids.add_ident(&ident); Symbol::new(self.home, ident_id) } diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index 2798957571..ba74bcf063 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -225,7 +225,7 @@ impl Scope { region, }; - let ident_id = all_ident_ids.add(&ident); + let ident_id = all_ident_ids.add_ident(&ident); let symbol = Symbol::new(self.home, ident_id); self.symbols.insert(symbol, region); @@ -273,7 +273,7 @@ impl Scope { ) -> Result<(Symbol, Option), (Region, Loc, Symbol)> { match self.idents.get(&ident) { Some(&(original_symbol, original_region)) => { - let shadow_ident_id = all_ident_ids.add(&ident); + let shadow_ident_id = all_ident_ids.add_ident(&ident); let shadow_symbol = Symbol::new(self.home, shadow_ident_id); self.symbols.insert(shadow_symbol, region); @@ -315,7 +315,7 @@ impl Scope { // use that existing IdentId. Otherwise, create a fresh one. let ident_id = match exposed_ident_ids.get_id(&ident) { Some(ident_id) => ident_id, - None => all_ident_ids.add(&ident), + None => all_ident_ids.add_ident(&ident), }; let symbol = Symbol::new(self.home, ident_id); @@ -330,7 +330,7 @@ impl Scope { /// /// Used for record guards like { x: Just _ } pub fn ignore(&mut self, ident: &Ident, all_ident_ids: &mut IdentIds) -> Symbol { - let ident_id = all_ident_ids.add(ident); + let ident_id = all_ident_ids.add_ident(ident); Symbol::new(self.home, ident_id) } diff --git a/compiler/gen_wasm/src/backend.rs b/compiler/gen_wasm/src/backend.rs index 7b5162c8b1..3654696cc6 100644 --- a/compiler/gen_wasm/src/backend.rs +++ b/compiler/gen_wasm/src/backend.rs @@ -183,7 +183,7 @@ impl<'a> WasmBackend<'a> { .get_mut(&self.env.module_id) .unwrap(); - let ident_id = ident_ids.add(&Ident::from(debug_name)); + let ident_id = ident_ids.add_ident(&Ident::from(debug_name)); Symbol::new(self.env.module_id, ident_id) } diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index d67ef00bba..6f30cd0f6f 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -564,11 +564,11 @@ impl IdentIds { .map(|(index, ident)| (IdentId(index as u32), ident)) } - pub fn add(&mut self, ident_name: &Ident) -> IdentId { + pub fn add_ident(&mut self, ident_name: &Ident) -> IdentId { self.add_str(ident_name.as_inline_str().as_str()) } - fn add_str(&mut self, string: &str) -> IdentId { + pub fn add_str(&mut self, string: &str) -> IdentId { let offset = self.buffer.len() as u32; let length = string.len() as u16; @@ -585,7 +585,7 @@ impl IdentIds { pub fn get_or_insert(&mut self, name: &Ident) -> IdentId { match self.get_id(name) { Some(id) => id, - None => self.add(name), + None => self.add_ident(name), } } diff --git a/compiler/mono/src/code_gen_help/mod.rs b/compiler/mono/src/code_gen_help/mod.rs index d2d864ff37..68361fd267 100644 --- a/compiler/mono/src/code_gen_help/mod.rs +++ b/compiler/mono/src/code_gen_help/mod.rs @@ -396,7 +396,7 @@ impl<'a> CodeGenHelp<'a> { } fn create_symbol(&self, ident_ids: &mut IdentIds, debug_name: &str) -> Symbol { - let ident_id = ident_ids.add(&Ident::from(debug_name)); + let ident_id = ident_ids.add_ident(&Ident::from(debug_name)); Symbol::new(self.home, ident_id) } diff --git a/editor/src/editor/mvc/let_update.rs b/editor/src/editor/mvc/let_update.rs index 585aa6c5dd..b9a734b8f4 100644 --- a/editor/src/editor/mvc/let_update.rs +++ b/editor/src/editor/mvc/let_update.rs @@ -27,7 +27,7 @@ pub fn start_new_let_value(ed_model: &mut EdModel, new_char: &char) -> EdResult< let val_expr_id = ed_model.module.env.pool.add(val_expr2_node); let ident = Ident::from(val_name_string); - let ident_id = ed_model.module.env.ident_ids.add(&ident); + let ident_id = ed_model.module.env.ident_ids.add_ident(&ident); let var_symbol = Symbol::new(ed_model.module.env.home, ident_id); let body = Expr2::Var(var_symbol); let body_id = ed_model.module.env.pool.add(body); diff --git a/editor/src/editor/mvc/tld_value_update.rs b/editor/src/editor/mvc/tld_value_update.rs index 27e85ffe31..3afaafdcf8 100644 --- a/editor/src/editor/mvc/tld_value_update.rs +++ b/editor/src/editor/mvc/tld_value_update.rs @@ -28,7 +28,7 @@ pub fn start_new_tld_value(ed_model: &mut EdModel, new_char: &char) -> EdResult< let val_expr_id = ed_model.module.env.pool.add(val_expr_node); let ident = Ident::from(new_char.to_string().as_str()); - let ident_id = ed_model.module.env.ident_ids.add(&ident); + let ident_id = ed_model.module.env.ident_ids.add_ident(&ident); let module_ident_ids_opt = ed_model .loaded_module @@ -38,7 +38,7 @@ pub fn start_new_tld_value(ed_model: &mut EdModel, new_char: &char) -> EdResult< if let Some(module_ident_ids_ref) = module_ident_ids_opt { // this might create different IdentId for interns and env.ident_ids which may be a problem - module_ident_ids_ref.add(&ident); + module_ident_ids_ref.add_ident(&ident); } else { KeyNotFound { key_str: format!("{:?}", ed_model.module.env.home), From 8875a9ee9ce19f8d32e3e049fb99e21d0f35eec1 Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Tue, 26 Apr 2022 19:00:41 +0200 Subject: [PATCH 599/846] auto use preferred color format --- code_markup/src/colors.rs | 6 +++--- editor/src/editor/main.rs | 27 ++++++++++++++++++--------- editor/src/graphics/colors.rs | 6 +++--- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/code_markup/src/colors.rs b/code_markup/src/colors.rs index b2c4c8a298..bf64fd7b95 100644 --- a/code_markup/src/colors.rs +++ b/code_markup/src/colors.rs @@ -1,4 +1,4 @@ -use palette::{FromColor, Hsv, Srgb}; +use palette::{FromColor, Hsv, LinSrgb, Srgb}; pub type RgbaTup = (f32, f32, f32, f32); pub const WHITE: RgbaTup = (1.0, 1.0, 1.0, 1.0); @@ -12,11 +12,11 @@ pub fn from_hsb(hue: usize, saturation: usize, brightness: usize) -> RgbaTup { } pub fn from_hsba(hue: usize, saturation: usize, brightness: usize, alpha: f32) -> RgbaTup { - let rgb = Srgb::from_color(Hsv::new( + let rgb = LinSrgb::from(Srgb::from_color(Hsv::new( hue as f32, (saturation as f32) / 100.0, (brightness as f32) / 100.0, - )); + ))); (rgb.red, rgb.green, rgb.blue, alpha) } diff --git a/editor/src/editor/main.rs b/editor/src/editor/main.rs index 5dbfac12f7..cac5843445 100644 --- a/editor/src/editor/main.rs +++ b/editor/src/editor/main.rs @@ -74,7 +74,7 @@ fn run_event_loop(project_dir_path_opt: Option<&Path>) -> Result<(), Box) -> Result<(), Box) -> Result<(), Box) -> Result<(), Box Result<(wgpu::Device, wgpu::Queue), wgpu::RequestDeviceError> { +) -> Result<(wgpu::Device, wgpu::Queue, wgpu::TextureFormat), wgpu::RequestDeviceError> { if force_fallback_adapter { log::error!("Falling back to software renderer. GPU acceleration has been disabled."); } @@ -418,7 +416,13 @@ async fn create_device( If you're running this from inside nix, follow the instructions here to resolve this: https://github.com/rtfeldman/roc/blob/trunk/BUILDING_FROM_SOURCE.md#editor "#); - adapter + let color_format = surface.get_preferred_format(&adapter).unwrap(); + + if color_format != wgpu::TextureFormat::Bgra8UnormSrgb { + log::warn!("Your preferred TextureFormat {:?} is different than expected. Colors may look different, please report this issue on github and tag @Anton-4.", color_format); + } + + let request_res = adapter .request_device( &wgpu::DeviceDescriptor { label: None, @@ -427,7 +431,12 @@ async fn create_device( }, None, ) - .await + .await; + + match request_res { + Ok((device, queue)) => Ok((device, queue, color_format)), + Err(err) => Err(err), + } } fn draw_rects( diff --git a/editor/src/graphics/colors.rs b/editor/src/graphics/colors.rs index 924c9ab301..67dc2801a8 100644 --- a/editor/src/graphics/colors.rs +++ b/editor/src/graphics/colors.rs @@ -1,4 +1,4 @@ -use palette::{FromColor, Hsv, Srgb}; +use palette::{FromColor, Hsv, LinSrgb, Srgb}; pub type RgbaTup = (f32, f32, f32, f32); pub const WHITE: RgbaTup = (1.0, 1.0, 1.0, 1.0); @@ -21,11 +21,11 @@ pub fn from_hsb(hue: usize, saturation: usize, brightness: usize) -> RgbaTup { } pub fn from_hsba(hue: usize, saturation: usize, brightness: usize, alpha: f32) -> RgbaTup { - let rgb = Srgb::from_color(Hsv::new( + let rgb = LinSrgb::from(Srgb::from_color(Hsv::new( hue as f32, (saturation as f32) / 100.0, (brightness as f32) / 100.0, - )); + ))); (rgb.red, rgb.green, rgb.blue, alpha) } From c31b796938a3e928bcc38785687b7f89f3985619 Mon Sep 17 00:00:00 2001 From: Folkert Date: Tue, 26 Apr 2022 20:10:29 +0200 Subject: [PATCH 600/846] more types! --- ast/src/canonicalization/module.rs | 3 +- ast/src/lang/env.rs | 6 +-- ast/src/lang/scope.rs | 9 ++-- compiler/can/src/def.rs | 2 +- compiler/can/src/env.rs | 6 +-- compiler/can/src/module.rs | 4 +- compiler/collections/src/vec_map.rs | 30 ++++++++++- compiler/load_internal/src/file.rs | 79 +++++++++++++---------------- compiler/module/src/symbol.rs | 43 +++++++++++++--- docs/src/lib.rs | 5 +- 10 files changed, 116 insertions(+), 71 deletions(-) diff --git a/ast/src/canonicalization/module.rs b/ast/src/canonicalization/module.rs index 64c568af5f..634e7e881c 100644 --- a/ast/src/canonicalization/module.rs +++ b/ast/src/canonicalization/module.rs @@ -7,6 +7,7 @@ use roc_can::operator::desugar_def; use roc_collections::all::{default_hasher, ImMap, ImSet, MutMap, MutSet, SendMap}; use roc_module::ident::Ident; use roc_module::ident::Lowercase; +use roc_module::symbol::IdentIdsByModule; use roc_module::symbol::{IdentIds, ModuleId, ModuleIds, Symbol}; use roc_parse::ast; use roc_parse::pattern::PatternType; @@ -48,7 +49,7 @@ pub fn canonicalize_module_defs<'a>( home: ModuleId, module_ids: &ModuleIds, exposed_ident_ids: IdentIds, - dep_idents: MutMap, + dep_idents: IdentIdsByModule, aliases: MutMap, exposed_imports: MutMap, mut exposed_symbols: MutSet, diff --git a/ast/src/lang/env.rs b/ast/src/lang/env.rs index 0af9303543..d2ea5448bd 100644 --- a/ast/src/lang/env.rs +++ b/ast/src/lang/env.rs @@ -2,7 +2,7 @@ use crate::mem_pool::pool::{NodeId, Pool}; use bumpalo::{collections::Vec as BumpVec, Bump}; use roc_collections::all::{MutMap, MutSet}; use roc_module::ident::{Ident, Lowercase, ModuleName}; -use roc_module::symbol::{IdentIds, ModuleId, ModuleIds, Symbol}; +use roc_module::symbol::{IdentIds, IdentIdsByModule, ModuleId, ModuleIds, Symbol}; use roc_problem::can::{Problem, RuntimeError}; use roc_region::all::{Loc, Region}; use roc_types::subs::VarStore; @@ -19,7 +19,7 @@ pub struct Env<'a> { pub problems: BumpVec<'a, Problem>, - pub dep_idents: MutMap, + pub dep_idents: IdentIdsByModule, pub module_ids: &'a ModuleIds, pub ident_ids: IdentIds, pub exposed_ident_ids: IdentIds, @@ -41,7 +41,7 @@ impl<'a> Env<'a> { arena: &'a Bump, pool: &'a mut Pool, var_store: &'a mut VarStore, - dep_idents: MutMap, + dep_idents: IdentIdsByModule, module_ids: &'a ModuleIds, exposed_ident_ids: IdentIds, ) -> Env<'a> { diff --git a/ast/src/lang/scope.rs b/ast/src/lang/scope.rs index 1f57b4360b..ced87957e4 100644 --- a/ast/src/lang/scope.rs +++ b/ast/src/lang/scope.rs @@ -12,7 +12,8 @@ use crate::mem_pool::shallow_clone::ShallowClone; use roc_collections::all::{MutMap, MutSet}; use roc_module::ident::{Ident, Lowercase}; use roc_module::symbol::{ - get_module_ident_ids, get_module_ident_ids_mut, IdentIds, Interns, ModuleId, Symbol, + get_module_ident_ids, get_module_ident_ids_mut, IdentIds, IdentIdsByModule, Interns, ModuleId, + Symbol, }; use roc_problem::can::RuntimeError; use roc_region::all::{Loc, Region}; @@ -320,11 +321,7 @@ impl Scope { self.aliases.contains_key(&name) } - pub fn fill_scope( - &mut self, - env: &Env, - all_ident_ids: &mut MutMap, - ) -> ASTResult<()> { + pub fn fill_scope(&mut self, env: &Env, all_ident_ids: &mut IdentIdsByModule) -> ASTResult<()> { let ident_ids = get_module_ident_ids(all_ident_ids, &env.home)?.clone(); for (_, ident_ref) in ident_ids.ident_strs() { diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index a5413def46..bf7520dbcd 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -984,7 +984,7 @@ fn add_annotation_aliases( aliases: &mut VecMap, ) { for (name, alias) in type_annotation.aliases.iter() { - if !aliases.contains(name) { + if !aliases.contains_key(name) { aliases.insert(*name, alias.clone()); } } diff --git a/compiler/can/src/env.rs b/compiler/can/src/env.rs index 2c7a28ad69..e127c32bea 100644 --- a/compiler/can/src/env.rs +++ b/compiler/can/src/env.rs @@ -1,7 +1,7 @@ use crate::procedure::References; use roc_collections::{MutMap, VecSet}; use roc_module::ident::{Ident, Lowercase, ModuleName}; -use roc_module::symbol::{IdentIds, ModuleId, ModuleIds, Symbol}; +use roc_module::symbol::{IdentIds, IdentIdsByModule, ModuleId, ModuleIds, Symbol}; use roc_problem::can::{Problem, RuntimeError}; use roc_region::all::{Loc, Region}; @@ -11,7 +11,7 @@ pub struct Env<'a> { /// are assumed to be relative to this path. pub home: ModuleId, - pub dep_idents: &'a MutMap, + pub dep_idents: &'a IdentIdsByModule, pub module_ids: &'a ModuleIds, @@ -42,7 +42,7 @@ pub struct Env<'a> { impl<'a> Env<'a> { pub fn new( home: ModuleId, - dep_idents: &'a MutMap, + dep_idents: &'a IdentIdsByModule, module_ids: &'a ModuleIds, exposed_ident_ids: IdentIds, ) -> Env<'a> { diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index db8cd17b1c..0db77094cc 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -10,7 +10,7 @@ use bumpalo::Bump; use roc_collections::{MutMap, SendMap, VecSet}; use roc_module::ident::Ident; use roc_module::ident::Lowercase; -use roc_module::symbol::{IdentIds, ModuleId, ModuleIds, Symbol}; +use roc_module::symbol::{IdentIds, IdentIdsByModule, ModuleId, ModuleIds, Symbol}; use roc_parse::ast; use roc_parse::header::HeaderFor; use roc_parse::pattern::PatternType; @@ -170,7 +170,7 @@ pub fn canonicalize_module_defs<'a>( home: ModuleId, module_ids: &ModuleIds, exposed_ident_ids: IdentIds, - dep_idents: &'a MutMap, + dep_idents: &'a IdentIdsByModule, aliases: MutMap, exposed_imports: MutMap, exposed_symbols: &VecSet, diff --git a/compiler/collections/src/vec_map.rs b/compiler/collections/src/vec_map.rs index 60b1608737..68de20f849 100644 --- a/compiler/collections/src/vec_map.rs +++ b/compiler/collections/src/vec_map.rs @@ -54,7 +54,7 @@ impl VecMap { } } - pub fn contains(&self, key: &K) -> bool { + pub fn contains_key(&self, key: &K) -> bool { self.keys.contains(key) } @@ -69,6 +69,34 @@ impl VecMap { } } + pub fn get(&self, key: &K) -> Option<&V> { + match self.keys.iter().position(|x| x == key) { + None => None, + Some(index) => Some(&self.values[index]), + } + } + + pub fn get_mut(&mut self, key: &K) -> Option<&mut V> { + match self.keys.iter().position(|x| x == key) { + None => None, + Some(index) => Some(&mut self.values[index]), + } + } + + pub fn get_or_insert(&mut self, key: K, default_value: impl Fn() -> V) -> &mut V { + match self.keys.iter().position(|x| x == &key) { + Some(index) => &mut self.values[index], + None => { + let value = default_value(); + + self.keys.push(key); + self.values.push(value); + + self.values.last_mut().unwrap() + } + } + } + pub fn iter(&self) -> impl Iterator { self.keys.iter().zip(self.values.iter()) } diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index 20584442b3..3b5acebcc6 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -18,8 +18,8 @@ use roc_constrain::module::{ use roc_error_macros::internal_error; use roc_module::ident::{Ident, ModuleName, QualifiedModuleName, TagName}; use roc_module::symbol::{ - IdentIds, Interns, ModuleId, ModuleIds, PQModuleName, PackageModuleIds, PackageQualified, - Symbol, + IdentIds, IdentIdsByModule, Interns, ModuleId, ModuleIds, PQModuleName, PackageModuleIds, + PackageQualified, Symbol, }; use roc_mono::ir::{ CapturedSymbols, EntryPoint, ExternalSpecializations, PartialProc, Proc, ProcLayout, Procs, @@ -168,6 +168,8 @@ impl Default for ModuleCache<'_> { } } +type SharedIdentIdsByModule = Arc>; + fn start_phase<'a>( module_id: ModuleId, phase: Phase, @@ -228,8 +230,7 @@ fn start_phase<'a>( let deps_by_name = &parsed.deps_by_name; let num_deps = deps_by_name.len(); - let mut dep_idents: MutMap = - IdentIds::exposed_builtins(num_deps); + let mut dep_idents: IdentIdsByModule = IdentIds::exposed_builtins(num_deps); let State { ident_ids_by_module, @@ -419,7 +420,7 @@ pub struct LoadedModule { pub type_problems: MutMap>, pub declarations_by_id: MutMap>, pub exposed_to_host: MutMap, - pub dep_idents: MutMap, + pub dep_idents: IdentIdsByModule, pub exposed_aliases: MutMap, pub exposed_values: Vec, pub sources: MutMap)>, @@ -483,7 +484,7 @@ struct ConstrainedModule { constraint: ConstraintSoa, ident_ids: IdentIds, var_store: VarStore, - dep_idents: MutMap, + dep_idents: IdentIdsByModule, module_timing: ModuleTiming, } @@ -587,7 +588,7 @@ enum Msg<'a> { solved_module: SolvedModule, solved_subs: Solved, decls: Vec, - dep_idents: MutMap, + dep_idents: IdentIdsByModule, module_timing: ModuleTiming, abilities_store: AbilitiesStore, }, @@ -595,7 +596,7 @@ enum Msg<'a> { solved_subs: Solved, exposed_vars_by_symbol: Vec<(Symbol, Variable)>, exposed_aliases_by_symbol: MutMap, - dep_idents: MutMap, + dep_idents: IdentIdsByModule, documentation: MutMap, abilities_store: AbilitiesStore, }, @@ -668,13 +669,13 @@ struct State<'a> { /// This is the "final" list of IdentIds, after canonicalization and constraint gen /// have completed for a given module. - pub constrained_ident_ids: MutMap, + pub constrained_ident_ids: IdentIdsByModule, /// From now on, these will be used by multiple threads; time to make an Arc>! pub arc_modules: Arc>>, pub arc_shorthands: Arc>>>, - pub ident_ids_by_module: Arc>>, + pub ident_ids_by_module: SharedIdentIdsByModule, pub declarations_by_id: MutMap>, @@ -705,7 +706,7 @@ impl<'a> State<'a> { goal_phase: Phase, exposed_types: ExposedByModule, arc_modules: Arc>>, - ident_ids_by_module: Arc>>, + ident_ids_by_module: SharedIdentIdsByModule, cached_subs: MutMap)>, render: RenderTarget, ) -> Self { @@ -814,7 +815,7 @@ enum BuildTask<'a> { module_name: PQModuleName<'a>, module_ids: Arc>>, shorthands: Arc>>>, - ident_ids_by_module: Arc>>, + ident_ids_by_module: SharedIdentIdsByModule, }, Parse { header: ModuleHeader<'a>, @@ -822,7 +823,7 @@ enum BuildTask<'a> { CanonicalizeAndConstrain { parsed: ParsedModule<'a>, module_ids: ModuleIds, - dep_idents: MutMap, + dep_idents: IdentIdsByModule, exposed_symbols: VecSet, aliases: MutMap, skip_constraint_gen: bool, @@ -837,7 +838,7 @@ enum BuildTask<'a> { constraint: ConstraintSoa, var_store: VarStore, declarations: Vec, - dep_idents: MutMap, + dep_idents: IdentIdsByModule, cached_subs: CachedSubs, }, BuildPendingSpecializations { @@ -951,7 +952,7 @@ pub enum PrintTarget { pub struct LoadStart<'a> { arc_modules: Arc>>, - ident_ids_by_module: Arc>>, + ident_ids_by_module: SharedIdentIdsByModule, root_id: ModuleId, root_msg: Msg<'a>, } @@ -2403,7 +2404,7 @@ fn finish( solved: Solved, exposed_aliases_by_symbol: MutMap, exposed_vars_by_symbol: Vec<(Symbol, Variable)>, - dep_idents: MutMap, + dep_idents: IdentIdsByModule, documentation: MutMap, abilities_store: AbilitiesStore, ) -> LoadedModule { @@ -2451,7 +2452,7 @@ fn load_pkg_config<'a>( shorthand: &'a str, app_module_id: ModuleId, module_ids: Arc>>, - ident_ids_by_module: Arc>>, + ident_ids_by_module: SharedIdentIdsByModule, ) -> Result, LoadingProblem<'a>> { let module_start_time = SystemTime::now(); @@ -2569,7 +2570,7 @@ fn load_builtin_module_help<'a>( fn load_builtin_module<'a>( arena: &'a Bump, module_ids: Arc>>, - ident_ids_by_module: Arc>>, + ident_ids_by_module: SharedIdentIdsByModule, module_timing: ModuleTiming, module_id: ModuleId, module_name: &str, @@ -2594,7 +2595,7 @@ fn load_module<'a>( module_name: PQModuleName<'a>, module_ids: Arc>>, arc_shorthands: Arc>>>, - ident_ids_by_module: Arc>>, + ident_ids_by_module: SharedIdentIdsByModule, ) -> Result<(ModuleId, Msg<'a>), LoadingProblem<'a>> { let module_start_time = SystemTime::now(); @@ -2781,7 +2782,7 @@ fn parse_header<'a>( is_root_module: bool, opt_shorthand: Option<&'a str>, module_ids: Arc>>, - ident_ids_by_module: Arc>>, + ident_ids_by_module: SharedIdentIdsByModule, src_bytes: &'a [u8], start_time: SystemTime, ) -> Result<(ModuleId, Msg<'a>), LoadingProblem<'a>> { @@ -2969,7 +2970,7 @@ fn load_filename<'a>( is_root_module: bool, opt_shorthand: Option<&'a str>, module_ids: Arc>>, - ident_ids_by_module: Arc>>, + ident_ids_by_module: SharedIdentIdsByModule, module_start_time: SystemTime, ) -> Result<(ModuleId, Msg<'a>), LoadingProblem<'a>> { let file_io_start = SystemTime::now(); @@ -3003,7 +3004,7 @@ fn load_from_str<'a>( filename: PathBuf, src: &'a str, module_ids: Arc>>, - ident_ids_by_module: Arc>>, + ident_ids_by_module: SharedIdentIdsByModule, module_start_time: SystemTime, ) -> Result<(ModuleId, Msg<'a>), LoadingProblem<'a>> { let file_io_start = SystemTime::now(); @@ -3039,7 +3040,7 @@ fn send_header<'a>( info: HeaderInfo<'a>, parse_state: roc_parse::state::State<'a>, module_ids: Arc>>, - ident_ids_by_module: Arc>>, + ident_ids_by_module: SharedIdentIdsByModule, module_timing: ModuleTiming, ) -> (ModuleId, Msg<'a>) { use ModuleNameEnum::*; @@ -3102,9 +3103,7 @@ fn send_header<'a>( home = module_ids.get_or_insert(&name); // Ensure this module has an entry in the exposed_ident_ids map. - ident_ids_by_module - .entry(home) - .or_insert_with(IdentIds::default); + ident_ids_by_module.get_or_insert(home); // For each of our imports, add an entry to deps_by_name // @@ -3131,9 +3130,7 @@ fn send_header<'a>( // Add the new exposed idents to the dep module's IdentIds, so // once that module later gets loaded, its lookups will resolve // to the same symbols as the ones we're using here. - let ident_ids = ident_ids_by_module - .entry(module_id) - .or_insert_with(IdentIds::default); + let ident_ids = ident_ids_by_module.get_or_insert(module_id); for ident in exposed_idents { let ident_id = ident_ids.get_or_insert(&ident); @@ -3255,7 +3252,7 @@ fn send_header_two<'a>( info: PlatformHeaderInfo<'a>, parse_state: roc_parse::state::State<'a>, module_ids: Arc>>, - ident_ids_by_module: Arc>>, + ident_ids_by_module: SharedIdentIdsByModule, module_timing: ModuleTiming, ) -> (ModuleId, Msg<'a>) { let PlatformHeaderInfo { @@ -3314,9 +3311,7 @@ fn send_header_two<'a>( home = module_ids.get_or_insert(&name); // Ensure this module has an entry in the exposed_ident_ids map. - ident_ids_by_module - .entry(home) - .or_insert_with(IdentIds::default); + ident_ids_by_module.get_or_insert(home); // For each of our imports, add an entry to deps_by_name // @@ -3338,9 +3333,7 @@ fn send_header_two<'a>( // Add the new exposed idents to the dep module's IdentIds, so // once that module later gets loaded, its lookups will resolve // to the same symbols as the ones we're using here. - let ident_ids = ident_ids_by_module - .entry(module_id) - .or_insert_with(IdentIds::default); + let ident_ids = ident_ids_by_module.get_or_insert(module_id); for ident in exposed_idents { let ident_id = ident_ids.get_or_insert(&ident); @@ -3354,9 +3347,7 @@ fn send_header_two<'a>( } { - let ident_ids = ident_ids_by_module - .entry(app_module_id) - .or_insert_with(IdentIds::default); + let ident_ids = ident_ids_by_module.get_or_insert(app_module_id); for entry in requires { let entry = entry.value; @@ -3486,7 +3477,7 @@ impl<'a> BuildTask<'a> { var_store: VarStore, imported_modules: MutMap, exposed_types: &mut ExposedByModule, - dep_idents: MutMap, + dep_idents: IdentIdsByModule, declarations: Vec, cached_subs: CachedSubs, ) -> Self { @@ -3668,7 +3659,7 @@ fn run_solve<'a>( constraint: ConstraintSoa, var_store: VarStore, decls: Vec, - dep_idents: MutMap, + dep_idents: IdentIdsByModule, cached_subs: CachedSubs, ) -> Msg<'a> { let solve_start = SystemTime::now(); @@ -3758,7 +3749,7 @@ fn fabricate_pkg_config_module<'a>( filename: PathBuf, parse_state: roc_parse::state::State<'a>, module_ids: Arc>>, - ident_ids_by_module: Arc>>, + ident_ids_by_module: SharedIdentIdsByModule, header: &PlatformHeader<'a>, module_timing: ModuleTiming, ) -> (ModuleId, Msg<'a>) { @@ -3791,7 +3782,7 @@ fn fabricate_pkg_config_module<'a>( fn canonicalize_and_constrain<'a>( arena: &'a Bump, module_ids: &ModuleIds, - dep_idents: MutMap, + dep_idents: IdentIdsByModule, exposed_symbols: VecSet, aliases: MutMap, parsed: ParsedModule<'a>, @@ -4576,7 +4567,7 @@ fn to_file_problem_report(filename: &Path, error: io::ErrorKind) -> String { fn to_parse_problem_report<'a>( problem: FileError<'a, SyntaxError<'a>>, mut module_ids: ModuleIds, - all_ident_ids: MutMap, + all_ident_ids: IdentIdsByModule, render: RenderTarget, ) -> String { use roc_reporting::report::{parse_problem, RocDocAllocator, DEFAULT_PALETTE}; diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index 6f30cd0f6f..7043223a93 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -1,6 +1,6 @@ use crate::ident::{Ident, ModuleName}; use crate::module_err::{IdentIdNotFound, ModuleIdNotFound, ModuleResult}; -use roc_collections::all::{default_hasher, MutMap, SendMap}; +use roc_collections::{default_hasher, MutMap, SendMap, VecMap}; use roc_ident::IdentStr; use roc_region::all::Region; use snafu::OptionExt; @@ -207,7 +207,7 @@ lazy_static! { #[derive(Debug, Default)] pub struct Interns { pub module_ids: ModuleIds, - pub all_ident_ids: MutMap, + pub all_ident_ids: IdentIdsByModule, } impl Interns { @@ -249,7 +249,7 @@ impl Interns { } pub fn get_module_ident_ids<'a>( - all_ident_ids: &'a MutMap, + all_ident_ids: &'a IdentIdsByModule, module_id: &ModuleId, ) -> ModuleResult<&'a IdentIds> { all_ident_ids @@ -261,7 +261,7 @@ pub fn get_module_ident_ids<'a>( } pub fn get_module_ident_ids_mut<'a>( - all_ident_ids: &'a mut MutMap, + all_ident_ids: &'a mut IdentIdsByModule, module_id: &ModuleId, ) -> ModuleResult<&'a mut IdentIds> { all_ident_ids @@ -697,6 +697,35 @@ impl IdentIds { } } +#[derive(Debug, Default)] +pub struct IdentIdsByModule(VecMap); + +impl IdentIdsByModule { + pub fn get_or_insert(&mut self, module_id: ModuleId) -> &mut IdentIds { + self.0.get_or_insert(module_id, IdentIds::default) + } + + pub fn get_mut(&mut self, key: &ModuleId) -> Option<&mut IdentIds> { + self.0.get_mut(key) + } + + pub fn get(&self, key: &ModuleId) -> Option<&IdentIds> { + self.0.get(key) + } + + pub fn insert(&mut self, key: ModuleId, value: IdentIds) -> Option { + self.0.insert(key, value) + } + + pub fn keys(&self) -> impl Iterator { + self.0.keys() + } + + pub fn len(&self) -> usize { + self.0.len() + } +} + // BUILTINS const fn offset_helper(mut array: [u32; N]) -> [u32; N] { @@ -778,8 +807,8 @@ macro_rules! define_builtins { num_modules: $total:literal } => { impl IdentIds { - pub fn exposed_builtins(extra_capacity: usize) -> MutMap { - let mut exposed_idents_by_module = HashMap::with_capacity_and_hasher(extra_capacity + $total, default_hasher()); + pub fn exposed_builtins(extra_capacity: usize) -> IdentIdsByModule { + let mut exposed_idents_by_module = VecMap::with_capacity(extra_capacity + $total); $( debug_assert!(!exposed_idents_by_module.contains_key(&ModuleId($module_id)), r"Error setting up Builtins: when setting up module {} {:?} - the module ID {} is already present in the map. Check the map for duplicate module IDs!", $module_id, $module_name, $module_id); @@ -838,7 +867,7 @@ macro_rules! define_builtins { debug_assert!(exposed_idents_by_module.len() == $total, "Error setting up Builtins: `total:` is set to the wrong amount. It was set to {} but {} modules were set up.", $total, exposed_idents_by_module.len()); - exposed_idents_by_module + IdentIdsByModule(exposed_idents_by_module) } } diff --git a/docs/src/lib.rs b/docs/src/lib.rs index a2c01973c7..965fc7480f 100644 --- a/docs/src/lib.rs +++ b/docs/src/lib.rs @@ -6,13 +6,12 @@ use html::mark_node_to_html; use roc_can::scope::Scope; use roc_code_markup::markup::nodes::MarkupNode; use roc_code_markup::slow_pool::SlowPool; -use roc_collections::all::MutMap; use roc_highlight::highlight_parser::{highlight_defs, highlight_expr}; use roc_load::docs::DocEntry::DocDef; use roc_load::docs::{DocEntry, TypeAnnotation}; use roc_load::docs::{ModuleDocumentation, RecordField}; use roc_load::{LoadedModule, LoadingProblem}; -use roc_module::symbol::{IdentIds, Interns, ModuleId}; +use roc_module::symbol::{IdentIdsByModule, Interns, ModuleId}; use roc_parse::ident::{parse_ident, Ident}; use roc_parse::state::State; use roc_region::all::Region; @@ -711,7 +710,7 @@ struct DocUrl { fn doc_url<'a>( home: ModuleId, exposed_values: &[&str], - dep_idents: &MutMap, + dep_idents: &IdentIdsByModule, scope: &Scope, interns: &'a Interns, mut module_name: &'a str, From e87cb5555b86f5bcec4dc3ecd24a561b4d3de6c2 Mon Sep 17 00:00:00 2001 From: Folkert Date: Tue, 26 Apr 2022 20:18:17 +0200 Subject: [PATCH 601/846] use u8 as length type --- compiler/module/src/symbol.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index 7043223a93..0c564ab430 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -530,7 +530,7 @@ pub struct IdentId(u32); pub struct IdentIds { buffer: Vec, - lengths: Vec, + lengths: Vec, offsets: Vec, } @@ -570,7 +570,7 @@ impl IdentIds { pub fn add_str(&mut self, string: &str) -> IdentId { let offset = self.buffer.len() as u32; - let length = string.len() as u16; + let length = string.len() as u8; let ident_id = IdentId(self.lengths.len() as u32); @@ -613,7 +613,7 @@ impl IdentIds { // `buffer`, we can update them in-place self.buffer.extend(new_ident_name.bytes()); - self.lengths[key_index] = length as u16; + self.lengths[key_index] = length as u8; self.offsets[key_index] = offset as u32; Ok(ident_id) @@ -647,7 +647,7 @@ impl IdentIds { write!(self.buffer, "{}", index).unwrap(); let length = self.buffer.len() - offset; - self.lengths.push(length as u16); + self.lengths.push(length as u8); self.offsets.push(offset as u32); IdentId(index as u32) @@ -661,7 +661,7 @@ impl IdentIds { #[inline(always)] fn find_index(&self, string: &str) -> Option { - let target_length = string.len() as u16; + let target_length = string.len() as u8; let mut offset = 0; for (index, length) in self.lengths.iter().enumerate() { @@ -816,7 +816,7 @@ macro_rules! define_builtins { let ident_ids = { const TOTAL : usize = [ $($ident_name),+ ].len(); const NAMES : [ &str; TOTAL] = [ $($ident_name),+ ]; - const LENGTHS: [ u16; TOTAL] = [ $($ident_name.len() as u16),+ ]; + const LENGTHS: [ u8; TOTAL] = [ $($ident_name.len() as u8),+ ]; const OFFSETS: [ u32; TOTAL] = offset_helper([ $($ident_name.len() as u32),+ ]); const BUFFER: &str = concat!($($ident_name),+); From d690d3f3253bb1179fa554ee3941941c3eafcf30 Mon Sep 17 00:00:00 2001 From: Folkert Date: Tue, 26 Apr 2022 20:26:13 +0200 Subject: [PATCH 602/846] clippy --- ast/src/lang/env.rs | 2 +- compiler/can/src/env.rs | 2 +- compiler/module/src/symbol.rs | 10 +++++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/ast/src/lang/env.rs b/ast/src/lang/env.rs index d2ea5448bd..6afee73494 100644 --- a/ast/src/lang/env.rs +++ b/ast/src/lang/env.rs @@ -150,7 +150,7 @@ impl<'a> Env<'a> { .filter(|(_, ident)| { ident.starts_with(|c: char| c.is_lowercase()) }) - .map(|(_, ident)| Lowercase::from(ident.as_ref())) + .map(|(_, ident)| Lowercase::from(ident)) .collect(); Err(RuntimeError::ValueNotExposed { module_name, diff --git a/compiler/can/src/env.rs b/compiler/can/src/env.rs index e127c32bea..aaa5bdd6e3 100644 --- a/compiler/can/src/env.rs +++ b/compiler/can/src/env.rs @@ -131,7 +131,7 @@ impl<'a> Env<'a> { .filter(|(_, ident)| { ident.starts_with(|c: char| c.is_lowercase()) }) - .map(|(_, ident)| Lowercase::from(ident.as_ref())) + .map(|(_, ident)| Lowercase::from(ident)) .collect(); Err(RuntimeError::ValueNotExposed { module_name, diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index 0c564ab430..4fcca0bbf9 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -724,6 +724,10 @@ impl IdentIdsByModule { pub fn len(&self) -> usize { self.0.len() } + + pub fn is_empty(&self) -> bool { + self.0.is_empty() + } } // BUILTINS @@ -827,8 +831,8 @@ macro_rules! define_builtins { match LENGTH_CHECK { None => (), Some((given, expected)) => panic!( - "Symbol {} : {} should have index {} based on the insertion order", - given, NAMES[expected], expected + "Symbol {} : {} should have index {} based on the insertion order, try {} : {} instead", + given, NAMES[expected], expected, expected, NAMES[expected], ), } }; @@ -837,7 +841,7 @@ macro_rules! define_builtins { match DUPLICATE_CHECK { None => (), Some((first, second)) => panic!( - "Symbol {} : {} is duplicated at position {}", + "Symbol {} : {} is duplicated at position {}, try removing the duplicate", first, NAMES[first], second ), } From 9cfca53b0d1372489360eb10bc40249fe05ff698 Mon Sep 17 00:00:00 2001 From: Folkert Date: Tue, 26 Apr 2022 20:32:11 +0200 Subject: [PATCH 603/846] update guess --- compiler/module/src/symbol.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index 4fcca0bbf9..29c8fbebbe 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -537,8 +537,8 @@ pub struct IdentIds { impl IdentIds { pub fn with_capacity(capacity: usize) -> Self { Self { - // guess: the average symbol length is 3 - buffer: Vec::with_capacity(3 * capacity), + // guess: the average symbol length is 5 + buffer: Vec::with_capacity(5 * capacity), lengths: Vec::with_capacity(capacity), offsets: Vec::with_capacity(capacity), From e5e27dff1c049e24b11cbb1119dbb1e99d24a881 Mon Sep 17 00:00:00 2001 From: Folkert Date: Tue, 26 Apr 2022 20:40:47 +0200 Subject: [PATCH 604/846] style --- compiler/module/src/symbol.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index 29c8fbebbe..a85a99e936 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -737,9 +737,7 @@ const fn offset_helper(mut array: [u32; N]) -> [u32; N] { let mut i = 0; while i < N { - let temp = array[i]; - array[i] = sum; - sum += temp; + (array[i], sum) = (sum, sum + array[i]); i += 1; } @@ -747,10 +745,7 @@ const fn offset_helper(mut array: [u32; N]) -> [u32; N] { array } -const fn string_equality(a: &str, b: &str) -> bool { - let a = a.as_bytes(); - let b = b.as_bytes(); - +const fn byte_slice_equality(a: &[u8], b: &[u8]) -> bool { if a.len() != b.len() { return false; } @@ -773,7 +768,7 @@ const fn find_duplicates(array: [&str; N]) -> Option<(usize, usi let needle = array[i]; let mut j = i + 1; while j < N { - if !string_equality(needle, array[i]) { + if byte_slice_equality(needle.as_bytes(), array[j].as_bytes()) { return Some((i, j)); } From a0c8d4413b1dfbc228c8c7be9c988314b0d5f83d Mon Sep 17 00:00:00 2001 From: Folkert Date: Tue, 26 Apr 2022 21:32:34 +0200 Subject: [PATCH 605/846] using features that are too fancy --- compiler/module/src/symbol.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index a85a99e936..00f6725535 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -737,7 +737,10 @@ const fn offset_helper(mut array: [u32; N]) -> [u32; N] { let mut i = 0; while i < N { - (array[i], sum) = (sum, sum + array[i]); + // In rust 1.60 change to: (array[i], sum) = (sum, sum + array[i]); + let temp = array[i]; + array[i] = sum; + sum += temp; i += 1; } From 7b7da3ffce6b9095cd52ae00692f6fc4ca7bb02d Mon Sep 17 00:00:00 2001 From: Folkert Date: Tue, 26 Apr 2022 21:54:45 +0200 Subject: [PATCH 606/846] refactor out a SmallStringInterner --- compiler/module/src/symbol.rs | 205 ++++++++++++++++++---------------- 1 file changed, 108 insertions(+), 97 deletions(-) diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index 00f6725535..b117d9c0b5 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -522,19 +522,16 @@ impl ModuleIds { #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] pub struct IdentId(u32); -/// Stores a mapping between IdentId and InlinableString. -/// -/// Each module name is stored twice, for faster lookups. -/// Since these are interned strings, this shouldn't result in many total allocations in practice. +/// Collection of small (length < 256) strings, stored compactly. #[derive(Clone, Debug, Default, PartialEq, Eq)] -pub struct IdentIds { +pub struct SmallStringInterner { buffer: Vec, lengths: Vec, offsets: Vec, } -impl IdentIds { +impl SmallStringInterner { pub fn with_capacity(capacity: usize) -> Self { Self { // guess: the average symbol length is 5 @@ -545,100 +542,28 @@ impl IdentIds { } } - fn get_str(&self, index: usize) -> &str { - let length = self.lengths[index] as usize; - let offset = self.offsets[index] as usize; - - let bytes = &self.buffer[offset..][..length]; - - unsafe { std::str::from_utf8_unchecked(bytes) } - } - fn strs(&self) -> impl Iterator { - (0..self.offsets.len()).map(move |index| self.get_str(index)) + (0..self.offsets.len()).map(move |index| self.get(index)) } - pub fn ident_strs(&self) -> impl Iterator { - self.strs() - .enumerate() - .map(|(index, ident)| (IdentId(index as u32), ident)) - } + pub fn insert(&mut self, string: &str) -> usize { + assert!(string.len() < u8::MAX as usize); - pub fn add_ident(&mut self, ident_name: &Ident) -> IdentId { - self.add_str(ident_name.as_inline_str().as_str()) - } - - pub fn add_str(&mut self, string: &str) -> IdentId { let offset = self.buffer.len() as u32; let length = string.len() as u8; - let ident_id = IdentId(self.lengths.len() as u32); + let index = self.lengths.len(); self.lengths.push(length); self.offsets.push(offset); self.buffer.extend(string.bytes()); - ident_id + index } - pub fn get_or_insert(&mut self, name: &Ident) -> IdentId { - match self.get_id(name) { - Some(id) => id, - None => self.add_ident(name), - } - } - - // necessary when the name of a value is changed in the editor - // TODO fix when same ident_name is present multiple times, see issue #2548 - pub fn update_key( - &mut self, - old_ident_name: &str, - new_ident_name: &str, - ) -> Result { - let old_ident: Ident = old_ident_name.into(); - - let ident_id_ref_opt = self.get_id(&old_ident); - - match ident_id_ref_opt { - Some(ident_id_ref) => { - let ident_id = ident_id_ref; - - match self.find_index(old_ident_name) { - Some(key_index) => { - let length = new_ident_name.len(); - let offset = self.buffer.len(); - - // future optimization idea: if the current name bytes are at the end of - // `buffer`, we can update them in-place - self.buffer.extend(new_ident_name.bytes()); - - self.lengths[key_index] = length as u8; - self.offsets[key_index] = offset as u32; - - Ok(ident_id) - } - None => Err(format!( - r"Tried to find position of key {:?} in IdentIds.by_id but I could not find the key", - old_ident_name - )), - } - } - None => Err(format!( - "Tried to update key in IdentIds, but I could not find the key ({}).", - old_ident_name - )), - } - } - - /// Generates a unique, new name that's just a strigified integer - /// (e.g. "1" or "5"), using an internal counter. Since valid Roc variable - /// names cannot begin with a number, this has no chance of colliding - /// with actual user-defined variables. - /// - /// This is used, for example, during canonicalization of an Expr::Closure - /// to generate a unique symbol to refer to that closure. - pub fn gen_unique(&mut self) -> IdentId { + /// Insert a string equal to the current length into the interner. This is used to create unique values. + fn insert_index_str(&mut self) -> usize { use std::io::Write; let index = self.lengths.len(); @@ -650,13 +575,7 @@ impl IdentIds { self.lengths.push(length as u8); self.offsets.push(offset as u32); - IdentId(index as u32) - } - - #[inline(always)] - pub fn get_id(&self, ident_name: &Ident) -> Option { - self.find_index(ident_name.as_str()) - .map(|i| IdentId(i as u32)) + index } #[inline(always)] @@ -679,16 +598,106 @@ impl IdentIds { None } - pub fn get_name(&self, id: IdentId) -> Option<&str> { - let index = id.0 as usize; + fn get(&self, index: usize) -> &str { + let length = self.lengths[index] as usize; + let offset = self.offsets[index] as usize; + let bytes = &self.buffer[offset..][..length]; + + unsafe { std::str::from_utf8_unchecked(bytes) } + } + + fn try_get(&self, index: usize) -> Option<&str> { if index < self.lengths.len() { - Some(self.get_str(index)) + Some(self.get(index)) } else { None } } + fn modify(&mut self, index: usize, new_string: &str) { + let length = new_string.len(); + let offset = self.buffer.len(); + + // future optimization idea: if the current name bytes are at the end of + // `buffer`, we can update them in-place + self.buffer.extend(new_string.bytes()); + + self.lengths[index] = length as u8; + self.offsets[index] = offset as u32; + } +} + +/// Stores a mapping between IdentId and InlinableString. +/// +/// Each module name is stored twice, for faster lookups. +/// Since these are interned strings, this shouldn't result in many total allocations in practice. +#[derive(Clone, Debug, Default, PartialEq, Eq)] +pub struct IdentIds { + interner: SmallStringInterner, +} + +impl IdentIds { + pub fn ident_strs(&self) -> impl Iterator { + self.interner + .strs() + .enumerate() + .map(|(index, ident)| (IdentId(index as u32), ident)) + } + + pub fn add_ident(&mut self, ident_name: &Ident) -> IdentId { + IdentId(self.interner.insert(ident_name.as_str()) as u32) + } + + pub fn get_or_insert(&mut self, name: &Ident) -> IdentId { + match self.get_id(name) { + Some(id) => id, + None => self.add_ident(name), + } + } + + // necessary when the name of a value is changed in the editor + // TODO fix when same ident_name is present multiple times, see issue #2548 + pub fn update_key( + &mut self, + old_ident_name: &str, + new_ident_name: &str, + ) -> Result { + match self.interner.find_index(old_ident_name) { + Some(index) => { + self.interner.modify(index, new_ident_name); + + Ok(IdentId(index as u32)) + } + None => Err(format!( + r"Tried to find position of key {:?} in IdentIds.by_id but I could not find the key", + old_ident_name + )), + } + } + + /// Generates a unique, new name that's just a strigified integer + /// (e.g. "1" or "5"), using an internal counter. Since valid Roc variable + /// names cannot begin with a number, this has no chance of colliding + /// with actual user-defined variables. + /// + /// This is used, for example, during canonicalization of an Expr::Closure + /// to generate a unique symbol to refer to that closure. + pub fn gen_unique(&mut self) -> IdentId { + IdentId(self.interner.insert_index_str() as u32) + } + + #[inline(always)] + pub fn get_id(&self, ident_name: &Ident) -> Option { + self.interner + .find_index(ident_name.as_str()) + .map(|i| IdentId(i as u32)) + } + + pub fn get_name(&self, id: IdentId) -> Option<&str> { + self.interner.try_get(id.0 as usize) + } + pub fn get_name_str_res(&self, ident_id: IdentId) -> ModuleResult<&str> { self.get_name(ident_id).with_context(|| IdentIdNotFound { ident_id, @@ -845,11 +854,13 @@ macro_rules! define_builtins { } }; - IdentIds { + let interner = SmallStringInterner { buffer: BUFFER.as_bytes().to_vec(), lengths: LENGTHS.to_vec(), offsets: OFFSETS.to_vec(), - } + }; + + IdentIds{ interner } }; if cfg!(debug_assertions) { From fc9067805b73a1c369850ce009e49e5c26c174ad Mon Sep 17 00:00:00 2001 From: Folkert Date: Tue, 26 Apr 2022 22:22:10 +0200 Subject: [PATCH 607/846] move SmallStringInterner to its own file --- compiler/collections/src/lib.rs | 2 + .../collections/src/small_string_interner.rs | 118 ++++++++++++++++ compiler/module/src/symbol.rs | 127 ++---------------- 3 files changed, 129 insertions(+), 118 deletions(-) create mode 100644 compiler/collections/src/small_string_interner.rs diff --git a/compiler/collections/src/lib.rs b/compiler/collections/src/lib.rs index f0f98b5e64..bb83cbddf2 100644 --- a/compiler/collections/src/lib.rs +++ b/compiler/collections/src/lib.rs @@ -3,10 +3,12 @@ #![allow(clippy::large_enum_variant)] pub mod all; +mod small_string_interner; pub mod soa; mod vec_map; mod vec_set; pub use all::{default_hasher, BumpMap, ImEntry, ImMap, ImSet, MutMap, MutSet, SendMap}; +pub use small_string_interner::SmallStringInterner; pub use vec_map::VecMap; pub use vec_set::VecSet; diff --git a/compiler/collections/src/small_string_interner.rs b/compiler/collections/src/small_string_interner.rs new file mode 100644 index 0000000000..0da3c7dad5 --- /dev/null +++ b/compiler/collections/src/small_string_interner.rs @@ -0,0 +1,118 @@ +/// Collection of small (length < 256) strings, stored compactly. +#[derive(Clone, Debug, Default, PartialEq, Eq)] +pub struct SmallStringInterner { + buffer: Vec, + + lengths: Vec, + offsets: Vec, +} + +impl SmallStringInterner { + pub fn with_capacity(capacity: usize) -> Self { + Self { + // guess: the average symbol length is 5 + buffer: Vec::with_capacity(5 * capacity), + + lengths: Vec::with_capacity(capacity), + offsets: Vec::with_capacity(capacity), + } + } + + pub const fn from_parts(buffer: Vec, lengths: Vec, offsets: Vec) -> Self { + Self { + buffer, + lengths, + offsets, + } + } + + pub fn iter(&self) -> impl Iterator { + (0..self.offsets.len()).map(move |index| self.get(index)) + } + + pub fn insert(&mut self, string: &str) -> usize { + assert!(string.len() < u8::MAX as usize); + + let offset = self.buffer.len() as u32; + let length = string.len() as u8; + + let index = self.lengths.len(); + + self.lengths.push(length); + self.offsets.push(offset); + + self.buffer.extend(string.bytes()); + + index + } + + /// Insert a string equal to the current length into the interner. + /// + /// Assuming that normally you don't insert strings consisting of just digits, + /// this is an easy way to create a unique string name. We use this to create + /// unique variable names: variable names cannot start with a digit in the source, + /// so if we insert the current length of `length` as its digits, that is always unique + pub fn insert_index_str(&mut self) -> usize { + use std::io::Write; + + let index = self.lengths.len(); + + let offset = self.buffer.len(); + write!(self.buffer, "{}", index).unwrap(); + let length = self.buffer.len() - offset; + + self.lengths.push(length as u8); + self.offsets.push(offset as u32); + + index + } + + #[inline(always)] + pub fn find_index(&self, string: &str) -> Option { + let target_length = string.len() as u8; + + let mut offset = 0; + for (index, length) in self.lengths.iter().enumerate() { + if *length == target_length { + let slice = &self.buffer[offset..][..*length as usize]; + + if string.as_bytes() == slice { + return Some(index); + } + } + + offset += *length as usize; + } + + None + } + + fn get(&self, index: usize) -> &str { + let length = self.lengths[index] as usize; + let offset = self.offsets[index] as usize; + + let bytes = &self.buffer[offset..][..length]; + + unsafe { std::str::from_utf8_unchecked(bytes) } + } + + pub fn try_get(&self, index: usize) -> Option<&str> { + if index < self.lengths.len() { + Some(self.get(index)) + } else { + None + } + } + + pub fn update(&mut self, index: usize, new_string: &str) { + let length = new_string.len(); + let offset = self.buffer.len(); + + // future optimization idea: if the current name bytes are at the end of + // `buffer`, we can update them in-place + self.buffer.extend(new_string.bytes()); + + self.lengths[index] = length as u8; + self.offsets[index] = offset as u32; + } +} diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index b117d9c0b5..c69571b779 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -1,6 +1,6 @@ use crate::ident::{Ident, ModuleName}; use crate::module_err::{IdentIdNotFound, ModuleIdNotFound, ModuleResult}; -use roc_collections::{default_hasher, MutMap, SendMap, VecMap}; +use roc_collections::{default_hasher, MutMap, SendMap, SmallStringInterner, VecMap}; use roc_ident::IdentStr; use roc_region::all::Region; use snafu::OptionExt; @@ -522,116 +522,7 @@ impl ModuleIds { #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] pub struct IdentId(u32); -/// Collection of small (length < 256) strings, stored compactly. -#[derive(Clone, Debug, Default, PartialEq, Eq)] -pub struct SmallStringInterner { - buffer: Vec, - - lengths: Vec, - offsets: Vec, -} - -impl SmallStringInterner { - pub fn with_capacity(capacity: usize) -> Self { - Self { - // guess: the average symbol length is 5 - buffer: Vec::with_capacity(5 * capacity), - - lengths: Vec::with_capacity(capacity), - offsets: Vec::with_capacity(capacity), - } - } - - fn strs(&self) -> impl Iterator { - (0..self.offsets.len()).map(move |index| self.get(index)) - } - - pub fn insert(&mut self, string: &str) -> usize { - assert!(string.len() < u8::MAX as usize); - - let offset = self.buffer.len() as u32; - let length = string.len() as u8; - - let index = self.lengths.len(); - - self.lengths.push(length); - self.offsets.push(offset); - - self.buffer.extend(string.bytes()); - - index - } - - /// Insert a string equal to the current length into the interner. This is used to create unique values. - fn insert_index_str(&mut self) -> usize { - use std::io::Write; - - let index = self.lengths.len(); - - let offset = self.buffer.len(); - write!(self.buffer, "{}", index).unwrap(); - let length = self.buffer.len() - offset; - - self.lengths.push(length as u8); - self.offsets.push(offset as u32); - - index - } - - #[inline(always)] - fn find_index(&self, string: &str) -> Option { - let target_length = string.len() as u8; - - let mut offset = 0; - for (index, length) in self.lengths.iter().enumerate() { - if *length == target_length { - let slice = &self.buffer[offset..][..*length as usize]; - - if string.as_bytes() == slice { - return Some(index); - } - } - - offset += *length as usize; - } - - None - } - - fn get(&self, index: usize) -> &str { - let length = self.lengths[index] as usize; - let offset = self.offsets[index] as usize; - - let bytes = &self.buffer[offset..][..length]; - - unsafe { std::str::from_utf8_unchecked(bytes) } - } - - fn try_get(&self, index: usize) -> Option<&str> { - if index < self.lengths.len() { - Some(self.get(index)) - } else { - None - } - } - - fn modify(&mut self, index: usize, new_string: &str) { - let length = new_string.len(); - let offset = self.buffer.len(); - - // future optimization idea: if the current name bytes are at the end of - // `buffer`, we can update them in-place - self.buffer.extend(new_string.bytes()); - - self.lengths[index] = length as u8; - self.offsets[index] = offset as u32; - } -} - -/// Stores a mapping between IdentId and InlinableString. -/// -/// Each module name is stored twice, for faster lookups. -/// Since these are interned strings, this shouldn't result in many total allocations in practice. +/// Stores a mapping between Ident and IdentId. #[derive(Clone, Debug, Default, PartialEq, Eq)] pub struct IdentIds { interner: SmallStringInterner, @@ -640,7 +531,7 @@ pub struct IdentIds { impl IdentIds { pub fn ident_strs(&self) -> impl Iterator { self.interner - .strs() + .iter() .enumerate() .map(|(index, ident)| (IdentId(index as u32), ident)) } @@ -665,7 +556,7 @@ impl IdentIds { ) -> Result { match self.interner.find_index(old_ident_name) { Some(index) => { - self.interner.modify(index, new_ident_name); + self.interner.update(index, new_ident_name); Ok(IdentId(index as u32)) } @@ -854,11 +745,11 @@ macro_rules! define_builtins { } }; - let interner = SmallStringInterner { - buffer: BUFFER.as_bytes().to_vec(), - lengths: LENGTHS.to_vec(), - offsets: OFFSETS.to_vec(), - }; + let interner = SmallStringInterner::from_parts ( + BUFFER.as_bytes().to_vec(), + LENGTHS.to_vec(), + OFFSETS.to_vec(), + ); IdentIds{ interner } }; From 0f863bdd8506b0d32f55fb635129db09b83b684c Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 26 Apr 2022 16:42:55 -0400 Subject: [PATCH 608/846] Explicitly use large code models in AArch64 code gen This appears to be necessary to compile our programs on AArch64 boxes. My guess is special-cased code due to PIEs for large code models in LLVM's codebase but I really have no idea. --- compiler/build/src/link.rs | 5 ++--- compiler/build/src/program.rs | 6 ++---- compiler/build/src/target.rs | 13 +++++++++++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/compiler/build/src/link.rs b/compiler/build/src/link.rs index a7e32d0328..4bf75d24b3 100644 --- a/compiler/build/src/link.rs +++ b/compiler/build/src/link.rs @@ -1072,7 +1072,7 @@ pub fn module_to_dylib( opt_level: OptLevel, ) -> Result { use crate::target::{self, convert_opt_level}; - use inkwell::targets::{CodeModel, FileType, RelocMode}; + use inkwell::targets::{FileType, RelocMode}; let dir = tempfile::tempdir().unwrap(); let filename = PathBuf::from("Test.roc"); @@ -1083,9 +1083,8 @@ pub fn module_to_dylib( // Emit the .o file using position-independent code (PIC) - needed for dylibs let reloc = RelocMode::PIC; - let model = CodeModel::Default; let target_machine = - target::target_machine(target, convert_opt_level(opt_level), reloc, model).unwrap(); + target::target_machine(target, convert_opt_level(opt_level), reloc).unwrap(); target_machine .write_to_file(module, FileType::Object, &app_o_file) diff --git a/compiler/build/src/program.rs b/compiler/build/src/program.rs index 3d8ac5e456..62a965d8aa 100644 --- a/compiler/build/src/program.rs +++ b/compiler/build/src/program.rs @@ -249,7 +249,7 @@ pub fn gen_from_mono_module_llvm( use inkwell::attributes::{Attribute, AttributeLoc}; use inkwell::context::Context; use inkwell::module::Linkage; - use inkwell::targets::{CodeModel, FileType, RelocMode}; + use inkwell::targets::{FileType, RelocMode}; let code_gen_start = SystemTime::now(); @@ -437,10 +437,8 @@ pub fn gen_from_mono_module_llvm( match target.architecture { Architecture::X86_64 | Architecture::X86_32(_) | Architecture::Aarch64(_) => { let reloc = RelocMode::PIC; - let model = CodeModel::Default; let target_machine = - target::target_machine(target, convert_opt_level(opt_level), reloc, model) - .unwrap(); + target::target_machine(target, convert_opt_level(opt_level), reloc).unwrap(); target_machine .write_to_file(env.module, FileType::Object, app_o_file) diff --git a/compiler/build/src/target.rs b/compiler/build/src/target.rs index 6beee37300..096ccbc867 100644 --- a/compiler/build/src/target.rs +++ b/compiler/build/src/target.rs @@ -147,19 +147,28 @@ pub fn target_machine( target: &Triple, opt: OptimizationLevel, reloc: RelocMode, - model: CodeModel, ) -> Option { let arch = arch_str(target); init_arch(target); + let code_model = match target.architecture { + // LLVM 12 will not compile our programs without a large code model. + // The reason is not totally clear to me, but my guess is a few special-cases in + // llvm/lib/Target/AArch64/AArch64ISelLowering.cpp (instructions) + // llvm/lib/Target/AArch64/AArch64Subtarget.cpp (GoT tables) + // Revisit when upgrading to LLVM 13. + Architecture::Aarch64(..) => CodeModel::Large, + _ => CodeModel::Default, + }; + Target::from_name(arch).unwrap().create_target_machine( &TargetTriple::create(target_triple_str(target)), "generic", "", // TODO: this probably should be TargetMachine::get_host_cpu_features() to enable all features. opt, reloc, - model, + code_model, ) } From 6d9598a1796a0e1440421010889328579522aa2f Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 26 Apr 2022 17:36:45 -0400 Subject: [PATCH 609/846] Mark return-by-pointer parameters as `sret` in LLVM We need to do this so that LLVM picks up the correct calling convention - in particular, on AArch64, return-by-pointer parameters need to go in x8 for the C callconv! This ends up fixing all `cli_run` tests! ``` running 35 tests WARNING: skipping testing example form.roc because the test is broken right now! test cli_run::cli ... ok test cli_run::exposed_not_defined ... ok test cli_run::format_check_folders ... ok test cli_run::format_check_good ... ok test cli_run::format_check_reformatting_needed ... ok test cli_run::effects ... ok test cli_run::fib ... ok test cli_run::helloC ... ok test cli_run::closure ... ok WARNING: skipping testing example helloWeb.roc because the test is broken right now! test cli_run::helloWeb ... ok test cli_run::cfold ... ok test cli_run::base64 ... ok test cli_run::helloWorld ... ok test cli_run::known_type_error ... ok test cli_run::helloRust ... ok test cli_run::helloZig ... ok WARNING: skipping testing benchmark QuicksortApp.roc because the test is broken right now! test cli_run::quicksort_app ... ok test cli_run::astar ... ok test cli_run::quicksort ... ok test cli_run::issue2279 ... ok test cli_run::helloSwift ... ok test cli_run::run_multi_dep_str_optimized ... ok test cli_run::nqueens ... ok test cli_run::false_interpreter ... ok test cli_run::rbtree_ck ... ok test cli_run::unknown_generates_with ... ok test cli_run::rbtree_insert ... ok test cli_run::unused_import ... ok test cli_run::run_multi_dep_str_unoptimized ... ok test cli_run::tui ... ok test cli_run::run_multi_dep_thunk_optimized ... ok test cli_run::run_multi_dep_thunk_unoptimized ... ok test cli_run::deriv ... ok test cli_run::breakout ... ok test cli_run::gui ... ok test result: ok. 35 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 12.09s ``` --- compiler/gen_llvm/src/llvm/build.rs | 266 ++++++++++++++-------- compiler/gen_llvm/src/llvm/externs.rs | 28 ++- compiler/gen_llvm/src/llvm/refcounting.rs | 10 +- 3 files changed, 192 insertions(+), 112 deletions(-) diff --git a/compiler/gen_llvm/src/llvm/build.rs b/compiler/gen_llvm/src/llvm/build.rs index 0af58a6f79..db8961c2d6 100644 --- a/compiler/gen_llvm/src/llvm/build.rs +++ b/compiler/gen_llvm/src/llvm/build.rs @@ -30,6 +30,7 @@ use crate::llvm::refcounting::{ }; use bumpalo::collections::Vec; use bumpalo::Bump; +use inkwell::attributes::{Attribute, AttributeLoc}; use inkwell::basic_block::BasicBlock; use inkwell::builder::Builder; use inkwell::context::Context; @@ -40,7 +41,7 @@ use inkwell::memory_buffer::MemoryBuffer; use inkwell::module::{Linkage, Module}; use inkwell::passes::{PassManager, PassManagerBuilder}; use inkwell::types::{ - BasicMetadataTypeEnum, BasicType, BasicTypeEnum, FunctionType, IntType, StructType, + AnyType, BasicMetadataTypeEnum, BasicType, BasicTypeEnum, FunctionType, IntType, StructType, }; use inkwell::values::BasicValueEnum::{self, *}; use inkwell::values::{ @@ -467,7 +468,7 @@ fn add_float_intrinsic<'ctx, F>( if let Some(_) = module.get_function(full_name) { // zig defined this function already } else { - add_intrinsic(module, full_name, construct_type($typ)); + add_intrinsic(ctx, module, full_name, construct_type($typ)); } }; } @@ -492,7 +493,7 @@ fn add_int_intrinsic<'ctx, F>( if let Some(_) = module.get_function(full_name) { // zig defined this function already } else { - add_intrinsic(module, full_name, construct_type($typ)); + add_intrinsic(ctx, module, full_name, construct_type($typ)); } }; } @@ -527,6 +528,7 @@ fn add_intrinsics<'ctx>(ctx: &'ctx Context, module: &Module<'ctx>) { } add_intrinsic( + ctx, module, LLVM_SETJMP, i32_type.fn_type(&[i8_ptr_type.into()], false), @@ -534,12 +536,14 @@ fn add_intrinsics<'ctx>(ctx: &'ctx Context, module: &Module<'ctx>) { if true { add_intrinsic( + ctx, module, LLVM_LONGJMP, void_type.fn_type(&[i8_ptr_type.into()], false), ); } else { add_intrinsic( + ctx, module, LLVM_LONGJMP, void_type.fn_type(&[i8_ptr_type.into(), i32_type.into()], false), @@ -547,14 +551,21 @@ fn add_intrinsics<'ctx>(ctx: &'ctx Context, module: &Module<'ctx>) { } add_intrinsic( + ctx, module, LLVM_FRAME_ADDRESS, i8_ptr_type.fn_type(&[i32_type.into()], false), ); - add_intrinsic(module, LLVM_STACK_SAVE, i8_ptr_type.fn_type(&[], false)); + add_intrinsic( + ctx, + module, + LLVM_STACK_SAVE, + i8_ptr_type.fn_type(&[], false), + ); add_intrinsic( + ctx, module, LLVM_LROUND_I64_F64, i64_type.fn_type(&[f64_type.into()], false), @@ -631,18 +642,17 @@ const LLVM_ADD_SATURATED: IntrinsicName = llvm_int_intrinsic!("llvm.sadd.sat", " const LLVM_SUB_SATURATED: IntrinsicName = llvm_int_intrinsic!("llvm.ssub.sat", "llvm.usub.sat"); fn add_intrinsic<'ctx>( + context: &Context, module: &Module<'ctx>, intrinsic_name: &str, fn_type: FunctionType<'ctx>, ) -> FunctionValue<'ctx> { add_func( + context, module, intrinsic_name, - fn_type, + FunctionSpec::intrinsic(fn_type), Linkage::External, - // LLVM intrinsics always use the C calling convention, because - // they are implemented in C libraries - C_CALL_CONV, ) } @@ -3254,32 +3264,29 @@ fn expose_function_to_host_help_c_abi_generic<'a, 'ctx, 'env>( // let mut argument_types = roc_function.get_type().get_param_types(); let mut argument_types = cc_argument_types; - let c_function_type = match roc_function.get_type().get_return_type() { + match roc_function.get_type().get_return_type() { None => { // this function already returns by-pointer let output_type = roc_function.get_type().get_param_types().pop().unwrap(); argument_types.insert(0, output_type); - - env.context - .void_type() - .fn_type(&function_arguments(env, &argument_types), false) } Some(return_type) => { let output_type = return_type.ptr_type(AddressSpace::Generic); argument_types.insert(0, output_type.into()); - - env.context - .void_type() - .fn_type(&function_arguments(env, &argument_types), false) } - }; + } + // This is not actually a function that returns a value but then became + // return-by-pointer do to the calling convention. Instead, here we + // explicitly are forcing the passing of values via the first parameter + // pointer, since they are generic and hence opaque to anything outside roc. + let c_function_spec = FunctionSpec::cconv(env, CCReturn::Void, None, &argument_types); let c_function = add_func( + env.context, env.module, c_function_name, - c_function_type, + c_function_spec, Linkage::External, - C_CALL_CONV, ); let subprogram = env.new_subprogram(c_function_name); @@ -3392,20 +3399,18 @@ fn expose_function_to_host_help_c_abi_gen_test<'a, 'ctx, 'env>( let mut argument_types = cc_argument_types; let return_type = wrapper_return_type; - let c_function_type = { + let c_function_spec = { let output_type = return_type.ptr_type(AddressSpace::Generic); argument_types.push(output_type.into()); - env.context - .void_type() - .fn_type(&function_arguments(env, &argument_types), false) + FunctionSpec::cconv(env, CCReturn::Void, None, &argument_types) }; let c_function = add_func( + env.context, env.module, c_function_name, - c_function_type, + c_function_spec, Linkage::External, - C_CALL_CONV, ); let subprogram = env.new_subprogram(c_function_name); @@ -3470,15 +3475,20 @@ fn expose_function_to_host_help_c_abi_gen_test<'a, 'ctx, 'env>( builder.build_return(None); // STEP 3: build a {} -> u64 function that gives the size of the return type - let size_function_type = env.context.i64_type().fn_type(&[], false); + let size_function_spec = FunctionSpec::cconv( + env, + CCReturn::Return, + Some(env.context.i64_type().as_basic_type_enum()), + &[], + ); let size_function_name: String = format!("roc__{}_size", ident_string); let size_function = add_func( + env.context, env.module, size_function_name.as_str(), - size_function_type, + size_function_spec, Linkage::External, - C_CALL_CONV, ); let subprogram = env.new_subprogram(&size_function_name); @@ -3510,14 +3520,14 @@ fn expose_function_to_host_help_c_abi_v2<'a, 'ctx, 'env>( let cc_return = to_cc_return(env, &return_layout); let roc_return = RocReturn::from_layout(env, &return_layout); - let c_function_type = cc_return.to_signature(env, return_type, argument_types.as_slice()); + let c_function_spec = FunctionSpec::cconv(env, cc_return, Some(return_type), &argument_types); let c_function = add_func( + env.context, env.module, c_function_name, - c_function_type, + c_function_spec, Linkage::External, - C_CALL_CONV, ); let subprogram = env.new_subprogram(c_function_name); @@ -3628,15 +3638,20 @@ fn expose_function_to_host_help_c_abi<'a, 'ctx, 'env>( ); // STEP 3: build a {} -> u64 function that gives the size of the return type - let size_function_type = env.context.i64_type().fn_type(&[], false); + let size_function_spec = FunctionSpec::cconv( + env, + CCReturn::Return, + Some(env.context.i64_type().as_basic_type_enum()), + &[], + ); let size_function_name: String = format!("roc__{}_size", ident_string); let size_function = add_func( + env.context, env.module, size_function_name.as_str(), - size_function_type, + size_function_spec, Linkage::External, - C_CALL_CONV, ); let subprogram = env.new_subprogram(&size_function_name); @@ -3917,16 +3932,20 @@ fn make_exception_catching_wrapper<'a, 'ctx, 'env>( // argument_types.push(wrapper_return_type.ptr_type(AddressSpace::Generic).into()); // let wrapper_function_type = env.context.void_type().fn_type(&argument_types, false); - let wrapper_function_type = - wrapper_return_type.fn_type(&function_arguments(env, &argument_types), false); + let wrapper_function_spec = FunctionSpec::cconv( + env, + CCReturn::Return, + Some(wrapper_return_type.as_basic_type_enum()), + &argument_types, + ); // Add main to the module. let wrapper_function = add_func( + env.context, env.module, wrapper_function_name, - wrapper_function_type, + wrapper_function_spec, Linkage::External, - C_CALL_CONV, ); let subprogram = env.new_subprogram(wrapper_function_name); @@ -4155,23 +4174,15 @@ fn build_proc_header<'a, 'ctx, 'env>( arg_basic_types.push(arg_type); } - let fn_type = match RocReturn::from_layout(env, &proc.ret_layout) { - RocReturn::Return => ret_type.fn_type(&function_arguments(env, &arg_basic_types), false), - RocReturn::ByPointer => { - // println!( "{:?} will return void instead of {:?}", symbol, proc.ret_layout); - arg_basic_types.push(ret_type.ptr_type(AddressSpace::Generic).into()); - env.context - .void_type() - .fn_type(&function_arguments(env, &arg_basic_types), false) - } - }; + let roc_return = RocReturn::from_layout(env, &proc.ret_layout); + let fn_spec = FunctionSpec::fastcc(env, roc_return, ret_type, arg_basic_types); let fn_val = add_func( + env.context, env.module, fn_name.as_str(), - fn_type, + fn_spec, Linkage::Internal, - FAST_CALL_CONV, ); let subprogram = env.new_subprogram(&fn_name); @@ -4189,8 +4200,6 @@ fn build_proc_header<'a, 'ctx, 'env>( } if false { - use inkwell::attributes::{Attribute, AttributeLoc}; - let kind_id = Attribute::get_named_enum_kind_id("alwaysinline"); debug_assert!(kind_id > 0); let enum_attr = env.context.create_enum_attribute(kind_id, 1); @@ -4198,8 +4207,6 @@ fn build_proc_header<'a, 'ctx, 'env>( } if false { - use inkwell::attributes::{Attribute, AttributeLoc}; - let kind_id = Attribute::get_named_enum_kind_id("noinline"); debug_assert!(kind_id > 0); let enum_attr = env.context.create_enum_attribute(kind_id, 1); @@ -4253,14 +4260,14 @@ pub fn build_closure_caller<'a, 'ctx, 'env>( alias_symbol.as_str(&env.interns) ); - let function_type = context.void_type().fn_type(&argument_types, false); + let function_spec = FunctionSpec::cconv(env, CCReturn::Void, None, &argument_types); let function_value = add_func( + env.context, env.module, function_name.as_str(), - function_type, + function_spec, Linkage::External, - C_CALL_CONV, ); // STEP 2: build function body @@ -4359,7 +4366,8 @@ fn build_host_exposed_alias_size_help<'a, 'ctx, 'env>( let builder = env.builder; let context = env.context; - let size_function_type = env.context.i64_type().fn_type(&[], false); + let i64 = env.context.i64_type().as_basic_type_enum(); + let size_function_spec = FunctionSpec::cconv(env, CCReturn::Return, Some(i64), &[]); let size_function_name: String = if let Some(label) = opt_label { format!( "roc__{}_{}_{}_size", @@ -4376,11 +4384,11 @@ fn build_host_exposed_alias_size_help<'a, 'ctx, 'env>( }; let size_function = add_func( + env.context, env.module, size_function_name.as_str(), - size_function_type, + size_function_spec, Linkage::External, - C_CALL_CONV, ); let entry = context.append_basic_block(size_function, "entry"); @@ -6199,6 +6207,7 @@ fn to_cc_type_builtin<'a, 'ctx, 'env>( } } +#[derive(Clone, Copy)] enum RocReturn { /// Return as normal Return, @@ -6239,7 +6248,7 @@ impl RocReturn { } } -#[derive(Debug)] +#[derive(Debug, Clone, Copy)] pub enum CCReturn { /// Return as normal Return, @@ -6251,32 +6260,113 @@ pub enum CCReturn { Void, } -impl CCReturn { - fn to_signature<'a, 'ctx, 'env>( - &self, +#[derive(Debug, Clone, Copy)] +pub struct FunctionSpec<'ctx> { + /// The function type + pub typ: FunctionType<'ctx>, + call_conv: u32, + + /// Index (0-based) of return-by-pointer parameter, if it exists. + /// We only care about this for C-call-conv functions, because this may take + /// ownership of a register due to the convention. For example, on AArch64, + /// values returned-by-pointer use the x8 register. + /// But for internal functions we need to worry about that and we don't want + /// that, since it might eat a register and cause a spill! + cconv_sret_parameter: Option, +} + +impl<'ctx> FunctionSpec<'ctx> { + fn attach_attributes(&self, ctx: &Context, fn_val: FunctionValue<'ctx>) { + fn_val.set_call_conventions(self.call_conv); + + if let Some(param_index) = self.cconv_sret_parameter { + // Indicate to LLVM that this argument holds the return value of the function. + let sret_attribute_id = Attribute::get_named_enum_kind_id("sret"); + debug_assert!(sret_attribute_id > 0); + let ret_typ = self.typ.get_param_types()[param_index as usize]; + let sret_attribute = + ctx.create_type_attribute(sret_attribute_id, ret_typ.as_any_type_enum()); + fn_val.add_attribute(AttributeLoc::Param(0), sret_attribute); + } + } + + /// C-calling convention + pub fn cconv<'a, 'env>( env: &Env<'a, 'ctx, 'env>, - return_type: BasicTypeEnum<'ctx>, + cc_return: CCReturn, + return_type: Option>, argument_types: &[BasicTypeEnum<'ctx>], - ) -> FunctionType<'ctx> { - match self { + ) -> FunctionSpec<'ctx> { + let (typ, opt_sret_parameter) = match cc_return { CCReturn::ByPointer => { // turn the output type into a pointer type. Make it the first argument to the function - let output_type = return_type.ptr_type(AddressSpace::Generic); + let output_type = return_type.unwrap().ptr_type(AddressSpace::Generic); + let mut arguments: Vec<'_, BasicTypeEnum> = bumpalo::vec![in env.arena; output_type.into()]; arguments.extend(argument_types); let arguments = function_arguments(env, &arguments); - env.context.void_type().fn_type(&arguments, false) + (env.context.void_type().fn_type(&arguments, false), Some(0)) } CCReturn::Return => { let arguments = function_arguments(env, argument_types); - return_type.fn_type(&arguments, false) + (return_type.unwrap().fn_type(&arguments, false), None) } CCReturn::Void => { let arguments = function_arguments(env, argument_types); - env.context.void_type().fn_type(&arguments, false) + (env.context.void_type().fn_type(&arguments, false), None) } + }; + + Self { + typ, + call_conv: C_CALL_CONV, + cconv_sret_parameter: opt_sret_parameter, + } + } + + /// Fastcc calling convention + fn fastcc<'a, 'env>( + env: &Env<'a, 'ctx, 'env>, + roc_return: RocReturn, + return_type: BasicTypeEnum<'ctx>, + mut argument_types: Vec>, + ) -> FunctionSpec<'ctx> { + let typ = match roc_return { + RocReturn::Return => { + return_type.fn_type(&function_arguments(env, &argument_types), false) + } + RocReturn::ByPointer => { + argument_types.push(return_type.ptr_type(AddressSpace::Generic).into()); + env.context + .void_type() + .fn_type(&function_arguments(env, &argument_types), false) + } + }; + + Self { + typ, + call_conv: FAST_CALL_CONV, + cconv_sret_parameter: None, + } + } + + pub fn known_fastcc<'a, 'env>(fn_type: FunctionType<'ctx>) -> FunctionSpec<'ctx> { + Self { + typ: fn_type, + call_conv: FAST_CALL_CONV, + cconv_sret_parameter: None, + } + } + + pub fn intrinsic(fn_type: FunctionType<'ctx>) -> Self { + // LLVM intrinsics always use the C calling convention, because + // they are implemented in C libraries + Self { + typ: fn_type, + call_conv: C_CALL_CONV, + cconv_sret_parameter: None, } } } @@ -6357,27 +6447,19 @@ fn build_foreign_symbol<'a, 'ctx, 'env>( arguments.push(value); } - let cc_type = cc_return.to_signature(env, return_type, cc_argument_types.as_slice()); + let cc_type = + FunctionSpec::cconv(env, cc_return, Some(return_type), &cc_argument_types); let cc_function = get_foreign_symbol(env, foreign.clone(), cc_type); - let fastcc_type = match roc_return { - RocReturn::Return => { - return_type.fn_type(&function_arguments(env, &fastcc_argument_types), false) - } - RocReturn::ByPointer => { - fastcc_argument_types.push(return_type.ptr_type(AddressSpace::Generic).into()); - env.context - .void_type() - .fn_type(&function_arguments(env, &fastcc_argument_types), false) - } - }; + let fastcc_type = + FunctionSpec::fastcc(env, roc_return, return_type, fastcc_argument_types); let fastcc_function = add_func( + env.context, env.module, &fastcc_function_name, fastcc_type, Linkage::Internal, - FAST_CALL_CONV, ); let old = builder.get_insert_block().unwrap(); @@ -7433,7 +7515,7 @@ fn throw_exception<'a, 'ctx, 'env>(env: &Env<'a, 'ctx, 'env>, message: &str) { fn get_foreign_symbol<'a, 'ctx, 'env>( env: &Env<'a, 'ctx, 'env>, foreign_symbol: roc_module::ident::ForeignSymbol, - function_type: FunctionType<'ctx>, + function_spec: FunctionSpec<'ctx>, ) -> FunctionValue<'ctx> { let module = env.module; @@ -7441,11 +7523,11 @@ fn get_foreign_symbol<'a, 'ctx, 'env>( Some(gvalue) => gvalue, None => { let foreign_function = add_func( + env.context, module, foreign_symbol.as_str(), - function_type, + function_spec, Linkage::External, - C_CALL_CONV, ); foreign_function @@ -7457,11 +7539,11 @@ fn get_foreign_symbol<'a, 'ctx, 'env>( /// We never want to define the same function twice in the same module! /// The result can be bugs that are difficult to track down. pub fn add_func<'ctx>( + ctx: &Context, module: &Module<'ctx>, name: &str, - typ: FunctionType<'ctx>, + spec: FunctionSpec<'ctx>, linkage: Linkage, - call_conv: u32, ) -> FunctionValue<'ctx> { if cfg!(debug_assertions) { if let Some(func) = module.get_function(name) { @@ -7469,9 +7551,9 @@ pub fn add_func<'ctx>( } } - let fn_val = module.add_function(name, typ, Some(linkage)); + let fn_val = module.add_function(name, spec.typ, Some(linkage)); - fn_val.set_call_conventions(call_conv); + spec.attach_attributes(ctx, fn_val); fn_val } diff --git a/compiler/gen_llvm/src/llvm/externs.rs b/compiler/gen_llvm/src/llvm/externs.rs index 889a0edd3b..055c0f8712 100644 --- a/compiler/gen_llvm/src/llvm/externs.rs +++ b/compiler/gen_llvm/src/llvm/externs.rs @@ -1,6 +1,7 @@ -use crate::llvm::build::Env; use crate::llvm::build::{add_func, C_CALL_CONV}; +use crate::llvm::build::{CCReturn, Env, FunctionSpec}; use inkwell::module::Linkage; +use inkwell::types::BasicType; use inkwell::values::BasicValue; use inkwell::AddressSpace; @@ -82,21 +83,18 @@ pub fn add_default_roc_externs(env: &Env<'_, '_, '_>) { // roc_realloc { let libc_realloc_val = { - let fn_val = add_func( - module, - "realloc", - i8_ptr_type.fn_type( - &[ - // ptr: *void - i8_ptr_type.into(), - // size: usize - usize_type.into(), - ], - false, - ), - Linkage::External, - C_CALL_CONV, + let fn_spec = FunctionSpec::cconv( + env, + CCReturn::Return, + Some(i8_ptr_type.as_basic_type_enum()), + &[ + // ptr: *void + i8_ptr_type.into(), + // size: usize + usize_type.into(), + ], ); + let fn_val = add_func(env.context, module, "realloc", fn_spec, Linkage::External); let mut params = fn_val.get_param_iter(); let ptr_arg = params.next().unwrap(); diff --git a/compiler/gen_llvm/src/llvm/refcounting.rs b/compiler/gen_llvm/src/llvm/refcounting.rs index 504d59b96a..efc9d9bfa5 100644 --- a/compiler/gen_llvm/src/llvm/refcounting.rs +++ b/compiler/gen_llvm/src/llvm/refcounting.rs @@ -18,7 +18,7 @@ use roc_module::symbol::Interns; use roc_module::symbol::Symbol; use roc_mono::layout::{Builtin, Layout, LayoutIds, UnionLayout}; -use super::build::load_roc_value; +use super::build::{load_roc_value, FunctionSpec}; use super::convert::{argument_type_from_layout, argument_type_from_union_layout}; pub struct PointerToRefcount<'ctx> { @@ -143,11 +143,11 @@ impl<'ctx> PointerToRefcount<'ctx> { ); let function_value = add_func( + env.context, env.module, fn_name, - fn_type, + FunctionSpec::known_fastcc(fn_type), Linkage::Internal, - FAST_CALL_CONV, // Because it's an internal-only function, it should use the fast calling convention. ); let subprogram = env.new_subprogram(fn_name); @@ -1138,11 +1138,11 @@ pub fn build_header_help<'a, 'ctx, 'env>( }; let fn_val = add_func( + env.context, env.module, fn_name, - fn_type, + FunctionSpec::known_fastcc(fn_type), Linkage::Private, - FAST_CALL_CONV, // Because it's an internal-only function, it should use the fast calling convention. ); let subprogram = env.new_subprogram(fn_name); From fae4a8c9f88d7945225a9d935187385c6e86b1a0 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 26 Apr 2022 17:43:17 -0400 Subject: [PATCH 610/846] Never really liked paperclips --- compiler/gen_llvm/src/llvm/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/gen_llvm/src/llvm/build.rs b/compiler/gen_llvm/src/llvm/build.rs index db8961c2d6..ee0f07f57b 100644 --- a/compiler/gen_llvm/src/llvm/build.rs +++ b/compiler/gen_llvm/src/llvm/build.rs @@ -6352,7 +6352,7 @@ impl<'ctx> FunctionSpec<'ctx> { } } - pub fn known_fastcc<'a, 'env>(fn_type: FunctionType<'ctx>) -> FunctionSpec<'ctx> { + pub fn known_fastcc(fn_type: FunctionType<'ctx>) -> FunctionSpec<'ctx> { Self { typ: fn_type, call_conv: FAST_CALL_CONV, From d18c46550fb19a0fef24117d799246464a1380dc Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 27 Apr 2022 01:28:31 +0200 Subject: [PATCH 611/846] fix test building --- compiler/can/tests/helpers/mod.rs | 9 +-------- compiler/solve/tests/solve_expr.rs | 6 +++--- reporting/tests/helpers/mod.rs | 9 +-------- 3 files changed, 5 insertions(+), 19 deletions(-) diff --git a/compiler/can/tests/helpers/mod.rs b/compiler/can/tests/helpers/mod.rs index f37d6a9190..151a248ead 100644 --- a/compiler/can/tests/helpers/mod.rs +++ b/compiler/can/tests/helpers/mod.rs @@ -74,14 +74,7 @@ pub fn can_expr_with(arena: &Bump, home: ModuleId, expr_str: &str) -> CanExprOut &loc_expr.value, ); - let mut all_ident_ids = MutMap::default(); - - // When pretty printing types, we may need the exposed builtins, - // so include them in the Interns we'll ultimately return. - for (module_id, ident_ids) in IdentIds::exposed_builtins(0) { - all_ident_ids.insert(module_id, ident_ids); - } - + let mut all_ident_ids = IdentIds::exposed_builtins(1); all_ident_ids.insert(home, env.ident_ids); let interns = Interns { diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index ecf4ea4058..7c9f9fec11 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -314,11 +314,11 @@ mod solve_expr { .into_iter() .map(|(member, typ)| { let member_data = abilities_store.member_def(member).unwrap(); - let member_str = member.ident_str(&interns).as_str(); - let ability_str = member_data.parent_ability.ident_str(&interns).as_str(); + let member_str = member.as_str(&interns); + let ability_str = member_data.parent_ability.as_str(&interns); ( format!("{}:{}", ability_str, member_str), - typ.ident_str(&interns).as_str(), + typ.as_str(&interns), ) }) .collect::>(); diff --git a/reporting/tests/helpers/mod.rs b/reporting/tests/helpers/mod.rs index 269e0598ff..09ad346648 100644 --- a/reporting/tests/helpers/mod.rs +++ b/reporting/tests/helpers/mod.rs @@ -183,14 +183,7 @@ pub fn can_expr_with<'a>( let constraint = introduce_builtin_imports(&mut constraints, imports, constraint, &mut var_store); - let mut all_ident_ids = MutMap::default(); - - // When pretty printing types, we may need the exposed builtins, - // so include them in the Interns we'll ultimately return. - for (module_id, ident_ids) in IdentIds::exposed_builtins(0) { - all_ident_ids.insert(module_id, ident_ids); - } - + let mut all_ident_ids = IdentIds::exposed_builtins(1); all_ident_ids.insert(home, env.ident_ids); let interns = Interns { From bb180db30f9646876ca3ec1ca229bc5c3c4b4ce4 Mon Sep 17 00:00:00 2001 From: Ayaz <20735482+ayazhafiz@users.noreply.github.com> Date: Tue, 26 Apr 2022 22:42:17 -0400 Subject: [PATCH 612/846] Fix a typo from AArch64-related bugfix --- compiler/gen_llvm/src/llvm/build.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/gen_llvm/src/llvm/build.rs b/compiler/gen_llvm/src/llvm/build.rs index ee0f07f57b..4b9989c3dd 100644 --- a/compiler/gen_llvm/src/llvm/build.rs +++ b/compiler/gen_llvm/src/llvm/build.rs @@ -6270,8 +6270,8 @@ pub struct FunctionSpec<'ctx> { /// We only care about this for C-call-conv functions, because this may take /// ownership of a register due to the convention. For example, on AArch64, /// values returned-by-pointer use the x8 register. - /// But for internal functions we need to worry about that and we don't want - /// that, since it might eat a register and cause a spill! + /// But for internal functions we don't need to worry about that and we don't + /// the convention, since it might eat a register and cause a spill! cconv_sret_parameter: Option, } From b8ad2aedb4a889972d049fac54a8752cb51ca094 Mon Sep 17 00:00:00 2001 From: Ayaz <20735482+ayazhafiz@users.noreply.github.com> Date: Tue, 26 Apr 2022 22:43:04 -0400 Subject: [PATCH 613/846] Update build.rs --- compiler/gen_llvm/src/llvm/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/gen_llvm/src/llvm/build.rs b/compiler/gen_llvm/src/llvm/build.rs index 4b9989c3dd..219ca9a4e2 100644 --- a/compiler/gen_llvm/src/llvm/build.rs +++ b/compiler/gen_llvm/src/llvm/build.rs @@ -6271,7 +6271,7 @@ pub struct FunctionSpec<'ctx> { /// ownership of a register due to the convention. For example, on AArch64, /// values returned-by-pointer use the x8 register. /// But for internal functions we don't need to worry about that and we don't - /// the convention, since it might eat a register and cause a spill! + /// want the convention, since it might eat a register and cause a spill! cconv_sret_parameter: Option, } From b2f3ff0c3be6935699e0a3fd48637f4039bbec23 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 27 Apr 2022 11:37:57 +0200 Subject: [PATCH 614/846] fix bug with updating strings giving incorrect results --- .../collections/src/small_string_interner.rs | 58 ++++++++++++++++--- compiler/module/src/symbol.rs | 19 ++---- 2 files changed, 54 insertions(+), 23 deletions(-) diff --git a/compiler/collections/src/small_string_interner.rs b/compiler/collections/src/small_string_interner.rs index 0da3c7dad5..fd9cfe734b 100644 --- a/compiler/collections/src/small_string_interner.rs +++ b/compiler/collections/src/small_string_interner.rs @@ -1,5 +1,5 @@ /// Collection of small (length < 256) strings, stored compactly. -#[derive(Clone, Debug, Default, PartialEq, Eq)] +#[derive(Clone, Default, PartialEq, Eq)] pub struct SmallStringInterner { buffer: Vec, @@ -7,6 +7,19 @@ pub struct SmallStringInterner { offsets: Vec, } +impl std::fmt::Debug for SmallStringInterner { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let strings: Vec<_> = self.iter().collect(); + + f.debug_struct("SmallStringInterner") + .field("buffer", &self.buffer) + .field("lengths", &self.lengths) + .field("offsets", &self.offsets) + .field("strings", &strings) + .finish() + } +} + impl SmallStringInterner { pub fn with_capacity(capacity: usize) -> Self { Self { @@ -31,17 +44,19 @@ impl SmallStringInterner { } pub fn insert(&mut self, string: &str) -> usize { - assert!(string.len() < u8::MAX as usize); + let bytes = string.as_bytes(); + + assert!(bytes.len() < u8::MAX as usize); let offset = self.buffer.len() as u32; - let length = string.len() as u8; + let length = bytes.len() as u8; let index = self.lengths.len(); self.lengths.push(length); self.offsets.push(offset); - self.buffer.extend(string.bytes()); + self.buffer.extend(bytes); index } @@ -71,17 +86,17 @@ impl SmallStringInterner { pub fn find_index(&self, string: &str) -> Option { let target_length = string.len() as u8; - let mut offset = 0; + // there can be gaps in the parts of the string that we use (because of updates) + // hence we can't just sum the lengths we've seen so far to get the next offset for (index, length) in self.lengths.iter().enumerate() { if *length == target_length { - let slice = &self.buffer[offset..][..*length as usize]; + let offset = self.offsets[index]; + let slice = &self.buffer[offset as usize..][..*length as usize]; if string.as_bytes() == slice { return Some(index); } } - - offset += *length as usize; } None @@ -115,4 +130,31 @@ impl SmallStringInterner { self.lengths[index] = length as u8; self.offsets[index] = offset as u32; } + + pub fn find_and_update(&mut self, old_string: &str, new_string: &str) -> Option { + match self.find_index(old_string) { + Some(index) => { + self.update(index, new_string); + + Some(index) + } + None => None, + } + } +} + +#[cfg(test)] +mod test { + use super::SmallStringInterner; + + #[test] + fn update_key() { + let mut interner = SmallStringInterner::default(); + + interner.insert("main"); + interner.insert("a"); + interner.find_and_update("a", "ab"); + interner.insert("c"); + assert!(interner.find_and_update("c", "cd").is_some()); + } } diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index c69571b779..d8bf11b8f4 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -549,21 +549,10 @@ impl IdentIds { // necessary when the name of a value is changed in the editor // TODO fix when same ident_name is present multiple times, see issue #2548 - pub fn update_key( - &mut self, - old_ident_name: &str, - new_ident_name: &str, - ) -> Result { - match self.interner.find_index(old_ident_name) { - Some(index) => { - self.interner.update(index, new_ident_name); - - Ok(IdentId(index as u32)) - } - None => Err(format!( - r"Tried to find position of key {:?} in IdentIds.by_id but I could not find the key", - old_ident_name - )), + pub fn update_key(&mut self, old_name: &str, new_name: &str) -> Result { + match self.interner.find_and_update(old_name, new_name) { + Some(index) => Ok(IdentId(index as u32)), + None => Err(format!("The identifier {:?} is not in IdentIds", old_name)), } } From 61d4d66f803a249a01d6447156a49b042948073b Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 27 Apr 2022 14:26:20 +0200 Subject: [PATCH 615/846] move to u16 again for lengths --- .../collections/src/small_string_interner.rs | 18 ++++++++++-------- compiler/module/src/symbol.rs | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/compiler/collections/src/small_string_interner.rs b/compiler/collections/src/small_string_interner.rs index fd9cfe734b..537398ea45 100644 --- a/compiler/collections/src/small_string_interner.rs +++ b/compiler/collections/src/small_string_interner.rs @@ -1,9 +1,11 @@ -/// Collection of small (length < 256) strings, stored compactly. +/// Collection of small (length < u16::MAX) strings, stored compactly. #[derive(Clone, Default, PartialEq, Eq)] pub struct SmallStringInterner { buffer: Vec, - lengths: Vec, + // lengths could be Vec, but the mono refcount generation + // stringifies Layout's and that creates > 256 character strings + lengths: Vec, offsets: Vec, } @@ -31,7 +33,7 @@ impl SmallStringInterner { } } - pub const fn from_parts(buffer: Vec, lengths: Vec, offsets: Vec) -> Self { + pub const fn from_parts(buffer: Vec, lengths: Vec, offsets: Vec) -> Self { Self { buffer, lengths, @@ -46,10 +48,10 @@ impl SmallStringInterner { pub fn insert(&mut self, string: &str) -> usize { let bytes = string.as_bytes(); - assert!(bytes.len() < u8::MAX as usize); + assert!(bytes.len() < u16::MAX as usize); let offset = self.buffer.len() as u32; - let length = bytes.len() as u8; + let length = bytes.len() as u16; let index = self.lengths.len(); @@ -76,7 +78,7 @@ impl SmallStringInterner { write!(self.buffer, "{}", index).unwrap(); let length = self.buffer.len() - offset; - self.lengths.push(length as u8); + self.lengths.push(length as u16); self.offsets.push(offset as u32); index @@ -84,7 +86,7 @@ impl SmallStringInterner { #[inline(always)] pub fn find_index(&self, string: &str) -> Option { - let target_length = string.len() as u8; + let target_length = string.len() as u16; // there can be gaps in the parts of the string that we use (because of updates) // hence we can't just sum the lengths we've seen so far to get the next offset @@ -127,7 +129,7 @@ impl SmallStringInterner { // `buffer`, we can update them in-place self.buffer.extend(new_string.bytes()); - self.lengths[index] = length as u8; + self.lengths[index] = length as u16; self.offsets[index] = offset as u32; } diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index d8bf11b8f4..9a7da7d51f 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -707,7 +707,7 @@ macro_rules! define_builtins { let ident_ids = { const TOTAL : usize = [ $($ident_name),+ ].len(); const NAMES : [ &str; TOTAL] = [ $($ident_name),+ ]; - const LENGTHS: [ u8; TOTAL] = [ $($ident_name.len() as u8),+ ]; + const LENGTHS: [ u16; TOTAL] = [ $($ident_name.len() as u16),+ ]; const OFFSETS: [ u32; TOTAL] = offset_helper([ $($ident_name.len() as u32),+ ]); const BUFFER: &str = concat!($($ident_name),+); From 443efc4eb86deb46df42f874edb26ab9fdf589bd Mon Sep 17 00:00:00 2001 From: Jared Cone Date: Sun, 24 Apr 2022 23:28:55 -0700 Subject: [PATCH 616/846] Handle ListEnd error --- reporting/src/error/parse.rs | 19 +++++++++++++++++++ reporting/tests/test_reporting.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/reporting/src/error/parse.rs b/reporting/src/error/parse.rs index 922ef4cf38..12e0ea1d9c 100644 --- a/reporting/src/error/parse.rs +++ b/reporting/src/error/parse.rs @@ -3415,6 +3415,25 @@ fn to_imports_report<'a>( } } + EImports::ListEnd(pos) => { + let surroundings = Region::new(start, pos); + let region = LineColumnRegion::from_pos(lines.convert_pos(pos)); + + let doc = alloc.stack([ + alloc.reflow(r"I am partway through parsing a imports list, but I got stuck here:"), + alloc.region_with_subregion(lines.convert_region(surroundings), region), + alloc.concat([alloc.reflow("I am expecting a comma or end of list, like")]), + alloc.parser_suggestion("imports [ Math, Util ]").indent(4), + ]); + + Report { + filename, + doc, + title: "WEIRD IMPORTS".to_string(), + severity: Severity::RuntimeError, + } + } + _ => todo!("unhandled parse error {:?}", parse_problem), } } diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 2436c2241f..e99f8b730c 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -9882,6 +9882,34 @@ I need all branches in an `if` to have the same type! ) } + fn imports_missing_comma() { + new_report_problem_as( + "imports_missing_comma", + indoc!( + r#" + app "test-missing-comma" + packages { pf: "platform" } + imports [ pf.Task Base64 ] + provides [ main, @Foo ] to pf + "# + ), + indoc!( + r#" + ── WEIRD IMPORTS ────────────────────────── tmp/imports_missing_comma/Test.roc ─ + + I am partway through parsing a imports list, but I got stuck here: + + 2│ packages { pf: "platform" } + 3│ imports [ pf.Task Base64 ] + ^ + + I am expecting a comma or end of list, like + + imports [ Math, Util ]"# + ), + ) + } + #[test] fn not_enough_cases_for_open_union() { new_report_problem_as( From 1649e13cf08772d977e0739ce7d2bd654d502a32 Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Wed, 27 Apr 2022 15:31:43 +0200 Subject: [PATCH 617/846] add additional assert Co-authored-by: Ayaz <20735482+ayazhafiz@users.noreply.github.com> --- compiler/collections/src/small_string_interner.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/collections/src/small_string_interner.rs b/compiler/collections/src/small_string_interner.rs index 537398ea45..e34a7b5241 100644 --- a/compiler/collections/src/small_string_interner.rs +++ b/compiler/collections/src/small_string_interner.rs @@ -155,7 +155,7 @@ mod test { interner.insert("main"); interner.insert("a"); - interner.find_and_update("a", "ab"); + assert!(interner.find_and_update("a", "ab").is_some()); interner.insert("c"); assert!(interner.find_and_update("c", "cd").is_some()); } From 7a53534d41cc16f693511cd20e24d5b5c05cad09 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 27 Apr 2022 16:14:15 +0200 Subject: [PATCH 618/846] rework how we filter captured symbols, and check for unused symbols --- compiler/can/src/expr.rs | 73 +++++++++++++++------------------------- 1 file changed, 28 insertions(+), 45 deletions(-) diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index ce46645be0..836d35467f 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -6,10 +6,10 @@ use crate::num::{ finish_parsing_base, finish_parsing_float, finish_parsing_num, float_expr_from_result, int_expr_from_result, num_expr_from_result, FloatBound, IntBound, NumericBound, }; -use crate::pattern::{canonicalize_pattern, Pattern}; +use crate::pattern::{bindings_from_patterns, canonicalize_pattern, Pattern}; use crate::procedure::References; use crate::scope::Scope; -use roc_collections::{MutSet, SendMap, VecMap, VecSet}; +use roc_collections::{SendMap, VecMap, VecSet}; use roc_module::called_via::CalledVia; use roc_module::ident::{ForeignSymbol, Lowercase, TagName}; use roc_module::low_level::LowLevel; @@ -682,6 +682,7 @@ pub fn canonicalize_expr<'a>( // rest of this block, but keep the original around for later diffing. let original_scope = scope; let mut scope = original_scope.clone(); + let mut can_args = Vec::with_capacity(loc_arg_patterns.len()); let mut output = Output::default(); @@ -699,8 +700,7 @@ pub fn canonicalize_expr<'a>( can_args.push((var_store.fresh(), can_argument_pattern)); } - let bound_by_argument_patterns: Vec<_> = - output.references.bound_symbols().copied().collect(); + let bound_by_argument_patterns = bindings_from_patterns(can_args.iter().map(|x| &x.1)); let (loc_body_expr, new_output) = canonicalize_expr( env, @@ -710,50 +710,38 @@ pub fn canonicalize_expr<'a>( &loc_body_expr.value, ); - let mut captured_symbols: MutSet = - new_output.references.value_lookups().copied().collect(); - - // filter out the closure's name itself - captured_symbols.remove(&symbol); - - // symbols bound either in this pattern or deeper down are not captured! - captured_symbols.retain(|s| !new_output.references.bound_symbols().any(|x| x == s)); - captured_symbols.retain(|s| !bound_by_argument_patterns.contains(s)); - - // filter out top-level symbols - // those will be globally available, and don't need to be captured - captured_symbols.retain(|s| !env.top_level_symbols.contains(s)); - - // filter out imported symbols - // those will be globally available, and don't need to be captured - captured_symbols.retain(|s| s.module_id() == env.home); - - // TODO any Closure that has an empty `captured_symbols` list could be excluded! + let mut captured_symbols: Vec<_> = new_output + .references + .value_lookups() + .copied() + // filter out the closure's name itself + .filter(|s| *s != symbol) + // symbols bound either in this pattern or deeper down are not captured! + .filter(|s| !new_output.references.bound_symbols().any(|x| x == s)) + .filter(|s| bound_by_argument_patterns.iter().all(|(k, _)| s != k)) + // filter out top-level symbols those will be globally available, and don't need to be captured + .filter(|s| !env.top_level_symbols.contains(s)) + // filter out imported symbols those will be globally available, and don't need to be captured + .filter(|s| s.module_id() == env.home) + // filter out functions that don't close over anything + .filter(|s| !new_output.non_closures.contains(s)) + .filter(|s| !output.non_closures.contains(s)) + .map(|s| (s, var_store.fresh())) + .collect(); output.union(new_output); - // filter out aliases - debug_assert!(captured_symbols - .iter() - .all(|s| !output.references.references_type_def(*s))); - // captured_symbols.retain(|s| !output.references.referenced_type_defs.contains(s)); - - // filter out functions that don't close over anything - captured_symbols.retain(|s| !output.non_closures.contains(s)); - // Now that we've collected all the references, check to see if any of the args we defined // went unreferenced. If any did, report them as unused arguments. - for (sub_symbol, region) in scope.symbols() { - if !original_scope.contains_symbol(*sub_symbol) { - if !output.references.has_value_lookup(*sub_symbol) { - // The body never referenced this argument we declared. It's an unused argument! - env.problem(Problem::UnusedArgument(symbol, *sub_symbol, *region)); - } - + for (sub_symbol, region) in bound_by_argument_patterns { + if !output.references.has_value_lookup(sub_symbol) { + // The body never referenced this argument we declared. It's an unused argument! + env.problem(Problem::UnusedArgument(symbol, sub_symbol, region)); + } else { // We shouldn't ultimately count arguments as referenced locals. Otherwise, // we end up with weird conclusions like the expression (\x -> x + 1) // references the (nonexistent) local variable x! - output.references.remove_value_lookup(sub_symbol); + output.references.remove_value_lookup(&sub_symbol); } } @@ -761,11 +749,6 @@ pub fn canonicalize_expr<'a>( // when we canonicalize a surrounding def (if it exists) env.closures.insert(symbol, output.references.clone()); - let mut captured_symbols: Vec<_> = captured_symbols - .into_iter() - .map(|s| (s, var_store.fresh())) - .collect(); - // sort symbols, so we know the order in which they're stored in the closure record captured_symbols.sort(); From c65f90b8c5a6bfabce5cae8849278a439ecefe9b Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 27 Apr 2022 16:22:00 +0200 Subject: [PATCH 619/846] refactor closure canonicalization --- compiler/can/src/expr.rs | 218 +++++++++++++++++++++------------------ 1 file changed, 115 insertions(+), 103 deletions(-) diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index 836d35467f..5a0c404ed0 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -668,110 +668,10 @@ pub fn canonicalize_expr<'a>( unreachable!("Backpassing should have been desugared by now") } ast::Expr::Closure(loc_arg_patterns, loc_body_expr) => { - // The globally unique symbol that will refer to this closure once it gets converted - // into a top-level procedure for code gen. - // - // In the Foo module, this will look something like Foo.$1 or Foo.$2. - let symbol = env - .closure_name_symbol - .unwrap_or_else(|| env.gen_unique_symbol()); - env.closure_name_symbol = None; + let (closure_data, output) = + canonicalize_closure(env, var_store, scope, loc_arg_patterns, loc_body_expr); - // The body expression gets a new scope for canonicalization. - // Shadow `scope` to make sure we don't accidentally use the original one for the - // rest of this block, but keep the original around for later diffing. - let original_scope = scope; - let mut scope = original_scope.clone(); - - let mut can_args = Vec::with_capacity(loc_arg_patterns.len()); - let mut output = Output::default(); - - for loc_pattern in loc_arg_patterns.iter() { - let can_argument_pattern = canonicalize_pattern( - env, - var_store, - &mut scope, - &mut output, - FunctionArg, - &loc_pattern.value, - loc_pattern.region, - ); - - can_args.push((var_store.fresh(), can_argument_pattern)); - } - - let bound_by_argument_patterns = bindings_from_patterns(can_args.iter().map(|x| &x.1)); - - let (loc_body_expr, new_output) = canonicalize_expr( - env, - var_store, - &mut scope, - loc_body_expr.region, - &loc_body_expr.value, - ); - - let mut captured_symbols: Vec<_> = new_output - .references - .value_lookups() - .copied() - // filter out the closure's name itself - .filter(|s| *s != symbol) - // symbols bound either in this pattern or deeper down are not captured! - .filter(|s| !new_output.references.bound_symbols().any(|x| x == s)) - .filter(|s| bound_by_argument_patterns.iter().all(|(k, _)| s != k)) - // filter out top-level symbols those will be globally available, and don't need to be captured - .filter(|s| !env.top_level_symbols.contains(s)) - // filter out imported symbols those will be globally available, and don't need to be captured - .filter(|s| s.module_id() == env.home) - // filter out functions that don't close over anything - .filter(|s| !new_output.non_closures.contains(s)) - .filter(|s| !output.non_closures.contains(s)) - .map(|s| (s, var_store.fresh())) - .collect(); - - output.union(new_output); - - // Now that we've collected all the references, check to see if any of the args we defined - // went unreferenced. If any did, report them as unused arguments. - for (sub_symbol, region) in bound_by_argument_patterns { - if !output.references.has_value_lookup(sub_symbol) { - // The body never referenced this argument we declared. It's an unused argument! - env.problem(Problem::UnusedArgument(symbol, sub_symbol, region)); - } else { - // We shouldn't ultimately count arguments as referenced locals. Otherwise, - // we end up with weird conclusions like the expression (\x -> x + 1) - // references the (nonexistent) local variable x! - output.references.remove_value_lookup(&sub_symbol); - } - } - - // store the references of this function in the Env. This information is used - // when we canonicalize a surrounding def (if it exists) - env.closures.insert(symbol, output.references.clone()); - - // sort symbols, so we know the order in which they're stored in the closure record - captured_symbols.sort(); - - // store that this function doesn't capture anything. It will be promoted to a - // top-level function, and does not need to be captured by other surrounding functions. - if captured_symbols.is_empty() { - output.non_closures.insert(symbol); - } - - ( - Closure(ClosureData { - function_type: var_store.fresh(), - closure_type: var_store.fresh(), - closure_ext_var: var_store.fresh(), - return_type: var_store.fresh(), - name: symbol, - captured_symbols, - recursive: Recursive::NotRecursive, - arguments: can_args, - loc_body: Box::new(loc_body_expr), - }), - output, - ) + (Closure(closure_data), output) } ast::Expr::When(loc_cond, branches) => { // Infer the condition expression's type. @@ -1043,6 +943,118 @@ pub fn canonicalize_expr<'a>( ) } +pub fn canonicalize_closure<'a>( + env: &mut Env<'a>, + var_store: &mut VarStore, + scope: &mut Scope, + loc_arg_patterns: &'a [Loc>], + loc_body_expr: &'a Loc>, +) -> (ClosureData, Output) { + // The globally unique symbol that will refer to this closure once it gets converted + // into a top-level procedure for code gen. + // + // In the Foo module, this will look something like Foo.$1 or Foo.$2. + let symbol = env + .closure_name_symbol + .unwrap_or_else(|| env.gen_unique_symbol()); + env.closure_name_symbol = None; + + // The body expression gets a new scope for canonicalization. + // Shadow `scope` to make sure we don't accidentally use the original one for the + // rest of this block, but keep the original around for later diffing. + let original_scope = scope; + let mut scope = original_scope.clone(); + + let mut can_args = Vec::with_capacity(loc_arg_patterns.len()); + let mut output = Output::default(); + + for loc_pattern in loc_arg_patterns.iter() { + let can_argument_pattern = canonicalize_pattern( + env, + var_store, + &mut scope, + &mut output, + FunctionArg, + &loc_pattern.value, + loc_pattern.region, + ); + + can_args.push((var_store.fresh(), can_argument_pattern)); + } + + let bound_by_argument_patterns = bindings_from_patterns(can_args.iter().map(|x| &x.1)); + + let (loc_body_expr, new_output) = canonicalize_expr( + env, + var_store, + &mut scope, + loc_body_expr.region, + &loc_body_expr.value, + ); + + let mut captured_symbols: Vec<_> = new_output + .references + .value_lookups() + .copied() + // filter out the closure's name itself + .filter(|s| *s != symbol) + // symbols bound either in this pattern or deeper down are not captured! + .filter(|s| !new_output.references.bound_symbols().any(|x| x == s)) + .filter(|s| bound_by_argument_patterns.iter().all(|(k, _)| s != k)) + // filter out top-level symbols those will be globally available, and don't need to be captured + .filter(|s| !env.top_level_symbols.contains(s)) + // filter out imported symbols those will be globally available, and don't need to be captured + .filter(|s| s.module_id() == env.home) + // filter out functions that don't close over anything + .filter(|s| !new_output.non_closures.contains(s)) + .filter(|s| !output.non_closures.contains(s)) + .map(|s| (s, var_store.fresh())) + .collect(); + + output.union(new_output); + + // Now that we've collected all the references, check to see if any of the args we defined + // went unreferenced. If any did, report them as unused arguments. + for (sub_symbol, region) in bound_by_argument_patterns { + if !output.references.has_value_lookup(sub_symbol) { + // The body never referenced this argument we declared. It's an unused argument! + env.problem(Problem::UnusedArgument(symbol, sub_symbol, region)); + } else { + // We shouldn't ultimately count arguments as referenced locals. Otherwise, + // we end up with weird conclusions like the expression (\x -> x + 1) + // references the (nonexistent) local variable x! + output.references.remove_value_lookup(&sub_symbol); + } + } + + // store the references of this function in the Env. This information is used + // when we canonicalize a surrounding def (if it exists) + env.closures.insert(symbol, output.references.clone()); + + // sort symbols, so we know the order in which they're stored in the closure record + captured_symbols.sort(); + + // store that this function doesn't capture anything. It will be promoted to a + // top-level function, and does not need to be captured by other surrounding functions. + if captured_symbols.is_empty() { + output.non_closures.insert(symbol); + } + + let closure_data = ClosureData { + function_type: var_store.fresh(), + closure_type: var_store.fresh(), + closure_ext_var: var_store.fresh(), + return_type: var_store.fresh(), + name: symbol, + captured_symbols, + recursive: Recursive::NotRecursive, + arguments: can_args, + loc_body: Box::new(loc_body_expr), + }; + + (closure_data, output) +} + #[inline(always)] fn canonicalize_when_branch<'a>( env: &mut Env<'a>, From 41ee2c3e6ab176f452fb61e3e0c6acc13d14c36e Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 27 Apr 2022 16:38:53 +0200 Subject: [PATCH 620/846] unwrapping of an Opaque does not count as a binding of the opaque name --- compiler/can/src/pattern.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/compiler/can/src/pattern.rs b/compiler/can/src/pattern.rs index c35d214645..52ee8eaaed 100644 --- a/compiler/can/src/pattern.rs +++ b/compiler/can/src/pattern.rs @@ -682,12 +682,9 @@ fn add_bindings_from_patterns( add_bindings_from_patterns(&loc_arg.region, &loc_arg.value, answer); } } - UnwrappedOpaque { - argument, opaque, .. - } => { + UnwrappedOpaque { argument, .. } => { let (_, loc_arg) = &**argument; add_bindings_from_patterns(&loc_arg.region, &loc_arg.value, answer); - answer.push((*opaque, *region)); } RecordDestructure { destructs, .. } => { for Loc { From c28a0af9323ac8534a7aca20afe5ea08699ce571 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 27 Apr 2022 16:39:21 +0200 Subject: [PATCH 621/846] refactor: special-case the canonicalization of a Closure def --- compiler/can/src/def.rs | 94 ++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 53 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 982f88068a..6115566172 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1146,62 +1146,51 @@ fn canonicalize_pending_value_def<'a>( .introduced_variables .union(&type_annotation.introduced_variables); - // bookkeeping for tail-call detection. If we're assigning to an - // identifier (e.g. `f = \x -> ...`), then this symbol can be tail-called. - let outer_identifier = env.tailcallable_symbol; - - if let Pattern::Identifier(ref defined_symbol) = &loc_can_pattern.value { - env.tailcallable_symbol = Some(*defined_symbol); - }; - - // register the name of this closure, to make sure the closure won't capture it's own name - if let (Pattern::Identifier(ref defined_symbol), &ast::Expr::Closure(_, _)) = - (&loc_can_pattern.value, &loc_expr.value) - { - env.closure_name_symbol = Some(*defined_symbol); - }; - pattern_to_vars_by_symbol(&mut vars_by_symbol, &loc_can_pattern.value, expr_var); - let (mut loc_can_expr, can_output) = - canonicalize_expr(env, var_store, scope, loc_expr.region, &loc_expr.value); - - output.references.union_mut(&can_output.references); - - // reset the tailcallable_symbol - env.tailcallable_symbol = outer_identifier; - // First, make sure we are actually assigning an identifier instead of (for example) a tag. // // If we're assigning (UserId userId) = ... then this is certainly not a closure declaration, // which also implies it's not a self tail call! // // Only defs of the form (foo = ...) can be closure declarations or self tail calls. - - match (&loc_can_pattern.value, &loc_can_expr.value) { + match (&loc_can_pattern.value, &loc_expr.value) { ( Pattern::Identifier(symbol) | Pattern::AbilityMemberSpecialization { ident: symbol, .. }, - Closure(ClosureData { - function_type, - closure_type, - closure_ext_var, - return_type, - name: closure_name, - arguments, - loc_body: body, - captured_symbols, - .. - }), + ast::Expr::Closure(arguments, body), ) => { + // bookkeeping for tail-call detection. If we're assigning to an + // identifier (e.g. `f = \x -> ...`), then this symbol can be tail-called. + let outer_identifier = env.tailcallable_symbol; + + if let Pattern::Identifier(ref defined_symbol) = &loc_can_pattern.value { + env.tailcallable_symbol = Some(*defined_symbol); + }; + + // register the name of this closure, to make sure the closure won't capture it's own name + if let (Pattern::Identifier(ref defined_symbol), &ast::Expr::Closure(_, _)) = + (&loc_can_pattern.value, &loc_expr.value) + { + env.closure_name_symbol = Some(*defined_symbol); + }; + + let (mut closure_data, can_output) = + crate::expr::canonicalize_closure(env, var_store, scope, arguments, body); + + // reset the tailcallable_symbol + env.tailcallable_symbol = outer_identifier; + + output.references.union_mut(&can_output.references); + // Since everywhere in the code it'll be referred to by its defined name, // remove its generated name from the closure map. (We'll re-insert it later.) - let closure_references = env.closures.remove(closure_name).unwrap_or_else(|| { - panic!( - "Tried to remove symbol {:?} from procedures, but it was not found: {:?}", - closure_name, env.closures - ) - }); + let closure_references = env.closures.remove(&closure_data.name).unwrap_or_else(|| { + panic!( + "Tried to remove symbol {:?} from procedures, but it was not found: {:?}", + closure_data.name, env.closures + ) + }); // The closure is self tail recursive iff it tail calls itself (by defined name). let is_recursive = match can_output.tail_call { @@ -1209,17 +1198,10 @@ fn canonicalize_pending_value_def<'a>( _ => Recursive::NotRecursive, }; - loc_can_expr.value = Closure(ClosureData { - function_type: *function_type, - closure_type: *closure_type, - closure_ext_var: *closure_ext_var, - return_type: *return_type, - name: *symbol, - captured_symbols: captured_symbols.clone(), - recursive: is_recursive, - arguments: arguments.clone(), - loc_body: body.clone(), - }); + closure_data.recursive = is_recursive; + closure_data.name = *symbol; + + let loc_can_expr = Loc::at(loc_expr.region, Expr::Closure(closure_data)); let def = single_can_def( loc_can_pattern, @@ -1237,7 +1219,13 @@ fn canonicalize_pending_value_def<'a>( def, } } + _ => { + let (loc_can_expr, can_output) = + canonicalize_expr(env, var_store, scope, loc_expr.region, &loc_expr.value); + + output.references.union_mut(&can_output.references); + let refs = can_output.references.clone(); let def = single_can_def( From 6783b66db70b20baf49a0054e963cf2424b11ce1 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 27 Apr 2022 16:44:29 +0200 Subject: [PATCH 622/846] stop using env.closures --- compiler/can/src/def.rs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 6115566172..f41b8cd377 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1181,17 +1181,9 @@ fn canonicalize_pending_value_def<'a>( // reset the tailcallable_symbol env.tailcallable_symbol = outer_identifier; + let closure_references = can_output.references.clone(); output.references.union_mut(&can_output.references); - // Since everywhere in the code it'll be referred to by its defined name, - // remove its generated name from the closure map. (We'll re-insert it later.) - let closure_references = env.closures.remove(&closure_data.name).unwrap_or_else(|| { - panic!( - "Tried to remove symbol {:?} from procedures, but it was not found: {:?}", - closure_data.name, env.closures - ) - }); - // The closure is self tail recursive iff it tail calls itself (by defined name). let is_recursive = match can_output.tail_call { Some(tail_symbol) if tail_symbol == *symbol => Recursive::TailRecursive, From 465fad9da1035da324cfdb6b9e433f4702de06fd Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 27 Apr 2022 17:01:18 +0200 Subject: [PATCH 623/846] refactor it all again --- compiler/can/src/def.rs | 298 +++++++++++++++------------------------- 1 file changed, 109 insertions(+), 189 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index f41b8cd377..17bdc0487e 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1020,12 +1020,12 @@ fn canonicalize_pending_value_def<'a>( ) -> DefOutput { use PendingValueDef::*; - // Make types for the body expr, even if we won't end up having a body. - let expr_var = var_store.fresh(); - let mut vars_by_symbol = SendMap::default(); - match pending_def { AnnotationOnly(_, loc_can_pattern, loc_ann) => { + // Make types for the body expr, even if we won't end up having a body. + let expr_var = var_store.fresh(); + let mut vars_by_symbol = SendMap::default(); + // annotation sans body cannot introduce new rigids that are visible in other annotations // but the rigids can show up in type error messages, so still register them let type_annotation = canonicalize_annotation( @@ -1146,210 +1146,130 @@ fn canonicalize_pending_value_def<'a>( .introduced_variables .union(&type_annotation.introduced_variables); - pattern_to_vars_by_symbol(&mut vars_by_symbol, &loc_can_pattern.value, expr_var); - - // First, make sure we are actually assigning an identifier instead of (for example) a tag. - // - // If we're assigning (UserId userId) = ... then this is certainly not a closure declaration, - // which also implies it's not a self tail call! - // - // Only defs of the form (foo = ...) can be closure declarations or self tail calls. - match (&loc_can_pattern.value, &loc_expr.value) { - ( - Pattern::Identifier(symbol) - | Pattern::AbilityMemberSpecialization { ident: symbol, .. }, - ast::Expr::Closure(arguments, body), - ) => { - // bookkeeping for tail-call detection. If we're assigning to an - // identifier (e.g. `f = \x -> ...`), then this symbol can be tail-called. - let outer_identifier = env.tailcallable_symbol; - - if let Pattern::Identifier(ref defined_symbol) = &loc_can_pattern.value { - env.tailcallable_symbol = Some(*defined_symbol); - }; - - // register the name of this closure, to make sure the closure won't capture it's own name - if let (Pattern::Identifier(ref defined_symbol), &ast::Expr::Closure(_, _)) = - (&loc_can_pattern.value, &loc_expr.value) - { - env.closure_name_symbol = Some(*defined_symbol); - }; - - let (mut closure_data, can_output) = - crate::expr::canonicalize_closure(env, var_store, scope, arguments, body); - - // reset the tailcallable_symbol - env.tailcallable_symbol = outer_identifier; - - let closure_references = can_output.references.clone(); - output.references.union_mut(&can_output.references); - - // The closure is self tail recursive iff it tail calls itself (by defined name). - let is_recursive = match can_output.tail_call { - Some(tail_symbol) if tail_symbol == *symbol => Recursive::TailRecursive, - _ => Recursive::NotRecursive, - }; - - closure_data.recursive = is_recursive; - closure_data.name = *symbol; - - let loc_can_expr = Loc::at(loc_expr.region, Expr::Closure(closure_data)); - - let def = single_can_def( - loc_can_pattern, - loc_can_expr, - expr_var, - Some(Loc::at(loc_ann.region, type_annotation)), - vars_by_symbol.clone(), - ); - - output.union(can_output); - - DefOutput { - output, - references: DefReferences::Function(closure_references), - def, - } - } - - _ => { - let (loc_can_expr, can_output) = - canonicalize_expr(env, var_store, scope, loc_expr.region, &loc_expr.value); - - output.references.union_mut(&can_output.references); - - let refs = can_output.references.clone(); - - let def = single_can_def( - loc_can_pattern, - loc_can_expr, - expr_var, - Some(Loc::at(loc_ann.region, type_annotation)), - vars_by_symbol.clone(), - ); - - output.union(can_output); - - DefOutput { - output, - references: DefReferences::Value(refs), - def, - } - } - } + canonicalize_pending_body( + env, + output, + scope, + var_store, + loc_can_pattern, + loc_expr, + Some(Loc::at(loc_ann.region, type_annotation)), + ) } - // If we have a pattern, then the def has a body (that is, it's not a - // standalone annotation), so we need to canonicalize the pattern and expr. - Body(loc_pattern, loc_can_pattern, loc_expr) => { + Body(_loc_pattern, loc_can_pattern, loc_expr) => { + // + canonicalize_pending_body( + env, + output, + scope, + var_store, + loc_can_pattern, + loc_expr, + None, + ) + } + } +} + +// TODO trim down these arguments! +#[allow(clippy::too_many_arguments)] +#[allow(clippy::cognitive_complexity)] +fn canonicalize_pending_body<'a>( + env: &mut Env<'a>, + mut output: Output, + scope: &mut Scope, + var_store: &mut VarStore, + + loc_can_pattern: Loc, + loc_expr: &'a Loc, + + opt_loc_annotation: Option>, +) -> DefOutput { + // Make types for the body expr, even if we won't end up having a body. + let expr_var = var_store.fresh(); + let mut vars_by_symbol = SendMap::default(); + + pattern_to_vars_by_symbol(&mut vars_by_symbol, &loc_can_pattern.value, expr_var); + + // First, make sure we are actually assigning an identifier instead of (for example) a tag. + // + // If we're assigning (UserId userId) = ... then this is certainly not a closure declaration, + // which also implies it's not a self tail call! + // + // Only defs of the form (foo = ...) can be closure declarations or self tail calls. + match (&loc_can_pattern.value, &loc_expr.value) { + ( + Pattern::Identifier(defined_symbol) + | Pattern::AbilityMemberSpecialization { + ident: defined_symbol, + .. + }, + ast::Expr::Closure(arguments, body), + ) => { // bookkeeping for tail-call detection. If we're assigning to an // identifier (e.g. `f = \x -> ...`), then this symbol can be tail-called. let outer_identifier = env.tailcallable_symbol; - - if let (&ast::Pattern::Identifier(_name), &Pattern::Identifier(ref defined_symbol)) = - (&loc_pattern.value, &loc_can_pattern.value) - { - env.tailcallable_symbol = Some(*defined_symbol); - - // TODO isn't types_by_symbol enough? Do we need vars_by_symbol too? - vars_by_symbol.insert(*defined_symbol, expr_var); - }; + env.tailcallable_symbol = Some(*defined_symbol); // register the name of this closure, to make sure the closure won't capture it's own name - if let (Pattern::Identifier(ref defined_symbol), &ast::Expr::Closure(_, _)) = - (&loc_can_pattern.value, &loc_expr.value) - { - env.closure_name_symbol = Some(*defined_symbol); - }; + env.closure_name_symbol = Some(*defined_symbol); - let (mut loc_can_expr, can_output) = - canonicalize_expr(env, var_store, scope, loc_expr.region, &loc_expr.value); + let (mut closure_data, can_output) = + crate::expr::canonicalize_closure(env, var_store, scope, arguments, body); // reset the tailcallable_symbol env.tailcallable_symbol = outer_identifier; - // First, make sure we are actually assigning an identifier instead of (for example) a tag. - // - // If we're assigning (UserId userId) = ... then this is certainly not a closure declaration, - // which also implies it's not a self tail call! - // - // Only defs of the form (foo = ...) can be closure declarations or self tail calls. - match (&loc_can_pattern.value, &loc_can_expr.value) { - ( - Pattern::Identifier(symbol), - Closure(ClosureData { - function_type, - closure_type, - closure_ext_var, - return_type, - name: closure_name, - arguments, - loc_body: body, - captured_symbols, - .. - }), - ) => { - // Since everywhere in the code it'll be referred to by its defined name, - // remove its generated name from the closure map. (We'll re-insert it later.) - let closure_references = env.closures.remove(closure_name).unwrap_or_else(|| { - panic!( - "Tried to remove symbol {:?} from procedures, but it was not found: {:?}", - closure_name, env.closures - ) - }); + let closure_references = can_output.references.clone(); + output.references.union_mut(&can_output.references); - // The closure is self tail recursive iff it tail calls itself (by defined name). - let is_recursive = match can_output.tail_call { - Some(tail_symbol) if tail_symbol == *symbol => Recursive::TailRecursive, - _ => Recursive::NotRecursive, - }; + // The closure is self tail recursive iff it tail calls itself (by defined name). + let is_recursive = match can_output.tail_call { + Some(tail_symbol) if tail_symbol == *defined_symbol => Recursive::TailRecursive, + _ => Recursive::NotRecursive, + }; - loc_can_expr.value = Closure(ClosureData { - function_type: *function_type, - closure_type: *closure_type, - closure_ext_var: *closure_ext_var, - return_type: *return_type, - name: *symbol, - captured_symbols: captured_symbols.clone(), - recursive: is_recursive, - arguments: arguments.clone(), - loc_body: body.clone(), - }); + closure_data.recursive = is_recursive; + closure_data.name = *defined_symbol; - let def = single_can_def( - loc_can_pattern, - loc_can_expr, - expr_var, - None, - vars_by_symbol.clone(), - ); + let loc_can_expr = Loc::at(loc_expr.region, Expr::Closure(closure_data)); - output.union(can_output); + let def = single_can_def( + loc_can_pattern, + loc_can_expr, + expr_var, + opt_loc_annotation, + vars_by_symbol, + ); - DefOutput { - output, - references: DefReferences::Function(closure_references), - def, - } - } - _ => { - let refs = can_output.references.clone(); + output.union(can_output); - let def = single_can_def( - loc_can_pattern, - loc_can_expr, - expr_var, - None, - vars_by_symbol.clone(), - ); + DefOutput { + output, + references: DefReferences::Function(closure_references), + def, + } + } - output.union(can_output); + _ => { + let (loc_can_expr, can_output) = + canonicalize_expr(env, var_store, scope, loc_expr.region, &loc_expr.value); - DefOutput { - output, - references: DefReferences::Value(refs), - def, - } - } + let def = single_can_def( + loc_can_pattern, + loc_can_expr, + expr_var, + opt_loc_annotation, + vars_by_symbol, + ); + + let refs = can_output.references.clone(); + output.union(can_output); + + DefOutput { + output, + references: DefReferences::Value(refs), + def, } } } From 2973af5f79df608e5823bbfa5c34b9ae2cf90cbb Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 27 Apr 2022 17:11:33 +0200 Subject: [PATCH 624/846] get rid of env.closure_name_symbol --- compiler/can/src/def.rs | 17 +++++++++-------- compiler/can/src/env.rs | 4 ---- compiler/can/src/expr.rs | 10 +++------- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 17bdc0487e..9d2b013a1f 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1211,18 +1211,18 @@ fn canonicalize_pending_body<'a>( let outer_identifier = env.tailcallable_symbol; env.tailcallable_symbol = Some(*defined_symbol); - // register the name of this closure, to make sure the closure won't capture it's own name - env.closure_name_symbol = Some(*defined_symbol); - - let (mut closure_data, can_output) = - crate::expr::canonicalize_closure(env, var_store, scope, arguments, body); + let (mut closure_data, can_output) = crate::expr::canonicalize_closure( + env, + var_store, + scope, + arguments, + body, + Some(*defined_symbol), + ); // reset the tailcallable_symbol env.tailcallable_symbol = outer_identifier; - let closure_references = can_output.references.clone(); - output.references.union_mut(&can_output.references); - // The closure is self tail recursive iff it tail calls itself (by defined name). let is_recursive = match can_output.tail_call { Some(tail_symbol) if tail_symbol == *defined_symbol => Recursive::TailRecursive, @@ -1242,6 +1242,7 @@ fn canonicalize_pending_body<'a>( vars_by_symbol, ); + let closure_references = can_output.references.clone(); output.union(can_output); DefOutput { diff --git a/compiler/can/src/env.rs b/compiler/can/src/env.rs index 40523b2fb7..e5dfd2e6de 100644 --- a/compiler/can/src/env.rs +++ b/compiler/can/src/env.rs @@ -24,9 +24,6 @@ pub struct Env<'a> { /// current tail-callable symbol pub tailcallable_symbol: Option, - /// current closure name (if any) - pub closure_name_symbol: Option, - /// Symbols of values/functions which were referenced by qualified lookups. pub qualified_value_lookups: VecSet, @@ -57,7 +54,6 @@ impl<'a> Env<'a> { qualified_value_lookups: VecSet::default(), qualified_type_lookups: VecSet::default(), tailcallable_symbol: None, - closure_name_symbol: None, top_level_symbols: VecSet::default(), } } diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index 5a0c404ed0..f04548d147 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -669,7 +669,7 @@ pub fn canonicalize_expr<'a>( } ast::Expr::Closure(loc_arg_patterns, loc_body_expr) => { let (closure_data, output) = - canonicalize_closure(env, var_store, scope, loc_arg_patterns, loc_body_expr); + canonicalize_closure(env, var_store, scope, loc_arg_patterns, loc_body_expr, None); (Closure(closure_data), output) } @@ -949,15 +949,11 @@ pub fn canonicalize_closure<'a>( scope: &mut Scope, loc_arg_patterns: &'a [Loc>], loc_body_expr: &'a Loc>, + opt_def_name: Option, ) -> (ClosureData, Output) { // The globally unique symbol that will refer to this closure once it gets converted // into a top-level procedure for code gen. - // - // In the Foo module, this will look something like Foo.$1 or Foo.$2. - let symbol = env - .closure_name_symbol - .unwrap_or_else(|| env.gen_unique_symbol()); - env.closure_name_symbol = None; + let symbol = opt_def_name.unwrap_or_else(|| env.gen_unique_symbol()); // The body expression gets a new scope for canonicalization. // Shadow `scope` to make sure we don't accidentally use the original one for the From 984ef53e75b7d1ae265fc7a2b76d314a8e65e5d7 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 27 Apr 2022 17:29:32 +0200 Subject: [PATCH 625/846] shaving off a couple more lines --- compiler/can/src/def.rs | 152 ++++++++++++++++++---------------------- 1 file changed, 70 insertions(+), 82 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 9d2b013a1f..a0929c6111 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1185,94 +1185,82 @@ fn canonicalize_pending_body<'a>( opt_loc_annotation: Option>, ) -> DefOutput { - // Make types for the body expr, even if we won't end up having a body. + // We treat closure definitions `foo = \a, b -> ...` differntly from other body expressions, + // because they need more bookkeeping (for tail calls, closure captures, etc.) + // + // Only defs of the form `foo = ...` can be closure declarations or self tail calls. + let (loc_can_expr, def_references) = { + match (&loc_can_pattern.value, &loc_expr.value) { + ( + Pattern::Identifier(defined_symbol) + | Pattern::AbilityMemberSpecialization { + ident: defined_symbol, + .. + }, + ast::Expr::Closure(arguments, body), + ) => { + // bookkeeping for tail-call detection. + let outer_tailcallable = env.tailcallable_symbol; + env.tailcallable_symbol = Some(*defined_symbol); + + let (mut closure_data, can_output) = crate::expr::canonicalize_closure( + env, + var_store, + scope, + arguments, + body, + Some(*defined_symbol), + ); + + // reset the tailcallable_symbol + env.tailcallable_symbol = outer_tailcallable; + + // The closure is self tail recursive iff it tail calls itself (by defined name). + let is_recursive = match can_output.tail_call { + Some(tail_symbol) if tail_symbol == *defined_symbol => Recursive::TailRecursive, + _ => Recursive::NotRecursive, + }; + + closure_data.recursive = is_recursive; + closure_data.name = *defined_symbol; + + let loc_can_expr = Loc::at(loc_expr.region, Expr::Closure(closure_data)); + + let def_references = DefReferences::Function(can_output.references.clone()); + output.union(can_output); + + (loc_can_expr, def_references) + } + + _ => { + let (loc_can_expr, can_output) = + canonicalize_expr(env, var_store, scope, loc_expr.region, &loc_expr.value); + + let def_references = DefReferences::Value(can_output.references.clone()); + output.union(can_output); + + (loc_can_expr, def_references) + } + } + }; + let expr_var = var_store.fresh(); let mut vars_by_symbol = SendMap::default(); pattern_to_vars_by_symbol(&mut vars_by_symbol, &loc_can_pattern.value, expr_var); - // First, make sure we are actually assigning an identifier instead of (for example) a tag. - // - // If we're assigning (UserId userId) = ... then this is certainly not a closure declaration, - // which also implies it's not a self tail call! - // - // Only defs of the form (foo = ...) can be closure declarations or self tail calls. - match (&loc_can_pattern.value, &loc_expr.value) { - ( - Pattern::Identifier(defined_symbol) - | Pattern::AbilityMemberSpecialization { - ident: defined_symbol, - .. - }, - ast::Expr::Closure(arguments, body), - ) => { - // bookkeeping for tail-call detection. If we're assigning to an - // identifier (e.g. `f = \x -> ...`), then this symbol can be tail-called. - let outer_identifier = env.tailcallable_symbol; - env.tailcallable_symbol = Some(*defined_symbol); + let def = single_can_def( + loc_can_pattern, + loc_can_expr, + expr_var, + opt_loc_annotation, + vars_by_symbol, + ); - let (mut closure_data, can_output) = crate::expr::canonicalize_closure( - env, - var_store, - scope, - arguments, - body, - Some(*defined_symbol), - ); - - // reset the tailcallable_symbol - env.tailcallable_symbol = outer_identifier; - - // The closure is self tail recursive iff it tail calls itself (by defined name). - let is_recursive = match can_output.tail_call { - Some(tail_symbol) if tail_symbol == *defined_symbol => Recursive::TailRecursive, - _ => Recursive::NotRecursive, - }; - - closure_data.recursive = is_recursive; - closure_data.name = *defined_symbol; - - let loc_can_expr = Loc::at(loc_expr.region, Expr::Closure(closure_data)); - - let def = single_can_def( - loc_can_pattern, - loc_can_expr, - expr_var, - opt_loc_annotation, - vars_by_symbol, - ); - - let closure_references = can_output.references.clone(); - output.union(can_output); - - DefOutput { - output, - references: DefReferences::Function(closure_references), - def, - } - } - - _ => { - let (loc_can_expr, can_output) = - canonicalize_expr(env, var_store, scope, loc_expr.region, &loc_expr.value); - - let def = single_can_def( - loc_can_pattern, - loc_can_expr, - expr_var, - opt_loc_annotation, - vars_by_symbol, - ); - - let refs = can_output.references.clone(); - output.union(can_output); - - DefOutput { - output, - references: DefReferences::Value(refs), - def, - } - } + DefOutput { + output, + references: def_references, + def, } } From 2d0a9c8531f5b35d3562e0d662806833abb34844 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 27 Apr 2022 17:57:42 +0200 Subject: [PATCH 626/846] stop scope diffing in when canonicalization --- compiler/can/src/expr.rs | 22 ++++++++-------------- compiler/can/src/pattern.rs | 15 +++++++++------ compiler/can/src/scope.rs | 4 ---- 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index f04548d147..2b78a814d0 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -1099,23 +1099,17 @@ fn canonicalize_when_branch<'a>( } }; - // Now that we've collected all the references for this branch, check to see if - // any of the new idents it defined were unused. If any were, report it. - for (symbol, region) in scope.symbols() { - let symbol = *symbol; - - if !output.references.has_type_or_value_lookup(symbol) - && !branch_output.references.has_type_or_value_lookup(symbol) - && !original_scope.contains_symbol(symbol) - && !scope.abilities_store.is_specialization_name(symbol) - { - env.problem(Problem::UnusedDef(symbol, *region)); - } - } - let references = branch_output.references.clone(); output.union(branch_output); + // Now that we've collected all the references for this branch, check to see if + // any of the new idents it defined were unused. If any were, report it. + for (symbol, region) in bindings_from_patterns(patterns.iter()) { + if !output.references.has_value_lookup(symbol) { + env.problem(Problem::UnusedDef(symbol, region)); + } + } + ( WhenBranch { patterns, diff --git a/compiler/can/src/pattern.rs b/compiler/can/src/pattern.rs index 52ee8eaaed..c83db68fac 100644 --- a/compiler/can/src/pattern.rs +++ b/compiler/can/src/pattern.rs @@ -687,12 +687,15 @@ fn add_bindings_from_patterns( add_bindings_from_patterns(&loc_arg.region, &loc_arg.value, answer); } RecordDestructure { destructs, .. } => { - for Loc { - region, - value: RecordDestruct { symbol, .. }, - } in destructs - { - answer.push((*symbol, *region)); + for loc_destruct in destructs { + match loc_destruct.value.typ { + DestructType::Required | DestructType::Optional(_, _) => { + answer.push((loc_destruct.value.symbol, loc_destruct.region)); + } + DestructType::Guard(_, _) => { + // a guard does not introduce the symbol + } + } } } NumLiteral(..) diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index b45b7eea6c..af3518067b 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -104,10 +104,6 @@ impl Scope { self.idents.contains_key(ident) } - pub fn contains_symbol(&self, symbol: Symbol) -> bool { - self.symbols.contains_key(&symbol) - } - pub fn num_idents(&self) -> usize { self.idents.len() } From 454aa17586bdeef7c1d8a827fcf88b23fa871093 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 27 Apr 2022 18:01:22 +0200 Subject: [PATCH 627/846] change where scope is cloned --- compiler/can/src/expr.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index 2b78a814d0..5faf11f645 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -685,8 +685,14 @@ pub fn canonicalize_expr<'a>( let mut can_branches = Vec::with_capacity(branches.len()); for branch in branches.iter() { - let (can_when_branch, branch_references) = - canonicalize_when_branch(env, var_store, scope, region, *branch, &mut output); + let (can_when_branch, branch_references) = canonicalize_when_branch( + env, + var_store, + scope.clone(), + region, + *branch, + &mut output, + ); output.references.union_mut(&branch_references); @@ -1055,16 +1061,13 @@ pub fn canonicalize_closure<'a>( fn canonicalize_when_branch<'a>( env: &mut Env<'a>, var_store: &mut VarStore, - scope: &mut Scope, + mut scope: Scope, _region: Region, branch: &'a ast::WhenBranch<'a>, output: &mut Output, ) -> (WhenBranch, References) { let mut patterns = Vec::with_capacity(branch.patterns.len()); - let original_scope = scope; - let mut scope = original_scope.clone(); - // TODO report symbols not bound in all patterns for loc_pattern in branch.patterns.iter() { let can_pattern = canonicalize_pattern( From b2656635153070d2ad395efeb588f5d84d626485 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 27 Apr 2022 18:44:06 +0200 Subject: [PATCH 628/846] reduce allocations in pattern iteration --- compiler/can/src/def.rs | 4 +- compiler/can/src/expr.rs | 7 +- compiler/can/src/pattern.rs | 129 +++++++++++++++++++++--------------- 3 files changed, 82 insertions(+), 58 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index a0929c6111..a621d50f23 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -5,7 +5,7 @@ use crate::env::Env; use crate::expr::ClosureData; use crate::expr::Expr::{self, *}; use crate::expr::{canonicalize_expr, Output, Recursive}; -use crate::pattern::{bindings_from_patterns, canonicalize_def_header_pattern, Pattern}; +use crate::pattern::{canonicalize_def_header_pattern, BindingsFromPattern, Pattern}; use crate::procedure::References; use crate::reference_matrix::ReferenceMatrix; use crate::scope::create_alias; @@ -478,7 +478,7 @@ pub(crate) fn canonicalize_defs<'a>( let mut symbol_to_index: Vec<(IdentId, u32)> = Vec::with_capacity(pending_value_defs.len()); for (def_index, pending_def) in pending_value_defs.iter().enumerate() { - for (s, r) in bindings_from_patterns(std::iter::once(pending_def.loc_pattern())) { + for (s, r) in BindingsFromPattern::new(pending_def.loc_pattern()) { // store the top-level defs, used to ensure that closures won't capture them if let PatternType::TopLevelDef = pattern_type { env.top_level_symbols.insert(s); diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index 5faf11f645..caf5d32e26 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -6,7 +6,7 @@ use crate::num::{ finish_parsing_base, finish_parsing_float, finish_parsing_num, float_expr_from_result, int_expr_from_result, num_expr_from_result, FloatBound, IntBound, NumericBound, }; -use crate::pattern::{bindings_from_patterns, canonicalize_pattern, Pattern}; +use crate::pattern::{canonicalize_pattern, BindingsFromPattern, Pattern}; use crate::procedure::References; use crate::scope::Scope; use roc_collections::{SendMap, VecMap, VecSet}; @@ -984,7 +984,8 @@ pub fn canonicalize_closure<'a>( can_args.push((var_store.fresh(), can_argument_pattern)); } - let bound_by_argument_patterns = bindings_from_patterns(can_args.iter().map(|x| &x.1)); + let bound_by_argument_patterns: Vec<_> = + BindingsFromPattern::new_many(can_args.iter().map(|x| &x.1)).collect(); let (loc_body_expr, new_output) = canonicalize_expr( env, @@ -1107,7 +1108,7 @@ fn canonicalize_when_branch<'a>( // Now that we've collected all the references for this branch, check to see if // any of the new idents it defined were unused. If any were, report it. - for (symbol, region) in bindings_from_patterns(patterns.iter()) { + for (symbol, region) in BindingsFromPattern::new_many(patterns.iter()) { if !output.references.has_value_lookup(symbol) { env.problem(Problem::UnusedDef(symbol, region)); } diff --git a/compiler/can/src/pattern.rs b/compiler/can/src/pattern.rs index c83db68fac..9d35c77b18 100644 --- a/compiler/can/src/pattern.rs +++ b/compiler/can/src/pattern.rs @@ -644,69 +644,92 @@ fn malformed_pattern(env: &mut Env, problem: MalformedPatternProblem, region: Re Pattern::MalformedPattern(problem, region) } -pub fn bindings_from_patterns<'a, I>(loc_patterns: I) -> Vec<(Symbol, Region)> -where - I: Iterator>, -{ - let mut answer = Vec::new(); - - for loc_pattern in loc_patterns { - add_bindings_from_patterns(&loc_pattern.region, &loc_pattern.value, &mut answer); - } - - answer +enum BindingsFromPatternWork<'a> { + Pattern(&'a Loc), + Destruct(&'a Loc), } -/// helper function for idents_from_patterns -fn add_bindings_from_patterns( - region: &Region, - pattern: &Pattern, - answer: &mut Vec<(Symbol, Region)>, -) { - use Pattern::*; +pub struct BindingsFromPattern<'a> { + stack: Vec>, +} - match pattern { - Identifier(symbol) - | Shadowed(_, _, symbol) - | AbilityMemberSpecialization { - ident: symbol, - specializes: _, - } => { - answer.push((*symbol, *region)); +impl<'a> BindingsFromPattern<'a> { + pub fn new(initial: &'a Loc) -> Self { + Self { + stack: vec![BindingsFromPatternWork::Pattern(initial)], } - AppliedTag { - arguments: loc_args, - .. - } => { - for (_, loc_arg) in loc_args { - add_bindings_from_patterns(&loc_arg.region, &loc_arg.value, answer); - } + } + + pub fn new_many(it: I) -> Self + where + I: Iterator>, + { + Self { + stack: it.map(BindingsFromPatternWork::Pattern).collect(), } - UnwrappedOpaque { argument, .. } => { - let (_, loc_arg) = &**argument; - add_bindings_from_patterns(&loc_arg.region, &loc_arg.value, answer); - } - RecordDestructure { destructs, .. } => { - for loc_destruct in destructs { - match loc_destruct.value.typ { - DestructType::Required | DestructType::Optional(_, _) => { - answer.push((loc_destruct.value.symbol, loc_destruct.region)); + } +} + +impl<'a> Iterator for BindingsFromPattern<'a> { + type Item = (Symbol, Region); + + fn next(&mut self) -> Option { + use Pattern::*; + + while let Some(work) = self.stack.pop() { + match work { + BindingsFromPatternWork::Pattern(loc_pattern) => { + use BindingsFromPatternWork::*; + + match &loc_pattern.value { + Identifier(symbol) + | Shadowed(_, _, symbol) + | AbilityMemberSpecialization { + ident: symbol, + specializes: _, + } => { + return Some((*symbol, loc_pattern.region)); + } + AppliedTag { + arguments: loc_args, + .. + } => { + let it = loc_args.iter().rev().map(|(_, p)| Pattern(p)); + self.stack.extend(it); + } + UnwrappedOpaque { argument, .. } => { + let (_, loc_arg) = &**argument; + self.stack.push(Pattern(loc_arg)); + } + RecordDestructure { destructs, .. } => { + let it = destructs.iter().rev().map(Destruct); + self.stack.extend(it); + } + NumLiteral(..) + | IntLiteral(..) + | FloatLiteral(..) + | StrLiteral(_) + | SingleQuote(_) + | Underscore + | MalformedPattern(_, _) + | UnsupportedPattern(_) + | OpaqueNotInScope(..) => (), } - DestructType::Guard(_, _) => { - // a guard does not introduce the symbol + } + BindingsFromPatternWork::Destruct(loc_destruct) => { + match loc_destruct.value.typ { + DestructType::Required | DestructType::Optional(_, _) => { + return Some((loc_destruct.value.symbol, loc_destruct.region)); + } + DestructType::Guard(_, _) => { + // a guard does not introduce the symbol + } } } } } - NumLiteral(..) - | IntLiteral(..) - | FloatLiteral(..) - | StrLiteral(_) - | SingleQuote(_) - | Underscore - | MalformedPattern(_, _) - | UnsupportedPattern(_) - | OpaqueNotInScope(..) => (), + + None } } From c487506ab420a4a11b833d6a22d537b06a449ed6 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 27 Apr 2022 19:11:25 +0200 Subject: [PATCH 629/846] reduce allocations further --- compiler/can/src/pattern.rs | 70 ++++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 20 deletions(-) diff --git a/compiler/can/src/pattern.rs b/compiler/can/src/pattern.rs index 9d35c77b18..7487b76651 100644 --- a/compiler/can/src/pattern.rs +++ b/compiler/can/src/pattern.rs @@ -644,39 +644,40 @@ fn malformed_pattern(env: &mut Env, problem: MalformedPatternProblem, region: Re Pattern::MalformedPattern(problem, region) } -enum BindingsFromPatternWork<'a> { +/// An iterator over the bindings made by a pattern. +/// +/// We attempt to make no allocations when we can. +pub enum BindingsFromPattern<'a> { + Empty, + One(&'a Loc), + Many(Vec>), +} + +pub enum BindingsFromPatternWork<'a> { Pattern(&'a Loc), Destruct(&'a Loc), } -pub struct BindingsFromPattern<'a> { - stack: Vec>, -} - impl<'a> BindingsFromPattern<'a> { pub fn new(initial: &'a Loc) -> Self { - Self { - stack: vec![BindingsFromPatternWork::Pattern(initial)], - } + Self::One(initial) } - pub fn new_many(it: I) -> Self + pub fn new_many(mut it: I) -> Self where I: Iterator>, { - Self { - stack: it.map(BindingsFromPatternWork::Pattern).collect(), + if let (1, Some(1)) = it.size_hint() { + Self::new(it.next().unwrap()) + } else { + Self::Many(it.map(BindingsFromPatternWork::Pattern).collect()) } } -} -impl<'a> Iterator for BindingsFromPattern<'a> { - type Item = (Symbol, Region); - - fn next(&mut self) -> Option { + fn next_many(stack: &mut Vec>) -> Option<(Symbol, Region)> { use Pattern::*; - while let Some(work) = self.stack.pop() { + while let Some(work) = stack.pop() { match work { BindingsFromPatternWork::Pattern(loc_pattern) => { use BindingsFromPatternWork::*; @@ -695,15 +696,15 @@ impl<'a> Iterator for BindingsFromPattern<'a> { .. } => { let it = loc_args.iter().rev().map(|(_, p)| Pattern(p)); - self.stack.extend(it); + stack.extend(it); } UnwrappedOpaque { argument, .. } => { let (_, loc_arg) = &**argument; - self.stack.push(Pattern(loc_arg)); + stack.push(Pattern(loc_arg)); } RecordDestructure { destructs, .. } => { let it = destructs.iter().rev().map(Destruct); - self.stack.extend(it); + stack.extend(it); } NumLiteral(..) | IntLiteral(..) @@ -733,6 +734,35 @@ impl<'a> Iterator for BindingsFromPattern<'a> { } } +impl<'a> Iterator for BindingsFromPattern<'a> { + type Item = (Symbol, Region); + + fn next(&mut self) -> Option { + use Pattern::*; + + match self { + BindingsFromPattern::Empty => None, + BindingsFromPattern::One(loc_pattern) => match &loc_pattern.value { + Identifier(symbol) + | Shadowed(_, _, symbol) + | AbilityMemberSpecialization { + ident: symbol, + specializes: _, + } => { + let region = loc_pattern.region; + *self = Self::Empty; + Some((*symbol, region)) + } + _ => { + *self = Self::Many(vec![BindingsFromPatternWork::Pattern(loc_pattern)]); + self.next() + } + }, + BindingsFromPattern::Many(stack) => Self::next_many(stack), + } + } +} + fn flatten_str_literal(literal: &StrLiteral<'_>) -> Pattern { use ast::StrLiteral::*; From 1de3148cf1c2383a445e27d164ff786ba9d50280 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 27 Apr 2022 19:18:26 +0200 Subject: [PATCH 630/846] fix problem with record guards --- compiler/can/src/pattern.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/compiler/can/src/pattern.rs b/compiler/can/src/pattern.rs index 7487b76651..e43f9c3622 100644 --- a/compiler/can/src/pattern.rs +++ b/compiler/can/src/pattern.rs @@ -718,12 +718,13 @@ impl<'a> BindingsFromPattern<'a> { } } BindingsFromPatternWork::Destruct(loc_destruct) => { - match loc_destruct.value.typ { + match &loc_destruct.value.typ { DestructType::Required | DestructType::Optional(_, _) => { return Some((loc_destruct.value.symbol, loc_destruct.region)); } - DestructType::Guard(_, _) => { + DestructType::Guard(_, inner) => { // a guard does not introduce the symbol + stack.push(BindingsFromPatternWork::Pattern(inner)) } } } From 7af2bb343c7b6abd07c1aee9714adf2b1340a3c4 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 27 Apr 2022 19:53:30 +0200 Subject: [PATCH 631/846] remove unused Scope functions --- compiler/can/src/scope.rs | 18 +----------------- compiler/collections/src/vec_map.rs | 7 ------- 2 files changed, 1 insertion(+), 24 deletions(-) diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index 24dcd22a26..4c6cb97295 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -106,10 +106,6 @@ impl IdentStore { self.symbols.push(symbol); self.regions.push(region); } - - fn len(&self) -> usize { - self.idents.len() - } } #[derive(Clone, Debug)] @@ -188,18 +184,6 @@ impl Scope { } } - pub fn symbols(&self) -> impl Iterator { - self.idents.symbols.iter().zip(self.idents.regions.iter()) - } - - pub fn contains_ident(&self, ident: &Ident) -> bool { - self.idents.get_index(ident).is_some() - } - - pub fn num_idents(&self) -> usize { - self.idents.len() - } - pub fn lookup(&self, ident: &Ident, region: Region) -> Result { match self.idents.get_symbol(ident) { Some(symbol) => Ok(symbol), @@ -369,7 +353,7 @@ impl Scope { let original_symbol = self.idents.symbols[index]; let original_region = self.idents.regions[index]; - let shadow_ident_id = all_ident_ids.add(ident.clone()); + let shadow_ident_id = all_ident_ids.add_ident(&ident); let shadow_symbol = Symbol::new(self.home, shadow_ident_id); if self.abilities_store.is_ability_member_name(original_symbol) { diff --git a/compiler/collections/src/vec_map.rs b/compiler/collections/src/vec_map.rs index 41916117e7..3471edfa36 100644 --- a/compiler/collections/src/vec_map.rs +++ b/compiler/collections/src/vec_map.rs @@ -58,13 +58,6 @@ impl VecMap { self.keys.contains(key) } - pub fn get(&self, key: &K) -> Option<&V> { - match self.keys.iter().position(|k| k == key) { - None => None, - Some(index) => Some(&self.values[index]), - } - } - pub fn remove(&mut self, key: &K) { match self.keys.iter().position(|x| x == key) { None => { From 09fbd4a5051cfe0f93f87565964bfc66df568f82 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 27 Apr 2022 20:22:52 +0200 Subject: [PATCH 632/846] fix typo --- compiler/can/src/def.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index e18ebbdeaa..ef41233dc8 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1189,7 +1189,7 @@ fn canonicalize_pending_body<'a>( opt_loc_annotation: Option>, ) -> DefOutput { - // We treat closure definitions `foo = \a, b -> ...` differntly from other body expressions, + // We treat closure definitions `foo = \a, b -> ...` differently from other body expressions, // because they need more bookkeeping (for tail calls, closure captures, etc.) // // Only defs of the form `foo = ...` can be closure declarations or self tail calls. From 08c89682369ae46a200a890c76ca5b6eeb5f4de9 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 27 Apr 2022 20:40:58 +0200 Subject: [PATCH 633/846] use interner in Scope + fix shadowing being reported incorrectly --- compiler/can/src/def.rs | 17 +++++++------ compiler/can/src/pattern.rs | 3 +-- compiler/can/src/scope.rs | 50 ++++++++++++------------------------- 3 files changed, 26 insertions(+), 44 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index ef41233dc8..7b927d26ab 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -107,7 +107,7 @@ enum PendingTypeDef<'a> { }, /// An invalid alias, that is ignored in the rest of the pipeline - /// e.g. a shadowed alias, or a definition like `MyAlias 1 : Int` + /// e.g. a definition like `MyAlias 1 : Int` /// with an incorrect pattern InvalidAlias { #[allow(dead_code)] @@ -116,6 +116,9 @@ enum PendingTypeDef<'a> { region: Region, }, + /// An alias with a name that shadows another symbol + ShadowedAlias, + /// An invalid ability, that is ignored in the rest of the pipeline. /// E.g. a shadowed ability, or with a bad definition. InvalidAbility { @@ -137,6 +140,7 @@ impl PendingTypeDef<'_> { } PendingTypeDef::Ability { name, .. } => Some((name.value, name.region)), PendingTypeDef::InvalidAlias { symbol, region, .. } => Some((*symbol, *region)), + PendingTypeDef::ShadowedAlias { .. } => None, PendingTypeDef::InvalidAbility { symbol, region } => Some((*symbol, *region)), PendingTypeDef::AbilityNotOnToplevel => None, PendingTypeDef::AbilityShadows => None, @@ -302,6 +306,7 @@ pub(crate) fn canonicalize_defs<'a>( PendingTypeDef::InvalidAlias { .. } | PendingTypeDef::InvalidAbility { .. } | PendingTypeDef::AbilityShadows + | PendingTypeDef::ShadowedAlias { .. } | PendingTypeDef::AbilityNotOnToplevel => { /* ignore */ } } } @@ -1365,7 +1370,7 @@ fn to_pending_type_def<'a>( let region = Region::span_across(&name.region, &ann.region); - match scope.introduce( + match scope.introduce_without_shadow_symbol( name.value.into(), &env.exposed_ident_ids, &mut env.ident_ids, @@ -1415,18 +1420,14 @@ fn to_pending_type_def<'a>( } } - Err((original_region, loc_shadowed_symbol, new_symbol)) => { + Err((original_region, loc_shadowed_symbol)) => { env.problem(Problem::Shadowing { original_region, shadow: loc_shadowed_symbol, kind: shadow_kind, }); - PendingTypeDef::InvalidAlias { - kind, - symbol: new_symbol, - region, - } + PendingTypeDef::ShadowedAlias } } } diff --git a/compiler/can/src/pattern.rs b/compiler/can/src/pattern.rs index 49676c8509..20d8877c04 100644 --- a/compiler/can/src/pattern.rs +++ b/compiler/can/src/pattern.rs @@ -684,7 +684,6 @@ impl<'a> BindingsFromPattern<'a> { match &loc_pattern.value { Identifier(symbol) - | Shadowed(_, _, symbol) | AbilityMemberSpecialization { ident: symbol, specializes: _, @@ -712,6 +711,7 @@ impl<'a> BindingsFromPattern<'a> { | StrLiteral(_) | SingleQuote(_) | Underscore + | Shadowed(_, _, _) | MalformedPattern(_, _) | UnsupportedPattern(_) | OpaqueNotInScope(..) => (), @@ -745,7 +745,6 @@ impl<'a> Iterator for BindingsFromPattern<'a> { BindingsFromPattern::Empty => None, BindingsFromPattern::One(loc_pattern) => match &loc_pattern.value { Identifier(symbol) - | Shadowed(_, _, symbol) | AbilityMemberSpecialization { ident: symbol, specializes: _, diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index 4c6cb97295..176a043f24 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -1,5 +1,5 @@ use roc_collections::all::{MutSet, SendMap}; -use roc_collections::soa; +use roc_collections::SmallStringInterner; use roc_module::ident::{Ident, Lowercase}; use roc_module::symbol::{IdentIds, ModuleId, Symbol}; use roc_problem::can::RuntimeError; @@ -11,11 +11,7 @@ use crate::abilities::AbilitiesStore; #[derive(Clone, Debug)] struct IdentStore { - /// One big byte array that stores all `Ident`s - string: Vec, - - /// Slices into `string` to get an individual `Ident` - idents: Vec>, + interner: SmallStringInterner, /// A Symbol for each Ident symbols: Vec, @@ -30,8 +26,7 @@ impl IdentStore { let capacity = defaults.len(); let mut this = Self { - string: Vec::with_capacity(capacity), - idents: Vec::with_capacity(capacity), + interner: SmallStringInterner::with_capacity(capacity), symbols: Vec::with_capacity(capacity), regions: Vec::with_capacity(capacity), }; @@ -44,46 +39,34 @@ impl IdentStore { } fn iter_idents(&self) -> impl Iterator + '_ { - self.idents.iter().filter_map(move |slice| { - // empty slice is used when ability members are shadowed - if slice.is_empty() { + self.interner.iter().filter_map(move |string| { + // empty string is used when ability members are shadowed + if string.is_empty() { None } else { - let bytes = &self.string[slice.indices()]; - let string = unsafe { std::str::from_utf8_unchecked(bytes) }; - Some(Ident::from(string)) } }) } fn iter_idents_symbols(&self) -> impl Iterator + '_ { - self.idents + self.interner .iter() .zip(self.symbols.iter()) - .filter_map(move |(slice, symbol)| { + .filter_map(move |(string, symbol)| { // empty slice is used when ability members are shadowed - if slice.is_empty() { + if string.is_empty() { None } else { - let bytes = &self.string[slice.indices()]; - let string = unsafe { std::str::from_utf8_unchecked(bytes) }; - Some((Ident::from(string), *symbol)) } }) } fn get_index(&self, ident: &Ident) -> Option { - let ident_bytes = ident.as_inline_str().as_str().as_bytes(); + let ident_str = ident.as_inline_str().as_str(); - for (i, slice) in self.idents.iter().enumerate() { - if slice.len() == ident_bytes.len() && &self.string[slice.indices()] == ident_bytes { - return Some(i); - } - } - - None + self.interner.find_index(ident_str) } fn get_symbol(&self, ident: &Ident) -> Option { @@ -98,11 +81,13 @@ impl IdentStore { /// Does not check that the ident is unique fn insert_unchecked(&mut self, ident: Ident, symbol: Symbol, region: Region) { - let ident_bytes = ident.as_inline_str().as_str().as_bytes(); + let ident_str = ident.as_inline_str().as_str(); - let slice = soa::Slice::extend_new(&mut self.string, ident_bytes.iter().copied()); + let index = self.interner.insert(ident_str); + + debug_assert_eq!(index, self.symbols.len()); + debug_assert_eq!(index, self.regions.len()); - self.idents.push(slice); self.symbols.push(symbol); self.regions.push(region); } @@ -305,9 +290,6 @@ impl Scope { let ident_id = all_ident_ids.add_ident(&ident); let symbol = Symbol::new(self.home, ident_id); - self.idents.symbols[index] = symbol; - self.idents.regions[index] = region; - Err((original_region, shadow, symbol)) } None => Ok(self.commit_introduction(ident, exposed_ident_ids, all_ident_ids, region)), From 1372825ebbe714e54b38c7dbcf9b083cbed61d31 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 27 Apr 2022 20:53:00 +0200 Subject: [PATCH 634/846] refactor --- compiler/can/src/def.rs | 5 +++-- compiler/can/src/scope.rs | 29 ++++++++++++----------------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 7b927d26ab..4263ca13ca 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -12,6 +12,7 @@ use crate::scope::create_alias; use crate::scope::Scope; use roc_collections::VecMap; use roc_collections::{ImSet, MutMap, SendMap}; +use roc_module::ident::Ident; use roc_module::ident::Lowercase; use roc_module::symbol::IdentId; use roc_module::symbol::ModuleId; @@ -1371,7 +1372,7 @@ fn to_pending_type_def<'a>( let region = Region::span_across(&name.region, &ann.region); match scope.introduce_without_shadow_symbol( - name.value.into(), + &Ident::from(name.value), &env.exposed_ident_ids, &mut env.ident_ids, region, @@ -1451,7 +1452,7 @@ fn to_pending_type_def<'a>( loc_has: _, } => { let name = match scope.introduce_without_shadow_symbol( - name.value.into(), + &Ident::from(name.value), &env.exposed_ident_ids, &mut env.ident_ids, name.region, diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index 176a043f24..9acc236bdb 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -32,7 +32,7 @@ impl IdentStore { }; for (ident, (symbol, region)) in defaults { - this.insert_unchecked(ident, symbol, region); + this.insert_unchecked(&ident, symbol, region); } this @@ -80,7 +80,7 @@ impl IdentStore { } /// Does not check that the ident is unique - fn insert_unchecked(&mut self, ident: Ident, symbol: Symbol, region: Region) { + fn insert_unchecked(&mut self, ident: &Ident, symbol: Symbol, region: Region) { let ident_str = ident.as_inline_str().as_str(); let index = self.interner.insert(ident_str); @@ -279,32 +279,27 @@ impl Scope { all_ident_ids: &mut IdentIds, region: Region, ) -> Result, Symbol)> { - match self.idents.get_index(&ident) { - Some(index) => { - let original_region = self.idents.regions[index]; - let shadow = Loc { - value: ident.clone(), - region, - }; - + match self.introduce_without_shadow_symbol(&ident, exposed_ident_ids, all_ident_ids, region) + { + Ok(symbol) => Ok(symbol), + Err((original_region, shadow)) => { let ident_id = all_ident_ids.add_ident(&ident); let symbol = Symbol::new(self.home, ident_id); Err((original_region, shadow, symbol)) } - None => Ok(self.commit_introduction(ident, exposed_ident_ids, all_ident_ids, region)), } } /// Like [Self::introduce], but does not introduce a new symbol for the shadowing symbol. pub fn introduce_without_shadow_symbol( &mut self, - ident: Ident, + ident: &Ident, exposed_ident_ids: &IdentIds, all_ident_ids: &mut IdentIds, region: Region, ) -> Result)> { - match self.idents.get_symbol_and_region(&ident) { + match self.idents.get_symbol_and_region(ident) { Some((_, original_region)) => { let shadow = Loc { value: ident.clone(), @@ -344,7 +339,7 @@ impl Scope { // Add a symbol for the shadow, but don't re-associate the member name. let dummy = Ident::default(); - self.idents.insert_unchecked(dummy, shadow_symbol, region); + self.idents.insert_unchecked(&dummy, shadow_symbol, region); Ok((shadow_symbol, Some(original_symbol))) } else { @@ -363,7 +358,7 @@ impl Scope { } None => { let new_symbol = - self.commit_introduction(ident, exposed_ident_ids, all_ident_ids, region); + self.commit_introduction(&ident, exposed_ident_ids, all_ident_ids, region); Ok((new_symbol, None)) } } @@ -371,7 +366,7 @@ impl Scope { fn commit_introduction( &mut self, - ident: Ident, + ident: &Ident, exposed_ident_ids: &IdentIds, all_ident_ids: &mut IdentIds, region: Region, @@ -412,7 +407,7 @@ impl Scope { match self.idents.get_symbol_and_region(&ident) { Some(shadowed) => Err(shadowed), None => { - self.idents.insert_unchecked(ident, symbol, region); + self.idents.insert_unchecked(&ident, symbol, region); Ok(()) } From d09036bb4f099ed44cc43204bb986459e7f444dc Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 27 Apr 2022 20:59:40 +0200 Subject: [PATCH 635/846] don't have shadowing overwrite our data --- compiler/can/src/scope.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index 9acc236bdb..6038ead0ec 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -349,10 +349,6 @@ impl Scope { region, }; - // overwrite the data for this ident with the shadowed values - self.idents.symbols[index] = shadow_symbol; - self.idents.regions[index] = region; - Err((original_region, shadow, shadow_symbol)) } } @@ -374,9 +370,9 @@ impl Scope { // If this IdentId was already added previously // when the value was exposed in the module header, // use that existing IdentId. Otherwise, create a fresh one. - let ident_id = match exposed_ident_ids.get_id(&ident) { + let ident_id = match exposed_ident_ids.get_id(ident) { Some(ident_id) => ident_id, - None => all_ident_ids.add_ident(&ident), + None => all_ident_ids.add_ident(ident), }; let symbol = Symbol::new(self.home, ident_id); From 2844be4383047d4a70dde59c178744314eee8705 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 27 Apr 2022 21:03:18 +0200 Subject: [PATCH 636/846] move IdentStore to the bottom --- compiler/can/src/scope.rs | 168 +++++++++++++++++++------------------- 1 file changed, 84 insertions(+), 84 deletions(-) diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index 6038ead0ec..88e420ef5a 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -9,90 +9,6 @@ use roc_types::types::{Alias, AliasKind, Type}; use crate::abilities::AbilitiesStore; -#[derive(Clone, Debug)] -struct IdentStore { - interner: SmallStringInterner, - - /// A Symbol for each Ident - symbols: Vec, - - /// A Region for each Ident - regions: Vec, -} - -impl IdentStore { - fn new() -> Self { - let defaults = Symbol::default_in_scope(); - let capacity = defaults.len(); - - let mut this = Self { - interner: SmallStringInterner::with_capacity(capacity), - symbols: Vec::with_capacity(capacity), - regions: Vec::with_capacity(capacity), - }; - - for (ident, (symbol, region)) in defaults { - this.insert_unchecked(&ident, symbol, region); - } - - this - } - - fn iter_idents(&self) -> impl Iterator + '_ { - self.interner.iter().filter_map(move |string| { - // empty string is used when ability members are shadowed - if string.is_empty() { - None - } else { - Some(Ident::from(string)) - } - }) - } - - fn iter_idents_symbols(&self) -> impl Iterator + '_ { - self.interner - .iter() - .zip(self.symbols.iter()) - .filter_map(move |(string, symbol)| { - // empty slice is used when ability members are shadowed - if string.is_empty() { - None - } else { - Some((Ident::from(string), *symbol)) - } - }) - } - - fn get_index(&self, ident: &Ident) -> Option { - let ident_str = ident.as_inline_str().as_str(); - - self.interner.find_index(ident_str) - } - - fn get_symbol(&self, ident: &Ident) -> Option { - Some(self.symbols[self.get_index(ident)?]) - } - - fn get_symbol_and_region(&self, ident: &Ident) -> Option<(Symbol, Region)> { - let index = self.get_index(ident)?; - - Some((self.symbols[index], self.regions[index])) - } - - /// Does not check that the ident is unique - fn insert_unchecked(&mut self, ident: &Ident, symbol: Symbol, region: Region) { - let ident_str = ident.as_inline_str().as_str(); - - let index = self.interner.insert(ident_str); - - debug_assert_eq!(index, self.symbols.len()); - debug_assert_eq!(index, self.regions.len()); - - self.symbols.push(symbol); - self.regions.push(region); - } -} - #[derive(Clone, Debug)] pub struct Scope { idents: IdentStore, @@ -471,3 +387,87 @@ pub fn create_alias( kind, } } + +#[derive(Clone, Debug)] +struct IdentStore { + interner: SmallStringInterner, + + /// A Symbol for each Ident + symbols: Vec, + + /// A Region for each Ident + regions: Vec, +} + +impl IdentStore { + fn new() -> Self { + let defaults = Symbol::default_in_scope(); + let capacity = defaults.len(); + + let mut this = Self { + interner: SmallStringInterner::with_capacity(capacity), + symbols: Vec::with_capacity(capacity), + regions: Vec::with_capacity(capacity), + }; + + for (ident, (symbol, region)) in defaults { + this.insert_unchecked(&ident, symbol, region); + } + + this + } + + fn iter_idents(&self) -> impl Iterator + '_ { + self.interner.iter().filter_map(move |string| { + // empty string is used when ability members are shadowed + if string.is_empty() { + None + } else { + Some(Ident::from(string)) + } + }) + } + + fn iter_idents_symbols(&self) -> impl Iterator + '_ { + self.interner + .iter() + .zip(self.symbols.iter()) + .filter_map(move |(string, symbol)| { + // empty slice is used when ability members are shadowed + if string.is_empty() { + None + } else { + Some((Ident::from(string), *symbol)) + } + }) + } + + fn get_index(&self, ident: &Ident) -> Option { + let ident_str = ident.as_inline_str().as_str(); + + self.interner.find_index(ident_str) + } + + fn get_symbol(&self, ident: &Ident) -> Option { + Some(self.symbols[self.get_index(ident)?]) + } + + fn get_symbol_and_region(&self, ident: &Ident) -> Option<(Symbol, Region)> { + let index = self.get_index(ident)?; + + Some((self.symbols[index], self.regions[index])) + } + + /// Does not check that the ident is unique + fn insert_unchecked(&mut self, ident: &Ident, symbol: Symbol, region: Region) { + let ident_str = ident.as_inline_str().as_str(); + + let index = self.interner.insert(ident_str); + + debug_assert_eq!(index, self.symbols.len()); + debug_assert_eq!(index, self.regions.len()); + + self.symbols.push(symbol); + self.regions.push(region); + } +} From e522df352856b3e7f5c1bf7113011474d0215491 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 27 Apr 2022 23:31:37 +0200 Subject: [PATCH 637/846] fix can tests --- compiler/can/tests/test_can.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/compiler/can/tests/test_can.rs b/compiler/can/tests/test_can.rs index 838280f73d..a4117f165b 100644 --- a/compiler/can/tests/test_can.rs +++ b/compiler/can/tests/test_can.rs @@ -373,11 +373,9 @@ mod test_can { let arena = Bump::new(); let CanExprOut { problems, .. } = can_expr_with(&arena, test_home(), src); - assert_eq!(problems.len(), 2); + assert_eq!(problems.len(), 1); assert!(problems.iter().all(|problem| match problem { Problem::RuntimeError(RuntimeError::Shadowing { .. }) => true, - // Due to one of the shadows - Problem::UnusedDef(..) => true, _ => false, })); } @@ -396,11 +394,9 @@ mod test_can { let arena = Bump::new(); let CanExprOut { problems, .. } = can_expr_with(&arena, test_home(), src); - assert_eq!(problems.len(), 2); + assert_eq!(problems.len(), 1); assert!(problems.iter().all(|problem| match problem { Problem::RuntimeError(RuntimeError::Shadowing { .. }) => true, - // Due to one of the shadows - Problem::UnusedDef(..) => true, _ => false, })); } @@ -419,12 +415,10 @@ mod test_can { let arena = Bump::new(); let CanExprOut { problems, .. } = can_expr_with(&arena, test_home(), src); - assert_eq!(problems.len(), 2); + assert_eq!(problems.len(), 1); println!("{:#?}", problems); assert!(problems.iter().all(|problem| match problem { Problem::RuntimeError(RuntimeError::Shadowing { .. }) => true, - // Due to one of the shadows - Problem::UnusedDef(..) => true, _ => false, })); } From fa8108e3a83a51939ce7277ad84762050128d0fc Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 27 Apr 2022 13:31:33 -0400 Subject: [PATCH 638/846] SJLJ roc_panic on AArch64 ``` $ uname -m arm64 $ cargo test -p test_gen gen_num::abs_min_int_overflow Finished test [unoptimized + debuginfo] target(s) in 0.09s Running src/tests.rs (target/debug/deps/test_gen-b2041868d2cf26f3) running 1 test test gen_num::abs_min_int_overflow - should panic ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 933 filtered out; finished in 0.14s ``` --- compiler/builtins/bitcode/src/main.zig | 21 +++++ compiler/builtins/src/bitcode.rs | 3 + compiler/gen_llvm/src/llvm/build.rs | 109 ++++++------------------- compiler/gen_llvm/src/llvm/externs.rs | 29 ++----- 4 files changed, 55 insertions(+), 107 deletions(-) diff --git a/compiler/builtins/bitcode/src/main.zig b/compiler/builtins/bitcode/src/main.zig index 0c0dfa3b22..5eb871a7a0 100644 --- a/compiler/builtins/bitcode/src/main.zig +++ b/compiler/builtins/bitcode/src/main.zig @@ -163,6 +163,27 @@ comptime { @export(utils.panic, .{ .name = "roc_builtins.utils." ++ "panic", .linkage = .Weak }); } +// Utils continued - SJLJ +// For tests (in particular test_gen), roc_panic is implemented in terms of +// setjmp/longjmp. LLVM is unable to generate code for longjmp on AArch64 (https://github.com/rtfeldman/roc/issues/2965), +// so instead we ask Zig to please provide implementations for us, which is does +// (seemingly via musl). +pub usingnamespace @import("std").c.builtins; +pub extern fn setjmp([*c]c_int) c_int; +pub extern fn longjmp([*c]c_int, c_int) noreturn; +pub extern fn _setjmp([*c]c_int) c_int; +pub extern fn _longjmp([*c]c_int, c_int) noreturn; +pub extern fn sigsetjmp([*c]c_int, c_int) c_int; +pub extern fn siglongjmp([*c]c_int, c_int) noreturn; +pub extern fn longjmperror() void; +// Zig won't expose the externs (and hence link correctly) unless we force them to be used. +pub export fn __roc_force_setjmp(it: [*c]c_int) c_int { + return setjmp(it); +} +pub export fn __roc_force_longjmp(a0: [*c]c_int, a1: c_int) noreturn { + longjmp(a0, a1); +} + // Export helpers - Must be run inside a comptime fn exportBuiltinFn(comptime func: anytype, comptime func_name: []const u8) void { @export(func, .{ .name = "roc_builtins." ++ func_name, .linkage = .Strong }); diff --git a/compiler/builtins/src/bitcode.rs b/compiler/builtins/src/bitcode.rs index 6299e5cd35..73de5d2452 100644 --- a/compiler/builtins/src/bitcode.rs +++ b/compiler/builtins/src/bitcode.rs @@ -365,6 +365,9 @@ pub const UTILS_EXPECT_FAILED: &str = "roc_builtins.expect.expect_failed"; pub const UTILS_GET_EXPECT_FAILURES: &str = "roc_builtins.expect.get_expect_failures"; pub const UTILS_DEINIT_FAILURES: &str = "roc_builtins.expect.deinit_failures"; +pub const UTILS_LONGJMP: &str = "longjmp"; +pub const UTILS_SETJMP: &str = "setjmp"; + #[derive(Debug, Default)] pub struct IntToIntrinsicName { pub options: [IntrinsicName; 10], diff --git a/compiler/gen_llvm/src/llvm/build.rs b/compiler/gen_llvm/src/llvm/build.rs index 219ca9a4e2..da7d335e8e 100644 --- a/compiler/gen_llvm/src/llvm/build.rs +++ b/compiler/gen_llvm/src/llvm/build.rs @@ -521,35 +521,11 @@ fn add_intrinsics<'ctx>(ctx: &'ctx Context, module: &Module<'ctx>) { let i8_ptr_type = i8_type.ptr_type(AddressSpace::Generic); let i32_type = ctx.i32_type(); let i64_type = ctx.i64_type(); - let void_type = ctx.void_type(); if let Some(func) = module.get_function("__muloti4") { func.set_linkage(Linkage::WeakAny); } - add_intrinsic( - ctx, - module, - LLVM_SETJMP, - i32_type.fn_type(&[i8_ptr_type.into()], false), - ); - - if true { - add_intrinsic( - ctx, - module, - LLVM_LONGJMP, - void_type.fn_type(&[i8_ptr_type.into()], false), - ); - } else { - add_intrinsic( - ctx, - module, - LLVM_LONGJMP, - void_type.fn_type(&[i8_ptr_type.into(), i32_type.into()], false), - ); - } - add_intrinsic( ctx, module, @@ -628,9 +604,6 @@ static LLVM_LROUND_I64_F64: &str = "llvm.lround.i64.f64"; static LLVM_FRAME_ADDRESS: &str = "llvm.frameaddress.p0i8"; static LLVM_STACK_SAVE: &str = "llvm.stacksave"; -static LLVM_SETJMP: &str = "llvm.eh.sjlj.setjmp"; -pub static LLVM_LONGJMP: &str = "llvm.eh.sjlj.longjmp"; - const LLVM_ADD_WITH_OVERFLOW: IntrinsicName = llvm_int_intrinsic!("llvm.sadd.with.overflow", "llvm.uadd.with.overflow"); const LLVM_SUB_WITH_OVERFLOW: IntrinsicName = @@ -3677,10 +3650,15 @@ fn expose_function_to_host_help_c_abi<'a, 'ctx, 'env>( } pub fn get_sjlj_buffer<'a, 'ctx, 'env>(env: &Env<'a, 'ctx, 'env>) -> PointerValue<'ctx> { + // The size of jump_buf is platform-dependent. + // AArch64 needs 3 64-bit words, x86 seemingly needs less than that. Let's just make it 3 + // 64-bit words. + // We can always increase the size, since we hand it off opaquely to both `setjmp` and `longjmp`. + // The unused space won't be touched. let type_ = env .context - .i8_type() - .array_type(5 * env.target_info.ptr_width() as u32); + .i32_type() + .array_type(6 * env.target_info.ptr_width() as u32); let global = match env.module.get_global("roc_sjlj_buffer") { Some(global) => global, @@ -3692,12 +3670,26 @@ pub fn get_sjlj_buffer<'a, 'ctx, 'env>(env: &Env<'a, 'ctx, 'env>) -> PointerValu env.builder .build_bitcast( global.as_pointer_value(), - env.context.i8_type().ptr_type(AddressSpace::Generic), + env.context.i32_type().ptr_type(AddressSpace::Generic), "cast_sjlj_buffer", ) .into_pointer_value() } +/// Pointer to pointer of the panic message. +pub fn get_panic_msg_ptr<'a, 'ctx, 'env>(env: &Env<'a, 'ctx, 'env>) -> PointerValue<'ctx> { + let ptr_to_u8_ptr = env.context.i8_type().ptr_type(AddressSpace::Generic); + + let global_name = "roc_panic_msg_ptr"; + let global = env.module.get_global(global_name).unwrap_or_else(|| { + let global = env.module.add_global(ptr_to_u8_ptr, None, global_name); + global.set_initializer(&ptr_to_u8_ptr.const_zero()); + global + }); + + global.as_pointer_value() +} + fn set_jump_and_catch_long_jump<'a, 'ctx, 'env>( env: &Env<'a, 'ctx, 'env>, parent: FunctionValue<'ctx>, @@ -3718,51 +3710,7 @@ fn set_jump_and_catch_long_jump<'a, 'ctx, 'env>( let buffer = get_sjlj_buffer(env); - let cast = env - .builder - .build_bitcast( - buffer, - env.context - .i8_type() - .ptr_type(AddressSpace::Generic) - .array_type(5) - .ptr_type(AddressSpace::Generic), - "to [5 x i8*]", - ) - .into_pointer_value(); - - let zero = env.context.i32_type().const_zero(); - - let index = env.context.i32_type().const_zero(); - let fa = unsafe { - env.builder - .build_in_bounds_gep(cast, &[zero, index], "name") - }; - - let index = env.context.i32_type().const_int(2, false); - let ss = unsafe { - env.builder - .build_in_bounds_gep(cast, &[zero, index], "name") - }; - - let index = env.context.i32_type().const_int(3, false); - let error_msg = unsafe { - env.builder - .build_in_bounds_gep(cast, &[zero, index], "name") - }; - - let frame_address = env.call_intrinsic( - LLVM_FRAME_ADDRESS, - &[env.context.i32_type().const_zero().into()], - ); - - env.builder.build_store(fa, frame_address); - - let stack_save = env.call_intrinsic(LLVM_STACK_SAVE, &[]); - - env.builder.build_store(ss, stack_save); - - let panicked_u32 = env.call_intrinsic(LLVM_SETJMP, &[buffer.into()]); + let panicked_u32 = call_bitcode_fn(env, &[buffer.into()], bitcode::UTILS_SETJMP); let panicked_bool = env.builder.build_int_compare( IntPredicate::NE, panicked_u32.into_int_value(), @@ -3792,17 +3740,10 @@ fn set_jump_and_catch_long_jump<'a, 'ctx, 'env>( let error_msg = { // u8** - let ptr_int_ptr = builder.build_bitcast( - error_msg, - env.context - .i8_type() - .ptr_type(AddressSpace::Generic) - .ptr_type(AddressSpace::Generic), - "cast", - ); + let ptr_int_ptr = get_panic_msg_ptr(env); // u8* again - let ptr_int = builder.build_load(ptr_int_ptr.into_pointer_value(), "ptr_int"); + let ptr_int = builder.build_load(ptr_int_ptr, "ptr_int"); ptr_int }; diff --git a/compiler/gen_llvm/src/llvm/externs.rs b/compiler/gen_llvm/src/llvm/externs.rs index 055c0f8712..1f1a691199 100644 --- a/compiler/gen_llvm/src/llvm/externs.rs +++ b/compiler/gen_llvm/src/llvm/externs.rs @@ -1,9 +1,11 @@ -use crate::llvm::build::{add_func, C_CALL_CONV}; +use crate::llvm::bitcode::call_void_bitcode_fn; +use crate::llvm::build::{add_func, get_panic_msg_ptr, C_CALL_CONV}; use crate::llvm::build::{CCReturn, Env, FunctionSpec}; use inkwell::module::Linkage; use inkwell::types::BasicType; use inkwell::values::BasicValue; use inkwell::AddressSpace; +use roc_builtins::bitcode; /// Define functions for roc_alloc, roc_realloc, and roc_dealloc /// which use libc implementations (malloc, realloc, and free) @@ -184,7 +186,7 @@ pub fn add_sjlj_roc_panic(env: &Env<'_, '_, '_>) { // roc_panic { - use crate::llvm::build::LLVM_LONGJMP; + // use crate::llvm::build::LLVM_LONGJMP; // The type of this function (but not the implementation) should have // already been defined by the builtins, which rely on it. @@ -210,29 +212,10 @@ pub fn add_sjlj_roc_panic(env: &Env<'_, '_, '_>) { let buffer = crate::llvm::build::get_sjlj_buffer(env); // write our error message pointer - let index = env - .ptr_int() - .const_int(3 * env.target_info.ptr_width() as u64, false); - let message_buffer_raw = - unsafe { builder.build_gep(buffer, &[index], "raw_msg_buffer_ptr") }; - let message_buffer = builder.build_bitcast( - message_buffer_raw, - env.context - .i8_type() - .ptr_type(AddressSpace::Generic) - .ptr_type(AddressSpace::Generic), - "to **u8", - ); - - env.builder - .build_store(message_buffer.into_pointer_value(), ptr_arg); + env.builder.build_store(get_panic_msg_ptr(env), ptr_arg); let tag = env.context.i32_type().const_int(1, false); - if true { - let _call = env.build_intrinsic_call(LLVM_LONGJMP, &[buffer.into()]); - } else { - let _call = env.build_intrinsic_call(LLVM_LONGJMP, &[buffer.into(), tag.into()]); - } + let _call = call_void_bitcode_fn(env, &[buffer.into(), tag.into()], bitcode::UTILS_LONGJMP); builder.build_unreachable(); From b5dd5d4e8048b6091ccd3d29c36d1b3e2433ad88 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 27 Apr 2022 13:35:53 -0400 Subject: [PATCH 639/846] Dead code --- compiler/gen_llvm/src/llvm/build.rs | 31 ----------------------------- 1 file changed, 31 deletions(-) diff --git a/compiler/gen_llvm/src/llvm/build.rs b/compiler/gen_llvm/src/llvm/build.rs index da7d335e8e..c771265e76 100644 --- a/compiler/gen_llvm/src/llvm/build.rs +++ b/compiler/gen_llvm/src/llvm/build.rs @@ -515,38 +515,12 @@ fn add_intrinsics<'ctx>(ctx: &'ctx Context, module: &Module<'ctx>) { // List of all supported LLVM intrinsics: // // https://releases.llvm.org/10.0.0/docs/LangRef.html#standard-c-library-intrinsics - let f64_type = ctx.f64_type(); let i1_type = ctx.bool_type(); - let i8_type = ctx.i8_type(); - let i8_ptr_type = i8_type.ptr_type(AddressSpace::Generic); - let i32_type = ctx.i32_type(); - let i64_type = ctx.i64_type(); if let Some(func) = module.get_function("__muloti4") { func.set_linkage(Linkage::WeakAny); } - add_intrinsic( - ctx, - module, - LLVM_FRAME_ADDRESS, - i8_ptr_type.fn_type(&[i32_type.into()], false), - ); - - add_intrinsic( - ctx, - module, - LLVM_STACK_SAVE, - i8_ptr_type.fn_type(&[], false), - ); - - add_intrinsic( - ctx, - module, - LLVM_LROUND_I64_F64, - i64_type.fn_type(&[f64_type.into()], false), - ); - add_float_intrinsic(ctx, module, &LLVM_LOG, |t| t.fn_type(&[t.into()], false)); add_float_intrinsic(ctx, module, &LLVM_POW, |t| { t.fn_type(&[t.into(), t.into()], false) @@ -598,11 +572,6 @@ static LLVM_FLOOR: IntrinsicName = float_intrinsic!("llvm.floor"); static LLVM_MEMSET_I64: &str = "llvm.memset.p0i8.i64"; static LLVM_MEMSET_I32: &str = "llvm.memset.p0i8.i32"; -static LLVM_LROUND_I64_F64: &str = "llvm.lround.i64.f64"; - -// static LLVM_FRAME_ADDRESS: &str = "llvm.frameaddress"; -static LLVM_FRAME_ADDRESS: &str = "llvm.frameaddress.p0i8"; -static LLVM_STACK_SAVE: &str = "llvm.stacksave"; const LLVM_ADD_WITH_OVERFLOW: IntrinsicName = llvm_int_intrinsic!("llvm.sadd.with.overflow", "llvm.uadd.with.overflow"); From 8e117c0877f5284e9afbf15f175c678e5cb20030 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 27 Apr 2022 13:52:47 -0400 Subject: [PATCH 640/846] Clip --- compiler/gen_llvm/src/llvm/build.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/compiler/gen_llvm/src/llvm/build.rs b/compiler/gen_llvm/src/llvm/build.rs index c771265e76..84e547aa3f 100644 --- a/compiler/gen_llvm/src/llvm/build.rs +++ b/compiler/gen_llvm/src/llvm/build.rs @@ -3712,9 +3712,7 @@ fn set_jump_and_catch_long_jump<'a, 'ctx, 'env>( let ptr_int_ptr = get_panic_msg_ptr(env); // u8* again - let ptr_int = builder.build_load(ptr_int_ptr, "ptr_int"); - - ptr_int + builder.build_load(ptr_int_ptr, "ptr_int") }; let return_value = { From 3fb1b39871a008da3f91edb4146e51ea225318c2 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 27 Apr 2022 17:01:17 -0400 Subject: [PATCH 641/846] Spin ldopen on Aarch64 tests --- compiler/build/src/link.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/compiler/build/src/link.rs b/compiler/build/src/link.rs index 4bf75d24b3..3acb21720d 100644 --- a/compiler/build/src/link.rs +++ b/compiler/build/src/link.rs @@ -1104,6 +1104,21 @@ pub fn module_to_dylib( // Load the dylib let path = dylib_path.as_path().to_str().unwrap(); + if matches!(target.architecture, Architecture::Aarch64(_)) { + // On AArch64 darwin machines, calling `ldopen` on Roc-generated libs from multiple threads + // sometimes fails with + // cannot dlopen until fork() handlers have completed + // This may be due to codesigning. In any case, spinning until we are able to dlopen seems + // to be okay. + loop { + match unsafe { Library::new(path) } { + Ok(lib) => return Ok(lib), + Err(Error::DlOpen { .. }) => continue, + Err(other) => return Err(other), + } + } + } + unsafe { Library::new(path) } } From f19701293c2ba563543f62e7cd24cf165f3545d6 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 27 Apr 2022 17:04:24 -0400 Subject: [PATCH 642/846] Mark setjmp/longjmp as explicitly linked --- linker/src/lib.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/linker/src/lib.rs b/linker/src/lib.rs index 1b4a2a8d14..b41144a600 100644 --- a/linker/src/lib.rs +++ b/linker/src/lib.rs @@ -1401,8 +1401,16 @@ fn surgery_impl( return Ok(-1); } } - } else if matches!(app_obj.symbol_by_index(index), Ok(sym) if ["__divti3", "__udivti3"].contains(&sym.name().unwrap_or_default())) - { + } else if { + const ALWAYS_LINKED: &[&str] = &[ + "__divti3", + "__udivti3", + // By zig builtins + "setjmp", + "longjmp", + ]; + matches!(app_obj.symbol_by_index(index), Ok(sym) if ALWAYS_LINKED.contains(&sym.name().unwrap_or_default())) + } { // Explicitly ignore some symbols that are currently always linked. continue; } else { From fbf4cd11ff28a406b458f126998b373131876594 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 27 Apr 2022 17:16:45 -0400 Subject: [PATCH 643/846] Turn off busted test and turn on similar repro --- compiler/test_gen/src/gen_tags.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/compiler/test_gen/src/gen_tags.rs b/compiler/test_gen/src/gen_tags.rs index 43bcdb05c8..c6002dc330 100644 --- a/compiler/test_gen/src/gen_tags.rs +++ b/compiler/test_gen/src/gen_tags.rs @@ -1201,6 +1201,7 @@ fn applied_tag_function_result() { #[test] #[cfg(any(feature = "gen-llvm"))] +#[ignore = "This test has incorrect refcounts: https://github.com/rtfeldman/roc/issues/2968"] fn applied_tag_function_linked_list() { assert_evals_to!( indoc!( @@ -1220,6 +1221,27 @@ fn applied_tag_function_linked_list() { ); } +#[test] +#[cfg(any(feature = "gen-llvm"))] +fn applied_tag_function_pair() { + assert_evals_to!( + indoc!( + r#" + Pair a : [ Pair a a ] + + x : List (Pair Str) + x = List.map2 [ "a", "b" ] [ "c", "d" ] Pair + + when List.first x is + Ok (Pair "a" "c") -> 1 + _ -> 0 + "# + ), + 1, + i64 + ); +} + #[test] #[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] #[should_panic(expected = "")] // TODO: this only panics because it returns 0 instead of 1! From 2b3eef1cbe6b122201fa6f9ae1bd4ec0bcf121cf Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Thu, 28 Apr 2022 13:03:52 +0200 Subject: [PATCH 644/846] mono test output update --- .../test_mono/generated/closure_in_list.txt | 20 ++-- compiler/test_mono/generated/dict.txt | 16 +-- .../generated/empty_list_of_function_type.txt | 40 +++---- compiler/test_mono/generated/factorial.txt | 28 ++--- compiler/test_mono/generated/has_none.txt | 6 +- .../if_guard_bind_variable_false.txt | 12 +- compiler/test_mono/generated/ir_int_add.txt | 30 ++--- compiler/test_mono/generated/ir_plus.txt | 8 +- compiler/test_mono/generated/ir_round.txt | 4 +- compiler/test_mono/generated/ir_two_defs.txt | 8 +- compiler/test_mono/generated/ir_when_idiv.txt | 18 +-- compiler/test_mono/generated/ir_when_just.txt | 24 ++-- compiler/test_mono/generated/is_nil.txt | 4 +- ...cialize_errors_behind_unified_branches.txt | 60 +++++----- compiler/test_mono/generated/issue_2810.txt | 8 +- .../generated/linked_list_length_twice.txt | 32 +++--- compiler/test_mono/generated/list_append.txt | 8 +- .../generated/list_append_closure.txt | 8 +- .../generated/list_cannot_update_inplace.txt | 75 ++++++------ compiler/test_mono/generated/list_get.txt | 22 ++-- compiler/test_mono/generated/list_len.txt | 30 ++--- .../generated/list_pass_to_function.txt | 35 +++--- .../generated/monomorphized_ints_aliased.txt | 28 ++--- .../generated/nested_pattern_match.txt | 46 ++++---- .../generated/opaque_assign_to_symbol.txt | 16 ++- .../test_mono/generated/optional_when.txt | 50 ++++---- compiler/test_mono/generated/peano.txt | 8 +- compiler/test_mono/generated/peano1.txt | 8 +- compiler/test_mono/generated/peano2.txt | 10 +- .../test_mono/generated/quicksort_help.txt | 46 ++++---- .../test_mono/generated/quicksort_swap.txt | 107 +++++++++--------- ...optional_field_function_no_use_default.txt | 14 +-- ...rd_optional_field_function_use_default.txt | 12 +- ...cord_optional_field_let_no_use_default.txt | 14 +-- .../record_optional_field_let_use_default.txt | 12 +- compiler/test_mono/generated/rigids.txt | 101 ++++++++--------- .../generated/somehow_drops_definitions.txt | 32 +++--- .../generated/specialize_ability_call.txt | 10 +- .../generated/specialize_closures.txt | 24 ++-- .../generated/specialize_lowlevel.txt | 24 ++-- .../test_mono/generated/when_nested_maybe.txt | 46 ++++---- .../test_mono/generated/when_on_record.txt | 10 +- .../generated/when_on_two_values.txt | 36 +++--- 43 files changed, 564 insertions(+), 586 deletions(-) diff --git a/compiler/test_mono/generated/closure_in_list.txt b/compiler/test_mono/generated/closure_in_list.txt index 18496e4156..4687f8cc52 100644 --- a/compiler/test_mono/generated/closure_in_list.txt +++ b/compiler/test_mono/generated/closure_in_list.txt @@ -1,21 +1,21 @@ -procedure List.7 (#Attr.2): - let Test.8 : U64 = lowlevel ListLen #Attr.2; - ret Test.8; +procedure List.6 (#Attr.2): + let List.139 : U64 = lowlevel ListLen #Attr.2; + ret List.139; procedure Test.1 (Test.5): let Test.2 : I64 = 41i64; - let Test.12 : {I64} = Struct {Test.2}; - let Test.11 : List {I64} = Array [Test.12]; - ret Test.11; + let Test.11 : {I64} = Struct {Test.2}; + let Test.10 : List {I64} = Array [Test.11]; + ret Test.10; -procedure Test.3 (Test.10, #Attr.12): +procedure Test.3 (Test.9, #Attr.12): let Test.2 : I64 = StructAtIndex 0 #Attr.12; let Test.2 : I64 = 41i64; ret Test.2; procedure Test.0 (): - let Test.9 : {} = Struct {}; - let Test.7 : List {I64} = CallByName Test.1 Test.9; - let Test.6 : U64 = CallByName List.7 Test.7; + let Test.8 : {} = Struct {}; + let Test.7 : List {I64} = CallByName Test.1 Test.8; + let Test.6 : U64 = CallByName List.6 Test.7; dec Test.7; ret Test.6; diff --git a/compiler/test_mono/generated/dict.txt b/compiler/test_mono/generated/dict.txt index 4244fb0e0c..31ae33d719 100644 --- a/compiler/test_mono/generated/dict.txt +++ b/compiler/test_mono/generated/dict.txt @@ -1,13 +1,13 @@ -procedure Dict.2 (): - let Test.4 : Dict [] [] = lowlevel DictEmpty ; - ret Test.4; +procedure Dict.1 (): + let Dict.28 : Dict [] [] = lowlevel DictEmpty ; + ret Dict.28; -procedure Dict.8 (#Attr.2): - let Test.3 : U64 = lowlevel DictSize #Attr.2; +procedure Dict.7 (#Attr.2): + let Dict.27 : U64 = lowlevel DictSize #Attr.2; dec #Attr.2; - ret Test.3; + ret Dict.27; procedure Test.0 (): - let Test.2 : Dict [] [] = CallByName Dict.2; - let Test.1 : U64 = CallByName Dict.8 Test.2; + let Test.2 : Dict [] [] = CallByName Dict.1; + let Test.1 : U64 = CallByName Dict.7 Test.2; ret Test.1; diff --git a/compiler/test_mono/generated/empty_list_of_function_type.txt b/compiler/test_mono/generated/empty_list_of_function_type.txt index d25fa169f9..ae00ee7d57 100644 --- a/compiler/test_mono/generated/empty_list_of_function_type.txt +++ b/compiler/test_mono/generated/empty_list_of_function_type.txt @@ -1,23 +1,23 @@ -procedure List.3 (#Attr.2, #Attr.3): - let Test.20 : U64 = lowlevel ListLen #Attr.2; - let Test.17 : Int1 = lowlevel NumLt #Attr.3 Test.20; - if Test.17 then - let Test.19 : {} = lowlevel ListGetUnsafe #Attr.2 #Attr.3; - let Test.18 : [C {}, C {}] = Ok Test.19; - ret Test.18; +procedure List.2 (#Attr.2, #Attr.3): + let List.144 : U64 = lowlevel ListLen #Attr.2; + let List.141 : Int1 = lowlevel NumLt #Attr.3 List.144; + if List.141 then + let List.143 : {} = lowlevel ListGetUnsafe #Attr.2 #Attr.3; + let List.142 : [C {}, C {}] = Ok List.143; + ret List.142; else - let Test.16 : {} = Struct {}; - let Test.15 : [C {}, C {}] = Err Test.16; - ret Test.15; + let List.140 : {} = Struct {}; + let List.139 : [C {}, C {}] = Err List.140; + ret List.139; procedure Test.2 (Test.6): - let Test.24 : Str = "bar"; - ret Test.24; + let Test.18 : Str = "bar"; + ret Test.18; procedure Test.0 (): - joinpoint Test.22 Test.3: + joinpoint Test.16 Test.3: let Test.14 : U64 = 0i64; - let Test.7 : [C {}, C {}] = CallByName List.3 Test.3 Test.14; + let Test.7 : [C {}, C {}] = CallByName List.2 Test.3 Test.14; dec Test.3; let Test.11 : U8 = 1i64; let Test.12 : U8 = GetTagId Test.7; @@ -32,11 +32,11 @@ procedure Test.0 (): let Test.10 : Str = "bad!"; ret Test.10; in - let Test.25 : Int1 = false; - if Test.25 then + let Test.19 : Int1 = false; + if Test.19 then let Test.1 : List {} = Array []; - jump Test.22 Test.1; + jump Test.16 Test.1; else - let Test.23 : {} = Struct {}; - let Test.21 : List {} = Array [Test.23]; - jump Test.22 Test.21; + let Test.17 : {} = Struct {}; + let Test.15 : List {} = Array [Test.17]; + jump Test.16 Test.15; diff --git a/compiler/test_mono/generated/factorial.txt b/compiler/test_mono/generated/factorial.txt index f318bd7aa3..449fcd3072 100644 --- a/compiler/test_mono/generated/factorial.txt +++ b/compiler/test_mono/generated/factorial.txt @@ -1,24 +1,24 @@ -procedure Num.23 (#Attr.2, #Attr.3): - let Test.14 : I64 = lowlevel NumSub #Attr.2 #Attr.3; - ret Test.14; +procedure Num.20 (#Attr.2, #Attr.3): + let Num.229 : I64 = lowlevel NumSub #Attr.2 #Attr.3; + ret Num.229; -procedure Num.24 (#Attr.2, #Attr.3): - let Test.12 : I64 = lowlevel NumMul #Attr.2 #Attr.3; - ret Test.12; +procedure Num.21 (#Attr.2, #Attr.3): + let Num.228 : I64 = lowlevel NumMul #Attr.2 #Attr.3; + ret Num.228; -procedure Test.1 (Test.17, Test.18): +procedure Test.1 (Test.15, Test.16): joinpoint Test.7 Test.2 Test.3: - let Test.15 : I64 = 0i64; - let Test.16 : Int1 = lowlevel Eq Test.15 Test.2; - if Test.16 then + let Test.13 : I64 = 0i64; + let Test.14 : Int1 = lowlevel Eq Test.13 Test.2; + if Test.14 then ret Test.3; else - let Test.13 : I64 = 1i64; - let Test.10 : I64 = CallByName Num.23 Test.2 Test.13; - let Test.11 : I64 = CallByName Num.24 Test.2 Test.3; + let Test.12 : I64 = 1i64; + let Test.10 : I64 = CallByName Num.20 Test.2 Test.12; + let Test.11 : I64 = CallByName Num.21 Test.2 Test.3; jump Test.7 Test.10 Test.11; in - jump Test.7 Test.17 Test.18; + jump Test.7 Test.15 Test.16; procedure Test.0 (): let Test.5 : I64 = 10i64; diff --git a/compiler/test_mono/generated/has_none.txt b/compiler/test_mono/generated/has_none.txt index 5cd44fc90f..19a2c3d273 100644 --- a/compiler/test_mono/generated/has_none.txt +++ b/compiler/test_mono/generated/has_none.txt @@ -15,7 +15,7 @@ procedure Test.3 (Test.29): let Test.15 : Int1 = true; ret Test.15; else - let Test.7 : TODO = UnionAtIndex (Id 0) (Index 1) Test.4; + let Test.7 : [, C [C I64, C ] *self] = UnionAtIndex (Id 0) (Index 1) Test.4; jump Test.13 Test.7; in jump Test.13 Test.29; @@ -23,8 +23,8 @@ procedure Test.3 (Test.29): procedure Test.0 (): let Test.28 : I64 = 3i64; let Test.26 : [C I64, C ] = Just Test.28; - let Test.27 : TODO = Nil ; - let Test.12 : TODO = Cons Test.26 Test.27; + let Test.27 : [, C [C I64, C ] *self] = Nil ; + let Test.12 : [, C [C I64, C ] *self] = Cons Test.26 Test.27; let Test.11 : Int1 = CallByName Test.3 Test.12; dec Test.12; ret Test.11; diff --git a/compiler/test_mono/generated/if_guard_bind_variable_false.txt b/compiler/test_mono/generated/if_guard_bind_variable_false.txt index abd10f26af..cf492ae71d 100644 --- a/compiler/test_mono/generated/if_guard_bind_variable_false.txt +++ b/compiler/test_mono/generated/if_guard_bind_variable_false.txt @@ -1,16 +1,16 @@ procedure Bool.7 (#Attr.2, #Attr.3): - let Test.11 : Int1 = lowlevel Eq #Attr.2 #Attr.3; - ret Test.11; + let Bool.14 : Int1 = lowlevel Eq #Attr.2 #Attr.3; + ret Bool.14; procedure Test.1 (Test.3): let Test.6 : I64 = 10i64; - joinpoint Test.8 Test.13: - if Test.13 then + joinpoint Test.8 Test.12: + if Test.12 then let Test.7 : I64 = 0i64; ret Test.7; else - let Test.12 : I64 = 42i64; - ret Test.12; + let Test.11 : I64 = 42i64; + ret Test.11; in let Test.10 : I64 = 5i64; let Test.9 : Int1 = CallByName Bool.7 Test.6 Test.10; diff --git a/compiler/test_mono/generated/ir_int_add.txt b/compiler/test_mono/generated/ir_int_add.txt index bee729da6d..76ed6d9e5d 100644 --- a/compiler/test_mono/generated/ir_int_add.txt +++ b/compiler/test_mono/generated/ir_int_add.txt @@ -1,19 +1,19 @@ -procedure List.7 (#Attr.2): - let Test.7 : U64 = lowlevel ListLen #Attr.2; - ret Test.7; +procedure List.6 (#Attr.2): + let List.139 : U64 = lowlevel ListLen #Attr.2; + ret List.139; -procedure Num.22 (#Attr.2, #Attr.3): - let Test.5 : U64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Test.5; +procedure Num.19 (#Attr.2, #Attr.3): + let Num.230 : U64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.230; procedure Test.0 (): - let Test.10 : U64 = 5i64; - let Test.11 : U64 = 4i64; - let Test.8 : U64 = CallByName Num.22 Test.10 Test.11; - let Test.9 : U64 = 3i64; - let Test.3 : U64 = CallByName Num.22 Test.8 Test.9; - let Test.6 : List I64 = Array [1i64, 2i64]; - let Test.4 : U64 = CallByName List.7 Test.6; - dec Test.6; - let Test.2 : U64 = CallByName Num.22 Test.3 Test.4; + let Test.8 : U64 = 5i64; + let Test.9 : U64 = 4i64; + let Test.6 : U64 = CallByName Num.19 Test.8 Test.9; + let Test.7 : U64 = 3i64; + let Test.3 : U64 = CallByName Num.19 Test.6 Test.7; + let Test.5 : List I64 = Array [1i64, 2i64]; + let Test.4 : U64 = CallByName List.6 Test.5; + dec Test.5; + let Test.2 : U64 = CallByName Num.19 Test.3 Test.4; ret Test.2; diff --git a/compiler/test_mono/generated/ir_plus.txt b/compiler/test_mono/generated/ir_plus.txt index 3bcafd0029..141f90d4a3 100644 --- a/compiler/test_mono/generated/ir_plus.txt +++ b/compiler/test_mono/generated/ir_plus.txt @@ -1,9 +1,9 @@ -procedure Num.22 (#Attr.2, #Attr.3): - let Test.4 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Test.4; +procedure Num.19 (#Attr.2, #Attr.3): + let Num.228 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.228; procedure Test.0 (): let Test.2 : I64 = 1i64; let Test.3 : I64 = 2i64; - let Test.1 : I64 = CallByName Num.22 Test.2 Test.3; + let Test.1 : I64 = CallByName Num.19 Test.2 Test.3; ret Test.1; diff --git a/compiler/test_mono/generated/ir_round.txt b/compiler/test_mono/generated/ir_round.txt index a62c2c4a09..6686a4e849 100644 --- a/compiler/test_mono/generated/ir_round.txt +++ b/compiler/test_mono/generated/ir_round.txt @@ -1,6 +1,6 @@ procedure Num.45 (#Attr.2): - let Test.3 : I64 = lowlevel NumRound #Attr.2; - ret Test.3; + let Num.228 : I64 = lowlevel NumRound #Attr.2; + ret Num.228; procedure Test.0 (): let Test.2 : Float64 = 3.6f64; diff --git a/compiler/test_mono/generated/ir_two_defs.txt b/compiler/test_mono/generated/ir_two_defs.txt index 39d09c2318..a27db2c903 100644 --- a/compiler/test_mono/generated/ir_two_defs.txt +++ b/compiler/test_mono/generated/ir_two_defs.txt @@ -1,9 +1,9 @@ -procedure Num.22 (#Attr.2, #Attr.3): - let Test.6 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Test.6; +procedure Num.19 (#Attr.2, #Attr.3): + let Num.228 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.228; procedure Test.0 (): let Test.4 : I64 = 3i64; let Test.5 : I64 = 4i64; - let Test.3 : I64 = CallByName Num.22 Test.4 Test.5; + let Test.3 : I64 = CallByName Num.19 Test.4 Test.5; ret Test.3; diff --git a/compiler/test_mono/generated/ir_when_idiv.txt b/compiler/test_mono/generated/ir_when_idiv.txt index 999d7f762e..b1fb84e522 100644 --- a/compiler/test_mono/generated/ir_when_idiv.txt +++ b/compiler/test_mono/generated/ir_when_idiv.txt @@ -1,14 +1,14 @@ procedure Num.40 (#Attr.2, #Attr.3): - let Test.15 : I64 = 0i64; - let Test.12 : Int1 = lowlevel NotEq #Attr.3 Test.15; - if Test.12 then - let Test.14 : I64 = lowlevel NumDivUnchecked #Attr.2 #Attr.3; - let Test.13 : [C {}, C I64] = Ok Test.14; - ret Test.13; + let Num.233 : I64 = 0i64; + let Num.230 : Int1 = lowlevel NotEq #Attr.3 Num.233; + if Num.230 then + let Num.232 : I64 = lowlevel NumDivUnchecked #Attr.2 #Attr.3; + let Num.231 : [C {}, C I64] = Ok Num.232; + ret Num.231; else - let Test.11 : {} = Struct {}; - let Test.10 : [C {}, C I64] = Err Test.11; - ret Test.10; + let Num.229 : {} = Struct {}; + let Num.228 : [C {}, C I64] = Err Num.229; + ret Num.228; procedure Test.0 (): let Test.8 : I64 = 1000i64; diff --git a/compiler/test_mono/generated/ir_when_just.txt b/compiler/test_mono/generated/ir_when_just.txt index c3e60612d4..e11182583b 100644 --- a/compiler/test_mono/generated/ir_when_just.txt +++ b/compiler/test_mono/generated/ir_when_just.txt @@ -1,18 +1,18 @@ -procedure Num.22 (#Attr.2, #Attr.3): - let Test.6 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Test.6; +procedure Num.19 (#Attr.2, #Attr.3): + let Num.228 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.228; procedure Test.0 (): - let Test.11 : I64 = 41i64; - let Test.1 : [C I64, C ] = Just Test.11; - let Test.8 : U8 = 0i64; - let Test.9 : U8 = GetTagId Test.1; - let Test.10 : Int1 = lowlevel Eq Test.8 Test.9; - if Test.10 then + let Test.10 : I64 = 41i64; + let Test.1 : [C I64, C ] = Just Test.10; + let Test.7 : U8 = 0i64; + let Test.8 : U8 = GetTagId Test.1; + let Test.9 : Int1 = lowlevel Eq Test.7 Test.8; + if Test.9 then let Test.3 : I64 = UnionAtIndex (Id 0) (Index 0) Test.1; let Test.5 : I64 = 1i64; - let Test.4 : I64 = CallByName Num.22 Test.3 Test.5; + let Test.4 : I64 = CallByName Num.19 Test.3 Test.5; ret Test.4; else - let Test.7 : I64 = 1i64; - ret Test.7; + let Test.6 : I64 = 1i64; + ret Test.6; diff --git a/compiler/test_mono/generated/is_nil.txt b/compiler/test_mono/generated/is_nil.txt index 72af4853cd..c12eed1f71 100644 --- a/compiler/test_mono/generated/is_nil.txt +++ b/compiler/test_mono/generated/is_nil.txt @@ -11,8 +11,8 @@ procedure Test.2 (Test.3): procedure Test.0 (): let Test.15 : I64 = 2i64; - let Test.16 : TODO = Nil ; - let Test.9 : TODO = Cons Test.15 Test.16; + let Test.16 : [, C I64 *self] = Nil ; + let Test.9 : [, C I64 *self] = Cons Test.15 Test.16; let Test.8 : Int1 = CallByName Test.2 Test.9; dec Test.9; ret Test.8; diff --git a/compiler/test_mono/generated/issue_2583_specialize_errors_behind_unified_branches.txt b/compiler/test_mono/generated/issue_2583_specialize_errors_behind_unified_branches.txt index 1cb2cc555f..95aed66add 100644 --- a/compiler/test_mono/generated/issue_2583_specialize_errors_behind_unified_branches.txt +++ b/compiler/test_mono/generated/issue_2583_specialize_errors_behind_unified_branches.txt @@ -1,40 +1,40 @@ -procedure List.10 (#Attr.2): - let Test.20 : U64 = 0i64; - let Test.21 : U64 = lowlevel ListLen #Attr.2; - let Test.16 : Int1 = lowlevel NotEq Test.20 Test.21; - if Test.16 then - let Test.19 : U64 = 0i64; - let Test.18 : I64 = lowlevel ListGetUnsafe #Attr.2 Test.19; - let Test.17 : [C Int1, C I64] = Ok Test.18; - ret Test.17; +procedure List.9 (#Attr.2): + let List.145 : U64 = 0i64; + let List.146 : U64 = lowlevel ListLen #Attr.2; + let List.141 : Int1 = lowlevel NotEq List.145 List.146; + if List.141 then + let List.144 : U64 = 0i64; + let List.143 : I64 = lowlevel ListGetUnsafe #Attr.2 List.144; + let List.142 : [C Int1, C I64] = Ok List.143; + ret List.142; else - let Test.15 : Int1 = true; - let Test.14 : [C Int1, C I64] = Err Test.15; - ret Test.14; + let List.140 : Int1 = true; + let List.139 : [C Int1, C I64] = Err List.140; + ret List.139; -procedure Str.28 (#Attr.2): +procedure Str.27 (#Attr.2): let #Attr.3 : {I64, U8} = lowlevel StrToNum #Attr.2; - let Test.9 : U8 = StructAtIndex 1 #Attr.3; - let Test.10 : U8 = 0i64; - let Test.6 : Int1 = lowlevel NumGt Test.9 Test.10; - if Test.6 then - let Test.8 : Int1 = false; - let Test.7 : [C Int1, C I64] = Err Test.8; - ret Test.7; + let Str.69 : U8 = StructAtIndex 1 #Attr.3; + let Str.70 : U8 = 0i64; + let Str.66 : Int1 = lowlevel NumGt Str.69 Str.70; + if Str.66 then + let Str.68 : Int1 = false; + let Str.67 : [C Int1, C I64] = Err Str.68; + ret Str.67; else - let Test.5 : I64 = StructAtIndex 0 #Attr.3; - let Test.4 : [C Int1, C I64] = Ok Test.5; - ret Test.4; + let Str.65 : I64 = StructAtIndex 0 #Attr.3; + let Str.64 : [C Int1, C I64] = Ok Str.65; + ret Str.64; procedure Test.0 (): - let Test.11 : Int1 = true; - if Test.11 then - let Test.13 : List I64 = Array []; - let Test.12 : [C Int1, C I64] = CallByName List.10 Test.13; - dec Test.13; - ret Test.12; + let Test.4 : Int1 = true; + if Test.4 then + let Test.6 : List I64 = Array []; + let Test.5 : [C Int1, C I64] = CallByName List.9 Test.6; + dec Test.6; + ret Test.5; else let Test.3 : Str = ""; - let Test.2 : [C Int1, C I64] = CallByName Str.28 Test.3; + let Test.2 : [C Int1, C I64] = CallByName Str.27 Test.3; dec Test.3; ret Test.2; diff --git a/compiler/test_mono/generated/issue_2810.txt b/compiler/test_mono/generated/issue_2810.txt index d5b11bcac2..60660e287c 100644 --- a/compiler/test_mono/generated/issue_2810.txt +++ b/compiler/test_mono/generated/issue_2810.txt @@ -1,6 +1,6 @@ procedure Test.0 (): - let Test.16 : [C TODO, C ] = SystemTool ; - let Test.14 : TODO = Job Test.16; - let Test.13 : [C TODO, C ] = FromJob Test.14; - let Test.4 : TODO = Job Test.13; + let Test.16 : [C [C [C *self, C ]], C ] = SystemTool ; + let Test.14 : [C [C *self, C ]] = Job Test.16; + let Test.13 : [C [C [C *self, C ]], C ] = FromJob Test.14; + let Test.4 : [C [C *self, C ]] = Job Test.13; ret Test.4; diff --git a/compiler/test_mono/generated/linked_list_length_twice.txt b/compiler/test_mono/generated/linked_list_length_twice.txt index 3b1d0984f3..4d99868290 100644 --- a/compiler/test_mono/generated/linked_list_length_twice.txt +++ b/compiler/test_mono/generated/linked_list_length_twice.txt @@ -1,25 +1,25 @@ -procedure Num.22 (#Attr.2, #Attr.3): - let Test.10 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Test.10; +procedure Num.19 (#Attr.2, #Attr.3): + let Num.229 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.229; procedure Test.3 (Test.5): - let Test.16 : Int1 = 1i64; - let Test.17 : Int1 = GetTagId Test.5; - let Test.18 : Int1 = lowlevel Eq Test.16 Test.17; - if Test.18 then - let Test.12 : I64 = 0i64; - ret Test.12; + let Test.15 : Int1 = 1i64; + let Test.16 : Int1 = GetTagId Test.5; + let Test.17 : Int1 = lowlevel Eq Test.15 Test.16; + if Test.17 then + let Test.11 : I64 = 0i64; + ret Test.11; else - let Test.6 : TODO = UnionAtIndex (Id 0) (Index 1) Test.5; - let Test.14 : I64 = 1i64; - let Test.15 : I64 = CallByName Test.3 Test.6; - let Test.13 : I64 = CallByName Num.22 Test.14 Test.15; - ret Test.13; + let Test.6 : [, C I64 *self] = UnionAtIndex (Id 0) (Index 1) Test.5; + let Test.13 : I64 = 1i64; + let Test.14 : I64 = CallByName Test.3 Test.6; + let Test.12 : I64 = CallByName Num.19 Test.13 Test.14; + ret Test.12; procedure Test.0 (): - let Test.2 : TODO = Nil ; + let Test.2 : [, C I64 *self] = Nil ; let Test.8 : I64 = CallByName Test.3 Test.2; let Test.9 : I64 = CallByName Test.3 Test.2; dec Test.2; - let Test.7 : I64 = CallByName Num.22 Test.8 Test.9; + let Test.7 : I64 = CallByName Num.19 Test.8 Test.9; ret Test.7; diff --git a/compiler/test_mono/generated/list_append.txt b/compiler/test_mono/generated/list_append.txt index c899f2abd7..93bb4798f8 100644 --- a/compiler/test_mono/generated/list_append.txt +++ b/compiler/test_mono/generated/list_append.txt @@ -1,9 +1,9 @@ -procedure List.5 (#Attr.2, #Attr.3): - let Test.4 : List I64 = lowlevel ListAppend #Attr.2 #Attr.3; - ret Test.4; +procedure List.4 (#Attr.2, #Attr.3): + let List.139 : List I64 = lowlevel ListAppend #Attr.2 #Attr.3; + ret List.139; procedure Test.0 (): let Test.2 : List I64 = Array [1i64]; let Test.3 : I64 = 2i64; - let Test.1 : List I64 = CallByName List.5 Test.2 Test.3; + let Test.1 : List I64 = CallByName List.4 Test.2 Test.3; ret Test.1; diff --git a/compiler/test_mono/generated/list_append_closure.txt b/compiler/test_mono/generated/list_append_closure.txt index 43227f7089..80d4aae9c5 100644 --- a/compiler/test_mono/generated/list_append_closure.txt +++ b/compiler/test_mono/generated/list_append_closure.txt @@ -1,10 +1,10 @@ -procedure List.5 (#Attr.2, #Attr.3): - let Test.7 : List I64 = lowlevel ListAppend #Attr.2 #Attr.3; - ret Test.7; +procedure List.4 (#Attr.2, #Attr.3): + let List.139 : List I64 = lowlevel ListAppend #Attr.2 #Attr.3; + ret List.139; procedure Test.1 (Test.2): let Test.6 : I64 = 42i64; - let Test.5 : List I64 = CallByName List.5 Test.2 Test.6; + let Test.5 : List I64 = CallByName List.4 Test.2 Test.6; ret Test.5; procedure Test.0 (): diff --git a/compiler/test_mono/generated/list_cannot_update_inplace.txt b/compiler/test_mono/generated/list_cannot_update_inplace.txt index 42ba0d2a8e..fd3a3616e8 100644 --- a/compiler/test_mono/generated/list_cannot_update_inplace.txt +++ b/compiler/test_mono/generated/list_cannot_update_inplace.txt @@ -1,50 +1,45 @@ -procedure List.4 (#Attr.2, #Attr.3, #Attr.4): - let Test.24 : U64 = lowlevel ListLen #Attr.2; - let Test.17 : Int1 = lowlevel NumLt #Attr.3 Test.24; - if Test.17 then - let Test.19 : {List I64, I64} = CallByName List.58 #Attr.2 #Attr.3 #Attr.4; - let Test.18 : List I64 = StructAtIndex 0 Test.19; - inc Test.18; - dec Test.19; - ret Test.18; +procedure List.3 (List.63, List.64, List.65): + let List.142 : {List I64, I64} = CallByName List.57 List.63 List.64 List.65; + let List.141 : List I64 = StructAtIndex 0 List.142; + inc List.141; + dec List.142; + ret List.141; + +procedure List.57 (#Attr.2, #Attr.3, #Attr.4): + let List.146 : U64 = lowlevel ListLen #Attr.2; + let List.144 : Int1 = lowlevel NumLt #Attr.3 List.146; + if List.144 then + let List.145 : {List I64, I64} = lowlevel ListReplaceUnsafe #Attr.2 #Attr.3 #Attr.4; + ret List.145; else - ret #Attr.2; + let List.143 : {List I64, I64} = Struct {#Attr.2, #Attr.4}; + ret List.143; -procedure List.58 (#Attr.2, #Attr.3, #Attr.4): - let Test.23 : U64 = lowlevel ListLen #Attr.2; - let Test.21 : Int1 = lowlevel NumLt #Attr.3 Test.23; - if Test.21 then - let Test.22 : {List I64, I64} = lowlevel ListReplaceUnsafe #Attr.2 #Attr.3 #Attr.4; - ret Test.22; - else - let Test.20 : {List I64, I64} = Struct {#Attr.2, #Attr.4}; - ret Test.20; +procedure List.6 (#Attr.2): + let List.140 : U64 = lowlevel ListLen #Attr.2; + ret List.140; -procedure List.7 (#Attr.2): - let Test.9 : U64 = lowlevel ListLen #Attr.2; - ret Test.9; - -procedure Num.22 (#Attr.2, #Attr.3): - let Test.7 : U64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Test.7; +procedure Num.19 (#Attr.2, #Attr.3): + let Num.228 : U64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.228; procedure Test.1 (): - let Test.10 : List I64 = Array [1i64, 2i64, 3i64]; - ret Test.10; + let Test.8 : List I64 = Array [1i64, 2i64, 3i64]; + ret Test.8; procedure Test.2 (Test.3): - let Test.14 : U64 = 0i64; - let Test.15 : I64 = 0i64; - let Test.13 : List I64 = CallByName List.4 Test.3 Test.14 Test.15; - ret Test.13; + let Test.12 : U64 = 0i64; + let Test.13 : I64 = 0i64; + let Test.11 : List I64 = CallByName List.3 Test.3 Test.12 Test.13; + ret Test.11; procedure Test.0 (): - let Test.12 : List I64 = CallByName Test.1; - let Test.11 : List I64 = CallByName Test.2 Test.12; - let Test.5 : U64 = CallByName List.7 Test.11; - dec Test.11; - let Test.8 : List I64 = CallByName Test.1; - let Test.6 : U64 = CallByName List.7 Test.8; - dec Test.8; - let Test.4 : U64 = CallByName Num.22 Test.5 Test.6; + let Test.10 : List I64 = CallByName Test.1; + let Test.9 : List I64 = CallByName Test.2 Test.10; + let Test.5 : U64 = CallByName List.6 Test.9; + dec Test.9; + let Test.7 : List I64 = CallByName Test.1; + let Test.6 : U64 = CallByName List.6 Test.7; + dec Test.7; + let Test.4 : U64 = CallByName Num.19 Test.5 Test.6; ret Test.4; diff --git a/compiler/test_mono/generated/list_get.txt b/compiler/test_mono/generated/list_get.txt index b8d8636c97..7e5e29fff8 100644 --- a/compiler/test_mono/generated/list_get.txt +++ b/compiler/test_mono/generated/list_get.txt @@ -1,19 +1,19 @@ -procedure List.3 (#Attr.2, #Attr.3): - let Test.13 : U64 = lowlevel ListLen #Attr.2; - let Test.10 : Int1 = lowlevel NumLt #Attr.3 Test.13; - if Test.10 then - let Test.12 : I64 = lowlevel ListGetUnsafe #Attr.2 #Attr.3; - let Test.11 : [C {}, C I64] = Ok Test.12; - ret Test.11; +procedure List.2 (#Attr.2, #Attr.3): + let List.144 : U64 = lowlevel ListLen #Attr.2; + let List.141 : Int1 = lowlevel NumLt #Attr.3 List.144; + if List.141 then + let List.143 : I64 = lowlevel ListGetUnsafe #Attr.2 #Attr.3; + let List.142 : [C {}, C I64] = Ok List.143; + ret List.142; else - let Test.9 : {} = Struct {}; - let Test.8 : [C {}, C I64] = Err Test.9; - ret Test.8; + let List.140 : {} = Struct {}; + let List.139 : [C {}, C I64] = Err List.140; + ret List.139; procedure Test.1 (Test.2): let Test.6 : List I64 = Array [1i64, 2i64, 3i64]; let Test.7 : U64 = 0i64; - let Test.5 : [C {}, C I64] = CallByName List.3 Test.6 Test.7; + let Test.5 : [C {}, C I64] = CallByName List.2 Test.6 Test.7; dec Test.6; ret Test.5; diff --git a/compiler/test_mono/generated/list_len.txt b/compiler/test_mono/generated/list_len.txt index 13d10a54ce..9735510540 100644 --- a/compiler/test_mono/generated/list_len.txt +++ b/compiler/test_mono/generated/list_len.txt @@ -1,21 +1,21 @@ -procedure List.7 (#Attr.2): - let Test.10 : U64 = lowlevel ListLen #Attr.2; - ret Test.10; +procedure List.6 (#Attr.2): + let List.139 : U64 = lowlevel ListLen #Attr.2; + ret List.139; -procedure List.7 (#Attr.2): - let Test.8 : U64 = lowlevel ListLen #Attr.2; - ret Test.8; +procedure List.6 (#Attr.2): + let List.140 : U64 = lowlevel ListLen #Attr.2; + ret List.140; -procedure Num.22 (#Attr.2, #Attr.3): - let Test.6 : U64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Test.6; +procedure Num.19 (#Attr.2, #Attr.3): + let Num.228 : U64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.228; procedure Test.0 (): - let Test.9 : List I64 = Array [1i64, 2i64, 3i64]; - let Test.4 : U64 = CallByName List.7 Test.9; - dec Test.9; - let Test.7 : List Float64 = Array [1f64]; - let Test.5 : U64 = CallByName List.7 Test.7; + let Test.7 : List I64 = Array [1i64, 2i64, 3i64]; + let Test.4 : U64 = CallByName List.6 Test.7; dec Test.7; - let Test.3 : U64 = CallByName Num.22 Test.4 Test.5; + let Test.6 : List Float64 = Array [1f64]; + let Test.5 : U64 = CallByName List.6 Test.6; + dec Test.6; + let Test.3 : U64 = CallByName Num.19 Test.4 Test.5; ret Test.3; diff --git a/compiler/test_mono/generated/list_pass_to_function.txt b/compiler/test_mono/generated/list_pass_to_function.txt index 99a6e73255..a53e9f973a 100644 --- a/compiler/test_mono/generated/list_pass_to_function.txt +++ b/compiler/test_mono/generated/list_pass_to_function.txt @@ -1,29 +1,24 @@ -procedure List.4 (#Attr.2, #Attr.3, #Attr.4): - let Test.16 : U64 = lowlevel ListLen #Attr.2; - let Test.9 : Int1 = lowlevel NumLt #Attr.3 Test.16; - if Test.9 then - let Test.11 : {List I64, I64} = CallByName List.58 #Attr.2 #Attr.3 #Attr.4; - let Test.10 : List I64 = StructAtIndex 0 Test.11; - inc Test.10; - dec Test.11; - ret Test.10; - else - ret #Attr.2; +procedure List.3 (List.63, List.64, List.65): + let List.140 : {List I64, I64} = CallByName List.57 List.63 List.64 List.65; + let List.139 : List I64 = StructAtIndex 0 List.140; + inc List.139; + dec List.140; + ret List.139; -procedure List.58 (#Attr.2, #Attr.3, #Attr.4): - let Test.15 : U64 = lowlevel ListLen #Attr.2; - let Test.13 : Int1 = lowlevel NumLt #Attr.3 Test.15; - if Test.13 then - let Test.14 : {List I64, I64} = lowlevel ListReplaceUnsafe #Attr.2 #Attr.3 #Attr.4; - ret Test.14; +procedure List.57 (#Attr.2, #Attr.3, #Attr.4): + let List.144 : U64 = lowlevel ListLen #Attr.2; + let List.142 : Int1 = lowlevel NumLt #Attr.3 List.144; + if List.142 then + let List.143 : {List I64, I64} = lowlevel ListReplaceUnsafe #Attr.2 #Attr.3 #Attr.4; + ret List.143; else - let Test.12 : {List I64, I64} = Struct {#Attr.2, #Attr.4}; - ret Test.12; + let List.141 : {List I64, I64} = Struct {#Attr.2, #Attr.4}; + ret List.141; procedure Test.2 (Test.3): let Test.6 : U64 = 0i64; let Test.7 : I64 = 0i64; - let Test.5 : List I64 = CallByName List.4 Test.3 Test.6 Test.7; + let Test.5 : List I64 = CallByName List.3 Test.3 Test.6 Test.7; ret Test.5; procedure Test.0 (): diff --git a/compiler/test_mono/generated/monomorphized_ints_aliased.txt b/compiler/test_mono/generated/monomorphized_ints_aliased.txt index b461c2a04e..f65562e3fd 100644 --- a/compiler/test_mono/generated/monomorphized_ints_aliased.txt +++ b/compiler/test_mono/generated/monomorphized_ints_aliased.txt @@ -1,21 +1,21 @@ -procedure Num.22 (#Attr.2, #Attr.3): - let Test.12 : U64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Test.12; +procedure Num.19 (#Attr.2, #Attr.3): + let Num.228 : U64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.228; procedure Test.5 (Test.7, Test.8): - let Test.18 : U64 = 1i64; - ret Test.18; + let Test.17 : U64 = 1i64; + ret Test.17; procedure Test.6 (Test.7, Test.8): - let Test.15 : U64 = 1i64; - ret Test.15; + let Test.14 : U64 = 1i64; + ret Test.14; procedure Test.0 (): - let Test.16 : U8 = 100i64; - let Test.17 : U32 = 100i64; - let Test.10 : U64 = CallByName Test.5 Test.16 Test.17; - let Test.13 : U32 = 100i64; - let Test.14 : U8 = 100i64; - let Test.11 : U64 = CallByName Test.6 Test.13 Test.14; - let Test.9 : U64 = CallByName Num.22 Test.10 Test.11; + let Test.15 : U8 = 100i64; + let Test.16 : U32 = 100i64; + let Test.10 : U64 = CallByName Test.5 Test.15 Test.16; + let Test.12 : U32 = 100i64; + let Test.13 : U8 = 100i64; + let Test.11 : U64 = CallByName Test.6 Test.12 Test.13; + let Test.9 : U64 = CallByName Num.19 Test.10 Test.11; ret Test.9; diff --git a/compiler/test_mono/generated/nested_pattern_match.txt b/compiler/test_mono/generated/nested_pattern_match.txt index 6bb9eebf35..061f72e7c9 100644 --- a/compiler/test_mono/generated/nested_pattern_match.txt +++ b/compiler/test_mono/generated/nested_pattern_match.txt @@ -1,30 +1,30 @@ -procedure Num.22 (#Attr.2, #Attr.3): - let Test.8 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Test.8; +procedure Num.19 (#Attr.2, #Attr.3): + let Num.228 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.228; procedure Test.0 (): - let Test.20 : I64 = 41i64; - let Test.19 : [C I64, C ] = Just Test.20; - let Test.2 : [C [C I64, C ], C ] = Just Test.19; - joinpoint Test.16: - let Test.9 : I64 = 1i64; - ret Test.9; + let Test.19 : I64 = 41i64; + let Test.18 : [C I64, C ] = Just Test.19; + let Test.2 : [C [C I64, C ], C ] = Just Test.18; + joinpoint Test.15: + let Test.8 : I64 = 1i64; + ret Test.8; in - let Test.14 : U8 = 0i64; - let Test.15 : U8 = GetTagId Test.2; - let Test.18 : Int1 = lowlevel Eq Test.14 Test.15; - if Test.18 then - let Test.11 : [C I64, C ] = UnionAtIndex (Id 0) (Index 0) Test.2; - let Test.12 : U8 = 0i64; - let Test.13 : U8 = GetTagId Test.11; - let Test.17 : Int1 = lowlevel Eq Test.12 Test.13; - if Test.17 then - let Test.10 : [C I64, C ] = UnionAtIndex (Id 0) (Index 0) Test.2; - let Test.5 : I64 = UnionAtIndex (Id 0) (Index 0) Test.10; + let Test.13 : U8 = 0i64; + let Test.14 : U8 = GetTagId Test.2; + let Test.17 : Int1 = lowlevel Eq Test.13 Test.14; + if Test.17 then + let Test.10 : [C I64, C ] = UnionAtIndex (Id 0) (Index 0) Test.2; + let Test.11 : U8 = 0i64; + let Test.12 : U8 = GetTagId Test.10; + let Test.16 : Int1 = lowlevel Eq Test.11 Test.12; + if Test.16 then + let Test.9 : [C I64, C ] = UnionAtIndex (Id 0) (Index 0) Test.2; + let Test.5 : I64 = UnionAtIndex (Id 0) (Index 0) Test.9; let Test.7 : I64 = 1i64; - let Test.6 : I64 = CallByName Num.22 Test.5 Test.7; + let Test.6 : I64 = CallByName Num.19 Test.5 Test.7; ret Test.6; else - jump Test.16; + jump Test.15; else - jump Test.16; + jump Test.15; diff --git a/compiler/test_mono/generated/opaque_assign_to_symbol.txt b/compiler/test_mono/generated/opaque_assign_to_symbol.txt index 8e0c7fe63b..23eee2ceea 100644 --- a/compiler/test_mono/generated/opaque_assign_to_symbol.txt +++ b/compiler/test_mono/generated/opaque_assign_to_symbol.txt @@ -1,10 +1,8 @@ -procedure : `#UserApp.fromUtf8` [C {}, C U8] -procedure = `#UserApp.fromUtf8` (`#UserApp.char`): - let `#UserApp.3` : [C {}, C U8] = Ok `#UserApp.4`; - ret `#UserApp.3`; +procedure Test.3 (Test.4): + let Test.8 : [C {}, C U8] = Ok Test.4; + ret Test.8; -procedure : `#UserApp.out` [C {}, C U8] -procedure = `#UserApp.out` (): - let `#UserApp.2` : U8 = 98i64; - let `#UserApp.1` : [C {}, C U8] = CallByName `#UserApp.fromUtf8` `#UserApp.2`; - ret `#UserApp.1`; +procedure Test.0 (): + let Test.7 : U8 = 98i64; + let Test.6 : [C {}, C U8] = CallByName Test.3 Test.7; + ret Test.6; diff --git a/compiler/test_mono/generated/optional_when.txt b/compiler/test_mono/generated/optional_when.txt index b2649e0a96..25ab447db4 100644 --- a/compiler/test_mono/generated/optional_when.txt +++ b/compiler/test_mono/generated/optional_when.txt @@ -1,11 +1,11 @@ -procedure Num.24 (#Attr.2, #Attr.3): - let Test.18 : I64 = lowlevel NumMul #Attr.2 #Attr.3; - ret Test.18; +procedure Num.21 (#Attr.2, #Attr.3): + let Num.230 : I64 = lowlevel NumMul #Attr.2 #Attr.3; + ret Num.230; procedure Test.1 (Test.6): - let Test.22 : Int1 = false; - let Test.23 : Int1 = lowlevel Eq Test.22 Test.6; - if Test.23 then + let Test.21 : Int1 = false; + let Test.22 : Int1 = lowlevel Eq Test.21 Test.6; + if Test.22 then let Test.8 : I64 = 3i64; ret Test.8; else @@ -13,10 +13,10 @@ procedure Test.1 (Test.6): ret Test.10; procedure Test.1 (Test.6): - let Test.30 : Int1 = StructAtIndex 1 Test.6; - let Test.31 : Int1 = false; - let Test.32 : Int1 = lowlevel Eq Test.31 Test.30; - if Test.32 then + let Test.29 : Int1 = StructAtIndex 1 Test.6; + let Test.30 : Int1 = false; + let Test.31 : Int1 = lowlevel Eq Test.30 Test.29; + if Test.31 then let Test.8 : I64 = StructAtIndex 0 Test.6; ret Test.8; else @@ -24,19 +24,19 @@ procedure Test.1 (Test.6): ret Test.10; procedure Test.0 (): - let Test.40 : I64 = 7i64; - let Test.41 : Int1 = false; - let Test.39 : {I64, Int1} = Struct {Test.40, Test.41}; - let Test.35 : I64 = CallByName Test.1 Test.39; - let Test.38 : Int1 = false; - let Test.36 : I64 = CallByName Test.1 Test.38; - let Test.25 : I64 = CallByName Num.24 Test.35 Test.36; - let Test.33 : I64 = 11i64; - let Test.34 : Int1 = true; - let Test.27 : {I64, Int1} = Struct {Test.33, Test.34}; - let Test.26 : I64 = CallByName Test.1 Test.27; - let Test.16 : I64 = CallByName Num.24 Test.25 Test.26; - let Test.24 : Int1 = true; - let Test.17 : I64 = CallByName Test.1 Test.24; - let Test.15 : I64 = CallByName Num.24 Test.16 Test.17; + let Test.39 : I64 = 7i64; + let Test.40 : Int1 = false; + let Test.38 : {I64, Int1} = Struct {Test.39, Test.40}; + let Test.34 : I64 = CallByName Test.1 Test.38; + let Test.37 : Int1 = false; + let Test.35 : I64 = CallByName Test.1 Test.37; + let Test.24 : I64 = CallByName Num.21 Test.34 Test.35; + let Test.32 : I64 = 11i64; + let Test.33 : Int1 = true; + let Test.26 : {I64, Int1} = Struct {Test.32, Test.33}; + let Test.25 : I64 = CallByName Test.1 Test.26; + let Test.16 : I64 = CallByName Num.21 Test.24 Test.25; + let Test.23 : Int1 = true; + let Test.17 : I64 = CallByName Test.1 Test.23; + let Test.15 : I64 = CallByName Num.21 Test.16 Test.17; ret Test.15; diff --git a/compiler/test_mono/generated/peano.txt b/compiler/test_mono/generated/peano.txt index bee928bf10..88f73530ed 100644 --- a/compiler/test_mono/generated/peano.txt +++ b/compiler/test_mono/generated/peano.txt @@ -1,6 +1,6 @@ procedure Test.0 (): - let Test.10 : TODO = Z ; - let Test.9 : TODO = S Test.10; - let Test.8 : TODO = S Test.9; - let Test.2 : TODO = S Test.8; + let Test.10 : [, C *self] = Z ; + let Test.9 : [, C *self] = S Test.10; + let Test.8 : [, C *self] = S Test.9; + let Test.2 : [, C *self] = S Test.8; ret Test.2; diff --git a/compiler/test_mono/generated/peano1.txt b/compiler/test_mono/generated/peano1.txt index 8d6b38bd55..2c0ab5219e 100644 --- a/compiler/test_mono/generated/peano1.txt +++ b/compiler/test_mono/generated/peano1.txt @@ -1,8 +1,8 @@ procedure Test.0 (): - let Test.14 : TODO = Z ; - let Test.13 : TODO = S Test.14; - let Test.12 : TODO = S Test.13; - let Test.2 : TODO = S Test.12; + let Test.14 : [, C *self] = Z ; + let Test.13 : [, C *self] = S Test.14; + let Test.12 : [, C *self] = S Test.13; + let Test.2 : [, C *self] = S Test.12; let Test.9 : Int1 = 1i64; let Test.10 : Int1 = GetTagId Test.2; dec Test.2; diff --git a/compiler/test_mono/generated/peano2.txt b/compiler/test_mono/generated/peano2.txt index a708c54baf..466d098896 100644 --- a/compiler/test_mono/generated/peano2.txt +++ b/compiler/test_mono/generated/peano2.txt @@ -1,13 +1,13 @@ procedure Test.0 (): - let Test.20 : TODO = Z ; - let Test.19 : TODO = S Test.20; - let Test.18 : TODO = S Test.19; - let Test.2 : TODO = S Test.18; + let Test.20 : [, C *self] = Z ; + let Test.19 : [, C *self] = S Test.20; + let Test.18 : [, C *self] = S Test.19; + let Test.2 : [, C *self] = S Test.18; let Test.15 : Int1 = 0i64; let Test.16 : Int1 = GetTagId Test.2; let Test.17 : Int1 = lowlevel Eq Test.15 Test.16; if Test.17 then - let Test.11 : TODO = UnionAtIndex (Id 0) (Index 0) Test.2; + let Test.11 : [, C *self] = UnionAtIndex (Id 0) (Index 0) Test.2; inc Test.11; dec Test.2; let Test.12 : Int1 = 0i64; diff --git a/compiler/test_mono/generated/quicksort_help.txt b/compiler/test_mono/generated/quicksort_help.txt index c9bad93164..1c286140e4 100644 --- a/compiler/test_mono/generated/quicksort_help.txt +++ b/compiler/test_mono/generated/quicksort_help.txt @@ -1,37 +1,37 @@ +procedure Num.19 (#Attr.2, #Attr.3): + let Num.228 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.228; + +procedure Num.20 (#Attr.2, #Attr.3): + let Num.229 : I64 = lowlevel NumSub #Attr.2 #Attr.3; + ret Num.229; + procedure Num.22 (#Attr.2, #Attr.3): - let Test.19 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Test.19; + let Num.230 : Int1 = lowlevel NumLt #Attr.2 #Attr.3; + ret Num.230; -procedure Num.23 (#Attr.2, #Attr.3): - let Test.22 : I64 = lowlevel NumSub #Attr.2 #Attr.3; - ret Test.22; - -procedure Num.25 (#Attr.2, #Attr.3): - let Test.26 : Int1 = lowlevel NumLt #Attr.2 #Attr.3; - ret Test.26; - -procedure Test.1 (Test.27, Test.28, Test.29): +procedure Test.1 (Test.24, Test.25, Test.26): joinpoint Test.12 Test.2 Test.3 Test.4: - let Test.14 : Int1 = CallByName Num.25 Test.3 Test.4; + let Test.14 : Int1 = CallByName Num.22 Test.3 Test.4; if Test.14 then dec Test.2; - let Test.25 : List [] = Array []; - let Test.24 : I64 = 0i64; - let Test.23 : {I64, List []} = Struct {Test.24, Test.25}; - let Test.5 : I64 = StructAtIndex 0 Test.23; - let Test.6 : List [] = StructAtIndex 1 Test.23; + let Test.23 : List [] = Array []; + let Test.22 : I64 = 0i64; + let Test.21 : {I64, List []} = Struct {Test.22, Test.23}; + let Test.5 : I64 = StructAtIndex 0 Test.21; + let Test.6 : List [] = StructAtIndex 1 Test.21; inc Test.6; - dec Test.23; - let Test.21 : I64 = 1i64; - let Test.20 : I64 = CallByName Num.23 Test.5 Test.21; - let Test.16 : List I64 = CallByName Test.1 Test.6 Test.3 Test.20; + dec Test.21; + let Test.20 : I64 = 1i64; + let Test.19 : I64 = CallByName Num.20 Test.5 Test.20; + let Test.16 : List I64 = CallByName Test.1 Test.6 Test.3 Test.19; let Test.18 : I64 = 1i64; - let Test.17 : I64 = CallByName Num.22 Test.5 Test.18; + let Test.17 : I64 = CallByName Num.19 Test.5 Test.18; jump Test.12 Test.16 Test.17 Test.4; else ret Test.2; in - jump Test.12 Test.27 Test.28 Test.29; + jump Test.12 Test.24 Test.25 Test.26; procedure Test.0 (): let Test.9 : List I64 = Array []; diff --git a/compiler/test_mono/generated/quicksort_swap.txt b/compiler/test_mono/generated/quicksort_swap.txt index 467ec71cf3..ba42385f06 100644 --- a/compiler/test_mono/generated/quicksort_swap.txt +++ b/compiler/test_mono/generated/quicksort_swap.txt @@ -1,72 +1,67 @@ -procedure List.3 (#Attr.2, #Attr.3): - let Test.42 : U64 = lowlevel ListLen #Attr.2; - let Test.39 : Int1 = lowlevel NumLt #Attr.3 Test.42; - if Test.39 then - let Test.41 : I64 = lowlevel ListGetUnsafe #Attr.2 #Attr.3; - let Test.40 : [C {}, C I64] = Ok Test.41; - ret Test.40; +procedure List.2 (#Attr.2, #Attr.3): + let List.154 : U64 = lowlevel ListLen #Attr.2; + let List.151 : Int1 = lowlevel NumLt #Attr.3 List.154; + if List.151 then + let List.153 : I64 = lowlevel ListGetUnsafe #Attr.2 #Attr.3; + let List.152 : [C {}, C I64] = Ok List.153; + ret List.152; else - let Test.38 : {} = Struct {}; - let Test.37 : [C {}, C I64] = Err Test.38; - ret Test.37; + let List.150 : {} = Struct {}; + let List.149 : [C {}, C I64] = Err List.150; + ret List.149; -procedure List.4 (#Attr.2, #Attr.3, #Attr.4): - let Test.20 : U64 = lowlevel ListLen #Attr.2; - let Test.13 : Int1 = lowlevel NumLt #Attr.3 Test.20; - if Test.13 then - let Test.15 : {List I64, I64} = CallByName List.58 #Attr.2 #Attr.3 #Attr.4; - let Test.14 : List I64 = StructAtIndex 0 Test.15; - inc Test.14; - dec Test.15; - ret Test.14; - else - ret #Attr.2; +procedure List.3 (List.63, List.64, List.65): + let List.142 : {List I64, I64} = CallByName List.57 List.63 List.64 List.65; + let List.141 : List I64 = StructAtIndex 0 List.142; + inc List.141; + dec List.142; + ret List.141; -procedure List.58 (#Attr.2, #Attr.3, #Attr.4): - let Test.19 : U64 = lowlevel ListLen #Attr.2; - let Test.17 : Int1 = lowlevel NumLt #Attr.3 Test.19; - if Test.17 then - let Test.18 : {List I64, I64} = lowlevel ListReplaceUnsafe #Attr.2 #Attr.3 #Attr.4; - ret Test.18; +procedure List.57 (#Attr.2, #Attr.3, #Attr.4): + let List.158 : U64 = lowlevel ListLen #Attr.2; + let List.156 : Int1 = lowlevel NumLt #Attr.3 List.158; + if List.156 then + let List.157 : {List I64, I64} = lowlevel ListReplaceUnsafe #Attr.2 #Attr.3 #Attr.4; + ret List.157; else - let Test.16 : {List I64, I64} = Struct {#Attr.2, #Attr.4}; - ret Test.16; + let List.155 : {List I64, I64} = Struct {#Attr.2, #Attr.4}; + ret List.155; procedure Test.1 (Test.2): - let Test.43 : U64 = 0i64; - let Test.35 : [C {}, C I64] = CallByName List.3 Test.2 Test.43; - let Test.36 : U64 = 0i64; - let Test.34 : [C {}, C I64] = CallByName List.3 Test.2 Test.36; - let Test.8 : {[C {}, C I64], [C {}, C I64]} = Struct {Test.34, Test.35}; - joinpoint Test.31: - let Test.22 : List I64 = Array []; - ret Test.22; + let Test.28 : U64 = 0i64; + let Test.26 : [C {}, C I64] = CallByName List.2 Test.2 Test.28; + let Test.27 : U64 = 0i64; + let Test.25 : [C {}, C I64] = CallByName List.2 Test.2 Test.27; + let Test.8 : {[C {}, C I64], [C {}, C I64]} = Struct {Test.25, Test.26}; + joinpoint Test.22: + let Test.13 : List I64 = Array []; + ret Test.13; in - let Test.28 : [C {}, C I64] = StructAtIndex 1 Test.8; - let Test.29 : U8 = 1i64; - let Test.30 : U8 = GetTagId Test.28; - let Test.33 : Int1 = lowlevel Eq Test.29 Test.30; - if Test.33 then - let Test.25 : [C {}, C I64] = StructAtIndex 0 Test.8; - let Test.26 : U8 = 1i64; - let Test.27 : U8 = GetTagId Test.25; - let Test.32 : Int1 = lowlevel Eq Test.26 Test.27; - if Test.32 then - let Test.24 : [C {}, C I64] = StructAtIndex 0 Test.8; - let Test.4 : I64 = UnionAtIndex (Id 1) (Index 0) Test.24; - let Test.23 : [C {}, C I64] = StructAtIndex 1 Test.8; - let Test.5 : I64 = UnionAtIndex (Id 1) (Index 0) Test.23; - let Test.21 : U64 = 0i64; - let Test.10 : List I64 = CallByName List.4 Test.2 Test.21 Test.5; + let Test.19 : [C {}, C I64] = StructAtIndex 1 Test.8; + let Test.20 : U8 = 1i64; + let Test.21 : U8 = GetTagId Test.19; + let Test.24 : Int1 = lowlevel Eq Test.20 Test.21; + if Test.24 then + let Test.16 : [C {}, C I64] = StructAtIndex 0 Test.8; + let Test.17 : U8 = 1i64; + let Test.18 : U8 = GetTagId Test.16; + let Test.23 : Int1 = lowlevel Eq Test.17 Test.18; + if Test.23 then + let Test.15 : [C {}, C I64] = StructAtIndex 0 Test.8; + let Test.4 : I64 = UnionAtIndex (Id 1) (Index 0) Test.15; + let Test.14 : [C {}, C I64] = StructAtIndex 1 Test.8; + let Test.5 : I64 = UnionAtIndex (Id 1) (Index 0) Test.14; + let Test.12 : U64 = 0i64; + let Test.10 : List I64 = CallByName List.3 Test.2 Test.12 Test.5; let Test.11 : U64 = 0i64; - let Test.9 : List I64 = CallByName List.4 Test.10 Test.11 Test.4; + let Test.9 : List I64 = CallByName List.3 Test.10 Test.11 Test.4; ret Test.9; else dec Test.2; - jump Test.31; + jump Test.22; else dec Test.2; - jump Test.31; + jump Test.22; procedure Test.0 (): let Test.7 : List I64 = Array [1i64, 2i64]; diff --git a/compiler/test_mono/generated/record_optional_field_function_no_use_default.txt b/compiler/test_mono/generated/record_optional_field_function_no_use_default.txt index efbc0ca6e2..355268a33e 100644 --- a/compiler/test_mono/generated/record_optional_field_function_no_use_default.txt +++ b/compiler/test_mono/generated/record_optional_field_function_no_use_default.txt @@ -1,16 +1,16 @@ -procedure Num.22 (#Attr.2, #Attr.3): - let Test.8 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Test.8; +procedure Num.19 (#Attr.2, #Attr.3): + let Num.228 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.228; procedure Test.1 (Test.4): let Test.2 : I64 = StructAtIndex 0 Test.4; let Test.3 : I64 = StructAtIndex 1 Test.4; - let Test.7 : I64 = CallByName Num.22 Test.2 Test.3; + let Test.7 : I64 = CallByName Num.19 Test.2 Test.3; ret Test.7; procedure Test.0 (): - let Test.9 : I64 = 4i64; - let Test.10 : I64 = 9i64; - let Test.6 : {I64, I64} = Struct {Test.9, Test.10}; + let Test.8 : I64 = 4i64; + let Test.9 : I64 = 9i64; + let Test.6 : {I64, I64} = Struct {Test.8, Test.9}; let Test.5 : I64 = CallByName Test.1 Test.6; ret Test.5; diff --git a/compiler/test_mono/generated/record_optional_field_function_use_default.txt b/compiler/test_mono/generated/record_optional_field_function_use_default.txt index b3a418d3f3..fce1b7a406 100644 --- a/compiler/test_mono/generated/record_optional_field_function_use_default.txt +++ b/compiler/test_mono/generated/record_optional_field_function_use_default.txt @@ -1,13 +1,13 @@ -procedure Num.22 (#Attr.2, #Attr.3): - let Test.9 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Test.9; +procedure Num.19 (#Attr.2, #Attr.3): + let Num.228 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.228; procedure Test.1 (Test.4): let Test.8 : I64 = 10i64; - let Test.7 : I64 = CallByName Num.22 Test.8 Test.4; + let Test.7 : I64 = CallByName Num.19 Test.8 Test.4; ret Test.7; procedure Test.0 (): - let Test.10 : I64 = 9i64; - let Test.5 : I64 = CallByName Test.1 Test.10; + let Test.9 : I64 = 9i64; + let Test.5 : I64 = CallByName Test.1 Test.9; ret Test.5; diff --git a/compiler/test_mono/generated/record_optional_field_let_no_use_default.txt b/compiler/test_mono/generated/record_optional_field_let_no_use_default.txt index 4c10690d37..864862eaef 100644 --- a/compiler/test_mono/generated/record_optional_field_let_no_use_default.txt +++ b/compiler/test_mono/generated/record_optional_field_let_no_use_default.txt @@ -1,16 +1,16 @@ -procedure Num.22 (#Attr.2, #Attr.3): - let Test.8 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Test.8; +procedure Num.19 (#Attr.2, #Attr.3): + let Num.228 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.228; procedure Test.1 (Test.2): let Test.3 : I64 = StructAtIndex 0 Test.2; let Test.4 : I64 = StructAtIndex 1 Test.2; - let Test.7 : I64 = CallByName Num.22 Test.3 Test.4; + let Test.7 : I64 = CallByName Num.19 Test.3 Test.4; ret Test.7; procedure Test.0 (): - let Test.9 : I64 = 4i64; - let Test.10 : I64 = 9i64; - let Test.6 : {I64, I64} = Struct {Test.9, Test.10}; + let Test.8 : I64 = 4i64; + let Test.9 : I64 = 9i64; + let Test.6 : {I64, I64} = Struct {Test.8, Test.9}; let Test.5 : I64 = CallByName Test.1 Test.6; ret Test.5; diff --git a/compiler/test_mono/generated/record_optional_field_let_use_default.txt b/compiler/test_mono/generated/record_optional_field_let_use_default.txt index 14a00e3638..e8bf95b3e4 100644 --- a/compiler/test_mono/generated/record_optional_field_let_use_default.txt +++ b/compiler/test_mono/generated/record_optional_field_let_use_default.txt @@ -1,13 +1,13 @@ -procedure Num.22 (#Attr.2, #Attr.3): - let Test.8 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Test.8; +procedure Num.19 (#Attr.2, #Attr.3): + let Num.228 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.228; procedure Test.1 (Test.2): let Test.3 : I64 = 10i64; - let Test.7 : I64 = CallByName Num.22 Test.3 Test.2; + let Test.7 : I64 = CallByName Num.19 Test.3 Test.2; ret Test.7; procedure Test.0 (): - let Test.9 : I64 = 9i64; - let Test.5 : I64 = CallByName Test.1 Test.9; + let Test.8 : I64 = 9i64; + let Test.5 : I64 = CallByName Test.1 Test.8; ret Test.5; diff --git a/compiler/test_mono/generated/rigids.txt b/compiler/test_mono/generated/rigids.txt index bb5a06de40..fb83256d5a 100644 --- a/compiler/test_mono/generated/rigids.txt +++ b/compiler/test_mono/generated/rigids.txt @@ -1,68 +1,63 @@ -procedure List.3 (#Attr.2, #Attr.3): - let Test.44 : U64 = lowlevel ListLen #Attr.2; - let Test.41 : Int1 = lowlevel NumLt #Attr.3 Test.44; - if Test.41 then - let Test.43 : I64 = lowlevel ListGetUnsafe #Attr.2 #Attr.3; - let Test.42 : [C {}, C I64] = Ok Test.43; - ret Test.42; +procedure List.2 (#Attr.2, #Attr.3): + let List.154 : U64 = lowlevel ListLen #Attr.2; + let List.151 : Int1 = lowlevel NumLt #Attr.3 List.154; + if List.151 then + let List.153 : I64 = lowlevel ListGetUnsafe #Attr.2 #Attr.3; + let List.152 : [C {}, C I64] = Ok List.153; + ret List.152; else - let Test.40 : {} = Struct {}; - let Test.39 : [C {}, C I64] = Err Test.40; - ret Test.39; + let List.150 : {} = Struct {}; + let List.149 : [C {}, C I64] = Err List.150; + ret List.149; -procedure List.4 (#Attr.2, #Attr.3, #Attr.4): - let Test.24 : U64 = lowlevel ListLen #Attr.2; - let Test.17 : Int1 = lowlevel NumLt #Attr.3 Test.24; - if Test.17 then - let Test.19 : {List I64, I64} = CallByName List.58 #Attr.2 #Attr.3 #Attr.4; - let Test.18 : List I64 = StructAtIndex 0 Test.19; - inc Test.18; - dec Test.19; - ret Test.18; - else - ret #Attr.2; +procedure List.3 (List.63, List.64, List.65): + let List.142 : {List I64, I64} = CallByName List.57 List.63 List.64 List.65; + let List.141 : List I64 = StructAtIndex 0 List.142; + inc List.141; + dec List.142; + ret List.141; -procedure List.58 (#Attr.2, #Attr.3, #Attr.4): - let Test.23 : U64 = lowlevel ListLen #Attr.2; - let Test.21 : Int1 = lowlevel NumLt #Attr.3 Test.23; - if Test.21 then - let Test.22 : {List I64, I64} = lowlevel ListReplaceUnsafe #Attr.2 #Attr.3 #Attr.4; - ret Test.22; +procedure List.57 (#Attr.2, #Attr.3, #Attr.4): + let List.158 : U64 = lowlevel ListLen #Attr.2; + let List.156 : Int1 = lowlevel NumLt #Attr.3 List.158; + if List.156 then + let List.157 : {List I64, I64} = lowlevel ListReplaceUnsafe #Attr.2 #Attr.3 #Attr.4; + ret List.157; else - let Test.20 : {List I64, I64} = Struct {#Attr.2, #Attr.4}; - ret Test.20; + let List.155 : {List I64, I64} = Struct {#Attr.2, #Attr.4}; + ret List.155; procedure Test.1 (Test.2, Test.3, Test.4): - let Test.38 : [C {}, C I64] = CallByName List.3 Test.4 Test.3; - let Test.37 : [C {}, C I64] = CallByName List.3 Test.4 Test.2; - let Test.13 : {[C {}, C I64], [C {}, C I64]} = Struct {Test.37, Test.38}; - joinpoint Test.34: - let Test.25 : List I64 = Array []; - ret Test.25; + let Test.29 : [C {}, C I64] = CallByName List.2 Test.4 Test.3; + let Test.28 : [C {}, C I64] = CallByName List.2 Test.4 Test.2; + let Test.13 : {[C {}, C I64], [C {}, C I64]} = Struct {Test.28, Test.29}; + joinpoint Test.25: + let Test.16 : List I64 = Array []; + ret Test.16; in - let Test.31 : [C {}, C I64] = StructAtIndex 1 Test.13; - let Test.32 : U8 = 1i64; - let Test.33 : U8 = GetTagId Test.31; - let Test.36 : Int1 = lowlevel Eq Test.32 Test.33; - if Test.36 then - let Test.28 : [C {}, C I64] = StructAtIndex 0 Test.13; - let Test.29 : U8 = 1i64; - let Test.30 : U8 = GetTagId Test.28; - let Test.35 : Int1 = lowlevel Eq Test.29 Test.30; - if Test.35 then - let Test.27 : [C {}, C I64] = StructAtIndex 0 Test.13; - let Test.6 : I64 = UnionAtIndex (Id 1) (Index 0) Test.27; - let Test.26 : [C {}, C I64] = StructAtIndex 1 Test.13; - let Test.7 : I64 = UnionAtIndex (Id 1) (Index 0) Test.26; - let Test.15 : List I64 = CallByName List.4 Test.4 Test.2 Test.7; - let Test.14 : List I64 = CallByName List.4 Test.15 Test.3 Test.6; + let Test.22 : [C {}, C I64] = StructAtIndex 1 Test.13; + let Test.23 : U8 = 1i64; + let Test.24 : U8 = GetTagId Test.22; + let Test.27 : Int1 = lowlevel Eq Test.23 Test.24; + if Test.27 then + let Test.19 : [C {}, C I64] = StructAtIndex 0 Test.13; + let Test.20 : U8 = 1i64; + let Test.21 : U8 = GetTagId Test.19; + let Test.26 : Int1 = lowlevel Eq Test.20 Test.21; + if Test.26 then + let Test.18 : [C {}, C I64] = StructAtIndex 0 Test.13; + let Test.6 : I64 = UnionAtIndex (Id 1) (Index 0) Test.18; + let Test.17 : [C {}, C I64] = StructAtIndex 1 Test.13; + let Test.7 : I64 = UnionAtIndex (Id 1) (Index 0) Test.17; + let Test.15 : List I64 = CallByName List.3 Test.4 Test.2 Test.7; + let Test.14 : List I64 = CallByName List.3 Test.15 Test.3 Test.6; ret Test.14; else dec Test.4; - jump Test.34; + jump Test.25; else dec Test.4; - jump Test.34; + jump Test.25; procedure Test.0 (): let Test.10 : U64 = 0i64; diff --git a/compiler/test_mono/generated/somehow_drops_definitions.txt b/compiler/test_mono/generated/somehow_drops_definitions.txt index 067e533b9c..8e5dc13493 100644 --- a/compiler/test_mono/generated/somehow_drops_definitions.txt +++ b/compiler/test_mono/generated/somehow_drops_definitions.txt @@ -1,27 +1,27 @@ -procedure Num.22 (#Attr.2, #Attr.3): - let Test.27 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Test.27; +procedure Num.19 (#Attr.2, #Attr.3): + let Num.229 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.229; -procedure Num.24 (#Attr.2, #Attr.3): - let Test.22 : I64 = lowlevel NumMul #Attr.2 #Attr.3; - ret Test.22; +procedure Num.21 (#Attr.2, #Attr.3): + let Num.228 : I64 = lowlevel NumMul #Attr.2 #Attr.3; + ret Num.228; procedure Test.1 (): - let Test.28 : I64 = 1i64; - ret Test.28; + let Test.26 : I64 = 1i64; + ret Test.26; procedure Test.2 (): - let Test.23 : I64 = 2i64; - ret Test.23; + let Test.22 : I64 = 2i64; + ret Test.22; procedure Test.3 (Test.6): - let Test.26 : I64 = CallByName Test.1; - let Test.25 : I64 = CallByName Num.22 Test.6 Test.26; - ret Test.25; + let Test.25 : I64 = CallByName Test.1; + let Test.24 : I64 = CallByName Num.19 Test.6 Test.25; + ret Test.24; procedure Test.4 (Test.7): let Test.21 : I64 = CallByName Test.2; - let Test.20 : I64 = CallByName Num.24 Test.7 Test.21; + let Test.20 : I64 = CallByName Num.21 Test.7 Test.21; ret Test.20; procedure Test.5 (Test.8, Test.9): @@ -44,8 +44,8 @@ procedure Test.0 (): let Test.11 : I64 = CallByName Test.5 Test.12 Test.13; ret Test.11; in - let Test.24 : Int1 = true; - if Test.24 then + let Test.23 : Int1 = true; + if Test.23 then let Test.3 : Int1 = false; jump Test.19 Test.3; else diff --git a/compiler/test_mono/generated/specialize_ability_call.txt b/compiler/test_mono/generated/specialize_ability_call.txt index 9e3179be06..7f4932ff35 100644 --- a/compiler/test_mono/generated/specialize_ability_call.txt +++ b/compiler/test_mono/generated/specialize_ability_call.txt @@ -1,7 +1,7 @@ -procedure Test.5 (Test.8): - ret Test.8; +procedure Test.5 (Test.7): + ret Test.7; procedure Test.0 (): - let Test.10 : U64 = 1234i64; - let Test.9 : U64 = CallByName Test.5 Test.10; - ret Test.9; + let Test.9 : U64 = 1234i64; + let Test.8 : U64 = CallByName Test.5 Test.9; + ret Test.8; diff --git a/compiler/test_mono/generated/specialize_closures.txt b/compiler/test_mono/generated/specialize_closures.txt index 1d6423ffb7..65fbdf1102 100644 --- a/compiler/test_mono/generated/specialize_closures.txt +++ b/compiler/test_mono/generated/specialize_closures.txt @@ -1,10 +1,10 @@ -procedure Num.22 (#Attr.2, #Attr.3): - let Test.28 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Test.28; +procedure Num.19 (#Attr.2, #Attr.3): + let Num.229 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.229; -procedure Num.24 (#Attr.2, #Attr.3): - let Test.25 : I64 = lowlevel NumMul #Attr.2 #Attr.3; - ret Test.25; +procedure Num.21 (#Attr.2, #Attr.3): + let Num.228 : I64 = lowlevel NumMul #Attr.2 #Attr.3; + ret Num.228; procedure Test.1 (Test.2, Test.3): let Test.17 : U8 = GetTagId Test.2; @@ -23,29 +23,29 @@ procedure Test.1 (Test.2, Test.3): procedure Test.7 (Test.10, #Attr.12): let Test.4 : I64 = UnionAtIndex (Id 0) (Index 0) #Attr.12; - let Test.27 : I64 = CallByName Num.22 Test.10 Test.4; - ret Test.27; + let Test.26 : I64 = CallByName Num.19 Test.10 Test.4; + ret Test.26; procedure Test.8 (Test.11, #Attr.12): let Test.6 : Int1 = UnionAtIndex (Id 1) (Index 1) #Attr.12; let Test.5 : I64 = UnionAtIndex (Id 1) (Index 0) #Attr.12; if Test.6 then - let Test.24 : I64 = CallByName Num.24 Test.11 Test.5; + let Test.24 : I64 = CallByName Num.21 Test.11 Test.5; ret Test.24; else ret Test.11; procedure Test.0 (): + let Test.4 : I64 = 1i64; let Test.5 : I64 = 2i64; let Test.6 : Int1 = true; - let Test.4 : I64 = 1i64; joinpoint Test.22 Test.14: let Test.15 : I64 = 42i64; let Test.13 : I64 = CallByName Test.1 Test.14 Test.15; ret Test.13; in - let Test.26 : Int1 = true; - if Test.26 then + let Test.25 : Int1 = true; + if Test.25 then let Test.7 : [C I64, C I64 Int1] = ClosureTag(Test.7) Test.4; jump Test.22 Test.7; else diff --git a/compiler/test_mono/generated/specialize_lowlevel.txt b/compiler/test_mono/generated/specialize_lowlevel.txt index 8a15d461e3..b6ede4db71 100644 --- a/compiler/test_mono/generated/specialize_lowlevel.txt +++ b/compiler/test_mono/generated/specialize_lowlevel.txt @@ -1,24 +1,24 @@ -procedure Num.22 (#Attr.2, #Attr.3): - let Test.24 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Test.24; +procedure Num.19 (#Attr.2, #Attr.3): + let Num.229 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.229; -procedure Num.24 (#Attr.2, #Attr.3): - let Test.21 : I64 = lowlevel NumMul #Attr.2 #Attr.3; - ret Test.21; +procedure Num.21 (#Attr.2, #Attr.3): + let Num.228 : I64 = lowlevel NumMul #Attr.2 #Attr.3; + ret Num.228; procedure Test.6 (Test.8, #Attr.12): let Test.4 : I64 = UnionAtIndex (Id 0) (Index 0) #Attr.12; - let Test.23 : I64 = CallByName Num.22 Test.8 Test.4; - ret Test.23; + let Test.22 : I64 = CallByName Num.19 Test.8 Test.4; + ret Test.22; procedure Test.7 (Test.9, #Attr.12): let Test.5 : I64 = UnionAtIndex (Id 1) (Index 0) #Attr.12; - let Test.20 : I64 = CallByName Num.24 Test.9 Test.5; + let Test.20 : I64 = CallByName Num.21 Test.9 Test.5; ret Test.20; procedure Test.0 (): - let Test.5 : I64 = 2i64; let Test.4 : I64 = 1i64; + let Test.5 : I64 = 2i64; let Test.12 : I64 = 42i64; joinpoint Test.19 Test.13: let Test.14 : U8 = GetTagId Test.13; @@ -35,8 +35,8 @@ procedure Test.0 (): jump Test.15 Test.17; in - let Test.22 : Int1 = true; - if Test.22 then + let Test.21 : Int1 = true; + if Test.21 then let Test.6 : [C I64, C I64] = ClosureTag(Test.6) Test.4; jump Test.19 Test.6; else diff --git a/compiler/test_mono/generated/when_nested_maybe.txt b/compiler/test_mono/generated/when_nested_maybe.txt index 6bb9eebf35..061f72e7c9 100644 --- a/compiler/test_mono/generated/when_nested_maybe.txt +++ b/compiler/test_mono/generated/when_nested_maybe.txt @@ -1,30 +1,30 @@ -procedure Num.22 (#Attr.2, #Attr.3): - let Test.8 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Test.8; +procedure Num.19 (#Attr.2, #Attr.3): + let Num.228 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.228; procedure Test.0 (): - let Test.20 : I64 = 41i64; - let Test.19 : [C I64, C ] = Just Test.20; - let Test.2 : [C [C I64, C ], C ] = Just Test.19; - joinpoint Test.16: - let Test.9 : I64 = 1i64; - ret Test.9; + let Test.19 : I64 = 41i64; + let Test.18 : [C I64, C ] = Just Test.19; + let Test.2 : [C [C I64, C ], C ] = Just Test.18; + joinpoint Test.15: + let Test.8 : I64 = 1i64; + ret Test.8; in - let Test.14 : U8 = 0i64; - let Test.15 : U8 = GetTagId Test.2; - let Test.18 : Int1 = lowlevel Eq Test.14 Test.15; - if Test.18 then - let Test.11 : [C I64, C ] = UnionAtIndex (Id 0) (Index 0) Test.2; - let Test.12 : U8 = 0i64; - let Test.13 : U8 = GetTagId Test.11; - let Test.17 : Int1 = lowlevel Eq Test.12 Test.13; - if Test.17 then - let Test.10 : [C I64, C ] = UnionAtIndex (Id 0) (Index 0) Test.2; - let Test.5 : I64 = UnionAtIndex (Id 0) (Index 0) Test.10; + let Test.13 : U8 = 0i64; + let Test.14 : U8 = GetTagId Test.2; + let Test.17 : Int1 = lowlevel Eq Test.13 Test.14; + if Test.17 then + let Test.10 : [C I64, C ] = UnionAtIndex (Id 0) (Index 0) Test.2; + let Test.11 : U8 = 0i64; + let Test.12 : U8 = GetTagId Test.10; + let Test.16 : Int1 = lowlevel Eq Test.11 Test.12; + if Test.16 then + let Test.9 : [C I64, C ] = UnionAtIndex (Id 0) (Index 0) Test.2; + let Test.5 : I64 = UnionAtIndex (Id 0) (Index 0) Test.9; let Test.7 : I64 = 1i64; - let Test.6 : I64 = CallByName Num.22 Test.5 Test.7; + let Test.6 : I64 = CallByName Num.19 Test.5 Test.7; ret Test.6; else - jump Test.16; + jump Test.15; else - jump Test.16; + jump Test.15; diff --git a/compiler/test_mono/generated/when_on_record.txt b/compiler/test_mono/generated/when_on_record.txt index b313695135..9dcef9aa67 100644 --- a/compiler/test_mono/generated/when_on_record.txt +++ b/compiler/test_mono/generated/when_on_record.txt @@ -1,9 +1,9 @@ -procedure Num.22 (#Attr.2, #Attr.3): - let Test.5 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Test.5; +procedure Num.19 (#Attr.2, #Attr.3): + let Num.228 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.228; procedure Test.0 (): - let Test.6 : I64 = 2i64; + let Test.5 : I64 = 2i64; let Test.4 : I64 = 3i64; - let Test.3 : I64 = CallByName Num.22 Test.6 Test.4; + let Test.3 : I64 = CallByName Num.19 Test.5 Test.4; ret Test.3; diff --git a/compiler/test_mono/generated/when_on_two_values.txt b/compiler/test_mono/generated/when_on_two_values.txt index 2085f6c7df..c9866b76f4 100644 --- a/compiler/test_mono/generated/when_on_two_values.txt +++ b/compiler/test_mono/generated/when_on_two_values.txt @@ -1,28 +1,28 @@ -procedure Num.22 (#Attr.2, #Attr.3): - let Test.7 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Test.7; +procedure Num.19 (#Attr.2, #Attr.3): + let Num.228 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.228; procedure Test.0 (): - let Test.16 : I64 = 3i64; - let Test.15 : I64 = 2i64; - let Test.4 : {I64, I64} = Struct {Test.15, Test.16}; - joinpoint Test.12: + let Test.15 : I64 = 3i64; + let Test.14 : I64 = 2i64; + let Test.4 : {I64, I64} = Struct {Test.14, Test.15}; + joinpoint Test.11: let Test.2 : I64 = StructAtIndex 0 Test.4; let Test.3 : I64 = StructAtIndex 1 Test.4; - let Test.6 : I64 = CallByName Num.22 Test.2 Test.3; + let Test.6 : I64 = CallByName Num.19 Test.2 Test.3; ret Test.6; in - let Test.10 : I64 = StructAtIndex 1 Test.4; - let Test.11 : I64 = 3i64; - let Test.14 : Int1 = lowlevel Eq Test.11 Test.10; - if Test.14 then - let Test.8 : I64 = StructAtIndex 0 Test.4; - let Test.9 : I64 = 4i64; - let Test.13 : Int1 = lowlevel Eq Test.9 Test.8; - if Test.13 then + let Test.9 : I64 = StructAtIndex 1 Test.4; + let Test.10 : I64 = 3i64; + let Test.13 : Int1 = lowlevel Eq Test.10 Test.9; + if Test.13 then + let Test.7 : I64 = StructAtIndex 0 Test.4; + let Test.8 : I64 = 4i64; + let Test.12 : Int1 = lowlevel Eq Test.8 Test.7; + if Test.12 then let Test.5 : I64 = 9i64; ret Test.5; else - jump Test.12; + jump Test.11; else - jump Test.12; + jump Test.11; From 0bc85ad32c46bdcd484fc7f73b08fddf3185ca57 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 28 Apr 2022 09:13:29 -0400 Subject: [PATCH 645/846] Only load setjmp/longjmp from Zig on aarch64 --- compiler/builtins/bitcode/src/main.zig | 11 ++- compiler/gen_llvm/src/llvm/build.rs | 97 ++++++++++++++++++++++---- compiler/gen_llvm/src/llvm/externs.rs | 25 +++++-- 3 files changed, 114 insertions(+), 19 deletions(-) diff --git a/compiler/builtins/bitcode/src/main.zig b/compiler/builtins/bitcode/src/main.zig index 5eb871a7a0..85f35fbca2 100644 --- a/compiler/builtins/bitcode/src/main.zig +++ b/compiler/builtins/bitcode/src/main.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const builtin = @import("builtin"); const math = std.math; const utils = @import("utils.zig"); const expect = @import("expect.zig"); @@ -161,6 +162,11 @@ comptime { exportExpectFn(expect.deinitFailuresC, "deinit_failures"); @export(utils.panic, .{ .name = "roc_builtins.utils." ++ "panic", .linkage = .Weak }); + + if (builtin.target.cpu.arch == .aarch64) { + @export(__roc_force_setjmp, .{ .name = "__roc_force_setjmp", .linkage = .Weak }); + @export(__roc_force_longjmp, .{ .name = "__roc_force_longjmp", .linkage = .Weak }); + } } // Utils continued - SJLJ @@ -177,10 +183,10 @@ pub extern fn sigsetjmp([*c]c_int, c_int) c_int; pub extern fn siglongjmp([*c]c_int, c_int) noreturn; pub extern fn longjmperror() void; // Zig won't expose the externs (and hence link correctly) unless we force them to be used. -pub export fn __roc_force_setjmp(it: [*c]c_int) c_int { +fn __roc_force_setjmp(it: [*c]c_int) callconv(.C) c_int { return setjmp(it); } -pub export fn __roc_force_longjmp(a0: [*c]c_int, a1: c_int) noreturn { +fn __roc_force_longjmp(a0: [*c]c_int, a1: c_int) callconv(.C) noreturn { longjmp(a0, a1); } @@ -214,7 +220,6 @@ fn exportExpectFn(comptime func: anytype, comptime func_name: []const u8) void { // Custom panic function, as builtin Zig version errors during LLVM verification pub fn panic(message: []const u8, stacktrace: ?*std.builtin.StackTrace) noreturn { - const builtin = @import("builtin"); if (builtin.is_test) { std.debug.print("{s}: {?}", .{ message, stacktrace }); } else { diff --git a/compiler/gen_llvm/src/llvm/build.rs b/compiler/gen_llvm/src/llvm/build.rs index 84e547aa3f..f25be30109 100644 --- a/compiler/gen_llvm/src/llvm/build.rs +++ b/compiler/gen_llvm/src/llvm/build.rs @@ -64,7 +64,7 @@ use roc_mono::ir::{ ModifyRc, OptLevel, ProcLayout, }; use roc_mono::layout::{Builtin, LambdaSet, Layout, LayoutIds, TagIdIntType, UnionLayout}; -use roc_target::TargetInfo; +use roc_target::{PtrWidth, TargetInfo}; use target_lexicon::{Architecture, OperatingSystem, Triple}; /// This is for Inkwell's FunctionValue::verify - we want to know the verification @@ -516,11 +516,36 @@ fn add_intrinsics<'ctx>(ctx: &'ctx Context, module: &Module<'ctx>) { // // https://releases.llvm.org/10.0.0/docs/LangRef.html#standard-c-library-intrinsics let i1_type = ctx.bool_type(); + let i8_type = ctx.i8_type(); + let i8_ptr_type = i8_type.ptr_type(AddressSpace::Generic); + let i32_type = ctx.i32_type(); + let void_type = ctx.void_type(); if let Some(func) = module.get_function("__muloti4") { func.set_linkage(Linkage::WeakAny); } + add_intrinsic( + ctx, + module, + LLVM_SETJMP, + i32_type.fn_type(&[i8_ptr_type.into()], false), + ); + + add_intrinsic( + ctx, + module, + LLVM_LONGJMP, + void_type.fn_type(&[i8_ptr_type.into()], false), + ); + + add_intrinsic( + ctx, + module, + LLVM_FRAME_ADDRESS, + i8_ptr_type.fn_type(&[i32_type.into()], false), + ); + add_float_intrinsic(ctx, module, &LLVM_LOG, |t| t.fn_type(&[t.into()], false)); add_float_intrinsic(ctx, module, &LLVM_POW, |t| { t.fn_type(&[t.into(), t.into()], false) @@ -573,6 +598,11 @@ static LLVM_FLOOR: IntrinsicName = float_intrinsic!("llvm.floor"); static LLVM_MEMSET_I64: &str = "llvm.memset.p0i8.i64"; static LLVM_MEMSET_I32: &str = "llvm.memset.p0i8.i32"; +static LLVM_FRAME_ADDRESS: &str = "llvm.frameaddress.p0i8"; + +static LLVM_SETJMP: &str = "llvm.eh.sjlj.setjmp"; +pub static LLVM_LONGJMP: &str = "llvm.eh.sjlj.longjmp"; + const LLVM_ADD_WITH_OVERFLOW: IntrinsicName = llvm_int_intrinsic!("llvm.sadd.with.overflow", "llvm.uadd.with.overflow"); const LLVM_SUB_WITH_OVERFLOW: IntrinsicName = @@ -3620,14 +3650,21 @@ fn expose_function_to_host_help_c_abi<'a, 'ctx, 'env>( pub fn get_sjlj_buffer<'a, 'ctx, 'env>(env: &Env<'a, 'ctx, 'env>) -> PointerValue<'ctx> { // The size of jump_buf is platform-dependent. - // AArch64 needs 3 64-bit words, x86 seemingly needs less than that. Let's just make it 3 - // 64-bit words. - // We can always increase the size, since we hand it off opaquely to both `setjmp` and `longjmp`. - // The unused space won't be touched. - let type_ = env - .context - .i32_type() - .array_type(6 * env.target_info.ptr_width() as u32); + // - AArch64 needs 3 machine-sized words + // - LLVM says the following about the SJLJ intrinsic: + // + // [It is] a five word buffer in which the calling context is saved. + // The front end places the frame pointer in the first word, and the + // target implementation of this intrinsic should place the destination + // address for a llvm.eh.sjlj.longjmp in the second word. + // The following three words are available for use in a target-specific manner. + // + // So, let's create a 5-word buffer. + let word_type = match env.target_info.ptr_width() { + PtrWidth::Bytes4 => env.context.i32_type(), + PtrWidth::Bytes8 => env.context.i64_type(), + }; + let type_ = word_type.array_type(5); let global = match env.module.get_global("roc_sjlj_buffer") { Some(global) => global, @@ -3645,6 +3682,44 @@ pub fn get_sjlj_buffer<'a, 'ctx, 'env>(env: &Env<'a, 'ctx, 'env>) -> PointerValu .into_pointer_value() } +pub fn build_setjmp_call<'a, 'ctx, 'env>(env: &Env<'a, 'ctx, 'env>) -> BasicValueEnum<'ctx> { + let jmp_buf = get_sjlj_buffer(env); + if cfg!(target_arch = "aarch64") { + // Due to https://github.com/rtfeldman/roc/issues/2965, we use a setjmp we linked in from Zig + call_bitcode_fn(env, &[jmp_buf.into()], bitcode::UTILS_SETJMP) + } else { + // Anywhere else, use the LLVM intrinsic. + let jmp_buf_i8p = env + .builder + .build_bitcast( + jmp_buf, + env.context + .i8_type() + .ptr_type(AddressSpace::Generic) + .array_type(5) + .ptr_type(AddressSpace::Generic), + "jmp_buf [5 x i8*]", + ) + .into_pointer_value(); + // LLVM asks us to please store the frame pointer in the first word. + let frame_address = env.call_intrinsic( + LLVM_FRAME_ADDRESS, + &[env.context.i32_type().const_zero().into()], + ); + + let zero = env.context.i32_type().const_zero(); + let fa_index = env.context.i32_type().const_zero(); + let fa = unsafe { + env.builder + .build_in_bounds_gep(jmp_buf_i8p, &[zero, fa_index], "frame address index") + }; + + env.builder.build_store(fa, frame_address); + + env.call_intrinsic(LLVM_SETJMP, &[jmp_buf_i8p.into()]) + } +} + /// Pointer to pointer of the panic message. pub fn get_panic_msg_ptr<'a, 'ctx, 'env>(env: &Env<'a, 'ctx, 'env>) -> PointerValue<'ctx> { let ptr_to_u8_ptr = env.context.i8_type().ptr_type(AddressSpace::Generic); @@ -3677,9 +3752,7 @@ fn set_jump_and_catch_long_jump<'a, 'ctx, 'env>( let catch_block = context.append_basic_block(parent, "catch_block"); let cont_block = context.append_basic_block(parent, "cont_block"); - let buffer = get_sjlj_buffer(env); - - let panicked_u32 = call_bitcode_fn(env, &[buffer.into()], bitcode::UTILS_SETJMP); + let panicked_u32 = build_setjmp_call(env); let panicked_bool = env.builder.build_int_compare( IntPredicate::NE, panicked_u32.into_int_value(), diff --git a/compiler/gen_llvm/src/llvm/externs.rs b/compiler/gen_llvm/src/llvm/externs.rs index 1f1a691199..4d91f59216 100644 --- a/compiler/gen_llvm/src/llvm/externs.rs +++ b/compiler/gen_llvm/src/llvm/externs.rs @@ -7,6 +7,8 @@ use inkwell::values::BasicValue; use inkwell::AddressSpace; use roc_builtins::bitcode; +use super::build::{get_sjlj_buffer, LLVM_LONGJMP}; + /// Define functions for roc_alloc, roc_realloc, and roc_dealloc /// which use libc implementations (malloc, realloc, and free) pub fn add_default_roc_externs(env: &Env<'_, '_, '_>) { @@ -209,13 +211,10 @@ pub fn add_sjlj_roc_panic(env: &Env<'_, '_, '_>) { builder.position_at_end(entry); - let buffer = crate::llvm::build::get_sjlj_buffer(env); - // write our error message pointer env.builder.build_store(get_panic_msg_ptr(env), ptr_arg); - let tag = env.context.i32_type().const_int(1, false); - let _call = call_void_bitcode_fn(env, &[buffer.into(), tag.into()], bitcode::UTILS_LONGJMP); + build_longjmp_call(env); builder.build_unreachable(); @@ -224,3 +223,21 @@ pub fn add_sjlj_roc_panic(env: &Env<'_, '_, '_>) { } } } + +pub fn build_longjmp_call<'a, 'ctx, 'env>(env: &Env<'a, 'ctx, 'env>) { + let jmp_buf = get_sjlj_buffer(env); + if cfg!(target_arch = "aarch64") { + // Call the Zig-linked longjmp: `void longjmp(i32*, i32)` + let tag = env.context.i32_type().const_int(1, false); + let _call = + call_void_bitcode_fn(env, &[jmp_buf.into(), tag.into()], bitcode::UTILS_LONGJMP); + } else { + // Call the LLVM-intrinsic longjmp: `void @llvm.eh.sjlj.longjmp(i8* %setjmp_buf)` + let jmp_buf_i8p = env.builder.build_bitcast( + jmp_buf, + env.context.i8_type().ptr_type(AddressSpace::Generic), + "jmp_buf i8*", + ); + let _call = env.build_intrinsic_call(LLVM_LONGJMP, &[jmp_buf_i8p.into()]); + } +} From 9b589b69d93f6d1e25f803fc7943e2438f095807 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 28 Apr 2022 09:13:54 -0400 Subject: [PATCH 646/846] Revert "Mark setjmp/longjmp as explicitly linked" This reverts commit f19701293c2ba563543f62e7cd24cf165f3545d6. --- linker/src/lib.rs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/linker/src/lib.rs b/linker/src/lib.rs index b41144a600..1b4a2a8d14 100644 --- a/linker/src/lib.rs +++ b/linker/src/lib.rs @@ -1401,16 +1401,8 @@ fn surgery_impl( return Ok(-1); } } - } else if { - const ALWAYS_LINKED: &[&str] = &[ - "__divti3", - "__udivti3", - // By zig builtins - "setjmp", - "longjmp", - ]; - matches!(app_obj.symbol_by_index(index), Ok(sym) if ALWAYS_LINKED.contains(&sym.name().unwrap_or_default())) - } { + } else if matches!(app_obj.symbol_by_index(index), Ok(sym) if ["__divti3", "__udivti3"].contains(&sym.name().unwrap_or_default())) + { // Explicitly ignore some symbols that are currently always linked. continue; } else { From 48df3ecfbe27bba81d3436a438f907a66a3896e7 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 28 Apr 2022 10:25:55 -0400 Subject: [PATCH 647/846] Pedants --- compiler/gen_llvm/src/llvm/externs.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/gen_llvm/src/llvm/externs.rs b/compiler/gen_llvm/src/llvm/externs.rs index 4d91f59216..9180b1fe1f 100644 --- a/compiler/gen_llvm/src/llvm/externs.rs +++ b/compiler/gen_llvm/src/llvm/externs.rs @@ -224,7 +224,7 @@ pub fn add_sjlj_roc_panic(env: &Env<'_, '_, '_>) { } } -pub fn build_longjmp_call<'a, 'ctx, 'env>(env: &Env<'a, 'ctx, 'env>) { +pub fn build_longjmp_call(env: &Env) { let jmp_buf = get_sjlj_buffer(env); if cfg!(target_arch = "aarch64") { // Call the Zig-linked longjmp: `void longjmp(i32*, i32)` @@ -238,6 +238,6 @@ pub fn build_longjmp_call<'a, 'ctx, 'env>(env: &Env<'a, 'ctx, 'env>) { env.context.i8_type().ptr_type(AddressSpace::Generic), "jmp_buf i8*", ); - let _call = env.build_intrinsic_call(LLVM_LONGJMP, &[jmp_buf_i8p.into()]); + let _call = env.build_intrinsic_call(LLVM_LONGJMP, &[jmp_buf_i8p]); } } From 94f1e399e3c62f79abae74e394d1dbbd604eb8cf Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 28 Apr 2022 11:10:01 -0400 Subject: [PATCH 648/846] Fix codegen for non-aarch64 --- compiler/gen_llvm/src/llvm/build.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/compiler/gen_llvm/src/llvm/build.rs b/compiler/gen_llvm/src/llvm/build.rs index f25be30109..97450ec527 100644 --- a/compiler/gen_llvm/src/llvm/build.rs +++ b/compiler/gen_llvm/src/llvm/build.rs @@ -3689,7 +3689,7 @@ pub fn build_setjmp_call<'a, 'ctx, 'env>(env: &Env<'a, 'ctx, 'env>) -> BasicValu call_bitcode_fn(env, &[jmp_buf.into()], bitcode::UTILS_SETJMP) } else { // Anywhere else, use the LLVM intrinsic. - let jmp_buf_i8p = env + let jmp_buf_i8p_arr = env .builder .build_bitcast( jmp_buf, @@ -3710,13 +3710,21 @@ pub fn build_setjmp_call<'a, 'ctx, 'env>(env: &Env<'a, 'ctx, 'env>) -> BasicValu let zero = env.context.i32_type().const_zero(); let fa_index = env.context.i32_type().const_zero(); let fa = unsafe { - env.builder - .build_in_bounds_gep(jmp_buf_i8p, &[zero, fa_index], "frame address index") + env.builder.build_in_bounds_gep( + jmp_buf_i8p_arr, + &[zero, fa_index], + "frame address index", + ) }; env.builder.build_store(fa, frame_address); - env.call_intrinsic(LLVM_SETJMP, &[jmp_buf_i8p.into()]) + let jmp_buf_i8p = env.builder.build_bitcast( + jmp_buf, + env.context.i8_type().ptr_type(AddressSpace::Generic), + "jmp_buf i8*", + ); + env.call_intrinsic(LLVM_SETJMP, &[jmp_buf_i8p]) } } From 38bb5a189eba265cc33c5c38a9dccd2c11925fdf Mon Sep 17 00:00:00 2001 From: Folkert Date: Thu, 28 Apr 2022 19:41:21 +0200 Subject: [PATCH 649/846] fix load test --- compiler/load_internal/tests/test_load.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/load_internal/tests/test_load.rs b/compiler/load_internal/tests/test_load.rs index 769eafc8af..ae018333c1 100644 --- a/compiler/load_internal/tests/test_load.rs +++ b/compiler/load_internal/tests/test_load.rs @@ -866,7 +866,7 @@ mod test_load { Dict Result List - Nat + Box " ) ) From 70844b1218a20f010ff4a037335bb28b746a012e Mon Sep 17 00:00:00 2001 From: Folkert Date: Thu, 28 Apr 2022 19:49:44 +0200 Subject: [PATCH 650/846] add snapshot functionality --- compiler/can/src/scope.rs | 46 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index 88e420ef5a..786d0e5f2f 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -341,6 +341,37 @@ impl Scope { pub fn contains_alias(&mut self, name: Symbol) -> bool { self.aliases.contains_key(&name) } + + pub fn inner_scope(&mut self, f: F) -> T + where + F: FnOnce(&mut Scope) -> T, + { + let snapshot = self.snapshot(); + + let result = f(self); + + *self = Self::rollback(snapshot); + + result + } + + pub fn snapshot(&self) -> ScopeSnapshot { + ScopeSnapshot { + idents: self.idents.clone(), + aliases: self.aliases.clone(), + abilities_store: self.abilities_store.clone(), + home: self.home, + } + } + + pub fn rollback(snapshot: ScopeSnapshot) -> Scope { + Scope { + idents: snapshot.idents, + aliases: snapshot.aliases, + abilities_store: snapshot.abilities_store, + home: snapshot.home, + } + } } pub fn create_alias( @@ -471,3 +502,18 @@ impl IdentStore { self.regions.push(region); } } + +#[derive(Clone, Debug)] +pub struct ScopeSnapshot { + idents: IdentStore, + + /// The type aliases currently in scope + aliases: SendMap, + + /// The abilities currently in scope, and their implementors. + abilities_store: AbilitiesStore, + + /// The current module being processed. This will be used to turn + /// unqualified idents into Symbols. + home: ModuleId, +} From 5a613db7b610e937951c4739565e616b059eead8 Mon Sep 17 00:00:00 2001 From: Folkert Date: Thu, 28 Apr 2022 20:01:01 +0200 Subject: [PATCH 651/846] use snapshots for inner scopes --- compiler/can/src/def.rs | 28 ++++++---------- compiler/can/src/expr.rs | 69 ++++++++++++++++++++++---------------- compiler/can/src/module.rs | 4 +-- compiler/can/src/scope.rs | 4 +-- 4 files changed, 54 insertions(+), 51 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 4263ca13ca..659203c805 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -208,10 +208,10 @@ pub(crate) fn canonicalize_defs<'a>( env: &mut Env<'a>, mut output: Output, var_store: &mut VarStore, - mut scope: Scope, + scope: &mut Scope, loc_defs: &'a [&'a Loc>], pattern_type: PatternType, -) -> (CanDefs, Scope, Output, MutMap) { +) -> (CanDefs, Output, MutMap) { // Canonicalizing defs while detecting shadowing involves a multi-step process: // // 1. Go through each of the patterns. @@ -236,7 +236,7 @@ pub(crate) fn canonicalize_defs<'a>( for loc_def in loc_defs { match loc_def.value.unroll_def() { Ok(type_def) => { - pending_type_defs.push(to_pending_type_def(env, type_def, &mut scope, pattern_type)) + pending_type_defs.push(to_pending_type_def(env, type_def, scope, pattern_type)) } Err(value_def) => value_defs.push(Loc::at(loc_def.region, value_def)), } @@ -322,7 +322,7 @@ pub(crate) fn canonicalize_defs<'a>( let symbol = name.value; let can_ann = canonicalize_annotation( env, - &mut scope, + scope, &ann.value, ann.region, var_store, @@ -446,7 +446,7 @@ pub(crate) fn canonicalize_defs<'a>( env, &mut output, var_store, - &mut scope, + scope, abilities, &abilities_in_scope, pattern_type, @@ -465,7 +465,7 @@ pub(crate) fn canonicalize_defs<'a>( env, var_store, loc_def.value, - &mut scope, + scope, &mut new_output, pattern_type, ) { @@ -512,7 +512,7 @@ pub(crate) fn canonicalize_defs<'a>( env, pending_def, output, - &mut scope, + scope, var_store, &mut aliases, &abilities_in_scope, @@ -525,13 +525,6 @@ pub(crate) fn canonicalize_defs<'a>( def_ordering.insert_symbol_references(def_id as u32, &temp_output.references) } - // This returns both the defs info as well as the new scope. - // - // We have to return the new scope because we added defs to it - // (and those lookups shouldn't fail later, e.g. when canonicalizing - // the return expr), but we didn't want to mutate the original scope - // directly because we wanted to keep a clone of it around to diff - // when looking for unused idents. ( CanDefs { defs, @@ -539,7 +532,6 @@ pub(crate) fn canonicalize_defs<'a>( // The result needs a thread-safe `SendMap` aliases, }, - scope, output, symbols_introduced, ) @@ -1278,11 +1270,11 @@ fn canonicalize_pending_body<'a>( pub fn can_defs_with_return<'a>( env: &mut Env<'a>, var_store: &mut VarStore, - scope: Scope, + scope: &mut Scope, loc_defs: &'a [&'a Loc>], loc_ret: &'a Loc>, ) -> (Expr, Output) { - let (unsorted, mut scope, defs_output, symbols_introduced) = canonicalize_defs( + let (unsorted, defs_output, symbols_introduced) = canonicalize_defs( env, Output::default(), var_store, @@ -1294,7 +1286,7 @@ pub fn can_defs_with_return<'a>( // The def as a whole is a tail call iff its return expression is a tail call. // Use its output as a starting point because its tail_call already has the right answer! let (ret_expr, mut output) = - canonicalize_expr(env, var_store, &mut scope, loc_ret.region, &loc_ret.value); + canonicalize_expr(env, var_store, scope, loc_ret.region, &loc_ret.value); output .introduced_variables diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index caf5d32e26..89f0ad17d2 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -654,15 +654,10 @@ pub fn canonicalize_expr<'a>( (RuntimeError(problem), Output::default()) } ast::Expr::Defs(loc_defs, loc_ret) => { - can_defs_with_return( - env, - var_store, - // The body expression gets a new scope for canonicalization, - // so clone it. - scope.clone(), - loc_defs, - loc_ret, - ) + // The body expression gets a new scope for canonicalization, + scope.inner_scope(|inner_scope| { + can_defs_with_return(env, var_store, inner_scope, loc_defs, loc_ret) + }) } ast::Expr::Backpassing(_, _, _) => { unreachable!("Backpassing should have been desugared by now") @@ -685,14 +680,16 @@ pub fn canonicalize_expr<'a>( let mut can_branches = Vec::with_capacity(branches.len()); for branch in branches.iter() { - let (can_when_branch, branch_references) = canonicalize_when_branch( - env, - var_store, - scope.clone(), - region, - *branch, - &mut output, - ); + let (can_when_branch, branch_references) = scope.inner_scope(|inner_scope| { + canonicalize_when_branch( + env, + var_store, + inner_scope, + region, + *branch, + &mut output, + ) + }); output.references.union_mut(&branch_references); @@ -956,17 +953,31 @@ pub fn canonicalize_closure<'a>( loc_arg_patterns: &'a [Loc>], loc_body_expr: &'a Loc>, opt_def_name: Option, +) -> (ClosureData, Output) { + scope.inner_scope(|inner_scope| { + canonicalize_closure_inner_scope( + env, + var_store, + inner_scope, + loc_arg_patterns, + loc_body_expr, + opt_def_name, + ) + }) +} + +fn canonicalize_closure_inner_scope<'a>( + env: &mut Env<'a>, + var_store: &mut VarStore, + scope: &mut Scope, + loc_arg_patterns: &'a [Loc>], + loc_body_expr: &'a Loc>, + opt_def_name: Option, ) -> (ClosureData, Output) { // The globally unique symbol that will refer to this closure once it gets converted // into a top-level procedure for code gen. let symbol = opt_def_name.unwrap_or_else(|| env.gen_unique_symbol()); - // The body expression gets a new scope for canonicalization. - // Shadow `scope` to make sure we don't accidentally use the original one for the - // rest of this block, but keep the original around for later diffing. - let original_scope = scope; - let mut scope = original_scope.clone(); - let mut can_args = Vec::with_capacity(loc_arg_patterns.len()); let mut output = Output::default(); @@ -974,7 +985,7 @@ pub fn canonicalize_closure<'a>( let can_argument_pattern = canonicalize_pattern( env, var_store, - &mut scope, + scope, &mut output, FunctionArg, &loc_pattern.value, @@ -990,7 +1001,7 @@ pub fn canonicalize_closure<'a>( let (loc_body_expr, new_output) = canonicalize_expr( env, var_store, - &mut scope, + scope, loc_body_expr.region, &loc_body_expr.value, ); @@ -1062,7 +1073,7 @@ pub fn canonicalize_closure<'a>( fn canonicalize_when_branch<'a>( env: &mut Env<'a>, var_store: &mut VarStore, - mut scope: Scope, + scope: &mut Scope, _region: Region, branch: &'a ast::WhenBranch<'a>, output: &mut Output, @@ -1074,7 +1085,7 @@ fn canonicalize_when_branch<'a>( let can_pattern = canonicalize_pattern( env, var_store, - &mut scope, + scope, output, WhenBranch, &loc_pattern.value, @@ -1087,7 +1098,7 @@ fn canonicalize_when_branch<'a>( let (value, mut branch_output) = canonicalize_expr( env, var_store, - &mut scope, + scope, branch.value.region, &branch.value.value, ); @@ -1096,7 +1107,7 @@ fn canonicalize_when_branch<'a>( None => None, Some(loc_expr) => { let (can_guard, guard_branch_output) = - canonicalize_expr(env, var_store, &mut scope, loc_expr.region, &loc_expr.value); + canonicalize_expr(env, var_store, scope, loc_expr.region, &loc_expr.value); branch_output.union(guard_branch_output); Some(can_guard) diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index 0db77094cc..0f8cec0432 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -285,11 +285,11 @@ pub fn canonicalize_module_defs<'a>( } } - let (defs, mut scope, output, symbols_introduced) = canonicalize_defs( + let (defs, output, symbols_introduced) = canonicalize_defs( &mut env, Output::default(), var_store, - scope, + &mut scope, &desugared, PatternType::TopLevelDef, ); diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index 786d0e5f2f..fcfbf20811 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -355,7 +355,7 @@ impl Scope { result } - pub fn snapshot(&self) -> ScopeSnapshot { + fn snapshot(&self) -> ScopeSnapshot { ScopeSnapshot { idents: self.idents.clone(), aliases: self.aliases.clone(), @@ -364,7 +364,7 @@ impl Scope { } } - pub fn rollback(snapshot: ScopeSnapshot) -> Scope { + fn rollback(snapshot: ScopeSnapshot) -> Scope { Scope { idents: snapshot.idents, aliases: snapshot.aliases, From fb9d60226d6153796e464ccf2296168bc446daf2 Mon Sep 17 00:00:00 2001 From: Folkert Date: Thu, 28 Apr 2022 20:30:02 +0200 Subject: [PATCH 652/846] store `exposed_ident_ids in the scope itself --- compiler/can/src/annotation.rs | 7 +-- compiler/can/src/def.rs | 32 ++++------ compiler/can/src/effect_module.rs | 98 ++++--------------------------- compiler/can/src/module.rs | 9 +-- compiler/can/src/pattern.rs | 22 +------ compiler/can/src/scope.rs | 30 ++++++---- compiler/can/tests/helpers/mod.rs | 2 +- compiler/constrain/src/expr.rs | 3 +- reporting/tests/helpers/mod.rs | 2 +- 9 files changed, 54 insertions(+), 151 deletions(-) diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index c5e9548c40..1116280e35 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -579,12 +579,7 @@ fn can_annotation_help( vars: loc_vars, }, ) => { - let symbol = match scope.introduce( - name.value.into(), - &env.exposed_ident_ids, - &mut env.ident_ids, - region, - ) { + let symbol = match scope.introduce(name.value.into(), &mut env.ident_ids, region) { Ok(symbol) => symbol, Err((original_region, shadow, _new_symbol)) => { diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 659203c805..f0beb1e007 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -569,23 +569,19 @@ fn resolve_abilities<'a>( let name_region = member.name.region; let member_name = member.name.extract_spaces().item; - let member_sym = match scope.introduce( - member_name.into(), - &env.exposed_ident_ids, - &mut env.ident_ids, - name_region, - ) { - Ok(sym) => sym, - Err((original_region, shadow, _new_symbol)) => { - env.problem(roc_problem::can::Problem::Shadowing { - original_region, - shadow, - kind: ShadowKind::Variable, - }); - // Pretend the member isn't a part of the ability - continue; - } - }; + let member_sym = + match scope.introduce(member_name.into(), &mut env.ident_ids, name_region) { + Ok(sym) => sym, + Err((original_region, shadow, _new_symbol)) => { + env.problem(roc_problem::can::Problem::Shadowing { + original_region, + shadow, + kind: ShadowKind::Variable, + }); + // Pretend the member isn't a part of the ability + continue; + } + }; if pattern_type == PatternType::TopLevelDef { env.top_level_symbols.insert(member_sym); @@ -1365,7 +1361,6 @@ fn to_pending_type_def<'a>( match scope.introduce_without_shadow_symbol( &Ident::from(name.value), - &env.exposed_ident_ids, &mut env.ident_ids, region, ) { @@ -1445,7 +1440,6 @@ fn to_pending_type_def<'a>( } => { let name = match scope.introduce_without_shadow_symbol( &Ident::from(name.value), - &env.exposed_ident_ids, &mut env.ident_ids, name.region, ) { diff --git a/compiler/can/src/effect_module.rs b/compiler/can/src/effect_module.rs index c799416ad4..d603f20e1d 100644 --- a/compiler/can/src/effect_module.rs +++ b/compiler/can/src/effect_module.rs @@ -94,12 +94,7 @@ pub(crate) fn build_effect_builtins( macro_rules! new_symbol { ($scope:expr, $env:expr, $name:expr) => {{ $scope - .introduce( - $name.into(), - &$env.exposed_ident_ids, - &mut $env.ident_ids, - Region::zero(), - ) + .introduce($name.into(), &mut $env.ident_ids, Region::zero()) .unwrap() }}; } @@ -116,7 +111,6 @@ fn build_effect_always( scope .introduce( "effect_always_value".into(), - &env.exposed_ident_ids, &mut env.ident_ids, Region::zero(), ) @@ -127,7 +121,6 @@ fn build_effect_always( scope .introduce( "effect_always_inner".into(), - &env.exposed_ident_ids, &mut env.ident_ids, Region::zero(), ) @@ -136,12 +129,7 @@ fn build_effect_always( let always_symbol = { scope - .introduce( - "always".into(), - &env.exposed_ident_ids, - &mut env.ident_ids, - Region::zero(), - ) + .introduce("always".into(), &mut env.ident_ids, Region::zero()) .unwrap() }; @@ -261,7 +249,6 @@ fn build_effect_map( scope .introduce( "effect_map_thunk".into(), - &env.exposed_ident_ids, &mut env.ident_ids, Region::zero(), ) @@ -272,7 +259,6 @@ fn build_effect_map( scope .introduce( "effect_map_mapper".into(), - &env.exposed_ident_ids, &mut env.ident_ids, Region::zero(), ) @@ -281,12 +267,7 @@ fn build_effect_map( let map_symbol = { scope - .introduce( - "map".into(), - &env.exposed_ident_ids, - &mut env.ident_ids, - Region::zero(), - ) + .introduce("map".into(), &mut env.ident_ids, Region::zero()) .unwrap() }; @@ -320,7 +301,6 @@ fn build_effect_map( scope .introduce( "effect_map_inner".into(), - &env.exposed_ident_ids, &mut env.ident_ids, Region::zero(), ) @@ -479,7 +459,6 @@ fn build_effect_after( scope .introduce( "effect_after_thunk".into(), - &env.exposed_ident_ids, &mut env.ident_ids, Region::zero(), ) @@ -490,7 +469,6 @@ fn build_effect_after( scope .introduce( "effect_after_toEffect".into(), - &env.exposed_ident_ids, &mut env.ident_ids, Region::zero(), ) @@ -499,12 +477,7 @@ fn build_effect_after( let after_symbol = { scope - .introduce( - "after".into(), - &env.exposed_ident_ids, - &mut env.ident_ids, - Region::zero(), - ) + .introduce("after".into(), &mut env.ident_ids, Region::zero()) .unwrap() }; @@ -791,23 +764,13 @@ fn build_effect_forever( let forever_symbol = { scope - .introduce( - "forever".into(), - &env.exposed_ident_ids, - &mut env.ident_ids, - Region::zero(), - ) + .introduce("forever".into(), &mut env.ident_ids, Region::zero()) .unwrap() }; let effect = { scope - .introduce( - "effect".into(), - &env.exposed_ident_ids, - &mut env.ident_ids, - Region::zero(), - ) + .introduce("effect".into(), &mut env.ident_ids, Region::zero()) .unwrap() }; @@ -897,12 +860,7 @@ fn build_effect_forever_body( ) -> Expr { let closure_name = { scope - .introduce( - "forever_inner".into(), - &env.exposed_ident_ids, - &mut env.ident_ids, - Region::zero(), - ) + .introduce("forever_inner".into(), &mut env.ident_ids, Region::zero()) .unwrap() }; @@ -935,23 +893,13 @@ fn build_effect_forever_inner_body( ) -> Expr { let thunk1_symbol = { scope - .introduce( - "thunk1".into(), - &env.exposed_ident_ids, - &mut env.ident_ids, - Region::zero(), - ) + .introduce("thunk1".into(), &mut env.ident_ids, Region::zero()) .unwrap() }; let thunk2_symbol = { scope - .introduce( - "thunk2".into(), - &env.exposed_ident_ids, - &mut env.ident_ids, - Region::zero(), - ) + .introduce("thunk2".into(), &mut env.ident_ids, Region::zero()) .unwrap() }; @@ -1190,12 +1138,7 @@ fn build_effect_loop_body( ) -> Expr { let closure_name = { scope - .introduce( - "loop_inner".into(), - &env.exposed_ident_ids, - &mut env.ident_ids, - Region::zero(), - ) + .introduce("loop_inner".into(), &mut env.ident_ids, Region::zero()) .unwrap() }; @@ -1410,12 +1353,7 @@ pub fn build_host_exposed_def( let arg_symbol = { let ident = name.clone().into(); scope - .introduce( - ident, - &env.exposed_ident_ids, - &mut env.ident_ids, - Region::zero(), - ) + .introduce(ident, &mut env.ident_ids, Region::zero()) .unwrap() }; @@ -1439,12 +1377,7 @@ pub fn build_host_exposed_def( let ident = name.into(); scope - .introduce( - ident, - &env.exposed_ident_ids, - &mut env.ident_ids, - Region::zero(), - ) + .introduce(ident, &mut env.ident_ids, Region::zero()) .unwrap() }; @@ -1501,12 +1434,7 @@ pub fn build_host_exposed_def( let ident = name.into(); scope - .introduce( - ident, - &env.exposed_ident_ids, - &mut env.ident_ids, - Region::zero(), - ) + .introduce(ident, &mut env.ident_ids, Region::zero()) .unwrap() }; diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index 0f8cec0432..dd7d9c47d2 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -108,12 +108,7 @@ impl GeneratedInfo { } let effect_symbol = scope - .introduce( - name.into(), - &env.exposed_ident_ids, - &mut env.ident_ids, - Region::zero(), - ) + .introduce(name.into(), &mut env.ident_ids, Region::zero()) .unwrap(); { @@ -177,7 +172,7 @@ pub fn canonicalize_module_defs<'a>( var_store: &mut VarStore, ) -> Result { let mut can_exposed_imports = MutMap::default(); - let mut scope = Scope::new(home, var_store); + let mut scope = Scope::new(home, var_store, exposed_ident_ids.clone()); let mut env = Env::new(home, dep_idents, module_ids, exposed_ident_ids); let num_deps = dep_idents.len(); diff --git a/compiler/can/src/pattern.rs b/compiler/can/src/pattern.rs index 20d8877c04..5085f62e3a 100644 --- a/compiler/can/src/pattern.rs +++ b/compiler/can/src/pattern.rs @@ -192,7 +192,6 @@ pub fn canonicalize_def_header_pattern<'a>( // Identifiers that shadow ability members may appear (and may only appear) at the header of a def. Identifier(name) => match scope.introduce_or_shadow_ability_member( (*name).into(), - &env.exposed_ident_ids, &mut env.ident_ids, region, ) { @@ -238,12 +237,7 @@ pub fn canonicalize_pattern<'a>( use PatternType::*; let can_pattern = match pattern { - Identifier(name) => match scope.introduce( - (*name).into(), - &env.exposed_ident_ids, - &mut env.ident_ids, - region, - ) { + Identifier(name) => match scope.introduce((*name).into(), &mut env.ident_ids, region) { Ok(symbol) => { output.references.insert_bound(symbol); @@ -463,12 +457,7 @@ pub fn canonicalize_pattern<'a>( for loc_pattern in patterns.iter() { match loc_pattern.value { Identifier(label) => { - match scope.introduce( - label.into(), - &env.exposed_ident_ids, - &mut env.ident_ids, - region, - ) { + match scope.introduce(label.into(), &mut env.ident_ids, region) { Ok(symbol) => { output.references.insert_bound(symbol); @@ -524,12 +513,7 @@ pub fn canonicalize_pattern<'a>( } OptionalField(label, loc_default) => { // an optional DOES introduce the label into scope! - match scope.introduce( - label.into(), - &env.exposed_ident_ids, - &mut env.ident_ids, - region, - ) { + match scope.introduce(label.into(), &mut env.ident_ids, region) { Ok(symbol) => { let (can_default, expr_output) = canonicalize_expr( env, diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index fcfbf20811..08f96d9eda 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -11,6 +11,8 @@ use crate::abilities::AbilitiesStore; #[derive(Clone, Debug)] pub struct Scope { + exposed_ident_ids: IdentIds, + idents: IdentStore, /// The type aliases currently in scope @@ -65,9 +67,10 @@ fn add_aliases(var_store: &mut VarStore) -> SendMap { } impl Scope { - pub fn new(home: ModuleId, _var_store: &mut VarStore) -> Scope { + pub fn new(home: ModuleId, _var_store: &mut VarStore, exposed_ident_ids: IdentIds) -> Scope { Scope { home, + exposed_ident_ids, idents: IdentStore::new(), aliases: SendMap::default(), // TODO(abilities): default abilities in scope @@ -75,9 +78,14 @@ impl Scope { } } - pub fn new_with_aliases(home: ModuleId, var_store: &mut VarStore) -> Scope { + pub fn new_with_aliases( + home: ModuleId, + var_store: &mut VarStore, + exposed_ident_ids: IdentIds, + ) -> Scope { Scope { home, + exposed_ident_ids, idents: IdentStore::new(), aliases: add_aliases(var_store), // TODO(abilities): default abilities in scope @@ -191,12 +199,10 @@ impl Scope { pub fn introduce( &mut self, ident: Ident, - exposed_ident_ids: &IdentIds, all_ident_ids: &mut IdentIds, region: Region, ) -> Result, Symbol)> { - match self.introduce_without_shadow_symbol(&ident, exposed_ident_ids, all_ident_ids, region) - { + match self.introduce_without_shadow_symbol(&ident, all_ident_ids, region) { Ok(symbol) => Ok(symbol), Err((original_region, shadow)) => { let ident_id = all_ident_ids.add_ident(&ident); @@ -211,7 +217,6 @@ impl Scope { pub fn introduce_without_shadow_symbol( &mut self, ident: &Ident, - exposed_ident_ids: &IdentIds, all_ident_ids: &mut IdentIds, region: Region, ) -> Result)> { @@ -223,7 +228,7 @@ impl Scope { }; Err((original_region, shadow)) } - None => Ok(self.commit_introduction(ident, exposed_ident_ids, all_ident_ids, region)), + None => Ok(self.commit_introduction(ident, all_ident_ids, region)), } } @@ -237,7 +242,6 @@ impl Scope { pub fn introduce_or_shadow_ability_member( &mut self, ident: Ident, - exposed_ident_ids: &IdentIds, all_ident_ids: &mut IdentIds, region: Region, ) -> Result<(Symbol, Option), (Region, Loc, Symbol)> { @@ -269,8 +273,7 @@ impl Scope { } } None => { - let new_symbol = - self.commit_introduction(&ident, exposed_ident_ids, all_ident_ids, region); + let new_symbol = self.commit_introduction(&ident, all_ident_ids, region); Ok((new_symbol, None)) } } @@ -279,14 +282,13 @@ impl Scope { fn commit_introduction( &mut self, ident: &Ident, - exposed_ident_ids: &IdentIds, all_ident_ids: &mut IdentIds, region: Region, ) -> Symbol { // If this IdentId was already added previously // when the value was exposed in the module header, // use that existing IdentId. Otherwise, create a fresh one. - let ident_id = match exposed_ident_ids.get_id(ident) { + let ident_id = match self.exposed_ident_ids.get_id(ident) { Some(ident_id) => ident_id, None => all_ident_ids.add_ident(ident), }; @@ -358,6 +360,7 @@ impl Scope { fn snapshot(&self) -> ScopeSnapshot { ScopeSnapshot { idents: self.idents.clone(), + exposed_ident_ids: self.exposed_ident_ids.clone(), aliases: self.aliases.clone(), abilities_store: self.abilities_store.clone(), home: self.home, @@ -367,6 +370,7 @@ impl Scope { fn rollback(snapshot: ScopeSnapshot) -> Scope { Scope { idents: snapshot.idents, + exposed_ident_ids: snapshot.exposed_ident_ids, aliases: snapshot.aliases, abilities_store: snapshot.abilities_store, home: snapshot.home, @@ -505,6 +509,8 @@ impl IdentStore { #[derive(Clone, Debug)] pub struct ScopeSnapshot { + exposed_ident_ids: IdentIds, + idents: IdentStore, /// The type aliases currently in scope diff --git a/compiler/can/tests/helpers/mod.rs b/compiler/can/tests/helpers/mod.rs index 151a248ead..326aa99900 100644 --- a/compiler/can/tests/helpers/mod.rs +++ b/compiler/can/tests/helpers/mod.rs @@ -55,7 +55,7 @@ pub fn can_expr_with(arena: &Bump, home: ModuleId, expr_str: &str) -> CanExprOut // rules multiple times unnecessarily. let loc_expr = operator::desugar_expr(arena, &loc_expr); - let mut scope = Scope::new(home, &mut var_store); + let mut scope = Scope::new(home, &mut var_store, dep_idents.clone()); scope.add_alias( Symbol::NUM_INT, Region::zero(), diff --git a/compiler/constrain/src/expr.rs b/compiler/constrain/src/expr.rs index bf08238fc5..a7bb659b4d 100644 --- a/compiler/constrain/src/expr.rs +++ b/compiler/constrain/src/expr.rs @@ -685,7 +685,8 @@ pub fn constrain_expr( .clone() .intersection(new_pattern_headers.clone()) .is_empty(), - "Two patterns introduce the same symbols - that's a bug!" + "Two patterns introduce the same symbols - that's a bug!\n{:?}", + pattern_headers.clone().intersection(new_pattern_headers) ); pattern_headers.extend(new_pattern_headers); pattern_cons.push(pattern_con); diff --git a/reporting/tests/helpers/mod.rs b/reporting/tests/helpers/mod.rs index 09ad346648..482f6c567f 100644 --- a/reporting/tests/helpers/mod.rs +++ b/reporting/tests/helpers/mod.rs @@ -151,7 +151,7 @@ pub fn can_expr_with<'a>( // rules multiple times unnecessarily. let loc_expr = operator::desugar_expr(arena, &loc_expr); - let mut scope = Scope::new_with_aliases(home, &mut var_store); + let mut scope = Scope::new_with_aliases(home, &mut var_store, dep_idents.clone()); let dep_idents = IdentIds::exposed_builtins(0); let mut env = Env::new(home, &dep_idents, &module_ids, IdentIds::default()); let (loc_expr, output) = canonicalize_expr( From 5006231e812a376c95e7312159a433883626e399 Mon Sep 17 00:00:00 2001 From: Folkert Date: Thu, 28 Apr 2022 20:31:27 +0200 Subject: [PATCH 653/846] remove exposed_ident_ids from Env --- compiler/can/src/env.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/compiler/can/src/env.rs b/compiler/can/src/env.rs index b03b6daa8b..dc0b3e092c 100644 --- a/compiler/can/src/env.rs +++ b/compiler/can/src/env.rs @@ -33,7 +33,6 @@ pub struct Env<'a> { pub top_level_symbols: VecSet, pub ident_ids: IdentIds, - pub exposed_ident_ids: IdentIds, } impl<'a> Env<'a> { @@ -47,8 +46,7 @@ impl<'a> Env<'a> { home, dep_idents, module_ids, - ident_ids: exposed_ident_ids.clone(), // we start with these, but will add more later - exposed_ident_ids, + ident_ids: exposed_ident_ids, // we start with these, but will add more later problems: Vec::new(), closures: MutMap::default(), qualified_value_lookups: VecSet::default(), From 65e534b2b17c84f20cb3c53429c43877403b8be3 Mon Sep 17 00:00:00 2001 From: Folkert Date: Thu, 28 Apr 2022 20:34:55 +0200 Subject: [PATCH 654/846] rename --- compiler/can/src/scope.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index 08f96d9eda..0a5f8ccbea 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -67,10 +67,10 @@ fn add_aliases(var_store: &mut VarStore) -> SendMap { } impl Scope { - pub fn new(home: ModuleId, _var_store: &mut VarStore, exposed_ident_ids: IdentIds) -> Scope { + pub fn new(home: ModuleId, _var_store: &mut VarStore, initial_ident_ids: IdentIds) -> Scope { Scope { home, - exposed_ident_ids, + exposed_ident_ids: initial_ident_ids, idents: IdentStore::new(), aliases: SendMap::default(), // TODO(abilities): default abilities in scope @@ -81,11 +81,11 @@ impl Scope { pub fn new_with_aliases( home: ModuleId, var_store: &mut VarStore, - exposed_ident_ids: IdentIds, + initial_ident_ids: IdentIds, ) -> Scope { Scope { home, - exposed_ident_ids, + exposed_ident_ids: initial_ident_ids, idents: IdentStore::new(), aliases: add_aliases(var_store), // TODO(abilities): default abilities in scope From 37cb9279f57f1eae6eac4e1357fa841dd423d86a Mon Sep 17 00:00:00 2001 From: Folkert Date: Thu, 28 Apr 2022 20:38:58 +0200 Subject: [PATCH 655/846] prepare for all_ident_ids --- compiler/can/src/scope.rs | 54 ++++++++-------------------------- reporting/tests/helpers/mod.rs | 2 +- 2 files changed, 14 insertions(+), 42 deletions(-) diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index 0a5f8ccbea..eb3dfdcca1 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -11,8 +11,6 @@ use crate::abilities::AbilitiesStore; #[derive(Clone, Debug)] pub struct Scope { - exposed_ident_ids: IdentIds, - idents: IdentStore, /// The type aliases currently in scope @@ -24,6 +22,9 @@ pub struct Scope { /// The current module being processed. This will be used to turn /// unqualified idents into Symbols. home: ModuleId, + + exposed_ident_ids: IdentIds, + all_ident_ids: IdentIds, } fn add_aliases(var_store: &mut VarStore) -> SendMap { @@ -70,6 +71,7 @@ impl Scope { pub fn new(home: ModuleId, _var_store: &mut VarStore, initial_ident_ids: IdentIds) -> Scope { Scope { home, + all_ident_ids: initial_ident_ids.clone(), exposed_ident_ids: initial_ident_ids, idents: IdentStore::new(), aliases: SendMap::default(), @@ -85,6 +87,7 @@ impl Scope { ) -> Scope { Scope { home, + all_ident_ids: initial_ident_ids.clone(), exposed_ident_ids: initial_ident_ids, idents: IdentStore::new(), aliases: add_aliases(var_store), @@ -348,34 +351,20 @@ impl Scope { where F: FnOnce(&mut Scope) -> T, { - let snapshot = self.snapshot(); + let idents = self.idents.clone(); + let exposed_ident_ids = self.exposed_ident_ids.clone(); + let aliases = self.aliases.clone(); + let abilities_store = self.abilities_store.clone(); let result = f(self); - *self = Self::rollback(snapshot); + self.idents = idents; + self.exposed_ident_ids = exposed_ident_ids; + self.aliases = aliases; + self.abilities_store = abilities_store; result } - - fn snapshot(&self) -> ScopeSnapshot { - ScopeSnapshot { - idents: self.idents.clone(), - exposed_ident_ids: self.exposed_ident_ids.clone(), - aliases: self.aliases.clone(), - abilities_store: self.abilities_store.clone(), - home: self.home, - } - } - - fn rollback(snapshot: ScopeSnapshot) -> Scope { - Scope { - idents: snapshot.idents, - exposed_ident_ids: snapshot.exposed_ident_ids, - aliases: snapshot.aliases, - abilities_store: snapshot.abilities_store, - home: snapshot.home, - } - } } pub fn create_alias( @@ -506,20 +495,3 @@ impl IdentStore { self.regions.push(region); } } - -#[derive(Clone, Debug)] -pub struct ScopeSnapshot { - exposed_ident_ids: IdentIds, - - idents: IdentStore, - - /// The type aliases currently in scope - aliases: SendMap, - - /// The abilities currently in scope, and their implementors. - abilities_store: AbilitiesStore, - - /// The current module being processed. This will be used to turn - /// unqualified idents into Symbols. - home: ModuleId, -} diff --git a/reporting/tests/helpers/mod.rs b/reporting/tests/helpers/mod.rs index 482f6c567f..7b784aa220 100644 --- a/reporting/tests/helpers/mod.rs +++ b/reporting/tests/helpers/mod.rs @@ -151,7 +151,7 @@ pub fn can_expr_with<'a>( // rules multiple times unnecessarily. let loc_expr = operator::desugar_expr(arena, &loc_expr); - let mut scope = Scope::new_with_aliases(home, &mut var_store, dep_idents.clone()); + let mut scope = Scope::new_with_aliases(home, &mut var_store, IdentIds::default()); let dep_idents = IdentIds::exposed_builtins(0); let mut env = Env::new(home, &dep_idents, &module_ids, IdentIds::default()); let (loc_expr, output) = canonicalize_expr( From 7fb5b23fb04302bbc91bf85e809f820b5ed8b70f Mon Sep 17 00:00:00 2001 From: Folkert Date: Thu, 28 Apr 2022 21:08:28 +0200 Subject: [PATCH 656/846] move identids into Scope --- compiler/can/src/annotation.rs | 4 +- compiler/can/src/def.rs | 49 +++++++------- compiler/can/src/effect_module.rs | 106 ++++++------------------------ compiler/can/src/env.rs | 10 ++- compiler/can/src/expr.rs | 10 +-- compiler/can/src/module.rs | 10 +-- compiler/can/src/pattern.rs | 62 +++++++++-------- compiler/can/src/scope.rs | 47 +++++++------ compiler/can/tests/helpers/mod.rs | 4 +- reporting/tests/helpers/mod.rs | 2 +- 10 files changed, 123 insertions(+), 181 deletions(-) diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index 1116280e35..45f42692e4 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -277,7 +277,7 @@ fn make_apply_symbol( } } } else { - match env.qualified_lookup(module_name, ident, region) { + match env.qualified_lookup(scope, module_name, ident, region) { Ok(symbol) => Ok(symbol), Err(problem) => { // Either the module wasn't imported, or @@ -579,7 +579,7 @@ fn can_annotation_help( vars: loc_vars, }, ) => { - let symbol = match scope.introduce(name.value.into(), &mut env.ident_ids, region) { + let symbol = match scope.introduce(name.value.into(), region) { Ok(symbol) => symbol, Err((original_region, shadow, _new_symbol)) => { diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index f0beb1e007..cdc2546e66 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -243,7 +243,7 @@ pub(crate) fn canonicalize_defs<'a>( } if cfg!(debug_assertions) { - env.home.register_debug_idents(&env.ident_ids); + scope.register_debug_idents(); } enum TypeDef<'a> { @@ -278,7 +278,8 @@ pub(crate) fn canonicalize_defs<'a>( } => { let referenced_symbols = crate::annotation::find_type_def_symbols( env.home, - &mut env.ident_ids, + // TODO IDENT_IDS + &mut scope.ident_ids, &ann.value, ); @@ -295,7 +296,8 @@ pub(crate) fn canonicalize_defs<'a>( // definition. referenced_symbols.extend(crate::annotation::find_type_def_symbols( env.home, - &mut env.ident_ids, + // TODO IDENT_IDS + &mut scope.ident_ids, &member.typ.value, )); } @@ -569,19 +571,18 @@ fn resolve_abilities<'a>( let name_region = member.name.region; let member_name = member.name.extract_spaces().item; - let member_sym = - match scope.introduce(member_name.into(), &mut env.ident_ids, name_region) { - Ok(sym) => sym, - Err((original_region, shadow, _new_symbol)) => { - env.problem(roc_problem::can::Problem::Shadowing { - original_region, - shadow, - kind: ShadowKind::Variable, - }); - // Pretend the member isn't a part of the ability - continue; - } - }; + let member_sym = match scope.introduce(member_name.into(), name_region) { + Ok(sym) => sym, + Err((original_region, shadow, _new_symbol)) => { + env.problem(roc_problem::can::Problem::Shadowing { + original_region, + shadow, + kind: ShadowKind::Variable, + }); + // Pretend the member isn't a part of the ability + continue; + } + }; if pattern_type == PatternType::TopLevelDef { env.top_level_symbols.insert(member_sym); @@ -1072,7 +1073,7 @@ fn canonicalize_pending_value_def<'a>( region: loc_ann.region, } } else { - let symbol = env.gen_unique_symbol(); + let symbol = scope.gen_unique_symbol(); // generate a fake pattern for each argument. this makes signatures // that are functions only crash when they are applied. @@ -1359,11 +1360,7 @@ fn to_pending_type_def<'a>( let region = Region::span_across(&name.region, &ann.region); - match scope.introduce_without_shadow_symbol( - &Ident::from(name.value), - &mut env.ident_ids, - region, - ) { + match scope.introduce_without_shadow_symbol(&Ident::from(name.value), region) { Ok(symbol) => { let mut can_rigids: Vec> = Vec::with_capacity(vars.len()); @@ -1438,11 +1435,9 @@ fn to_pending_type_def<'a>( members, loc_has: _, } => { - let name = match scope.introduce_without_shadow_symbol( - &Ident::from(name.value), - &mut env.ident_ids, - name.region, - ) { + let name = match scope + .introduce_without_shadow_symbol(&Ident::from(name.value), name.region) + { Ok(symbol) => Loc::at(name.region, symbol), Err((original_region, shadowed_symbol)) => { env.problem(Problem::Shadowing { diff --git a/compiler/can/src/effect_module.rs b/compiler/can/src/effect_module.rs index d603f20e1d..6bba0ed464 100644 --- a/compiler/can/src/effect_module.rs +++ b/compiler/can/src/effect_module.rs @@ -87,15 +87,13 @@ pub(crate) fn build_effect_builtins( // show up with their name. We have to register them like below to make the names show up in // debug prints if false { - env.home.register_debug_idents(&env.ident_ids); + scope.register_debug_idents(); } } macro_rules! new_symbol { ($scope:expr, $env:expr, $name:expr) => {{ - $scope - .introduce($name.into(), &mut $env.ident_ids, Region::zero()) - .unwrap() + $scope.introduce($name.into(), Region::zero()).unwrap() }}; } @@ -109,29 +107,17 @@ fn build_effect_always( let value_symbol = { scope - .introduce( - "effect_always_value".into(), - &mut env.ident_ids, - Region::zero(), - ) + .introduce("effect_always_value".into(), Region::zero()) .unwrap() }; let inner_closure_symbol = { scope - .introduce( - "effect_always_inner".into(), - &mut env.ident_ids, - Region::zero(), - ) + .introduce("effect_always_inner".into(), Region::zero()) .unwrap() }; - let always_symbol = { - scope - .introduce("always".into(), &mut env.ident_ids, Region::zero()) - .unwrap() - }; + let always_symbol = { scope.introduce("always".into(), Region::zero()).unwrap() }; // \{} -> value let const_closure = { @@ -247,29 +233,17 @@ fn build_effect_map( let thunk_symbol = { scope - .introduce( - "effect_map_thunk".into(), - &mut env.ident_ids, - Region::zero(), - ) + .introduce("effect_map_thunk".into(), Region::zero()) .unwrap() }; let mapper_symbol = { scope - .introduce( - "effect_map_mapper".into(), - &mut env.ident_ids, - Region::zero(), - ) + .introduce("effect_map_mapper".into(), Region::zero()) .unwrap() }; - let map_symbol = { - scope - .introduce("map".into(), &mut env.ident_ids, Region::zero()) - .unwrap() - }; + let map_symbol = { scope.introduce("map".into(), Region::zero()).unwrap() }; // `thunk {}` let force_thunk_call = { @@ -299,11 +273,7 @@ fn build_effect_map( let inner_closure_symbol = { scope - .introduce( - "effect_map_inner".into(), - &mut env.ident_ids, - Region::zero(), - ) + .introduce("effect_map_inner".into(), Region::zero()) .unwrap() }; @@ -457,29 +427,17 @@ fn build_effect_after( let thunk_symbol = { scope - .introduce( - "effect_after_thunk".into(), - &mut env.ident_ids, - Region::zero(), - ) + .introduce("effect_after_thunk".into(), Region::zero()) .unwrap() }; let to_effect_symbol = { scope - .introduce( - "effect_after_toEffect".into(), - &mut env.ident_ids, - Region::zero(), - ) + .introduce("effect_after_toEffect".into(), Region::zero()) .unwrap() }; - let after_symbol = { - scope - .introduce("after".into(), &mut env.ident_ids, Region::zero()) - .unwrap() - }; + let after_symbol = { scope.introduce("after".into(), Region::zero()).unwrap() }; // `thunk {}` let force_thunk_call = { @@ -762,17 +720,9 @@ fn build_effect_forever( // // Making `foreverInner` perfectly tail-call optimizable - let forever_symbol = { - scope - .introduce("forever".into(), &mut env.ident_ids, Region::zero()) - .unwrap() - }; + let forever_symbol = { scope.introduce("forever".into(), Region::zero()).unwrap() }; - let effect = { - scope - .introduce("effect".into(), &mut env.ident_ids, Region::zero()) - .unwrap() - }; + let effect = { scope.introduce("effect".into(), Region::zero()).unwrap() }; let body = build_effect_forever_body(env, scope, effect_symbol, forever_symbol, effect, var_store); @@ -860,7 +810,7 @@ fn build_effect_forever_body( ) -> Expr { let closure_name = { scope - .introduce("forever_inner".into(), &mut env.ident_ids, Region::zero()) + .introduce("forever_inner".into(), Region::zero()) .unwrap() }; @@ -891,17 +841,9 @@ fn build_effect_forever_inner_body( effect: Symbol, var_store: &mut VarStore, ) -> Expr { - let thunk1_symbol = { - scope - .introduce("thunk1".into(), &mut env.ident_ids, Region::zero()) - .unwrap() - }; + let thunk1_symbol = { scope.introduce("thunk1".into(), Region::zero()).unwrap() }; - let thunk2_symbol = { - scope - .introduce("thunk2".into(), &mut env.ident_ids, Region::zero()) - .unwrap() - }; + let thunk2_symbol = { scope.introduce("thunk2".into(), Region::zero()).unwrap() }; // @Effect thunk1 = effect let thunk_from_effect = { @@ -1138,7 +1080,7 @@ fn build_effect_loop_body( ) -> Expr { let closure_name = { scope - .introduce("loop_inner".into(), &mut env.ident_ids, Region::zero()) + .introduce("loop_inner".into(), Region::zero()) .unwrap() }; @@ -1352,9 +1294,7 @@ pub fn build_host_exposed_def( let arg_symbol = { let ident = name.clone().into(); - scope - .introduce(ident, &mut env.ident_ids, Region::zero()) - .unwrap() + scope.introduce(ident, Region::zero()).unwrap() }; let arg_var = var_store.fresh(); @@ -1376,9 +1316,7 @@ pub fn build_host_exposed_def( let name = format!("effect_closure_{}", ident); let ident = name.into(); - scope - .introduce(ident, &mut env.ident_ids, Region::zero()) - .unwrap() + scope.introduce(ident, Region::zero()).unwrap() }; let effect_closure = Expr::Closure(ClosureData { @@ -1433,9 +1371,7 @@ pub fn build_host_exposed_def( let name = format!("effect_closure_{}", ident); let ident = name.into(); - scope - .introduce(ident, &mut env.ident_ids, Region::zero()) - .unwrap() + scope.introduce(ident, Region::zero()).unwrap() }; let empty_record_pattern = Pattern::RecordDestructure { diff --git a/compiler/can/src/env.rs b/compiler/can/src/env.rs index dc0b3e092c..73bad7d1aa 100644 --- a/compiler/can/src/env.rs +++ b/compiler/can/src/env.rs @@ -1,4 +1,5 @@ use crate::procedure::References; +use crate::scope::Scope; use roc_collections::{MutMap, VecSet}; use roc_module::ident::{Ident, Lowercase, ModuleName}; use roc_module::symbol::{IdentIds, IdentIdsByModule, ModuleId, ModuleIds, Symbol}; @@ -32,7 +33,7 @@ pub struct Env<'a> { pub top_level_symbols: VecSet, - pub ident_ids: IdentIds, + ident_ids: IdentIds, } impl<'a> Env<'a> { @@ -59,6 +60,7 @@ impl<'a> Env<'a> { /// Returns Err if the symbol resolved, but it was not exposed by the given module pub fn qualified_lookup( &mut self, + scope: &Scope, module_name_str: &str, ident: &str, region: Region, @@ -79,7 +81,7 @@ impl<'a> Env<'a> { // You can do qualified lookups on your own module, e.g. // if I'm in the Foo module, I can do a `Foo.bar` lookup. if module_id == self.home { - match self.ident_ids.get_id(&ident) { + match scope.ident_ids.get_id(&ident) { Some(ident_id) => { let symbol = Symbol::new(module_id, ident_id); @@ -97,7 +99,8 @@ impl<'a> Env<'a> { value: ident, region, }, - self.ident_ids + scope + .ident_ids .ident_strs() .map(|(_, string)| string.into()) .collect(), @@ -167,6 +170,7 @@ impl<'a> Env<'a> { /// /// This is used, for example, during canonicalization of an Expr::Closure /// to generate a unique symbol to refer to that closure. + // TODO IDENT_IDS pub fn gen_unique_symbol(&mut self) -> Symbol { let ident_id = self.ident_ids.gen_unique(); diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index 89f0ad17d2..4b67071d4e 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -407,6 +407,7 @@ pub fn canonicalize_expr<'a>( fields, update: loc_update, } => { + dbg!(&loc_update); let (can_update, update_out) = canonicalize_expr(env, var_store, scope, loc_update.region, &loc_update.value); if let Var(symbol) = &can_update.value { @@ -437,6 +438,7 @@ pub fn canonicalize_expr<'a>( ), } } else { + dbg!(&can_update.value); // only (optionally qualified) variables can be updated, not arbitrary expressions let error = roc_problem::can::RuntimeError::InvalidRecordUpdate { @@ -731,7 +733,7 @@ pub fn canonicalize_expr<'a>( } ast::Expr::AccessorFunction(field) => ( Accessor(AccessorData { - name: env.gen_unique_symbol(), + name: scope.gen_unique_symbol(), function_var: var_store.fresh(), record_var: var_store.fresh(), ext_var: var_store.fresh(), @@ -746,7 +748,7 @@ pub fn canonicalize_expr<'a>( let variant_var = var_store.fresh(); let ext_var = var_store.fresh(); - let symbol = env.gen_unique_symbol(); + let symbol = scope.gen_unique_symbol(); ( ZeroArgumentTag { @@ -976,7 +978,7 @@ fn canonicalize_closure_inner_scope<'a>( ) -> (ClosureData, Output) { // The globally unique symbol that will refer to this closure once it gets converted // into a top-level procedure for code gen. - let symbol = opt_def_name.unwrap_or_else(|| env.gen_unique_symbol()); + let symbol = opt_def_name.unwrap_or_else(|| scope.gen_unique_symbol()); let mut can_args = Vec::with_capacity(loc_arg_patterns.len()); let mut output = Output::default(); @@ -1273,7 +1275,7 @@ fn canonicalize_var_lookup( } else { // Since module_name was nonempty, this is a qualified var. // Look it up in the env! - match env.qualified_lookup(module_name, ident, region) { + match env.qualified_lookup(scope, module_name, ident, region) { Ok(symbol) => { output.references.insert_value_lookup(symbol); diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index dd7d9c47d2..6f114bb0f1 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -107,9 +107,7 @@ impl GeneratedInfo { env.problem(Problem::UnknownGeneratesWith(unknown)); } - let effect_symbol = scope - .introduce(name.into(), &mut env.ident_ids, Region::zero()) - .unwrap(); + let effect_symbol = scope.introduce(name.into(), Region::zero()).unwrap(); { let a_var = var_store.fresh(); @@ -409,7 +407,7 @@ pub fn canonicalize_module_defs<'a>( let symbol = def.pattern_vars.iter().next().unwrap().0; let ident_id = symbol.ident_id(); let ident = - env.ident_ids.get_name(ident_id).unwrap().to_string(); + scope.ident_ids.get_name(ident_id).unwrap().to_string(); let def_annotation = def.annotation.clone().unwrap(); let annotation = crate::annotation::Annotation { typ: def_annotation.signature, @@ -537,6 +535,8 @@ pub fn canonicalize_module_defs<'a>( } } + let ident_ids = scope.ident_ids.clone(); + let output = ModuleOutput { scope, aliases, @@ -547,7 +547,7 @@ pub fn canonicalize_module_defs<'a>( exposed_imports: can_exposed_imports, problems: env.problems, lookups, - ident_ids: env.ident_ids, + ident_ids, }; Ok(output) diff --git a/compiler/can/src/pattern.rs b/compiler/can/src/pattern.rs index 5085f62e3a..3025694963 100644 --- a/compiler/can/src/pattern.rs +++ b/compiler/can/src/pattern.rs @@ -190,36 +190,34 @@ pub fn canonicalize_def_header_pattern<'a>( match pattern { // Identifiers that shadow ability members may appear (and may only appear) at the header of a def. - Identifier(name) => match scope.introduce_or_shadow_ability_member( - (*name).into(), - &mut env.ident_ids, - region, - ) { - Ok((symbol, shadowing_ability_member)) => { - output.references.insert_bound(symbol); - let can_pattern = match shadowing_ability_member { - // A fresh identifier. - None => Pattern::Identifier(symbol), - // Likely a specialization of an ability. - Some(ability_member_name) => Pattern::AbilityMemberSpecialization { - ident: symbol, - specializes: ability_member_name, - }, - }; - Loc::at(region, can_pattern) - } - Err((original_region, shadow, new_symbol)) => { - env.problem(Problem::RuntimeError(RuntimeError::Shadowing { - original_region, - shadow: shadow.clone(), - kind: ShadowKind::Variable, - })); - output.references.insert_bound(new_symbol); + Identifier(name) => { + match scope.introduce_or_shadow_ability_member((*name).into(), region) { + Ok((symbol, shadowing_ability_member)) => { + output.references.insert_bound(symbol); + let can_pattern = match shadowing_ability_member { + // A fresh identifier. + None => Pattern::Identifier(symbol), + // Likely a specialization of an ability. + Some(ability_member_name) => Pattern::AbilityMemberSpecialization { + ident: symbol, + specializes: ability_member_name, + }, + }; + Loc::at(region, can_pattern) + } + Err((original_region, shadow, new_symbol)) => { + env.problem(Problem::RuntimeError(RuntimeError::Shadowing { + original_region, + shadow: shadow.clone(), + kind: ShadowKind::Variable, + })); + output.references.insert_bound(new_symbol); - let can_pattern = Pattern::Shadowed(original_region, shadow, new_symbol); - Loc::at(region, can_pattern) + let can_pattern = Pattern::Shadowed(original_region, shadow, new_symbol); + Loc::at(region, can_pattern) + } } - }, + } _ => canonicalize_pattern(env, var_store, scope, output, pattern_type, pattern, region), } } @@ -237,7 +235,7 @@ pub fn canonicalize_pattern<'a>( use PatternType::*; let can_pattern = match pattern { - Identifier(name) => match scope.introduce((*name).into(), &mut env.ident_ids, region) { + Identifier(name) => match scope.introduce((*name).into(), region) { Ok(symbol) => { output.references.insert_bound(symbol); @@ -457,7 +455,7 @@ pub fn canonicalize_pattern<'a>( for loc_pattern in patterns.iter() { match loc_pattern.value { Identifier(label) => { - match scope.introduce(label.into(), &mut env.ident_ids, region) { + match scope.introduce(label.into(), region) { Ok(symbol) => { output.references.insert_bound(symbol); @@ -490,7 +488,7 @@ pub fn canonicalize_pattern<'a>( RequiredField(label, loc_guard) => { // a guard does not introduce the label into scope! - let symbol = scope.ignore(&Ident::from(label), &mut env.ident_ids); + let symbol = scope.ignore(&Ident::from(label)); let can_guard = canonicalize_pattern( env, var_store, @@ -513,7 +511,7 @@ pub fn canonicalize_pattern<'a>( } OptionalField(label, loc_default) => { // an optional DOES introduce the label into scope! - match scope.introduce(label.into(), &mut env.ident_ids, region) { + match scope.introduce(label.into(), region) { Ok(symbol) => { let (can_default, expr_output) = canonicalize_expr( env, diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index eb3dfdcca1..819a692bcc 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -24,7 +24,7 @@ pub struct Scope { home: ModuleId, exposed_ident_ids: IdentIds, - all_ident_ids: IdentIds, + pub ident_ids: IdentIds, } fn add_aliases(var_store: &mut VarStore) -> SendMap { @@ -71,7 +71,7 @@ impl Scope { pub fn new(home: ModuleId, _var_store: &mut VarStore, initial_ident_ids: IdentIds) -> Scope { Scope { home, - all_ident_ids: initial_ident_ids.clone(), + ident_ids: initial_ident_ids.clone(), exposed_ident_ids: initial_ident_ids, idents: IdentStore::new(), aliases: SendMap::default(), @@ -87,7 +87,7 @@ impl Scope { ) -> Scope { Scope { home, - all_ident_ids: initial_ident_ids.clone(), + ident_ids: initial_ident_ids.clone(), exposed_ident_ids: initial_ident_ids, idents: IdentStore::new(), aliases: add_aliases(var_store), @@ -202,13 +202,12 @@ impl Scope { pub fn introduce( &mut self, ident: Ident, - all_ident_ids: &mut IdentIds, region: Region, ) -> Result, Symbol)> { - match self.introduce_without_shadow_symbol(&ident, all_ident_ids, region) { + match self.introduce_without_shadow_symbol(&ident, region) { Ok(symbol) => Ok(symbol), Err((original_region, shadow)) => { - let ident_id = all_ident_ids.add_ident(&ident); + let ident_id = self.ident_ids.add_ident(&ident); let symbol = Symbol::new(self.home, ident_id); Err((original_region, shadow, symbol)) @@ -220,7 +219,6 @@ impl Scope { pub fn introduce_without_shadow_symbol( &mut self, ident: &Ident, - all_ident_ids: &mut IdentIds, region: Region, ) -> Result)> { match self.idents.get_symbol_and_region(ident) { @@ -231,7 +229,7 @@ impl Scope { }; Err((original_region, shadow)) } - None => Ok(self.commit_introduction(ident, all_ident_ids, region)), + None => Ok(self.commit_introduction(ident, region)), } } @@ -245,7 +243,6 @@ impl Scope { pub fn introduce_or_shadow_ability_member( &mut self, ident: Ident, - all_ident_ids: &mut IdentIds, region: Region, ) -> Result<(Symbol, Option), (Region, Loc, Symbol)> { match self.idents.get_index(&ident) { @@ -253,7 +250,7 @@ impl Scope { let original_symbol = self.idents.symbols[index]; let original_region = self.idents.regions[index]; - let shadow_ident_id = all_ident_ids.add_ident(&ident); + let shadow_ident_id = self.ident_ids.add_ident(&ident); let shadow_symbol = Symbol::new(self.home, shadow_ident_id); if self.abilities_store.is_ability_member_name(original_symbol) { @@ -276,24 +273,19 @@ impl Scope { } } None => { - let new_symbol = self.commit_introduction(&ident, all_ident_ids, region); + let new_symbol = self.commit_introduction(&ident, region); Ok((new_symbol, None)) } } } - fn commit_introduction( - &mut self, - ident: &Ident, - all_ident_ids: &mut IdentIds, - region: Region, - ) -> Symbol { + fn commit_introduction(&mut self, ident: &Ident, region: Region) -> Symbol { // If this IdentId was already added previously // when the value was exposed in the module header, // use that existing IdentId. Otherwise, create a fresh one. let ident_id = match self.exposed_ident_ids.get_id(ident) { Some(ident_id) => ident_id, - None => all_ident_ids.add_ident(ident), + None => self.ident_ids.add_ident(ident), }; let symbol = Symbol::new(self.home, ident_id); @@ -306,8 +298,8 @@ impl Scope { /// Ignore an identifier. /// /// Used for record guards like { x: Just _ } - pub fn ignore(&mut self, ident: &Ident, all_ident_ids: &mut IdentIds) -> Symbol { - let ident_id = all_ident_ids.add_ident(ident); + pub fn ignore(&mut self, ident: &Ident) -> Symbol { + let ident_id = self.ident_ids.add_ident(ident); Symbol::new(self.home, ident_id) } @@ -365,6 +357,21 @@ impl Scope { result } + + pub fn register_debug_idents(&self) { + self.home.register_debug_idents(&self.ident_ids) + } + + /// Generates a unique, new symbol like "$1" or "$5", + /// using the home module as the module_id. + /// + /// This is used, for example, during canonicalization of an Expr::Closure + /// to generate a unique symbol to refer to that closure. + pub fn gen_unique_symbol(&mut self) -> Symbol { + let ident_id = self.ident_ids.gen_unique(); + + Symbol::new(self.home, ident_id) + } } pub fn create_alias( diff --git a/compiler/can/tests/helpers/mod.rs b/compiler/can/tests/helpers/mod.rs index 326aa99900..ec898feb58 100644 --- a/compiler/can/tests/helpers/mod.rs +++ b/compiler/can/tests/helpers/mod.rs @@ -55,7 +55,7 @@ pub fn can_expr_with(arena: &Bump, home: ModuleId, expr_str: &str) -> CanExprOut // rules multiple times unnecessarily. let loc_expr = operator::desugar_expr(arena, &loc_expr); - let mut scope = Scope::new(home, &mut var_store, dep_idents.clone()); + let mut scope = Scope::new(home, &mut var_store, IdentIds::default()); scope.add_alias( Symbol::NUM_INT, Region::zero(), @@ -75,7 +75,7 @@ pub fn can_expr_with(arena: &Bump, home: ModuleId, expr_str: &str) -> CanExprOut ); let mut all_ident_ids = IdentIds::exposed_builtins(1); - all_ident_ids.insert(home, env.ident_ids); + all_ident_ids.insert(home, scope.ident_ids); let interns = Interns { module_ids: env.module_ids.clone(), diff --git a/reporting/tests/helpers/mod.rs b/reporting/tests/helpers/mod.rs index 7b784aa220..74ccd4f3a1 100644 --- a/reporting/tests/helpers/mod.rs +++ b/reporting/tests/helpers/mod.rs @@ -184,7 +184,7 @@ pub fn can_expr_with<'a>( introduce_builtin_imports(&mut constraints, imports, constraint, &mut var_store); let mut all_ident_ids = IdentIds::exposed_builtins(1); - all_ident_ids.insert(home, env.ident_ids); + all_ident_ids.insert(home, scope.ident_ids); let interns = Interns { module_ids: env.module_ids.clone(), From 992575051af91f4f247c3b507f24c06912cb51c5 Mon Sep 17 00:00:00 2001 From: Folkert Date: Thu, 28 Apr 2022 21:11:08 +0200 Subject: [PATCH 657/846] remove identids from Env --- compiler/can/src/env.rs | 16 ---------------- compiler/can/src/module.rs | 4 ++-- compiler/can/tests/helpers/mod.rs | 2 +- reporting/tests/helpers/mod.rs | 2 +- 4 files changed, 4 insertions(+), 20 deletions(-) diff --git a/compiler/can/src/env.rs b/compiler/can/src/env.rs index 73bad7d1aa..c28b54a038 100644 --- a/compiler/can/src/env.rs +++ b/compiler/can/src/env.rs @@ -32,8 +32,6 @@ pub struct Env<'a> { pub qualified_type_lookups: VecSet, pub top_level_symbols: VecSet, - - ident_ids: IdentIds, } impl<'a> Env<'a> { @@ -41,13 +39,11 @@ impl<'a> Env<'a> { home: ModuleId, dep_idents: &'a IdentIdsByModule, module_ids: &'a ModuleIds, - exposed_ident_ids: IdentIds, ) -> Env<'a> { Env { home, dep_idents, module_ids, - ident_ids: exposed_ident_ids, // we start with these, but will add more later problems: Vec::new(), closures: MutMap::default(), qualified_value_lookups: VecSet::default(), @@ -165,18 +161,6 @@ impl<'a> Env<'a> { } } - /// Generates a unique, new symbol like "$1" or "$5", - /// using the home module as the module_id. - /// - /// This is used, for example, during canonicalization of an Expr::Closure - /// to generate a unique symbol to refer to that closure. - // TODO IDENT_IDS - pub fn gen_unique_symbol(&mut self) -> Symbol { - let ident_id = self.ident_ids.gen_unique(); - - Symbol::new(self.home, ident_id) - } - pub fn problem(&mut self, problem: Problem) { self.problems.push(problem) } diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index 6f114bb0f1..76d42a9855 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -170,8 +170,8 @@ pub fn canonicalize_module_defs<'a>( var_store: &mut VarStore, ) -> Result { let mut can_exposed_imports = MutMap::default(); - let mut scope = Scope::new(home, var_store, exposed_ident_ids.clone()); - let mut env = Env::new(home, dep_idents, module_ids, exposed_ident_ids); + let mut scope = Scope::new(home, var_store, exposed_ident_ids); + let mut env = Env::new(home, dep_idents, module_ids); let num_deps = dep_idents.len(); for (name, alias) in aliases.into_iter() { diff --git a/compiler/can/tests/helpers/mod.rs b/compiler/can/tests/helpers/mod.rs index ec898feb58..7ecaf81c66 100644 --- a/compiler/can/tests/helpers/mod.rs +++ b/compiler/can/tests/helpers/mod.rs @@ -65,7 +65,7 @@ pub fn can_expr_with(arena: &Bump, home: ModuleId, expr_str: &str) -> CanExprOut ); let dep_idents = IdentIds::exposed_builtins(0); - let mut env = Env::new(home, &dep_idents, &module_ids, IdentIds::default()); + let mut env = Env::new(home, &dep_idents, &module_ids); let (loc_expr, output) = canonicalize_expr( &mut env, &mut var_store, diff --git a/reporting/tests/helpers/mod.rs b/reporting/tests/helpers/mod.rs index 74ccd4f3a1..83918a5934 100644 --- a/reporting/tests/helpers/mod.rs +++ b/reporting/tests/helpers/mod.rs @@ -153,7 +153,7 @@ pub fn can_expr_with<'a>( let mut scope = Scope::new_with_aliases(home, &mut var_store, IdentIds::default()); let dep_idents = IdentIds::exposed_builtins(0); - let mut env = Env::new(home, &dep_idents, &module_ids, IdentIds::default()); + let mut env = Env::new(home, &dep_idents, &module_ids); let (loc_expr, output) = canonicalize_expr( &mut env, &mut var_store, From b1fe5659a4069bb66216898c24b17e505edbf18e Mon Sep 17 00:00:00 2001 From: Folkert Date: Thu, 28 Apr 2022 21:19:27 +0200 Subject: [PATCH 658/846] cleanup --- compiler/can/src/effect_module.rs | 45 +++++++++---------------------- compiler/can/src/env.rs | 2 +- compiler/can/src/expr.rs | 2 -- compiler/can/src/module.rs | 2 -- 4 files changed, 13 insertions(+), 38 deletions(-) diff --git a/compiler/can/src/effect_module.rs b/compiler/can/src/effect_module.rs index 6bba0ed464..96350ad283 100644 --- a/compiler/can/src/effect_module.rs +++ b/compiler/can/src/effect_module.rs @@ -1,6 +1,5 @@ use crate::annotation::IntroducedVariables; use crate::def::{Declaration, Def}; -use crate::env::Env; use crate::expr::{ClosureData, Expr, Recursive}; use crate::pattern::Pattern; use crate::scope::Scope; @@ -35,7 +34,6 @@ pub(crate) struct HostedGeneratedFunctions { /// For this alias we implement the functions specified in HostedGeneratedFunctions with the /// standard implementation. pub(crate) fn build_effect_builtins( - env: &mut Env, scope: &mut Scope, effect_symbol: Symbol, var_store: &mut VarStore, @@ -45,7 +43,7 @@ pub(crate) fn build_effect_builtins( ) { macro_rules! helper { ($f:expr) => {{ - let (symbol, def) = $f(env, scope, effect_symbol, var_store); + let (symbol, def) = $f(scope, effect_symbol, var_store); // make the outside world know this symbol exists exposed_symbols.insert(symbol); @@ -92,13 +90,12 @@ pub(crate) fn build_effect_builtins( } macro_rules! new_symbol { - ($scope:expr, $env:expr, $name:expr) => {{ + ($scope:expr, $name:expr) => {{ $scope.introduce($name.into(), Region::zero()).unwrap() }}; } fn build_effect_always( - env: &mut Env, scope: &mut Scope, effect_symbol: Symbol, var_store: &mut VarStore, @@ -224,7 +221,6 @@ fn build_effect_always( } fn build_effect_map( - env: &mut Env, scope: &mut Scope, effect_symbol: Symbol, var_store: &mut VarStore, @@ -418,7 +414,6 @@ fn build_effect_map( } fn build_effect_after( - env: &mut Env, scope: &mut Scope, effect_symbol: Symbol, var_store: &mut VarStore, @@ -667,7 +662,6 @@ fn force_effect( } fn build_effect_forever( - env: &mut Env, scope: &mut Scope, effect_symbol: Symbol, var_store: &mut VarStore, @@ -724,8 +718,7 @@ fn build_effect_forever( let effect = { scope.introduce("effect".into(), Region::zero()).unwrap() }; - let body = - build_effect_forever_body(env, scope, effect_symbol, forever_symbol, effect, var_store); + let body = build_effect_forever_body(scope, effect_symbol, forever_symbol, effect, var_store); let arguments = vec![(var_store.fresh(), Loc::at_zero(Pattern::Identifier(effect)))]; @@ -801,7 +794,6 @@ fn build_effect_forever( } fn build_effect_forever_body( - env: &mut Env, scope: &mut Scope, effect_symbol: Symbol, forever_symbol: Symbol, @@ -814,14 +806,8 @@ fn build_effect_forever_body( .unwrap() }; - let inner_body = build_effect_forever_inner_body( - env, - scope, - effect_symbol, - forever_symbol, - effect, - var_store, - ); + let inner_body = + build_effect_forever_inner_body(scope, effect_symbol, forever_symbol, effect, var_store); let captured_symbols = vec![effect]; wrap_in_effect_thunk( @@ -834,7 +820,6 @@ fn build_effect_forever_body( } fn build_effect_forever_inner_body( - env: &mut Env, scope: &mut Scope, effect_symbol: Symbol, forever_symbol: Symbol, @@ -934,17 +919,15 @@ fn build_effect_forever_inner_body( } fn build_effect_loop( - env: &mut Env, scope: &mut Scope, effect_symbol: Symbol, var_store: &mut VarStore, ) -> (Symbol, Def) { - let loop_symbol = new_symbol!(scope, env, "loop"); - let state_symbol = new_symbol!(scope, env, "state"); - let step_symbol = new_symbol!(scope, env, "step"); + let loop_symbol = new_symbol!(scope, "loop"); + let state_symbol = new_symbol!(scope, "state"); + let step_symbol = new_symbol!(scope, "step"); let body = build_effect_loop_body( - env, scope, effect_symbol, loop_symbol, @@ -1070,7 +1053,6 @@ fn build_effect_loop( } fn build_effect_loop_body( - env: &mut Env, scope: &mut Scope, effect_symbol: Symbol, loop_symbol: Symbol, @@ -1085,7 +1067,6 @@ fn build_effect_loop_body( }; let inner_body = build_effect_loop_inner_body( - env, scope, effect_symbol, loop_symbol, @@ -1127,7 +1108,6 @@ fn applied_tag_pattern( } fn build_effect_loop_inner_body( - env: &mut Env, scope: &mut Scope, effect_symbol: Symbol, loop_symbol: Symbol, @@ -1135,11 +1115,11 @@ fn build_effect_loop_inner_body( step_symbol: Symbol, var_store: &mut VarStore, ) -> Expr { - let thunk1_symbol = new_symbol!(scope, env, "thunk3"); - let thunk2_symbol = new_symbol!(scope, env, "thunk4"); + let thunk1_symbol = new_symbol!(scope, "thunk3"); + let thunk2_symbol = new_symbol!(scope, "thunk4"); - let new_state_symbol = new_symbol!(scope, env, "newState"); - let done_symbol = new_symbol!(scope, env, "done"); + let new_state_symbol = new_symbol!(scope, "newState"); + let done_symbol = new_symbol!(scope, "done"); // Effect thunk1 = step state let thunk_from_effect = { @@ -1262,7 +1242,6 @@ fn build_effect_loop_inner_body( } pub fn build_host_exposed_def( - env: &mut Env, scope: &mut Scope, symbol: Symbol, ident: &str, diff --git a/compiler/can/src/env.rs b/compiler/can/src/env.rs index c28b54a038..a9398cb138 100644 --- a/compiler/can/src/env.rs +++ b/compiler/can/src/env.rs @@ -2,7 +2,7 @@ use crate::procedure::References; use crate::scope::Scope; use roc_collections::{MutMap, VecSet}; use roc_module::ident::{Ident, Lowercase, ModuleName}; -use roc_module::symbol::{IdentIds, IdentIdsByModule, ModuleId, ModuleIds, Symbol}; +use roc_module::symbol::{ IdentIdsByModule, ModuleId, ModuleIds, Symbol}; use roc_problem::can::{Problem, RuntimeError}; use roc_region::all::{Loc, Region}; diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index 4b67071d4e..515fb90930 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -407,7 +407,6 @@ pub fn canonicalize_expr<'a>( fields, update: loc_update, } => { - dbg!(&loc_update); let (can_update, update_out) = canonicalize_expr(env, var_store, scope, loc_update.region, &loc_update.value); if let Var(symbol) = &can_update.value { @@ -438,7 +437,6 @@ pub fn canonicalize_expr<'a>( ), } } else { - dbg!(&can_update.value); // only (optionally qualified) variables can be updated, not arbitrary expressions let error = roc_problem::can::RuntimeError::InvalidRecordUpdate { diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index 76d42a9855..05c43b52ee 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -362,7 +362,6 @@ pub fn canonicalize_module_defs<'a>( // NOTE this currently builds all functions, not just the ones that the user requested crate::effect_module::build_effect_builtins( - &mut env, &mut scope, effect_symbol, var_store, @@ -417,7 +416,6 @@ pub fn canonicalize_module_defs<'a>( }; let hosted_def = crate::effect_module::build_host_exposed_def( - &mut env, &mut scope, *symbol, &ident, From 572bd66fb7be972a56fd789f0c9eaf54401853ce Mon Sep 17 00:00:00 2001 From: Folkert Date: Thu, 28 Apr 2022 21:34:58 +0200 Subject: [PATCH 659/846] remove exosed_ident_ids --- compiler/can/src/env.rs | 2 +- compiler/can/src/scope.rs | 24 +++++++++---------- .../collections/src/small_string_interner.rs | 8 +++++++ compiler/module/src/symbol.rs | 14 +++++++++++ 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/compiler/can/src/env.rs b/compiler/can/src/env.rs index a9398cb138..550ce5abec 100644 --- a/compiler/can/src/env.rs +++ b/compiler/can/src/env.rs @@ -2,7 +2,7 @@ use crate::procedure::References; use crate::scope::Scope; use roc_collections::{MutMap, VecSet}; use roc_module::ident::{Ident, Lowercase, ModuleName}; -use roc_module::symbol::{ IdentIdsByModule, ModuleId, ModuleIds, Symbol}; +use roc_module::symbol::{IdentIdsByModule, ModuleId, ModuleIds, Symbol}; use roc_problem::can::{Problem, RuntimeError}; use roc_region::all::{Loc, Region}; diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index 819a692bcc..0592850e75 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -23,8 +23,10 @@ pub struct Scope { /// unqualified idents into Symbols. home: ModuleId, - exposed_ident_ids: IdentIds, pub ident_ids: IdentIds, + + /// The first `exposed_ident_count` identifiers are exposed + exposed_ident_count: usize, } fn add_aliases(var_store: &mut VarStore) -> SendMap { @@ -71,8 +73,8 @@ impl Scope { pub fn new(home: ModuleId, _var_store: &mut VarStore, initial_ident_ids: IdentIds) -> Scope { Scope { home, - ident_ids: initial_ident_ids.clone(), - exposed_ident_ids: initial_ident_ids, + exposed_ident_count: initial_ident_ids.len(), + ident_ids: initial_ident_ids, idents: IdentStore::new(), aliases: SendMap::default(), // TODO(abilities): default abilities in scope @@ -87,8 +89,8 @@ impl Scope { ) -> Scope { Scope { home, - ident_ids: initial_ident_ids.clone(), - exposed_ident_ids: initial_ident_ids, + exposed_ident_count: initial_ident_ids.len(), + ident_ids: initial_ident_ids, idents: IdentStore::new(), aliases: add_aliases(var_store), // TODO(abilities): default abilities in scope @@ -280,12 +282,10 @@ impl Scope { } fn commit_introduction(&mut self, ident: &Ident, region: Region) -> Symbol { - // If this IdentId was already added previously - // when the value was exposed in the module header, - // use that existing IdentId. Otherwise, create a fresh one. - let ident_id = match self.exposed_ident_ids.get_id(ident) { - Some(ident_id) => ident_id, - None => self.ident_ids.add_ident(ident), + // if the identifier is exposed, use the IdentId we already have for it + let ident_id = match self.ident_ids.get_id(ident) { + Some(ident_id) if ident_id.index() < self.exposed_ident_count => ident_id, + _ => self.ident_ids.add_ident(ident), }; let symbol = Symbol::new(self.home, ident_id); @@ -344,14 +344,12 @@ impl Scope { F: FnOnce(&mut Scope) -> T, { let idents = self.idents.clone(); - let exposed_ident_ids = self.exposed_ident_ids.clone(); let aliases = self.aliases.clone(); let abilities_store = self.abilities_store.clone(); let result = f(self); self.idents = idents; - self.exposed_ident_ids = exposed_ident_ids; self.aliases = aliases; self.abilities_store = abilities_store; diff --git a/compiler/collections/src/small_string_interner.rs b/compiler/collections/src/small_string_interner.rs index e34a7b5241..387e6fcd2c 100644 --- a/compiler/collections/src/small_string_interner.rs +++ b/compiler/collections/src/small_string_interner.rs @@ -143,6 +143,14 @@ impl SmallStringInterner { None => None, } } + + pub fn len(&self) -> usize { + self.lengths.len() + } + + pub fn is_empty(&self) -> bool { + self.lengths.is_empty() + } } #[cfg(test)] diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index 6195ec2153..462d44a8e4 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -522,6 +522,12 @@ impl ModuleIds { #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] pub struct IdentId(u32); +impl IdentId { + pub const fn index(self) -> usize { + self.0 as usize + } +} + /// Stores a mapping between Ident and IdentId. #[derive(Clone, Debug, Default, PartialEq, Eq)] pub struct IdentIds { @@ -584,6 +590,14 @@ impl IdentIds { ident_ids_str: format!("{:?}", self), }) } + + pub fn len(&self) -> usize { + self.interner.len() + } + + pub fn is_empty(&self) -> bool { + self.interner.is_empty() + } } #[derive(Debug, Default)] From 83f9c2a3a07bbad208f36266014107b3735d8868 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 28 Apr 2022 16:04:24 -0400 Subject: [PATCH 660/846] Trunk test for 2777 Closes #2777 --- compiler/test_gen/src/gen_tags.rs | 58 +++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/compiler/test_gen/src/gen_tags.rs b/compiler/test_gen/src/gen_tags.rs index 43bcdb05c8..59d0a17542 100644 --- a/compiler/test_gen/src/gen_tags.rs +++ b/compiler/test_gen/src/gen_tags.rs @@ -7,10 +7,9 @@ use crate::helpers::dev::assert_evals_to; #[cfg(feature = "gen-wasm")] use crate::helpers::wasm::assert_evals_to; -// use crate::assert_wasm_evals_to as assert_evals_to; -#[allow(unused_imports)] +#[cfg(test)] use indoc::indoc; -#[allow(unused_imports)] +#[cfg(test)] use roc_std::{RocList, RocStr}; #[test] @@ -1605,3 +1604,56 @@ fn opaque_assign_to_symbol() { u8 ) } + +#[test] +#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] +fn issue_2777_default_branch_codegen() { + assert_evals_to!( + indoc!( + r#" + f1 = \color -> + when color is + Red -> "red" + Yellow -> "yellow" + _ -> "unknown" + + r1 = Red |> f1 |> Str.concat (f1 Orange) + + f2 = \color -> + when color is + Red -> "red" + Yellow -> "yellow" + Green -> "green" + _ -> "unknown" + + r2 = Red |> f2 |> Str.concat (f2 Orange) + + f3 = \color -> + when color is + Red -> "red" + Yellow -> "yellow" + Green -> "green" + _ -> "unknown" + + r3 = Orange |> f3 |> Str.concat (f3 Red) + + f4 = \color -> + when color is + Red -> "red" + Yellow | Gold -> "yellow" + _ -> "unknown" + + r4 = Red |> f4 |> Str.concat (f4 Orange) + + [r1, r2, r3, r4] + "# + ), + RocList::from_slice(&[ + RocStr::from("redunknown"), + RocStr::from("redunknown"), + RocStr::from("unknownred"), + RocStr::from("redunknown"), + ]), + RocList + ) +} From 9429e5081421d079c040253c4a2fcbc42a721f7c Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 28 Apr 2022 16:06:51 -0400 Subject: [PATCH 661/846] Test for 2778 Closes #2778 --- reporting/tests/test_reporting.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index e99f8b730c..898b319680 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -9942,4 +9942,23 @@ I need all branches in an `if` to have the same type! ), ) } + + #[test] + fn issue_2778_specialization_is_not_a_redundant_pattern() { + new_report_problem_as( + "issue_2778_specialization_is_not_a_redundant_pattern", + indoc!( + r#" + formatColor = \color -> + when color is + Red -> "red" + Yellow -> "yellow" + _ -> "unknown" + + Red |> formatColor |> Str.concat (formatColor Orange) + "# + ), + "", // no problem + ) + } } From 3bffdb603712d94202478c205546a0bf533e6892 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 28 Apr 2022 16:12:08 -0400 Subject: [PATCH 662/846] Add test for 2900 Closes #2900 --- compiler/test_gen/src/gen_tags.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/compiler/test_gen/src/gen_tags.rs b/compiler/test_gen/src/gen_tags.rs index 59d0a17542..ba77d1268a 100644 --- a/compiler/test_gen/src/gen_tags.rs +++ b/compiler/test_gen/src/gen_tags.rs @@ -1657,3 +1657,25 @@ fn issue_2777_default_branch_codegen() { RocList ) } + +#[test] +#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] +#[should_panic(expected = "Erroneous")] +fn issue_2900_unreachable_pattern() { + assert_evals_to!( + indoc!( + r#" + foo : [ Foo, Bar, Baz, Blah ] -> Str + foo = \arg -> + when arg is + Foo -> "foo" + AnUnreachableTag -> "blah" + _ -> "other" + + foo Foo + "# + ), + RocStr::from("foo"), + RocStr + ) +} From f17cf9d02b7c6d1293d1369669afdd3837286ae4 Mon Sep 17 00:00:00 2001 From: Folkert Date: Thu, 28 Apr 2022 22:30:27 +0200 Subject: [PATCH 663/846] remove var_store argument --- compiler/can/src/module.rs | 2 +- compiler/can/src/scope.rs | 2 +- compiler/can/tests/helpers/mod.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index 05c43b52ee..c51086a415 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -170,7 +170,7 @@ pub fn canonicalize_module_defs<'a>( var_store: &mut VarStore, ) -> Result { let mut can_exposed_imports = MutMap::default(); - let mut scope = Scope::new(home, var_store, exposed_ident_ids); + let mut scope = Scope::new(home, exposed_ident_ids); let mut env = Env::new(home, dep_idents, module_ids); let num_deps = dep_idents.len(); diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index 0592850e75..6d31390f92 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -70,7 +70,7 @@ fn add_aliases(var_store: &mut VarStore) -> SendMap { } impl Scope { - pub fn new(home: ModuleId, _var_store: &mut VarStore, initial_ident_ids: IdentIds) -> Scope { + pub fn new(home: ModuleId, initial_ident_ids: IdentIds) -> Scope { Scope { home, exposed_ident_count: initial_ident_ids.len(), diff --git a/compiler/can/tests/helpers/mod.rs b/compiler/can/tests/helpers/mod.rs index 7ecaf81c66..23c1b4191b 100644 --- a/compiler/can/tests/helpers/mod.rs +++ b/compiler/can/tests/helpers/mod.rs @@ -55,7 +55,7 @@ pub fn can_expr_with(arena: &Bump, home: ModuleId, expr_str: &str) -> CanExprOut // rules multiple times unnecessarily. let loc_expr = operator::desugar_expr(arena, &loc_expr); - let mut scope = Scope::new(home, &mut var_store, IdentIds::default()); + let mut scope = Scope::new(home, IdentIds::default()); scope.add_alias( Symbol::NUM_INT, Region::zero(), From 6dc07c6ea4134cb6cf4bebb7c073523fa6a2c72b Mon Sep 17 00:00:00 2001 From: Folkert Date: Thu, 28 Apr 2022 23:03:05 +0200 Subject: [PATCH 664/846] add some basic scope tests --- compiler/can/src/scope.rs | 138 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index 6d31390f92..a7be8fa852 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -118,6 +118,11 @@ impl Scope { } } + #[cfg(test)] + fn idents_in_scope(&self) -> impl Iterator + '_ { + self.idents.iter_idents() + } + pub fn lookup_alias(&self, symbol: Symbol) -> Option<&Alias> { self.aliases.get(&symbol) } @@ -500,3 +505,136 @@ impl IdentStore { self.regions.push(region); } } + +#[cfg(test)] +mod test { + use super::*; + use roc_module::symbol::ModuleIds; + use roc_region::all::Position; + + use pretty_assertions::{assert_eq, assert_ne}; + + #[test] + fn scope_contains_introduced() { + let _register_module_debug_names = ModuleIds::default(); + let mut scope = Scope::new(ModuleId::ATTR, IdentIds::default()); + + let region = Region::zero(); + let ident = Ident::from("mezolit"); + + assert!(scope.lookup(&ident, region).is_err()); + + assert!(scope.introduce(ident.clone(), region).is_ok()); + + assert!(scope.lookup(&ident, region).is_ok()); + } + + #[test] + fn second_introduce_shadows() { + let _register_module_debug_names = ModuleIds::default(); + let mut scope = Scope::new(ModuleId::ATTR, IdentIds::default()); + + let region1 = Region::from_pos(Position { offset: 10 }); + let region2 = Region::from_pos(Position { offset: 20 }); + let ident = Ident::from("mezolit"); + + assert!(scope.lookup(&ident, Region::zero()).is_err()); + + let first = scope.introduce(ident.clone(), region1).unwrap(); + let (original_region, _ident, shadow_symbol) = + scope.introduce(ident.clone(), region2).unwrap_err(); + + scope.register_debug_idents(); + + assert_ne!(first, shadow_symbol); + assert_eq!(original_region, region1); + + let lookup = scope.lookup(&ident, Region::zero()).unwrap(); + + assert_eq!(first, lookup); + } + + #[test] + fn inner_scope_does_not_influence_outer() { + let _register_module_debug_names = ModuleIds::default(); + let mut scope = Scope::new(ModuleId::ATTR, IdentIds::default()); + + let region = Region::zero(); + let ident = Ident::from("uránia"); + + assert!(scope.lookup(&ident, region).is_err()); + + scope.inner_scope(|inner| { + assert!(inner.introduce(ident.clone(), region).is_ok()); + }); + + assert!(scope.lookup(&ident, region).is_err()); + } + + #[test] + fn idents_with_inner_scope() { + let _register_module_debug_names = ModuleIds::default(); + let mut scope = Scope::new(ModuleId::ATTR, IdentIds::default()); + + let idents: Vec<_> = scope.idents_in_scope().collect(); + + assert_eq!( + &idents, + &[ + Ident::from("Box"), + Ident::from("Set"), + Ident::from("Dict"), + Ident::from("Str"), + Ident::from("Ok"), + Ident::from("False"), + Ident::from("List"), + Ident::from("True"), + Ident::from("Err"), + ] + ); + + let builtin_count = idents.len(); + + let region = Region::zero(); + + let ident1 = Ident::from("uránia"); + let ident2 = Ident::from("malmok"); + let ident3 = Ident::from("Járnak"); + + scope.introduce(ident1.clone(), region).unwrap(); + scope.introduce(ident2.clone(), region).unwrap(); + scope.introduce(ident3.clone(), region).unwrap(); + + let idents: Vec<_> = scope.idents_in_scope().collect(); + + assert_eq!( + &idents[builtin_count..], + &[ident1.clone(), ident2.clone(), ident3.clone(),] + ); + + scope.inner_scope(|inner| { + let ident4 = Ident::from("Ångström"); + let ident5 = Ident::from("Sirály"); + + inner.introduce(ident4.clone(), region).unwrap(); + inner.introduce(ident5.clone(), region).unwrap(); + + let idents: Vec<_> = inner.idents_in_scope().collect(); + + assert_eq!( + &idents[builtin_count..], + &[ + ident1.clone(), + ident2.clone(), + ident3.clone(), + ident4, + ident5 + ] + ); + }); + + let idents: Vec<_> = scope.idents_in_scope().collect(); + + assert_eq!(&idents[builtin_count..], &[ident1, ident2, ident3,]); + } +} From 99340e314c414a734f3ddd44fd968cfaa4e6379f Mon Sep 17 00:00:00 2001 From: Folkert Date: Thu, 28 Apr 2022 23:27:46 +0200 Subject: [PATCH 665/846] remove clone of scope.ident_ids --- compiler/can/src/module.rs | 4 ---- compiler/load_internal/src/docs.rs | 3 +-- compiler/load_internal/src/file.rs | 3 +-- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index c51086a415..b7a67a2d31 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -47,7 +47,6 @@ pub struct ModuleOutput { pub exposed_imports: MutMap, pub lookups: Vec<(Symbol, Variable, Region)>, pub problems: Vec, - pub ident_ids: IdentIds, pub referenced_values: VecSet, pub referenced_types: VecSet, pub scope: Scope, @@ -533,8 +532,6 @@ pub fn canonicalize_module_defs<'a>( } } - let ident_ids = scope.ident_ids.clone(); - let output = ModuleOutput { scope, aliases, @@ -545,7 +542,6 @@ pub fn canonicalize_module_defs<'a>( exposed_imports: can_exposed_imports, problems: env.problems, lookups, - ident_ids, }; Ok(output) diff --git a/compiler/load_internal/src/docs.rs b/compiler/load_internal/src/docs.rs index de45d9f0c0..890ddb46b0 100644 --- a/compiler/load_internal/src/docs.rs +++ b/compiler/load_internal/src/docs.rs @@ -89,14 +89,13 @@ pub struct Tag { pub fn generate_module_docs<'a>( scope: Scope, module_name: ModuleName, - ident_ids: &'a IdentIds, parsed_defs: &'a [Loc>], ) -> ModuleDocumentation { let (entries, _) = parsed_defs .iter() .fold((vec![], None), |(acc, maybe_comments_after), def| { - generate_entry_doc(ident_ids, acc, maybe_comments_after, &def.value) + generate_entry_doc(&scope.ident_ids, acc, maybe_comments_after, &def.value) }); ModuleDocumentation { diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index 633da66ad6..0b88a8d282 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -3844,7 +3844,6 @@ fn canonicalize_and_constrain<'a>( let docs = crate::docs::generate_module_docs( module_output.scope.clone(), name.as_str().into(), - &module_output.ident_ids, parsed_defs, ); @@ -3915,7 +3914,7 @@ fn canonicalize_and_constrain<'a>( var_store, constraints, constraint, - ident_ids: module_output.ident_ids, + ident_ids: module_output.scope.ident_ids, dep_idents, module_timing, }; From e243402f9b3e26d998bdc233e58da55a072c5b2c Mon Sep 17 00:00:00 2001 From: Folkert Date: Thu, 28 Apr 2022 23:28:14 +0200 Subject: [PATCH 666/846] rename --- compiler/can/src/expr.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index 515fb90930..b5979ca622 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -955,7 +955,7 @@ pub fn canonicalize_closure<'a>( opt_def_name: Option, ) -> (ClosureData, Output) { scope.inner_scope(|inner_scope| { - canonicalize_closure_inner_scope( + canonicalize_closure_body( env, var_store, inner_scope, @@ -966,7 +966,7 @@ pub fn canonicalize_closure<'a>( }) } -fn canonicalize_closure_inner_scope<'a>( +fn canonicalize_closure_body<'a>( env: &mut Env<'a>, var_store: &mut VarStore, scope: &mut Scope, From 42d74199e5494445a837bf80a9718b28feed48db Mon Sep 17 00:00:00 2001 From: Folkert Date: Thu, 28 Apr 2022 23:43:24 +0200 Subject: [PATCH 667/846] limit cost of inner_scope --- compiler/can/src/scope.rs | 24 ++++++++++++++---------- compiler/collections/src/vec_map.rs | 5 +++++ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index a7be8fa852..45d60400f8 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -1,5 +1,4 @@ -use roc_collections::all::{MutSet, SendMap}; -use roc_collections::SmallStringInterner; +use roc_collections::{MutSet, SmallStringInterner, VecMap}; use roc_module::ident::{Ident, Lowercase}; use roc_module::symbol::{IdentIds, ModuleId, Symbol}; use roc_problem::can::RuntimeError; @@ -14,7 +13,7 @@ pub struct Scope { idents: IdentStore, /// The type aliases currently in scope - pub aliases: SendMap, + pub aliases: VecMap, /// The abilities currently in scope, and their implementors. pub abilities_store: AbilitiesStore, @@ -29,11 +28,11 @@ pub struct Scope { exposed_ident_count: usize, } -fn add_aliases(var_store: &mut VarStore) -> SendMap { +fn add_aliases(var_store: &mut VarStore) -> VecMap { use roc_types::solved_types::{BuiltinAlias, FreeVars}; let solved_aliases = roc_types::builtin_aliases::aliases(); - let mut aliases = SendMap::default(); + let mut aliases = VecMap::default(); for (symbol, builtin_alias) in solved_aliases { let BuiltinAlias { @@ -76,7 +75,7 @@ impl Scope { exposed_ident_count: initial_ident_ids.len(), ident_ids: initial_ident_ids, idents: IdentStore::new(), - aliases: SendMap::default(), + aliases: VecMap::default(), // TODO(abilities): default abilities in scope abilities_store: AbilitiesStore::default(), } @@ -348,15 +347,20 @@ impl Scope { where F: FnOnce(&mut Scope) -> T, { + // store enough information to roll back to the original outer scope + // + // - abilities_store: abilitie definitions not allowed in inner scopes + // - ident_ids: identifiers in inner scopes should still be available in the ident_ids + // - idents: we have to clone for now + // - aliases: stored in a VecMap, we just discard anything added in an inner scope + // - exposed_ident_count: unchanged let idents = self.idents.clone(); - let aliases = self.aliases.clone(); - let abilities_store = self.abilities_store.clone(); + let aliases_count = self.aliases.len(); let result = f(self); self.idents = idents; - self.aliases = aliases; - self.abilities_store = abilities_store; + self.aliases.truncate(aliases_count); result } diff --git a/compiler/collections/src/vec_map.rs b/compiler/collections/src/vec_map.rs index 3471edfa36..e4cb42011d 100644 --- a/compiler/collections/src/vec_map.rs +++ b/compiler/collections/src/vec_map.rs @@ -109,6 +109,11 @@ impl VecMap { self.values.iter() } + pub fn truncate(&mut self, len: usize) { + self.keys.truncate(len); + self.values.truncate(len); + } + pub fn unzip(self) -> (Vec, Vec) { (self.keys, self.values) } From 3b64fe59b5e324c1eafb30eb8b95a0efc784ee80 Mon Sep 17 00:00:00 2001 From: Ayaz <20735482+ayazhafiz@users.noreply.github.com> Date: Thu, 28 Apr 2022 20:14:39 -0400 Subject: [PATCH 668/846] Update compiler/can/src/scope.rs --- compiler/can/src/scope.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index 45d60400f8..a99c158cc7 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -349,7 +349,7 @@ impl Scope { { // store enough information to roll back to the original outer scope // - // - abilities_store: abilitie definitions not allowed in inner scopes + // - abilities_store: ability definitions not allowed in inner scopes // - ident_ids: identifiers in inner scopes should still be available in the ident_ids // - idents: we have to clone for now // - aliases: stored in a VecMap, we just discard anything added in an inner scope From 98869b557dc4ca12191edd9f60274b225ae55913 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 27 Apr 2022 18:04:41 -0400 Subject: [PATCH 669/846] Exhaustive and redundant marks --- compiler/can/src/builtins.rs | 8 +++++++- compiler/can/src/constraint.rs | 20 +++++++++++++++----- compiler/can/src/effect_module.rs | 3 ++- compiler/can/src/exhaustive.rs | 8 +++++++- compiler/can/src/expr.rs | 13 +++++++++++-- compiler/can/src/traverse.rs | 1 + compiler/constrain/src/expr.rs | 17 ++++++++++++++--- compiler/solve/src/solve.rs | 19 ++++++++++++++++--- compiler/types/src/subs.rs | 20 +++++++++++++++++++- 9 files changed, 92 insertions(+), 17 deletions(-) diff --git a/compiler/can/src/builtins.rs b/compiler/can/src/builtins.rs index 72847c71b1..c7b344e5f3 100644 --- a/compiler/can/src/builtins.rs +++ b/compiler/can/src/builtins.rs @@ -9,7 +9,7 @@ use roc_module::ident::{Lowercase, TagName}; use roc_module::low_level::LowLevel; use roc_module::symbol::Symbol; use roc_region::all::{Loc, Region}; -use roc_types::subs::{VarStore, Variable}; +use roc_types::subs::{ExhaustiveMark, VarStore, Variable}; macro_rules! macro_magic { (@single $($x:tt)*) => (()); @@ -4728,6 +4728,7 @@ fn result_map(symbol: Symbol, var_store: &mut VarStore) -> Def { loc_cond: Box::new(no_region(Var(Symbol::ARG_1))), branches, branches_cond_var: var_store.fresh(), + exhaustive: ExhaustiveMark(var_store.fresh()), }; defn( @@ -4826,6 +4827,7 @@ fn result_map_err(symbol: Symbol, var_store: &mut VarStore) -> Def { loc_cond: Box::new(no_region(Var(Symbol::ARG_1))), branches, branches_cond_var: var_store.fresh(), + exhaustive: ExhaustiveMark(var_store.fresh()), }; defn( @@ -4890,6 +4892,7 @@ fn result_with_default(symbol: Symbol, var_store: &mut VarStore) -> Def { loc_cond: Box::new(no_region(Var(Symbol::ARG_1))), branches, branches_cond_var: var_store.fresh(), + exhaustive: ExhaustiveMark(var_store.fresh()), }; defn( @@ -4968,6 +4971,7 @@ fn result_is_err(symbol: Symbol, var_store: &mut VarStore) -> Def { loc_cond: Box::new(no_region(Var(Symbol::ARG_1))), branches, branches_cond_var: var_store.fresh(), + exhaustive: ExhaustiveMark(var_store.fresh()), }; defn( @@ -5046,6 +5050,7 @@ fn result_is_ok(symbol: Symbol, var_store: &mut VarStore) -> Def { loc_cond: Box::new(no_region(Var(Symbol::ARG_1))), branches, branches_cond_var: var_store.fresh(), + exhaustive: ExhaustiveMark(var_store.fresh()), }; defn( @@ -5139,6 +5144,7 @@ fn result_after(symbol: Symbol, var_store: &mut VarStore) -> Def { loc_cond: Box::new(no_region(Var(Symbol::ARG_1))), branches, branches_cond_var: var_store.fresh(), + exhaustive: ExhaustiveMark(var_store.fresh()), }; defn( diff --git a/compiler/can/src/constraint.rs b/compiler/can/src/constraint.rs index 7ef3cceaaf..36347185cb 100644 --- a/compiler/can/src/constraint.rs +++ b/compiler/can/src/constraint.rs @@ -4,7 +4,7 @@ use roc_collections::soa::{EitherIndex, Index, Slice}; use roc_module::ident::TagName; use roc_module::symbol::{ModuleId, Symbol}; use roc_region::all::{Loc, Region}; -use roc_types::subs::Variable; +use roc_types::subs::{ExhaustiveMark, Variable}; use roc_types::types::{Category, PatternCategory, Type}; #[derive(Debug)] @@ -614,6 +614,7 @@ impl Constraints { expected_branches: Expected, sketched_rows: SketchedRows, context: ExhaustiveContext, + exhaustive: ExhaustiveMark, ) -> Constraint { let real_var = Self::push_type_variable(real_var); let real_category = Index::push_new(&mut self.categories, real_category); @@ -622,7 +623,7 @@ impl Constraints { let equality = Index::push_new(&mut self.eq, equality); let sketched_rows = Index::push_new(&mut self.sketched_rows, sketched_rows); - Constraint::Exhaustive(equality, sketched_rows, context) + Constraint::Exhaustive(equality, sketched_rows, context, exhaustive) } } @@ -672,7 +673,12 @@ pub enum Constraint { Index, Region, ), - Exhaustive(Index, Index, ExhaustiveContext), + Exhaustive( + Index, + Index, + ExhaustiveContext, + ExhaustiveMark, + ), } #[derive(Debug, Clone, Copy, Default)] @@ -727,8 +733,12 @@ impl std::fmt::Debug for Constraint { arg0, arg1, arg2, arg3 ) } - Self::Exhaustive(arg0, arg1, arg2) => { - write!(f, "Exhaustive({:?}, {:?}, {:?})", arg0, arg1, arg2) + Self::Exhaustive(arg0, arg1, arg2, arg3) => { + write!( + f, + "Exhaustive({:?}, {:?}, {:?}, {:?})", + arg0, arg1, arg2, arg3 + ) } } } diff --git a/compiler/can/src/effect_module.rs b/compiler/can/src/effect_module.rs index 96350ad283..404869884f 100644 --- a/compiler/can/src/effect_module.rs +++ b/compiler/can/src/effect_module.rs @@ -8,7 +8,7 @@ use roc_module::called_via::CalledVia; use roc_module::ident::{Lowercase, TagName}; use roc_module::symbol::Symbol; use roc_region::all::{Loc, Region}; -use roc_types::subs::{VarStore, Variable}; +use roc_types::subs::{ExhaustiveMark, VarStore, Variable}; use roc_types::types::{AliasKind, LambdaSet, Type, TypeExtension}; #[derive(Debug, Default, Clone, Copy)] @@ -1232,6 +1232,7 @@ fn build_effect_loop_inner_body( loc_cond: Box::new(force_thunk_call), branches, branches_cond_var: var_store.fresh(), + exhaustive: ExhaustiveMark(var_store.fresh()), }; Expr::LetNonRec( diff --git a/compiler/can/src/exhaustive.rs b/compiler/can/src/exhaustive.rs index 40d80df0df..b489a3773c 100644 --- a/compiler/can/src/exhaustive.rs +++ b/compiler/can/src/exhaustive.rs @@ -7,7 +7,7 @@ use roc_exhaustive::{ }; use roc_module::ident::{TagIdIntType, TagName}; use roc_region::all::{Loc, Region}; -use roc_types::subs::{Content, FlatType, Subs, SubsFmtContent, Variable}; +use roc_types::subs::{Content, FlatType, RedundantMark, Subs, SubsFmtContent, Variable}; use roc_types::types::AliasKind; pub use roc_exhaustive::Context as ExhaustiveContext; @@ -15,6 +15,12 @@ pub use roc_exhaustive::Context as ExhaustiveContext; pub const GUARD_CTOR: &str = "#Guard"; pub const NONEXHAUSIVE_CTOR: &str = "#Open"; +pub struct ErrorSummary { + errors: Vec, + exhaustive: bool, + redundant: Vec, +} + pub fn check( subs: &Subs, sketched_rows: SketchedRows, diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index 515fb90930..014edbcd7e 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -18,7 +18,7 @@ use roc_parse::ast::{self, EscapedChar, StrLiteral}; use roc_parse::pattern::PatternType::*; use roc_problem::can::{PrecedenceProblem, Problem, RuntimeError}; use roc_region::all::{Loc, Region}; -use roc_types::subs::{VarStore, Variable}; +use roc_types::subs::{ExhaustiveMark, VarStore, Variable}; use roc_types::types::{Alias, Category, LambdaSet, Type}; use std::fmt::{Debug, Display}; use std::{char, u32}; @@ -84,12 +84,18 @@ pub enum Expr { Var(Symbol), // Branching When { + /// The actual condition of the when expression. + loc_cond: Box>, cond_var: Variable, + /// Result type produced by the branches. expr_var: Variable, region: Region, - loc_cond: Box>, + /// The branches of the when, and the type of the condition that they expect to be matched + /// against. branches: Vec, branches_cond_var: Variable, + /// Whether the branches are exhaustive. + exhaustive: ExhaustiveMark, }, If { cond_var: Variable, @@ -711,6 +717,7 @@ pub fn canonicalize_expr<'a>( loc_cond: Box::new(can_cond), branches: can_branches, branches_cond_var: var_store.fresh(), + exhaustive: ExhaustiveMark(var_store.fresh()), }; (expr, output) @@ -1342,6 +1349,7 @@ pub fn inline_calls(var_store: &mut VarStore, scope: &mut Scope, expr: Expr) -> loc_cond, branches, branches_cond_var, + exhaustive, } => { let loc_cond = Box::new(Loc { region: loc_cond.region, @@ -1378,6 +1386,7 @@ pub fn inline_calls(var_store: &mut VarStore, scope: &mut Scope, expr: Expr) -> loc_cond, branches: new_branches, branches_cond_var, + exhaustive, } } If { diff --git a/compiler/can/src/traverse.rs b/compiler/can/src/traverse.rs index d45f7f3a87..8f01008806 100644 --- a/compiler/can/src/traverse.rs +++ b/compiler/can/src/traverse.rs @@ -66,6 +66,7 @@ fn walk_expr(visitor: &mut V, expr: &Expr) { branches, region: _, branches_cond_var: _, + exhaustive: _, } => { walk_when(visitor, *cond_var, *expr_var, loc_cond, branches); } diff --git a/compiler/constrain/src/expr.rs b/compiler/constrain/src/expr.rs index a7bb659b4d..6155417dab 100644 --- a/compiler/constrain/src/expr.rs +++ b/compiler/constrain/src/expr.rs @@ -15,7 +15,7 @@ use roc_collections::all::{HumanIndex, MutMap, SendMap}; use roc_module::ident::{Lowercase, TagName}; use roc_module::symbol::{ModuleId, Symbol}; use roc_region::all::{Loc, Region}; -use roc_types::subs::Variable; +use roc_types::subs::{ExhaustiveMark, Variable}; use roc_types::types::Type::{self, *}; use roc_types::types::{ AliasKind, AnnotationSource, Category, PReason, Reason, RecordField, TypeExtension, @@ -585,6 +585,7 @@ pub fn constrain_expr( loc_cond, branches, branches_cond_var, + exhaustive, .. } => { let branches_cond_var = *branches_cond_var; @@ -650,7 +651,7 @@ pub fn constrain_expr( // constraints. let mut pattern_vars = Vec::with_capacity(branches.len()); let mut pattern_headers = SendMap::default(); - let mut pattern_cons = Vec::with_capacity(branches.len() + 1); + let mut pattern_cons = Vec::with_capacity(branches.len() + 2); let mut branch_cons = Vec::with_capacity(branches.len()); for (index, when_branch) in branches.iter().enumerate() { @@ -718,6 +719,15 @@ pub fn constrain_expr( ); pattern_cons.push(cond_constraint); + // Mark the `when` as exhaustive initially. We'll refine this if the condition + // disagrees. + pattern_cons.push(constraints.store( + ExhaustiveMark::EXHAUSTIVE_TYPE, + exhaustive.0, + file!(), + line!(), + )); + // Now check the condition against the type expected by the branches. let sketched_rows = sketch_rows(real_cond_var, branches_region, branches); let cond_matches_branches_constraint = constraints.exhaustive( @@ -727,6 +737,7 @@ pub fn constrain_expr( Expected::ForReason(Reason::WhenBranches, branches_cond_type, branches_region), sketched_rows, ExhaustiveContext::BadCase, + *exhaustive, ); pattern_cons.push(cond_matches_branches_constraint); @@ -749,7 +760,7 @@ pub fn constrain_expr( let branch_constraints = constraints.and_constraint(total_cons); constraints.exists( - [branches_cond_var, real_cond_var, *expr_var], + [exhaustive.0, branches_cond_var, real_cond_var, *expr_var], branch_constraints, ) } diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index 7223bdce72..522cf974d2 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -11,8 +11,8 @@ use roc_module::symbol::Symbol; use roc_region::all::{Loc, Region}; use roc_types::solved_types::Solved; use roc_types::subs::{ - AliasVariables, Content, Descriptor, FlatType, Mark, OptVariable, Rank, RecordFields, Subs, - SubsIndex, SubsSlice, UnionTags, Variable, VariableSubsSlice, + AliasVariables, Content, Descriptor, ExhaustiveMark, FlatType, Mark, OptVariable, Rank, + RecordFields, Subs, SubsIndex, SubsSlice, UnionTags, Variable, VariableSubsSlice, }; use roc_types::types::Type::{self, *}; use roc_types::types::{ @@ -1172,7 +1172,7 @@ fn solve( } } } - &Exhaustive(eq, sketched_rows, context) => { + &Exhaustive(eq, sketched_rows, context, exhaustive_mark) => { // A few cases: // 1. Either condition or branch types already have a type error. In this case just // propagate it. @@ -1286,8 +1286,21 @@ fn solve( let sketched_rows = constraints.sketched_rows[sketched_rows.index()].clone(); if should_check_exhaustiveness { + use roc_can::exhaustive::check; + use roc_exhaustive::Error; + let checked = roc_can::exhaustive::check(subs, sketched_rows, context); if let Err(errors) = checked { + for error in errors.iter() { + match error { + Error::Incomplete(..) => subs + .set_content(exhaustive_mark.0, ExhaustiveMark::NON_EXHAUSTIVE), + Error::Redundant { index, .. } => { + // + } + } + } + problems.extend(errors.into_iter().map(TypeError::Exhaustive)); } } diff --git a/compiler/types/src/subs.rs b/compiler/types/src/subs.rs index 6ffc2945ca..dac17353ca 100644 --- a/compiler/types/src/subs.rs +++ b/compiler/types/src/subs.rs @@ -1,6 +1,6 @@ #![deny(unsafe_op_in_unsafe_fn)] use crate::types::{ - name_type_var, AliasKind, ErrorType, Problem, RecordField, RecordFieldsError, TypeExt, + name_type_var, AliasKind, ErrorType, Problem, RecordField, RecordFieldsError, Type, TypeExt, }; use roc_collections::all::{ImMap, ImSet, MutSet, SendMap}; use roc_error_macros::internal_error; @@ -965,6 +965,24 @@ impl From for Option { } } +/// Marks whether a when expression is exhaustive using a variable. +#[derive(Clone, Copy, Debug)] +pub struct ExhaustiveMark(pub Variable); + +impl ExhaustiveMark { + pub const EXHAUSTIVE_TYPE: Type = Type::EmptyTagUnion; + pub const EXHAUSTIVE: Content = Content::Structure(FlatType::EmptyTagUnion); + pub const NON_EXHAUSTIVE: Content = Content::Error; +} + +/// Marks whether a when branch is redundant using a variable. +pub struct RedundantMark(Variable); + +impl RedundantMark { + pub const REDUNDANT: Content = Content::Structure(FlatType::EmptyTagUnion); + pub const NON_REDUNDANT: Content = Content::Error; +} + #[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct Variable(u32); From 2f1306afd12f010f0a67a28c4dd7e9025e41e066 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 28 Apr 2022 09:57:08 -0400 Subject: [PATCH 670/846] Redundant and exhaustive marks in mono --- compiler/can/src/builtins.rs | 14 +++++- compiler/can/src/effect_module.rs | 4 +- compiler/can/src/exhaustive.rs | 63 +++++++++++++++++++------ compiler/can/src/expr.rs | 6 ++- compiler/can/src/traverse.rs | 1 + compiler/constrain/src/expr.rs | 15 ++++-- compiler/mono/src/ir.rs | 77 ++++++++++++------------------- compiler/solve/src/solve.rs | 34 ++++++++------ compiler/types/src/subs.rs | 19 ++++++-- compiler/types/src/types.rs | 5 +- 10 files changed, 152 insertions(+), 86 deletions(-) diff --git a/compiler/can/src/builtins.rs b/compiler/can/src/builtins.rs index c7b344e5f3..4cbbfa956a 100644 --- a/compiler/can/src/builtins.rs +++ b/compiler/can/src/builtins.rs @@ -9,7 +9,7 @@ use roc_module::ident::{Lowercase, TagName}; use roc_module::low_level::LowLevel; use roc_module::symbol::Symbol; use roc_region::all::{Loc, Region}; -use roc_types::subs::{ExhaustiveMark, VarStore, Variable}; +use roc_types::subs::{ExhaustiveMark, RedundantMark, VarStore, Variable}; macro_rules! macro_magic { (@single $($x:tt)*) => (()); @@ -4686,6 +4686,7 @@ fn result_map(symbol: Symbol, var_store: &mut VarStore) -> Def { patterns: vec![no_region(pattern)], value: no_region(ok), guard: None, + redundant: RedundantMark(var_store.fresh()), }; branches.push(branch); @@ -4716,6 +4717,7 @@ fn result_map(symbol: Symbol, var_store: &mut VarStore) -> Def { patterns: vec![no_region(pattern)], value: no_region(err), guard: None, + redundant: RedundantMark(var_store.fresh()), }; branches.push(branch); @@ -4785,6 +4787,7 @@ fn result_map_err(symbol: Symbol, var_store: &mut VarStore) -> Def { patterns: vec![no_region(pattern)], value: no_region(ok), guard: None, + redundant: RedundantMark(var_store.fresh()), }; branches.push(branch); @@ -4815,6 +4818,7 @@ fn result_map_err(symbol: Symbol, var_store: &mut VarStore) -> Def { patterns: vec![no_region(pattern)], value: no_region(err), guard: None, + redundant: RedundantMark(var_store.fresh()), }; branches.push(branch); @@ -4860,6 +4864,7 @@ fn result_with_default(symbol: Symbol, var_store: &mut VarStore) -> Def { patterns: vec![no_region(pattern)], value: no_region(Var(Symbol::ARG_3)), guard: None, + redundant: RedundantMark(var_store.fresh()), }; branches.push(branch); @@ -4880,6 +4885,7 @@ fn result_with_default(symbol: Symbol, var_store: &mut VarStore) -> Def { patterns: vec![no_region(pattern)], value: no_region(Var(Symbol::ARG_2)), guard: None, + redundant: RedundantMark(var_store.fresh()), }; branches.push(branch); @@ -4932,6 +4938,7 @@ fn result_is_err(symbol: Symbol, var_store: &mut VarStore) -> Def { patterns: vec![no_region(pattern)], value: no_region(false_expr), guard: None, + redundant: RedundantMark(var_store.fresh()), }; branches.push(branch); @@ -4959,6 +4966,7 @@ fn result_is_err(symbol: Symbol, var_store: &mut VarStore) -> Def { patterns: vec![no_region(pattern)], value: no_region(true_expr), guard: None, + redundant: RedundantMark(var_store.fresh()), }; branches.push(branch); @@ -5011,6 +5019,7 @@ fn result_is_ok(symbol: Symbol, var_store: &mut VarStore) -> Def { patterns: vec![no_region(pattern)], value: no_region(true_expr), guard: None, + redundant: RedundantMark(var_store.fresh()), }; branches.push(branch); @@ -5038,6 +5047,7 @@ fn result_is_ok(symbol: Symbol, var_store: &mut VarStore) -> Def { patterns: vec![no_region(pattern)], value: no_region(false_expr), guard: None, + redundant: RedundantMark(var_store.fresh()), }; branches.push(branch); @@ -5102,6 +5112,7 @@ fn result_after(symbol: Symbol, var_store: &mut VarStore) -> Def { patterns: vec![no_region(pattern)], value: no_region(ok), guard: None, + redundant: RedundantMark(var_store.fresh()), }; branches.push(branch); @@ -5132,6 +5143,7 @@ fn result_after(symbol: Symbol, var_store: &mut VarStore) -> Def { patterns: vec![no_region(pattern)], value: no_region(err), guard: None, + redundant: RedundantMark(var_store.fresh()), }; branches.push(branch); diff --git a/compiler/can/src/effect_module.rs b/compiler/can/src/effect_module.rs index 404869884f..0b1d19c68d 100644 --- a/compiler/can/src/effect_module.rs +++ b/compiler/can/src/effect_module.rs @@ -8,7 +8,7 @@ use roc_module::called_via::CalledVia; use roc_module::ident::{Lowercase, TagName}; use roc_module::symbol::Symbol; use roc_region::all::{Loc, Region}; -use roc_types::subs::{ExhaustiveMark, VarStore, Variable}; +use roc_types::subs::{ExhaustiveMark, RedundantMark, VarStore, Variable}; use roc_types::types::{AliasKind, LambdaSet, Type, TypeExtension}; #[derive(Debug, Default, Clone, Copy)] @@ -1209,6 +1209,7 @@ fn build_effect_loop_inner_body( patterns: vec![Loc::at_zero(step_pattern)], value: Loc::at_zero(force_thunk2), guard: None, + redundant: RedundantMark(var_store.fresh()), } }; @@ -1220,6 +1221,7 @@ fn build_effect_loop_inner_body( patterns: vec![Loc::at_zero(done_pattern)], value: Loc::at_zero(Expr::Var(done_symbol)), guard: None, + redundant: RedundantMark(var_store.fresh()), } }; diff --git a/compiler/can/src/exhaustive.rs b/compiler/can/src/exhaustive.rs index b489a3773c..1d4d7d248a 100644 --- a/compiler/can/src/exhaustive.rs +++ b/compiler/can/src/exhaustive.rs @@ -15,23 +15,40 @@ pub use roc_exhaustive::Context as ExhaustiveContext; pub const GUARD_CTOR: &str = "#Guard"; pub const NONEXHAUSIVE_CTOR: &str = "#Open"; -pub struct ErrorSummary { - errors: Vec, - exhaustive: bool, - redundant: Vec, +pub struct ExhaustiveSummary { + pub errors: Vec, + pub exhaustive: bool, + pub redundancies: Vec, } pub fn check( subs: &Subs, sketched_rows: SketchedRows, context: ExhaustiveContext, -) -> Result<(), Vec> { +) -> ExhaustiveSummary { let overall_region = sketched_rows.overall_region; - // TODO: can we keep going even if we had redundant rows? - let matrix = sketched_rows - .reify_to_non_redundant(subs) - .map_err(|e| vec![e])?; - roc_exhaustive::check(overall_region, context, matrix) + let mut all_errors = Vec::with_capacity(1); + + let NonRedundantSummary { + non_redundant_rows, + errors, + redundancies, + } = sketched_rows.reify_to_non_redundant(subs); + all_errors.extend(errors); + + let exhaustive = match roc_exhaustive::check(overall_region, context, non_redundant_rows) { + Ok(()) => true, + Err(errors) => { + all_errors.extend(errors); + false + } + }; + + ExhaustiveSummary { + errors: all_errors, + exhaustive, + redundancies, + } } #[derive(Clone, Debug, PartialEq, Eq)] @@ -69,6 +86,7 @@ struct SketchedRow { patterns: Vec, region: Region, guard: Guard, + redundant_mark: RedundantMark, } #[derive(Clone, Debug, PartialEq, Eq)] @@ -78,7 +96,7 @@ pub struct SketchedRows { } impl SketchedRows { - pub fn reify_to_non_redundant(self, subs: &Subs) -> Result>, Error> { + fn reify_to_non_redundant(self, subs: &Subs) -> NonRedundantSummary { to_nonredundant_rows(subs, self) } } @@ -203,6 +221,7 @@ pub fn sketch_rows(target_var: Variable, region: Region, patterns: &[WhenBranch] patterns, guard, value: _, + redundant, } in patterns { let guard = if guard.is_some() { @@ -248,6 +267,7 @@ pub fn sketch_rows(target_var: Variable, region: Region, patterns: &[WhenBranch] patterns, region: loc_pat.region, guard, + redundant_mark: *redundant, }; rows.push(row); } @@ -261,18 +281,28 @@ pub fn sketch_rows(target_var: Variable, region: Region, patterns: &[WhenBranch] /// REDUNDANT PATTERNS +struct NonRedundantSummary { + non_redundant_rows: Vec>, + redundancies: Vec, + errors: Vec, +} + /// INVARIANT: Produces a list of rows where (forall row. length row == 1) -fn to_nonredundant_rows(subs: &Subs, rows: SketchedRows) -> Result>, Error> { +fn to_nonredundant_rows(subs: &Subs, rows: SketchedRows) -> NonRedundantSummary { let SketchedRows { rows, overall_region, } = rows; let mut checked_rows = Vec::with_capacity(rows.len()); + let mut redundancies = vec![]; + let mut errors = vec![]; + for SketchedRow { patterns, guard, region, + redundant_mark, } in rows.into_iter() { let next_row: Vec = patterns @@ -283,7 +313,8 @@ fn to_nonredundant_rows(subs: &Subs, rows: SketchedRows) -> Result Result (Union, TagId) { diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index 014edbcd7e..6ef8fed006 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -18,7 +18,7 @@ use roc_parse::ast::{self, EscapedChar, StrLiteral}; use roc_parse::pattern::PatternType::*; use roc_problem::can::{PrecedenceProblem, Problem, RuntimeError}; use roc_region::all::{Loc, Region}; -use roc_types::subs::{ExhaustiveMark, VarStore, Variable}; +use roc_types::subs::{ExhaustiveMark, RedundantMark, VarStore, Variable}; use roc_types::types::{Alias, Category, LambdaSet, Type}; use std::fmt::{Debug, Display}; use std::{char, u32}; @@ -338,6 +338,8 @@ pub struct WhenBranch { pub patterns: Vec>, pub value: Loc, pub guard: Option>, + /// Whether this branch is redundant in the `when` it appears in + pub redundant: RedundantMark, } impl WhenBranch { @@ -1137,6 +1139,7 @@ fn canonicalize_when_branch<'a>( patterns, value, guard, + redundant: RedundantMark(var_store.fresh()), }, references, ) @@ -1374,6 +1377,7 @@ pub fn inline_calls(var_store: &mut VarStore, scope: &mut Scope, expr: Expr) -> patterns: branch.patterns, value, guard, + redundant: RedundantMark(var_store.fresh()), }; new_branches.push(new_branch); diff --git a/compiler/can/src/traverse.rs b/compiler/can/src/traverse.rs index 8f01008806..b25d2d7928 100644 --- a/compiler/can/src/traverse.rs +++ b/compiler/can/src/traverse.rs @@ -108,6 +108,7 @@ fn walk_when_branch(visitor: &mut V, branch: &WhenBranch, expr_var: patterns, value, guard, + redundant: _, } = branch; patterns diff --git a/compiler/constrain/src/expr.rs b/compiler/constrain/src/expr.rs index 6155417dab..89a67bef97 100644 --- a/compiler/constrain/src/expr.rs +++ b/compiler/constrain/src/expr.rs @@ -15,7 +15,7 @@ use roc_collections::all::{HumanIndex, MutMap, SendMap}; use roc_module::ident::{Lowercase, TagName}; use roc_module::symbol::{ModuleId, Symbol}; use roc_region::all::{Loc, Region}; -use roc_types::subs::{ExhaustiveMark, Variable}; +use roc_types::subs::{ExhaustiveMark, RedundantMark, Variable}; use roc_types::types::Type::{self, *}; use roc_types::types::{ AliasKind, AnnotationSource, Category, PReason, Reason, RecordField, TypeExtension, @@ -1177,11 +1177,20 @@ fn constrain_when_branch_help( let mut state = PatternState { headers: SendMap::default(), - vars: Vec::with_capacity(1), - constraints: Vec::with_capacity(1), + vars: Vec::with_capacity(2), + constraints: Vec::with_capacity(2), delayed_is_open_constraints: Vec::new(), }; + // Mark the branch as non-redundant initially. We'll refine this during solving. + state.vars.push(when_branch.redundant.0); + state.constraints.push(constraints.store( + RedundantMark::NON_REDUNDANT_TYPE, + when_branch.redundant.0, + file!(), + line!(), + )); + // TODO investigate for error messages, is it better to unify all branches with a variable, // then unify that variable with the expectation? for (i, loc_pattern) in when_branch.patterns.iter().enumerate() { diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 76dec0f554..74d9af2caf 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -18,7 +18,10 @@ use roc_problem::can::{RuntimeError, ShadowKind}; use roc_region::all::{Loc, Region}; use roc_std::RocDec; use roc_target::TargetInfo; -use roc_types::subs::{Content, FlatType, StorageSubs, Subs, Variable, VariableSubsSlice}; +use roc_types::subs::{ + Content, ExhaustiveMark, FlatType, RedundantMark, StorageSubs, Subs, Variable, + VariableSubsSlice, +}; use std::collections::HashMap; use ven_pretty::{BoxAllocator, DocAllocator, DocBuilder}; @@ -2090,8 +2093,12 @@ fn pattern_to_when<'a>( patterns: vec![pattern], value: body, guard: None, + // TODO(exhaustive): should come from real var! + redundant: RedundantMark(Variable::EMPTY_TAG_UNION), }], branches_cond_var: pattern_var, + // TODO(exhaustive): should come from real var! + exhaustive: ExhaustiveMark(Variable::EMPTY_TAG_UNION), }; (symbol, Loc::at_zero(wrapped_body)) @@ -3751,10 +3758,11 @@ pub fn with_hole<'a>( When { cond_var, expr_var, - region, + region: _, loc_cond, branches, branches_cond_var: _, + exhaustive, } => { let cond_symbol = possible_reuse_symbol(env, procs, &loc_cond.value); @@ -3764,9 +3772,9 @@ pub fn with_hole<'a>( env, cond_var, expr_var, - region, cond_symbol, branches, + exhaustive, layout_cache, procs, Some(id), @@ -5442,10 +5450,11 @@ pub fn from_can<'a>( When { cond_var, expr_var, - region, + region: _, loc_cond, branches, branches_cond_var: _, + exhaustive, } => { let cond_symbol = possible_reuse_symbol(env, procs, &loc_cond.value); @@ -5453,9 +5462,9 @@ pub fn from_can<'a>( env, cond_var, expr_var, - region, cond_symbol, branches, + exhaustive, layout_cache, procs, None, @@ -5822,8 +5831,8 @@ pub fn from_can<'a>( fn to_opt_branches<'a>( env: &mut Env<'a, '_>, - region: Region, branches: std::vec::Vec, + exhaustive_mark: ExhaustiveMark, layout_cache: &mut LayoutCache<'a>, ) -> std::vec::Vec<( Pattern<'a>, @@ -5842,6 +5851,11 @@ fn to_opt_branches<'a>( Guard::NoGuard }; + if when_branch.redundant.is_redundant(&env.subs) { + // Don't codegen this branch since it's redundant. + continue; + } + for loc_pattern in when_branch.patterns { match from_can_pattern(env, layout_cache, &loc_pattern.value) { Ok((mono_pattern, assignments)) => { @@ -5891,45 +5905,14 @@ fn to_opt_branches<'a>( } } - // NOTE exhaustiveness is checked after the construction of all the branches - // In contrast to elm (currently), we still do codegen even if a pattern is non-exhaustive. - // So we not only report exhaustiveness errors, but also correct them - let context = roc_exhaustive::Context::BadCase; - match crate::exhaustive::check(region, &loc_branches, context) { - Ok(_) => {} - Err(errors) => { - use roc_exhaustive::Error::*; - let mut is_not_exhaustive = false; - let mut overlapping_branches = std::vec::Vec::new(); - - for error in errors { - match &error { - Incomplete(_, _, _) => { - is_not_exhaustive = true; - } - Redundant { index, .. } => { - overlapping_branches.push(index.to_zero_based()); - } - } - env.problems.push(MonoProblem::PatternProblem(error)) - } - - overlapping_branches.sort_unstable(); - - for i in overlapping_branches.into_iter().rev() { - opt_branches.remove(i); - } - - if is_not_exhaustive { - opt_branches.push(( - Pattern::Underscore, - None, - roc_can::expr::Expr::RuntimeError( - roc_problem::can::RuntimeError::NonExhaustivePattern, - ), - )); - } - } + if !exhaustive_mark.is_exhaustive(env.subs) { + // In contrast to elm (currently), we still do codegen even if a pattern is non-exhaustive. + // So we not only report exhaustiveness errors, but also correct them + opt_branches.push(( + Pattern::Underscore, + None, + roc_can::expr::Expr::RuntimeError(roc_problem::can::RuntimeError::NonExhaustivePattern), + )); } opt_branches @@ -5940,9 +5923,9 @@ fn from_can_when<'a>( env: &mut Env<'a, '_>, cond_var: Variable, expr_var: Variable, - region: Region, cond_symbol: Symbol, branches: std::vec::Vec, + exhaustive_mark: ExhaustiveMark, layout_cache: &mut LayoutCache<'a>, procs: &mut Procs<'a>, join_point: Option, @@ -5952,7 +5935,7 @@ fn from_can_when<'a>( // We can't know what to return! return Stmt::RuntimeError("Hit a 0-branch when expression"); } - let opt_branches = to_opt_branches(env, region, branches, layout_cache); + let opt_branches = to_opt_branches(env, branches, exhaustive_mark, layout_cache); let cond_layout = return_on_layout_error!(env, layout_cache.from_var(env.arena, cond_var, env.subs)); diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index 522cf974d2..294200a879 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -12,7 +12,8 @@ use roc_region::all::{Loc, Region}; use roc_types::solved_types::Solved; use roc_types::subs::{ AliasVariables, Content, Descriptor, ExhaustiveMark, FlatType, Mark, OptVariable, Rank, - RecordFields, Subs, SubsIndex, SubsSlice, UnionTags, Variable, VariableSubsSlice, + RecordFields, RedundantMark, Subs, SubsIndex, SubsSlice, UnionTags, Variable, + VariableSubsSlice, }; use roc_types::types::Type::{self, *}; use roc_types::types::{ @@ -1286,23 +1287,26 @@ fn solve( let sketched_rows = constraints.sketched_rows[sketched_rows.index()].clone(); if should_check_exhaustiveness { - use roc_can::exhaustive::check; - use roc_exhaustive::Error; + use roc_can::exhaustive::{check, ExhaustiveSummary}; - let checked = roc_can::exhaustive::check(subs, sketched_rows, context); - if let Err(errors) = checked { - for error in errors.iter() { - match error { - Error::Incomplete(..) => subs - .set_content(exhaustive_mark.0, ExhaustiveMark::NON_EXHAUSTIVE), - Error::Redundant { index, .. } => { - // - } - } - } + let ExhaustiveSummary { + errors, + exhaustive, + redundancies, + } = check(subs, sketched_rows, context); - problems.extend(errors.into_iter().map(TypeError::Exhaustive)); + // Store information about whether the "when" is exhaustive, and + // which (if any) of its branches are redundant. Codegen may use + // this for branch-fixing and redundant elimination. + if !exhaustive { + subs.set_content(exhaustive_mark.0, ExhaustiveMark::NON_EXHAUSTIVE) } + for redundant_mark in redundancies { + subs.set_content(redundant_mark.0, RedundantMark::REDUNDANT); + } + + // Store the errors. + problems.extend(errors.into_iter().map(TypeError::Exhaustive)); } state diff --git a/compiler/types/src/subs.rs b/compiler/types/src/subs.rs index dac17353ca..e497f06a0b 100644 --- a/compiler/types/src/subs.rs +++ b/compiler/types/src/subs.rs @@ -973,14 +973,27 @@ impl ExhaustiveMark { pub const EXHAUSTIVE_TYPE: Type = Type::EmptyTagUnion; pub const EXHAUSTIVE: Content = Content::Structure(FlatType::EmptyTagUnion); pub const NON_EXHAUSTIVE: Content = Content::Error; + + pub fn is_exhaustive(&self, subs: &Subs) -> bool { + matches!( + subs.get_content_without_compacting(self.0), + Content::Structure(FlatType::EmptyTagUnion) + ) + } } /// Marks whether a when branch is redundant using a variable. -pub struct RedundantMark(Variable); +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub struct RedundantMark(pub Variable); impl RedundantMark { - pub const REDUNDANT: Content = Content::Structure(FlatType::EmptyTagUnion); - pub const NON_REDUNDANT: Content = Content::Error; + pub const REDUNDANT: Content = Content::Error; + pub const NON_REDUNDANT: Content = Content::Structure(FlatType::EmptyTagUnion); + pub const NON_REDUNDANT_TYPE: Type = Type::EmptyTagUnion; + + pub fn is_redundant(&self, subs: &Subs) -> bool { + matches!(subs.get_content_without_compacting(self.0), Content::Error) + } } #[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] diff --git a/compiler/types/src/types.rs b/compiler/types/src/types.rs index 378fb0b8e6..28d309d663 100644 --- a/compiler/types/src/types.rs +++ b/compiler/types/src/types.rs @@ -2508,7 +2508,10 @@ pub fn gather_tags_unsorted_iter( // TODO investigate this likely can happen when there is a type error RigidVar(_) => break, - other => unreachable!("something weird ended up in a tag union type: {:?}", other), + other => unreachable!( + "something weird ended up in a tag union type: {:?} at {:?}", + other, var + ), } } From 51c8702820ff9d42789abfd61acff66f12e5e37d Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 28 Apr 2022 10:24:27 -0400 Subject: [PATCH 671/846] Smarter marks --- compiler/constrain/src/expr.rs | 20 +------------------- compiler/mono/src/ir.rs | 2 +- compiler/solve/src/solve.rs | 9 ++++----- compiler/types/src/subs.rs | 23 ++++++++++------------- 4 files changed, 16 insertions(+), 38 deletions(-) diff --git a/compiler/constrain/src/expr.rs b/compiler/constrain/src/expr.rs index 89a67bef97..aa4134f36d 100644 --- a/compiler/constrain/src/expr.rs +++ b/compiler/constrain/src/expr.rs @@ -15,7 +15,7 @@ use roc_collections::all::{HumanIndex, MutMap, SendMap}; use roc_module::ident::{Lowercase, TagName}; use roc_module::symbol::{ModuleId, Symbol}; use roc_region::all::{Loc, Region}; -use roc_types::subs::{ExhaustiveMark, RedundantMark, Variable}; +use roc_types::subs::Variable; use roc_types::types::Type::{self, *}; use roc_types::types::{ AliasKind, AnnotationSource, Category, PReason, Reason, RecordField, TypeExtension, @@ -719,15 +719,6 @@ pub fn constrain_expr( ); pattern_cons.push(cond_constraint); - // Mark the `when` as exhaustive initially. We'll refine this if the condition - // disagrees. - pattern_cons.push(constraints.store( - ExhaustiveMark::EXHAUSTIVE_TYPE, - exhaustive.0, - file!(), - line!(), - )); - // Now check the condition against the type expected by the branches. let sketched_rows = sketch_rows(real_cond_var, branches_region, branches); let cond_matches_branches_constraint = constraints.exhaustive( @@ -1182,15 +1173,6 @@ fn constrain_when_branch_help( delayed_is_open_constraints: Vec::new(), }; - // Mark the branch as non-redundant initially. We'll refine this during solving. - state.vars.push(when_branch.redundant.0); - state.constraints.push(constraints.store( - RedundantMark::NON_REDUNDANT_TYPE, - when_branch.redundant.0, - file!(), - line!(), - )); - // TODO investigate for error messages, is it better to unify all branches with a variable, // then unify that variable with the expectation? for (i, loc_pattern) in when_branch.patterns.iter().enumerate() { diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 74d9af2caf..52072542d4 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -5905,7 +5905,7 @@ fn to_opt_branches<'a>( } } - if !exhaustive_mark.is_exhaustive(env.subs) { + if exhaustive_mark.is_non_exhaustive(env.subs) { // In contrast to elm (currently), we still do codegen even if a pattern is non-exhaustive. // So we not only report exhaustiveness errors, but also correct them opt_branches.push(( diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index 294200a879..b93e534bfe 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -11,9 +11,8 @@ use roc_module::symbol::Symbol; use roc_region::all::{Loc, Region}; use roc_types::solved_types::Solved; use roc_types::subs::{ - AliasVariables, Content, Descriptor, ExhaustiveMark, FlatType, Mark, OptVariable, Rank, - RecordFields, RedundantMark, Subs, SubsIndex, SubsSlice, UnionTags, Variable, - VariableSubsSlice, + AliasVariables, Content, Descriptor, FlatType, Mark, OptVariable, Rank, RecordFields, Subs, + SubsIndex, SubsSlice, UnionTags, Variable, VariableSubsSlice, }; use roc_types::types::Type::{self, *}; use roc_types::types::{ @@ -1299,10 +1298,10 @@ fn solve( // which (if any) of its branches are redundant. Codegen may use // this for branch-fixing and redundant elimination. if !exhaustive { - subs.set_content(exhaustive_mark.0, ExhaustiveMark::NON_EXHAUSTIVE) + exhaustive_mark.set_non_exhaustive(subs); } for redundant_mark in redundancies { - subs.set_content(redundant_mark.0, RedundantMark::REDUNDANT); + redundant_mark.set_redundant(subs); } // Store the errors. diff --git a/compiler/types/src/subs.rs b/compiler/types/src/subs.rs index e497f06a0b..91cbf0fda1 100644 --- a/compiler/types/src/subs.rs +++ b/compiler/types/src/subs.rs @@ -1,6 +1,6 @@ #![deny(unsafe_op_in_unsafe_fn)] use crate::types::{ - name_type_var, AliasKind, ErrorType, Problem, RecordField, RecordFieldsError, Type, TypeExt, + name_type_var, AliasKind, ErrorType, Problem, RecordField, RecordFieldsError, TypeExt, }; use roc_collections::all::{ImMap, ImSet, MutSet, SendMap}; use roc_error_macros::internal_error; @@ -970,15 +970,12 @@ impl From for Option { pub struct ExhaustiveMark(pub Variable); impl ExhaustiveMark { - pub const EXHAUSTIVE_TYPE: Type = Type::EmptyTagUnion; - pub const EXHAUSTIVE: Content = Content::Structure(FlatType::EmptyTagUnion); - pub const NON_EXHAUSTIVE: Content = Content::Error; + pub fn set_non_exhaustive(&self, subs: &mut Subs) { + subs.set_content(self.0, Content::Error); + } - pub fn is_exhaustive(&self, subs: &Subs) -> bool { - matches!( - subs.get_content_without_compacting(self.0), - Content::Structure(FlatType::EmptyTagUnion) - ) + pub fn is_non_exhaustive(&self, subs: &Subs) -> bool { + matches!(subs.get_content_without_compacting(self.0), Content::Error,) } } @@ -987,12 +984,12 @@ impl ExhaustiveMark { pub struct RedundantMark(pub Variable); impl RedundantMark { - pub const REDUNDANT: Content = Content::Error; - pub const NON_REDUNDANT: Content = Content::Structure(FlatType::EmptyTagUnion); - pub const NON_REDUNDANT_TYPE: Type = Type::EmptyTagUnion; + pub fn set_redundant(&self, subs: &mut Subs) { + subs.set_content(self.0, Content::Error); + } pub fn is_redundant(&self, subs: &Subs) -> bool { - matches!(subs.get_content_without_compacting(self.0), Content::Error) + matches!(subs.get_content_without_compacting(self.0), Content::Error,) } } From 7ec14ab76f94461426fb06e0e4b5f6b48634ca86 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 28 Apr 2022 10:24:48 -0400 Subject: [PATCH 672/846] Fix test --- reporting/tests/test_reporting.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index d12bcc66ff..095417f6bf 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -9861,6 +9861,7 @@ I need all branches in an `if` to have the same type! ) } + #[test] fn imports_missing_comma() { new_report_problem_as( "imports_missing_comma", From bd4f004ceabe6c089a7756f2f887497eff6ff635 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 28 Apr 2022 11:05:12 -0400 Subject: [PATCH 673/846] Some marks are always known --- compiler/can/src/builtins.rs | 36 +++++++++++----------- compiler/can/src/effect_module.rs | 6 ++-- compiler/can/src/expr.rs | 6 ++-- compiler/constrain/src/expr.rs | 11 ++++++- compiler/mono/src/ir.rs | 8 ++--- compiler/types/src/subs.rs | 51 ++++++++++++++++++++++++++++--- 6 files changed, 85 insertions(+), 33 deletions(-) diff --git a/compiler/can/src/builtins.rs b/compiler/can/src/builtins.rs index 4cbbfa956a..47224c055a 100644 --- a/compiler/can/src/builtins.rs +++ b/compiler/can/src/builtins.rs @@ -4686,7 +4686,7 @@ fn result_map(symbol: Symbol, var_store: &mut VarStore) -> Def { patterns: vec![no_region(pattern)], value: no_region(ok), guard: None, - redundant: RedundantMark(var_store.fresh()), + redundant: RedundantMark::new(var_store), }; branches.push(branch); @@ -4717,7 +4717,7 @@ fn result_map(symbol: Symbol, var_store: &mut VarStore) -> Def { patterns: vec![no_region(pattern)], value: no_region(err), guard: None, - redundant: RedundantMark(var_store.fresh()), + redundant: RedundantMark::new(var_store), }; branches.push(branch); @@ -4730,7 +4730,7 @@ fn result_map(symbol: Symbol, var_store: &mut VarStore) -> Def { loc_cond: Box::new(no_region(Var(Symbol::ARG_1))), branches, branches_cond_var: var_store.fresh(), - exhaustive: ExhaustiveMark(var_store.fresh()), + exhaustive: ExhaustiveMark::new(var_store), }; defn( @@ -4787,7 +4787,7 @@ fn result_map_err(symbol: Symbol, var_store: &mut VarStore) -> Def { patterns: vec![no_region(pattern)], value: no_region(ok), guard: None, - redundant: RedundantMark(var_store.fresh()), + redundant: RedundantMark::new(var_store), }; branches.push(branch); @@ -4818,7 +4818,7 @@ fn result_map_err(symbol: Symbol, var_store: &mut VarStore) -> Def { patterns: vec![no_region(pattern)], value: no_region(err), guard: None, - redundant: RedundantMark(var_store.fresh()), + redundant: RedundantMark::new(var_store), }; branches.push(branch); @@ -4831,7 +4831,7 @@ fn result_map_err(symbol: Symbol, var_store: &mut VarStore) -> Def { loc_cond: Box::new(no_region(Var(Symbol::ARG_1))), branches, branches_cond_var: var_store.fresh(), - exhaustive: ExhaustiveMark(var_store.fresh()), + exhaustive: ExhaustiveMark::new(var_store), }; defn( @@ -4864,7 +4864,7 @@ fn result_with_default(symbol: Symbol, var_store: &mut VarStore) -> Def { patterns: vec![no_region(pattern)], value: no_region(Var(Symbol::ARG_3)), guard: None, - redundant: RedundantMark(var_store.fresh()), + redundant: RedundantMark::new(var_store), }; branches.push(branch); @@ -4885,7 +4885,7 @@ fn result_with_default(symbol: Symbol, var_store: &mut VarStore) -> Def { patterns: vec![no_region(pattern)], value: no_region(Var(Symbol::ARG_2)), guard: None, - redundant: RedundantMark(var_store.fresh()), + redundant: RedundantMark::new(var_store), }; branches.push(branch); @@ -4898,7 +4898,7 @@ fn result_with_default(symbol: Symbol, var_store: &mut VarStore) -> Def { loc_cond: Box::new(no_region(Var(Symbol::ARG_1))), branches, branches_cond_var: var_store.fresh(), - exhaustive: ExhaustiveMark(var_store.fresh()), + exhaustive: ExhaustiveMark::new(var_store), }; defn( @@ -4938,7 +4938,7 @@ fn result_is_err(symbol: Symbol, var_store: &mut VarStore) -> Def { patterns: vec![no_region(pattern)], value: no_region(false_expr), guard: None, - redundant: RedundantMark(var_store.fresh()), + redundant: RedundantMark::new(var_store), }; branches.push(branch); @@ -4966,7 +4966,7 @@ fn result_is_err(symbol: Symbol, var_store: &mut VarStore) -> Def { patterns: vec![no_region(pattern)], value: no_region(true_expr), guard: None, - redundant: RedundantMark(var_store.fresh()), + redundant: RedundantMark::new(var_store), }; branches.push(branch); @@ -4979,7 +4979,7 @@ fn result_is_err(symbol: Symbol, var_store: &mut VarStore) -> Def { loc_cond: Box::new(no_region(Var(Symbol::ARG_1))), branches, branches_cond_var: var_store.fresh(), - exhaustive: ExhaustiveMark(var_store.fresh()), + exhaustive: ExhaustiveMark::new(var_store), }; defn( @@ -5019,7 +5019,7 @@ fn result_is_ok(symbol: Symbol, var_store: &mut VarStore) -> Def { patterns: vec![no_region(pattern)], value: no_region(true_expr), guard: None, - redundant: RedundantMark(var_store.fresh()), + redundant: RedundantMark::new(var_store), }; branches.push(branch); @@ -5047,7 +5047,7 @@ fn result_is_ok(symbol: Symbol, var_store: &mut VarStore) -> Def { patterns: vec![no_region(pattern)], value: no_region(false_expr), guard: None, - redundant: RedundantMark(var_store.fresh()), + redundant: RedundantMark::new(var_store), }; branches.push(branch); @@ -5060,7 +5060,7 @@ fn result_is_ok(symbol: Symbol, var_store: &mut VarStore) -> Def { loc_cond: Box::new(no_region(Var(Symbol::ARG_1))), branches, branches_cond_var: var_store.fresh(), - exhaustive: ExhaustiveMark(var_store.fresh()), + exhaustive: ExhaustiveMark::new(var_store), }; defn( @@ -5112,7 +5112,7 @@ fn result_after(symbol: Symbol, var_store: &mut VarStore) -> Def { patterns: vec![no_region(pattern)], value: no_region(ok), guard: None, - redundant: RedundantMark(var_store.fresh()), + redundant: RedundantMark::new(var_store), }; branches.push(branch); @@ -5143,7 +5143,7 @@ fn result_after(symbol: Symbol, var_store: &mut VarStore) -> Def { patterns: vec![no_region(pattern)], value: no_region(err), guard: None, - redundant: RedundantMark(var_store.fresh()), + redundant: RedundantMark::new(var_store), }; branches.push(branch); @@ -5156,7 +5156,7 @@ fn result_after(symbol: Symbol, var_store: &mut VarStore) -> Def { loc_cond: Box::new(no_region(Var(Symbol::ARG_1))), branches, branches_cond_var: var_store.fresh(), - exhaustive: ExhaustiveMark(var_store.fresh()), + exhaustive: ExhaustiveMark::new(var_store), }; defn( diff --git a/compiler/can/src/effect_module.rs b/compiler/can/src/effect_module.rs index 0b1d19c68d..36933ff6e2 100644 --- a/compiler/can/src/effect_module.rs +++ b/compiler/can/src/effect_module.rs @@ -1209,7 +1209,7 @@ fn build_effect_loop_inner_body( patterns: vec![Loc::at_zero(step_pattern)], value: Loc::at_zero(force_thunk2), guard: None, - redundant: RedundantMark(var_store.fresh()), + redundant: RedundantMark::new(var_store), } }; @@ -1221,7 +1221,7 @@ fn build_effect_loop_inner_body( patterns: vec![Loc::at_zero(done_pattern)], value: Loc::at_zero(Expr::Var(done_symbol)), guard: None, - redundant: RedundantMark(var_store.fresh()), + redundant: RedundantMark::new(var_store), } }; @@ -1234,7 +1234,7 @@ fn build_effect_loop_inner_body( loc_cond: Box::new(force_thunk_call), branches, branches_cond_var: var_store.fresh(), - exhaustive: ExhaustiveMark(var_store.fresh()), + exhaustive: ExhaustiveMark::new(var_store), }; Expr::LetNonRec( diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index 6ef8fed006..4d5f3208b8 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -719,7 +719,7 @@ pub fn canonicalize_expr<'a>( loc_cond: Box::new(can_cond), branches: can_branches, branches_cond_var: var_store.fresh(), - exhaustive: ExhaustiveMark(var_store.fresh()), + exhaustive: ExhaustiveMark::new(var_store), }; (expr, output) @@ -1139,7 +1139,7 @@ fn canonicalize_when_branch<'a>( patterns, value, guard, - redundant: RedundantMark(var_store.fresh()), + redundant: RedundantMark::new(var_store), }, references, ) @@ -1377,7 +1377,7 @@ pub fn inline_calls(var_store: &mut VarStore, scope: &mut Scope, expr: Expr) -> patterns: branch.patterns, value, guard, - redundant: RedundantMark(var_store.fresh()), + redundant: RedundantMark::new(var_store), }; new_branches.push(new_branch); diff --git a/compiler/constrain/src/expr.rs b/compiler/constrain/src/expr.rs index aa4134f36d..64e76b6a3d 100644 --- a/compiler/constrain/src/expr.rs +++ b/compiler/constrain/src/expr.rs @@ -751,7 +751,12 @@ pub fn constrain_expr( let branch_constraints = constraints.and_constraint(total_cons); constraints.exists( - [exhaustive.0, branches_cond_var, real_cond_var, *expr_var], + [ + exhaustive.variable_for_introduction(), + branches_cond_var, + real_cond_var, + *expr_var, + ], branch_constraints, ) } @@ -1173,6 +1178,10 @@ fn constrain_when_branch_help( delayed_is_open_constraints: Vec::new(), }; + state + .vars + .push(when_branch.redundant.variable_for_introduction()); + // TODO investigate for error messages, is it better to unify all branches with a variable, // then unify that variable with the expectation? for (i, loc_pattern) in when_branch.patterns.iter().enumerate() { diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 52072542d4..94b030dab0 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -2093,12 +2093,12 @@ fn pattern_to_when<'a>( patterns: vec![pattern], value: body, guard: None, - // TODO(exhaustive): should come from real var! - redundant: RedundantMark(Variable::EMPTY_TAG_UNION), + // If this type-checked, it's non-redundant + redundant: RedundantMark::known_non_redundant(), }], branches_cond_var: pattern_var, - // TODO(exhaustive): should come from real var! - exhaustive: ExhaustiveMark(Variable::EMPTY_TAG_UNION), + // If this type-checked, it's exhaustive + exhaustive: ExhaustiveMark::known_exhaustive(), }; (symbol, Loc::at_zero(wrapped_body)) diff --git a/compiler/types/src/subs.rs b/compiler/types/src/subs.rs index 91cbf0fda1..97fd484cd2 100644 --- a/compiler/types/src/subs.rs +++ b/compiler/types/src/subs.rs @@ -967,32 +967,75 @@ impl From for Option { /// Marks whether a when expression is exhaustive using a variable. #[derive(Clone, Copy, Debug)] -pub struct ExhaustiveMark(pub Variable); +pub struct ExhaustiveMark(Variable); impl ExhaustiveMark { + pub fn new(var_store: &mut VarStore) -> Self { + Self(var_store.fresh()) + } + + // NOTE: only ever use this if you *know* a pattern match is surely exhaustive! + // Otherwise you will get unpleasant unification errors. + pub fn known_exhaustive() -> Self { + Self(Variable::EMPTY_TAG_UNION) + } + + pub fn variable_for_introduction(&self) -> Variable { + debug_assert!( + self.0 != Variable::EMPTY_TAG_UNION, + "Attempting to introduce known mark" + ); + self.0 + } + pub fn set_non_exhaustive(&self, subs: &mut Subs) { subs.set_content(self.0, Content::Error); } pub fn is_non_exhaustive(&self, subs: &Subs) -> bool { - matches!(subs.get_content_without_compacting(self.0), Content::Error,) + matches!(subs.get_content_without_compacting(self.0), Content::Error) } } /// Marks whether a when branch is redundant using a variable. #[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub struct RedundantMark(pub Variable); +pub struct RedundantMark(Variable); impl RedundantMark { + pub fn new(var_store: &mut VarStore) -> Self { + Self(var_store.fresh()) + } + + // NOTE: only ever use this if you *know* a pattern match is surely exhaustive! + // Otherwise you will get unpleasant unification errors. + pub fn known_non_redundant() -> Self { + Self(Variable::EMPTY_TAG_UNION) + } + + pub fn variable_for_introduction(&self) -> Variable { + debug_assert!( + self.0 != Variable::EMPTY_TAG_UNION, + "Attempting to introduce known mark" + ); + self.0 + } + pub fn set_redundant(&self, subs: &mut Subs) { subs.set_content(self.0, Content::Error); } pub fn is_redundant(&self, subs: &Subs) -> bool { - matches!(subs.get_content_without_compacting(self.0), Content::Error,) + matches!(subs.get_content_without_compacting(self.0), Content::Error) } } +pub fn new_marks(var_store: &mut VarStore) -> (RedundantMark, ExhaustiveMark) { + ( + RedundantMark::new(var_store), + ExhaustiveMark::new(var_store), + ) +} + #[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct Variable(u32); From 9dac9e4bc21335d0fd4d184a6a30089509a8fe9d Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 28 Apr 2022 14:06:02 -0400 Subject: [PATCH 674/846] Coalesce --- compiler/can/src/builtins.rs | 77 +++++++++-- compiler/can/src/constraint.rs | 40 +++++- compiler/can/src/def.rs | 7 +- compiler/can/src/effect_module.rs | 33 ++++- compiler/can/src/exhaustive.rs | 24 +++- compiler/can/src/expr.rs | 44 ++++++- compiler/can/src/module.rs | 2 +- compiler/can/src/pattern.rs | 55 +++++++- compiler/can/src/traverse.rs | 6 +- compiler/constrain/src/expr.rs | 212 ++++++++++++++++++------------ compiler/mono/src/ir.rs | 89 ++++--------- compiler/solve/src/solve.rs | 72 +++++++--- compiler/types/src/types.rs | 4 + reporting/src/error/type.rs | 38 +++++- reporting/tests/test_reporting.rs | 6 +- 15 files changed, 502 insertions(+), 207 deletions(-) diff --git a/compiler/can/src/builtins.rs b/compiler/can/src/builtins.rs index 47224c055a..d84646f4eb 100644 --- a/compiler/can/src/builtins.rs +++ b/compiler/can/src/builtins.rs @@ -1,5 +1,5 @@ use crate::def::Def; -use crate::expr::{self, ClosureData, Expr::*, IntValue}; +use crate::expr::{self, AnnotatedMark, ClosureData, Expr::*, IntValue}; use crate::expr::{Expr, Field, Recursive}; use crate::num::{FloatBound, IntBound, IntWidth, NumericBound}; use crate::pattern::Pattern; @@ -2622,8 +2622,16 @@ fn list_intersperse(symbol: Symbol, var_store: &mut VarStore) -> Def { recursive: Recursive::NotRecursive, captured_symbols: vec![(sep_sym, sep_var)], arguments: vec![ - (clos_acc_var, no_region(Pattern::Identifier(clos_acc_sym))), - (sep_var, no_region(Pattern::Identifier(clos_elem_sym))), + ( + clos_acc_var, + AnnotatedMark::new(var_store), + no_region(Pattern::Identifier(clos_acc_sym)), + ), + ( + sep_var, + AnnotatedMark::new(var_store), + no_region(Pattern::Identifier(clos_elem_sym)), + ), ], loc_body: { let append_sep = RunLowLevel { @@ -2708,9 +2716,14 @@ fn list_split(symbol: Symbol, var_store: &mut VarStore) -> Def { arguments: vec![ ( clos_start_var, + AnnotatedMark::new(var_store), no_region(Pattern::Identifier(clos_start_sym)), ), - (clos_len_var, no_region(Pattern::Identifier(clos_len_sym))), + ( + clos_len_var, + AnnotatedMark::new(var_store), + no_region(Pattern::Identifier(clos_len_sym)), + ), ], loc_body: { Box::new(no_region(RunLowLevel { @@ -2894,7 +2907,11 @@ fn list_drop_if(symbol: Symbol, var_store: &mut VarStore) -> Def { name: Symbol::LIST_DROP_IF_PREDICATE, recursive: Recursive::NotRecursive, captured_symbols: vec![(sym_predicate, t_predicate)], - arguments: vec![(t_elem, no_region(Pattern::Identifier(Symbol::ARG_3)))], + arguments: vec![( + t_elem, + AnnotatedMark::new(var_store), + no_region(Pattern::Identifier(Symbol::ARG_3)), + )], loc_body: { let should_drop = Call( Box::new(( @@ -3078,8 +3095,16 @@ fn list_join_map(symbol: Symbol, var_store: &mut VarStore) -> Def { recursive: Recursive::NotRecursive, captured_symbols: vec![(Symbol::ARG_2, before2list_after)], arguments: vec![ - (list_after, no_region(Pattern::Identifier(Symbol::ARG_3))), - (before, no_region(Pattern::Identifier(Symbol::ARG_4))), + ( + list_after, + AnnotatedMark::new(var_store), + no_region(Pattern::Identifier(Symbol::ARG_3)), + ), + ( + before, + AnnotatedMark::new(var_store), + no_region(Pattern::Identifier(Symbol::ARG_4)), + ), ], loc_body: { let mapper = Box::new(( @@ -3609,8 +3634,16 @@ fn list_sort_desc(symbol: Symbol, var_store: &mut VarStore) -> Def { recursive: Recursive::NotRecursive, captured_symbols: vec![], arguments: vec![ - (num_var, no_region(Pattern::Identifier(Symbol::ARG_2))), - (num_var, no_region(Pattern::Identifier(Symbol::ARG_3))), + ( + num_var, + AnnotatedMark::new(var_store), + no_region(Pattern::Identifier(Symbol::ARG_2)), + ), + ( + num_var, + AnnotatedMark::new(var_store), + no_region(Pattern::Identifier(Symbol::ARG_3)), + ), ], loc_body: { Box::new(no_region(RunLowLevel { @@ -4084,9 +4117,21 @@ fn set_walk(symbol: Symbol, var_store: &mut VarStore) -> Def { recursive: Recursive::NotRecursive, captured_symbols: vec![(Symbol::ARG_3, func_var)], arguments: vec![ - (accum_var, no_region(Pattern::Identifier(Symbol::ARG_5))), - (key_var, no_region(Pattern::Identifier(Symbol::ARG_6))), - (Variable::EMPTY_RECORD, no_region(Pattern::Underscore)), + ( + accum_var, + AnnotatedMark::new(var_store), + no_region(Pattern::Identifier(Symbol::ARG_5)), + ), + ( + key_var, + AnnotatedMark::new(var_store), + no_region(Pattern::Identifier(Symbol::ARG_6)), + ), + ( + Variable::EMPTY_RECORD, + AnnotatedMark::new(var_store), + no_region(Pattern::Underscore), + ), ], loc_body: Box::new(no_region(call_func)), }); @@ -5342,7 +5387,13 @@ fn defn_help( let closure_args = args .into_iter() - .map(|(var, symbol)| (var, no_region(Identifier(symbol)))) + .map(|(var, symbol)| { + ( + var, + AnnotatedMark::new(var_store), + no_region(Identifier(symbol)), + ) + }) .collect(); Closure(ClosureData { diff --git a/compiler/can/src/constraint.rs b/compiler/can/src/constraint.rs index 36347185cb..42e416b014 100644 --- a/compiler/can/src/constraint.rs +++ b/compiler/can/src/constraint.rs @@ -22,6 +22,7 @@ pub struct Constraints { pub strings: Vec<&'static str>, pub sketched_rows: Vec, pub eq: Vec, + pub pattern_eq: Vec, } impl Default for Constraints { @@ -45,6 +46,7 @@ impl Constraints { let strings = Vec::new(); let sketched_rows = Vec::new(); let eq = Vec::new(); + let pattern_eq = Vec::new(); types.extend([ Type::EmptyRec, @@ -97,6 +99,7 @@ impl Constraints { strings, sketched_rows, eq, + pattern_eq, } } @@ -610,19 +613,34 @@ impl Constraints { &mut self, real_var: Variable, real_region: Region, - real_category: Category, - expected_branches: Expected, + category_and_expectation: Result< + (Category, Expected), + (PatternCategory, PExpected), + >, sketched_rows: SketchedRows, context: ExhaustiveContext, exhaustive: ExhaustiveMark, ) -> Constraint { let real_var = Self::push_type_variable(real_var); - let real_category = Index::push_new(&mut self.categories, real_category); - let expected_branches = Index::push_new(&mut self.expectations, expected_branches); - let equality = Eq(real_var, expected_branches, real_category, real_region); - let equality = Index::push_new(&mut self.eq, equality); let sketched_rows = Index::push_new(&mut self.sketched_rows, sketched_rows); + let equality = match category_and_expectation { + Ok((category, expected)) => { + let category = Index::push_new(&mut self.categories, category); + let expected = Index::push_new(&mut self.expectations, expected); + let equality = Eq(real_var, expected, category, real_region); + let equality = Index::push_new(&mut self.eq, equality); + Ok(equality) + } + Err((category, expected)) => { + let category = Index::push_new(&mut self.pattern_categories, category); + let expected = Index::push_new(&mut self.pattern_expectations, expected); + let equality = PatternEq(real_var, expected, category, real_region); + let equality = Index::push_new(&mut self.pattern_eq, equality); + Err(equality) + } + }; + Constraint::Exhaustive(equality, sketched_rows, context, exhaustive) } } @@ -638,6 +656,14 @@ pub struct Eq( pub Region, ); +#[derive(Clone, Copy, Debug)] +pub struct PatternEq( + pub EitherIndex, + pub Index>, + pub Index, + pub Region, +); + #[derive(Clone, Copy)] pub enum Constraint { Eq(Eq), @@ -674,7 +700,7 @@ pub enum Constraint { Region, ), Exhaustive( - Index, + Result, Index>, Index, ExhaustiveContext, ExhaustiveMark, diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index cdc2546e66..f93b8732e2 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -2,6 +2,7 @@ use crate::abilities::MemberVariables; use crate::annotation::canonicalize_annotation; use crate::annotation::IntroducedVariables; use crate::env::Env; +use crate::expr::AnnotatedMark; use crate::expr::ClosureData; use crate::expr::Expr::{self, *}; use crate::expr::{canonicalize_expr, Output, Recursive}; @@ -1085,7 +1086,11 @@ fn canonicalize_pending_value_def<'a>( region: Region::zero(), }; - underscores.push((var_store.fresh(), underscore)); + underscores.push(( + var_store.fresh(), + AnnotatedMark::known_exhaustive(), + underscore, + )); } let body_expr = Loc { diff --git a/compiler/can/src/effect_module.rs b/compiler/can/src/effect_module.rs index 36933ff6e2..b302b64e71 100644 --- a/compiler/can/src/effect_module.rs +++ b/compiler/can/src/effect_module.rs @@ -1,6 +1,6 @@ use crate::annotation::IntroducedVariables; use crate::def::{Declaration, Def}; -use crate::expr::{ClosureData, Expr, Recursive}; +use crate::expr::{AnnotatedMark, ClosureData, Expr, Recursive}; use crate::pattern::Pattern; use crate::scope::Scope; use roc_collections::{SendMap, VecSet}; @@ -120,6 +120,7 @@ fn build_effect_always( let const_closure = { let arguments = vec![( var_store.fresh(), + AnnotatedMark::new(var_store), Loc::at_zero(empty_record_pattern(var_store)), )]; @@ -154,6 +155,7 @@ fn build_effect_always( let arguments = vec![( var_store.fresh(), + AnnotatedMark::new(var_store), Loc::at_zero(Pattern::Identifier(value_symbol)), )]; @@ -277,6 +279,7 @@ fn build_effect_map( let inner_closure = { let arguments = vec![( var_store.fresh(), + AnnotatedMark::new(var_store), Loc::at_zero(empty_record_pattern(var_store)), )]; @@ -302,6 +305,7 @@ fn build_effect_map( let arguments = vec![ ( var_store.fresh(), + AnnotatedMark::new(var_store), Loc::at_zero(Pattern::UnwrappedOpaque { opaque: effect_symbol, whole_var: var_store.fresh(), @@ -316,6 +320,7 @@ fn build_effect_map( ), ( var_store.fresh(), + AnnotatedMark::new(var_store), Loc::at_zero(Pattern::Identifier(mapper_symbol)), ), ]; @@ -466,6 +471,7 @@ fn build_effect_after( let arguments = vec![ ( var_store.fresh(), + AnnotatedMark::new(var_store), Loc::at_zero(Pattern::UnwrappedOpaque { opaque: effect_symbol, whole_var: var_store.fresh(), @@ -480,6 +486,7 @@ fn build_effect_after( ), ( var_store.fresh(), + AnnotatedMark::new(var_store), Loc::at_zero(Pattern::Identifier(to_effect_symbol)), ), ]; @@ -579,6 +586,7 @@ fn wrap_in_effect_thunk( let const_closure = { let arguments = vec![( var_store.fresh(), + AnnotatedMark::new(var_store), Loc::at_zero(empty_record_pattern(var_store)), )]; @@ -720,7 +728,11 @@ fn build_effect_forever( let body = build_effect_forever_body(scope, effect_symbol, forever_symbol, effect, var_store); - let arguments = vec![(var_store.fresh(), Loc::at_zero(Pattern::Identifier(effect)))]; + let arguments = vec![( + var_store.fresh(), + AnnotatedMark::new(var_store), + Loc::at_zero(Pattern::Identifier(effect)), + )]; let function_var = var_store.fresh(); let after_closure = Expr::Closure(ClosureData { @@ -939,10 +951,12 @@ fn build_effect_loop( let arguments = vec![ ( var_store.fresh(), + AnnotatedMark::new(var_store), Loc::at_zero(Pattern::Identifier(state_symbol)), ), ( var_store.fresh(), + AnnotatedMark::new(var_store), Loc::at_zero(Pattern::Identifier(step_symbol)), ), ]; @@ -1257,7 +1271,7 @@ pub fn build_host_exposed_def( let mut pattern_vars = SendMap::default(); pattern_vars.insert(symbol, expr_var); - let mut arguments: Vec<(Variable, Loc)> = Vec::new(); + let mut arguments: Vec<(Variable, AnnotatedMark, Loc)> = Vec::new(); let mut linked_symbol_arguments: Vec<(Variable, Expr)> = Vec::new(); let mut captured_symbols: Vec<(Symbol, Variable)> = Vec::new(); @@ -1281,7 +1295,11 @@ pub fn build_host_exposed_def( let arg_var = var_store.fresh(); - arguments.push((arg_var, Loc::at_zero(Pattern::Identifier(arg_symbol)))); + arguments.push(( + arg_var, + AnnotatedMark::new(var_store), + Loc::at_zero(Pattern::Identifier(arg_symbol)), + )); captured_symbols.push((arg_symbol, arg_var)); linked_symbol_arguments.push((arg_var, Expr::Var(arg_symbol))); @@ -1311,6 +1329,7 @@ pub fn build_host_exposed_def( recursive: Recursive::NotRecursive, arguments: vec![( var_store.fresh(), + AnnotatedMark::new(var_store), Loc::at_zero(empty_record_pattern(var_store)), )], loc_body: Box::new(Loc::at_zero(low_level_call)), @@ -1370,7 +1389,11 @@ pub fn build_host_exposed_def( name: effect_closure_symbol, captured_symbols, recursive: Recursive::NotRecursive, - arguments: vec![(var_store.fresh(), Loc::at_zero(empty_record_pattern))], + arguments: vec![( + var_store.fresh(), + AnnotatedMark::new(var_store), + Loc::at_zero(empty_record_pattern), + )], loc_body: Box::new(Loc::at_zero(low_level_call)), }); diff --git a/compiler/can/src/exhaustive.rs b/compiler/can/src/exhaustive.rs index 1d4d7d248a..c97f9d0013 100644 --- a/compiler/can/src/exhaustive.rs +++ b/compiler/can/src/exhaustive.rs @@ -197,7 +197,11 @@ fn sketch_pattern(var: Variable, pattern: &crate::pattern::Pattern) -> SketchedP } } -pub fn sketch_rows(target_var: Variable, region: Region, patterns: &[WhenBranch]) -> SketchedRows { +pub fn sketch_when_branches( + target_var: Variable, + region: Region, + patterns: &[WhenBranch], +) -> SketchedRows { let mut rows: Vec = Vec::with_capacity(patterns.len()); // If any of the branches has a guard, e.g. @@ -279,6 +283,24 @@ pub fn sketch_rows(target_var: Variable, region: Region, patterns: &[WhenBranch] } } +pub fn sketch_pattern_to_rows( + target_var: Variable, + region: Region, + pattern: &crate::pattern::Pattern, +) -> SketchedRows { + let row = SketchedRow { + patterns: vec![sketch_pattern(target_var, pattern)], + region, + // A single row cannot be redundant! + redundant_mark: RedundantMark::known_non_redundant(), + guard: Guard::NoGuard, + }; + SketchedRows { + rows: vec![row], + overall_region: region, + } +} + /// REDUNDANT PATTERNS struct NonRedundantSummary { diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index 4d5f3208b8..3b971bdc1b 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -241,6 +241,32 @@ impl Expr { } } +/// Stores exhaustiveness-checking metadata for a closure argument that may +/// have an annotated type. +#[derive(Clone, Copy, Debug)] +pub struct AnnotatedMark { + pub annotation_var: Variable, + pub exhaustive: ExhaustiveMark, +} + +impl AnnotatedMark { + pub fn new(var_store: &mut VarStore) -> Self { + Self { + annotation_var: var_store.fresh(), + exhaustive: ExhaustiveMark::new(var_store), + } + } + + // NOTE: only ever use this if you *know* a pattern match is surely exhaustive! + // Otherwise you will get unpleasant unification errors. + pub fn known_exhaustive() -> Self { + Self { + annotation_var: Variable::EMPTY_TAG_UNION, + exhaustive: ExhaustiveMark::known_exhaustive(), + } + } +} + #[derive(Clone, Debug)] pub struct ClosureData { pub function_type: Variable, @@ -250,7 +276,7 @@ pub struct ClosureData { pub name: Symbol, pub captured_symbols: Vec<(Symbol, Variable)>, pub recursive: Recursive, - pub arguments: Vec<(Variable, Loc)>, + pub arguments: Vec<(Variable, AnnotatedMark, Loc)>, pub loc_body: Box>, } @@ -302,7 +328,11 @@ impl AccessorData { let loc_body = Loc::at_zero(body); - let arguments = vec![(record_var, Loc::at_zero(Pattern::Identifier(record_symbol)))]; + let arguments = vec![( + record_var, + AnnotatedMark::known_exhaustive(), + Loc::at_zero(Pattern::Identifier(record_symbol)), + )]; ClosureData { function_type: function_var, @@ -1001,11 +1031,15 @@ fn canonicalize_closure_inner_scope<'a>( loc_pattern.region, ); - can_args.push((var_store.fresh(), can_argument_pattern)); + can_args.push(( + var_store.fresh(), + AnnotatedMark::new(var_store), + can_argument_pattern, + )); } let bound_by_argument_patterns: Vec<_> = - BindingsFromPattern::new_many(can_args.iter().map(|x| &x.1)).collect(); + BindingsFromPattern::new_many(can_args.iter().map(|x| &x.2)).collect(); let (loc_body_expr, new_output) = canonicalize_expr( env, @@ -1620,7 +1654,7 @@ pub fn inline_calls(var_store: &mut VarStore, scope: &mut Scope, expr: Expr) -> // Wrap the body in one LetNonRec for each argument, // such that at the end we have all the arguments in // scope with the values the caller provided. - for ((_param_var, loc_pattern), (expr_var, loc_expr)) in + for ((_param_var, _exhaustive_mark, loc_pattern), (expr_var, loc_expr)) in params.iter().cloned().zip(args.into_iter()).rev() { // TODO get the correct vars into here. diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index 05c43b52ee..0a3ca9613e 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -667,7 +667,7 @@ fn fix_values_captured_in_closure_expr( } // patterns can contain default expressions, so much go over them too! - for (_, loc_pat) in arguments.iter_mut() { + for (_, _, loc_pat) in arguments.iter_mut() { fix_values_captured_in_closure_pattern(&mut loc_pat.value, no_capture_symbols); } diff --git a/compiler/can/src/pattern.rs b/compiler/can/src/pattern.rs index 3025694963..2a3c32cbcd 100644 --- a/compiler/can/src/pattern.rs +++ b/compiler/can/src/pattern.rs @@ -13,7 +13,7 @@ use roc_parse::pattern::PatternType; use roc_problem::can::{MalformedPatternProblem, Problem, RuntimeError, ShadowKind}; use roc_region::all::{Loc, Region}; use roc_types::subs::{VarStore, Variable}; -use roc_types::types::{LambdaSet, Type}; +use roc_types::types::{LambdaSet, PatternCategory, Type}; /// A pattern, including possible problems (e.g. shadowing) so that /// codegen can generate a runtime error if this pattern is reached. @@ -105,6 +105,59 @@ impl Pattern { } } } + + /// Is this pattern sure to cover all instances of a type T, assuming it typechecks against T? + pub fn surely_exhaustive(&self) -> bool { + use Pattern::*; + match self { + Identifier(..) + | Underscore + | Shadowed(..) + | OpaqueNotInScope(..) + | UnsupportedPattern(..) + | MalformedPattern(..) + | AbilityMemberSpecialization { .. } => true, + AppliedTag { .. } + | RecordDestructure { .. } + | NumLiteral(..) + | IntLiteral(..) + | FloatLiteral(..) + | StrLiteral(..) + | SingleQuote(..) => false, + UnwrappedOpaque { argument, .. } => { + // Opaques can only match against one constructor (the opaque symbol), so this is + // surely exhaustive against T if the inner pattern is surely exhaustive against + // its type U. + argument.1.value.surely_exhaustive() + } + } + } + + pub fn category(&self) -> PatternCategory { + use Pattern::*; + use PatternCategory as C; + + match self { + Identifier(_) => C::PatternDefault, + + AppliedTag { tag_name, .. } => C::Ctor(tag_name.clone()), + UnwrappedOpaque { opaque, .. } => C::Opaque(*opaque), + RecordDestructure { destructs, .. } if destructs.is_empty() => C::EmptyRecord, + RecordDestructure { .. } => C::Record, + NumLiteral(..) => C::Num, + IntLiteral(..) => C::Int, + FloatLiteral(..) => C::Float, + StrLiteral(_) => C::Str, + SingleQuote(_) => C::Character, + Underscore => C::PatternDefault, + + AbilityMemberSpecialization { .. } => C::PatternDefault, + + Shadowed(..) | OpaqueNotInScope(..) | UnsupportedPattern(..) | MalformedPattern(..) => { + C::PatternDefault + } + } + } } #[derive(Clone, Debug)] diff --git a/compiler/can/src/traverse.rs b/compiler/can/src/traverse.rs index b25d2d7928..55ecdf14b9 100644 --- a/compiler/can/src/traverse.rs +++ b/compiler/can/src/traverse.rs @@ -82,9 +82,9 @@ fn walk_closure(visitor: &mut V, clos: &ClosureData) { .. } = clos; - arguments - .iter() - .for_each(|(var, arg)| visitor.visit_pattern(&arg.value, arg.region, Some(*var))); + arguments.iter().for_each(|(var, _exhaustive_mark, arg)| { + visitor.visit_pattern(&arg.value, arg.region, Some(*var)) + }); visitor.visit_expr(&loc_body.value, loc_body.region, *return_type); } diff --git a/compiler/constrain/src/expr.rs b/compiler/constrain/src/expr.rs index 64e76b6a3d..c79263c164 100644 --- a/compiler/constrain/src/expr.rs +++ b/compiler/constrain/src/expr.rs @@ -5,11 +5,11 @@ use crate::pattern::{constrain_pattern, PatternState}; use roc_can::annotation::IntroducedVariables; use roc_can::constraint::{Constraint, Constraints}; use roc_can::def::{Declaration, Def}; -use roc_can::exhaustive::{sketch_rows, ExhaustiveContext}; +use roc_can::exhaustive::{sketch_pattern_to_rows, sketch_when_branches, ExhaustiveContext}; use roc_can::expected::Expected::{self, *}; use roc_can::expected::PExpected; use roc_can::expr::Expr::{self, *}; -use roc_can::expr::{AccessorData, ClosureData, Field, WhenBranch}; +use roc_can::expr::{AccessorData, AnnotatedMark, ClosureData, Field, WhenBranch}; use roc_can::pattern::Pattern; use roc_collections::all::{HumanIndex, MutMap, SendMap}; use roc_module::ident::{Lowercase, TagName}; @@ -50,7 +50,7 @@ pub struct Env { fn constrain_untyped_args( constraints: &mut Constraints, env: &Env, - arguments: &[(Variable, Loc)], + arguments: &[(Variable, AnnotatedMark, Loc)], closure_type: Type, return_type: Type, ) -> (Vec, PatternState, Type) { @@ -59,7 +59,10 @@ fn constrain_untyped_args( let mut pattern_state = PatternState::default(); - for (pattern_var, loc_pattern) in arguments { + for (pattern_var, annotated_mark, loc_pattern) in arguments { + // Untyped args don't need exhaustiveness checking because they are the source of truth! + let _ = annotated_mark; + let pattern_type = Type::Variable(*pattern_var); let pattern_expected = PExpected::NoExpectation(pattern_type.clone()); @@ -720,12 +723,14 @@ pub fn constrain_expr( pattern_cons.push(cond_constraint); // Now check the condition against the type expected by the branches. - let sketched_rows = sketch_rows(real_cond_var, branches_region, branches); + let sketched_rows = sketch_when_branches(real_cond_var, branches_region, branches); let cond_matches_branches_constraint = constraints.exhaustive( real_cond_var, loc_cond.region, - loc_cond.value.category(), - Expected::ForReason(Reason::WhenBranches, branches_cond_type, branches_region), + Ok(( + loc_cond.value.category(), + Expected::ForReason(Reason::WhenBranches, branches_cond_type, branches_region), + )), sketched_rows, ExhaustiveContext::BadCase, *exhaustive, @@ -1547,7 +1552,7 @@ fn constrain_typed_function_arguments( def: &Def, def_pattern_state: &mut PatternState, argument_pattern_state: &mut PatternState, - arguments: &[(Variable, Loc)], + arguments: &[(Variable, AnnotatedMark, Loc)], arg_types: &[Type], ) { // ensure type matches the one in the annotation @@ -1558,38 +1563,113 @@ fn constrain_typed_function_arguments( }; let it = arguments.iter().zip(arg_types.iter()).enumerate(); - for (index, ((pattern_var, loc_pattern), loc_ann)) in it { - let pattern_expected = PExpected::ForReason( - PReason::TypedArg { - index: HumanIndex::zero_based(index), - opt_name: opt_label, - }, - loc_ann.clone(), - loc_pattern.region, - ); - - constrain_pattern( - constraints, - env, - &loc_pattern.value, - loc_pattern.region, - pattern_expected, - argument_pattern_state, - ); - - { - // NOTE: because we perform an equality with part of the signature - // this constraint must be to the def_pattern_state's constraints - def_pattern_state.vars.push(*pattern_var); - - let pattern_con = constraints.equal_types_var( - *pattern_var, - Expected::NoExpectation(loc_ann.clone()), - Category::Storage(std::file!(), std::line!()), + for (index, ((pattern_var, annotated_mark, loc_pattern), ann)) in it { + if loc_pattern.value.surely_exhaustive() { + // OPT: we don't need to perform any type-level exhaustiveness checking. + // Check instead only that the pattern unifies with the annotation type. + let pattern_expected = PExpected::ForReason( + PReason::TypedArg { + index: HumanIndex::zero_based(index), + opt_name: opt_label, + }, + ann.clone(), loc_pattern.region, ); - def_pattern_state.constraints.push(pattern_con); + constrain_pattern( + constraints, + env, + &loc_pattern.value, + loc_pattern.region, + pattern_expected, + argument_pattern_state, + ); + + { + // NOTE: because we perform an equality with part of the signature + // this constraint must be to the def_pattern_state's constraints + def_pattern_state.vars.push(*pattern_var); + + let pattern_con = constraints.equal_types_var( + *pattern_var, + Expected::NoExpectation(ann.clone()), + Category::Storage(std::file!(), std::line!()), + loc_pattern.region, + ); + + def_pattern_state.constraints.push(pattern_con); + } + } else { + // We need to check the types, and run exhaustiveness checking. + let &AnnotatedMark { + annotation_var, + exhaustive, + } = annotated_mark; + + def_pattern_state.vars.push(*pattern_var); + def_pattern_state.vars.push(annotation_var); + + { + // First, solve the type that the pattern is expecting to match in this + // position. + let pattern_expected = PExpected::NoExpectation(Type::Variable(*pattern_var)); + constrain_pattern( + constraints, + env, + &loc_pattern.value, + loc_pattern.region, + pattern_expected, + argument_pattern_state, + ); + } + + { + // Store the actual type in a variable. + argument_pattern_state + .constraints + .push(constraints.equal_types_var( + annotation_var, + Expected::NoExpectation(ann.clone()), + Category::Storage(file!(), line!()), + Region::zero(), + )); + } + + { + // let pattern_expected = PExpected::ForReason( + // PReason::TypedArg { + // index: HumanIndex::zero_based(index), + // opt_name: opt_label, + // }, + // ann.clone(), + // loc_pattern.region, + // ); + + // Exhaustiveness-check the type in the pattern against what the + // annotation wants. + let sketched_rows = + sketch_pattern_to_rows(annotation_var, loc_pattern.region, &loc_pattern.value); + let category = loc_pattern.value.category(); + let expected = PExpected::ForReason( + PReason::TypedArg { + index: HumanIndex::zero_based(index), + opt_name: opt_label, + }, + Type::Variable(*pattern_var), + loc_pattern.region, + ); + let exhaustive_constraint = constraints.exhaustive( + annotation_var, + loc_pattern.region, + Err((category, expected)), + sketched_rows, + ExhaustiveContext::BadArg, + exhaustive, + ); + argument_pattern_state + .constraints + .push(exhaustive_constraint) + } } } } @@ -1894,7 +1974,6 @@ pub fn rec_defs_help( delayed_is_open_constraints: vec![], }; let mut vars = Vec::with_capacity(state.vars.capacity() + 1); - let mut pattern_types = Vec::with_capacity(state.vars.capacity()); let ret_var = *ret_var; let closure_var = *closure_var; let closure_ext_var = *closure_ext_var; @@ -1904,53 +1983,16 @@ pub fn rec_defs_help( vars.push(closure_var); vars.push(closure_ext_var); - let it = arguments.iter().zip(arg_types.iter()).enumerate(); - for (index, ((pattern_var, loc_pattern), loc_ann)) in it { - { - // ensure type matches the one in the annotation - let opt_label = - if let Pattern::Identifier(label) = def.loc_pattern.value { - Some(label) - } else { - None - }; - let pattern_type: &Type = loc_ann; - - let pattern_expected = PExpected::ForReason( - PReason::TypedArg { - index: HumanIndex::zero_based(index), - opt_name: opt_label, - }, - pattern_type.clone(), - loc_pattern.region, - ); - - constrain_pattern( - constraints, - env, - &loc_pattern.value, - loc_pattern.region, - pattern_expected, - &mut state, - ); - } - - { - // NOTE: because we perform an equality with part of the signature - // this constraint must be to the def_pattern_state's constraints - def_pattern_state.vars.push(*pattern_var); - pattern_types.push(Type::Variable(*pattern_var)); - - let pattern_con = constraints.equal_types_var( - *pattern_var, - Expected::NoExpectation(loc_ann.clone()), - Category::Storage(std::file!(), std::line!()), - loc_pattern.region, - ); - - def_pattern_state.constraints.push(pattern_con); - } - } + constrain_typed_function_arguments( + constraints, + env, + def, + &mut def_pattern_state, + &mut state, + &arguments, + &arg_types, + ); + let pattern_types = arguments.iter().map(|a| Type::Variable(a.0)).collect(); let closure_constraint = constrain_closure_size( constraints, diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 94b030dab0..36ae0bc12b 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -8,7 +8,7 @@ use bumpalo::collections::Vec; use bumpalo::Bump; use roc_builtins::bitcode::{FloatWidth, IntWidth}; use roc_can::abilities::AbilitiesStore; -use roc_can::expr::{ClosureData, IntValue}; +use roc_can::expr::{AnnotatedMark, ClosureData, IntValue}; use roc_collections::all::{default_hasher, BumpMap, BumpMapDefault, MutMap}; use roc_exhaustive::{Ctor, CtorName, Guard, RenderAs, TagId}; use roc_module::ident::{ForeignSymbol, Lowercase, TagName}; @@ -209,7 +209,7 @@ impl<'a> PartialProc<'a> { env: &mut Env<'a, '_>, layout_cache: &mut LayoutCache<'a>, annotation: Variable, - loc_args: std::vec::Vec<(Variable, Loc)>, + loc_args: std::vec::Vec<(Variable, AnnotatedMark, Loc)>, loc_body: Loc, captured_symbols: CapturedSymbols<'a>, is_self_recursive: bool, @@ -858,7 +858,7 @@ impl<'a> Procs<'a> { env: &mut Env<'a, '_>, symbol: Symbol, annotation: Variable, - loc_args: std::vec::Vec<(Variable, Loc)>, + loc_args: std::vec::Vec<(Variable, AnnotatedMark, Loc)>, loc_body: Loc, captured_symbols: CapturedSymbols<'a>, ret_var: Variable, @@ -1938,8 +1938,9 @@ impl<'a> Stmt<'a> { #[allow(clippy::type_complexity)] fn patterns_to_when<'a>( env: &mut Env<'a, '_>, - layout_cache: &mut LayoutCache<'a>, - patterns: std::vec::Vec<(Variable, Loc)>, + // TODO REMOVE ME + _layout_cache: &mut LayoutCache<'a>, + patterns: std::vec::Vec<(Variable, AnnotatedMark, Loc)>, body_var: Variable, body: Loc, ) -> Result<(Vec<'a, Variable>, Vec<'a, Symbol>, Loc), Loc> { @@ -1954,66 +1955,26 @@ fn patterns_to_when<'a>( // NOTE this fails if the pattern contains rigid variables, // see https://github.com/rtfeldman/roc/issues/786 // this must be fixed when moving exhaustiveness checking to the new canonical AST - for (pattern_var, pattern) in patterns.into_iter() { - let context = roc_exhaustive::Context::BadArg; - let mono_pattern = match from_can_pattern(env, layout_cache, &pattern.value) { - Ok((pat, _assignments)) => { - // Don't apply any assignments (e.g. to initialize optional variables) yet. - // We'll take care of that later when expanding the new "when" branch. - pat - } - Err(runtime_error) => { - // Even if the body was Ok, replace it with this Err. - // If it was already an Err, leave it at that Err, so the first - // RuntimeError we encountered remains the first. - body = body.and({ - Err(Loc { - region: pattern.region, - value: runtime_error, - }) - }); + for (pattern_var, annotated_mark, pattern) in patterns.into_iter() { + if annotated_mark.exhaustive.is_non_exhaustive(env.subs) { + // Even if the body was Ok, replace it with this Err. + // If it was already an Err, leave it at that Err, so the first + // RuntimeError we encountered remains the first. + let value = RuntimeError::UnsupportedPattern(pattern.region); + body = body.and({ + Err(Loc { + region: pattern.region, + value, + }) + }); + } else if let Ok(unwrapped_body) = body { + let (new_symbol, new_body) = + pattern_to_when(env, pattern_var, pattern, body_var, unwrapped_body); - continue; - } - }; + symbols.push(new_symbol); + arg_vars.push(pattern_var); - match crate::exhaustive::check( - pattern.region, - &[( - Loc::at(pattern.region, mono_pattern), - roc_exhaustive::Guard::NoGuard, - )], - context, - ) { - Ok(_) => { - // Replace the body with a new one, but only if it was Ok. - if let Ok(unwrapped_body) = body { - let (new_symbol, new_body) = - pattern_to_when(env, pattern_var, pattern, body_var, unwrapped_body); - - symbols.push(new_symbol); - arg_vars.push(pattern_var); - - body = Ok(new_body) - } - } - Err(errors) => { - for error in errors { - env.problems.push(MonoProblem::PatternProblem(error)) - } - - let value = RuntimeError::UnsupportedPattern(pattern.region); - - // Even if the body was Ok, replace it with this Err. - // If it was already an Err, leave it at that Err, so the first - // RuntimeError we encountered remains the first. - body = body.and({ - Err(Loc { - region: pattern.region, - value, - }) - }); - } + body = Ok(new_body) } } @@ -5184,7 +5145,7 @@ fn tag_union_to_function<'a>( let loc_expr = Loc::at_zero(roc_can::expr::Expr::Var(arg_symbol)); - loc_pattern_args.push((arg_var, loc_pattern)); + loc_pattern_args.push((arg_var, AnnotatedMark::known_exhaustive(), loc_pattern)); loc_expr_args.push((arg_var, loc_expr)); } diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index b93e534bfe..92488b6f3a 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -1184,19 +1184,39 @@ fn solve( // 4. Condition and branch types aren't "almost equal", this is just a normal type // error. - let roc_can::constraint::Eq( - real_var, - expected_branches, - real_category, - real_region, - ) = constraints.eq[eq.index()]; + let (real_var, real_region, expected_type, category_and_expected) = match eq { + Ok(eq) => { + let roc_can::constraint::Eq(real_var, expected, category, real_region) = + constraints.eq[eq.index()]; + let expected = &constraints.expectations[expected.index()]; + ( + real_var, + real_region, + expected.get_type_ref(), + Ok((category, expected)), + ) + } + Err(peq) => { + let roc_can::constraint::PatternEq( + real_var, + expected, + category, + real_region, + ) = constraints.pattern_eq[peq.index()]; + let expected = &constraints.pattern_expectations[expected.index()]; + ( + real_var, + real_region, + expected.get_type_ref(), + Err((category, expected)), + ) + } + }; let real_var = either_type_index_to_var(constraints, subs, rank, pools, aliases, real_var); - let expected_branches = &constraints.expectations[expected_branches.index()]; - let branches_var = - type_to_var(subs, rank, pools, aliases, expected_branches.get_type_ref()); + let branches_var = type_to_var(subs, rank, pools, aliases, expected_type); let real_content = subs.get_content_without_compacting(real_var); let branches_content = subs.get_content_without_compacting(branches_var); @@ -1256,14 +1276,32 @@ fn solve( Failure(vars, actual_type, expected_type, _bad_impls) => { introduce(subs, rank, pools, &vars); - let real_category = - constraints.categories[real_category.index()].clone(); - let problem = TypeError::BadExpr( - real_region, - real_category, - actual_type, - expected_branches.replace_ref(expected_type), - ); + // Figure out the problem - it might be pattern or value + // related. + let problem = match category_and_expected { + Ok((category, expected)) => { + let real_category = + constraints.categories[category.index()].clone(); + TypeError::BadExpr( + real_region, + real_category, + actual_type, + expected.replace_ref(expected_type), + ) + } + + Err((category, expected)) => { + let real_category = constraints.pattern_categories + [category.index()] + .clone(); + TypeError::BadPattern( + real_region, + real_category, + expected_type, + expected.replace_ref(actual_type), + ) + } + }; problems.push(problem); should_check_exhaustiveness = false; diff --git a/compiler/types/src/types.rs b/compiler/types/src/types.rs index 28d309d663..3f7e26e923 100644 --- a/compiler/types/src/types.rs +++ b/compiler/types/src/types.rs @@ -1731,6 +1731,10 @@ pub enum Reason { name: Option, arg_index: HumanIndex, }, + TypedArg { + name: Option, + arg_index: HumanIndex, + }, FnCall { name: Option, arity: u8, diff --git a/reporting/src/error/type.rs b/reporting/src/error/type.rs index 0a63726159..9fbdd6eb2e 100644 --- a/reporting/src/error/type.rs +++ b/reporting/src/error/type.rs @@ -1204,6 +1204,43 @@ fn to_expr_report<'b>( } } + Reason::TypedArg { name, arg_index } => { + let name = match name { + Some(n) => alloc.symbol_unqualified(n), + None => alloc.text(" this definition "), + }; + let doc = alloc.stack([ + alloc + .text("The ") + .append(alloc.text(arg_index.ordinal())) + .append(alloc.text(" argument to ")) + .append(name.clone()) + .append(alloc.text(" is weird:")), + alloc.region(lines.convert_region(region)), + pattern_type_comparison( + alloc, + expected_type, + found, + add_category(alloc, alloc.text("The argument matches"), &category), + alloc.concat([ + alloc.text("But the annotation on "), + name, + alloc.text(" says the "), + alloc.text(arg_index.ordinal()), + alloc.text(" argument should be:"), + ]), + vec![], + ), + ]); + + Report { + filename, + title: "TYPE MISMATCH".to_string(), + doc, + severity: Severity::RuntimeError, + } + } + Reason::LowLevelOpArg { op, arg_index } => { panic!( "Compiler bug: argument #{} to low-level operation {:?} was the wrong type!", @@ -2312,7 +2349,6 @@ fn to_diff<'b>( // Skip the hint for numbers; it's not as useful as saying "this type is not a number" if !OPAQUE_NUM_SYMBOLS.contains(&sym) => { - dbg!(&type1, &type2); let (left, left_able) = to_doc(alloc, Parens::InFn, type1); let (right, right_able) = to_doc(alloc, Parens::InFn, type2); diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 095417f6bf..90c7638b12 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -8487,16 +8487,16 @@ I need all branches in an `if` to have the same type! r#" ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ - This pattern is being used in an unexpected way: + The 1st argument to `f` is weird: 4│ f = \Age n -> n ^^^^^ - It is a `Age` tag of type: + The argument is a pattern that matches a `Age` tag of type: [ Age a ] - But it needs to match: + But the annotation on `f` says the 1st argument should be: Age From ae0c0fe8feedad04728e24bd79126ce06b2b2fdb Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 28 Apr 2022 14:06:44 -0400 Subject: [PATCH 675/846] Simplify --- compiler/mono/src/ir.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 36ae0bc12b..a5f583b582 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -217,7 +217,7 @@ impl<'a> PartialProc<'a> { ) -> PartialProc<'a> { let number_of_arguments = loc_args.len(); - match patterns_to_when(env, layout_cache, loc_args, ret_var, loc_body) { + match patterns_to_when(env, loc_args, ret_var, loc_body) { Ok((_, pattern_symbols, body)) => { // a named closure. Since these aren't specialized by the surrounding // context, we can't add pending specializations for them yet. @@ -877,7 +877,7 @@ impl<'a> Procs<'a> { _ => false, }; - match patterns_to_when(env, layout_cache, loc_args, ret_var, loc_body) { + match patterns_to_when(env, loc_args, ret_var, loc_body) { Ok((_, pattern_symbols, body)) => { // an anonymous closure. These will always be specialized already // by the surrounding context, so we can add pending specializations @@ -1938,8 +1938,6 @@ impl<'a> Stmt<'a> { #[allow(clippy::type_complexity)] fn patterns_to_when<'a>( env: &mut Env<'a, '_>, - // TODO REMOVE ME - _layout_cache: &mut LayoutCache<'a>, patterns: std::vec::Vec<(Variable, AnnotatedMark, Loc)>, body_var: Variable, body: Loc, From 1af207325e9e2d9ec99af31617ce574297c495f9 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 28 Apr 2022 14:07:30 -0400 Subject: [PATCH 676/846] Simplify again --- compiler/mono/src/ir.rs | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index a5f583b582..556daab829 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -207,7 +207,6 @@ impl<'a> PartialProc<'a> { #[allow(clippy::too_many_arguments)] pub fn from_named_function( env: &mut Env<'a, '_>, - layout_cache: &mut LayoutCache<'a>, annotation: Variable, loc_args: std::vec::Vec<(Variable, AnnotatedMark, Loc)>, loc_body: Loc, @@ -3225,7 +3224,7 @@ pub fn with_hole<'a>( LetNonRec(def, cont, _) => { if let roc_can::pattern::Pattern::Identifier(symbol) = def.loc_pattern.value { if let Closure(closure_data) = def.loc_expr.value { - register_noncapturing_closure(env, procs, layout_cache, symbol, closure_data); + register_noncapturing_closure(env, procs, symbol, closure_data); return with_hole( env, @@ -3368,13 +3367,7 @@ pub fn with_hole<'a>( for def in defs.into_iter() { if let roc_can::pattern::Pattern::Identifier(symbol) = &def.loc_pattern.value { if let Closure(closure_data) = def.loc_expr.value { - register_noncapturing_closure( - env, - procs, - layout_cache, - *symbol, - closure_data, - ); + register_noncapturing_closure(env, procs, *symbol, closure_data); continue; } @@ -5245,7 +5238,6 @@ fn sorted_field_symbols<'a>( fn register_noncapturing_closure<'a>( env: &mut Env<'a, '_>, procs: &mut Procs<'a>, - layout_cache: &mut LayoutCache<'a>, closure_name: Symbol, closure_data: ClosureData, ) { @@ -5273,7 +5265,6 @@ fn register_noncapturing_closure<'a>( let partial_proc = PartialProc::from_named_function( env, - layout_cache, function_type, arguments, loc_body, @@ -5357,7 +5348,6 @@ fn register_capturing_closure<'a>( let partial_proc = PartialProc::from_named_function( env, - layout_cache, function_type, arguments, loc_body, @@ -5549,7 +5539,6 @@ pub fn from_can<'a>( register_noncapturing_closure( env, procs, - layout_cache, *symbol, accessor_data.to_closure_data(fresh_record_symbol), ); From 907cbdc3a732813ff4191e3837e7204b926f2935 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 28 Apr 2022 14:08:43 -0400 Subject: [PATCH 677/846] Compile fix --- compiler/load_internal/src/file.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index 633da66ad6..4e88ce1c3e 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -4292,7 +4292,6 @@ fn add_def_to_module<'a>( let partial_proc = PartialProc::from_named_function( mono_env, - layout_cache, annotation, loc_args, *loc_body, From 2cc47f184fc546ea9ad482f249a93318815a483b Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 28 Apr 2022 14:24:15 -0400 Subject: [PATCH 678/846] Remove unncessary variable introduction --- compiler/constrain/src/expr.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/compiler/constrain/src/expr.rs b/compiler/constrain/src/expr.rs index c79263c164..a716cf6dd8 100644 --- a/compiler/constrain/src/expr.rs +++ b/compiler/constrain/src/expr.rs @@ -1183,9 +1183,10 @@ fn constrain_when_branch_help( delayed_is_open_constraints: Vec::new(), }; - state - .vars - .push(when_branch.redundant.variable_for_introduction()); + // TODO: can i remove this? + // state + // .vars + // .push(when_branch.redundant.variable_for_introduction()); // TODO investigate for error messages, is it better to unify all branches with a variable, // then unify that variable with the expectation? From 12234c36ade740c97b21d4824a4ea3f2dc4740bb Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 28 Apr 2022 14:26:24 -0400 Subject: [PATCH 679/846] Remove unnecessary var introduction --- compiler/constrain/src/expr.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/compiler/constrain/src/expr.rs b/compiler/constrain/src/expr.rs index a716cf6dd8..c4c69b6208 100644 --- a/compiler/constrain/src/expr.rs +++ b/compiler/constrain/src/expr.rs @@ -1183,11 +1183,6 @@ fn constrain_when_branch_help( delayed_is_open_constraints: Vec::new(), }; - // TODO: can i remove this? - // state - // .vars - // .push(when_branch.redundant.variable_for_introduction()); - // TODO investigate for error messages, is it better to unify all branches with a variable, // then unify that variable with the expectation? for (i, loc_pattern) in when_branch.patterns.iter().enumerate() { From c969c7a15eb1c5723d0e209e02f189e8fbe0499e Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 28 Apr 2022 14:28:34 -0400 Subject: [PATCH 680/846] Remove more exhaustiveness checks in mono --- compiler/mono/src/ir.rs | 37 ------------------------------------- 1 file changed, 37 deletions(-) diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 556daab829..751c38fe4f 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -3310,24 +3310,6 @@ pub fn with_hole<'a>( } }; - let context = roc_exhaustive::Context::BadDestruct; - match crate::exhaustive::check( - def.loc_pattern.region, - &[( - Loc::at(def.loc_pattern.region, mono_pattern.clone()), - roc_exhaustive::Guard::NoGuard, - )], - context, - ) { - Ok(_) => {} - Err(errors) => { - for error in errors { - env.problems.push(MonoProblem::PatternProblem(error)) - } - } // TODO make all variables bound in the pattern evaluate to a runtime error - // return Stmt::RuntimeError("TODO non-exhaustive pattern"); - } - let mut hole = hole; for (symbol, variable, expr) in assignments { @@ -5720,25 +5702,6 @@ pub fn from_can<'a>( hole, ) } else { - let context = roc_exhaustive::Context::BadDestruct; - match crate::exhaustive::check( - def.loc_pattern.region, - &[( - Loc::at(def.loc_pattern.region, mono_pattern.clone()), - roc_exhaustive::Guard::NoGuard, - )], - context, - ) { - Ok(_) => {} - Err(errors) => { - for error in errors { - env.problems.push(MonoProblem::PatternProblem(error)) - } - - return Stmt::RuntimeError("TODO non-exhaustive pattern"); - } - } - // convert the continuation let mut stmt = from_can(env, variable, cont.value, procs, layout_cache); From 89757dc31ffd0f4335e199f426d667cdaef28a1d Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 28 Apr 2022 14:46:17 -0400 Subject: [PATCH 681/846] Remove MonoProblem --- Cargo.lock | 1 - compiler/build/src/program.rs | 29 +--- compiler/load_internal/src/file.rs | 7 - repl_eval/src/gen.rs | 15 +- reporting/Cargo.toml | 1 - reporting/src/error/mod.rs | 1 - reporting/src/error/mono.rs | 235 ----------------------------- reporting/src/report.rs | 1 - reporting/tests/test_reporting.rs | 130 ++-------------- 9 files changed, 12 insertions(+), 408 deletions(-) delete mode 100644 reporting/src/error/mono.rs diff --git a/Cargo.lock b/Cargo.lock index fcbcb4e2da..c5e3621ba0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3937,7 +3937,6 @@ dependencies = [ "roc_exhaustive", "roc_load", "roc_module", - "roc_mono", "roc_parse", "roc_problem", "roc_region", diff --git a/compiler/build/src/program.rs b/compiler/build/src/program.rs index 62a965d8aa..a9d595bdf0 100644 --- a/compiler/build/src/program.rs +++ b/compiler/build/src/program.rs @@ -24,10 +24,6 @@ pub struct CodeGenTiming { #[cfg(feature = "llvm")] const LLVM_VERSION: &str = "12"; -// TODO instead of finding exhaustiveness problems in monomorphization, find -// them after type checking (like Elm does) so we can complete the entire -// `roc check` process without needing to monomorphize. -/// Returns the number of problems reported. pub fn report_problems_monomorphized(loaded: &mut MonomorphizedModule) -> Problems { report_problems_help( loaded.total_problems(), @@ -35,7 +31,6 @@ pub fn report_problems_monomorphized(loaded: &mut MonomorphizedModule) -> Proble &loaded.interns, &mut loaded.can_problems, &mut loaded.type_problems, - &mut loaded.mono_problems, ) } @@ -46,7 +41,6 @@ pub fn report_problems_typechecked(loaded: &mut LoadedModule) -> Problems { &loaded.interns, &mut loaded.can_problems, &mut loaded.type_problems, - &mut Default::default(), ) } @@ -73,11 +67,9 @@ fn report_problems_help( interns: &Interns, can_problems: &mut MutMap>, type_problems: &mut MutMap>, - mono_problems: &mut MutMap>, ) -> Problems { use roc_reporting::report::{ - can_problem, mono_problem, type_problem, Report, RocDocAllocator, Severity::*, - DEFAULT_PALETTE, + can_problem, type_problem, Report, RocDocAllocator, Severity::*, DEFAULT_PALETTE, }; let palette = DEFAULT_PALETTE; @@ -134,25 +126,6 @@ fn report_problems_help( } } } - - let problems = mono_problems.remove(home).unwrap_or_default(); - - for problem in problems { - let report = mono_problem(&alloc, &lines, module_path.clone(), problem); - let severity = report.severity; - let mut buf = String::new(); - - report.render_color_terminal(&mut buf, &alloc, &palette); - - match severity { - Warning => { - warnings.push(buf); - } - RuntimeError => { - errors.push(buf); - } - } - } } let problems_reported; diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index 4e88ce1c3e..7389ee4e5f 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -519,7 +519,6 @@ pub struct MonomorphizedModule<'a> { pub platform_path: Box, pub can_problems: MutMap>, pub type_problems: MutMap>, - pub mono_problems: MutMap>, pub procedures: MutMap<(Symbol, ProcLayout<'a>), Proc<'a>>, pub entry_point: EntryPoint<'a>, pub exposed_to_host: ExposedToHost, @@ -547,10 +546,6 @@ impl<'a> MonomorphizedModule<'a> { total += problems.len(); } - for problems in self.mono_problems.values() { - total += problems.len(); - } - total } } @@ -2321,7 +2316,6 @@ fn finish_specialization( } = state; let ModuleCache { - mono_problems, type_problems, can_problems, sources, @@ -2384,7 +2378,6 @@ fn finish_specialization( Ok(MonomorphizedModule { can_problems, - mono_problems, type_problems, output_path: output_path.unwrap_or(DEFAULT_APP_OUTPUT_PATH).into(), platform_path, diff --git a/repl_eval/src/gen.rs b/repl_eval/src/gen.rs index efe32c4ca1..3c50ffa14d 100644 --- a/repl_eval/src/gen.rs +++ b/repl_eval/src/gen.rs @@ -7,7 +7,7 @@ use roc_fmt::annotation::{Newlines, Parens}; use roc_load::{LoadingProblem, MonomorphizedModule}; use roc_parse::ast::Expr; use roc_region::all::LineInfo; -use roc_reporting::report::{can_problem, mono_problem, type_problem, RocDocAllocator}; +use roc_reporting::report::{can_problem, type_problem, RocDocAllocator}; use roc_target::TargetInfo; use crate::eval::ToAstProblem; @@ -78,7 +78,6 @@ pub fn compile_to_mono<'a>( sources, can_problems, type_problems, - mono_problems, .. } = &mut loaded; @@ -87,9 +86,8 @@ pub fn compile_to_mono<'a>( for (home, (module_path, src)) in sources.iter() { let can_probs = can_problems.remove(home).unwrap_or_default(); let type_probs = type_problems.remove(home).unwrap_or_default(); - let mono_probs = mono_problems.remove(home).unwrap_or_default(); - let error_count = can_probs.len() + type_probs.len() + mono_probs.len(); + let error_count = can_probs.len() + type_probs.len(); if error_count == 0 { continue; @@ -119,15 +117,6 @@ pub fn compile_to_mono<'a>( lines.push(buf); } } - - for problem in mono_probs { - let report = mono_problem(&alloc, &line_info, module_path.clone(), problem); - let mut buf = String::new(); - - report.render_color_terminal(&mut buf, &alloc, &palette); - - lines.push(buf); - } } if !lines.is_empty() { diff --git a/reporting/Cargo.toml b/reporting/Cargo.toml index 63e16ad7c3..1c107cf580 100644 --- a/reporting/Cargo.toml +++ b/reporting/Cargo.toml @@ -15,7 +15,6 @@ roc_problem = { path = "../compiler/problem" } roc_types = { path = "../compiler/types" } roc_can = { path = "../compiler/can" } roc_solve = { path = "../compiler/solve" } -roc_mono = { path = "../compiler/mono" } ven_pretty = { path = "../vendor/pretty" } distance = "0.4.0" bumpalo = { version = "3.8.0", features = ["collections"] } diff --git a/reporting/src/error/mod.rs b/reporting/src/error/mod.rs index 2bf7e77288..88379cf382 100644 --- a/reporting/src/error/mod.rs +++ b/reporting/src/error/mod.rs @@ -1,4 +1,3 @@ pub mod canonicalize; -pub mod mono; pub mod parse; pub mod r#type; diff --git a/reporting/src/error/mono.rs b/reporting/src/error/mono.rs deleted file mode 100644 index 5326e1379b..0000000000 --- a/reporting/src/error/mono.rs +++ /dev/null @@ -1,235 +0,0 @@ -use crate::report::{Annotation, Report, RocDocAllocator, RocDocBuilder, Severity}; -use roc_module::ident::TagName; -use roc_region::all::LineInfo; -use std::path::PathBuf; -use ven_pretty::DocAllocator; - -pub fn mono_problem<'b>( - alloc: &'b RocDocAllocator<'b>, - lines: &LineInfo, - filename: PathBuf, - problem: roc_mono::ir::MonoProblem, -) -> Report<'b> { - use roc_exhaustive::Context::*; - use roc_exhaustive::Error::*; - use roc_mono::ir::MonoProblem::*; - - match problem { - PatternProblem(Incomplete(region, context, missing)) => match context { - BadArg => { - let doc = alloc.stack([ - alloc.reflow("This pattern does not cover all the possibilities:"), - alloc.region(lines.convert_region(region)), - alloc.reflow("Other possibilities include:"), - unhandled_patterns_to_doc_block(alloc, missing), - alloc.concat([ - alloc.reflow( - "I would have to crash if I saw one of those! \ - So rather than pattern matching in function arguments, put a ", - ), - alloc.keyword("when"), - alloc.reflow(" in the function body to account for all possibilities."), - ]), - ]); - - Report { - filename, - title: "UNSAFE PATTERN".to_string(), - doc, - severity: Severity::RuntimeError, - } - } - BadDestruct => { - let doc = alloc.stack([ - alloc.reflow("This pattern does not cover all the possibilities:"), - alloc.region(lines.convert_region(region)), - alloc.reflow("Other possibilities include:"), - unhandled_patterns_to_doc_block(alloc, missing), - alloc.concat([ - alloc.reflow( - "I would have to crash if I saw one of those! \ - You can use a binding to deconstruct a value if there is only ONE possibility. \ - Use a " - ), - alloc.keyword("when"), - alloc.reflow(" to account for all possibilities."), - ]), - ]); - - Report { - filename, - title: "UNSAFE PATTERN".to_string(), - doc, - severity: Severity::RuntimeError, - } - } - BadCase => { - let doc = alloc.stack([ - alloc.concat([ - alloc.reflow("This "), - alloc.keyword("when"), - alloc.reflow(" does not cover all the possibilities:"), - ]), - alloc.region(lines.convert_region(region)), - alloc.reflow("Other possibilities include:"), - unhandled_patterns_to_doc_block(alloc, missing), - alloc.reflow( - "I would have to crash if I saw one of those! \ - Add branches for them!", - ), - // alloc.hint().append(alloc.reflow("or use a hole.")), - ]); - - Report { - filename, - title: "UNSAFE PATTERN".to_string(), - doc, - severity: Severity::RuntimeError, - } - } - }, - PatternProblem(Redundant { - overall_region, - branch_region, - index, - }) => { - let doc = alloc.stack([ - alloc.concat([ - alloc.reflow("The "), - alloc.string(index.ordinal()), - alloc.reflow(" pattern is redundant:"), - ]), - alloc.region_with_subregion( - lines.convert_region(overall_region), - lines.convert_region(branch_region), - ), - alloc.reflow( - "Any value of this shape will be handled by \ - a previous pattern, so this one should be removed.", - ), - ]); - - Report { - filename, - title: "REDUNDANT PATTERN".to_string(), - doc, - severity: Severity::Warning, - } - } - } -} - -pub fn unhandled_patterns_to_doc_block<'b>( - alloc: &'b RocDocAllocator<'b>, - patterns: Vec, -) -> RocDocBuilder<'b> { - alloc - .vcat(patterns.into_iter().map(|v| pattern_to_doc(alloc, v))) - .indent(4) - .annotate(Annotation::TypeBlock) -} - -fn pattern_to_doc<'b>( - alloc: &'b RocDocAllocator<'b>, - pattern: roc_exhaustive::Pattern, -) -> RocDocBuilder<'b> { - pattern_to_doc_help(alloc, pattern, false) -} - -const AFTER_TAG_INDENT: &str = " "; - -fn pattern_to_doc_help<'b>( - alloc: &'b RocDocAllocator<'b>, - pattern: roc_exhaustive::Pattern, - in_type_param: bool, -) -> RocDocBuilder<'b> { - use roc_exhaustive::Literal::*; - use roc_exhaustive::Pattern::*; - use roc_exhaustive::{CtorName, RenderAs}; - - match pattern { - Anything => alloc.text("_"), - Literal(l) => match l { - Int(i) => alloc.text(i.to_string()), - U128(i) => alloc.text(i.to_string()), - Bit(true) => alloc.text("True"), - Bit(false) => alloc.text("False"), - Byte(b) => alloc.text(b.to_string()), - Float(f) => alloc.text(f.to_string()), - Decimal(d) => alloc.text(d.to_string()), - Str(s) => alloc.string(s.into()), - }, - Ctor(union, tag_id, args) => { - match union.render_as { - RenderAs::Guard => { - // #Guard - debug_assert!(union.alternatives[tag_id.0 as usize] - .name - .is_tag(&TagName::Tag("#Guard".into())),); - debug_assert!(args.len() == 2); - let tag = pattern_to_doc_help(alloc, args[1].clone(), in_type_param); - alloc.concat([ - tag, - alloc.text(AFTER_TAG_INDENT), - alloc.text("(note the lack of an "), - alloc.keyword("if"), - alloc.text(" clause)"), - ]) - } - RenderAs::Record(field_names) => { - let mut arg_docs = Vec::with_capacity(args.len()); - - for (label, v) in field_names.into_iter().zip(args.into_iter()) { - match &v { - Anything => { - arg_docs.push(alloc.text(label.to_string())); - } - Literal(_) | Ctor(_, _, _) => { - arg_docs.push( - alloc - .text(label.to_string()) - .append(alloc.reflow(": ")) - .append(pattern_to_doc_help(alloc, v, false)), - ); - } - } - } - - alloc - .text("{ ") - .append(alloc.intersperse(arg_docs, alloc.reflow(", "))) - .append(" }") - } - RenderAs::Tag | RenderAs::Opaque => { - let has_args = !args.is_empty(); - let arg_docs = args - .into_iter() - .map(|v| pattern_to_doc_help(alloc, v, true)); - - let ctor = &union.alternatives[tag_id.0 as usize]; - let tag_name = match (union.render_as, &ctor.name) { - (RenderAs::Tag, CtorName::Tag(tag)) => alloc.tag_name(tag.clone()), - (RenderAs::Opaque, CtorName::Opaque(opaque)) => { - alloc.wrapped_opaque_name(*opaque) - } - _ => unreachable!(), - }; - - // We assume the alternatives are sorted. If not, this assert will trigger - debug_assert!(tag_id == ctor.tag_id); - - let docs = std::iter::once(tag_name).chain(arg_docs); - - if in_type_param && has_args { - alloc - .text("(") - .append(alloc.intersperse(docs, alloc.space())) - .append(")") - } else { - alloc.intersperse(docs, alloc.space()) - } - } - } - } - } -} diff --git a/reporting/src/report.rs b/reporting/src/report.rs index ad6f6b2014..0fe8fe4213 100644 --- a/reporting/src/report.rs +++ b/reporting/src/report.rs @@ -7,7 +7,6 @@ use std::path::{Path, PathBuf}; use ven_pretty::{BoxAllocator, DocAllocator, DocBuilder, Render, RenderAnnotated}; pub use crate::error::canonicalize::can_problem; -pub use crate::error::mono::mono_problem; pub use crate::error::parse::parse_problem; pub use crate::error::r#type::type_problem; diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index 90c7638b12..a88ad14ecb 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -12,16 +12,12 @@ mod test_reporting { use bumpalo::Bump; use indoc::indoc; use roc_can::abilities::AbilitiesStore; - use roc_can::def::Declaration; - use roc_can::pattern::Pattern; use roc_load::{self, LoadedModule, LoadingProblem}; use roc_module::symbol::{Interns, ModuleId}; - use roc_mono::ir::{Procs, Stmt, UpdateModeIds}; - use roc_mono::layout::LayoutCache; use roc_region::all::LineInfo; use roc_reporting::report::{ - can_problem, mono_problem, parse_problem, type_problem, RenderTarget, Report, Severity, - ANSI_STYLE_CODES, DEFAULT_PALETTE, + can_problem, parse_problem, type_problem, RenderTarget, Report, Severity, ANSI_STYLE_CODES, + DEFAULT_PALETTE, }; use roc_reporting::report::{RocDocAllocator, RocDocBuilder}; use roc_solve::solve; @@ -114,7 +110,6 @@ mod test_reporting { String, Vec, Vec, - Vec, ModuleId, Interns, ), @@ -128,8 +123,6 @@ mod test_reporting { interns, mut solved, exposed_to_host, - mut declarations_by_id, - abilities_store, .. } = result?; @@ -142,65 +135,7 @@ mod test_reporting { name_all_type_vars(*var, subs); } - let mut mono_problems = Vec::new(); - - // MONO - - if type_problems.is_empty() && can_problems.is_empty() { - let arena = Bump::new(); - - assert!(exposed_to_host.len() == 1); - let (sym, _var) = exposed_to_host.into_iter().next().unwrap(); - - let home_decls = declarations_by_id.remove(&home).unwrap(); - let (loc_expr, var) = home_decls - .into_iter() - .find_map(|decl| match decl { - Declaration::Declare(def) => match def.loc_pattern.value { - Pattern::Identifier(s) if s == sym => Some((def.loc_expr, def.expr_var)), - _ => None, - }, - _ => None, - }) - .expect("No expression to monomorphize found!"); - - // Compile and add all the Procs before adding main - let mut procs = Procs::new_in(&arena); - let mut ident_ids = interns.all_ident_ids.get(&home).unwrap().clone(); - let mut update_mode_ids = UpdateModeIds::new(); - - // Populate Procs and Subs, and get the low-level Expr from the canonical Expr - let target_info = roc_target::TargetInfo::default_x86_64(); - let mut layout_cache = LayoutCache::new(target_info); - let mut mono_env = roc_mono::ir::Env { - arena: &arena, - subs, - problems: &mut mono_problems, - home, - ident_ids: &mut ident_ids, - update_mode_ids: &mut update_mode_ids, - target_info, - // call_specialization_counter=0 is reserved - call_specialization_counter: 1, - abilities_store: &abilities_store, - }; - let _mono_expr = Stmt::new( - &mut mono_env, - loc_expr.value, - var, - &mut procs, - &mut layout_cache, - ); - } - - Ok(( - module_src, - type_problems, - can_problems, - mono_problems, - home, - interns, - )) + Ok((module_src, type_problems, can_problems, home, interns)) } fn list_reports_new(subdir: &str, arena: &Bump, src: &str, finalize_render: F) -> String @@ -215,7 +150,7 @@ mod test_reporting { match infer_expr_help_new(subdir, arena, src) { Err(LoadingProblem::FormattedReport(fail)) => fail, - Ok((module_src, type_problems, can_problems, mono_problems, home, interns)) => { + Ok((module_src, type_problems, can_problems, home, interns)) => { let lines = LineInfo::new(&module_src); let src_lines: Vec<&str> = module_src.split('\n').collect(); let mut reports = Vec::new(); @@ -235,11 +170,6 @@ mod test_reporting { } } - for problem in mono_problems { - let report = mono_problem(&alloc, &lines, filename.clone(), problem.clone()); - reports.push(report); - } - let has_reports = !reports.is_empty(); let doc = alloc @@ -267,14 +197,13 @@ mod test_reporting { ( Vec, Vec, - Vec, ModuleId, Interns, ), ParseErrOut<'a>, > { let CanExprOut { - loc_expr, + loc_expr: _, output, var_store, var, @@ -315,43 +244,7 @@ mod test_reporting { name_all_type_vars(var, &mut subs); - let mut mono_problems = Vec::new(); - - // MONO - - if unify_problems.is_empty() && can_problems.is_empty() { - let arena = Bump::new(); - - // Compile and add all the Procs before adding main - let mut procs = Procs::new_in(&arena); - let mut ident_ids = interns.all_ident_ids.get(&home).unwrap().clone(); - let mut update_mode_ids = UpdateModeIds::new(); - - // Populate Procs and Subs, and get the low-level Expr from the canonical Expr - let target_info = roc_target::TargetInfo::default_x86_64(); - let mut layout_cache = LayoutCache::new(target_info); - let mut mono_env = roc_mono::ir::Env { - arena: &arena, - subs: &mut subs, - problems: &mut mono_problems, - home, - ident_ids: &mut ident_ids, - update_mode_ids: &mut update_mode_ids, - target_info, - // call_specialization_counter=0 is reserved - call_specialization_counter: 1, - abilities_store: &abilities_store, - }; - let _mono_expr = Stmt::new( - &mut mono_env, - loc_expr.value, - var, - &mut procs, - &mut layout_cache, - ); - } - - Ok((unify_problems, can_problems, mono_problems, home, interns)) + Ok((unify_problems, can_problems, home, interns)) } fn list_reports(arena: &Bump, src: &str, buf: &mut String, callback: F) @@ -380,7 +273,7 @@ mod test_reporting { callback(doc.pretty(&alloc).append(alloc.line()), buf) } - Ok((type_problems, can_problems, mono_problems, home, interns)) => { + Ok((type_problems, can_problems, home, interns)) => { let mut reports = Vec::new(); let alloc = RocDocAllocator::new(&src_lines, home, &interns); @@ -398,11 +291,6 @@ mod test_reporting { } } - for problem in mono_problems { - let report = mono_problem(&alloc, &lines, filename.clone(), problem.clone()); - reports.push(report); - } - let has_reports = !reports.is_empty(); let doc = alloc @@ -922,7 +810,7 @@ mod test_reporting { ); let arena = Bump::new(); - let (_type_problems, _can_problems, _mono_problems, home, interns) = + let (_type_problems, _can_problems, home, interns) = infer_expr_help(&arena, src).expect("parse error"); let mut buf = String::new(); @@ -953,7 +841,7 @@ mod test_reporting { ); let arena = Bump::new(); - let (_type_problems, _can_problems, _mono_problems, home, mut interns) = + let (_type_problems, _can_problems, home, mut interns) = infer_expr_help(&arena, src).expect("parse error"); let mut buf = String::new(); From 5f8834d6b45b178012f640fd2a01aff2beba99b0 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 28 Apr 2022 15:00:18 -0400 Subject: [PATCH 682/846] I dont got no references --- compiler/constrain/src/expr.rs | 4 ++-- compiler/mono/src/ir.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/constrain/src/expr.rs b/compiler/constrain/src/expr.rs index c4c69b6208..32d449f7b0 100644 --- a/compiler/constrain/src/expr.rs +++ b/compiler/constrain/src/expr.rs @@ -1985,8 +1985,8 @@ pub fn rec_defs_help( def, &mut def_pattern_state, &mut state, - &arguments, - &arg_types, + arguments, + arg_types, ); let pattern_types = arguments.iter().map(|a| Type::Variable(a.0)).collect(); diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 751c38fe4f..1b0875c14a 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -5762,7 +5762,7 @@ fn to_opt_branches<'a>( Guard::NoGuard }; - if when_branch.redundant.is_redundant(&env.subs) { + if when_branch.redundant.is_redundant(env.subs) { // Don't codegen this branch since it's redundant. continue; } From afe49cf57073f35f83ea2cd799f632ce34755fcc Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 28 Apr 2022 15:47:19 -0400 Subject: [PATCH 683/846] Cleanup --- compiler/test_gen/src/helpers/llvm.rs | 17 ++--------------- compiler/test_mono/src/tests.rs | 5 ----- compiler/unify/src/unify.rs | 5 +++-- 3 files changed, 5 insertions(+), 22 deletions(-) diff --git a/compiler/test_gen/src/helpers/llvm.rs b/compiler/test_gen/src/helpers/llvm.rs index 99252b15c5..e67a612c28 100644 --- a/compiler/test_gen/src/helpers/llvm.rs +++ b/compiler/test_gen/src/helpers/llvm.rs @@ -83,15 +83,12 @@ fn create_llvm_module<'a>( let mut delayed_errors = Vec::new(); for (home, (module_path, src)) in loaded.sources { - use roc_reporting::report::{ - can_problem, mono_problem, type_problem, RocDocAllocator, DEFAULT_PALETTE, - }; + use roc_reporting::report::{can_problem, type_problem, RocDocAllocator, DEFAULT_PALETTE}; let can_problems = loaded.can_problems.remove(&home).unwrap_or_default(); let type_problems = loaded.type_problems.remove(&home).unwrap_or_default(); - let mono_problems = loaded.mono_problems.remove(&home).unwrap_or_default(); - let error_count = can_problems.len() + type_problems.len() + mono_problems.len(); + let error_count = can_problems.len() + type_problems.len(); if error_count == 0 { continue; @@ -144,16 +141,6 @@ fn create_llvm_module<'a>( lines.push(buf); } } - - for problem in mono_problems { - let report = mono_problem(&alloc, &line_info, module_path.clone(), problem); - let mut buf = String::new(); - - report.render_color_terminal(&mut buf, &alloc, &palette); - - delayed_errors.push(buf.clone()); - lines.push(buf); - } } if !lines.is_empty() { diff --git a/compiler/test_mono/src/tests.rs b/compiler/test_mono/src/tests.rs index f0c2c51f01..69eb86b8c0 100644 --- a/compiler/test_mono/src/tests.rs +++ b/compiler/test_mono/src/tests.rs @@ -5,9 +5,6 @@ // we actually want to compare against the literal float bits #![allow(clippy::float_cmp)] -#[macro_use] -extern crate pretty_assertions; - #[macro_use] extern crate indoc; @@ -123,14 +120,12 @@ fn compiles_to_ir(test_name: &str, src: &str) { let can_problems = loaded.can_problems.remove(&home).unwrap_or_default(); let type_problems = loaded.type_problems.remove(&home).unwrap_or_default(); - let mono_problems = loaded.mono_problems.remove(&home).unwrap_or_default(); if !can_problems.is_empty() { println!("Ignoring {} canonicalization problems", can_problems.len()); } assert!(type_problems.is_empty()); - assert_eq!(mono_problems, Vec::new()); debug_assert_eq!(exposed_to_host.values.len(), 1); diff --git a/compiler/unify/src/unify.rs b/compiler/unify/src/unify.rs index 06a4f7e399..f5c224bc09 100644 --- a/compiler/unify/src/unify.rs +++ b/compiler/unify/src/unify.rs @@ -5,8 +5,7 @@ use roc_module::symbol::Symbol; use roc_types::subs::Content::{self, *}; use roc_types::subs::{ AliasVariables, Descriptor, ErrorTypeContext, FlatType, GetSubsSlice, Mark, OptVariable, - RecordFields, Subs, SubsFmtContent, SubsIndex, SubsSlice, UnionTags, Variable, - VariableSubsSlice, + RecordFields, Subs, SubsIndex, SubsSlice, UnionTags, Variable, VariableSubsSlice, }; use roc_types::types::{AliasKind, DoesNotImplementAbility, ErrorType, Mismatch, RecordField}; @@ -295,6 +294,8 @@ pub fn unify_pool( /// NOTE: Only run this on individual tests! Run on multiple threads, this would clobber each others' output. #[cfg(debug_assertions)] fn debug_print_unified_types(subs: &mut Subs, ctx: &Context, opt_outcome: Option<&Outcome>) { + use roc_types::subs::SubsFmtContent; + static mut UNIFICATION_DEPTH: usize = 0; if std::env::var("ROC_PRINT_UNIFICATIONS").is_ok() { From 38fd9e82862e30d11f89652d0f0091710c8de159 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 28 Apr 2022 16:38:54 -0400 Subject: [PATCH 684/846] Fix gen-dev tests --- compiler/test_gen/src/helpers/dev.rs | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/compiler/test_gen/src/helpers/dev.rs b/compiler/test_gen/src/helpers/dev.rs index 0ecd1bb37c..1210ce98e3 100644 --- a/compiler/test_gen/src/helpers/dev.rs +++ b/compiler/test_gen/src/helpers/dev.rs @@ -107,15 +107,12 @@ pub fn helper( let mut delayed_errors = Vec::new(); for (home, (module_path, src)) in loaded.sources { - use roc_reporting::report::{ - can_problem, mono_problem, type_problem, RocDocAllocator, DEFAULT_PALETTE, - }; + use roc_reporting::report::{can_problem, type_problem, RocDocAllocator, DEFAULT_PALETTE}; let can_problems = loaded.can_problems.remove(&home).unwrap_or_default(); let type_problems = loaded.type_problems.remove(&home).unwrap_or_default(); - let mono_problems = loaded.mono_problems.remove(&home).unwrap_or_default(); - let error_count = can_problems.len() + type_problems.len() + mono_problems.len(); + let error_count = can_problems.len() + type_problems.len(); if error_count == 0 { continue; @@ -156,15 +153,6 @@ pub fn helper( lines.push(buf); } } - - for problem in mono_problems { - let report = mono_problem(&alloc, &line_info, module_path.clone(), problem); - let mut buf = String::new(); - - report.render_color_terminal(&mut buf, &alloc, &palette); - - lines.push(buf); - } } if !lines.is_empty() { From 5be9a001e3332a6250b91369761dfac2aa1eadd6 Mon Sep 17 00:00:00 2001 From: ayazhafiz Date: Thu, 28 Apr 2022 20:28:59 -0400 Subject: [PATCH 685/846] Empty records are exhaustive --- compiler/can/src/pattern.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/can/src/pattern.rs b/compiler/can/src/pattern.rs index 2a3c32cbcd..f2ca57a239 100644 --- a/compiler/can/src/pattern.rs +++ b/compiler/can/src/pattern.rs @@ -117,8 +117,8 @@ impl Pattern { | UnsupportedPattern(..) | MalformedPattern(..) | AbilityMemberSpecialization { .. } => true, + RecordDestructure { destructs, .. } => destructs.is_empty(), AppliedTag { .. } - | RecordDestructure { .. } | NumLiteral(..) | IntLiteral(..) | FloatLiteral(..) From 07781dd95f0968b8e08f19d312627f50bc5c7985 Mon Sep 17 00:00:00 2001 From: ayazhafiz Date: Thu, 28 Apr 2022 20:37:42 -0400 Subject: [PATCH 686/846] Disable closure wasm test --- compiler/test_gen/src/gen_primitives.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/test_gen/src/gen_primitives.rs b/compiler/test_gen/src/gen_primitives.rs index 3ef5d89e8f..593096087b 100644 --- a/compiler/test_gen/src/gen_primitives.rs +++ b/compiler/test_gen/src/gen_primitives.rs @@ -2503,7 +2503,7 @@ fn backpassing_result() { } #[test] -#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] +#[cfg(any(feature = "gen-llvm"))] #[should_panic(expected = "Shadowing { original_region: @57-58, shadow: @74-75 Ident")] fn function_malformed_pattern() { assert_evals_to!( From dad10af0f91399861448a432e8ccdbcf4d9203cc Mon Sep 17 00:00:00 2001 From: ayazhafiz Date: Thu, 28 Apr 2022 21:07:17 -0400 Subject: [PATCH 687/846] Make sure to stacksave on x86 --- compiler/gen_llvm/src/llvm/build.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/compiler/gen_llvm/src/llvm/build.rs b/compiler/gen_llvm/src/llvm/build.rs index 97450ec527..6cffc4cb37 100644 --- a/compiler/gen_llvm/src/llvm/build.rs +++ b/compiler/gen_llvm/src/llvm/build.rs @@ -546,6 +546,13 @@ fn add_intrinsics<'ctx>(ctx: &'ctx Context, module: &Module<'ctx>) { i8_ptr_type.fn_type(&[i32_type.into()], false), ); + add_intrinsic( + ctx, + module, + LLVM_STACK_SAVE, + i8_ptr_type.fn_type(&[], false), + ); + add_float_intrinsic(ctx, module, &LLVM_LOG, |t| t.fn_type(&[t.into()], false)); add_float_intrinsic(ctx, module, &LLVM_POW, |t| { t.fn_type(&[t.into(), t.into()], false) @@ -599,6 +606,7 @@ static LLVM_MEMSET_I64: &str = "llvm.memset.p0i8.i64"; static LLVM_MEMSET_I32: &str = "llvm.memset.p0i8.i32"; static LLVM_FRAME_ADDRESS: &str = "llvm.frameaddress.p0i8"; +static LLVM_STACK_SAVE: &str = "llvm.stacksave"; static LLVM_SETJMP: &str = "llvm.eh.sjlj.setjmp"; pub static LLVM_LONGJMP: &str = "llvm.eh.sjlj.longjmp"; @@ -3689,6 +3697,8 @@ pub fn build_setjmp_call<'a, 'ctx, 'env>(env: &Env<'a, 'ctx, 'env>) -> BasicValu call_bitcode_fn(env, &[jmp_buf.into()], bitcode::UTILS_SETJMP) } else { // Anywhere else, use the LLVM intrinsic. + // https://llvm.org/docs/ExceptionHandling.html#llvm-eh-sjlj-setjmp + let jmp_buf_i8p_arr = env .builder .build_bitcast( @@ -3701,6 +3711,7 @@ pub fn build_setjmp_call<'a, 'ctx, 'env>(env: &Env<'a, 'ctx, 'env>) -> BasicValu "jmp_buf [5 x i8*]", ) .into_pointer_value(); + // LLVM asks us to please store the frame pointer in the first word. let frame_address = env.call_intrinsic( LLVM_FRAME_ADDRESS, @@ -3716,9 +3727,19 @@ pub fn build_setjmp_call<'a, 'ctx, 'env>(env: &Env<'a, 'ctx, 'env>) -> BasicValu "frame address index", ) }; - env.builder.build_store(fa, frame_address); + // LLVM says that the target implementation of the setjmp intrinsic will put the + // destination address at index 1, and that the remaining three words are for ad-hoc target + // usage. But for whatever reason, on x86, it appears we need a stacksave in those words. + let ss_index = env.context.i32_type().const_int(2, false); + let ss = unsafe { + env.builder + .build_in_bounds_gep(jmp_buf_i8p_arr, &[zero, ss_index], "name") + }; + let stack_save = env.call_intrinsic(LLVM_STACK_SAVE, &[]); + env.builder.build_store(ss, stack_save); + let jmp_buf_i8p = env.builder.build_bitcast( jmp_buf, env.context.i8_type().ptr_type(AddressSpace::Generic), From c6f313c33a0531d319701832369b69154a4edbd1 Mon Sep 17 00:00:00 2001 From: ayazhafiz Date: Thu, 28 Apr 2022 21:13:10 -0400 Subject: [PATCH 688/846] Fix test with type errors --- compiler/test_gen/src/gen_tags.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/test_gen/src/gen_tags.rs b/compiler/test_gen/src/gen_tags.rs index ba77d1268a..4e8bfe68dc 100644 --- a/compiler/test_gen/src/gen_tags.rs +++ b/compiler/test_gen/src/gen_tags.rs @@ -1676,6 +1676,8 @@ fn issue_2900_unreachable_pattern() { "# ), RocStr::from("foo"), - RocStr + RocStr, + |x| x, + true // ignore type errors ) } From e1fe7d7ed8371d6fcc26161558c7774624f9bb1b Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 29 Apr 2022 09:09:28 -0400 Subject: [PATCH 689/846] Comment --- compiler/gen_llvm/src/llvm/externs.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/compiler/gen_llvm/src/llvm/externs.rs b/compiler/gen_llvm/src/llvm/externs.rs index 9180b1fe1f..b3c428958b 100644 --- a/compiler/gen_llvm/src/llvm/externs.rs +++ b/compiler/gen_llvm/src/llvm/externs.rs @@ -188,8 +188,6 @@ pub fn add_sjlj_roc_panic(env: &Env<'_, '_, '_>) { // roc_panic { - // use crate::llvm::build::LLVM_LONGJMP; - // The type of this function (but not the implementation) should have // already been defined by the builtins, which rely on it. let fn_val = module.get_function("roc_panic").unwrap(); From ca7c9ec5e63d88305c3d3aa84f56a70e685f8cc3 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 29 Apr 2022 10:01:04 -0400 Subject: [PATCH 690/846] No more lowercase for opaques --- compiler/can/src/annotation.rs | 23 ++++++++++++++++------- compiler/can/src/effect_module.rs | 6 +++--- compiler/can/src/expr.rs | 2 +- compiler/can/src/pattern.rs | 2 +- compiler/constrain/src/expr.rs | 9 +++++---- compiler/constrain/src/pattern.rs | 9 +++++---- 6 files changed, 31 insertions(+), 20 deletions(-) diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index 45f42692e4..8e49713914 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -1045,26 +1045,35 @@ pub fn instantiate_and_freshen_alias_type( pub fn freshen_opaque_def( var_store: &mut VarStore, opaque: &Alias, -) -> (Vec<(Lowercase, Type)>, Vec, Type) { +) -> (Vec, Vec, Type) { debug_assert!(opaque.kind == AliasKind::Opaque); - let fresh_arguments = opaque + let fresh_variables: Vec = opaque .type_variables .iter() - .map(|_| Type::Variable(var_store.fresh())) + .map(|_| var_store.fresh()) .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(); - instantiate_and_freshen_alias_type( + let (_fresh_type_arguments, fresh_lambda_set, fresh_type) = instantiate_and_freshen_alias_type( var_store, &mut introduced_variables, &opaque.type_variables, - fresh_arguments, + fresh_type_arguments, &opaque.lambda_set_variables, opaque.typ.clone(), - ) + ); + + (fresh_variables, fresh_lambda_set, fresh_type) } fn insertion_sort_by(arr: &mut [T], mut compare: F) diff --git a/compiler/can/src/effect_module.rs b/compiler/can/src/effect_module.rs index b302b64e71..b416483dc2 100644 --- a/compiler/can/src/effect_module.rs +++ b/compiler/can/src/effect_module.rs @@ -5,7 +5,7 @@ use crate::pattern::Pattern; use crate::scope::Scope; use roc_collections::{SendMap, VecSet}; use roc_module::called_via::CalledVia; -use roc_module::ident::{Lowercase, TagName}; +use roc_module::ident::TagName; use roc_module::symbol::Symbol; use roc_region::all::{Loc, Region}; use roc_types::subs::{ExhaustiveMark, RedundantMark, VarStore, Variable}; @@ -1466,7 +1466,7 @@ fn build_effect_opaque( fn build_fresh_opaque_variables( var_store: &mut VarStore, -) -> (Box, Vec<(Lowercase, Type)>, Vec) { +) -> (Box, Vec, Vec) { let closure_var = var_store.fresh(); // 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(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))]; (Box::new(actual), type_arguments, lambda_set_variables) diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index d9d844291c..4138ab07ae 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -190,7 +190,7 @@ pub enum Expr { // for the expression from the opaque definition. `type_arguments` is something like // [(n, fresh1)], and `specialized_def_type` becomes "[ Id U64 fresh1 ]". specialized_def_type: Box, - type_arguments: Vec<(Lowercase, Type)>, + type_arguments: Vec, lambda_set_variables: Vec, }, diff --git a/compiler/can/src/pattern.rs b/compiler/can/src/pattern.rs index f2ca57a239..2318d8b115 100644 --- a/compiler/can/src/pattern.rs +++ b/compiler/can/src/pattern.rs @@ -47,7 +47,7 @@ pub enum Pattern { // for the expression from the opaque definition. `type_arguments` is something like // [(n, fresh1)], and `specialized_def_type` becomes "[ Id U64 fresh1 ]". specialized_def_type: Box, - type_arguments: Vec<(Lowercase, Type)>, + type_arguments: Vec, lambda_set_variables: Vec, }, RecordDestructure { diff --git a/compiler/constrain/src/expr.rs b/compiler/constrain/src/expr.rs index 32d449f7b0..364930ef14 100644 --- a/compiler/constrain/src/expr.rs +++ b/compiler/constrain/src/expr.rs @@ -1022,7 +1022,10 @@ pub fn constrain_expr( let opaque_type = Type::Alias { 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(), actual: Box::new(arg_type.clone()), kind: AliasKind::Opaque, @@ -1059,9 +1062,7 @@ pub fn constrain_expr( let mut vars = vec![*arg_var, *opaque_var]; // Also add the fresh variables we created for the type argument and lambda sets - vars.extend(type_arguments.iter().map(|(_, t)| { - t.expect_variable("all type arguments should be fresh variables here") - })); + vars.extend(type_arguments); vars.extend(lambda_set_variables.iter().map(|v| { v.0.expect_variable("all lambda sets should be fresh variables here") })); diff --git a/compiler/constrain/src/pattern.rs b/compiler/constrain/src/pattern.rs index 9f6cc6c468..26c4d1826a 100644 --- a/compiler/constrain/src/pattern.rs +++ b/compiler/constrain/src/pattern.rs @@ -514,7 +514,10 @@ pub fn constrain_pattern( let opaque_type = Type::Alias { 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(), actual: Box::new(arg_pattern_type.clone()), kind: AliasKind::Opaque, @@ -571,9 +574,7 @@ pub fn constrain_pattern( .vars .extend_from_slice(&[*arg_pattern_var, *whole_var]); // Also add the fresh variables we created for the type argument and lambda sets - state.vars.extend(type_arguments.iter().map(|(_, t)| { - t.expect_variable("all type arguments should be fresh variables here") - })); + state.vars.extend(type_arguments); state.vars.extend(lambda_set_variables.iter().map(|v| { v.0.expect_variable("all lambda sets should be fresh variables here") })); From 2e62fba7bc84480af47a999649e3c32a30a3df6f Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 29 Apr 2022 10:44:33 -0400 Subject: [PATCH 691/846] Delay instantiation of opaque types --- compiler/can/src/annotation.rs | 63 ++++++++--------------- compiler/solve/src/solve.rs | 92 ++++++++++++++++++++++++---------- 2 files changed, 86 insertions(+), 69 deletions(-) diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index 8e49713914..70f09fcd5e 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -508,51 +508,30 @@ fn can_annotation_help( return error; } - let is_structural = alias.kind == AliasKind::Structural; - if is_structural { - let mut type_var_to_arg = Vec::new(); + let mut type_var_to_arg = Vec::new(); - for (loc_var, arg_ann) in alias.type_variables.iter().zip(args) { - let name = loc_var.value.0.clone(); + for (loc_var, arg_ann) in alias.type_variables.iter().zip(args) { + let name = loc_var.value.0.clone(); - type_var_to_arg.push((name, arg_ann)); - } - - let mut lambda_set_variables = - Vec::with_capacity(alias.lambda_set_variables.len()); - - for _ in 0..alias.lambda_set_variables.len() { - let lvar = var_store.fresh(); - - introduced_variables.insert_lambda_set(lvar); - - lambda_set_variables.push(LambdaSet(Type::Variable(lvar))); - } - - Type::DelayedAlias(AliasCommon { - symbol, - type_arguments: type_var_to_arg, - lambda_set_variables, - }) - } else { - let (type_arguments, lambda_set_variables, actual) = - instantiate_and_freshen_alias_type( - var_store, - introduced_variables, - &alias.type_variables, - args, - &alias.lambda_set_variables, - alias.typ.clone(), - ); - - Type::Alias { - symbol, - type_arguments, - lambda_set_variables, - actual: Box::new(actual), - kind: alias.kind, - } + type_var_to_arg.push((name, arg_ann)); } + + let mut lambda_set_variables = + Vec::with_capacity(alias.lambda_set_variables.len()); + + for _ in 0..alias.lambda_set_variables.len() { + let lvar = var_store.fresh(); + + introduced_variables.insert_lambda_set(lvar); + + lambda_set_variables.push(LambdaSet(Type::Variable(lvar))); + } + + Type::DelayedAlias(AliasCommon { + symbol, + type_arguments: type_var_to_arg, + lambda_set_variables, + }) } None => Type::Apply(symbol, args, region), } diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index 92488b6f3a..cc70c9d9ed 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -16,8 +16,8 @@ use roc_types::subs::{ }; use roc_types::types::Type::{self, *}; use roc_types::types::{ - gather_fields_unsorted_iter, AliasCommon, AliasKind, Category, ErrorType, PatternCategory, - Reason, TypeExtension, + gather_fields_unsorted_iter, AliasCommon, AliasKind, Category, ErrorType, LambdaSet, + PatternCategory, Reason, TypeExtension, }; use roc_unify::unify::{unify, Mode, Unified::*}; @@ -139,14 +139,12 @@ impl DelayedAliasVariables { #[derive(Debug, Default)] pub struct Aliases { - aliases: Vec<(Symbol, Type, DelayedAliasVariables)>, + aliases: Vec<(Symbol, Type, DelayedAliasVariables, AliasKind)>, variables: Vec, } impl Aliases { pub fn insert(&mut self, symbol: Symbol, alias: Alias) { - // debug_assert!(self.get(&symbol).is_none()); - let alias_variables = { let start = self.variables.len() as _; @@ -172,7 +170,8 @@ impl Aliases { } }; - self.aliases.push((symbol, alias.typ, alias_variables)); + self.aliases + .push((symbol, alias.typ, alias_variables, alias.kind)); } fn instantiate_result_result( @@ -229,10 +228,16 @@ impl Aliases { Some(var) } - Symbol::NUM_NUM | Symbol::NUM_FLOATINGPOINT | Symbol::NUM_INTEGER => { - // These are opaque types Num range := range (respectively for FloatingPoint and - // Integer). They should not have been built as DelayedAliases! - internal_error!("Attempting to build delayed instantiation of opaque num"); + Symbol::NUM_NUM | Symbol::NUM_INTEGER | Symbol::NUM_FLOATINGPOINT => { + // Num range := range | Integer range := range | FloatingPoint range := range + Self::build_num_opaque( + subs, + rank, + pools, + symbol, + subs.variables[alias_variables.variables_start as usize], + ) + .into() } Symbol::NUM_INT => { // Int range : Num (Integer range) @@ -290,11 +295,13 @@ impl Aliases { return Ok(var); } - let (typ, delayed_variables) = match self.aliases.iter_mut().find(|(s, _, _)| *s == symbol) - { - None => return Err(()), - Some((_, typ, delayed_variables)) => (typ, delayed_variables), - }; + let (typ, delayed_variables, kind) = + match self.aliases.iter_mut().find(|(s, _, _, _)| *s == symbol) { + None => return Err(()), + Some((_, typ, delayed_variables, kind)) => (typ, delayed_variables, kind), + }; + + dbg!(symbol, &typ, &delayed_variables); let mut substitutions: MutMap<_, _> = Default::default(); @@ -338,23 +345,54 @@ impl Aliases { typ.substitute_variables(&substitutions); } - // assumption: an alias does not (transitively) syntactically contain itself - // (if it did it would have to be a recursive tag union) - let mut t = Type::EmptyRec; + let alias_variable = match kind { + AliasKind::Structural => { + // We can replace structural aliases wholly with the type on the + // RHS of their definition. + let mut t = Type::EmptyRec; - std::mem::swap(typ, &mut t); + std::mem::swap(typ, &mut t); - let alias_variable = type_to_variable(subs, rank, pools, arena, self, &t); + // assumption: an alias does not (transitively) syntactically contain itself + // (if it did it would have to be a recursive tag union, which we should have fixed up + // during canonicalization) + let alias_variable = type_to_variable(subs, rank, pools, arena, self, &t); - { - match self.aliases.iter_mut().find(|(s, _, _)| *s == symbol) { - None => unreachable!(), - Some((_, typ, _)) => { - // swap typ back - std::mem::swap(typ, &mut t); + { + match self.aliases.iter_mut().find(|(s, _, _, _)| *s == symbol) { + None => unreachable!(), + Some((_, typ, _, _)) => { + // swap typ back + std::mem::swap(typ, &mut t); + } + } } + + alias_variable } - } + + AliasKind::Opaque => { + // For opaques, the instantiation must be to an opaque type rather than just what's + // on the RHS. + let opaq = Type::Alias { + symbol, + kind: *kind, + lambda_set_variables: new_lambda_set_variables + .iter() + .copied() + .map(Type::Variable) + .map(LambdaSet) + .collect(), + type_arguments: new_type_variables + .iter() + .map(|v| ("".into(), Type::Variable(*v))) + .collect(), + actual: Box::new(typ.clone()), + }; + + type_to_variable(subs, rank, pools, arena, self, &opaq) + } + }; Ok(alias_variable) } From c225515a1ba04d2fefd1fd3e7add2c7a45e2972f Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 29 Apr 2022 10:55:29 -0400 Subject: [PATCH 692/846] Get rid of variable name on DelayedAlias --- compiler/can/src/annotation.rs | 8 ++----- compiler/load_internal/src/file.rs | 34 ++++++++++++------------------ compiler/solve/src/solve.rs | 4 +--- compiler/types/src/types.rs | 26 ++++++++++------------- 4 files changed, 28 insertions(+), 44 deletions(-) diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index 70f09fcd5e..23d735107c 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -510,10 +510,8 @@ fn can_annotation_help( let mut type_var_to_arg = Vec::new(); - for (loc_var, arg_ann) in alias.type_variables.iter().zip(args) { - let name = loc_var.value.0.clone(); - - type_var_to_arg.push((name, arg_ann)); + for (_, arg_ann) in alias.type_variables.iter().zip(args) { + type_var_to_arg.push(arg_ann); } let mut lambda_set_variables = @@ -671,8 +669,6 @@ fn can_annotation_help( let alias = scope.lookup_alias(symbol).unwrap(); local_aliases.insert(symbol, alias.clone()); - // Type::Alias(symbol, vars, Box::new(alias.typ.clone())) - if vars.is_empty() && env.home == symbol.module_id() { let actual_var = var_store.fresh(); introduced_variables.insert_host_exposed_alias(symbol, actual_var); diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index aea2867805..bccc1a3873 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -4738,16 +4738,13 @@ fn default_aliases() -> roc_solve::solve::Aliases { let typ = Type::DelayedAlias(AliasCommon { symbol: Symbol::NUM_NUM, - type_arguments: vec![( - "range".into(), - Type::Alias { - symbol: Symbol::NUM_INTEGER, - type_arguments: vec![("range".into(), Type::Variable(tvar))], - lambda_set_variables: vec![], - actual: Box::new(Type::Variable(tvar)), - kind: AliasKind::Opaque, - }, - )], + type_arguments: vec![Type::Alias { + symbol: Symbol::NUM_INTEGER, + type_arguments: vec![("range".into(), Type::Variable(tvar))], + lambda_set_variables: vec![], + actual: Box::new(Type::Variable(tvar)), + kind: AliasKind::Opaque, + }], lambda_set_variables: vec![], }); @@ -4770,16 +4767,13 @@ fn default_aliases() -> roc_solve::solve::Aliases { let typ = Type::DelayedAlias(AliasCommon { symbol: Symbol::NUM_NUM, - type_arguments: vec![( - "range".into(), - Type::Alias { - symbol: Symbol::NUM_FLOATINGPOINT, - type_arguments: vec![("range".into(), Type::Variable(tvar))], - lambda_set_variables: vec![], - actual: Box::new(Type::Variable(tvar)), - kind: AliasKind::Opaque, - }, - )], + type_arguments: vec![Type::Alias { + symbol: Symbol::NUM_FLOATINGPOINT, + type_arguments: vec![("range".into(), Type::Variable(tvar))], + lambda_set_variables: vec![], + actual: Box::new(Type::Variable(tvar)), + kind: AliasKind::Opaque, + }], lambda_set_variables: vec![], }); diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index cc70c9d9ed..c3ffcc2bd4 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -1928,9 +1928,7 @@ fn type_to_variable<'a>( let length = type_arguments.len() + lambda_set_variables.len(); let new_variables = VariableSubsSlice::reserve_into_subs(subs, length); - for (target_index, (_, arg_type)) in - (new_variables.indices()).zip(type_arguments) - { + for (target_index, arg_type) in (new_variables.indices()).zip(type_arguments) { let copy_var = helper!(arg_type); subs.variables[target_index] = copy_var; } diff --git a/compiler/types/src/types.rs b/compiler/types/src/types.rs index 3f7e26e923..23903999ed 100644 --- a/compiler/types/src/types.rs +++ b/compiler/types/src/types.rs @@ -187,7 +187,7 @@ impl LambdaSet { #[derive(PartialEq, Eq, Clone)] pub struct AliasCommon { pub symbol: Symbol, - pub type_arguments: Vec<(Lowercase, Type)>, + pub type_arguments: Vec, pub lambda_set_variables: Vec, } @@ -385,7 +385,7 @@ impl fmt::Debug for Type { }) => { write!(f, "(DelayedAlias {:?}", symbol)?; - for (_, arg) in type_arguments { + for arg in type_arguments { write!(f, " {:?}", arg)?; } @@ -694,7 +694,7 @@ impl Type { lambda_set_variables, .. }) => { - for (_, value) in type_arguments.iter_mut() { + for value in type_arguments.iter_mut() { stack.push(value); } @@ -803,7 +803,7 @@ impl Type { lambda_set_variables, .. }) => { - for (_, value) in type_arguments.iter_mut() { + for value in type_arguments.iter_mut() { stack.push(value); } @@ -903,7 +903,7 @@ impl Type { lambda_set_variables: _no_aliases_in_lambda_sets, .. }) => { - for (_, ta) in type_arguments { + for ta in type_arguments { ta.substitute_alias(rep_symbol, rep_args, actual)?; } @@ -985,9 +985,7 @@ impl Type { .. }) => { symbol == &rep_symbol - || type_arguments - .iter() - .any(|v| v.1.contains_symbol(rep_symbol)) + || type_arguments.iter().any(|v| v.contains_symbol(rep_symbol)) || lambda_set_variables .iter() .any(|v| v.0.contains_symbol(rep_symbol)) @@ -1163,10 +1161,8 @@ impl Type { if false { let mut type_var_to_arg = Vec::new(); - for (loc_var, arg_ann) in alias.type_variables.iter().zip(args) { - let name = loc_var.value.0.clone(); - - type_var_to_arg.push((name, arg_ann.clone())); + for (_, arg_ann) in alias.type_variables.iter().zip(args) { + type_var_to_arg.push(arg_ann.clone()); } let mut lambda_set_variables = @@ -1383,7 +1379,7 @@ fn symbols_help(initial: &Type) -> Vec { .. }) => { output.push(*symbol); - stack.extend(type_arguments.iter().map(|v| &v.1)); + stack.extend(type_arguments); } Alias { symbol: alias_symbol, @@ -1491,7 +1487,7 @@ fn variables_help(tipe: &Type, accum: &mut ImSet) { lambda_set_variables, .. }) => { - for (_, arg) in type_arguments { + for arg in type_arguments { variables_help(arg, accum); } @@ -1623,7 +1619,7 @@ fn variables_help_detailed(tipe: &Type, accum: &mut VariableDetail) { lambda_set_variables, .. }) => { - for (_, arg) in type_arguments { + for arg in type_arguments { variables_help_detailed(arg, accum); } From 452b882f12f477a55d0828621789ff9a2659b67d Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 29 Apr 2022 11:04:15 -0400 Subject: [PATCH 693/846] Remove unused alias types --- compiler/load_internal/src/file.rs | 145 +---------------------------- compiler/solve/src/solve.rs | 2 - 2 files changed, 4 insertions(+), 143 deletions(-) diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index bccc1a3873..e8fb1d4ef2 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -39,7 +39,7 @@ use roc_solve::solve; use roc_target::TargetInfo; use roc_types::solved_types::Solved; use roc_types::subs::{Subs, VarStore, Variable}; -use roc_types::types::{Alias, AliasCommon, AliasKind, TypeExtension}; +use roc_types::types::{Alias, AliasKind}; use std::collections::hash_map::Entry::{Occupied, Vacant}; use std::collections::HashMap; use std::io; @@ -4689,151 +4689,14 @@ fn to_missing_platform_report(module_id: ModuleId, other: PlatformPath) -> Strin /// Builtin aliases that are not covered by type checker optimizations /// /// Types like `F64` and `I32` are hardcoded into Subs and therefore we don't define them here. -/// All that remains are the generic number types (Num, Int, Float) and Result +/// Generic number types (Num, Int, Float, etc.) are treated as `DelayedAlias`es resolved during +/// type solving. +/// All that remains are Signed8, Signed16, etc. fn default_aliases() -> roc_solve::solve::Aliases { use roc_types::types::Type; let mut solve_aliases = roc_solve::solve::Aliases::default(); - let mut var_store = VarStore::default(); - - // Num range := range - { - let symbol = Symbol::NUM_NUM; - let tvar = var_store.fresh(); - - let alias = Alias { - region: Region::zero(), - type_variables: vec![Loc::at_zero(("range".into(), tvar))], - lambda_set_variables: Default::default(), - recursion_variables: Default::default(), - typ: Type::Variable(tvar), - kind: roc_types::types::AliasKind::Structural, - }; - - solve_aliases.insert(symbol, alias); - } - - // FloatingPoint range := [] - { - let symbol = Symbol::NUM_FLOATINGPOINT; - let tvar = var_store.fresh(); - - let alias = Alias { - region: Region::zero(), - type_variables: vec![Loc::at_zero(("range".into(), tvar))], - lambda_set_variables: Default::default(), - recursion_variables: Default::default(), - typ: Type::Variable(tvar), - kind: roc_types::types::AliasKind::Opaque, - }; - - solve_aliases.insert(symbol, alias); - } - - // Int range : Num (Integer range) - { - let symbol = Symbol::NUM_INT; - let tvar = var_store.fresh(); - - let typ = Type::DelayedAlias(AliasCommon { - symbol: Symbol::NUM_NUM, - type_arguments: vec![Type::Alias { - symbol: Symbol::NUM_INTEGER, - type_arguments: vec![("range".into(), Type::Variable(tvar))], - lambda_set_variables: vec![], - actual: Box::new(Type::Variable(tvar)), - kind: AliasKind::Opaque, - }], - lambda_set_variables: vec![], - }); - - let alias = Alias { - region: Region::zero(), - type_variables: vec![Loc::at_zero(("range".into(), tvar))], - lambda_set_variables: Default::default(), - recursion_variables: Default::default(), - typ, - kind: roc_types::types::AliasKind::Structural, - }; - - solve_aliases.insert(symbol, alias); - } - - // Float range : Num (FloatingPoint range) - { - let symbol = Symbol::NUM_FLOAT; - let tvar = var_store.fresh(); - - let typ = Type::DelayedAlias(AliasCommon { - symbol: Symbol::NUM_NUM, - type_arguments: vec![Type::Alias { - symbol: Symbol::NUM_FLOATINGPOINT, - type_arguments: vec![("range".into(), Type::Variable(tvar))], - lambda_set_variables: vec![], - actual: Box::new(Type::Variable(tvar)), - kind: AliasKind::Opaque, - }], - lambda_set_variables: vec![], - }); - - let alias = Alias { - region: Region::zero(), - type_variables: vec![Loc::at_zero(("range".into(), tvar))], - lambda_set_variables: Default::default(), - recursion_variables: Default::default(), - typ, - kind: roc_types::types::AliasKind::Structural, - }; - - solve_aliases.insert(symbol, alias); - } - - // Integer range := range - { - let symbol = Symbol::NUM_INTEGER; - let tvar = var_store.fresh(); - - let alias = Alias { - region: Region::zero(), - type_variables: vec![Loc::at_zero(("range".into(), tvar))], - lambda_set_variables: Default::default(), - recursion_variables: Default::default(), - typ: Type::Variable(tvar), - kind: roc_types::types::AliasKind::Structural, - }; - - solve_aliases.insert(symbol, alias); - } - - { - let symbol = Symbol::RESULT_RESULT; - let tvar1 = var_store.fresh(); - let tvar2 = var_store.fresh(); - - let typ = Type::TagUnion( - vec![ - (TagName::Tag("Ok".into()), vec![Type::Variable(tvar1)]), - (TagName::Tag("Err".into()), vec![Type::Variable(tvar2)]), - ], - TypeExtension::Closed, - ); - - let alias = Alias { - region: Region::zero(), - type_variables: vec![ - Loc::at_zero(("ok".into(), tvar1)), - Loc::at_zero(("err".into(), tvar2)), - ], - lambda_set_variables: Default::default(), - recursion_variables: Default::default(), - typ, - kind: roc_types::types::AliasKind::Structural, - }; - - solve_aliases.insert(symbol, alias); - } - let mut zero_opaque = |alias_name: Symbol| { let alias = Alias { region: Region::zero(), diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index c3ffcc2bd4..aa852c156a 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -301,8 +301,6 @@ impl Aliases { Some((_, typ, delayed_variables, kind)) => (typ, delayed_variables, kind), }; - dbg!(symbol, &typ, &delayed_variables); - let mut substitutions: MutMap<_, _> = Default::default(); for rec_var in delayed_variables From 83c6c3a17d4d3e0ba8341d2db82c98480c5dc269 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 29 Apr 2022 11:36:31 -0400 Subject: [PATCH 694/846] Remove Lowercase from Alias and Opaque --- ast/src/constrain.rs | 15 +++++------- ast/src/lang/core/types.rs | 18 +++++++++++---- ast/src/lang/scope.rs | 4 ++-- ast/src/solve_type.rs | 2 +- compiler/can/src/annotation.rs | 6 ++--- compiler/can/src/def.rs | 15 +++++++----- compiler/can/src/effect_module.rs | 13 ++--------- compiler/constrain/src/builtins.rs | 13 +++++------ compiler/constrain/src/expr.rs | 5 +--- compiler/constrain/src/pattern.rs | 5 +--- compiler/load_internal/src/file.rs | 2 +- compiler/solve/src/solve.rs | 33 ++++++++++++++------------- compiler/types/src/builtin_aliases.rs | 12 +++++----- compiler/types/src/solved_types.rs | 12 +++++----- compiler/types/src/types.rs | 33 +++++++++++++-------------- 15 files changed, 91 insertions(+), 97 deletions(-) diff --git a/ast/src/constrain.rs b/ast/src/constrain.rs index de68e4b6cb..d3211e7d19 100644 --- a/ast/src/constrain.rs +++ b/ast/src/constrain.rs @@ -27,7 +27,7 @@ use crate::{ }, env::Env, }, - mem_pool::{pool::Pool, pool_str::PoolStr, pool_vec::PoolVec, shallow_clone::ShallowClone}, + mem_pool::{pool::Pool, pool_vec::PoolVec, shallow_clone::ShallowClone}, }; /// A presence constraint is an additive constraint that defines the lower bound @@ -1846,7 +1846,7 @@ fn num_float(pool: &mut Pool, range: TypeId) -> Type2 { Type2::Alias( Symbol::NUM_FLOAT, - PoolVec::new(vec![(PoolStr::new("range", pool), range)].into_iter(), pool), + PoolVec::new(vec![range].into_iter(), pool), num_num_id, ) } @@ -1859,7 +1859,7 @@ fn num_floatingpoint(pool: &mut Pool, range: TypeId) -> Type2 { Type2::Opaque( Symbol::NUM_FLOATINGPOINT, - PoolVec::new(vec![(PoolStr::new("range", pool), range)].into_iter(), pool), + PoolVec::new(vec![range].into_iter(), pool), pool.add(alias_content), ) } @@ -1874,7 +1874,7 @@ fn num_int(pool: &mut Pool, range: TypeId) -> Type2 { Type2::Alias( Symbol::NUM_INT, - PoolVec::new(vec![(PoolStr::new("range", pool), range)].into_iter(), pool), + PoolVec::new(vec![range].into_iter(), pool), num_num_id, ) } @@ -1907,7 +1907,7 @@ fn _num_integer(pool: &mut Pool, range: TypeId) -> Type2 { Type2::Opaque( Symbol::NUM_INTEGER, - PoolVec::new(vec![(PoolStr::new("range", pool), range)].into_iter(), pool), + PoolVec::new(vec![range].into_iter(), pool), pool.add(alias_content), ) } @@ -1920,10 +1920,7 @@ fn num_num(pool: &mut Pool, type_id: TypeId) -> Type2 { Type2::Opaque( Symbol::NUM_NUM, - PoolVec::new( - vec![(PoolStr::new("range", pool), type_id)].into_iter(), - pool, - ), + PoolVec::new(vec![type_id].into_iter(), pool), pool.add(alias_content), ) } diff --git a/ast/src/lang/core/types.rs b/ast/src/lang/core/types.rs index 3536222bf5..4bfc075ace 100644 --- a/ast/src/lang/core/types.rs +++ b/ast/src/lang/core/types.rs @@ -23,8 +23,8 @@ pub type TypeId = NodeId; pub enum Type2 { Variable(Variable), // 4B - Alias(Symbol, PoolVec<(PoolStr, TypeId)>, TypeId), // 24B = 8B + 8B + 4B + pad - Opaque(Symbol, PoolVec<(PoolStr, TypeId)>, TypeId), // 24B = 8B + 8B + 4B + pad + Alias(Symbol, PoolVec, TypeId), // 24B = 8B + 8B + 4B + pad + Opaque(Symbol, PoolVec, TypeId), // 24B = 8B + 8B + 4B + pad AsAlias(Symbol, PoolVec<(PoolStr, TypeId)>, TypeId), // 24B = 8B + 8B + 4B + pad // 24B @@ -736,7 +736,7 @@ fn can_tags<'a>( enum TypeApply { Apply(Symbol, PoolVec), - Alias(Symbol, PoolVec<(PoolStr, TypeId)>, TypeId), + Alias(Symbol, PoolVec, TypeId), Erroneous(roc_types::types::Problem), } @@ -838,7 +838,17 @@ fn to_type_apply<'a>( // instantiate variables Type2::substitute(env.pool, &substitutions, actual); - TypeApply::Alias(symbol, arguments, actual) + let type_arguments = PoolVec::with_capacity(arguments.len() as u32, env.pool); + + for (node_id, type_id) in arguments + .iter_node_ids() + .zip(type_arguments.iter_node_ids()) + { + let typ = env.pool[node_id].1; + env.pool[type_id] = typ; + } + + TypeApply::Alias(symbol, type_arguments, actual) } None => TypeApply::Apply(symbol, argument_type_ids), } diff --git a/ast/src/lang/scope.rs b/ast/src/lang/scope.rs index ced87957e4..ff528d4d2c 100644 --- a/ast/src/lang/scope.rs +++ b/ast/src/lang/scope.rs @@ -48,7 +48,7 @@ fn to_type2( SolvedType::Alias(symbol, solved_type_variables, _todo, solved_actual, _kind) => { let type_variables = PoolVec::with_capacity(solved_type_variables.len() as u32, pool); - for (type_variable_node_id, (lowercase, solved_arg)) in type_variables + for (type_variable_node_id, solved_arg) in type_variables .iter_node_ids() .zip(solved_type_variables.iter()) { @@ -56,7 +56,7 @@ fn to_type2( let node = pool.add(typ2); - pool[type_variable_node_id] = (PoolStr::new(lowercase.as_str(), pool), node); + pool[type_variable_node_id] = node; } let actual_typ2 = to_type2(pool, solved_actual, free_vars, var_store); diff --git a/ast/src/solve_type.rs b/ast/src/solve_type.rs index eac6ae712e..5b05fdb518 100644 --- a/ast/src/solve_type.rs +++ b/ast/src/solve_type.rs @@ -899,7 +899,7 @@ fn type_to_variable<'a>( let mut arg_vars = Vec::with_capacity(args.len()); - for (_, arg_type_id) in args.iter(mempool) { + for arg_type_id in args.iter(mempool) { let arg_type = mempool.get(*arg_type_id); let arg_var = type_to_variable(arena, mempool, subs, rank, pools, cached, arg_type); diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index 23d735107c..d995a2d867 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -597,20 +597,20 @@ fn can_annotation_help( let var_name = Lowercase::from(var); if let Some(var) = introduced_variables.var_by_name(&var_name) { - vars.push((var_name.clone(), Type::Variable(var))); + vars.push(Type::Variable(var)); lowercase_vars.push(Loc::at(loc_var.region, (var_name, var))); } else { let var = var_store.fresh(); introduced_variables .insert_named(var_name.clone(), Loc::at(loc_var.region, var)); - vars.push((var_name.clone(), Type::Variable(var))); + vars.push(Type::Variable(var)); lowercase_vars.push(Loc::at(loc_var.region, (var_name, var))); } } - let alias_args = vars.iter().map(|(_, v)| v.clone()).collect::>(); + let alias_args = vars.clone(); let alias_actual = if let Type::TagUnion(tags, ext) = inner_type { let rec_var = var_store.fresh(); diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index f93b8732e2..0bdd2b5dd5 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1788,7 +1788,10 @@ fn make_tag_union_of_alias_recursive<'a>( let made_recursive = make_tag_union_recursive_help( env, - Loc::at(alias.header_region(), (alias_name, &alias_args)), + Loc::at( + alias.header_region(), + (alias_name, alias_args.iter().map(|ta| &ta.1)), + ), alias.region, others, &mut alias.typ, @@ -1835,12 +1838,12 @@ enum MakeTagUnionRecursive { /// ``` /// /// When `Err` is returned, a problem will be added to `env`. -fn make_tag_union_recursive_help<'a>( +fn make_tag_union_recursive_help<'a, 'b>( env: &mut Env<'a>, - recursive_alias: Loc<(Symbol, &[(Lowercase, Type)])>, + recursive_alias: Loc<(Symbol, impl Iterator)>, region: Region, others: Vec, - typ: &mut Type, + typ: &'b mut Type, var_store: &mut VarStore, can_report_cyclic_error: &mut bool, ) -> MakeTagUnionRecursive { @@ -1852,7 +1855,7 @@ fn make_tag_union_recursive_help<'a>( match typ { Type::TagUnion(tags, ext) => { let recursion_variable = var_store.fresh(); - let type_arguments = args.iter().map(|(_, t)| t.clone()).collect::>(); + let type_arguments: Vec<_> = args.into_iter().cloned().collect(); let mut pending_typ = Type::RecursiveTagUnion(recursion_variable, tags.to_vec(), ext.clone()); @@ -1890,7 +1893,7 @@ fn make_tag_union_recursive_help<'a>( // try to make `actual` recursive make_tag_union_recursive_help( env, - Loc::at_zero((symbol, type_arguments)), + Loc::at_zero((symbol, type_arguments.iter())), region, others, actual, diff --git a/compiler/can/src/effect_module.rs b/compiler/can/src/effect_module.rs index b416483dc2..552837d2e8 100644 --- a/compiler/can/src/effect_module.rs +++ b/compiler/can/src/effect_module.rs @@ -184,7 +184,6 @@ fn build_effect_always( let effect_a = build_effect_opaque( effect_symbol, - "a", var_a, Type::Variable(var_a), var_store, @@ -362,7 +361,6 @@ fn build_effect_map( let effect_a = build_effect_opaque( effect_symbol, - "a", var_a, Type::Variable(var_a), var_store, @@ -371,7 +369,6 @@ fn build_effect_map( let effect_b = build_effect_opaque( effect_symbol, - "b", var_b, Type::Variable(var_b), var_store, @@ -515,7 +512,6 @@ fn build_effect_after( let effect_a = build_effect_opaque( effect_symbol, - "a", var_a, Type::Variable(var_a), var_store, @@ -524,7 +520,6 @@ fn build_effect_after( let effect_b = build_effect_opaque( effect_symbol, - "b", var_b, Type::Variable(var_b), var_store, @@ -758,7 +753,6 @@ fn build_effect_forever( let effect_a = build_effect_opaque( effect_symbol, - "a", var_a, Type::Variable(var_a), var_store, @@ -767,7 +761,6 @@ fn build_effect_forever( let effect_b = build_effect_opaque( effect_symbol, - "b", var_b, Type::Variable(var_b), var_store, @@ -985,7 +978,6 @@ fn build_effect_loop( let effect_b = build_effect_opaque( effect_symbol, - "b", var_b, Type::Variable(var_b), var_store, @@ -1017,7 +1009,7 @@ fn build_effect_loop( Type::Alias { symbol: effect_symbol, - type_arguments: vec![("a".into(), state_type)], + type_arguments: vec![state_type], lambda_set_variables: vec![roc_types::types::LambdaSet(Type::Variable( closure_var, ))], @@ -1440,7 +1432,6 @@ pub fn build_effect_actual(a_type: Type, var_store: &mut VarStore) -> Type { /// Effect a := {} -> a fn build_effect_opaque( effect_symbol: Symbol, - a_name: &str, a_var: Variable, a_type: Type, var_store: &mut VarStore, @@ -1457,7 +1448,7 @@ fn build_effect_opaque( Type::Alias { symbol: effect_symbol, - type_arguments: vec![(a_name.into(), Type::Variable(a_var))], + type_arguments: vec![Type::Variable(a_var)], lambda_set_variables: vec![roc_types::types::LambdaSet(Type::Variable(closure_var))], actual: Box::new(actual), kind: AliasKind::Opaque, diff --git a/compiler/constrain/src/builtins.rs b/compiler/constrain/src/builtins.rs index dcabe649ab..7a0e9a73b3 100644 --- a/compiler/constrain/src/builtins.rs +++ b/compiler/constrain/src/builtins.rs @@ -2,7 +2,6 @@ use arrayvec::ArrayVec; use roc_can::constraint::{Constraint, Constraints}; use roc_can::expected::Expected::{self, *}; use roc_can::num::{FloatBound, FloatWidth, IntBound, IntWidth, NumericBound, SignDemand}; -use roc_module::ident::Lowercase; use roc_module::symbol::Symbol; use roc_region::all::Region; use roc_types::subs::Variable; @@ -161,7 +160,7 @@ pub fn str_type() -> Type { #[inline(always)] fn builtin_alias( symbol: Symbol, - type_arguments: Vec<(Lowercase, Type)>, + type_arguments: Vec, actual: Box, kind: AliasKind, ) -> Type { @@ -178,7 +177,7 @@ fn builtin_alias( pub fn num_float(range: Type) -> Type { builtin_alias( Symbol::NUM_FLOAT, - vec![("range".into(), range.clone())], + vec![range.clone()], Box::new(num_num(num_floatingpoint(range))), AliasKind::Structural, ) @@ -188,7 +187,7 @@ pub fn num_float(range: Type) -> Type { pub fn num_floatingpoint(range: Type) -> Type { builtin_alias( Symbol::NUM_FLOATINGPOINT, - vec![("range".into(), range.clone())], + vec![range.clone()], Box::new(range), AliasKind::Opaque, ) @@ -228,7 +227,7 @@ pub fn num_binary64() -> Type { pub fn num_int(range: Type) -> Type { builtin_alias( Symbol::NUM_INT, - vec![("range".into(), range.clone())], + vec![range.clone()], Box::new(num_num(num_integer(range))), AliasKind::Structural, ) @@ -248,7 +247,7 @@ pub fn num_signed64() -> Type { pub fn num_integer(range: Type) -> Type { builtin_alias( Symbol::NUM_INTEGER, - vec![("range".into(), range.clone())], + vec![range.clone()], Box::new(range), AliasKind::Opaque, ) @@ -258,7 +257,7 @@ pub fn num_integer(range: Type) -> Type { pub fn num_num(typ: Type) -> Type { builtin_alias( Symbol::NUM_NUM, - vec![("range".into(), typ.clone())], + vec![typ.clone()], Box::new(typ), AliasKind::Opaque, ) diff --git a/compiler/constrain/src/expr.rs b/compiler/constrain/src/expr.rs index 364930ef14..0402dced58 100644 --- a/compiler/constrain/src/expr.rs +++ b/compiler/constrain/src/expr.rs @@ -1022,10 +1022,7 @@ pub fn constrain_expr( let opaque_type = Type::Alias { symbol: *name, - type_arguments: type_arguments - .iter() - .map(|v| ("".into(), Type::Variable(*v))) - .collect(), + type_arguments: type_arguments.iter().copied().map(Type::Variable).collect(), lambda_set_variables: lambda_set_variables.clone(), actual: Box::new(arg_type.clone()), kind: AliasKind::Opaque, diff --git a/compiler/constrain/src/pattern.rs b/compiler/constrain/src/pattern.rs index 26c4d1826a..b2dde1ae63 100644 --- a/compiler/constrain/src/pattern.rs +++ b/compiler/constrain/src/pattern.rs @@ -514,10 +514,7 @@ pub fn constrain_pattern( let opaque_type = Type::Alias { symbol: *opaque, - type_arguments: type_arguments - .iter() - .map(|v| ("".into(), Type::Variable(*v))) - .collect(), + type_arguments: type_arguments.iter().copied().map(Type::Variable).collect(), lambda_set_variables: lambda_set_variables.clone(), actual: Box::new(arg_pattern_type.clone()), kind: AliasKind::Opaque, diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index e8fb1d4ef2..7fa6bf8292 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -16,7 +16,7 @@ use roc_constrain::module::{ ExposedModuleTypes, }; use roc_error_macros::internal_error; -use roc_module::ident::{Ident, ModuleName, QualifiedModuleName, TagName}; +use roc_module::ident::{Ident, ModuleName, QualifiedModuleName}; use roc_module::symbol::{ IdentIds, IdentIdsByModule, Interns, ModuleId, ModuleIds, PQModuleName, PackageModuleIds, PackageQualified, Symbol, diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index aa852c156a..1cd4b1e41c 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -372,19 +372,24 @@ impl Aliases { AliasKind::Opaque => { // For opaques, the instantiation must be to an opaque type rather than just what's // on the RHS. + let lambda_set_variables = new_lambda_set_variables + .iter() + .copied() + .map(Type::Variable) + .map(LambdaSet) + .collect(); + let type_arguments = new_type_variables + .clone() + .iter() + .copied() + .map(Type::Variable) + .collect(); + let opaq = Type::Alias { symbol, kind: *kind, - lambda_set_variables: new_lambda_set_variables - .iter() - .copied() - .map(Type::Variable) - .map(LambdaSet) - .collect(), - type_arguments: new_type_variables - .iter() - .map(|v| ("".into(), Type::Variable(*v))) - .collect(), + lambda_set_variables, + type_arguments, actual: Box::new(typ.clone()), }; @@ -1971,9 +1976,7 @@ fn type_to_variable<'a>( let length = type_arguments.len() + lambda_set_variables.len(); let new_variables = VariableSubsSlice::reserve_into_subs(subs, length); - for (target_index, (_, arg_type)) in - (new_variables.indices()).zip(type_arguments) - { + for (target_index, arg_type) in (new_variables.indices()).zip(type_arguments) { let copy_var = helper!(arg_type); subs.variables[target_index] = copy_var; } @@ -2013,9 +2016,7 @@ fn type_to_variable<'a>( let length = type_arguments.len() + lambda_set_variables.len(); let new_variables = VariableSubsSlice::reserve_into_subs(subs, length); - for (target_index, (_, arg_type)) in - (new_variables.indices()).zip(type_arguments) - { + for (target_index, arg_type) in (new_variables.indices()).zip(type_arguments) { let copy_var = helper!(arg_type); subs.variables[target_index] = copy_var; } diff --git a/compiler/types/src/builtin_aliases.rs b/compiler/types/src/builtin_aliases.rs index 6be002465c..0cd7797e10 100644 --- a/compiler/types/src/builtin_aliases.rs +++ b/compiler/types/src/builtin_aliases.rs @@ -381,7 +381,7 @@ pub fn flex(tvar: VarId) -> SolvedType { pub fn num_type(range: SolvedType) -> SolvedType { SolvedType::Alias( Symbol::NUM_NUM, - vec![("range".into(), range.clone())], + vec![(range.clone())], vec![], Box::new(num_alias_content(range)), AliasKind::Opaque, @@ -399,7 +399,7 @@ fn num_alias_content(range: SolvedType) -> SolvedType { pub fn floatingpoint_type(range: SolvedType) -> SolvedType { SolvedType::Alias( Symbol::NUM_FLOATINGPOINT, - vec![("range".into(), range.clone())], + vec![(range.clone())], vec![], Box::new(floatingpoint_alias_content(range)), AliasKind::Opaque, @@ -417,7 +417,7 @@ fn floatingpoint_alias_content(range: SolvedType) -> SolvedType { pub fn float_type(range: SolvedType) -> SolvedType { SolvedType::Alias( Symbol::NUM_FLOAT, - vec![("range".into(), range.clone())], + vec![(range.clone())], vec![], Box::new(float_alias_content(range)), AliasKind::Structural, @@ -669,7 +669,7 @@ fn i8_alias_content() -> SolvedType { pub fn int_type(range: SolvedType) -> SolvedType { SolvedType::Alias( Symbol::NUM_INT, - vec![("range".into(), range.clone())], + vec![(range.clone())], vec![], Box::new(int_alias_content(range)), AliasKind::Structural, @@ -687,7 +687,7 @@ fn int_alias_content(range: SolvedType) -> SolvedType { pub fn integer_type(range: SolvedType) -> SolvedType { SolvedType::Alias( Symbol::NUM_INTEGER, - vec![("range".into(), range.clone())], + vec![(range.clone())], vec![], Box::new(integer_alias_content(range)), AliasKind::Opaque, @@ -979,7 +979,7 @@ pub fn ordering_type() -> SolvedType { pub fn result_type(a: SolvedType, e: SolvedType) -> SolvedType { SolvedType::Alias( Symbol::RESULT_RESULT, - vec![("ok".into(), a.clone()), ("err".into(), e.clone())], + vec![a.clone(), e.clone()], vec![], Box::new(result_alias_content(a, e)), AliasKind::Structural, diff --git a/compiler/types/src/solved_types.rs b/compiler/types/src/solved_types.rs index 76fd39ecab..1f4eeb4f1c 100644 --- a/compiler/types/src/solved_types.rs +++ b/compiler/types/src/solved_types.rs @@ -55,7 +55,7 @@ pub enum SolvedType { Alias( Symbol, - Vec<(Lowercase, SolvedType)>, + Vec, Vec, Box, AliasKind, @@ -63,7 +63,7 @@ pub enum SolvedType { HostExposedAlias { name: Symbol, - arguments: Vec<(Lowercase, SolvedType)>, + arguments: Vec, lambda_set_variables: Vec, actual_var: VarId, actual: Box, @@ -212,8 +212,8 @@ pub fn to_type( Alias(symbol, solved_type_variables, solved_lambda_sets, solved_actual, kind) => { let mut type_variables = Vec::with_capacity(solved_type_variables.len()); - for (lowercase, solved_arg) in solved_type_variables { - type_variables.push((lowercase.clone(), to_type(solved_arg, free_vars, var_store))); + for solved_arg in solved_type_variables { + type_variables.push(to_type(solved_arg, free_vars, var_store)); } let mut lambda_set_variables = Vec::with_capacity(solved_lambda_sets.len()); @@ -244,8 +244,8 @@ pub fn to_type( } => { let mut type_variables = Vec::with_capacity(solved_type_variables.len()); - for (lowercase, solved_arg) in solved_type_variables { - type_variables.push((lowercase.clone(), to_type(solved_arg, free_vars, var_store))); + for solved_arg in solved_type_variables { + type_variables.push(to_type(solved_arg, free_vars, var_store)); } let mut lambda_set_variables = Vec::with_capacity(solved_lambda_sets.len()); diff --git a/compiler/types/src/types.rs b/compiler/types/src/types.rs index 23903999ed..95a7d61029 100644 --- a/compiler/types/src/types.rs +++ b/compiler/types/src/types.rs @@ -208,14 +208,14 @@ pub enum Type { DelayedAlias(AliasCommon), Alias { symbol: Symbol, - type_arguments: Vec<(Lowercase, Type)>, + type_arguments: Vec, lambda_set_variables: Vec, actual: Box, kind: AliasKind, }, HostExposedAlias { name: Symbol, - type_arguments: Vec<(Lowercase, Type)>, + type_arguments: Vec, lambda_set_variables: Vec, actual_var: Variable, actual: Box, @@ -409,7 +409,7 @@ impl fmt::Debug for Type { } => { write!(f, "(Alias {:?}", symbol)?; - for (_, arg) in type_arguments { + for arg in type_arguments { write!(f, " {:?}", arg)?; } @@ -433,7 +433,7 @@ impl fmt::Debug for Type { } => { write!(f, "HostExposedAlias {:?}", name)?; - for (_, arg) in arguments { + for arg in arguments { write!(f, " {:?}", arg)?; } @@ -708,7 +708,7 @@ impl Type { actual, .. } => { - for (_, value) in type_arguments.iter_mut() { + for value in type_arguments.iter_mut() { stack.push(value); } @@ -724,7 +724,7 @@ impl Type { actual: actual_type, .. } => { - for (_, value) in type_arguments.iter_mut() { + for value in type_arguments.iter_mut() { stack.push(value); } @@ -817,7 +817,7 @@ impl Type { actual, .. } => { - for (_, value) in type_arguments.iter_mut() { + for value in type_arguments.iter_mut() { stack.push(value); } for lambda_set in lambda_set_variables.iter_mut() { @@ -832,7 +832,7 @@ impl Type { actual: actual_type, .. } => { - for (_, value) in type_arguments.iter_mut() { + for value in type_arguments.iter_mut() { stack.push(value); } @@ -914,7 +914,7 @@ impl Type { actual: alias_actual, .. } => { - for (_, ta) in type_arguments { + for ta in type_arguments { ta.substitute_alias(rep_symbol, rep_args, actual)?; } alias_actual.substitute_alias(rep_symbol, rep_args, actual) @@ -1139,8 +1139,7 @@ impl Type { .. } => { for arg in type_args { - arg.1 - .instantiate_aliases(region, aliases, var_store, new_lambda_set_variables); + arg.instantiate_aliases(region, aliases, var_store, new_lambda_set_variables); } for arg in lambda_set_variables { @@ -1202,7 +1201,7 @@ impl Type { // TODO substitute further in args for ( Loc { - value: (lowercase, placeholder), + value: (_, placeholder), .. }, filler, @@ -1215,7 +1214,7 @@ impl Type { var_store, new_lambda_set_variables, ); - named_args.push((lowercase.clone(), filler.clone())); + named_args.push(filler.clone()); substitution.insert(*placeholder, filler); } @@ -1500,7 +1499,7 @@ fn variables_help(tipe: &Type, accum: &mut ImSet) { actual, .. } => { - for (_, arg) in type_arguments { + for arg in type_arguments { variables_help(arg, accum); } variables_help(actual, accum); @@ -1510,7 +1509,7 @@ fn variables_help(tipe: &Type, accum: &mut ImSet) { actual, .. } => { - for (_, arg) in arguments { + for arg in arguments { variables_help(arg, accum); } variables_help(actual, accum); @@ -1636,7 +1635,7 @@ fn variables_help_detailed(tipe: &Type, accum: &mut VariableDetail) { actual, .. } => { - for (_, arg) in type_arguments { + for arg in type_arguments { variables_help_detailed(arg, accum); } variables_help_detailed(actual, accum); @@ -1646,7 +1645,7 @@ fn variables_help_detailed(tipe: &Type, accum: &mut VariableDetail) { actual, .. } => { - for (_, arg) in arguments { + for arg in arguments { variables_help_detailed(arg, accum); } variables_help_detailed(actual, accum); From 7d3f02d0e1c9911c7f501da0cebfc6b53069c40c Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 29 Apr 2022 12:18:48 -0400 Subject: [PATCH 695/846] Unnecessary clone --- compiler/solve/src/solve.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index 1cd4b1e41c..08f8921c62 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -379,7 +379,6 @@ impl Aliases { .map(LambdaSet) .collect(); let type_arguments = new_type_variables - .clone() .iter() .copied() .map(Type::Variable) From b8217bf9de86a6d1d2b42e33a6c8f3a8a0a7ad9d Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 29 Apr 2022 18:42:57 +0200 Subject: [PATCH 696/846] separate imports from local symbols --- compiler/can/src/scope.rs | 92 +++++++++++++++++++++++++++++++++------ 1 file changed, 79 insertions(+), 13 deletions(-) diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index a99c158cc7..9b9000b582 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -26,6 +26,8 @@ pub struct Scope { /// The first `exposed_ident_count` identifiers are exposed exposed_ident_count: usize, + + imports: Vec<(Ident, Symbol, Region)>, } fn add_aliases(var_store: &mut VarStore) -> VecMap { @@ -78,6 +80,7 @@ impl Scope { aliases: VecMap::default(), // TODO(abilities): default abilities in scope abilities_store: AbilitiesStore::default(), + imports: Vec::new(), } } @@ -94,6 +97,7 @@ impl Scope { aliases: add_aliases(var_store), // TODO(abilities): default abilities in scope abilities_store: AbilitiesStore::default(), + imports: Vec::new(), } } @@ -101,15 +105,18 @@ impl Scope { match self.idents.get_symbol(ident) { Some(symbol) => Ok(symbol), None => { + for (import, symbol, _) in self.imports.iter() { + if ident == import { + return Ok(*symbol); + } + } + let error = RuntimeError::LookupNotInScope( Loc { region, value: ident.clone(), }, - self.idents - .iter_idents() - .map(|v| v.as_ref().into()) - .collect(), + self.idents_in_scope().map(|v| v.as_ref().into()).collect(), ); Err(error) @@ -117,9 +124,11 @@ impl Scope { } } - #[cfg(test)] fn idents_in_scope(&self) -> impl Iterator + '_ { - self.idents.iter_idents() + let it1 = self.idents.iter_idents(); + let it2 = self.imports.iter().map(|t| t.0.clone()); + + it1.chain(it2) } pub fn lookup_alias(&self, symbol: Symbol) -> Option<&Alias> { @@ -235,7 +244,19 @@ impl Scope { }; Err((original_region, shadow)) } - None => Ok(self.commit_introduction(ident, region)), + None => { + for (import, _, original_region) in self.imports.iter() { + if ident == import { + let shadow = Loc { + value: ident.clone(), + region, + }; + return Err((*original_region, shadow)); + } + } + + Ok(self.commit_introduction(ident, region)) + } } } @@ -317,14 +338,15 @@ impl Scope { symbol: Symbol, region: Region, ) -> Result<(), (Symbol, Region)> { - match self.idents.get_symbol_and_region(&ident) { - Some(shadowed) => Err(shadowed), - None => { - self.idents.insert_unchecked(&ident, symbol, region); - - Ok(()) + for t in self.imports.iter() { + if t.0 == ident { + return Err((t.1, t.2)); } } + + self.imports.push((ident, symbol, region)); + + Ok(()) } pub fn add_alias( @@ -641,4 +663,48 @@ mod test { assert_eq!(&idents[builtin_count..], &[ident1, ident2, ident3,]); } + + #[test] + fn import_is_in_scope() { + let _register_module_debug_names = ModuleIds::default(); + let mut scope = Scope::new(ModuleId::ATTR, IdentIds::default()); + + let ident = Ident::from("product"); + let symbol = Symbol::LIST_PRODUCT; + let region = Region::zero(); + + assert!(scope.lookup(&ident, region).is_err()); + + assert!(scope.import(ident.clone(), symbol, region).is_ok()); + + assert!(scope.lookup(&ident, region).is_ok()); + + assert!(scope.idents_in_scope().any(|x| x == ident)); + } + + #[test] + fn shadow_of_import() { + let _register_module_debug_names = ModuleIds::default(); + let mut scope = Scope::new(ModuleId::ATTR, IdentIds::default()); + + let ident = Ident::from("product"); + let symbol = Symbol::LIST_PRODUCT; + + let region1 = Region::from_pos(Position { offset: 10 }); + let region2 = Region::from_pos(Position { offset: 20 }); + + scope.import(ident.clone(), symbol, region1).unwrap(); + + let (original_region, _ident, shadow_symbol) = + scope.introduce(ident.clone(), region2).unwrap_err(); + + scope.register_debug_idents(); + + assert_ne!(symbol, shadow_symbol); + assert_eq!(original_region, region1); + + let lookup = scope.lookup(&ident, Region::zero()).unwrap(); + + assert_eq!(symbol, lookup); + } } From 9906623e3426edfe15950d5a47a9f18812619574 Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 29 Apr 2022 20:28:32 +0200 Subject: [PATCH 697/846] scoped locals step 1 --- compiler/can/src/scope.rs | 168 ++++++++++++++++++++++++++++++++------ 1 file changed, 143 insertions(+), 25 deletions(-) diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index 9b9000b582..e34d1a3bea 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -1,6 +1,6 @@ use roc_collections::{MutSet, SmallStringInterner, VecMap}; use roc_module::ident::{Ident, Lowercase}; -use roc_module::symbol::{IdentIds, ModuleId, Symbol}; +use roc_module::symbol::{IdentId, IdentIds, ModuleId, Symbol}; use roc_problem::can::RuntimeError; use roc_region::all::{Loc, Region}; use roc_types::subs::{VarStore, Variable}; @@ -8,10 +8,14 @@ use roc_types::types::{Alias, AliasKind, Type}; use crate::abilities::AbilitiesStore; +use bitvec::vec::BitVec; + #[derive(Clone, Debug)] pub struct Scope { idents: IdentStore, + locals: ScopedIdentIds, + /// The type aliases currently in scope pub aliases: VecMap, @@ -72,15 +76,21 @@ fn add_aliases(var_store: &mut VarStore) -> VecMap { impl Scope { pub fn new(home: ModuleId, initial_ident_ids: IdentIds) -> Scope { + let imports = Symbol::default_in_scope() + .into_iter() + .map(|(a, (b, c))| (a, b, c)) + .collect(); + Scope { home, exposed_ident_count: initial_ident_ids.len(), + locals: ScopedIdentIds::from_ident_ids(initial_ident_ids.clone()), ident_ids: initial_ident_ids, idents: IdentStore::new(), aliases: VecMap::default(), // TODO(abilities): default abilities in scope abilities_store: AbilitiesStore::default(), - imports: Vec::new(), + imports, } } @@ -89,15 +99,21 @@ impl Scope { var_store: &mut VarStore, initial_ident_ids: IdentIds, ) -> Scope { + let imports = Symbol::default_in_scope() + .into_iter() + .map(|(a, (b, c))| (a, b, c)) + .collect(); + Scope { home, exposed_ident_count: initial_ident_ids.len(), + locals: ScopedIdentIds::from_ident_ids(initial_ident_ids.clone()), ident_ids: initial_ident_ids, idents: IdentStore::new(), aliases: add_aliases(var_store), // TODO(abilities): default abilities in scope abilities_store: AbilitiesStore::default(), - imports: Vec::new(), + imports, } } @@ -125,10 +141,10 @@ impl Scope { } fn idents_in_scope(&self) -> impl Iterator + '_ { - let it1 = self.idents.iter_idents(); + let it1 = self.locals.idents_in_scope(); let it2 = self.imports.iter().map(|t| t.0.clone()); - it1.chain(it2) + it2.chain(it1) } pub fn lookup_alias(&self, symbol: Symbol) -> Option<&Alias> { @@ -238,6 +254,8 @@ impl Scope { ) -> Result)> { match self.idents.get_symbol_and_region(ident) { Some((_, original_region)) => { + assert!(self.locals.has_in_scope(ident).is_some()); + let shadow = Loc { value: ident.clone(), region, @@ -245,6 +263,8 @@ impl Scope { Err((original_region, shadow)) } None => { + assert!(self.locals.has_in_scope(ident).is_none()); + for (import, _, original_region) in self.imports.iter() { if ident == import { let shadow = Loc { @@ -317,6 +337,8 @@ impl Scope { self.idents.insert_unchecked(ident, symbol, region); + self.locals.introduce_into_scope(ident, region); + symbol } @@ -378,11 +400,13 @@ impl Scope { // - exposed_ident_count: unchanged let idents = self.idents.clone(); let aliases_count = self.aliases.len(); + let locals_snapshot = self.locals.snapshot(); let result = f(self); self.idents = idents; self.aliases.truncate(aliases_count); + self.locals.revert(locals_snapshot); result } @@ -461,31 +485,13 @@ struct IdentStore { impl IdentStore { fn new() -> Self { - let defaults = Symbol::default_in_scope(); - let capacity = defaults.len(); + let capacity = 64; - let mut this = Self { + Self { interner: SmallStringInterner::with_capacity(capacity), symbols: Vec::with_capacity(capacity), regions: Vec::with_capacity(capacity), - }; - - for (ident, (symbol, region)) in defaults { - this.insert_unchecked(&ident, symbol, region); } - - this - } - - fn iter_idents(&self) -> impl Iterator + '_ { - self.interner.iter().filter_map(move |string| { - // empty string is used when ability members are shadowed - if string.is_empty() { - None - } else { - Some(Ident::from(string)) - } - }) } fn iter_idents_symbols(&self) -> impl Iterator + '_ { @@ -532,6 +538,95 @@ impl IdentStore { } } +#[derive(Clone, Debug)] +struct ScopedIdentIds { + ident_ids: IdentIds, + in_scope: BitVec, + regions: Vec, +} + +impl ScopedIdentIds { + fn from_ident_ids(ident_ids: IdentIds) -> Self { + let capacity = ident_ids.len(); + + Self { + in_scope: BitVec::repeat(false, capacity), + ident_ids, + regions: std::iter::repeat(Region::zero()).take(capacity).collect(), + } + } + + fn len(&self) -> usize { + self.in_scope.count_ones() + } + + fn is_empty(&self) -> bool { + self.len() == 0 + } + + fn snapshot(&self) -> usize { + debug_assert_eq!(self.ident_ids.len(), self.in_scope.len()); + + self.ident_ids.len() + } + + fn revert(&mut self, snapshot: usize) { + for i in snapshot..self.in_scope.len() { + self.in_scope.set(i, false); + } + } + + fn has_in_scope(&self, ident: &Ident) -> Option { + self.ident_ids + .ident_strs() + .zip(self.in_scope.iter()) + .find_map(|((ident_id, string), keep)| { + if *keep && string == ident.as_str() { + Some(ident_id) + } else { + None + } + }) + } + + fn idents_in_scope(&self) -> impl Iterator + '_ { + self.ident_ids + .ident_strs() + .zip(self.in_scope.iter()) + .filter_map(|((_, string), keep)| { + if *keep { + Some(Ident::from(string)) + } else { + None + } + }) + } + + fn introduce_into_scope(&mut self, ident_name: &Ident, region: Region) -> IdentId { + let id = self.ident_ids.add_ident(ident_name); + + debug_assert_eq!(id.index(), self.in_scope.len()); + debug_assert_eq!(id.index(), self.regions.len()); + + self.in_scope.push(true); + self.regions.push(region); + + id + } + + fn scopeless(&mut self, ident_name: &Ident, region: Region) -> IdentId { + let id = self.ident_ids.add_ident(ident_name); + + debug_assert_eq!(id.index(), self.in_scope.len()); + debug_assert_eq!(id.index(), self.regions.len()); + + self.in_scope.push(false); + self.regions.push(region); + + id + } +} + #[cfg(test)] mod test { use super::*; @@ -597,6 +692,29 @@ mod test { assert!(scope.lookup(&ident, region).is_err()); } + #[test] + fn default_idents_in_scope() { + let _register_module_debug_names = ModuleIds::default(); + let scope = Scope::new(ModuleId::ATTR, IdentIds::default()); + + let idents: Vec<_> = scope.idents_in_scope().collect(); + + assert_eq!( + &idents, + &[ + Ident::from("Box"), + Ident::from("Set"), + Ident::from("Dict"), + Ident::from("Str"), + Ident::from("Ok"), + Ident::from("False"), + Ident::from("List"), + Ident::from("True"), + Ident::from("Err"), + ] + ); + } + #[test] fn idents_with_inner_scope() { let _register_module_debug_names = ModuleIds::default(); From c725c27c1b1b908cfc010cb6e80d64c49d4da0dd Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 29 Apr 2022 20:44:42 +0200 Subject: [PATCH 698/846] step 2 --- compiler/can/src/scope.rs | 41 +++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index e34d1a3bea..85e7408db1 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -162,19 +162,9 @@ impl Scope { debug_assert!(opaque_ref.starts_with('@')); let opaque = opaque_ref[1..].into(); - match self.idents.get_symbol_and_region(&opaque) { - // TODO: is it worth caching any of these results? - Some((symbol, decl_region)) => { - if symbol.module_id() != self.home { - // The reference is to an opaque type declared in another module - this is - // illegal, as opaque types can only be wrapped/unwrapped in the scope they're - // declared. - return Err(RuntimeError::OpaqueOutsideScope { - opaque, - referenced_region: lookup_region, - imported_region: decl_region, - }); - } + match self.locals.has_in_scope(&opaque) { + Some((ident_id, _)) => { + let symbol = Symbol::new(self.home, ident_id); match self.aliases.get(&symbol) { None => Err(self.opaque_not_defined_error(opaque, lookup_region, None)), @@ -191,7 +181,22 @@ impl Scope { }, } } - None => Err(self.opaque_not_defined_error(opaque, lookup_region, None)), + None => { + for (import, _, decl_region) in self.imports.iter() { + if &opaque == import { + // The reference is to an opaque type declared in another module - this is + // illegal, as opaque types can only be wrapped/unwrapped in the scope they're + // declared. + return Err(RuntimeError::OpaqueOutsideScope { + opaque, + referenced_region: lookup_region, + imported_region: *decl_region, + }); + } + } + + Err(self.opaque_not_defined_error(opaque, lookup_region, None)) + } } } @@ -252,10 +257,8 @@ impl Scope { ident: &Ident, region: Region, ) -> Result)> { - match self.idents.get_symbol_and_region(ident) { + match self.locals.has_in_scope(ident) { Some((_, original_region)) => { - assert!(self.locals.has_in_scope(ident).is_some()); - let shadow = Loc { value: ident.clone(), region, @@ -576,13 +579,13 @@ impl ScopedIdentIds { } } - fn has_in_scope(&self, ident: &Ident) -> Option { + fn has_in_scope(&self, ident: &Ident) -> Option<(IdentId, Region)> { self.ident_ids .ident_strs() .zip(self.in_scope.iter()) .find_map(|((ident_id, string), keep)| { if *keep && string == ident.as_str() { - Some(ident_id) + Some((ident_id, self.regions[ident_id.index()])) } else { None } From 76a9d25f55390a35a245165de709e383da1150ba Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 29 Apr 2022 21:21:32 +0200 Subject: [PATCH 699/846] step 3 --- compiler/can/src/scope.rs | 62 +++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 12 deletions(-) diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index 85e7408db1..34606d7bd6 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -84,7 +84,7 @@ impl Scope { Scope { home, exposed_ident_count: initial_ident_ids.len(), - locals: ScopedIdentIds::from_ident_ids(initial_ident_ids.clone()), + locals: ScopedIdentIds::from_ident_ids(home, initial_ident_ids.clone()), ident_ids: initial_ident_ids, idents: IdentStore::new(), aliases: VecMap::default(), @@ -107,7 +107,7 @@ impl Scope { Scope { home, exposed_ident_count: initial_ident_ids.len(), - locals: ScopedIdentIds::from_ident_ids(initial_ident_ids.clone()), + locals: ScopedIdentIds::from_ident_ids(home, initial_ident_ids.clone()), ident_ids: initial_ident_ids, idents: IdentStore::new(), aliases: add_aliases(var_store), @@ -118,7 +118,16 @@ impl Scope { } pub fn lookup(&self, ident: &Ident, region: Region) -> Result { - match self.idents.get_symbol(ident) { + // match self.idents.get_symbol(ident) { + + let a = self.idents.get_symbol(ident); + let b = self.locals.get_symbol(ident); + + // dbg!(ident); + + // assert_eq!(a, b, "{:?} != {:?} | {:?}", a, b, ident); + + match a { Some(symbol) => Ok(symbol), None => { for (import, symbol, _) in self.imports.iter() { @@ -311,6 +320,8 @@ impl Scope { let dummy = Ident::default(); self.idents.insert_unchecked(&dummy, shadow_symbol, region); + let _ = self.locals.scopeless(&ident, region); + Ok((shadow_symbol, Some(original_symbol))) } else { // This is an illegal shadow. @@ -331,18 +342,29 @@ impl Scope { fn commit_introduction(&mut self, ident: &Ident, region: Region) -> Symbol { // if the identifier is exposed, use the IdentId we already have for it - let ident_id = match self.ident_ids.get_id(ident) { - Some(ident_id) if ident_id.index() < self.exposed_ident_count => ident_id, - _ => self.ident_ids.add_ident(ident), - }; + match self.ident_ids.get_id(ident) { + Some(ident_id) if ident_id.index() < self.exposed_ident_count => { + let symbol = Symbol::new(self.home, ident_id); - let symbol = Symbol::new(self.home, ident_id); + self.idents.insert_unchecked(ident, symbol, region); - self.idents.insert_unchecked(ident, symbol, region); + self.locals.in_scope.set(ident_id.index(), true); + self.locals.regions[ident_id.index()] = region; - self.locals.introduce_into_scope(ident, region); + symbol + } + _ => { + let ident_id = self.ident_ids.add_ident(ident); - symbol + let symbol = Symbol::new(self.home, ident_id); + + self.idents.insert_unchecked(ident, symbol, region); + + self.locals.introduce_into_scope(ident, region); + + symbol + } + } } /// Ignore an identifier. @@ -350,6 +372,7 @@ impl Scope { /// Used for record guards like { x: Just _ } pub fn ignore(&mut self, ident: &Ident) -> Symbol { let ident_id = self.ident_ids.add_ident(ident); + let _ = self.locals.scopeless(ident, Region::zero()); Symbol::new(self.home, ident_id) } @@ -546,16 +569,18 @@ struct ScopedIdentIds { ident_ids: IdentIds, in_scope: BitVec, regions: Vec, + home: ModuleId, } impl ScopedIdentIds { - fn from_ident_ids(ident_ids: IdentIds) -> Self { + fn from_ident_ids(home: ModuleId, ident_ids: IdentIds) -> Self { let capacity = ident_ids.len(); Self { in_scope: BitVec::repeat(false, capacity), ident_ids, regions: std::iter::repeat(Region::zero()).take(capacity).collect(), + home, } } @@ -579,6 +604,19 @@ impl ScopedIdentIds { } } + fn get_symbol(&self, ident: &Ident) -> Option { + self.ident_ids + .ident_strs() + .zip(self.in_scope.iter()) + .find_map(|((ident_id, string), keep)| { + if *keep && string == ident.as_str() { + Some(Symbol::new(self.home, ident_id)) + } else { + None + } + }) + } + fn has_in_scope(&self, ident: &Ident) -> Option<(IdentId, Region)> { self.ident_ids .ident_strs() From fe28d1554ba6cdba6817ec395262e174815a2bfa Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 29 Apr 2022 16:26:10 -0400 Subject: [PATCH 700/846] Only assert that rigids are introduced at given rank behind flag Closes #2489 --- compiler/solve/src/solve.rs | 12 +++++------- compiler/solve/tests/solve_expr.rs | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index 92488b6f3a..7d74a83200 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -678,6 +678,8 @@ fn solve( pools.get_mut(next_rank).extend(pool_variables); debug_assert_eq!( + // Check that no variable ended up in a higher rank than the next rank.. that + // would mean we generalized one level more than we need to! { let offenders = pools .get(next_rank) @@ -704,7 +706,7 @@ fn solve( pools.get_mut(next_rank).clear(); // check that things went well - debug_assert!({ + if cfg!(debug_assertions) && std::env::var("ROC_VERIFY_RIGID_RANKS").is_ok() { let rigid_vars = &constraints.variables[let_con.rigid_vars.indices()]; // NOTE the `subs.redundant` check does not come from elm. @@ -720,13 +722,9 @@ fn solve( let failing: Vec<_> = it.collect(); println!("Rigids {:?}", &rigid_vars); println!("Failing {:?}", failing); - - // nicer error message - failing.is_empty() - } else { - true + assert!(false) } - }); + } let mut new_env = env.clone(); for (symbol, loc_var) in local_def_vars.iter() { diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index 414e1e3a6d..7ca9f461c7 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -6215,4 +6215,23 @@ mod solve_expr { "a -> Task a *", ); } + + #[test] + fn export_rigid_to_lower_rank() { + infer_eq_without_problem( + indoc!( + r#" + app "test" provides [ foo ] to "./platform" + + F a : { foo : a } + + foo = \arg -> + x : F b + x = arg + x.foo + "# + ), + "F b -> b", + ) + } } From 9964f86a3d2932fafbb8775ffc1d2c79fed98d58 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 29 Apr 2022 17:45:55 -0400 Subject: [PATCH 701/846] Factor bespoke debug variables into debug_flags crate --- Cargo.lock | 8 +++ Cargo.toml | 1 + compiler/README.md | 41 ++++++++-------- compiler/debug_flags/Cargo.toml | 6 +++ compiler/debug_flags/src/lib.rs | 79 ++++++++++++++++++++++++++++++ compiler/load_internal/Cargo.toml | 3 +- compiler/load_internal/src/file.rs | 38 +++++++------- compiler/mono/Cargo.toml | 1 + compiler/mono/src/ir.rs | 7 +-- compiler/types/Cargo.toml | 1 + compiler/types/src/pretty_print.rs | 7 +-- compiler/unify/Cargo.toml | 3 ++ compiler/unify/src/unify.rs | 42 ++++++++-------- 13 files changed, 167 insertions(+), 70 deletions(-) create mode 100644 compiler/debug_flags/Cargo.toml create mode 100644 compiler/debug_flags/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index c5e3621ba0..72da692c47 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3540,6 +3540,10 @@ dependencies = [ "roc_types", ] +[[package]] +name = "roc_debug_flags" +version = "0.1.0" + [[package]] name = "roc_docs" version = "0.1.0" @@ -3765,6 +3769,7 @@ dependencies = [ "roc_can", "roc_collections", "roc_constrain", + "roc_debug_flags", "roc_error_macros", "roc_module", "roc_mono", @@ -3806,6 +3811,7 @@ dependencies = [ "roc_builtins", "roc_can", "roc_collections", + "roc_debug_flags", "roc_error_macros", "roc_exhaustive", "roc_module", @@ -4004,6 +4010,7 @@ version = "0.1.0" dependencies = [ "bumpalo", "roc_collections", + "roc_debug_flags", "roc_error_macros", "roc_module", "roc_region", @@ -4017,6 +4024,7 @@ version = "0.1.0" dependencies = [ "bitflags", "roc_collections", + "roc_debug_flags", "roc_error_macros", "roc_module", "roc_types", diff --git a/Cargo.toml b/Cargo.toml index 1e721c0d62..706c467a3a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,7 @@ members = [ "compiler/arena_pool", "compiler/test_gen", "compiler/roc_target", + "compiler/debug_flags", "vendor/ena", "vendor/inkwell", "vendor/pathfinding", diff --git a/compiler/README.md b/compiler/README.md index d26c7e862e..d4c93aab03 100644 --- a/compiler/README.md +++ b/compiler/README.md @@ -165,23 +165,19 @@ The compiler is invoked from the CLI via `build_file` in cli/src/build.rs For a more detailed understanding of the compilation phases, see the `Phase`, `BuildTask`, and `Msg` enums in `load/src/file.rs`. -## Debugging intermediate representations +## Debugging the compiler -### Debugging the typechecker +Please see the [debug flags](./debug_flags/src/lib.rs) for information on how to +ask the compiler to emit debug information during various stages of compilation. -Setting the following environment variables: +There are some goals for more sophisticated debugging tools: -- `ROC_PRINT_UNIFICATIONS` prints all type unifications that are done, - before and after the unification. -- `ROC_PRINT_MISMATCHES` prints all type mismatches hit during unification. -- `ROC_PRETTY_PRINT_ALIAS_CONTENTS` expands the contents of aliases during - pretty-printing of types. +- A nicer unification debugger, see https://github.com/rtfeldman/roc/issues/2486. + Any interest in helping out here is greatly appreciated. -Note that this is only relevant during debug builds. Eventually we should have -some better debugging tools here, see https://github.com/rtfeldman/roc/issues/2486 -for one. +### General Tips -### The mono IR +#### Miscompilations If you observe a miscomplication, you may first want to check the generated mono IR for your code - maybe there was a problem during specialization or layout @@ -189,13 +185,16 @@ generation. One way to do this is to add a test to `test_mono/src/tests.rs` and run the tests with `cargo test -p test_mono`; this will write the mono IR to a file. -You may also want to set some or all of the following environment variables: +#### Typechecking errors -- `PRINT_IR_AFTER_SPECIALIZATION=1` prints the mono IR after function - specialization to stdout -- `PRINT_IR_AFTER_RESET_REUSE=1` prints the mono IR after insertion of - reset/reuse isntructions to stdout -- `PRINT_IR_AFTER_REFCOUNT=1` prints the mono IR after insertion of reference - counting instructions to stdout -- `PRETTY_PRINT_IR_SYMBOLS=1` instructs the pretty printer to dump all the - information it knows about the mono IR whenever it is printed +First, try to minimize your reproduction into a test that fits in +[`solve_expr`](./solve/tests/solve_expr.rs). + +Once you've done this, check out the `ROC_PRINT_UNIFICATIONS` debug flag. It +will show you where type unification went right and wrong. This is usually +enough to figure out a fix for the bug. + +If that doesn't work and you know your error has something to do with ranks, +you may want to instrument `deep_copy_var_help` in [solve](./solve/src/solve.rs). + +If that doesn't work, chatting on Zulip is always a good strategy. diff --git a/compiler/debug_flags/Cargo.toml b/compiler/debug_flags/Cargo.toml new file mode 100644 index 0000000000..8aecfb22ec --- /dev/null +++ b/compiler/debug_flags/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "roc_debug_flags" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/compiler/debug_flags/src/lib.rs b/compiler/debug_flags/src/lib.rs new file mode 100644 index 0000000000..801ab53533 --- /dev/null +++ b/compiler/debug_flags/src/lib.rs @@ -0,0 +1,79 @@ +//! Flags for debugging the Roc compiler. +//! +//! Lists environment variable flags that can be enabled for verbose debugging features in debug +//! builds of the compiler. +//! +//! For example, I might define the following alias to run cargo with all unifications and +//! expanded type aliases printed: +//! +//! ```bash +//! alias cargo="\ +//! ROC_PRINT_UNIFICATIONS=1 \ +//! ROC_PRETTY_PRINT_ALIAS_CONTENTS=1 \ +//! cargo" +//! ``` +//! +//! More generally, I have the following: +//! +//! ```bash +//! alias cargo="\ +//! ROC_PRETTY_PRINT_ALIAS_CONTENTS=0 \ +//! ROC_PRINT_UNIFICATIONS=0 \ +//! ROC_PRINT_MISMATCHES=0 \ +//! ROC_PRINT_IR_AFTER_SPECIALIZATION=0 \ +//! ROC_PRINT_IR_AFTER_RESET_REUSE=0 \ +//! ROC_PRINT_IR_AFTER_REFCOUNT=0 \ +//! ROC_PRETTY_PRINT_IR_SYMBOLS=0 \ +//! cargo" +//! ``` +//! +//! Now you can turn debug flags on and off as you like. + +#[macro_export] +macro_rules! dbg_do { + ($flag:path, $expr:expr) => { + #[cfg(debug_assertions)] + { + if std::env::var($flag).unwrap_or("0".to_string()) != "0" { + $expr + } + } + }; +} + +macro_rules! flags { + ($($(#[doc = $doc:expr])+ $flag:ident)*) => {$( + $(#[doc = $doc])+ + pub static $flag: &str = stringify!($flag); + )*}; +} + +flags! { + // ===Types=== + + /// Expands the contents of aliases during pretty-printing of types. + ROC_PRETTY_PRINT_ALIAS_CONTENTS + + // ===Solve=== + + /// Prints type unifications, before and after they happen. + ROC_PRINT_UNIFICATIONS + + /// Prints all type mismatches hit during type unification. + ROC_PRINT_MISMATCHES + + // ===Mono=== + + /// Writes the mono IR to stderr after function specialization + ROC_PRINT_IR_AFTER_SPECIALIZATION + + /// Writes the mono IR to stderr after insertion of reset/reuse instructions + ROC_PRINT_IR_AFTER_RESET_REUSE + + /// Writes the mono IR to stderr after insertion of refcount instructions + ROC_PRINT_IR_AFTER_REFCOUNT + + /// Instructs the mono IR pretty printer to dump pretty symbols and verbose + /// layout information + ROC_PRETTY_PRINT_IR_SYMBOLS +} diff --git a/compiler/load_internal/Cargo.toml b/compiler/load_internal/Cargo.toml index 28641d1c1b..df3ffe4ffb 100644 --- a/compiler/load_internal/Cargo.toml +++ b/compiler/load_internal/Cargo.toml @@ -21,6 +21,7 @@ roc_solve = { path = "../solve" } roc_mono = { path = "../mono" } roc_target = { path = "../roc_target" } roc_reporting = { path = "../../reporting" } +roc_debug_flags = { path = "../debug_flags" } morphic_lib = { path = "../../vendor/morphic_lib" } ven_pretty = { path = "../../vendor/pretty" } bumpalo = { version = "3.8.0", features = ["collections"] } @@ -33,4 +34,4 @@ tempfile = "3.2.0" pretty_assertions = "1.0.0" maplit = "1.0.2" indoc = "1.0.3" -roc_test_utils = { path = "../../test_utils" } \ No newline at end of file +roc_test_utils = { path = "../../test_utils" } diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index aea2867805..0d2bcbc4b8 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -15,6 +15,10 @@ use roc_constrain::module::{ constrain_builtin_imports, constrain_module, ExposedByModule, ExposedForModule, ExposedModuleTypes, }; +use roc_debug_flags::{ + dbg_do, ROC_PRINT_IR_AFTER_REFCOUNT, ROC_PRINT_IR_AFTER_RESET_REUSE, + ROC_PRINT_IR_AFTER_SPECIALIZATION, +}; use roc_error_macros::internal_error; use roc_module::ident::{Ident, ModuleName, QualifiedModuleName, TagName}; use roc_module::symbol::{ @@ -1627,21 +1631,20 @@ fn start_tasks<'a>( Ok(()) } -#[cfg(debug_assertions)] -fn debug_print_ir(state: &State, flag: &str) { - if env::var(flag) != Ok("1".into()) { - return; - } +macro_rules! debug_print_ir { + ($state:expr, $flag:path) => { + dbg_do!($flag, { + let procs_string = $state + .procedures + .values() + .map(|proc| proc.to_pretty(200)) + .collect::>(); - let procs_string = state - .procedures - .values() - .map(|proc| proc.to_pretty(200)) - .collect::>(); + let result = procs_string.join("\n"); - let result = procs_string.join("\n"); - - println!("{}", result); + eprintln!("{}", result); + }) + }; } /// Report modules that are imported, but from which nothing is used @@ -2181,8 +2184,7 @@ fn update<'a>( && state.dependencies.solved_all() && state.goal_phase == Phase::MakeSpecializations { - #[cfg(debug_assertions)] - debug_print_ir(&state, "PRINT_IR_AFTER_SPECIALIZATION"); + debug_print_ir!(state, ROC_PRINT_IR_AFTER_SPECIALIZATION); Proc::insert_reset_reuse_operations( arena, @@ -2192,13 +2194,11 @@ fn update<'a>( &mut state.procedures, ); - #[cfg(debug_assertions)] - debug_print_ir(&state, "PRINT_IR_AFTER_RESET_REUSE"); + debug_print_ir!(state, ROC_PRINT_IR_AFTER_RESET_REUSE); Proc::insert_refcount_operations(arena, &mut state.procedures); - #[cfg(debug_assertions)] - debug_print_ir(&state, "PRINT_IR_AFTER_REFCOUNT"); + debug_print_ir!(state, ROC_PRINT_IR_AFTER_REFCOUNT); // This is not safe with the new non-recursive RC updates that we do for tag unions // diff --git a/compiler/mono/Cargo.toml b/compiler/mono/Cargo.toml index d47714ebdd..79b1ea060c 100644 --- a/compiler/mono/Cargo.toml +++ b/compiler/mono/Cargo.toml @@ -19,6 +19,7 @@ roc_problem = { path = "../problem" } roc_builtins = { path = "../builtins" } roc_target = { path = "../roc_target" } roc_error_macros = {path="../../error_macros"} +roc_debug_flags = {path="../debug_flags"} ven_pretty = { path = "../../vendor/pretty" } morphic_lib = { path = "../../vendor/morphic_lib" } bumpalo = { version = "3.8.0", features = ["collections"] } diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 1b0875c14a..790eaef5ce 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -10,6 +10,7 @@ use roc_builtins::bitcode::{FloatWidth, IntWidth}; use roc_can::abilities::AbilitiesStore; use roc_can::expr::{AnnotatedMark, ClosureData, IntValue}; use roc_collections::all::{default_hasher, BumpMap, BumpMapDefault, MutMap}; +use roc_debug_flags::{dbg_do, ROC_PRETTY_PRINT_IR_SYMBOLS}; use roc_exhaustive::{Ctor, CtorName, Guard, RenderAs, TagId}; use roc_module::ident::{ForeignSymbol, Lowercase, TagName}; use roc_module::low_level::LowLevel; @@ -25,11 +26,11 @@ use roc_types::subs::{ use std::collections::HashMap; use ven_pretty::{BoxAllocator, DocAllocator, DocBuilder}; +#[inline(always)] pub fn pretty_print_ir_symbols() -> bool { - #[cfg(debug_assertions)] - if std::env::var("PRETTY_PRINT_IR_SYMBOLS") == Ok("1".into()) { + dbg_do!(ROC_PRETTY_PRINT_IR_SYMBOLS, { return true; - } + }); false } diff --git a/compiler/types/Cargo.toml b/compiler/types/Cargo.toml index 550cb5f333..e00c368701 100644 --- a/compiler/types/Cargo.toml +++ b/compiler/types/Cargo.toml @@ -10,6 +10,7 @@ roc_collections = { path = "../collections" } roc_region = { path = "../region" } roc_module = { path = "../module" } roc_error_macros = {path="../../error_macros"} +roc_debug_flags = {path="../debug_flags"} ven_ena = { path = "../../vendor/ena" } bumpalo = { version = "3.8.0", features = ["collections"] } static_assertions = "1.1.0" diff --git a/compiler/types/src/pretty_print.rs b/compiler/types/src/pretty_print.rs index 917e4a33e0..b266edddb8 100644 --- a/compiler/types/src/pretty_print.rs +++ b/compiler/types/src/pretty_print.rs @@ -449,15 +449,12 @@ fn write_content<'a>( ); } - // useful for debugging - if cfg!(debug_assertions) - && std::env::var("ROC_PRETTY_PRINT_ALIAS_CONTENTS").is_ok() - { + roc_debug_flags::dbg_do!(roc_debug_flags::ROC_PRETTY_PRINT_ALIAS_CONTENTS, { buf.push_str("[[ but really "); let content = subs.get_content_without_compacting(*_actual); write_content(env, ctx, content, subs, buf, parens); buf.push_str("]]"); - } + }); }), } } diff --git a/compiler/unify/Cargo.toml b/compiler/unify/Cargo.toml index d8622ed928..e92e2aa3e3 100644 --- a/compiler/unify/Cargo.toml +++ b/compiler/unify/Cargo.toml @@ -19,3 +19,6 @@ path = "../module" [dependencies.roc_types] path = "../types" + +[dependencies.roc_debug_flags] +path = "../debug_flags" diff --git a/compiler/unify/src/unify.rs b/compiler/unify/src/unify.rs index f5c224bc09..9a5ca9a28a 100644 --- a/compiler/unify/src/unify.rs +++ b/compiler/unify/src/unify.rs @@ -1,4 +1,5 @@ use bitflags::bitflags; +use roc_debug_flags::{dbg_do, ROC_PRINT_MISMATCHES, ROC_PRINT_UNIFICATIONS}; use roc_error_macros::internal_error; use roc_module::ident::{Lowercase, TagName}; use roc_module::symbol::Symbol; @@ -11,14 +12,14 @@ use roc_types::types::{AliasKind, DoesNotImplementAbility, ErrorType, Mismatch, macro_rules! mismatch { () => {{ - if cfg!(debug_assertions) && std::env::var("ROC_PRINT_MISMATCHES").is_ok() { - println!( + dbg_do!(ROC_PRINT_MISMATCHES, { + eprintln!( "Mismatch in {} Line {} Column {}", file!(), line!(), column!() ); - } + }) Outcome { mismatches: vec![Mismatch::TypeMismatch], @@ -26,17 +27,16 @@ macro_rules! mismatch { } }}; ($msg:expr) => {{ - if cfg!(debug_assertions) && std::env::var("ROC_PRINT_MISMATCHES").is_ok() { - println!( + dbg_do!(ROC_PRINT_MISMATCHES, { + eprintln!( "Mismatch in {} Line {} Column {}", file!(), line!(), column!() ); - println!($msg); - println!(""); - } - + eprintln!($msg); + eprintln!(""); + }); Outcome { mismatches: vec![Mismatch::TypeMismatch], @@ -47,16 +47,16 @@ macro_rules! mismatch { mismatch!($msg) }}; ($msg:expr, $($arg:tt)*) => {{ - if cfg!(debug_assertions) && std::env::var("ROC_PRINT_MISMATCHES").is_ok() { - println!( + dbg_do!(ROC_PRINT_MISMATCHES, { + eprintln!( "Mismatch in {} Line {} Column {}", file!(), line!(), column!() ); - println!($msg, $($arg)*); - println!(""); - } + eprintln!($msg, $($arg)*); + eprintln!(""); + }); Outcome { mismatches: vec![Mismatch::TypeMismatch], @@ -64,16 +64,16 @@ macro_rules! mismatch { } }}; (%not_able, $var:expr, $ability:expr, $msg:expr, $($arg:tt)*) => {{ - if cfg!(debug_assertions) && std::env::var("ROC_PRINT_MISMATCHES").is_ok() { - println!( + dbg_do!(ROC_PRINT_MISMATCHES, { + eprintln!( "Mismatch in {} Line {} Column {}", file!(), line!(), column!() ); - println!($msg, $($arg)*); - println!(""); - } + eprintln!($msg, $($arg)*); + eprintln!(""); + }); Outcome { mismatches: vec![Mismatch::TypeMismatch, Mismatch::DoesNotImplementAbiity($var, $ability)], @@ -298,7 +298,7 @@ fn debug_print_unified_types(subs: &mut Subs, ctx: &Context, opt_outcome: Option static mut UNIFICATION_DEPTH: usize = 0; - if std::env::var("ROC_PRINT_UNIFICATIONS").is_ok() { + dbg_do!(ROC_PRINT_UNIFICATIONS, { let prefix = match opt_outcome { None => "❔", Some(outcome) if outcome.mismatches.is_empty() => "✅", @@ -340,7 +340,7 @@ fn debug_print_unified_types(subs: &mut Subs, ctx: &Context, opt_outcome: Option ); unsafe { UNIFICATION_DEPTH = new_depth }; - } + }) } fn unify_context(subs: &mut Subs, pool: &mut Pool, ctx: Context) -> Outcome { From 3411a4b26667c482947b6510fe218b63f8773a6e Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 29 Apr 2022 17:49:40 -0400 Subject: [PATCH 702/846] Simplify --- compiler/solve/src/solve.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index 7d74a83200..ae67dbf36c 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -722,7 +722,7 @@ fn solve( let failing: Vec<_> = it.collect(); println!("Rigids {:?}", &rigid_vars); println!("Failing {:?}", failing); - assert!(false) + debug_assert!(false); } } From 8fe3e24c8ba0347256740b53e881806c8b3eb5c7 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 30 Apr 2022 00:51:32 +0200 Subject: [PATCH 703/846] step 4: new scope with passing reporting tests --- compiler/can/src/annotation.rs | 5 +- compiler/can/src/def.rs | 6 +- compiler/can/src/env.rs | 3 +- compiler/can/src/module.rs | 8 +- compiler/can/src/scope.rs | 175 +++++++++-------------------- compiler/load_internal/src/docs.rs | 7 +- compiler/load_internal/src/file.rs | 2 +- reporting/tests/helpers/mod.rs | 2 +- 8 files changed, 71 insertions(+), 137 deletions(-) diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index 45f42692e4..d3de23d808 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -299,7 +299,7 @@ fn make_apply_symbol( /// `U8`, and `Str`. pub fn find_type_def_symbols( module_id: ModuleId, - ident_ids: &mut IdentIds, + ident_ids: &mut crate::scope::ScopedIdentIds, initial_annotation: &roc_parse::ast::TypeAnnotation, ) -> Vec { use roc_parse::ast::TypeAnnotation::*; @@ -312,9 +312,8 @@ pub fn find_type_def_symbols( match annotation { Apply(_module_name, ident, arguments) => { let ident: Ident = (*ident).into(); - let ident_id = ident_ids.get_or_insert(&ident); + let symbol = ident_ids.scopeless_symbol(&ident, Region::zero()); - let symbol = Symbol::new(module_id, ident_id); result.push(symbol); for t in arguments.iter() { diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index f93b8732e2..df88d636c0 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -279,8 +279,7 @@ pub(crate) fn canonicalize_defs<'a>( } => { let referenced_symbols = crate::annotation::find_type_def_symbols( env.home, - // TODO IDENT_IDS - &mut scope.ident_ids, + &mut scope.locals, &ann.value, ); @@ -297,8 +296,7 @@ pub(crate) fn canonicalize_defs<'a>( // definition. referenced_symbols.extend(crate::annotation::find_type_def_symbols( env.home, - // TODO IDENT_IDS - &mut scope.ident_ids, + &mut scope.locals, &member.typ.value, )); } diff --git a/compiler/can/src/env.rs b/compiler/can/src/env.rs index 550ce5abec..12cb7ce00c 100644 --- a/compiler/can/src/env.rs +++ b/compiler/can/src/env.rs @@ -77,7 +77,7 @@ impl<'a> Env<'a> { // You can do qualified lookups on your own module, e.g. // if I'm in the Foo module, I can do a `Foo.bar` lookup. if module_id == self.home { - match scope.ident_ids.get_id(&ident) { + match scope.locals.ident_ids.get_id(&ident) { Some(ident_id) => { let symbol = Symbol::new(module_id, ident_id); @@ -96,6 +96,7 @@ impl<'a> Env<'a> { region, }, scope + .locals .ident_ids .ident_strs() .map(|(_, string)| string.into()) diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index 7f79b60f4d..183e883f85 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -404,8 +404,12 @@ pub fn canonicalize_module_defs<'a>( GeneratedInfo::Hosted { effect_symbol, .. } => { let symbol = def.pattern_vars.iter().next().unwrap().0; let ident_id = symbol.ident_id(); - let ident = - scope.ident_ids.get_name(ident_id).unwrap().to_string(); + let ident = scope + .locals + .ident_ids + .get_name(ident_id) + .unwrap() + .to_string(); let def_annotation = def.annotation.clone().unwrap(); let annotation = crate::annotation::Annotation { typ: def_annotation.signature, diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index 34606d7bd6..bb4f90fe84 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -12,9 +12,7 @@ use bitvec::vec::BitVec; #[derive(Clone, Debug)] pub struct Scope { - idents: IdentStore, - - locals: ScopedIdentIds, + pub locals: ScopedIdentIds, /// The type aliases currently in scope pub aliases: VecMap, @@ -26,8 +24,6 @@ pub struct Scope { /// unqualified idents into Symbols. home: ModuleId, - pub ident_ids: IdentIds, - /// The first `exposed_ident_count` identifiers are exposed exposed_ident_count: usize, @@ -84,9 +80,7 @@ impl Scope { Scope { home, exposed_ident_count: initial_ident_ids.len(), - locals: ScopedIdentIds::from_ident_ids(home, initial_ident_ids.clone()), - ident_ids: initial_ident_ids, - idents: IdentStore::new(), + locals: ScopedIdentIds::from_ident_ids(home, initial_ident_ids), aliases: VecMap::default(), // TODO(abilities): default abilities in scope abilities_store: AbilitiesStore::default(), @@ -107,9 +101,7 @@ impl Scope { Scope { home, exposed_ident_count: initial_ident_ids.len(), - locals: ScopedIdentIds::from_ident_ids(home, initial_ident_ids.clone()), - ident_ids: initial_ident_ids, - idents: IdentStore::new(), + locals: ScopedIdentIds::from_ident_ids(home, initial_ident_ids), aliases: add_aliases(var_store), // TODO(abilities): default abilities in scope abilities_store: AbilitiesStore::default(), @@ -120,14 +112,14 @@ impl Scope { pub fn lookup(&self, ident: &Ident, region: Region) -> Result { // match self.idents.get_symbol(ident) { - let a = self.idents.get_symbol(ident); + // let a = self.idents.get_symbol(ident); let b = self.locals.get_symbol(ident); // dbg!(ident); // assert_eq!(a, b, "{:?} != {:?} | {:?}", a, b, ident); - match a { + match b { Some(symbol) => Ok(symbol), None => { for (import, symbol, _) in self.imports.iter() { @@ -216,8 +208,16 @@ impl Scope { opt_defined_alias: Option, ) -> RuntimeError { let opaques_in_scope = self - .idents - .iter_idents_symbols() + .locals + .ident_ids + .ident_strs() + .filter_map(|(ident_id, string)| { + if string.is_empty() { + None + } else { + Some((string, Symbol::new(self.home, ident_id))) + } + }) .filter(|(_, sym)| { self.aliases .get(sym) @@ -225,7 +225,7 @@ impl Scope { .unwrap_or(AliasKind::Structural) == AliasKind::Opaque }) - .map(|(v, _)| v.as_ref().into()) + .map(|(v, _)| v.into()) .collect(); RuntimeError::OpaqueNotDefined { @@ -252,8 +252,7 @@ impl Scope { match self.introduce_without_shadow_symbol(&ident, region) { Ok(symbol) => Ok(symbol), Err((original_region, shadow)) => { - let ident_id = self.ident_ids.add_ident(&ident); - let symbol = Symbol::new(self.home, ident_id); + let symbol = self.locals.scopeless_symbol(&ident, region); Err((original_region, shadow, symbol)) } @@ -304,23 +303,22 @@ impl Scope { ident: Ident, region: Region, ) -> Result<(Symbol, Option), (Region, Loc, Symbol)> { - match self.idents.get_index(&ident) { - Some(index) => { - let original_symbol = self.idents.symbols[index]; - let original_region = self.idents.regions[index]; + match self.locals.has_in_scope(&ident) { + Some((ident_id, original_region)) => { + let index = ident_id.index(); - let shadow_ident_id = self.ident_ids.add_ident(&ident); - let shadow_symbol = Symbol::new(self.home, shadow_ident_id); + let original_symbol = Symbol::new(self.home, ident_id); + let shadow_symbol = self.locals.scopeless_symbol(&ident, region); if self.abilities_store.is_ability_member_name(original_symbol) { self.abilities_store .register_specializing_symbol(shadow_symbol, original_symbol); - // Add a symbol for the shadow, but don't re-associate the member name. - let dummy = Ident::default(); - self.idents.insert_unchecked(&dummy, shadow_symbol, region); - - let _ = self.locals.scopeless(&ident, region); + // // Add a symbol for the shadow, but don't re-associate the member name. + // let dummy = Ident::default(); + // self.idents.insert_unchecked(&dummy, shadow_symbol, region); + // + // let _ = self.locals.scopeless(&ident, region); Ok((shadow_symbol, Some(original_symbol))) } else { @@ -342,27 +340,18 @@ impl Scope { fn commit_introduction(&mut self, ident: &Ident, region: Region) -> Symbol { // if the identifier is exposed, use the IdentId we already have for it - match self.ident_ids.get_id(ident) { + match self.locals.ident_ids.get_id(ident) { Some(ident_id) if ident_id.index() < self.exposed_ident_count => { let symbol = Symbol::new(self.home, ident_id); - self.idents.insert_unchecked(ident, symbol, region); - self.locals.in_scope.set(ident_id.index(), true); self.locals.regions[ident_id.index()] = region; symbol } _ => { - let ident_id = self.ident_ids.add_ident(ident); - - let symbol = Symbol::new(self.home, ident_id); - - self.idents.insert_unchecked(ident, symbol, region); - - self.locals.introduce_into_scope(ident, region); - - symbol + let ident_id = self.locals.introduce_into_scope(ident, region); + Symbol::new(self.home, ident_id) } } } @@ -371,9 +360,7 @@ impl Scope { /// /// Used for record guards like { x: Just _ } pub fn ignore(&mut self, ident: &Ident) -> Symbol { - let ident_id = self.ident_ids.add_ident(ident); - let _ = self.locals.scopeless(ident, Region::zero()); - Symbol::new(self.home, ident_id) + self.locals.scopeless_symbol(&ident, Region::zero()) } /// Import a Symbol from another module into this module's top-level scope. @@ -424,13 +411,11 @@ impl Scope { // - idents: we have to clone for now // - aliases: stored in a VecMap, we just discard anything added in an inner scope // - exposed_ident_count: unchanged - let idents = self.idents.clone(); let aliases_count = self.aliases.len(); let locals_snapshot = self.locals.snapshot(); let result = f(self); - self.idents = idents; self.aliases.truncate(aliases_count); self.locals.revert(locals_snapshot); @@ -438,7 +423,7 @@ impl Scope { } pub fn register_debug_idents(&self) { - self.home.register_debug_idents(&self.ident_ids) + self.home.register_debug_idents(&self.locals.ident_ids) } /// Generates a unique, new symbol like "$1" or "$5", @@ -447,7 +432,7 @@ impl Scope { /// This is used, for example, during canonicalization of an Expr::Closure /// to generate a unique symbol to refer to that closure. pub fn gen_unique_symbol(&mut self) -> Symbol { - let ident_id = self.ident_ids.gen_unique(); + let ident_id = self.locals.gen_unique(); Symbol::new(self.home, ident_id) } @@ -499,74 +484,8 @@ pub fn create_alias( } #[derive(Clone, Debug)] -struct IdentStore { - interner: SmallStringInterner, - - /// A Symbol for each Ident - symbols: Vec, - - /// A Region for each Ident - regions: Vec, -} - -impl IdentStore { - fn new() -> Self { - let capacity = 64; - - Self { - interner: SmallStringInterner::with_capacity(capacity), - symbols: Vec::with_capacity(capacity), - regions: Vec::with_capacity(capacity), - } - } - - fn iter_idents_symbols(&self) -> impl Iterator + '_ { - self.interner - .iter() - .zip(self.symbols.iter()) - .filter_map(move |(string, symbol)| { - // empty slice is used when ability members are shadowed - if string.is_empty() { - None - } else { - Some((Ident::from(string), *symbol)) - } - }) - } - - fn get_index(&self, ident: &Ident) -> Option { - let ident_str = ident.as_inline_str().as_str(); - - self.interner.find_index(ident_str) - } - - fn get_symbol(&self, ident: &Ident) -> Option { - Some(self.symbols[self.get_index(ident)?]) - } - - fn get_symbol_and_region(&self, ident: &Ident) -> Option<(Symbol, Region)> { - let index = self.get_index(ident)?; - - Some((self.symbols[index], self.regions[index])) - } - - /// Does not check that the ident is unique - fn insert_unchecked(&mut self, ident: &Ident, symbol: Symbol, region: Region) { - let ident_str = ident.as_inline_str().as_str(); - - let index = self.interner.insert(ident_str); - - debug_assert_eq!(index, self.symbols.len()); - debug_assert_eq!(index, self.regions.len()); - - self.symbols.push(symbol); - self.regions.push(region); - } -} - -#[derive(Clone, Debug)] -struct ScopedIdentIds { - ident_ids: IdentIds, +pub struct ScopedIdentIds { + pub ident_ids: IdentIds, in_scope: BitVec, regions: Vec, home: ModuleId, @@ -584,14 +503,6 @@ impl ScopedIdentIds { } } - fn len(&self) -> usize { - self.in_scope.count_ones() - } - - fn is_empty(&self) -> bool { - self.len() == 0 - } - fn snapshot(&self) -> usize { debug_assert_eq!(self.ident_ids.len(), self.in_scope.len()); @@ -655,6 +566,10 @@ impl ScopedIdentIds { id } + pub fn scopeless_symbol(&mut self, ident_name: &Ident, region: Region) -> Symbol { + Symbol::new(self.home, self.scopeless(ident_name, region)) + } + fn scopeless(&mut self, ident_name: &Ident, region: Region) -> IdentId { let id = self.ident_ids.add_ident(ident_name); @@ -666,6 +581,18 @@ impl ScopedIdentIds { id } + + fn gen_unique(&mut self) -> IdentId { + let id = self.ident_ids.gen_unique(); + + debug_assert_eq!(id.index(), self.in_scope.len()); + debug_assert_eq!(id.index(), self.regions.len()); + + self.in_scope.push(false); + self.regions.push(Region::zero()); + + id + } } #[cfg(test)] diff --git a/compiler/load_internal/src/docs.rs b/compiler/load_internal/src/docs.rs index 890ddb46b0..55cdca9328 100644 --- a/compiler/load_internal/src/docs.rs +++ b/compiler/load_internal/src/docs.rs @@ -95,7 +95,12 @@ pub fn generate_module_docs<'a>( parsed_defs .iter() .fold((vec![], None), |(acc, maybe_comments_after), def| { - generate_entry_doc(&scope.ident_ids, acc, maybe_comments_after, &def.value) + generate_entry_doc( + &scope.locals.ident_ids, + acc, + maybe_comments_after, + &def.value, + ) }); ModuleDocumentation { diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index aea2867805..11edbb4913 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -3907,7 +3907,7 @@ fn canonicalize_and_constrain<'a>( var_store, constraints, constraint, - ident_ids: module_output.scope.ident_ids, + ident_ids: module_output.scope.locals.ident_ids, dep_idents, module_timing, }; diff --git a/reporting/tests/helpers/mod.rs b/reporting/tests/helpers/mod.rs index 83918a5934..ed93ebf510 100644 --- a/reporting/tests/helpers/mod.rs +++ b/reporting/tests/helpers/mod.rs @@ -184,7 +184,7 @@ pub fn can_expr_with<'a>( introduce_builtin_imports(&mut constraints, imports, constraint, &mut var_store); let mut all_ident_ids = IdentIds::exposed_builtins(1); - all_ident_ids.insert(home, scope.ident_ids); + all_ident_ids.insert(home, scope.locals.ident_ids); let interns = Interns { module_ids: env.module_ids.clone(), From 953369e0d865f01af38c15688449c09b1e84dc36 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 30 Apr 2022 00:57:21 +0200 Subject: [PATCH 704/846] cleanup --- compiler/can/src/annotation.rs | 3 +-- compiler/can/src/def.rs | 8 ++------ compiler/can/src/scope.rs | 6 ++---- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index d3de23d808..49290f3379 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -2,7 +2,7 @@ use crate::env::Env; use crate::scope::Scope; use roc_collections::{ImMap, MutSet, SendMap, VecMap, VecSet}; use roc_module::ident::{Ident, Lowercase, TagName}; -use roc_module::symbol::{IdentIds, ModuleId, Symbol}; +use roc_module::symbol::Symbol; use roc_parse::ast::{AssignedField, ExtractSpaces, Pattern, Tag, TypeAnnotation, TypeHeader}; use roc_problem::can::ShadowKind; use roc_region::all::{Loc, Region}; @@ -298,7 +298,6 @@ fn make_apply_symbol( /// For example, in `[ A Age U8, B Str {} ]`, there are three type definition references - `Age`, /// `U8`, and `Str`. pub fn find_type_def_symbols( - module_id: ModuleId, ident_ids: &mut crate::scope::ScopedIdentIds, initial_annotation: &roc_parse::ast::TypeAnnotation, ) -> Vec { diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index df88d636c0..c78a55dc90 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -277,11 +277,8 @@ pub(crate) fn canonicalize_defs<'a>( ann, kind, } => { - let referenced_symbols = crate::annotation::find_type_def_symbols( - env.home, - &mut scope.locals, - &ann.value, - ); + let referenced_symbols = + crate::annotation::find_type_def_symbols(&mut scope.locals, &ann.value); referenced_type_symbols.insert(name.value, referenced_symbols); @@ -295,7 +292,6 @@ pub(crate) fn canonicalize_defs<'a>( // sure those are processed first before we resolve the whole ability // definition. referenced_symbols.extend(crate::annotation::find_type_def_symbols( - env.home, &mut scope.locals, &member.typ.value, )); diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index bb4f90fe84..743e2ae10c 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -1,4 +1,4 @@ -use roc_collections::{MutSet, SmallStringInterner, VecMap}; +use roc_collections::{MutSet, VecMap}; use roc_module::ident::{Ident, Lowercase}; use roc_module::symbol::{IdentId, IdentIds, ModuleId, Symbol}; use roc_problem::can::RuntimeError; @@ -305,8 +305,6 @@ impl Scope { ) -> Result<(Symbol, Option), (Region, Loc, Symbol)> { match self.locals.has_in_scope(&ident) { Some((ident_id, original_region)) => { - let index = ident_id.index(); - let original_symbol = Symbol::new(self.home, ident_id); let shadow_symbol = self.locals.scopeless_symbol(&ident, region); @@ -360,7 +358,7 @@ impl Scope { /// /// Used for record guards like { x: Just _ } pub fn ignore(&mut self, ident: &Ident) -> Symbol { - self.locals.scopeless_symbol(&ident, Region::zero()) + self.locals.scopeless_symbol(ident, Region::zero()) } /// Import a Symbol from another module into this module's top-level scope. From 6fb014babac375f0bf97491ca542e4945ef127ab Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 30 Apr 2022 01:25:27 +0200 Subject: [PATCH 705/846] more cleanup --- compiler/can/src/annotation.rs | 4 +- compiler/can/src/def.rs | 9 +-- compiler/can/src/pattern.rs | 3 +- compiler/can/src/scope.rs | 130 +++++++-------------------------- reporting/tests/helpers/mod.rs | 35 ++++++++- 5 files changed, 66 insertions(+), 115 deletions(-) diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index 49290f3379..2e857f4079 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -298,7 +298,7 @@ fn make_apply_symbol( /// For example, in `[ A Age U8, B Str {} ]`, there are three type definition references - `Age`, /// `U8`, and `Str`. pub fn find_type_def_symbols( - ident_ids: &mut crate::scope::ScopedIdentIds, + scope: &mut Scope, initial_annotation: &roc_parse::ast::TypeAnnotation, ) -> Vec { use roc_parse::ast::TypeAnnotation::*; @@ -311,7 +311,7 @@ pub fn find_type_def_symbols( match annotation { Apply(_module_name, ident, arguments) => { let ident: Ident = (*ident).into(); - let symbol = ident_ids.scopeless_symbol(&ident, Region::zero()); + let symbol = scope.scopeless_symbol(&ident, Region::zero()); result.push(symbol); diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index c78a55dc90..bbd7d3b8f0 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1,5 +1,6 @@ use crate::abilities::MemberVariables; use crate::annotation::canonicalize_annotation; +use crate::annotation::find_type_def_symbols; use crate::annotation::IntroducedVariables; use crate::env::Env; use crate::expr::AnnotatedMark; @@ -277,8 +278,7 @@ pub(crate) fn canonicalize_defs<'a>( ann, kind, } => { - let referenced_symbols = - crate::annotation::find_type_def_symbols(&mut scope.locals, &ann.value); + let referenced_symbols = find_type_def_symbols(scope, &ann.value); referenced_type_symbols.insert(name.value, referenced_symbols); @@ -291,10 +291,7 @@ pub(crate) fn canonicalize_defs<'a>( // Add the referenced type symbols of each member function. We need to make // sure those are processed first before we resolve the whole ability // definition. - referenced_symbols.extend(crate::annotation::find_type_def_symbols( - &mut scope.locals, - &member.typ.value, - )); + referenced_symbols.extend(find_type_def_symbols(scope, &member.typ.value)); } referenced_type_symbols.insert(name.value, referenced_symbols); diff --git a/compiler/can/src/pattern.rs b/compiler/can/src/pattern.rs index f2ca57a239..b4590a7e24 100644 --- a/compiler/can/src/pattern.rs +++ b/compiler/can/src/pattern.rs @@ -541,7 +541,8 @@ pub fn canonicalize_pattern<'a>( RequiredField(label, loc_guard) => { // a guard does not introduce the label into scope! - let symbol = scope.ignore(&Ident::from(label)); + let symbol = + scope.scopeless_symbol(&Ident::from(label), loc_pattern.region); let can_guard = canonicalize_pattern( env, var_store, diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index 743e2ae10c..55f5199254 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -1,9 +1,9 @@ -use roc_collections::{MutSet, VecMap}; +use roc_collections::VecMap; use roc_module::ident::{Ident, Lowercase}; use roc_module::symbol::{IdentId, IdentIds, ModuleId, Symbol}; use roc_problem::can::RuntimeError; use roc_region::all::{Loc, Region}; -use roc_types::subs::{VarStore, Variable}; +use roc_types::subs::Variable; use roc_types::types::{Alias, AliasKind, Type}; use crate::abilities::AbilitiesStore; @@ -30,46 +30,6 @@ pub struct Scope { imports: Vec<(Ident, Symbol, Region)>, } -fn add_aliases(var_store: &mut VarStore) -> VecMap { - use roc_types::solved_types::{BuiltinAlias, FreeVars}; - - let solved_aliases = roc_types::builtin_aliases::aliases(); - let mut aliases = VecMap::default(); - - for (symbol, builtin_alias) in solved_aliases { - let BuiltinAlias { - region, - vars, - typ, - kind, - } = builtin_alias; - - let mut free_vars = FreeVars::default(); - let typ = roc_types::solved_types::to_type(&typ, &mut free_vars, var_store); - - let mut variables = Vec::new(); - // make sure to sort these variables to make them line up with the type arguments - let mut type_variables: Vec<_> = free_vars.unnamed_vars.into_iter().collect(); - type_variables.sort(); - for (loc_name, (_, var)) in vars.iter().zip(type_variables) { - variables.push(Loc::at(loc_name.region, (loc_name.value.clone(), var))); - } - - let alias = Alias { - region, - typ, - lambda_set_variables: Vec::new(), - recursion_variables: MutSet::default(), - type_variables: variables, - kind, - }; - - aliases.insert(symbol, alias); - } - - aliases -} - impl Scope { pub fn new(home: ModuleId, initial_ident_ids: IdentIds) -> Scope { let imports = Symbol::default_in_scope() @@ -88,38 +48,8 @@ impl Scope { } } - pub fn new_with_aliases( - home: ModuleId, - var_store: &mut VarStore, - initial_ident_ids: IdentIds, - ) -> Scope { - let imports = Symbol::default_in_scope() - .into_iter() - .map(|(a, (b, c))| (a, b, c)) - .collect(); - - Scope { - home, - exposed_ident_count: initial_ident_ids.len(), - locals: ScopedIdentIds::from_ident_ids(home, initial_ident_ids), - aliases: add_aliases(var_store), - // TODO(abilities): default abilities in scope - abilities_store: AbilitiesStore::default(), - imports, - } - } - pub fn lookup(&self, ident: &Ident, region: Region) -> Result { - // match self.idents.get_symbol(ident) { - - // let a = self.idents.get_symbol(ident); - let b = self.locals.get_symbol(ident); - - // dbg!(ident); - - // assert_eq!(a, b, "{:?} != {:?} | {:?}", a, b, ident); - - match b { + match self.locals.get_symbol(ident) { Some(symbol) => Ok(symbol), None => { for (import, symbol, _) in self.imports.iter() { @@ -164,9 +94,7 @@ impl Scope { let opaque = opaque_ref[1..].into(); match self.locals.has_in_scope(&opaque) { - Some((ident_id, _)) => { - let symbol = Symbol::new(self.home, ident_id); - + Some((symbol, _)) => { match self.aliases.get(&symbol) { None => Err(self.opaque_not_defined_error(opaque, lookup_region, None)), @@ -252,7 +180,7 @@ impl Scope { match self.introduce_without_shadow_symbol(&ident, region) { Ok(symbol) => Ok(symbol), Err((original_region, shadow)) => { - let symbol = self.locals.scopeless_symbol(&ident, region); + let symbol = self.scopeless_symbol(&ident, region); Err((original_region, shadow, symbol)) } @@ -274,8 +202,6 @@ impl Scope { Err((original_region, shadow)) } None => { - assert!(self.locals.has_in_scope(ident).is_none()); - for (import, _, original_region) in self.imports.iter() { if ident == import { let shadow = Loc { @@ -304,20 +230,13 @@ impl Scope { region: Region, ) -> Result<(Symbol, Option), (Region, Loc, Symbol)> { match self.locals.has_in_scope(&ident) { - Some((ident_id, original_region)) => { - let original_symbol = Symbol::new(self.home, ident_id); - let shadow_symbol = self.locals.scopeless_symbol(&ident, region); + Some((original_symbol, original_region)) => { + let shadow_symbol = self.scopeless_symbol(&ident, region); if self.abilities_store.is_ability_member_name(original_symbol) { self.abilities_store .register_specializing_symbol(shadow_symbol, original_symbol); - // // Add a symbol for the shadow, but don't re-associate the member name. - // let dummy = Ident::default(); - // self.idents.insert_unchecked(&dummy, shadow_symbol, region); - // - // let _ = self.locals.scopeless(&ident, region); - Ok((shadow_symbol, Some(original_symbol))) } else { // This is an illegal shadow. @@ -338,6 +257,7 @@ impl Scope { fn commit_introduction(&mut self, ident: &Ident, region: Region) -> Symbol { // if the identifier is exposed, use the IdentId we already have for it + // other modules depend on the symbol having that IdentId match self.locals.ident_ids.get_id(ident) { Some(ident_id) if ident_id.index() < self.exposed_ident_count => { let symbol = Symbol::new(self.home, ident_id); @@ -354,11 +274,13 @@ impl Scope { } } - /// Ignore an identifier. + /// Create a new symbol, but don't add it to the scope (yet) /// - /// Used for record guards like { x: Just _ } - pub fn ignore(&mut self, ident: &Ident) -> Symbol { - self.locals.scopeless_symbol(ident, Region::zero()) + /// Used for record guards like { x: Just _ } where the `x` is not added to the scope, + /// but also in other places where we need to create a symbol and we don't have the right + /// scope information yet. An identifier can be introduced later, and will use the same IdentId + pub fn scopeless_symbol(&mut self, ident: &Ident, region: Region) -> Symbol { + self.locals.scopeless_symbol(ident, region) } /// Import a Symbol from another module into this module's top-level scope. @@ -405,10 +327,10 @@ impl Scope { // store enough information to roll back to the original outer scope // // - abilities_store: ability definitions not allowed in inner scopes - // - ident_ids: identifiers in inner scopes should still be available in the ident_ids - // - idents: we have to clone for now + // - locals: everything introduced in the inner scope is marked as not in scope in the rollback // - aliases: stored in a VecMap, we just discard anything added in an inner scope // - exposed_ident_count: unchanged + // - home: unchanged let aliases_count = self.aliases.len(); let locals_snapshot = self.locals.snapshot(); @@ -430,9 +352,7 @@ impl Scope { /// This is used, for example, during canonicalization of an Expr::Closure /// to generate a unique symbol to refer to that closure. pub fn gen_unique_symbol(&mut self) -> Symbol { - let ident_id = self.locals.gen_unique(); - - Symbol::new(self.home, ident_id) + Symbol::new(self.home, self.locals.gen_unique()) } } @@ -526,13 +446,16 @@ impl ScopedIdentIds { }) } - fn has_in_scope(&self, ident: &Ident) -> Option<(IdentId, Region)> { + fn has_in_scope(&self, ident: &Ident) -> Option<(Symbol, Region)> { self.ident_ids .ident_strs() .zip(self.in_scope.iter()) .find_map(|((ident_id, string), keep)| { if *keep && string == ident.as_str() { - Some((ident_id, self.regions[ident_id.index()])) + Some(( + Symbol::new(self.home, ident_id), + self.regions[ident_id.index()], + )) } else { None } @@ -564,11 +487,8 @@ impl ScopedIdentIds { id } - pub fn scopeless_symbol(&mut self, ident_name: &Ident, region: Region) -> Symbol { - Symbol::new(self.home, self.scopeless(ident_name, region)) - } - - fn scopeless(&mut self, ident_name: &Ident, region: Region) -> IdentId { + /// Adds an IdentId, but does not introduce it to the scope + fn scopeless_symbol(&mut self, ident_name: &Ident, region: Region) -> Symbol { let id = self.ident_ids.add_ident(ident_name); debug_assert_eq!(id.index(), self.in_scope.len()); @@ -577,7 +497,7 @@ impl ScopedIdentIds { self.in_scope.push(false); self.regions.push(region); - id + Symbol::new(self.home, id) } fn gen_unique(&mut self) -> IdentId { diff --git a/reporting/tests/helpers/mod.rs b/reporting/tests/helpers/mod.rs index ed93ebf510..01712519e2 100644 --- a/reporting/tests/helpers/mod.rs +++ b/reporting/tests/helpers/mod.rs @@ -151,7 +151,12 @@ pub fn can_expr_with<'a>( // rules multiple times unnecessarily. let loc_expr = operator::desugar_expr(arena, &loc_expr); - let mut scope = Scope::new_with_aliases(home, &mut var_store, IdentIds::default()); + let mut scope = Scope::new(home, IdentIds::default()); + + // to skip loading other modules, we populate the scope with the builtin aliases + // that makes the reporting tests much faster + add_aliases(&mut scope, &mut var_store); + let dep_idents = IdentIds::exposed_builtins(0); let mut env = Env::new(home, &dep_idents, &module_ids); let (loc_expr, output) = canonicalize_expr( @@ -204,6 +209,34 @@ pub fn can_expr_with<'a>( }) } +fn add_aliases(scope: &mut Scope, var_store: &mut VarStore) { + use roc_types::solved_types::{BuiltinAlias, FreeVars}; + + let solved_aliases = roc_types::builtin_aliases::aliases(); + + for (symbol, builtin_alias) in solved_aliases { + let BuiltinAlias { + region, + vars, + typ, + kind, + } = builtin_alias; + + let mut free_vars = FreeVars::default(); + let typ = roc_types::solved_types::to_type(&typ, &mut free_vars, var_store); + + let mut variables = Vec::new(); + // make sure to sort these variables to make them line up with the type arguments + let mut type_variables: Vec<_> = free_vars.unnamed_vars.into_iter().collect(); + type_variables.sort(); + for (loc_name, (_, var)) in vars.iter().zip(type_variables) { + variables.push(Loc::at(loc_name.region, (loc_name.value.clone(), var))); + } + + scope.add_alias(symbol, region, variables, typ, kind); + } +} + #[allow(dead_code)] pub fn mut_map_from_pairs(pairs: I) -> MutMap where From 4ad5e532c1bb5396f4dc6fcfc1bf8d40c147026f Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 30 Apr 2022 01:35:15 +0200 Subject: [PATCH 706/846] even more cleanup --- compiler/can/src/scope.rs | 47 ++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index 55f5199254..3d83f8f87a 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -12,8 +12,6 @@ use bitvec::vec::BitVec; #[derive(Clone, Debug)] pub struct Scope { - pub locals: ScopedIdentIds, - /// The type aliases currently in scope pub aliases: VecMap, @@ -27,7 +25,11 @@ pub struct Scope { /// The first `exposed_ident_count` identifiers are exposed exposed_ident_count: usize, + /// Identifiers that are imported (and introduced in the header) imports: Vec<(Ident, Symbol, Region)>, + + /// Identifiers that are in scope, and defined in the current module + pub locals: ScopedIdentIds, } impl Scope { @@ -49,15 +51,9 @@ impl Scope { } pub fn lookup(&self, ident: &Ident, region: Region) -> Result { - match self.locals.get_symbol(ident) { - Some(symbol) => Ok(symbol), + match self.scope_contains(ident) { + Some((symbol, _)) => Ok(symbol), None => { - for (import, symbol, _) in self.imports.iter() { - if ident == import { - return Ok(*symbol); - } - } - let error = RuntimeError::LookupNotInScope( Loc { region, @@ -163,6 +159,19 @@ impl Scope { } } + /// Is an identifier in scope, either in the locals or imports + fn scope_contains(&self, ident: &Ident) -> Option<(Symbol, Region)> { + self.locals.has_in_scope(ident).or_else(|| { + for (import, shadow, original_region) in self.imports.iter() { + if ident == import { + return Some((*shadow, *original_region)); + } + } + + None + }) + } + /// Introduce a new ident to scope. /// /// Returns Err if this would shadow an existing ident, including the @@ -193,7 +202,7 @@ impl Scope { ident: &Ident, region: Region, ) -> Result)> { - match self.locals.has_in_scope(ident) { + match self.scope_contains(ident) { Some((_, original_region)) => { let shadow = Loc { value: ident.clone(), @@ -201,19 +210,7 @@ impl Scope { }; Err((original_region, shadow)) } - None => { - for (import, _, original_region) in self.imports.iter() { - if ident == import { - let shadow = Loc { - value: ident.clone(), - region, - }; - return Err((*original_region, shadow)); - } - } - - Ok(self.commit_introduction(ident, region)) - } + None => Ok(self.commit_introduction(ident, region)), } } @@ -229,7 +226,7 @@ impl Scope { ident: Ident, region: Region, ) -> Result<(Symbol, Option), (Region, Loc, Symbol)> { - match self.locals.has_in_scope(&ident) { + match self.scope_contains(&ident) { Some((original_symbol, original_region)) => { let shadow_symbol = self.scopeless_symbol(&ident, region); From a78aff0f2fb476d0dab915eef8538a15f4c540d1 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 30 Apr 2022 01:54:16 +0200 Subject: [PATCH 707/846] clippy --- compiler/can/src/scope.rs | 32 +++++++++----------------------- compiler/module/src/symbol.rs | 6 ++++++ 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index 3d83f8f87a..25e10274d3 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -430,33 +430,19 @@ impl ScopedIdentIds { } } - fn get_symbol(&self, ident: &Ident) -> Option { - self.ident_ids - .ident_strs() - .zip(self.in_scope.iter()) - .find_map(|((ident_id, string), keep)| { - if *keep && string == ident.as_str() { - Some(Symbol::new(self.home, ident_id)) - } else { - None - } - }) - } - fn has_in_scope(&self, ident: &Ident) -> Option<(Symbol, Region)> { - self.ident_ids - .ident_strs() - .zip(self.in_scope.iter()) - .find_map(|((ident_id, string), keep)| { - if *keep && string == ident.as_str() { - Some(( + for index in self.in_scope.iter_ones() { + if let Some((ident_id, string)) = self.ident_ids.get_name_at_index(index) { + if string == ident.as_str() { + return Some(( Symbol::new(self.home, ident_id), self.regions[ident_id.index()], - )) - } else { - None + )); } - }) + } + } + + None } fn idents_in_scope(&self) -> impl Iterator + '_ { diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index 462d44a8e4..3e0fe96d77 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -584,6 +584,12 @@ impl IdentIds { self.interner.try_get(id.0 as usize) } + pub fn get_name_at_index(&self, index: usize) -> Option<(IdentId, &str)> { + self.interner + .try_get(index) + .map(|v| (IdentId(index as u32), v)) + } + pub fn get_name_str_res(&self, ident_id: IdentId) -> ModuleResult<&str> { self.get_name(ident_id).with_context(|| IdentIdNotFound { ident_id, From c1d9c63e3718f03efea24037ea7de13dd932493e Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 30 Apr 2022 12:27:50 +0200 Subject: [PATCH 708/846] flip the order of loops to make lookups much faster --- compiler/can/src/scope.rs | 12 +++------ .../collections/src/small_string_interner.rs | 26 ++++++++++++------- compiler/module/src/symbol.rs | 13 +++++----- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index 25e10274d3..7546f25279 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -431,14 +431,10 @@ impl ScopedIdentIds { } fn has_in_scope(&self, ident: &Ident) -> Option<(Symbol, Region)> { - for index in self.in_scope.iter_ones() { - if let Some((ident_id, string)) = self.ident_ids.get_name_at_index(index) { - if string == ident.as_str() { - return Some(( - Symbol::new(self.home, ident_id), - self.regions[ident_id.index()], - )); - } + for ident_id in self.ident_ids.get_id_many(ident) { + let index = ident_id.index(); + if self.in_scope[index] { + return Some((Symbol::new(self.home, ident_id), self.regions[index])); } } diff --git a/compiler/collections/src/small_string_interner.rs b/compiler/collections/src/small_string_interner.rs index 387e6fcd2c..9859767b44 100644 --- a/compiler/collections/src/small_string_interner.rs +++ b/compiler/collections/src/small_string_interner.rs @@ -86,22 +86,30 @@ impl SmallStringInterner { #[inline(always)] pub fn find_index(&self, string: &str) -> Option { + self.find_indices(string).next() + } + + #[inline(always)] + pub fn find_indices<'a>(&'a self, string: &'a str) -> impl Iterator + 'a { let target_length = string.len() as u16; // there can be gaps in the parts of the string that we use (because of updates) // hence we can't just sum the lengths we've seen so far to get the next offset - for (index, length) in self.lengths.iter().enumerate() { - if *length == target_length { - let offset = self.offsets[index]; - let slice = &self.buffer[offset as usize..][..*length as usize]; + self.lengths + .iter() + .enumerate() + .filter_map(move |(index, length)| { + if *length == target_length { + let offset = self.offsets[index]; + let slice = &self.buffer[offset as usize..][..*length as usize]; - if string.as_bytes() == slice { - return Some(index); + if string.as_bytes() == slice { + return Some(index); + } } - } - } - None + None + }) } fn get(&self, index: usize) -> &str { diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index 3e0fe96d77..ab7385ed28 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -580,14 +580,15 @@ impl IdentIds { .map(|i| IdentId(i as u32)) } - pub fn get_name(&self, id: IdentId) -> Option<&str> { - self.interner.try_get(id.0 as usize) + #[inline(always)] + pub fn get_id_many<'a>(&'a self, ident_name: &'a Ident) -> impl Iterator + 'a { + self.interner + .find_indices(ident_name.as_str()) + .map(|i| IdentId(i as u32)) } - pub fn get_name_at_index(&self, index: usize) -> Option<(IdentId, &str)> { - self.interner - .try_get(index) - .map(|v| (IdentId(index as u32), v)) + pub fn get_name(&self, id: IdentId) -> Option<&str> { + self.interner.try_get(id.0 as usize) } pub fn get_name_str_res(&self, ident_id: IdentId) -> ModuleResult<&str> { From d23a14eae601978f5ee058293ee2325892779628 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 30 Apr 2022 14:04:18 +0200 Subject: [PATCH 709/846] fix can tests --- compiler/can/tests/helpers/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/can/tests/helpers/mod.rs b/compiler/can/tests/helpers/mod.rs index 23c1b4191b..aaff51324c 100644 --- a/compiler/can/tests/helpers/mod.rs +++ b/compiler/can/tests/helpers/mod.rs @@ -75,7 +75,7 @@ pub fn can_expr_with(arena: &Bump, home: ModuleId, expr_str: &str) -> CanExprOut ); let mut all_ident_ids = IdentIds::exposed_builtins(1); - all_ident_ids.insert(home, scope.ident_ids); + all_ident_ids.insert(home, scope.locals.ident_ids); let interns = Interns { module_ids: env.module_ids.clone(), From e36aad6310b6c60500390af379b2c699ce1dcb03 Mon Sep 17 00:00:00 2001 From: Sean Hagstrom Date: Sat, 30 Apr 2022 14:25:42 +0100 Subject: [PATCH 710/846] fix(formatter): format and allow inline comments for defs --- compiler/fmt/src/expr.rs | 79 ++++++++++++++++++++++++++-------- compiler/fmt/tests/test_fmt.rs | 61 ++++++++++++++++++++++++++ 2 files changed, 122 insertions(+), 18 deletions(-) diff --git a/compiler/fmt/src/expr.rs b/compiler/fmt/src/expr.rs index 65e1773e34..fecb7fee37 100644 --- a/compiler/fmt/src/expr.rs +++ b/compiler/fmt/src/expr.rs @@ -117,25 +117,16 @@ impl<'a> Formattable for Expr<'a> { use self::Expr::*; //dbg!(self); - let format_newlines = newlines == Newlines::Yes; let apply_needs_parens = parens == Parens::InApply; match self { SpaceBefore(sub_expr, spaces) => { - if format_newlines { - fmt_spaces(buf, spaces.iter(), indent); - } else { - fmt_comments_only(buf, spaces.iter(), NewlineAt::Bottom, indent); - } + format_spaces(buf, spaces, newlines, indent); sub_expr.format_with_options(buf, parens, newlines, indent); } SpaceAfter(sub_expr, spaces) => { sub_expr.format_with_options(buf, parens, newlines, indent); - if format_newlines { - fmt_spaces(buf, spaces.iter(), indent); - } else { - fmt_comments_only(buf, spaces.iter(), NewlineAt::Bottom, indent); - } + format_spaces(buf, spaces, newlines, indent); } ParensAround(sub_expr) => { if parens == Parens::NotNeeded && !sub_expr_requests_parens(sub_expr) { @@ -321,15 +312,39 @@ impl<'a> Formattable for Expr<'a> { fmt_def(buf, &loc_def.value, indent); } - let empty_line_before_return = empty_line_before_expr(&ret.value); + match &ret.value { + SpaceBefore(sub_expr, spaces) => { + let empty_line_before_return = empty_line_before_expr(&ret.value); + let has_inline_comment = with_inline_comment(&ret.value); - if !empty_line_before_return { - buf.newline(); + if has_inline_comment { + buf.spaces(1); + format_spaces(buf, spaces, newlines, indent); + + if !empty_line_before_return { + buf.newline(); + } + + sub_expr.format_with_options( + buf, + Parens::NotNeeded, + Newlines::Yes, + indent, + ); + } else { + if !empty_line_before_return { + buf.newline(); + } + + ret.format_with_options(buf, Parens::NotNeeded, Newlines::Yes, indent); + } + } + _ => { + // Even if there were no defs, which theoretically should never happen, + // still print the return value. + ret.format_with_options(buf, Parens::NotNeeded, Newlines::Yes, indent); + } } - - // Even if there were no defs, which theoretically should never happen, - // still print the return value. - ret.format_with_options(buf, Parens::NotNeeded, Newlines::Yes, indent); } Expect(condition, continuation) => { fmt_expect(buf, condition, continuation, self.is_multiline(), indent); @@ -541,6 +556,34 @@ fn fmt_bin_ops<'a, 'buf>( loc_right_side.format_with_options(buf, apply_needs_parens, Newlines::Yes, next_indent); } +fn format_spaces<'a, 'buf>( + buf: &mut Buf<'buf>, + spaces: &[CommentOrNewline<'a>], + newlines: Newlines, + indent: u16, +) { + let format_newlines = newlines == Newlines::Yes; + + if format_newlines { + fmt_spaces(buf, spaces.iter(), indent); + } else { + fmt_comments_only(buf, spaces.iter(), NewlineAt::Bottom, indent); + } +} + +fn with_inline_comment<'a>(expr: &'a Expr<'a>) -> bool { + use roc_parse::ast::Expr::*; + + match expr { + SpaceBefore(_, spaces) => match spaces.iter().next() { + Some(CommentOrNewline::LineComment(_)) => true, + Some(_) => false, + None => false, + }, + _ => false, + } +} + fn empty_line_before_expr<'a>(expr: &'a Expr<'a>) -> bool { use roc_parse::ast::Expr::*; diff --git a/compiler/fmt/tests/test_fmt.rs b/compiler/fmt/tests/test_fmt.rs index 4dc4e7a6ce..2d88d4b23d 100644 --- a/compiler/fmt/tests/test_fmt.rs +++ b/compiler/fmt/tests/test_fmt.rs @@ -131,6 +131,67 @@ mod test_fmt { ); } + #[test] + fn def_with_inline_comment() { + expr_formats_same(indoc!( + r#" + x = 0 # comment + + x + "# + )); + + expr_formats_to( + indoc!( + r#" + x = 0# comment + + x + "# + ), + indoc!( + r#" + x = 0 # comment + + x + "# + ), + ); + + expr_formats_to( + indoc!( + r#" + x = 0# comment + x + "# + ), + indoc!( + r#" + x = 0 # comment + + x + "# + ), + ); + + expr_formats_to( + indoc!( + r#" + x = 0 # comment + + x + "# + ), + indoc!( + r#" + x = 0 # comment + + x + "# + ), + ); + } + #[test] fn def_with_comment_and_extra_space() { expr_formats_to( From e6621e5167c0b31850c5ccefb995472c6954b8ba Mon Sep 17 00:00:00 2001 From: Sean Hagstrom Date: Sat, 30 Apr 2022 14:37:53 +0100 Subject: [PATCH 711/846] remove outdated test for inline comment formatting I tested if the formatter was still inconsistent by locally changing the helloWorld example to have: ``` main = greeting = "Hello, World!\n" # This variable is for greeting greeting ``` And running the formatter multiple times with `cargo run -- formatter`. At the moment the results are consistent and the inline comments remains inlined. --- compiler/fmt/tests/test_fmt.rs | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/compiler/fmt/tests/test_fmt.rs b/compiler/fmt/tests/test_fmt.rs index 2d88d4b23d..51a87c5797 100644 --- a/compiler/fmt/tests/test_fmt.rs +++ b/compiler/fmt/tests/test_fmt.rs @@ -105,32 +105,6 @@ mod test_fmt { )); } - #[test] - #[ignore] - fn def_with_comment_on_same_line() { - // TODO(joshuawarner32): make trailing comments format stabily - // This test currently fails because the comment ends up as SpaceBefore for the following `a` - // This works fine when formatted _once_ - but if you format again, the formatter wants to - // insert a newline between `a = "Hello"` and the comment, further muddying the waters. - // Clearly the formatter shouldn't be allowed to migrate a comment around like that. - expr_formats_to( - indoc!( - r#" - a = "Hello" # This variable is for greeting - - a - "# - ), - indoc!( - r#" - a = "Hello" - # This variable is for greeting - a - "# - ), - ); - } - #[test] fn def_with_inline_comment() { expr_formats_same(indoc!( From 45197779ae9befba1f054959aa374b49b27df2db Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 30 Apr 2022 15:47:15 +0200 Subject: [PATCH 712/846] re-use idents more aggressively --- compiler/can/src/scope.rs | 151 +++++++++++++----- .../collections/src/small_string_interner.rs | 14 ++ compiler/module/src/symbol.rs | 4 + 3 files changed, 130 insertions(+), 39 deletions(-) diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index 7546f25279..ff4cd03fb5 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -51,9 +51,11 @@ impl Scope { } pub fn lookup(&self, ident: &Ident, region: Region) -> Result { - match self.scope_contains(ident) { - Some((symbol, _)) => Ok(symbol), - None => { + use ContainsIdent::*; + + match self.scope_contains_ident(ident) { + InScope(symbol, _) => Ok(symbol), + NotInScope(_) | NotPresent => { let error = RuntimeError::LookupNotInScope( Loc { region, @@ -159,17 +161,30 @@ impl Scope { } } - /// Is an identifier in scope, either in the locals or imports - fn scope_contains(&self, ident: &Ident) -> Option<(Symbol, Region)> { - self.locals.has_in_scope(ident).or_else(|| { - for (import, shadow, original_region) in self.imports.iter() { - if ident == import { - return Some((*shadow, *original_region)); - } + fn has_imported(&self, ident: &Ident) -> Option<(Symbol, Region)> { + for (import, shadow, original_region) in self.imports.iter() { + if ident == import { + return Some((*shadow, *original_region)); } + } - None - }) + None + } + + /// Is an identifier in scope, either in the locals or imports + fn scope_contains_ident(&self, ident: &Ident) -> ContainsIdent { + let result = self.locals.contains_ident(ident); + match result { + ContainsIdent::InScope(symbol, region) => result, + ContainsIdent::NotInScope(ident_id) => match self.has_imported(ident) { + Some((symbol, region)) => ContainsIdent::InScope(symbol, region), + None => result, + }, + ContainsIdent::NotPresent => match self.has_imported(ident) { + Some((symbol, region)) => ContainsIdent::InScope(symbol, region), + None => ContainsIdent::NotPresent, + }, + } } /// Introduce a new ident to scope. @@ -202,15 +217,38 @@ impl Scope { ident: &Ident, region: Region, ) -> Result)> { - match self.scope_contains(ident) { - Some((_, original_region)) => { + let x = self.scope_contains_ident(ident); + if !self.home.is_builtin() { + dbg!(ident, &x); + } + match x { + ContainsIdent::InScope(_, original_region) => { let shadow = Loc { value: ident.clone(), region, }; Err((original_region, shadow)) } - None => Ok(self.commit_introduction(ident, region)), + ContainsIdent::NotPresent => { + let ident_id = self.locals.introduce_into_scope(ident, region); + Ok(Symbol::new(self.home, ident_id)) + } + ContainsIdent::NotInScope(existing) => { + if existing.index() < self.exposed_ident_count { + // if the identifier is exposed, use the IdentId we already have for it + // other modules depend on the symbol having that IdentId + let symbol = Symbol::new(self.home, existing); + + self.locals.in_scope.set(existing.index(), true); + self.locals.regions[existing.index()] = region; + + Ok(symbol) + } else { + let ident_id = self.locals.introduce_into_scope_duplicate(existing, region); + + Ok(Symbol::new(self.home, ident_id)) + } + } } } @@ -226,9 +264,11 @@ impl Scope { ident: Ident, region: Region, ) -> Result<(Symbol, Option), (Region, Loc, Symbol)> { - match self.scope_contains(&ident) { - Some((original_symbol, original_region)) => { - let shadow_symbol = self.scopeless_symbol(&ident, region); + let ident = &ident; + + match self.scope_contains_ident(ident) { + ContainsIdent::InScope(original_symbol, original_region) => { + let shadow_symbol = self.scopeless_symbol(ident, region); if self.abilities_store.is_ability_member_name(original_symbol) { self.abilities_store @@ -245,28 +285,25 @@ impl Scope { Err((original_region, shadow, shadow_symbol)) } } - None => { - let new_symbol = self.commit_introduction(&ident, region); - Ok((new_symbol, None)) - } - } - } - - fn commit_introduction(&mut self, ident: &Ident, region: Region) -> Symbol { - // if the identifier is exposed, use the IdentId we already have for it - // other modules depend on the symbol having that IdentId - match self.locals.ident_ids.get_id(ident) { - Some(ident_id) if ident_id.index() < self.exposed_ident_count => { - let symbol = Symbol::new(self.home, ident_id); - - self.locals.in_scope.set(ident_id.index(), true); - self.locals.regions[ident_id.index()] = region; - - symbol - } - _ => { + ContainsIdent::NotPresent => { let ident_id = self.locals.introduce_into_scope(ident, region); - Symbol::new(self.home, ident_id) + Ok((Symbol::new(self.home, ident_id), None)) + } + ContainsIdent::NotInScope(existing) => { + if existing.index() < self.exposed_ident_count { + // if the identifier is exposed, use the IdentId we already have for it + // other modules depend on the symbol having that IdentId + let symbol = Symbol::new(self.home, existing); + + self.locals.in_scope.set(existing.index(), true); + self.locals.regions[existing.index()] = region; + + Ok((symbol, None)) + } else { + let ident_id = self.locals.introduce_into_scope_duplicate(existing, region); + + Ok((Symbol::new(self.home, ident_id), None)) + } } } } @@ -398,6 +435,13 @@ pub fn create_alias( } } +#[derive(Debug)] +enum ContainsIdent { + InScope(Symbol, Region), + NotInScope(IdentId), + NotPresent, +} + #[derive(Clone, Debug)] pub struct ScopedIdentIds { pub ident_ids: IdentIds, @@ -441,6 +485,23 @@ impl ScopedIdentIds { None } + fn contains_ident(&self, ident: &Ident) -> ContainsIdent { + use ContainsIdent::*; + + let mut result = NotPresent; + + for ident_id in self.ident_ids.get_id_many(ident) { + let index = ident_id.index(); + if self.in_scope[index] { + return InScope(Symbol::new(self.home, ident_id), self.regions[index]); + } else { + result = NotInScope(ident_id) + } + } + + result + } + fn idents_in_scope(&self) -> impl Iterator + '_ { self.ident_ids .ident_strs() @@ -466,6 +527,18 @@ impl ScopedIdentIds { id } + fn introduce_into_scope_duplicate(&mut self, existing: IdentId, region: Region) -> IdentId { + let id = self.ident_ids.duplicate_ident(existing); + + debug_assert_eq!(id.index(), self.in_scope.len()); + debug_assert_eq!(id.index(), self.regions.len()); + + self.in_scope.push(true); + self.regions.push(region); + + id + } + /// Adds an IdentId, but does not introduce it to the scope fn scopeless_symbol(&mut self, ident_name: &Ident, region: Region) -> Symbol { let id = self.ident_ids.add_ident(ident_name); diff --git a/compiler/collections/src/small_string_interner.rs b/compiler/collections/src/small_string_interner.rs index 9859767b44..8578af9d10 100644 --- a/compiler/collections/src/small_string_interner.rs +++ b/compiler/collections/src/small_string_interner.rs @@ -45,6 +45,7 @@ impl SmallStringInterner { (0..self.offsets.len()).map(move |index| self.get(index)) } + /// Insert without deduplicating pub fn insert(&mut self, string: &str) -> usize { let bytes = string.as_bytes(); @@ -63,6 +64,19 @@ impl SmallStringInterner { index } + /// Create a new entry that uses the same string bytes as an existing entry + pub fn duplicate(&mut self, existing: usize) -> usize { + let offset = self.offsets[existing]; + let length = self.lengths[existing]; + + let index = self.lengths.len(); + + self.lengths.push(length); + self.offsets.push(offset); + + index + } + /// Insert a string equal to the current length into the interner. /// /// Assuming that normally you don't insert strings consisting of just digits, diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index ab7385ed28..14fac71140 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -546,6 +546,10 @@ impl IdentIds { IdentId(self.interner.insert(ident_name.as_str()) as u32) } + pub fn duplicate_ident(&mut self, ident_id: IdentId) -> IdentId { + IdentId(self.interner.duplicate(ident_id.0 as usize) as u32) + } + pub fn get_or_insert(&mut self, name: &Ident) -> IdentId { match self.get_id(name) { Some(id) => id, From ec99d61953583539bd7884e47ba8a4f843907305 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 30 Apr 2022 17:11:46 +0200 Subject: [PATCH 713/846] skip generated symbols when looking for an ident --- compiler/can/src/scope.rs | 50 +++----- .../collections/src/small_string_interner.rs | 114 +++++++++++++++--- compiler/module/src/symbol.rs | 8 +- examples/hello-world/helloWorld.roc | 13 +- 4 files changed, 131 insertions(+), 54 deletions(-) diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index ff4cd03fb5..74bceefb58 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -175,8 +175,8 @@ impl Scope { fn scope_contains_ident(&self, ident: &Ident) -> ContainsIdent { let result = self.locals.contains_ident(ident); match result { - ContainsIdent::InScope(symbol, region) => result, - ContainsIdent::NotInScope(ident_id) => match self.has_imported(ident) { + ContainsIdent::InScope(_, _) => result, + ContainsIdent::NotInScope(_) => match self.has_imported(ident) { Some((symbol, region)) => ContainsIdent::InScope(symbol, region), None => result, }, @@ -217,18 +217,27 @@ impl Scope { ident: &Ident, region: Region, ) -> Result)> { - let x = self.scope_contains_ident(ident); - if !self.home.is_builtin() { - dbg!(ident, &x); - } - match x { - ContainsIdent::InScope(_, original_region) => { + match self.introduce_help(ident, region) { + Err((_, original_region)) => { let shadow = Loc { value: ident.clone(), region, }; Err((original_region, shadow)) } + Ok(symbol) => Ok(symbol), + } + } + + fn introduce_help( + &mut self, + ident: &Ident, + region: Region, + ) -> Result { + match self.scope_contains_ident(ident) { + ContainsIdent::InScope(original_symbol, original_region) => { + Err((original_symbol, original_region)) + } ContainsIdent::NotPresent => { let ident_id = self.locals.introduce_into_scope(ident, region); Ok(Symbol::new(self.home, ident_id)) @@ -266,8 +275,8 @@ impl Scope { ) -> Result<(Symbol, Option), (Region, Loc, Symbol)> { let ident = &ident; - match self.scope_contains_ident(ident) { - ContainsIdent::InScope(original_symbol, original_region) => { + match self.introduce_help(ident, region) { + Err((original_symbol, original_region)) => { let shadow_symbol = self.scopeless_symbol(ident, region); if self.abilities_store.is_ability_member_name(original_symbol) { @@ -285,26 +294,7 @@ impl Scope { Err((original_region, shadow, shadow_symbol)) } } - ContainsIdent::NotPresent => { - let ident_id = self.locals.introduce_into_scope(ident, region); - Ok((Symbol::new(self.home, ident_id), None)) - } - ContainsIdent::NotInScope(existing) => { - if existing.index() < self.exposed_ident_count { - // if the identifier is exposed, use the IdentId we already have for it - // other modules depend on the symbol having that IdentId - let symbol = Symbol::new(self.home, existing); - - self.locals.in_scope.set(existing.index(), true); - self.locals.regions[existing.index()] = region; - - Ok((symbol, None)) - } else { - let ident_id = self.locals.introduce_into_scope_duplicate(existing, region); - - Ok((Symbol::new(self.home, ident_id), None)) - } - } + Ok(symbol) => Ok((symbol, None)), } } diff --git a/compiler/collections/src/small_string_interner.rs b/compiler/collections/src/small_string_interner.rs index 8578af9d10..6b91136c13 100644 --- a/compiler/collections/src/small_string_interner.rs +++ b/compiler/collections/src/small_string_interner.rs @@ -1,3 +1,5 @@ +use std::{fmt::Debug, mem::ManuallyDrop}; + /// Collection of small (length < u16::MAX) strings, stored compactly. #[derive(Clone, Default, PartialEq, Eq)] pub struct SmallStringInterner { @@ -5,10 +7,54 @@ pub struct SmallStringInterner { // lengths could be Vec, but the mono refcount generation // stringifies Layout's and that creates > 256 character strings - lengths: Vec, + lengths: Vec, offsets: Vec, } +#[derive(Copy, Clone, PartialEq, Eq)] +#[repr(transparent)] +struct Length(i16); + +impl std::fmt::Debug for Length { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + self.kind().fmt(f) + } +} + +impl Length { + #[inline(always)] + const fn kind(self) -> Kind { + if self.0 == 0 { + Kind::Emtpy + } else if self.0 > 0 { + Kind::Interned(self.0 as usize) + } else { + Kind::Generated(self.0.abs() as usize) + } + } + + #[inline(always)] + const fn from_usize(len: usize) -> Self { + Self(len as i16) + } +} + +enum Kind { + Generated(usize), + Emtpy, + Interned(usize), +} + +impl Debug for Kind { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Self::Generated(arg0) => write!(f, "Generated({})", arg0), + Self::Emtpy => write!(f, "Emtpy"), + Self::Interned(arg0) => write!(f, "Interned({})", arg0), + } + } +} + impl std::fmt::Debug for SmallStringInterner { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let strings: Vec<_> = self.iter().collect(); @@ -33,7 +79,19 @@ impl SmallStringInterner { } } - pub const fn from_parts(buffer: Vec, lengths: Vec, offsets: Vec) -> Self { + /// # Safety + /// + /// lengths must be non-negative integers less than 2^15 + pub unsafe fn from_parts(buffer: Vec, lengths: Vec, offsets: Vec) -> Self { + // the recommended way of transmuting a vector + let mut lengths = ManuallyDrop::new(lengths); + + let lengths = Vec::from_raw_parts( + lengths.as_mut_ptr().cast(), + lengths.len(), + lengths.capacity(), + ); + Self { buffer, lengths, @@ -49,10 +107,10 @@ impl SmallStringInterner { pub fn insert(&mut self, string: &str) -> usize { let bytes = string.as_bytes(); - assert!(bytes.len() < u16::MAX as usize); + assert!(bytes.len() < (1 << 15)); let offset = self.buffer.len() as u32; - let length = bytes.len() as u16; + let length = Length::from_usize(bytes.len()); let index = self.lengths.len(); @@ -90,9 +148,11 @@ impl SmallStringInterner { let offset = self.buffer.len(); write!(self.buffer, "{}", index).unwrap(); - let length = self.buffer.len() - offset; - self.lengths.push(length as u16); + // this is a generated name, so store it as a negative length + let length = Length(-((self.buffer.len() - offset) as i16)); + + self.lengths.push(length); self.offsets.push(offset as u32); index @@ -105,34 +165,48 @@ impl SmallStringInterner { #[inline(always)] pub fn find_indices<'a>(&'a self, string: &'a str) -> impl Iterator + 'a { - let target_length = string.len() as u16; + let target_length = string.len(); // there can be gaps in the parts of the string that we use (because of updates) // hence we can't just sum the lengths we've seen so far to get the next offset self.lengths .iter() .enumerate() - .filter_map(move |(index, length)| { - if *length == target_length { - let offset = self.offsets[index]; - let slice = &self.buffer[offset as usize..][..*length as usize]; - - if string.as_bytes() == slice { - return Some(index); + .filter_map(move |(index, length)| match length.kind() { + Kind::Generated(_) => None, + Kind::Emtpy => { + if target_length == 0 { + Some(index) + } else { + None } } + Kind::Interned(length) => { + if target_length == length { + let offset = self.offsets[index]; + let slice = &self.buffer[offset as usize..][..length]; - None + if string.as_bytes() == slice { + return Some(index); + } + } + + None + } }) } fn get(&self, index: usize) -> &str { - let length = self.lengths[index] as usize; - let offset = self.offsets[index] as usize; + match self.lengths[index].kind() { + Kind::Emtpy => "", + Kind::Generated(length) | Kind::Interned(length) => { + let offset = self.offsets[index] as usize; - let bytes = &self.buffer[offset..][..length]; + let bytes = &self.buffer[offset..][..length]; - unsafe { std::str::from_utf8_unchecked(bytes) } + unsafe { std::str::from_utf8_unchecked(bytes) } + } + } } pub fn try_get(&self, index: usize) -> Option<&str> { @@ -151,7 +225,7 @@ impl SmallStringInterner { // `buffer`, we can update them in-place self.buffer.extend(new_string.bytes()); - self.lengths[index] = length as u16; + self.lengths[index] = Length::from_usize(length); self.offsets[index] = offset as u32; } diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index 14fac71140..7b09d04532 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -531,7 +531,7 @@ impl IdentId { /// Stores a mapping between Ident and IdentId. #[derive(Clone, Debug, Default, PartialEq, Eq)] pub struct IdentIds { - interner: SmallStringInterner, + pub interner: SmallStringInterner, } impl IdentIds { @@ -759,11 +759,13 @@ macro_rules! define_builtins { } }; - let interner = SmallStringInterner::from_parts ( + // Safety: all lengths are non-negative and smaller than 2^15 + let interner = unsafe { + SmallStringInterner::from_parts ( BUFFER.as_bytes().to_vec(), LENGTHS.to_vec(), OFFSETS.to_vec(), - ); + )}; IdentIds{ interner } }; diff --git a/examples/hello-world/helloWorld.roc b/examples/hello-world/helloWorld.roc index 40f354147d..2381655195 100644 --- a/examples/hello-world/helloWorld.roc +++ b/examples/hello-world/helloWorld.roc @@ -8,4 +8,15 @@ app "helloWorld" imports [] provides [ main ] to pf -main = "Hello, World!\n" +a = + foobar = "Hello" + + foobar + +b = + foobar = "World" + + foobar + +# main = "Hello, World!\n" +main = Str.concat a b From c3ef37d1bd650d0b922947734fdac58d58678116 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 30 Apr 2022 19:11:51 +0200 Subject: [PATCH 714/846] refactor --- compiler/can/src/scope.rs | 179 +++++++++++++++++++------------------- 1 file changed, 90 insertions(+), 89 deletions(-) diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index 74bceefb58..7bf84c86e4 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -76,10 +76,6 @@ impl Scope { it2.chain(it1) } - pub fn lookup_alias(&self, symbol: Symbol) -> Option<&Alias> { - self.aliases.get(&symbol) - } - /// Check if there is an opaque type alias referenced by `opaque_ref` referenced in the /// current scope. E.g. `@Age` must reference an opaque `Age` declared in this module, not any /// other! @@ -92,66 +88,68 @@ impl Scope { let opaque = opaque_ref[1..].into(); match self.locals.has_in_scope(&opaque) { - Some((symbol, _)) => { - match self.aliases.get(&symbol) { - None => Err(self.opaque_not_defined_error(opaque, lookup_region, None)), - - Some(alias) => match alias.kind { - // The reference is to a proper alias like `Age : U32`, not an opaque type! - AliasKind::Structural => Err(self.opaque_not_defined_error( - opaque, - lookup_region, - Some(alias.header_region()), - )), - // All is good - AliasKind::Opaque => Ok((symbol, alias)), - }, + Some((symbol, _)) => match self.lookup_opaque_alias(symbol) { + Ok(alias) => Ok((symbol, alias)), + Err(opt_alias_def_region) => { + Err(self.opaque_not_defined_error(opaque, lookup_region, opt_alias_def_region)) } - } + }, None => { - for (import, _, decl_region) in self.imports.iter() { - if &opaque == import { - // The reference is to an opaque type declared in another module - this is - // illegal, as opaque types can only be wrapped/unwrapped in the scope they're - // declared. - return Err(RuntimeError::OpaqueOutsideScope { - opaque, - referenced_region: lookup_region, - imported_region: *decl_region, - }); + // opaque types can only be wrapped/unwrapped in the scope they are defined in (and below) + let error = if let Some((_, decl_region)) = self.has_imported(&opaque) { + // specific error for when the opaque is imported, which definitely does not work + RuntimeError::OpaqueOutsideScope { + opaque, + referenced_region: lookup_region, + imported_region: decl_region, } - } + } else { + self.opaque_not_defined_error(opaque, lookup_region, None) + }; - Err(self.opaque_not_defined_error(opaque, lookup_region, None)) + Err(error) } } } + fn lookup_opaque_alias(&self, symbol: Symbol) -> Result<&Alias, Option> { + match self.aliases.get(&symbol) { + None => Err(None), + + Some(alias) => match alias.kind { + AliasKind::Opaque => Ok(alias), + AliasKind::Structural => Err(Some(alias.header_region())), + }, + } + } + + fn is_opaque(&self, ident_id: IdentId, string: &str) -> Option> { + if string.is_empty() { + return None; + } + + let symbol = Symbol::new(self.home, ident_id); + + if let Some(AliasKind::Opaque) = self.aliases.get(&symbol).map(|alias| alias.kind) { + Some(string.into()) + } else { + None + } + } + fn opaque_not_defined_error( &self, opaque: Ident, lookup_region: Region, opt_defined_alias: Option, ) -> RuntimeError { + // for opaques, we only look at the locals because opaques can only be matched + // on in the module that defines them. let opaques_in_scope = self .locals .ident_ids .ident_strs() - .filter_map(|(ident_id, string)| { - if string.is_empty() { - None - } else { - Some((string, Symbol::new(self.home, ident_id))) - } - }) - .filter(|(_, sym)| { - self.aliases - .get(sym) - .map(|alias| alias.kind) - .unwrap_or(AliasKind::Structural) - == AliasKind::Opaque - }) - .map(|(v, _)| v.into()) + .filter_map(|(ident_id, string)| self.is_opaque(ident_id, string)) .collect(); RuntimeError::OpaqueNotDefined { @@ -187,6 +185,43 @@ impl Scope { } } + fn introduce_help( + &mut self, + ident: &Ident, + region: Region, + ) -> Result { + match self.scope_contains_ident(ident) { + ContainsIdent::InScope(original_symbol, original_region) => { + // the ident is already in scope; up to the caller how to handle that + // (usually it's shadowing, but it is valid to shadow ability members) + Err((original_symbol, original_region)) + } + ContainsIdent::NotPresent => { + // We know nothing about this ident yet; introduce it to the scope + let ident_id = self.locals.introduce_into_scope(ident, region); + Ok(Symbol::new(self.home, ident_id)) + } + ContainsIdent::NotInScope(existing) => { + // The ident is not in scope, but its name is already in the string interner + if existing.index() < self.exposed_ident_count { + // if the identifier is exposed, use the IdentId we already have for it + // other modules depend on the symbol having that IdentId + let symbol = Symbol::new(self.home, existing); + + self.locals.in_scope.set(existing.index(), true); + self.locals.regions[existing.index()] = region; + + Ok(symbol) + } else { + // create a new IdentId that under the hood uses the same string bytes as an existing one + let ident_id = self.locals.introduce_into_scope_duplicate(existing, region); + + Ok(Symbol::new(self.home, ident_id)) + } + } + } + } + /// Introduce a new ident to scope. /// /// Returns Err if this would shadow an existing ident, including the @@ -229,38 +264,6 @@ impl Scope { } } - fn introduce_help( - &mut self, - ident: &Ident, - region: Region, - ) -> Result { - match self.scope_contains_ident(ident) { - ContainsIdent::InScope(original_symbol, original_region) => { - Err((original_symbol, original_region)) - } - ContainsIdent::NotPresent => { - let ident_id = self.locals.introduce_into_scope(ident, region); - Ok(Symbol::new(self.home, ident_id)) - } - ContainsIdent::NotInScope(existing) => { - if existing.index() < self.exposed_ident_count { - // if the identifier is exposed, use the IdentId we already have for it - // other modules depend on the symbol having that IdentId - let symbol = Symbol::new(self.home, existing); - - self.locals.in_scope.set(existing.index(), true); - self.locals.regions[existing.index()] = region; - - Ok(symbol) - } else { - let ident_id = self.locals.introduce_into_scope_duplicate(existing, region); - - Ok(Symbol::new(self.home, ident_id)) - } - } - } - } - /// Like [Self::introduce], but handles the case of when an ident matches an ability member /// name. In such cases a new symbol is created for the ident (since it's expected to be a /// specialization of the ability member), but the ident is not added to the ident->symbol map. @@ -317,10 +320,8 @@ impl Scope { symbol: Symbol, region: Region, ) -> Result<(), (Symbol, Region)> { - for t in self.imports.iter() { - if t.0 == ident { - return Err((t.1, t.2)); - } + if let Some((s, r)) = self.has_imported(&ident) { + return Err((s, r)); } self.imports.push((ident, symbol, region)); @@ -340,6 +341,10 @@ impl Scope { self.aliases.insert(name, alias); } + pub fn lookup_alias(&self, symbol: Symbol) -> Option<&Alias> { + self.aliases.get(&symbol) + } + pub fn contains_alias(&mut self, name: Symbol) -> bool { self.aliases.contains_key(&name) } @@ -465,14 +470,10 @@ impl ScopedIdentIds { } fn has_in_scope(&self, ident: &Ident) -> Option<(Symbol, Region)> { - for ident_id in self.ident_ids.get_id_many(ident) { - let index = ident_id.index(); - if self.in_scope[index] { - return Some((Symbol::new(self.home, ident_id), self.regions[index])); - } + match self.contains_ident(ident) { + ContainsIdent::InScope(symbol, region) => Some((symbol, region)), + ContainsIdent::NotInScope(_) | ContainsIdent::NotPresent => None, } - - None } fn contains_ident(&self, ident: &Ident) -> ContainsIdent { From 15f860e6d7c83ce6cedbcd99c52655ef6b7dc933 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 30 Apr 2022 19:58:09 +0200 Subject: [PATCH 715/846] search imports first; they are likely to be small, andl likely to contain used types --- compiler/can/src/scope.rs | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index 7bf84c86e4..4db2f54246 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -171,17 +171,10 @@ impl Scope { /// Is an identifier in scope, either in the locals or imports fn scope_contains_ident(&self, ident: &Ident) -> ContainsIdent { - let result = self.locals.contains_ident(ident); - match result { - ContainsIdent::InScope(_, _) => result, - ContainsIdent::NotInScope(_) => match self.has_imported(ident) { - Some((symbol, region)) => ContainsIdent::InScope(symbol, region), - None => result, - }, - ContainsIdent::NotPresent => match self.has_imported(ident) { - Some((symbol, region)) => ContainsIdent::InScope(symbol, region), - None => ContainsIdent::NotPresent, - }, + // exposed imports are likely to be small + match self.has_imported(ident) { + Some((symbol, region)) => ContainsIdent::InScope(symbol, region), + None => self.locals.contains_ident(ident), } } From 76754e4d2a8cf52f9b6b402e6168e000b3aa888f Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 30 Apr 2022 20:37:11 +0200 Subject: [PATCH 716/846] use &str instead of Ident in some key places --- ast/src/lang/scope.rs | 4 +- compiler/can/src/pattern.rs | 2 +- compiler/can/src/scope.rs | 57 +++++++++++-------- .../collections/src/small_string_interner.rs | 10 ++-- compiler/gen_wasm/src/backend.rs | 3 +- compiler/load_internal/src/file.rs | 2 +- compiler/module/src/symbol.rs | 12 ++-- compiler/mono/src/code_gen_help/mod.rs | 3 +- editor/src/editor/mvc/let_update.rs | 4 +- editor/src/editor/mvc/tld_value_update.rs | 7 +-- examples/hello-world/helloWorld.roc | 13 +---- 11 files changed, 57 insertions(+), 60 deletions(-) diff --git a/ast/src/lang/scope.rs b/ast/src/lang/scope.rs index ced87957e4..8cd657f7f9 100644 --- a/ast/src/lang/scope.rs +++ b/ast/src/lang/scope.rs @@ -246,7 +246,7 @@ impl Scope { // use that existing IdentId. Otherwise, create a fresh one. let ident_id = match exposed_ident_ids.get_id(&ident) { Some(ident_id) => ident_id, - None => all_ident_ids.add_ident(&ident), + None => all_ident_ids.add_str(ident.as_str()), }; let symbol = Symbol::new(self.home, ident_id); @@ -263,7 +263,7 @@ impl Scope { /// /// Used for record guards like { x: Just _ } pub fn ignore(&mut self, ident: Ident, all_ident_ids: &mut IdentIds) -> Symbol { - let ident_id = all_ident_ids.add_ident(&ident); + let ident_id = all_ident_ids.add_str(ident.as_str()); Symbol::new(self.home, ident_id) } diff --git a/compiler/can/src/pattern.rs b/compiler/can/src/pattern.rs index b4590a7e24..ca4b77ca39 100644 --- a/compiler/can/src/pattern.rs +++ b/compiler/can/src/pattern.rs @@ -288,7 +288,7 @@ pub fn canonicalize_pattern<'a>( use PatternType::*; let can_pattern = match pattern { - Identifier(name) => match scope.introduce((*name).into(), region) { + Identifier(name) => match scope.introduce_str(name, region) { Ok(symbol) => { output.references.insert_bound(symbol); diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index 4db2f54246..b51af4821c 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -53,7 +53,7 @@ impl Scope { pub fn lookup(&self, ident: &Ident, region: Region) -> Result { use ContainsIdent::*; - match self.scope_contains_ident(ident) { + match self.scope_contains_ident(ident.as_str()) { InScope(symbol, _) => Ok(symbol), NotInScope(_) | NotPresent => { let error = RuntimeError::LookupNotInScope( @@ -85,7 +85,8 @@ impl Scope { lookup_region: Region, ) -> Result<(Symbol, &Alias), RuntimeError> { debug_assert!(opaque_ref.starts_with('@')); - let opaque = opaque_ref[1..].into(); + let opaque_str = &opaque_ref[1..]; + let opaque = opaque_str.into(); match self.locals.has_in_scope(&opaque) { Some((symbol, _)) => match self.lookup_opaque_alias(symbol) { @@ -96,7 +97,7 @@ impl Scope { }, None => { // opaque types can only be wrapped/unwrapped in the scope they are defined in (and below) - let error = if let Some((_, decl_region)) = self.has_imported(&opaque) { + let error = if let Some((_, decl_region)) = self.has_imported(opaque_str) { // specific error for when the opaque is imported, which definitely does not work RuntimeError::OpaqueOutsideScope { opaque, @@ -159,9 +160,9 @@ impl Scope { } } - fn has_imported(&self, ident: &Ident) -> Option<(Symbol, Region)> { + fn has_imported(&self, ident: &str) -> Option<(Symbol, Region)> { for (import, shadow, original_region) in self.imports.iter() { - if ident == import { + if ident == import.as_str() { return Some((*shadow, *original_region)); } } @@ -170,7 +171,7 @@ impl Scope { } /// Is an identifier in scope, either in the locals or imports - fn scope_contains_ident(&self, ident: &Ident) -> ContainsIdent { + fn scope_contains_ident(&self, ident: &str) -> ContainsIdent { // exposed imports are likely to be small match self.has_imported(ident) { Some((symbol, region)) => ContainsIdent::InScope(symbol, region), @@ -178,11 +179,7 @@ impl Scope { } } - fn introduce_help( - &mut self, - ident: &Ident, - region: Region, - ) -> Result { + fn introduce_help(&mut self, ident: &str, region: Region) -> Result { match self.scope_contains_ident(ident) { ContainsIdent::InScope(original_symbol, original_region) => { // the ident is already in scope; up to the caller how to handle that @@ -229,10 +226,22 @@ impl Scope { ident: Ident, region: Region, ) -> Result, Symbol)> { - match self.introduce_without_shadow_symbol(&ident, region) { + self.introduce_str(ident.as_str(), region) + } + + pub fn introduce_str( + &mut self, + ident: &str, + region: Region, + ) -> Result, Symbol)> { + match self.introduce_help(ident, region) { Ok(symbol) => Ok(symbol), - Err((original_region, shadow)) => { - let symbol = self.scopeless_symbol(&ident, region); + Err((_, original_region)) => { + let shadow = Loc { + value: Ident::from(ident), + region, + }; + let symbol = self.locals.scopeless_symbol(ident, region); Err((original_region, shadow, symbol)) } @@ -245,7 +254,7 @@ impl Scope { ident: &Ident, region: Region, ) -> Result)> { - match self.introduce_help(ident, region) { + match self.introduce_help(ident.as_str(), region) { Err((_, original_region)) => { let shadow = Loc { value: ident.clone(), @@ -271,7 +280,7 @@ impl Scope { ) -> Result<(Symbol, Option), (Region, Loc, Symbol)> { let ident = &ident; - match self.introduce_help(ident, region) { + match self.introduce_help(ident.as_str(), region) { Err((original_symbol, original_region)) => { let shadow_symbol = self.scopeless_symbol(ident, region); @@ -300,7 +309,7 @@ impl Scope { /// but also in other places where we need to create a symbol and we don't have the right /// scope information yet. An identifier can be introduced later, and will use the same IdentId pub fn scopeless_symbol(&mut self, ident: &Ident, region: Region) -> Symbol { - self.locals.scopeless_symbol(ident, region) + self.locals.scopeless_symbol(ident.as_str(), region) } /// Import a Symbol from another module into this module's top-level scope. @@ -313,7 +322,7 @@ impl Scope { symbol: Symbol, region: Region, ) -> Result<(), (Symbol, Region)> { - if let Some((s, r)) = self.has_imported(&ident) { + if let Some((s, r)) = self.has_imported(ident.as_str()) { return Err((s, r)); } @@ -463,13 +472,13 @@ impl ScopedIdentIds { } fn has_in_scope(&self, ident: &Ident) -> Option<(Symbol, Region)> { - match self.contains_ident(ident) { + match self.contains_ident(ident.as_str()) { ContainsIdent::InScope(symbol, region) => Some((symbol, region)), ContainsIdent::NotInScope(_) | ContainsIdent::NotPresent => None, } } - fn contains_ident(&self, ident: &Ident) -> ContainsIdent { + fn contains_ident(&self, ident: &str) -> ContainsIdent { use ContainsIdent::*; let mut result = NotPresent; @@ -499,8 +508,8 @@ impl ScopedIdentIds { }) } - fn introduce_into_scope(&mut self, ident_name: &Ident, region: Region) -> IdentId { - let id = self.ident_ids.add_ident(ident_name); + fn introduce_into_scope(&mut self, ident_name: &str, region: Region) -> IdentId { + let id = self.ident_ids.add_str(ident_name); debug_assert_eq!(id.index(), self.in_scope.len()); debug_assert_eq!(id.index(), self.regions.len()); @@ -524,8 +533,8 @@ impl ScopedIdentIds { } /// Adds an IdentId, but does not introduce it to the scope - fn scopeless_symbol(&mut self, ident_name: &Ident, region: Region) -> Symbol { - let id = self.ident_ids.add_ident(ident_name); + fn scopeless_symbol(&mut self, ident_name: &str, region: Region) -> Symbol { + let id = self.ident_ids.add_str(ident_name); debug_assert_eq!(id.index(), self.in_scope.len()); debug_assert_eq!(id.index(), self.regions.len()); diff --git a/compiler/collections/src/small_string_interner.rs b/compiler/collections/src/small_string_interner.rs index 6b91136c13..37f396ad96 100644 --- a/compiler/collections/src/small_string_interner.rs +++ b/compiler/collections/src/small_string_interner.rs @@ -25,7 +25,7 @@ impl Length { #[inline(always)] const fn kind(self) -> Kind { if self.0 == 0 { - Kind::Emtpy + Kind::Empty } else if self.0 > 0 { Kind::Interned(self.0 as usize) } else { @@ -41,7 +41,7 @@ impl Length { enum Kind { Generated(usize), - Emtpy, + Empty, Interned(usize), } @@ -49,7 +49,7 @@ impl Debug for Kind { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Self::Generated(arg0) => write!(f, "Generated({})", arg0), - Self::Emtpy => write!(f, "Emtpy"), + Self::Empty => write!(f, "Emtpy"), Self::Interned(arg0) => write!(f, "Interned({})", arg0), } } @@ -174,7 +174,7 @@ impl SmallStringInterner { .enumerate() .filter_map(move |(index, length)| match length.kind() { Kind::Generated(_) => None, - Kind::Emtpy => { + Kind::Empty => { if target_length == 0 { Some(index) } else { @@ -198,7 +198,7 @@ impl SmallStringInterner { fn get(&self, index: usize) -> &str { match self.lengths[index].kind() { - Kind::Emtpy => "", + Kind::Empty => "", Kind::Generated(length) | Kind::Interned(length) => { let offset = self.offsets[index] as usize; diff --git a/compiler/gen_wasm/src/backend.rs b/compiler/gen_wasm/src/backend.rs index 3654696cc6..2d38016a1c 100644 --- a/compiler/gen_wasm/src/backend.rs +++ b/compiler/gen_wasm/src/backend.rs @@ -4,7 +4,6 @@ use std::fmt::Write; use code_builder::Align; use roc_builtins::bitcode::{FloatWidth, IntWidth}; use roc_collections::all::MutMap; -use roc_module::ident::Ident; use roc_module::low_level::{LowLevel, LowLevelWrapperType}; use roc_module::symbol::{Interns, Symbol}; use roc_mono::code_gen_help::{CodeGenHelp, HelperOp, REFCOUNT_MAX}; @@ -183,7 +182,7 @@ impl<'a> WasmBackend<'a> { .get_mut(&self.env.module_id) .unwrap(); - let ident_id = ident_ids.add_ident(&Ident::from(debug_name)); + let ident_id = ident_ids.add_str(debug_name); Symbol::new(self.env.module_id, ident_id) } diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index 11edbb4913..b28ed53e2a 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -1106,7 +1106,7 @@ pub fn load<'a>( ) -> Result, LoadingProblem<'a>> { // When compiling to wasm, we cannot spawn extra threads // so we have a single-threaded implementation - if cfg!(target_family = "wasm") { + if true || cfg!(target_family = "wasm") { load_single_threaded( arena, load_start, diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index 7b09d04532..0619e3c3d6 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -543,7 +543,11 @@ impl IdentIds { } pub fn add_ident(&mut self, ident_name: &Ident) -> IdentId { - IdentId(self.interner.insert(ident_name.as_str()) as u32) + self.add_str(ident_name.as_str()) + } + + pub fn add_str(&mut self, ident_name: &str) -> IdentId { + IdentId(self.interner.insert(ident_name) as u32) } pub fn duplicate_ident(&mut self, ident_id: IdentId) -> IdentId { @@ -553,7 +557,7 @@ impl IdentIds { pub fn get_or_insert(&mut self, name: &Ident) -> IdentId { match self.get_id(name) { Some(id) => id, - None => self.add_ident(name), + None => self.add_str(name.as_str()), } } @@ -585,9 +589,9 @@ impl IdentIds { } #[inline(always)] - pub fn get_id_many<'a>(&'a self, ident_name: &'a Ident) -> impl Iterator + 'a { + pub fn get_id_many<'a>(&'a self, ident_name: &'a str) -> impl Iterator + 'a { self.interner - .find_indices(ident_name.as_str()) + .find_indices(ident_name) .map(|i| IdentId(i as u32)) } diff --git a/compiler/mono/src/code_gen_help/mod.rs b/compiler/mono/src/code_gen_help/mod.rs index 68361fd267..7c5cb3eecc 100644 --- a/compiler/mono/src/code_gen_help/mod.rs +++ b/compiler/mono/src/code_gen_help/mod.rs @@ -1,6 +1,5 @@ use bumpalo::collections::vec::Vec; use bumpalo::Bump; -use roc_module::ident::Ident; use roc_module::low_level::LowLevel; use roc_module::symbol::{IdentIds, ModuleId, Symbol}; use roc_target::TargetInfo; @@ -396,7 +395,7 @@ impl<'a> CodeGenHelp<'a> { } fn create_symbol(&self, ident_ids: &mut IdentIds, debug_name: &str) -> Symbol { - let ident_id = ident_ids.add_ident(&Ident::from(debug_name)); + let ident_id = ident_ids.add_str(debug_name); Symbol::new(self.home, ident_id) } diff --git a/editor/src/editor/mvc/let_update.rs b/editor/src/editor/mvc/let_update.rs index b9a734b8f4..482b5d4c9a 100644 --- a/editor/src/editor/mvc/let_update.rs +++ b/editor/src/editor/mvc/let_update.rs @@ -1,7 +1,6 @@ use roc_ast::lang::core::expr::expr2::Expr2; use roc_ast::lang::core::pattern::Pattern2; use roc_ast::lang::core::val_def::ValueDef; -use roc_module::ident::Ident; use roc_module::symbol::Symbol; use crate::editor::ed_error::EdResult; @@ -26,8 +25,7 @@ pub fn start_new_let_value(ed_model: &mut EdModel, new_char: &char) -> EdResult< let val_expr2_node = Expr2::Blank; let val_expr_id = ed_model.module.env.pool.add(val_expr2_node); - let ident = Ident::from(val_name_string); - let ident_id = ed_model.module.env.ident_ids.add_ident(&ident); + let ident_id = ed_model.module.env.ident_ids.add_str(&val_name_string); let var_symbol = Symbol::new(ed_model.module.env.home, ident_id); let body = Expr2::Var(var_symbol); let body_id = ed_model.module.env.pool.add(body); diff --git a/editor/src/editor/mvc/tld_value_update.rs b/editor/src/editor/mvc/tld_value_update.rs index 3afaafdcf8..72323b25c2 100644 --- a/editor/src/editor/mvc/tld_value_update.rs +++ b/editor/src/editor/mvc/tld_value_update.rs @@ -1,6 +1,5 @@ use roc_ast::lang::core::{def::def2::Def2, expr::expr2::Expr2}; use roc_code_markup::slow_pool::MarkNodeId; -use roc_module::ident::Ident; use crate::{ editor::ed_error::{EdResult, FailedToUpdateIdentIdName, KeyNotFound}, @@ -27,8 +26,8 @@ pub fn start_new_tld_value(ed_model: &mut EdModel, new_char: &char) -> EdResult< let val_expr_node = Expr2::Blank; let val_expr_id = ed_model.module.env.pool.add(val_expr_node); - let ident = Ident::from(new_char.to_string().as_str()); - let ident_id = ed_model.module.env.ident_ids.add_ident(&ident); + let ident_str = new_char.to_string(); + let ident_id = ed_model.module.env.ident_ids.add_str(&ident_str); let module_ident_ids_opt = ed_model .loaded_module @@ -38,7 +37,7 @@ pub fn start_new_tld_value(ed_model: &mut EdModel, new_char: &char) -> EdResult< if let Some(module_ident_ids_ref) = module_ident_ids_opt { // this might create different IdentId for interns and env.ident_ids which may be a problem - module_ident_ids_ref.add_ident(&ident); + module_ident_ids_ref.add_str(&ident_str); } else { KeyNotFound { key_str: format!("{:?}", ed_model.module.env.home), diff --git a/examples/hello-world/helloWorld.roc b/examples/hello-world/helloWorld.roc index 2381655195..40f354147d 100644 --- a/examples/hello-world/helloWorld.roc +++ b/examples/hello-world/helloWorld.roc @@ -8,15 +8,4 @@ app "helloWorld" imports [] provides [ main ] to pf -a = - foobar = "Hello" - - foobar - -b = - foobar = "World" - - foobar - -# main = "Hello, World!\n" -main = Str.concat a b +main = "Hello, World!\n" From 66d29e8611079583ab8c171ecc893c7c211860a0 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 30 Apr 2022 21:00:48 +0200 Subject: [PATCH 717/846] fix typo --- compiler/collections/src/small_string_interner.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/collections/src/small_string_interner.rs b/compiler/collections/src/small_string_interner.rs index 37f396ad96..89cc93067e 100644 --- a/compiler/collections/src/small_string_interner.rs +++ b/compiler/collections/src/small_string_interner.rs @@ -49,7 +49,7 @@ impl Debug for Kind { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Self::Generated(arg0) => write!(f, "Generated({})", arg0), - Self::Empty => write!(f, "Emtpy"), + Self::Empty => write!(f, "Empty"), Self::Interned(arg0) => write!(f, "Interned({})", arg0), } } From a5ec269a4dc89192d315806966e09aea97149b7f Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 30 Apr 2022 21:06:34 +0200 Subject: [PATCH 718/846] clippy --- compiler/load_internal/src/file.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index b28ed53e2a..11edbb4913 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -1106,7 +1106,7 @@ pub fn load<'a>( ) -> Result, LoadingProblem<'a>> { // When compiling to wasm, we cannot spawn extra threads // so we have a single-threaded implementation - if true || cfg!(target_family = "wasm") { + if cfg!(target_family = "wasm") { load_single_threaded( arena, load_start, From d3f00c8c6d7c88a817b1bae90436cafad41f4d91 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 30 Apr 2022 21:21:14 +0200 Subject: [PATCH 719/846] use vec![] --- compiler/can/src/scope.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index b51af4821c..e8d4576f69 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -454,7 +454,7 @@ impl ScopedIdentIds { Self { in_scope: BitVec::repeat(false, capacity), ident_ids, - regions: std::iter::repeat(Region::zero()).take(capacity).collect(), + regions: vec![Region::zero(); capacity], home, } } From be6006bbab35aa07c1c7be95cb5e4ea2f3ef6966 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 30 Apr 2022 21:22:47 +0200 Subject: [PATCH 720/846] refactor --- compiler/can/src/scope.rs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index e8d4576f69..860cf04904 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -363,12 +363,16 @@ impl Scope { // - exposed_ident_count: unchanged // - home: unchanged let aliases_count = self.aliases.len(); - let locals_snapshot = self.locals.snapshot(); + let locals_snapshot = self.locals.in_scope.len(); let result = f(self); self.aliases.truncate(aliases_count); - self.locals.revert(locals_snapshot); + + // anything added in the inner scope is no longer in scope now + for i in locals_snapshot..self.locals.in_scope.len() { + self.locals.in_scope.set(i, false); + } result } @@ -459,18 +463,6 @@ impl ScopedIdentIds { } } - fn snapshot(&self) -> usize { - debug_assert_eq!(self.ident_ids.len(), self.in_scope.len()); - - self.ident_ids.len() - } - - fn revert(&mut self, snapshot: usize) { - for i in snapshot..self.in_scope.len() { - self.in_scope.set(i, false); - } - } - fn has_in_scope(&self, ident: &Ident) -> Option<(Symbol, Region)> { match self.contains_ident(ident.as_str()) { ContainsIdent::InScope(symbol, region) => Some((symbol, region)), From 10c2c5e8fdbf2690de2e6575f0d1bc896342607a Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 1 May 2022 14:29:02 +0200 Subject: [PATCH 721/846] make construct_closure_data more polymorphic --- compiler/mono/src/ir.rs | 52 ++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 1b0875c14a..e09117f7a6 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -4162,7 +4162,7 @@ pub fn with_hole<'a>( layout_cache, lambda_set, name, - symbols, + symbols.iter().copied(), assigned, hole, ) @@ -4734,17 +4734,25 @@ fn get_specialization<'a>( } #[allow(clippy::too_many_arguments)] -fn construct_closure_data<'a>( +fn construct_closure_data<'a, I>( env: &mut Env<'a, '_>, procs: &mut Procs<'a>, layout_cache: &mut LayoutCache<'a>, lambda_set: LambdaSet<'a>, name: Symbol, - symbols: &'a [&(Symbol, Variable)], + symbols: I, assigned: Symbol, hole: &'a Stmt<'a>, -) -> Stmt<'a> { +) -> Stmt<'a> +where + I: IntoIterator, + I::IntoIter: ExactSizeIterator, +{ let lambda_set_layout = Layout::LambdaSet(lambda_set); + let symbols = symbols.into_iter(); + + // arguments with a polymorphic type that we have to deal with + let mut polymorphic_arguments = Vec::new_in(env.arena); let mut result = match lambda_set.layout_for_member(name) { ClosureRepresentation::Union { @@ -4755,10 +4763,14 @@ fn construct_closure_data<'a>( } => { // captured variables are in symbol-alphabetic order, but now we want // them ordered by their alignment requirements - let mut combined = Vec::from_iter_in( - symbols.iter().map(|&&(s, _)| s).zip(field_layouts.iter()), - env.arena, - ); + let mut combined = Vec::with_capacity_in(symbols.len(), env.arena); + for ((symbol, variable), layout) in symbols.zip(field_layouts.iter()) { + if procs.partial_exprs.contains(*symbol) { + polymorphic_arguments.push((*symbol, *variable)); + } + + combined.push((*symbol, layout)) + } let ptr_bytes = env.target_info; @@ -4786,10 +4798,14 @@ fn construct_closure_data<'a>( // captured variables are in symbol-alphabetic order, but now we want // them ordered by their alignment requirements - let mut combined = Vec::from_iter_in( - symbols.iter().map(|&(s, _)| s).zip(field_layouts.iter()), - env.arena, - ); + let mut combined = Vec::with_capacity_in(symbols.len(), env.arena); + for ((symbol, variable), layout) in symbols.zip(field_layouts.iter()) { + if procs.partial_exprs.contains(*symbol) { + polymorphic_arguments.push((*symbol, *variable)); + } + + combined.push((*symbol, layout)) + } let ptr_bytes = env.target_info; @@ -4801,7 +4817,7 @@ fn construct_closure_data<'a>( }); let symbols = - Vec::from_iter_in(combined.iter().map(|(a, _)| **a), env.arena).into_bump_slice(); + Vec::from_iter_in(combined.iter().map(|(a, _)| *a), env.arena).into_bump_slice(); let field_layouts = Vec::from_iter_in(combined.iter().map(|(_, b)| **b), env.arena).into_bump_slice(); @@ -4842,10 +4858,8 @@ fn construct_closure_data<'a>( // TODO: this is not quite right. What we should actually be doing is removing references to // polymorphic expressions from the captured symbols, and allowing the specializations of those // symbols to be inlined when specializing the closure body elsewhere. - for &&(symbol, var) in symbols { - if procs.partial_exprs.contains(symbol) { - result = specialize_symbol(env, procs, layout_cache, Some(var), symbol, result, symbol); - } + for (symbol, var) in polymorphic_arguments { + result = specialize_symbol(env, procs, layout_cache, Some(var), symbol, result, symbol); } result @@ -6937,7 +6951,7 @@ fn specialize_symbol<'a>( layout_cache, lambda_set, original, - symbols, + symbols.iter().copied(), closure_data, env.arena.alloc(result), ) @@ -7696,7 +7710,7 @@ fn call_specialized_proc<'a>( layout_cache, lambda_set, proc_name, - symbols, + symbols.iter().copied(), closure_data_symbol, env.arena.alloc(new_hole), ); From a35619ec80d5bafe81bce812394f6182d52f2fb8 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 1 May 2022 14:29:52 +0200 Subject: [PATCH 722/846] add Symbol::contains helper for debugging --- compiler/module/src/symbol.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index 462d44a8e4..01a8cd703e 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -111,6 +111,11 @@ impl Symbol { pub const fn to_ne_bytes(self) -> [u8; 8] { self.0.to_ne_bytes() } + + #[cfg(debug_assertions)] + pub fn contains(self, needle: &str) -> bool { + format!("{:?}", self).contains(needle) + } } /// Rather than displaying as this: From 5c9f8f5037ac1aa537cbf85d93e7c9bd1dac2c01 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 1 May 2022 14:42:16 +0200 Subject: [PATCH 723/846] fix a bug where a closure is called immediately --- compiler/mono/src/ir.rs | 39 ++++++++++++++++++- compiler/test_gen/src/gen_primitives.rs | 52 +++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 2 deletions(-) diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index e09117f7a6..50341c8003 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -7411,13 +7411,20 @@ fn call_by_name_help<'a>( proc_name, ); + let has_closure = argument_layouts.len() != top_level_layout.arguments.len(); + let closure_argument = env.unique_symbol(); + + if has_closure { + field_symbols.push(closure_argument); + } + let field_symbols = field_symbols.into_bump_slice(); let call = self::Call { call_type: CallType::ByName { name: proc_name, ret_layout, - arg_layouts: argument_layouts, + arg_layouts: top_level_layout.arguments, specialization_id: env.next_call_specialization_id(), }, arguments: field_symbols, @@ -7425,8 +7432,36 @@ fn call_by_name_help<'a>( let result = build_call(env, call, assigned, *ret_layout, hole); + let field_symbols = if has_closure { + &field_symbols[..field_symbols.len() - 1] + } else { + field_symbols + }; + let iter = loc_args.into_iter().rev().zip(field_symbols.iter().rev()); - assign_to_symbols(env, procs, layout_cache, iter, result) + let x = assign_to_symbols(env, procs, layout_cache, iter, result); + + if has_closure { + let partial_proc = procs.partial_procs.get_symbol(proc_name).unwrap(); + + let captured = match partial_proc.captured_symbols { + CapturedSymbols::None => &[], + CapturedSymbols::Captured(slice) => slice, + }; + + construct_closure_data( + env, + procs, + layout_cache, + lambda_set, + proc_name, + captured.iter(), + closure_argument, + env.arena.alloc(x), + ) + } else { + x + } } PendingSpecializations::Making => { let opt_partial_proc = procs.partial_procs.symbol_to_id(proc_name); diff --git a/compiler/test_gen/src/gen_primitives.rs b/compiler/test_gen/src/gen_primitives.rs index 593096087b..8e7e86eca1 100644 --- a/compiler/test_gen/src/gen_primitives.rs +++ b/compiler/test_gen/src/gen_primitives.rs @@ -3344,3 +3344,55 @@ fn box_and_unbox_tag_union() { (u8, u8) ) } + +#[test] +#[cfg(any(feature = "gen-llvm"))] +fn closure_called_in_its_defining_scope() { + assert_evals_to!( + indoc!( + r#" + app "test" provides [ main ] to "./platform" + + main : Str + main = + g : Str + g = "hello world" + + getG : {} -> Str + getG = \{} -> g + + getG {} + "# + ), + RocStr::from("hello world"), + RocStr + ) +} + +#[test] +#[ignore] +#[cfg(any(feature = "gen-llvm"))] +fn issue_2894() { + assert_evals_to!( + indoc!( + r#" + app "test" provides [ main ] to "./platform" + + main : U32 + main = + g : { x : U32 } + g = { x: 1u32 } + + getG : {} -> { x : U32 } + getG = \{} -> g + + h : {} -> U32 + h = \{} -> (getG {}).x + + h {} + "# + ), + 1u32, + u32 + ) +} From 37ba70472fb70293f07f377b8995aec97c9c308b Mon Sep 17 00:00:00 2001 From: ayazhafiz Date: Sun, 1 May 2022 12:25:03 -0400 Subject: [PATCH 724/846] Add more debug flags --- Cargo.lock | 2 ++ compiler/alias_analysis/Cargo.toml | 2 +- compiler/alias_analysis/src/lib.rs | 18 +++++++++++++----- compiler/debug_flags/src/lib.rs | 25 ++++++++++++++++++------- compiler/gen_llvm/Cargo.toml | 1 + compiler/gen_llvm/src/llvm/build.rs | 17 +++++++++-------- compiler/load_internal/src/file.rs | 7 ++----- compiler/mono/src/ir.rs | 13 +++++++++++-- 8 files changed, 57 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 72da692c47..00722d3728 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3366,6 +3366,7 @@ version = "0.1.0" dependencies = [ "morphic_lib", "roc_collections", + "roc_debug_flags", "roc_module", "roc_mono", ] @@ -3683,6 +3684,7 @@ dependencies = [ "roc_alias_analysis", "roc_builtins", "roc_collections", + "roc_debug_flags", "roc_error_macros", "roc_module", "roc_mono", diff --git a/compiler/alias_analysis/Cargo.toml b/compiler/alias_analysis/Cargo.toml index 34cfb7666a..8777595cbf 100644 --- a/compiler/alias_analysis/Cargo.toml +++ b/compiler/alias_analysis/Cargo.toml @@ -10,4 +10,4 @@ morphic_lib = {path = "../../vendor/morphic_lib"} roc_collections = {path = "../collections"} roc_module = {path = "../module"} roc_mono = {path = "../mono"} - +roc_debug_flags = {path = "../debug_flags"} diff --git a/compiler/alias_analysis/src/lib.rs b/compiler/alias_analysis/src/lib.rs index 572a438847..590a4b6099 100644 --- a/compiler/alias_analysis/src/lib.rs +++ b/compiler/alias_analysis/src/lib.rs @@ -26,8 +26,16 @@ pub fn func_name_bytes(proc: &Proc) -> [u8; SIZE] { func_name_bytes_help(proc.name, proc.args.iter().map(|x| x.0), &proc.ret_layout) } -const DEBUG: bool = false; -const SIZE: usize = if DEBUG { 50 } else { 16 }; +#[inline(always)] +fn debug() -> bool { + use roc_debug_flags::{dbg_do, ROC_DEBUG_ALIAS_ANALYSIS}; + dbg_do!(ROC_DEBUG_ALIAS_ANALYSIS, { + return true; + }); + false +} + +const SIZE: usize = 16; #[derive(Debug, Clone, Copy, Hash)] struct TagUnionId(u64); @@ -87,7 +95,7 @@ where *target = *source; } - if DEBUG { + if debug() { for (i, c) in (format!("{:?}", symbol)).chars().take(25).enumerate() { name_bytes[25 + i] = c as u8; } @@ -175,7 +183,7 @@ where } } - if DEBUG { + if debug() { eprintln!( "{:?}: {:?} with {:?} args", proc.name, @@ -239,7 +247,7 @@ where p.build()? }; - if DEBUG { + if debug() { eprintln!("{}", program.to_source_string()); } diff --git a/compiler/debug_flags/src/lib.rs b/compiler/debug_flags/src/lib.rs index 801ab53533..b9d66a42b1 100644 --- a/compiler/debug_flags/src/lib.rs +++ b/compiler/debug_flags/src/lib.rs @@ -34,7 +34,7 @@ macro_rules! dbg_do { ($flag:path, $expr:expr) => { #[cfg(debug_assertions)] { - if std::env::var($flag).unwrap_or("0".to_string()) != "0" { + if std::env::var($flag).as_ref() == Ok(&"0".to_string()) { $expr } } @@ -64,16 +64,27 @@ flags! { // ===Mono=== - /// Writes the mono IR to stderr after function specialization + /// Writes a pretty-printed mono IR to stderr after function specialization. ROC_PRINT_IR_AFTER_SPECIALIZATION - /// Writes the mono IR to stderr after insertion of reset/reuse instructions + /// Writes a pretty-printed mono IR to stderr after insertion of reset/reuse + /// instructions. ROC_PRINT_IR_AFTER_RESET_REUSE - /// Writes the mono IR to stderr after insertion of refcount instructions + /// Writes a pretty-printed mono IR to stderr after insertion of refcount + /// instructions. ROC_PRINT_IR_AFTER_REFCOUNT - /// Instructs the mono IR pretty printer to dump pretty symbols and verbose - /// layout information - ROC_PRETTY_PRINT_IR_SYMBOLS + /// Prints debug information during the alias analysis pass. + ROC_DEBUG_ALIAS_ANALYSIS + + // ===LLVM Gen=== + + /// Prints LLVM function verification output. + ROC_PRINT_LLVM_FN_VERIFICATION + + // ===Load=== + + /// Print load phases as they complete. + ROC_PRINT_LOAD_LOG } diff --git a/compiler/gen_llvm/Cargo.toml b/compiler/gen_llvm/Cargo.toml index 3a1ebe8a57..5d020a5507 100644 --- a/compiler/gen_llvm/Cargo.toml +++ b/compiler/gen_llvm/Cargo.toml @@ -15,6 +15,7 @@ roc_error_macros = { path = "../../error_macros" } roc_mono = { path = "../mono" } roc_target = { path = "../roc_target" } roc_std = { path = "../../roc_std", default-features = false } +roc_debug_flags = { path = "../debug_flags" } morphic_lib = { path = "../../vendor/morphic_lib" } bumpalo = { version = "3.8.0", features = ["collections"] } inkwell = { path = "../../vendor/inkwell" } diff --git a/compiler/gen_llvm/src/llvm/build.rs b/compiler/gen_llvm/src/llvm/build.rs index 6cffc4cb37..977bb228ba 100644 --- a/compiler/gen_llvm/src/llvm/build.rs +++ b/compiler/gen_llvm/src/llvm/build.rs @@ -56,6 +56,7 @@ use morphic_lib::{ use roc_builtins::bitcode::{self, FloatWidth, IntWidth, IntrinsicName}; use roc_builtins::{float_intrinsic, llvm_int_intrinsic}; use roc_collections::all::{ImMap, MutMap, MutSet}; +use roc_debug_flags::{dbg_do, ROC_PRINT_LLVM_FN_VERIFICATION}; use roc_error_macros::internal_error; use roc_module::low_level::LowLevel; use roc_module::symbol::{Interns, ModuleId, Symbol}; @@ -67,13 +68,13 @@ use roc_mono::layout::{Builtin, LambdaSet, Layout, LayoutIds, TagIdIntType, Unio use roc_target::{PtrWidth, TargetInfo}; use target_lexicon::{Architecture, OperatingSystem, Triple}; -/// This is for Inkwell's FunctionValue::verify - we want to know the verification -/// output in debug builds, but we don't want it to print to stdout in release builds! -#[cfg(debug_assertions)] -const PRINT_FN_VERIFICATION_OUTPUT: bool = true; - -#[cfg(not(debug_assertions))] -const PRINT_FN_VERIFICATION_OUTPUT: bool = false; +#[inline(always)] +fn print_fn_verification_output() -> bool { + dbg_do!(ROC_PRINT_LLVM_FN_VERIFICATION, { + return true; + }); + false +} #[macro_export] macro_rules! debug_info_init { @@ -4513,7 +4514,7 @@ pub fn build_proc<'a, 'ctx, 'env>( } pub fn verify_fn(fn_val: FunctionValue<'_>) { - if !fn_val.verify(PRINT_FN_VERIFICATION_OUTPUT) { + if !fn_val.verify(print_fn_verification_output()) { unsafe { fn_val.delete(); } diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index 27884c80fe..b2a8af97aa 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -17,7 +17,7 @@ use roc_constrain::module::{ }; use roc_debug_flags::{ dbg_do, ROC_PRINT_IR_AFTER_REFCOUNT, ROC_PRINT_IR_AFTER_RESET_REUSE, - ROC_PRINT_IR_AFTER_SPECIALIZATION, + ROC_PRINT_IR_AFTER_SPECIALIZATION, ROC_PRINT_LOAD_LOG, }; use roc_error_macros::internal_error; use roc_module::ident::{Ident, ModuleName, QualifiedModuleName}; @@ -74,13 +74,10 @@ const PKG_CONFIG_FILE_NAME: &str = "Package-Config"; /// The . in between module names like Foo.Bar.Baz const MODULE_SEPARATOR: char = '.'; -const SHOW_MESSAGE_LOG: bool = false; - const EXPANDED_STACK_SIZE: usize = 8 * 1024 * 1024; macro_rules! log { - () => (if SHOW_MESSAGE_LOG { println!()} else {}); - ($($arg:tt)*) => (if SHOW_MESSAGE_LOG { println!($($arg)*); } else {}) + ($($arg:tt)*) => (dbg_do!(ROC_PRINT_LOAD_LOG, println!($($arg)*))) } /// Struct storing various intermediate stages by their ModuleId diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 790eaef5ce..4bd609b72e 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -10,7 +10,10 @@ use roc_builtins::bitcode::{FloatWidth, IntWidth}; use roc_can::abilities::AbilitiesStore; use roc_can::expr::{AnnotatedMark, ClosureData, IntValue}; use roc_collections::all::{default_hasher, BumpMap, BumpMapDefault, MutMap}; -use roc_debug_flags::{dbg_do, ROC_PRETTY_PRINT_IR_SYMBOLS}; +use roc_debug_flags::{ + dbg_do, ROC_PRINT_IR_AFTER_REFCOUNT, ROC_PRINT_IR_AFTER_RESET_REUSE, + ROC_PRINT_IR_AFTER_SPECIALIZATION, +}; use roc_exhaustive::{Ctor, CtorName, Guard, RenderAs, TagId}; use roc_module::ident::{ForeignSymbol, Lowercase, TagName}; use roc_module::low_level::LowLevel; @@ -28,7 +31,13 @@ use ven_pretty::{BoxAllocator, DocAllocator, DocBuilder}; #[inline(always)] pub fn pretty_print_ir_symbols() -> bool { - dbg_do!(ROC_PRETTY_PRINT_IR_SYMBOLS, { + dbg_do!(ROC_PRINT_IR_AFTER_SPECIALIZATION, { + return true; + }); + dbg_do!(ROC_PRINT_IR_AFTER_RESET_REUSE, { + return true; + }); + dbg_do!(ROC_PRINT_IR_AFTER_REFCOUNT, { return true; }); false From 4707528caa894ddea7026a9e99534c72f898f27c Mon Sep 17 00:00:00 2001 From: Sean Hagstrom Date: Sun, 1 May 2022 18:28:49 +0100 Subject: [PATCH 725/846] feature(formatter): allow single blank line around comments in lists, records, type annotations --- compiler/fmt/src/collection.rs | 24 +- compiler/fmt/src/expr.rs | 29 +- compiler/fmt/src/spaces.rs | 25 ++ compiler/fmt/tests/test_fmt.rs | 709 +++++++++++++++++++++++++++++++++ 4 files changed, 781 insertions(+), 6 deletions(-) diff --git a/compiler/fmt/src/collection.rs b/compiler/fmt/src/collection.rs index 9e54b327cf..836ad04210 100644 --- a/compiler/fmt/src/collection.rs +++ b/compiler/fmt/src/collection.rs @@ -2,7 +2,7 @@ use roc_parse::ast::{Collection, ExtractSpaces}; use crate::{ annotation::{Formattable, Newlines}, - spaces::{fmt_comments_only, NewlineAt, INDENT}, + spaces::{count_leading_newlines, fmt_comments_only, NewlineAt, INDENT}, Buf, }; @@ -25,12 +25,27 @@ pub fn fmt_collection<'a, 'buf, T: ExtractSpaces<'a> + Formattable>( buf.indent(braces_indent); buf.push(start); - for item in items.iter() { + for (index, item) in items.iter().enumerate() { let item = item.extract_spaces(); + let is_first_item = index == 0; buf.newline(); + if !item.before.is_empty() { + let is_only_newlines = item.before.iter().all(|s| s.is_newline()); + + if !is_first_item + && !is_only_newlines + && count_leading_newlines(item.before.iter()) > 1 + { + buf.newline(); + } + fmt_comments_only(buf, item.before.iter(), NewlineAt::Bottom, item_indent); + + if !is_only_newlines && count_leading_newlines(item.before.iter().rev()) > 0 { + buf.newline(); + } } item.item.format(buf, item_indent); @@ -41,6 +56,11 @@ pub fn fmt_collection<'a, 'buf, T: ExtractSpaces<'a> + Formattable>( fmt_comments_only(buf, item.after.iter(), NewlineAt::Top, item_indent); } } + + if count_leading_newlines(items.final_comments().iter()) > 1 { + buf.newline(); + } + fmt_comments_only( buf, items.final_comments().iter(), diff --git a/compiler/fmt/src/expr.rs b/compiler/fmt/src/expr.rs index fecb7fee37..7e038bc148 100644 --- a/compiler/fmt/src/expr.rs +++ b/compiler/fmt/src/expr.rs @@ -2,7 +2,7 @@ use crate::annotation::{Formattable, Newlines, Parens}; use crate::collection::fmt_collection; use crate::def::fmt_def; use crate::pattern::fmt_pattern; -use crate::spaces::{fmt_comments_only, fmt_spaces, NewlineAt, INDENT}; +use crate::spaces::{count_leading_newlines, fmt_comments_only, fmt_spaces, NewlineAt, INDENT}; use crate::Buf; use roc_module::called_via::{self, BinOp}; use roc_parse::ast::{ @@ -1105,16 +1105,38 @@ fn fmt_record<'a, 'buf>( if is_multiline { let field_indent = indent + INDENT; - for field in loc_fields.iter() { + for (index, field) in loc_fields.iter().enumerate() { // comma addition is handled by the `format_field_multiline` function // since we can have stuff like: // { x # comment // , y // } // In this case, we have to move the comma before the comment. + + let is_first_item = index == 0; + if let AssignedField::SpaceBefore(_sub_field, spaces) = &field.value { + let is_only_newlines = spaces.iter().all(|s| s.is_newline()); + if !is_first_item + && !is_only_newlines + && count_leading_newlines(spaces.iter()) > 1 + { + buf.newline(); + } + + fmt_comments_only(buf, spaces.iter(), NewlineAt::Top, field_indent); + + if !is_only_newlines && count_leading_newlines(spaces.iter().rev()) > 0 { + buf.newline(); + } + } + format_field_multiline(buf, &field.value, field_indent, ""); } + if count_leading_newlines(final_comments.iter()) > 1 { + buf.newline(); + } + fmt_comments_only(buf, final_comments.iter(), NewlineAt::Top, field_indent); buf.newline(); @@ -1189,7 +1211,7 @@ fn format_field_multiline<'a, 'buf, T>( buf.push_str(name.value); buf.push(','); } - AssignedField::SpaceBefore(sub_field, spaces) => { + AssignedField::SpaceBefore(sub_field, _spaces) => { // We have something like that: // ``` // # comment @@ -1197,7 +1219,6 @@ fn format_field_multiline<'a, 'buf, T>( // ``` // we'd like to preserve this - fmt_comments_only(buf, spaces.iter(), NewlineAt::Top, indent); format_field_multiline(buf, sub_field, indent, separator_prefix); } AssignedField::SpaceAfter(sub_field, spaces) => { diff --git a/compiler/fmt/src/spaces.rs b/compiler/fmt/src/spaces.rs index 4cb4f6fb8a..5ce9a64121 100644 --- a/compiler/fmt/src/spaces.rs +++ b/compiler/fmt/src/spaces.rs @@ -117,6 +117,31 @@ fn fmt_comment<'buf>(buf: &mut Buf<'buf>, comment: &str) { buf.push_str(comment.trim_end()); } +pub fn count_leading_newlines<'a, I>(data: I) -> u16 +where + I: Iterator>, +{ + let mut count = 0; + let mut allow_counting = false; + + for (index, val) in data.enumerate() { + let is_first = index == 0; + let is_newline = matches!(val, CommentOrNewline::Newline); + + if is_first && is_newline { + allow_counting = true + } + + if is_newline && allow_counting { + count += 1; + } else { + break; + } + } + + count +} + fn fmt_docs<'buf>(buf: &mut Buf<'buf>, docs: &str) { buf.push_str("##"); if !docs.starts_with(' ') { diff --git a/compiler/fmt/tests/test_fmt.rs b/compiler/fmt/tests/test_fmt.rs index 51a87c5797..3aae1b480e 100644 --- a/compiler/fmt/tests/test_fmt.rs +++ b/compiler/fmt/tests/test_fmt.rs @@ -192,6 +192,714 @@ mod test_fmt { ); } + #[test] + fn type_annotation_allow_blank_line_before_and_after_comment() { + expr_formats_same(indoc!( + r#" + person : + { + firstName : Str, + # comment + lastName : Str, + } + + person + "# + )); + + expr_formats_same(indoc!( + r#" + person : + { + firstName : Str, + + # comment + lastName : Str, + } + + person + "# + )); + + expr_formats_same(indoc!( + r#" + person : + { + firstName : Str, + # comment + + lastName : Str, + } + + person + "# + )); + + expr_formats_same(indoc!( + r#" + person : + { + firstName : Str, + + # comment + + lastName : Str, + } + + person + "# + )); + + expr_formats_same(indoc!( + r#" + person : + { + firstName : Str, + + # comment 1 + + lastName : Str, + + # comment 2 + # comment 3 + } + + person + "# + )); + + expr_formats_same(indoc!( + r#" + person : + { + firstName : Str, + + # comment 1 + + lastName : Str, + # comment 2 + # comment 3 + } + + person + "# + )); + + expr_formats_to( + indoc!( + r#" + person : + { + + # comment + + firstName : Str, + lastName : Str, + } + + person + "# + ), + indoc!( + r#" + person : + { + # comment + + firstName : Str, + lastName : Str, + } + + person + "# + ), + ); + + expr_formats_to( + indoc!( + r#" + person : + { + firstName : Str, + lastName : Str, + + # comment + + } + + person + "# + ), + indoc!( + r#" + person : + { + firstName : Str, + lastName : Str, + + # comment + } + + person + "# + ), + ); + + expr_formats_to( + indoc!( + r#" + person : + { + firstName : Str, + + + # comment + lastName : Str, + } + + person + "# + ), + indoc!( + r#" + person : + { + firstName : Str, + + # comment + lastName : Str, + } + + person + "# + ), + ); + + expr_formats_to( + indoc!( + r#" + person : + { + firstName : Str, + # comment + + + lastName : Str, + } + + person + "# + ), + indoc!( + r#" + person : + { + firstName : Str, + # comment + + lastName : Str, + } + + person + "# + ), + ); + + expr_formats_to( + indoc!( + r#" + person : + { + firstName : Str, + + + # comment + + + lastName : Str, + } + + person + "# + ), + indoc!( + r#" + person : + { + firstName : Str, + + # comment + + lastName : Str, + } + + person + "# + ), + ); + } + + #[test] + fn record_allow_blank_line_before_and_after_comment() { + expr_formats_same(indoc!( + r#" + person = { + firstName: "first", + # comment 1 + lastName: "last", + } + + person + "# + )); + + expr_formats_same(indoc!( + r#" + person = { + firstName: "first", + # comment 1 + + lastName: "last", + } + + person + "# + )); + + expr_formats_same(indoc!( + r#" + person = { + firstName: "first", + + # comment 1 + lastName: "last", + } + + person + "# + )); + + expr_formats_same(indoc!( + r#" + person = { + firstName: "first", + + # comment 1 + + lastName: "last", + } + + person + "# + )); + + expr_formats_same(indoc!( + r#" + person = { + firstName: "first", + + # comment 1 + + lastName: "last", + + # comment 2 + # comment 3 + } + + person + "# + )); + + expr_formats_same(indoc!( + r#" + person = { + firstName: "first", + + # comment 1 + + lastName: "last", + # comment 2 + # comment 3 + } + + person + "# + )); + + expr_formats_to( + indoc!( + r#" + person = { + + # comment + + firstName: "first", + lastName: "last", + } + + person + "# + ), + indoc!( + r#" + person = { + # comment + + firstName: "first", + lastName: "last", + } + + person + "# + ), + ); + + expr_formats_to( + indoc!( + r#" + person = { + firstName: "first", + lastName: "last", + + # comment + + } + + person + "# + ), + indoc!( + r#" + person = { + firstName: "first", + lastName: "last", + + # comment + } + + person + "# + ), + ); + + expr_formats_to( + indoc!( + r#" + person = { + firstName: "first", + + + # comment 1 + lastName: "last", + } + + person + "# + ), + indoc!( + r#" + person = { + firstName: "first", + + # comment 1 + lastName: "last", + } + + person + "# + ), + ); + + expr_formats_to( + indoc!( + r#" + person = { + firstName: "first", + # comment 1 + + + lastName: "last", + } + + person + "# + ), + indoc!( + r#" + person = { + firstName: "first", + # comment 1 + + lastName: "last", + } + + person + "# + ), + ); + + expr_formats_to( + indoc!( + r#" + person = { + firstName: "first", + + + # comment 1 + + + lastName: "last", + } + + person + "# + ), + indoc!( + r#" + person = { + firstName: "first", + + # comment 1 + + lastName: "last", + } + + person + "# + ), + ); + } + + #[test] + fn list_allow_blank_line_before_and_after_comment() { + expr_formats_same(indoc!( + r#" + list = [ + 0, + # comment + 1, + ] + + list + "# + )); + + expr_formats_same(indoc!( + r#" + list = [ + 0, + + # comment + 1, + ] + + list + "# + )); + + expr_formats_same(indoc!( + r#" + list = [ + 0, + # comment + + 1, + ] + + list + "# + )); + + expr_formats_same(indoc!( + r#" + list = [ + 0, + + # comment + + 1, + ] + + list + "# + )); + + expr_formats_same(indoc!( + r#" + list = [ + 0, + + # comment 1 + + 1, + + # comment 2 + # comment 3 + ] + + list + "# + )); + + expr_formats_same(indoc!( + r#" + list = [ + 0, + + # comment 1 + + 1, + # comment 2 + # comment 3 + ] + + list + "# + )); + expr_formats_to( + indoc!( + r#" + list = [ + + # comment + + 0, + 1, + ] + + list + "# + ), + indoc!( + r#" + list = [ + # comment + + 0, + 1, + ] + + list + "# + ), + ); + + expr_formats_to( + indoc!( + r#" + list = [ + 0, + 1, + + # comment + + ] + + list + "# + ), + indoc!( + r#" + list = [ + 0, + 1, + + # comment + ] + + list + "# + ), + ); + + expr_formats_to( + indoc!( + r#" + list = [ + 0, + + + # comment + 1, + ] + + list + "# + ), + indoc!( + r#" + list = [ + 0, + + # comment + 1, + ] + + list + "# + ), + ); + + expr_formats_to( + indoc!( + r#" + list = [ + 0, + # comment + + + 1, + ] + + list + "# + ), + indoc!( + r#" + list = [ + 0, + # comment + + 1, + ] + + list + "# + ), + ); + + expr_formats_to( + indoc!( + r#" + list = [ + 0, + + + # comment + + + 1, + ] + + list + "# + ), + indoc!( + r#" + list = [ + 0, + + # comment + + 1, + ] + + list + "# + ), + ); + } + #[test] fn force_space_at_beginning_of_comment() { expr_formats_to( @@ -1648,6 +2356,7 @@ mod test_fmt { r#" [ # Thirty Seven + 37, # Thirty Eight 38, From eb92d2018962458f592b55a6d255e4ed2ea1931a Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sun, 1 May 2022 15:30:46 -0400 Subject: [PATCH 726/846] Build builtin docs from builtins/roc --- README.md | 2 +- www/build.sh | 43 +++++++++++++++++++++++++------------------ 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index c0c5f98702..7be87d5bba 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ The core Roc language and standard library include no I/O operations, which give ## Project Goals -Roc is in relatively early stages of development. It's currently possible to build both platforms and applications (see the [examples](https://github.com/rtfeldman/roc/tree/trunk/examples) folder for some examples that aren't particularly organized at the moment), although [documentation](https://github.com/rtfeldman/roc/tree/trunk/compiler/builtins/docs) is in even earlier stages than the compiler itself. +Roc is in relatively early stages of development. It's currently possible to build both platforms and applications (see the [examples](https://github.com/rtfeldman/roc/tree/trunk/examples) folder for some examples that aren't particularly organized at the moment), although [documentation](https://github.com/rtfeldman/roc/tree/trunk/compiler/builtins/roc) is in even earlier stages than the compiler itself. Besides the above language design, a separate goal is for Roc to ship with an ambitiously boundary-pushing graphical editor. Not like "an IDE," but rather something that makes people say "I have never seen anything remotely like this outside of Bret Victor demos." diff --git a/www/build.sh b/www/build.sh index fbe0bdfbf4..cf27ae6b40 100755 --- a/www/build.sh +++ b/www/build.sh @@ -28,21 +28,28 @@ rm deploy.zip popd -# pushd .. -# echo 'Generating docs...' -# cargo --version -# rustc --version -# # We run the CLI with --no-default-features because that way we don't have the -# # "llvm" feature and therefore don't depend on LLVM being installed on the -# # system. (Netlify's build servers have Rust installed, but not LLVM.) -# # -# # We set RUSTFLAGS to -Awarnings to ignore warnings during this build, -# # because when building without "the" llvm feature (which is only ever done -# # for this exact use case), the result is lots of "unused" warnings! -# # -# # We set ROC_DOCS_ROOT_DIR=builtins so that links will be generated relative to -# # "/builtins/" rather than "/" - which is what we want based on how the server -# # is set up to serve them. -# RUSTFLAGS=-Awarnings ROC_DOCS_URL_ROOT=builtins cargo run -p roc_cli --no-default-features docs compiler/builtins/docs/*.roc -# mv generated-docs/ www/build/builtins -# popd +pushd .. +echo 'Generating docs...' +cargo --version +rustc --version + +# We set RUSTFLAGS to -Awarnings to ignore warnings during this build, +# because when building without "the" llvm feature (which is only ever done +# for this exact use case), the result is lots of "unused" warnings! +RUSTFLAGS=-Awarnings + +# We set ROC_DOCS_ROOT_DIR=builtins so that links will be generated relative to +# "/builtins/" rather than "/" - which is what we want based on how the server +# is set up to serve them. +ROC_DOCS_URL_ROOT=builtins + +# These just need to be defined so that some env! macros don't fail. +BUILTINS_WASM32_O="" +BUILTINS_HOST_O="" + +# We run the CLI with --no-default-features because that way we don't have the +# "llvm" feature and therefore don't depend on LLVM being installed on the +# system. (Netlify's build servers have Rust installed, but not LLVM.) +cargo run -p roc_cli --no-default-features docs compiler/builtins/roc/*.roc +mv generated-docs/ www/build/builtins +popd From 7fc0330a71f748f88cc91916fc9d73a2e8daf913 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sun, 1 May 2022 15:43:31 -0400 Subject: [PATCH 727/846] Move builtin docs from docs/ to roc/ --- compiler/builtins/roc/Num.roc | 937 +++++++++++++++++++++++++++++++++- 1 file changed, 936 insertions(+), 1 deletion(-) diff --git a/compiler/builtins/roc/Num.roc b/compiler/builtins/roc/Num.roc index dc0c1a7bd7..204ed9502a 100644 --- a/compiler/builtins/roc/Num.roc +++ b/compiler/builtins/roc/Num.roc @@ -158,8 +158,261 @@ interface Num Bool.{ Bool } ] +## Represents a number that could be either an [Int] or a [Float]. +## +## This is useful for functions that can work on either, for example #Num.add, whose type is: +## +## ``` +## add : Num a, Num a -> Num a +## ``` +## +## The number 1.5 technically has the type `Num (Fraction *)`, so when you pass +## two of them to [Num.add], the answer you get is `3.0 : Num (Fraction *)`. +## +## Similarly, the number 0x1 (that is, the integer 1 in hexadecimal notation) +## technically has the type `Num (Integer *)`, so when you pass two of them to +## [Num.add], the answer you get is `2 : Num (Integer *)`. +## +## The type [`Float a`]([Float]) is defined to be an alias for `Num (Fraction a)`, +## so `3.0 : Num (Fraction *)` is the same value as `3.0 : Float *`. +## Similarly, the type [`Int a`](#Int) is defined to be an alias for +## `Num (Integer a)`, so `2 : Num (Integer *)` is the same value as +## `2 : Int *`. +## +## In this way, the [Num] type makes it possible to have `1 + 0x1` return +## `2 : Int *` and `1.5 + 1.5` return `3.0 : Frac`. +## +## ## Number Literals +## +## Number literals without decimal points (like `0`, `4` or `360`) +## have the type `Num *` at first, but usually end up taking on +## a more specific type based on how they're used. +## +## For example, in `(1 + List.len myList)`, the `1` has the type `Num *` at first, +## but because `List.len` returns a `Nat`, the `1` ends up changing from +## `Num *` to the more specific `Nat`, and the expression as a whole +## ends up having the type `Nat`. +## +## Sometimes number literals don't become more specific. For example, +## the `Num.toStr` function has the type `Num * -> Str`. This means that +## when calling `Num.toStr (5 + 6)`, the expression `(5 + 6)` +## still has the type `Num *`. When this happens, `Num *` defaults to +## being an [I64] - so this addition expression would overflow +## if either 5 or 6 were replaced with a number big enough to cause +## addition overflow on an [I64] value. +## +## If this default of [I64] is not big enough for your purposes, +## you can add an `i128` to the end of the number literal, like so: +## +## >>> Num.toStr 5_000_000_000i128 +## +## This `i128` suffix specifies that you want this number literal to be +## an [I128] instead of a `Num *`. All the other numeric types have +## suffixes just like `i128`; here are some other examples: +## +## * `215u8` is a `215` value of type [U8] +## * `76.4f32` is a `76.4` value of type [F32] +## * `123.45dec` is a `123.45` value of type [Dec] +## * `12345nat` is a `12345` value of type [Nat] +## +## In practice, these are rarely needed. It's most common to write +## number literals without any suffix. Num range := range + +## A fixed-size integer - that is, a number with no fractional component. +## +## Integers come in two flavors: signed and unsigned. Signed integers can be +## negative ("signed" refers to how they can incorporate a minus sign), +## whereas unsigned integers cannot be negative. +## +## Since integers have a fixed size, the size you choose determines both the +## range of numbers it can represent, and also how much memory it takes up. +## +## #U8 is an an example of an integer. It is an unsigned #Int that takes up 8 bits +## (aka 1 byte) in memory. The `U` is for Unsigned and the 8 is for 8 bits. +## Because it has 8 bits to work with, it can store 256 numbers (2^8), +## and because it is unsigned, its min value is 0. This means the 256 numbers +## it can store range from 0 to 255. +## +## #I8 is a signed integer that takes up 8 bits. The `I` is for Integer, since +## integers in mathematics are signed by default. Because it has 8 bits just +## like #U8, it can store 256 numbers (still 2^16), but because it is signed, +## the range is different. Its 256 numbers range from -128 to 127. +## +## Here are some other examples: +## +## * #U16 is like #U8, except it takes up 16 bytes in memory. It can store 65,536 numbers (2^16), ranging from 0 to 65,536. +## * #I16 is like #U16, except it is signed. It can still store the same 65,536 numbers (2^16), ranging from -32,768 to 32,767. +## +## This pattern continues up to #U128 and #I128. +## +## ## Performance notes +## +## In general, using smaller numeric sizes means your program will use less memory. +## However, if a mathematical operation results in an answer that is too big +## or too small to fit in the size available for that answer (which is typically +## the same size as the inputs), then you'll get an overflow error. +## +## As such, minimizing memory usage without causing overflows involves choosing +## number sizes based on your knowledge of what numbers you expect your program +## to encounter at runtime. +## +## Minimizing memory usage does not imply maximum runtime speed! +## CPUs are typically fastest at performing integer operations on integers that +## are the same size as that CPU's native machine word size. That means a 64-bit +## CPU is typically fastest at executing instructions on #U64 and #I64 values, +## whereas a 32-bit CPU is typically fastest on #U32 and #I32 values. +## +## Putting these factors together, here are some reasonable guidelines for optimizing performance through integer size choice: +## +## * Start by deciding if this integer should allow negative numbers, and choose signed or unsigned accordingly. +## * Next, think about the range of numbers you expect this number to hold. Choose the smallest size you will never expect to overflow, no matter the inputs your program receives. (Validating inputs for size, and presenting the user with an error if they are too big, can help guard against overflow.) +## * Finally, if a particular numeric calculation is running too slowly, you can try experimenting with other number sizes. This rarely makes a meaningful difference, but some processors can operate on different number sizes at different speeds. +## +## All number literals without decimal points are compatible with #Int values. +## +## >>> 1 +## +## >>> 0 +## +## You can optionally put underscores in your #Int literals. +## They have no effect on the number's value, but can make large numbers easier to read. +## +## >>> 1_000_000 +## +## Integers come in two flavors: *signed* and *unsigned*. +## +## * *Unsigned* integers can never be negative. The lowest value they can hold is zero. +## * *Signed* integers can be negative. +## +## Integers also come in different sizes. Choosing a size depends on your performance +## needs and the range of numbers you need to represent. At a high level, the +## general trade-offs are: +## +## * Larger integer sizes can represent a wider range of numbers. If you absolutely need to represent numbers in a certain range, make sure to pick an integer size that can hold them! +## * Smaller integer sizes take up less memory. This savings rarely matters in variables and function arguments, but the sizes of integers that you use in data structures can add up. This can also affect whether those data structures fit in [cache lines](https://en.wikipedia.org/wiki/CPU_cache#Cache_performance), which can be a performance bottleneck. +## * Certain CPUs work faster on some numeric sizes than others. If the CPU is taking too long to run numeric calculations, you may find a performance improvement by experimenting with numeric sizes that are larger than otherwise necessary. However, in practice, doing this typically degrades overall performance, so be careful to measure properly! +## +## Here are the different fixed size integer types: +## +## | Range | Type | Size | +## |--------------------------------------------------------|-------|----------| +## | ` -128` | [I8] | 1 Byte | +## | ` 127` | | | +## |--------------------------------------------------------|-------|----------| +## | ` 0` | [U8] | 1 Byte | +## | ` 255` | | | +## |--------------------------------------------------------|-------|----------| +## | ` -32_768` | [I16] | 2 Bytes | +## | ` 32_767` | | | +## |--------------------------------------------------------|-------|----------| +## | ` 0` | [U16] | 2 Bytes | +## | ` 65_535` | | | +## |--------------------------------------------------------|-------|----------| +## | ` -2_147_483_648` | [I32] | 4 Bytes | +## | ` 2_147_483_647` | | | +## |--------------------------------------------------------|-------|----------| +## | ` 0` | [U32] | 4 Bytes | +## | ` (over 4 billion) 4_294_967_295` | | | +## |--------------------------------------------------------|-------|----------| +## | ` -9_223_372_036_854_775_808` | [I64] | 8 Bytes | +## | ` 9_223_372_036_854_775_807` | | | +## |--------------------------------------------------------|-------|----------| +## | ` 0` | [U64] | 8 Bytes | +## | ` (over 18 quintillion) 18_446_744_073_709_551_615` | | | +## |--------------------------------------------------------|-------|----------| +## | `-170_141_183_460_469_231_731_687_303_715_884_105_728` | [I128]| 16 Bytes | +## | ` 170_141_183_460_469_231_731_687_303_715_884_105_727` | | | +## |--------------------------------------------------------|-------|----------| +## | ` (over 340 undecillion) 0` | [U128]| 16 Bytes | +## | ` 340_282_366_920_938_463_463_374_607_431_768_211_455` | | | +## +## Roc also has one variable-size integer type: [Nat]. The size of [Nat] is equal +## to the size of a memory address, which varies by system. For example, when +## compiling for a 64-bit system, [Nat] is the same as [U64]. When compiling for a +## 32-bit system, it's the same as [U32]. +## +## A common use for [Nat] is to store the length ("len" for short) of a +## collection like a [List]. 64-bit systems can represent longer +## lists in memory than 32-bit systems can, which is why the length of a list +## is represented as a [Nat] in Roc. +## +## If any operation would result in an [Int] that is either too big +## or too small to fit in that range (e.g. calling `Num.maxI32 + 1`), +## then the operation will *overflow*. When an overflow occurs, the program will crash. +## +## As such, it's very important to design your code not to exceed these bounds! +## If you need to do math outside these bounds, consider using a larger numeric size. + Int range : Num (Integer range) + +## A fixed-size number with a fractional component. +## +## Roc fractions come in two flavors: fixed-point base-10 and floating-point base-2. +## +## * [Dec] is a 128-bit [fixed-point](https://en.wikipedia.org/wiki/Fixed-point_arithmetic) base-10 number. It's a great default choice, especially when precision is important - for example when representing currency. With [Dec], 0.1 + 0.2 returns 0.3. +## * [F64] and [F32] are [floating-point](https://en.wikipedia.org/wiki/Floating-point_arithmetic) base-2 numbers. They sacrifice precision for lower memory usage and improved performance on some operations. This makes them a good fit for representing graphical coordinates. With [F64], 0.1 + 0.2 returns 0.3000000000000000444089209850062616169452667236328125. +## +## If you don't specify a type, Roc will default to using [Dec] because it's +## the least error-prone overall. For example, suppose you write this: +## +## wasItPrecise = 0.1 + 0.2 == 0.3 +## +## The value of `wasItPrecise` here will be `True`, because Roc uses [Dec] +## by default when there are no types specified. +## +## In contrast, suppose we use `f32` or `f64` for one of these numbers: +## +## wasItPrecise = 0.1f64 + 0.2 == 0.3 +## +## Here, `wasItPrecise` will be `False` because the entire calculation will have +## been done in a base-2 floating point calculation, which causes noticeable +## precision loss in this case. +## +## The floating-point numbers ([F32] and [F64]) also have three values which +## are not ordinary [finite numbers](https://en.wikipedia.org/wiki/Finite_number). +## They are: +## * ∞ ([infinity](https://en.wikipedia.org/wiki/Infinity)) +## * -∞ (negative infinity) +## * *NaN* ([not a number](https://en.wikipedia.org/wiki/NaN)) +## +## These values are different from ordinary numbers in that they only occur +## when a floating-point calculation encounters an error. For example: +## * Dividing a positive [F64] by `0.0` returns ∞. +## * Dividing a negative [F64] by `0.0` returns -∞. +## * Dividing a [F64] of `0.0` by `0.0` returns [*NaN*](Num.isNaN). +## +## These rules come from the [IEEE-754](https://en.wikipedia.org/wiki/IEEE_754) +## floating point standard. Because almost all modern processors are built to +## this standard, deviating from these rules has a significant performance +## cost! Since the most common reason to choose [F64] or [F32] over [Dec] is +## access to hardware-accelerated performance, Roc follows these rules exactly. +## +## There's no literal syntax for these error values, but you can check to see if +## you ended up with one of them by using [isNaN], [isFinite], and [isInfinite]. +## Whenever a function in this module could return one of these values, that +## possibility is noted in the function's documentation. +## +## ## Performance Notes +## +## On typical modern CPUs, performance is similar between [Dec], [F64], and [F32] +## for addition and subtraction. For example, [F32] and [F64] do addition using +## a single CPU floating-point addition instruction, which typically takes a +## few clock cycles to complete. In contrast, [Dec] does addition using a few +## CPU integer arithmetic instructions, each of which typically takes only one +## clock cycle to complete. Exact numbers will vary by CPU, but they should be +## similar overall. +## +## [Dec] is significantly slower for multiplication and division. It not only +## needs to do more arithmetic instructions than [F32] and [F64] do, but also +## those instructions typically take more clock cycles to complete. +## +## With [Num.sqrt] and trigonometry functions like [Num.cos], there is +## an even bigger performance difference. [F32] and [F64] can do these in a +## single instruction, whereas [Dec] needs entire custom procedures - which use +## loops and conditionals. If you need to do performance-critical trigonometry +## or square roots, either [F64] or [F32] is probably a better choice than the +## usual default choice of [Dec], despite the precision problems they bring. Float range : Num (FloatingPoint range) Signed128 := [] @@ -182,6 +435,8 @@ I128 : Num (Integer Signed128) I64 : Num (Integer Signed64) I32 : Num (Integer Signed32) I16 : Num (Integer Signed16) + +## A signed 8-bit integer, ranging from -128 to 127 I8 : Int Signed8 U128 : Num (Integer Unsigned128) @@ -190,6 +445,16 @@ U32 : Num (Integer Unsigned32) U16 : Num (Integer Unsigned16) U8 : Num (Integer Unsigned8) +## A [natural number](https://en.wikipedia.org/wiki/Natural_number) represented +## as a 64-bit unsigned integer on 64-bit systems, a 32-bit unsigned integer +## on 32-bit systems, and so on. +## +## This system-specific size makes it useful for certain data structure +## functions like [List.len], because the number of elements many data strucures +## can hold is also system-specific. For example, the maximum number of elements +## a [List] can hold on a 64-bit system fits in a 64-bit unsigned integer, and +## on a 32-bit system it fits in 32-bit unsigned integer. This makes [Nat] a +## good fit for [List.len] regardless of system. Nat : Num (Integer Natural) Decimal := [] @@ -200,10 +465,60 @@ FloatingPoint range := range F64 : Num (FloatingPoint Binary64) F32 : Num (FloatingPoint Binary32) + +## A decimal number. +## +## [Dec] is the best default choice for representing base-10 decimal numbers +## like currency, because it is base-10 under the hood. In contrast, +## [F64] and [F32] are base-2 under the hood, which can lead to decimal +## precision loss even when doing addition and subtraction. For example, when +## using [F64], running 0.1 + 0.2 returns 0.3000000000000000444089209850062616169452667236328125, +## whereas when using [Dec], 0.1 + 0.2 returns 0.3. +## +## Under the hood, a [Dec] is an [I128], and operations on it perform +## [base-10 fixed-point arithmetic](https://en.wikipedia.org/wiki/Fixed-point_arithmetic) +## with 18 decimal places of precision. +## +## This means a [Dec] can represent whole numbers up to slightly over 170 +## quintillion, along with 18 decimal places. (To be precise, it can store +## numbers betwween `-170_141_183_460_469_231_731.687303715884105728` +## and `170_141_183_460_469_231_731.687303715884105727`.) Why 18 +## decimal places? It's the highest number of decimal places where you can still +## convert any [U64] to a [Dec] without losing information. +## +## There are some use cases where [F64] and [F32] can be better choices than [Dec] +## despite their precision issues. For example, in graphical applications they +## can be a better choice for representing coordinates because they take up +## less memory, certain relevant calculations run faster (see performance +## details, below), and decimal precision loss isn't as big a concern when +## dealing with screen coordinates as it is when dealing with currency. +## +## ## Performance +## +## [Dec] typically takes slightly less time than [F64] to perform addition and +## subtraction, but 10-20 times longer to perform multiplication and division. +## [sqrt] and trigonometry are massively slower with [Dec] than with [F64]. Dec : Num (FloatingPoint Decimal) # ------- Functions +## Convert a number to a [Str]. +## +## This is the same as calling `Num.format {}` - so for more details on +## exact formatting, see `Num.format`. +## +## >>> Num.toStr 42 +## +## Only [Float] values will include a decimal point, and they will always include one. +## +## >>> Num.toStr 4.2 +## +## >>> Num.toStr 4.0 +## +## When this function is given a non-[finite](Num.isFinite) +## [F64] or [F32] value, the returned string will be `"NaN"`, `"∞"`, or `"-∞"`. +## +## To get strings in hexadecimal, octal, or binary format, use `Num.format`. toStr : Num * -> Str intCast : Int a -> Int b @@ -212,26 +527,170 @@ bytesToU32 : List U8, Nat -> Result U32 [ OutOfBounds ] compare : Num a, Num a -> [ LT, EQ, GT ] +## Returns `True` if the first number is less than the second. +## +## `a < b` is shorthand for `Num.isLt a b`. +## +## If either argument is [*NaN*](Num.isNaN), returns `False` no matter what. (*NaN* +## is [defined to be unordered](https://en.wikipedia.org/wiki/NaN#Comparison_with_NaN).) +## +## >>> 5 +## >>> |> Num.isLt 6 isLt : Num a, Num a -> Bool + +## Returns `True` if the first number is greater than the second. +## +## `a > b` is shorthand for `Num.isGt a b`. +## +## If either argument is [*NaN*](Num.isNaN), returns `False` no matter what. (*NaN* +## is [defined to be unordered](https://en.wikipedia.org/wiki/NaN#Comparison_with_NaN).) +## +## >>> 6 +## >>> |> Num.isGt 5 isGt : Num a, Num a -> Bool + +## Returns `True` if the first number is less than or equal to the second. +## +## `a <= b` is shorthand for `Num.isLte a b`. +## +## If either argument is [*NaN*](Num.isNaN), returns `False` no matter what. (*NaN* +## is [defined to be unordered](https://en.wikipedia.org/wiki/NaN#Comparison_with_NaN).) isLte : Num a, Num a -> Bool + +## Returns `True` if the first number is greater than or equal to the second. +## +## `a >= b` is shorthand for `Num.isGte a b`. +## +## If either argument is [*NaN*](Num.isNaN), returns `False` no matter what. (*NaN* +## is [defined to be unordered](https://en.wikipedia.org/wiki/NaN#Comparison_with_NaN).) isGte : Num a, Num a -> Bool +## Returns `True` if the number is `0`, and `False` otherwise. isZero : Num a -> Bool +## A number is even if dividing it by 2 gives a remainder of 0. +## +## Examples of even numbers: 0, 2, 4, 6, 8, -2, -4, -6, -8 isEven : Int a -> Bool + +## A number is odd if dividing it by 2 gives a remainder of 1. +## +## Examples of odd numbers: 1, 3, 5, 7, -1, -3, -5, -7 isOdd : Int a -> Bool +## Positive numbers are greater than `0`. isPositive : Num a -> Bool + +## Negative numbers are less than `0`. isNegative : Num a -> Bool toFloat : Num * -> Float * +## Return the absolute value of the number. +## +## * For a positive number, returns the same number. +## * For a negative number, returns the same number except positive. +## * For zero, returns zero. +## +## >>> Num.abs 4 +## +## >>> Num.abs -2.5 +## +## >>> Num.abs 0 +## +## >>> Num.abs 0.0 +## +## This is safe to use with any [Float], but it can cause overflow when used with certain #Int values. +## +## For example, calling #Num.abs on the lowest value of a signed integer (such as [Num.minI64] or [Num.minI32]) will cause overflow. +## This is because, for any given size of signed integer (32-bit, 64-bit, etc.) its negated lowest value turns out to be 1 higher than +## the highest value it can represent. (For this reason, calling [Num.neg] on the lowest signed value will also cause overflow.) +## +## Calling this on an unsigned integer (like #U32 or #U64) never does anything. abs : Num a -> Num a + +## Return a negative number when given a positive one, and vice versa. +## +## >>> Num.neg 5 +## +## >>> Num.neg -2.5 +## +## >>> Num.neg 0 +## +## >>> Num.neg 0.0 +## +## This is safe to use with any [Float], but it can cause overflow when used with certain #Int values. +## +## For example, calling #Num.neg on the lowest value of a signed integer (such as [Num.minI64] or [Num.minI32]) will cause overflow. +## This is because, for any given size of signed integer (32-bit, 64-bit, etc.) its negated lowest value turns out to be 1 higher than +## the highest value it can represent. (For this reason, calling #Num.abs on the lowest signed value will also cause overflow.) +## +## Additionally, calling #Num.neg on any unsigned integer (such as any #U64 or #U32 value) other than zero will cause overflow. +## +## (It will never crash when given a [Float], however, because of how floating point numbers represent positive and negative numbers.) neg : Num a -> Num a +## Add two numbers of the same type. +## +## (To add an #Int and a [Float], first convert one so that they both have the same type. There are functions in the [`Frac`](/Frac) module that can convert both #Int to [Float] and the other way around.) +## +## `a + b` is shorthand for `Num.add a b`. +## +## >>> 5 + 7 +## +## >>> Num.add 5 7 +## +## `Num.add` can be convenient in pipelines. +## +## >>> Frac.pi +## >>> |> Num.add 1.0 +## +## If the answer to this operation can't fit in the return value (e.g. an +## [I8] answer that's higher than 127 or lower than -128), the result is an +## *overflow*. For [F64] and [F32], overflow results in an answer of either +## ∞ or -∞. For all other number types, overflow results in a panic. add : Num a, Num a -> Num a + +## Subtract two numbers of the same type. +## +## (To subtract an #Int and a [Float], first convert one so that they both have the same type. There are functions in the [`Frac`](/Frac) module that can convert both #Int to [Float] and the other way around.) +## +## `a - b` is shorthand for `Num.sub a b`. +## +## >>> 7 - 5 +## +## >>> Num.sub 7 5 +## +## `Num.sub` can be convenient in pipelines. +## +## >>> Frac.pi +## >>> |> Num.sub 2.0 +## +## If the answer to this operation can't fit in the return value (e.g. an +## [I8] answer that's higher than 127 or lower than -128), the result is an +## *overflow*. For [F64] and [F32], overflow results in an answer of either +## ∞ or -∞. For all other number types, overflow results in a panic. sub : Num a, Num a -> Num a + +## Multiply two numbers of the same type. +## +## (To multiply an #Int and a [Float], first convert one so that they both have the same type. There are functions in the [`Frac`](/Frac) module that can convert both #Int to [Float] and the other way around.) +## +## `a * b` is shorthand for `Num.mul a b`. +## +## >>> 5 * 7 +## +## >>> Num.mul 5 7 +## +## `Num.mul` can be convenient in pipelines. +## +## >>> Frac.pi +## >>> |> Num.mul 2.0 +## +## If the answer to this operation can't fit in the return value (e.g. an +## [I8] answer that's higher than 127 or lower than -128), the result is an +## *overflow*. For [F64] and [F32], overflow results in an answer of either +## ∞ or -∞. For all other number types, overflow results in a panic. mul : Num a, Num a -> Num a sin : Float a -> Float a @@ -242,19 +701,100 @@ asin : Float a -> Float a acos : Float a -> Float a atan : Float a -> Float a +## Returns an approximation of the absolute value of a [Float]'s square root. +## +## The square root of a negative number is an irrational number, and [Float] only +## supports rational numbers. As such, you should make sure never to pass this +## function a negative number! Calling [sqrt] on a negative [Dec] will cause a panic. +## +## Calling [sqrt] on [F32] and [F64] values follows these rules: +## * Passing a negative [F64] or [F32] returns [*NaN*](Num.isNaN). +## * Passing [*NaN*](Num.isNaN) or -∞ also returns [*NaN*](Num.isNaN). +## * Passing ∞ returns ∞. +## +## > These rules come from the [IEEE-754](https://en.wikipedia.org/wiki/IEEE_754) +## > floating point standard. Because almost all modern processors are built to +## > this standard, deviating from these rules has a significant performance +## > cost! Since the most common reason to choose [F64] or [F32] over [Dec] is +## > access to hardware-accelerated performance, Roc follows these rules exactly. +## +## >>> Num.sqrt 4.0 +## +## >>> Num.sqrt 1.5 +## +## >>> Num.sqrt 0.0 +## +## >>> Num.sqrt -4.0f64 sqrt : Float a -> Float a sqrtChecked : Float a -> Result (Float a) [ SqrtOfNegative ]* log : Float a -> Float a logChecked : Float a -> Result (Float a) [ LogNeedsPositive ]* +## Divide one [Float] by another. +## +## `a / b` is shorthand for `Num.div a b`. +## +## [Division by zero is undefined in mathematics](https://en.wikipedia.org/wiki/Division_by_zero). +## As such, you should make sure never to pass zero as the denomaintor to this function! +## Calling [div] on a [Dec] denominator of zero will cause a panic. +## +## Calling [div] on [F32] and [F64] values follows these rules: +## * Dividing a positive [F64] or [F32] by zero returns ∞. +## * Dividing a negative [F64] or [F32] by zero returns -∞. +## * Dividing a zero [F64] or [F32] by zero returns [*NaN*](Num.isNaN). +## +## > These rules come from the [IEEE-754](https://en.wikipedia.org/wiki/IEEE_754) +## > floating point standard. Because almost all modern processors are built to +## > this standard, deviating from these rules has a significant performance +## > cost! Since the most common reason to choose [F64] or [F32] over [Dec] is +## > access to hardware-accelerated performance, Roc follows these rules exactly. +## +## To divide an [Int] and a [Float], first convert the [Int] to a [Float] using +## one of the functions in this module like #toDec. +## +## >>> 5.0 / 7.0 +## +## >>> Num.div 5 7 +## +## `Num.div` can be convenient in pipelines. +## +## >>> Num.pi +## >>> |> Num.div 2.0 div : Float a, Float a -> Float a divChecked : Float a, Float a -> Result (Float a) [ DivByZero ]* divCeil : Int a, Int a -> Int a divCeilChecked : Int a, Int a -> Result (Int a) [ DivByZero ]* +## Divide two integers, truncating the result towards zero. +## +## `a // b` is shorthand for `Num.divTrunc a b`. +## +## Division by zero is undefined in mathematics. As such, you should make +## sure never to pass zero as the denomaintor to this function! If you do, +## it will crash. +## +## >>> 5 // 7 +## +## >>> Num.divTrunc 5 7 +## +## >>> 8 // -3 +## +## >>> Num.divTrunc 8 -3 +## divTrunc : Int a, Int a -> Int a divTruncChecked : Int a, Int a -> Result (Int a) [ DivByZero ]* +## Obtain the remainder (truncating modulo) from the division of two integers. +## +## `a % b` is shorthand for `Num.rem a b`. +## +## >>> 5 % 7 +## +## >>> Num.rem 5 7 +## +## >>> -8 % -3 +## +## >>> Num.rem -8 -3 rem : Int a, Int a -> Int a remChecked : Int a, Int a -> Result (Int a) [ DivByZero ]* @@ -267,84 +807,272 @@ shiftLeftBy : Int a, Int a -> Int a shiftRightBy : Int a, Int a -> Int a shiftRightZfBy : Int a, Int a -> Int a +## Round off the given float to the nearest integer. round : Float * -> Int * floor : Float * -> Int * ceiling : Float * -> Int * +## Raises a [Float] to the power of another [Float]. +## +## For an #Int alternative to this function, see [Num.powInt] pow : Float a, Float a -> Float a + +## Raises an integer to the power of another, by multiplying the integer by +## itself the given number of times. +## +## This process is known as [exponentiation by squaring](https://en.wikipedia.org/wiki/Exponentiation_by_squaring). +## +## For a [Float] alternative to this function, which supports negative exponents, +## see #Num.exp. +## +## >>> Num.exp 5 0 +## +## >>> Num.exp 5 1 +## +## >>> Num.exp 5 2 +## +## >>> Num.exp 5 6 +## +## ## Performance Notes +## +## Be careful! It is very easy for this function to produce an answer +## so large it causes an overflow. powInt : Int a, Int a -> Int a addWrap : Int range, Int range -> Int range + +## Add two numbers, clamping on the maximum representable number rather than +## overflowing. +## +## This is the same as [Num.add] except for the saturating behavior if the +## addition is to overflow. +## For example, if `x : U8` is 200 and `y : U8` is 100, `addSaturated x y` will +## yield 255, the maximum value of a `U8`. addSaturated : Num a, Num a -> Num a + +## Add two numbers and check for overflow. +## +## This is the same as [Num.add] except if the operation overflows, instead of +## panicking or returning ∞ or -∞, it will return `Err Overflow`. addChecked : Num a, Num a -> Result (Num a) [ Overflow ]* subWrap : Int range, Int range -> Int range + +## Subtract two numbers, clamping on the minimum representable number rather +## than overflowing. +## +## This is the same as [Num.sub] except for the saturating behavior if the +## subtraction is to overflow. +## For example, if `x : U8` is 10 and `y : U8` is 20, `subSaturated x y` will +## yield 0, the minimum value of a `U8`. subSaturated : Num a, Num a -> Num a + +## Subtract two numbers and check for overflow. +## +## This is the same as [Num.sub] except if the operation overflows, instead of +## panicking or returning ∞ or -∞, it will return `Err Overflow`. subChecked : Num a, Num a -> Result (Num a) [ Overflow ]* mulWrap : Int range, Int range -> Int range # mulSaturated : Num a, Num a -> Num a + +## Multiply two numbers and check for overflow. +## +## This is the same as [Num.mul] except if the operation overflows, instead of +## panicking or returning ∞ or -∞, it will return `Err Overflow`. mulChecked : Num a, Num a -> Result (Num a) [ Overflow ]* +## The lowest number that can be stored in an [I8] without underflowing its +## available memory and crashing. +## +## For reference, this number is `-128`. +## +## Note that the positive version of this number is larger than [Num.maxI8], +## which means if you call [Num.abs] on [Num.minI8], it will overflow and crash! minI8 : I8 minI8 = -128i8 +## The highest number that can be stored in an [I8] without overflowing its +## available memory and crashing. +## +## For reference, this number is `127`. +## +## Note that this is smaller than the positive version of [Num.minI8], +## which means if you call [Num.abs] on [Num.minI8], it will overflow and crash! maxI8 : I8 maxI8 = 127i8 +## The lowest number that can be stored in a [U8] without underflowing its +## available memory and crashing. +## +## For reference, this number is zero, because [U8] is +## [unsigned](https://en.wikipedia.org/wiki/Signed_number_representations), +## and zero is the lowest unsigned number. +## Unsigned numbers cannot be negative. minU8 : U8 minU8 = 0u8 +## The highest number that can be stored in a [U8] without overflowing its +## available memory and crashing. +## +## For reference, this number is `255`. maxU8 : U8 maxU8 = 255u8 +## The lowest number that can be stored in an [I16] without underflowing its +## available memory and crashing. +## +## For reference, this number is `-32_768`. +## +## Note that the positive version of this number is larger than [Num.maxI16], +## which means if you call [Num.abs] on [Num.minI16], it will overflow and crash! minI16 : I16 minI16 = -32768i16 +## The highest number that can be stored in an [I16] without overflowing its +## available memory and crashing. +## +## For reference, this number is `32_767`. +## +## Note that this is smaller than the positive version of [Num.minI16], +## which means if you call [Num.abs] on [Num.minI16], it will overflow and crash! maxI16 : I16 maxI16 = 32767i16 +## The lowest number that can be stored in a [U16] without underflowing its +## available memory and crashing. +## +## For reference, this number is zero, because [U16] is +## [unsigned](https://en.wikipedia.org/wiki/Signed_number_representations), +## and zero is the lowest unsigned number. +## Unsigned numbers cannot be negative. minU16 : U16 minU16 = 0u16 +## The highest number that can be stored in a [U16] without overflowing its +## available memory and crashing. +## +## For reference, this number is `65_535`. maxU16 : U16 maxU16 = 65535u16 +## The lowest number that can be stored in an [I32] without underflowing its +## available memory and crashing. +## +## For reference, this number is `-2_147_483_648`. +## +## Note that the positive version of this number is larger than [Num.maxI32], +## which means if you call [Num.abs] on [Num.minI32], it will overflow and crash! minI32 : I32 minI32 = -2147483648 +## The highest number that can be stored in an [I32] without overflowing its +## available memory and crashing. +## +## For reference, this number is `2_147_483_647`, +## which is over 2 million. +## +## Note that this is smaller than the positive version of [Num.minI32], +## which means if you call [Num.abs] on [Num.minI32], it will overflow and crash! maxI32 : I32 maxI32 = 2147483647 +## The lowest number that can be stored in a [U32] without underflowing its +## available memory and crashing. +## +## For reference, this number is zero, because [U32] is +## [unsigned](https://en.wikipedia.org/wiki/Signed_number_representations), +## and zero is the lowest unsigned number. +## Unsigned numbers cannot be negative. minU32 : U32 minU32 = 0 +## The highest number that can be stored in a [U32] without overflowing its +## available memory and crashing. +## +## For reference, this number is `4_294_967_295`. maxU32 : U32 maxU32 = 4294967295 +## The lowest number that can be stored in an [I64] without underflowing its +## available memory and crashing. +## +## For reference, this number is `-9_223_372_036_854_775_808`, +## which is under 9 quintillion. +## +## Note that the positive version of this number is larger than [Num.maxI64], +## which means if you call [Num.abs] on [Num.minI64], it will overflow and crash! minI64 : I64 minI64 = -9223372036854775808 +## The highest number that can be stored in an [I64] without overflowing its +## available memory and crashing. +## +## For reference, this number is `9_223_372_036_854_775_807`, +## which is over 9 quintillion. +## +## Note that this is smaller than the positive version of [Num.minI64], +## which means if you call [Num.abs] on [Num.minI64], it will overflow and crash! maxI64 : I64 maxI64 = 9223372036854775807 +## The lowest number that can be stored in a [U64] without underflowing its +## available memory and crashing. +## +## For reference, this number is zero, because [U64] is +## [unsigned](https://en.wikipedia.org/wiki/Signed_number_representations), +## and zero is the lowest unsigned number. +## Unsigned numbers cannot be negative. minU64 : U64 minU64 = 0 +## The highest number that can be stored in a [U64] without overflowing its +## available memory and crashing. +## +## For reference, this number is `18_446_744_073_709_551_615`, +## which is over 18 quintillion. maxU64 : U64 maxU64 = 18446744073709551615 +## The lowest number that can be stored in an [I128] without underflowing its +## available memory and crashing. +## +## For reference, this number is `-170_141_183_460_469_231_731_687_303_715_884_105_728`. +## which is under 170 undecillion. +## +## Note that the positive version of this number is larger than [Num.maxI128], +## which means if you call [Num.abs] on [Num.minI128], it will overflow and crash! minI128 : I128 minI128 = -170141183460469231731687303715884105728 +## The highest number that can be stored in an [I128] without overflowing its +## available memory and crashing. +## +## For reference, this number is `170_141_183_460_469_231_731_687_303_715_884_105_727`, +## which is over 170 undecillion. +## +## Note that this is smaller than the positive version of [Num.minI128], +## which means if you call [Num.abs] on [Num.minI128], it will overflow and crash! maxI128 : I128 maxI128 = 170141183460469231731687303715884105727 +## The lowest number that can be stored in a [U128] without underflowing its +## available memory and crashing. +## +## For reference, this number is zero, because [U128] is +## [unsigned](https://en.wikipedia.org/wiki/Signed_number_representations), +## and zero is the lowest unsigned number. +## Unsigned numbers cannot be negative. minU128 : U128 minU128 = 0 +## The highest number that can be stored in a [U128] without overflowing its +## available memory and crashing. +## +## For reference, this number is `340_282_366_920_938_463_463_374_607_431_768_211_455`, +## which is over 340 undecillion. maxU128 : U128 -maxU128 = 0340282366920938463463374607431768211455 +maxU128 = 340282366920938463463374607431768211455 minF32 : F32 minF32 = -3.40282347e38 @@ -358,6 +1086,9 @@ minF64 = -1.7976931348623157e308 maxF64 : F64 maxF64 = 1.7976931348623157e308 + +## Converts an [Int] to an [I8]. If the given number can't be precisely represented in an [I8], +## the returned number may be different from the given number. toI8 : Int * -> I8 toI16 : Int * -> I16 toI32 : Int * -> I32 @@ -368,11 +1099,35 @@ toU16 : Int * -> U16 toU32 : Int * -> U32 toU64 : Int * -> U64 toU128 : Int * -> U128 + +## Convert an [Int] to a [Nat]. If the given number doesn't fit in [Nat], it will be truncated. +## Since #Nat has a different maximum number depending on the system you're building +## for, this may give a different answer on different systems. +## +## For example, on a 32-bit system, #Num.maxNat will return the same answer as +## [Num.maxU32]. This means that calling `Num.toNat 9_000_000_000` on a 32-bit +## system will return [Num.maxU32] instead of 9 billion, because 9 billion is +## higher than [Num.maxU32] and will not fit in a [Nat] on a 32-bit system. +## +## However, calling `Num.toNat 9_000_000_000` on a 64-bit system will return +## the #Nat value of 9_000_000_000. This is because on a 64-bit system, [Nat] can +## hold up to [Num.maxU64], and 9_000_000_000 is lower than [Num.maxU64]. +## +## To convert a [Float] to a [Nat], first call either #Num.round, #Num.ceil, or [Num.floor] +## on it, then call this on the resulting [Int]. toNat : Int * -> Nat +## Converts a [Num] to an [F32]. If the given number can't be precisely represented in an [F32], +## the returned number may be different from the given number. toF32 : Num * -> F32 + +## Converts a [Num] to an [F64]. If the given number can't be precisely represented in an [F64], +## the returned number may be different from the given number. toF64 : Num * -> F64 +## Converts a [Int] to an [I8]. +## If the given integer can't be precisely represented in an [I8], returns +## `Err OutOfBounds`. toI8Checked : Int * -> Result I8 [ OutOfBounds ]* toI16Checked : Int * -> Result I16 [ OutOfBounds ]* toI32Checked : Int * -> Result I32 [ OutOfBounds ]* @@ -386,3 +1141,183 @@ toU128Checked : Int * -> Result U128 [ OutOfBounds ]* toNatChecked : Int * -> Result Nat [ OutOfBounds ]* toF32Checked : Num * -> Result F32 [ OutOfBounds ]* toF64Checked : Num * -> Result F64 [ OutOfBounds ]* + + +# Special Floating-Point operations + +## When given a [F64] or [F32] value, returns `False` if that value is +## [*NaN*](Num.isNaN), ∞ or -∞, and `True` otherwise. +## +## Always returns `True` when given a [Dec]. +## +## This is the opposite of [isInfinite], except when given [*NaN*](Num.isNaN). Both +## [isFinite] and [isInfinite] return `False` for [*NaN*](Num.isNaN). +#isFinite : Float * -> Bool + +## When given a [F64] or [F32] value, returns `True` if that value is either +## ∞ or -∞, and `False` otherwise. +## +## Always returns `False` when given a [Dec]. +## +## This is the opposite of [isFinite], except when given [*NaN*](Num.isNaN). Both +## [isFinite] and [isInfinite] return `False` for [*NaN*](Num.isNaN). +#isInfinite : Float * -> Bool + +## When given a [F64] or [F32] value, returns `True` if that value is +## *NaN* ([not a number](https://en.wikipedia.org/wiki/NaN)), and `False` otherwise. +## +## Always returns `False` when given a [Dec]. +## +## >>> Num.isNaN 12.3 +## +## >>> Num.isNaN (Num.pow -1 0.5) +## +## *NaN* is unusual from other numberic values in that: +## * *NaN* is not equal to any other number, even itself. [Bool.isEq] always returns `False` if either argument is *NaN*. +## * *NaN* has no ordering, so [isLt], [isLte], [isGt], and [isGte] always return `False` if either argument is *NaN*. +## +## These rules come from the [IEEE-754](https://en.wikipedia.org/wiki/IEEE_754) +## floating point standard. Because almost all modern processors are built to +## this standard, deviating from these rules has a significant performance +## cost! Since the most common reason to choose [F64] or [F32] over [Dec] is +## access to hardware-accelerated performance, Roc follows these rules exactly. +## +## Note that you should never put a *NaN* into a [Set], or use it as the key in +## a [Dict]. The result is entries that can never be removed from those +## collections! See the documentation for [Set.add] and [Dict.insert] for details. +#isNaN : Float * -> Bool + + +## Returns the higher of two numbers. +## +## If either argument is [*NaN*](Num.isNaN), returns `False` no matter what. (*NaN* +## is [defined to be unordered](https://en.wikipedia.org/wiki/NaN#Comparison_with_NaN).) +#max : Num a, Num a -> Num a + +## Returns the lower of two numbers. +## +## If either argument is [*NaN*](Num.isNaN), returns `False` no matter what. (*NaN* +## is [defined to be unordered](https://en.wikipedia.org/wiki/NaN#Comparison_with_NaN).) +#min : Num a, Num a -> Num a + +# Branchless implementation that works for all numeric types: +# +# let is_lt = arg1 < arg2; +# let is_eq = arg1 == arg2; +# return (is_lt as i8 - is_eq as i8) + 1; +# +# 1, 1 -> (0 - 1) + 1 == 0 # Eq +# 5, 1 -> (0 - 0) + 1 == 1 # Gt +# 1, 5 -> (1 - 0) + 1 == 2 # Lt + +## Returns `Lt` if the first number is less than the second, `Gt` if +## the first is greater than the second, and `Eq` if they're equal. +## +## Although this can be passed to `List.sort`, you'll get better performance +## by using `List.sortAsc` or `List.sortDesc` instead. +#compare : Num a, Num a -> [ Lt, Eq, Gt ] + +## [Endianness](https://en.wikipedia.org/wiki/Endianness) +# Endi : [ Big, Little, Native ] + +## The `Endi` argument does not matter for [U8] and [I8], since they have +## only one byte. +# toBytes : Num *, Endi -> List U8 + +## when Num.parseBytes bytes Big is +## Ok { val: f64, rest } -> ... +## Err (ExpectedNum (Float Binary64)) -> ... +# parseBytes : List U8, Endi -> Result { val : Num a, rest : List U8 } [ ExpectedNum a ]* + +## when Num.fromBytes bytes Big is +## Ok f64 -> ... +## Err (ExpectedNum (Float Binary64)) -> ... +# fromBytes : List U8, Endi -> Result (Num a) [ ExpectedNum a ]* + +# Bit shifts + +## [Logical bit shift](https://en.wikipedia.org/wiki/Bitwise_operation#Logical_shift) left. +## +## `a << b` is shorthand for `Num.shl a b`. +#shl : Int a, Int a -> Int a + +## [Arithmetic bit shift](https://en.wikipedia.org/wiki/Bitwise_operation#Arithmetic_shift) left. +## +## This is called `shlWrap` because any bits shifted +## off the beginning of the number will be wrapped around to +## the end. (In contrast, [shl] replaces discarded bits with zeroes.) +#shlWrap : Int a, Int a -> Int a + +## [Logical bit shift](https://en.wikipedia.org/wiki/Bitwise_operation#Logical_shift) right. +## +## `a >> b` is shorthand for `Num.shr a b`. +#shr : Int a, Int a -> Int a + +## [Arithmetic bit shift](https://en.wikipedia.org/wiki/Bitwise_operation#Arithmetic_shift) right. +## +## This is called `shrWrap` because any bits shifted +## off the end of the number will be wrapped around to +## the beginning. (In contrast, [shr] replaces discarded bits with zeroes.) +#shrWrap : Int a, Int a -> Int a + +# ## Convert a number into a [Str], formatted with the given options. +# ## +# ## Default options: +# ## * `base: Decimal` +# ## * `notation: Standard` +# ## * `decimalMark: HideForIntegers "."` +# ## * `decimalDigits: { min: 0, max: All }` +# ## * `minIntDigits: 1` +# ## * `wholeSep: { mark: ",", places: 3 }` +# ## +# ## ## Options +# ## +# ## +# ## ### decimalMark +# ## +# ## * `AlwaysShow` always shows the decimal mark, no matter what. +# ## * `HideForIntegers` hides the decimal mark if all the numbers after the decimal mark are 0. +# ## +# ## The [Str] included in either of these represents the mark itself. +# ## +# ## ### `decimalDigits +# ## +# ## With 0 decimal digits, the decimal mark will still be rendered if +# ## `decimalMark` is set to `AlwaysShow`. +# ## +# ## If `max` is less than `min`, then first the number will be truncated to `max` +# ## digits, and then zeroes will be added afterwards until it reaches `min` digits. +# ## +# ## >>> Num.format 1.23 { decPlaces: 0, decPointVis: AlwaysShow } +# ## +# ## ### minIntDigits +# ## +# ## If the integer portion of number is fewer than this many digits, zeroes will +# ## be added in front of it until there are at least `minWholeDigits` digits. +# ## +# ## If this is set to zero, then numbers less than 1 will begin with `"."` +# ## rather than `"0."`. +# ## +# ## ### wholeSep +# ## +# ## Examples: +# ## +# ## In some countries (e.g. USA and UK), a comma is used to separate thousands: +# ## >>> Num.format 1_000_000 { pf: Decimal, wholeSep: { mark: ",", places: 3 } } +# ## +# ## Sometimes when rendering bits, it's nice to group them into groups of 4: +# ## >>> Num.format 1_000_000 { pf: Binary, wholeSep: { mark: " ", places: 4 } } +# ## +# ## It's also common to render hexadecimal in groups of 2: +# ## >>> Num.format 1_000_000 { pf: Hexadecimal, wholeSep: { mark: " ", places: 2 } } +# format : +# Num *, +# { +# base ? [ Decimal, Hexadecimal, Octal, Binary ], +# notation ? [ Standard, Scientific ], +# decimalMark ? [ AlwaysShow Str, HideForIntegers ], +# decimalDigits ? { min : U16, max : [ All, Trunc U16, Round U16, Floor U16, Ceil U16 ] }, +# minWholeDigits ? U16, +# wholeSep ? { mark : Str, places : U64 } +# } +# -> Str From 2dcd0f4d2ba4613d9f9372caeb3d65034e3ee09c Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sun, 1 May 2022 20:57:18 -0400 Subject: [PATCH 728/846] Generate builtin docs in Earthfile --- Earthfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Earthfile b/Earthfile index 5114347083..2d614d5bef 100644 --- a/Earthfile +++ b/Earthfile @@ -100,6 +100,9 @@ test-rust: # RUN echo "4" | cargo run --locked --release --features="target-x86" -- --target=x86_32 examples/benchmarks/NQueens.roc # RUN --mount=type=cache,target=$SCCACHE_DIR \ # cargo test --locked --release --features with_sound --test cli_run i386 --features="i386-cli-run" && sccache --show-stats + # make sure doc generation works (that is, make sure build.sh returns status code 0) + RUN bash www/build.sh + verify-no-git-changes: FROM +test-rust From 4e220288a5fc7e7d80744225f6c96d24fe01c56c Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sun, 1 May 2022 20:58:01 -0400 Subject: [PATCH 729/846] Delete builtin docs for Num --- compiler/builtins/docs/Num.roc | 1301 -------------------------------- 1 file changed, 1301 deletions(-) delete mode 100644 compiler/builtins/docs/Num.roc diff --git a/compiler/builtins/docs/Num.roc b/compiler/builtins/docs/Num.roc deleted file mode 100644 index f9174c1bbc..0000000000 --- a/compiler/builtins/docs/Num.roc +++ /dev/null @@ -1,1301 +0,0 @@ -interface Num - exposes - [ - Num, - Binary64, - Binary32, - Dec, - Decimal, - Float, - FloatingPoint, - F32, - F64, - I8, - I16, - I32, - I64, - I128, - Int, - Integer, - Nat, - Natural, - Signed8, - Signed16, - Signed32, - Signed64, - Signed128, - U8, - U16, - U32, - U64, - U128, - Unsigned8, - Unsigned16, - Unsigned32, - Unsigned64, - Unsigned128, - abs, - acos, - add, - addChecked, - addWrap, - atan, - bitwiseAnd, - bitwiseOr, - bitwiseXor, - ceiling, - compare, - cos, - div, - divTrunc, - floor, - intCast, - isEven, - isGt, - isGte, - isLt, - isLte, - isMultipleOf, - isNegative, - isOdd, - isPositive, - isZero, - log, - logChecked, - maxFloat, - maxI8, - maxU8, - maxI16, - maxU16, - maxI32, - maxU32, - maxI64, - maxU64, - maxI128, - minFloat, - minI8, - minU8, - minI16, - minU16, - minI32, - minU32, - minI64, - minU64, - minI128, - mul, - mulChecked, - mulWrap, - neg, - pow, - powInt, - rem, - remChecked, - round, - shiftLeftBy, - shiftRightBy, - shiftRightZfBy, - sin, - sub, - subChecked, - subWrap, - sqrt, - sqrtChecked, - tan, - toI8, - toI8Checked, - toI16, - toI16Checked, - toI32, - toI32Checked, - toI64, - toI64Checked, - toI128, - toI128Checked, - toU8, - toU8Checked, - toU16, - toU16Checked, - toU32, - toU32Checked, - toU64, - toU64Checked, - toU128, - toU128Checked, - toNat, - toNatChecked, - toFloat, - toStr - ] - imports [] - -## ## Types - -## Represents a number that could be either an [Int] or a [Float]. -## -## This is useful for functions that can work on either, for example #Num.add, whose type is: -## -## ``` -## add : Num a, Num a -> Num a -## ``` -## -## The number 1.5 technically has the type `Num (Fraction *)`, so when you pass -## two of them to [Num.add], the answer you get is `3.0 : Num (Fraction *)`. -## -## Similarly, the number 0x1 (that is, the integer 1 in hexadecimal notation) -## technically has the type `Num (Integer *)`, so when you pass two of them to -## [Num.add], the answer you get is `2 : Num (Integer *)`. -## -## The type [`Float a`]([Float]) is defined to be an alias for `Num (Fraction a)`, -## so `3.0 : Num (Fraction *)` is the same value as `3.0 : Float *`. -## Similarly, the type [`Int a`](#Int) is defined to be an alias for -## `Num (Integer a)`, so `2 : Num (Integer *)` is the same value as -## `2 : Int *`. -## -## In this way, the [Num] type makes it possible to have `1 + 0x1` return -## `2 : Int *` and `1.5 + 1.5` return `3.0 : Frac`. -## -## ## Number Literals -## -## Number literals without decimal points (like `0`, `4` or `360`) -## have the type `Num *` at first, but usually end up taking on -## a more specific type based on how they're used. -## -## For example, in `(1 + List.len myList)`, the `1` has the type `Num *` at first, -## but because `List.len` returns a `Nat`, the `1` ends up changing from -## `Num *` to the more specific `Nat`, and the expression as a whole -## ends up having the type `Nat`. -## -## Sometimes number literals don't become more specific. For example, -## the `Num.toStr` function has the type `Num * -> Str`. This means that -## when calling `Num.toStr (5 + 6)`, the expression `(5 + 6)` -## still has the type `Num *`. When this happens, `Num *` defaults to -## being an [I64] - so this addition expression would overflow -## if either 5 or 6 were replaced with a number big enough to cause -## addition overflow on an [I64] value. -## -## If this default of [I64] is not big enough for your purposes, -## you can add an `i128` to the end of the number literal, like so: -## -## >>> Num.toStr 5_000_000_000i128 -## -## This `i128` suffix specifies that you want this number literal to be -## an [I128] instead of a `Num *`. All the other numeric types have -## suffixes just like `i128`; here are some other examples: -## -## * `215u8` is a `215` value of type [U8] -## * `76.4f32` is a `76.4` value of type [F32] -## * `123.45dec` is a `123.45` value of type [Dec] -## * `12345nat` is a `12345` value of type [Nat] -## -## In practice, these are rarely needed. It's most common to write -## number literals without any suffix. -Num a := a - -## A decimal number. -## -## [Dec] is the best default choice for representing base-10 decimal numbers -## like currency, because it is base-10 under the hood. In contrast, -## [F64] and [F32] are base-2 under the hood, which can lead to decimal -## precision loss even when doing addition and subtraction. For example, when -## using [F64], running 0.1 + 0.2 returns 0.3000000000000000444089209850062616169452667236328125, -## whereas when using [Dec], 0.1 + 0.2 returns 0.3. -## -## Under the hood, a [Dec] is an [I128], and operations on it perform -## [base-10 fixed-point arithmetic](https://en.wikipedia.org/wiki/Fixed-point_arithmetic) -## with 18 decimal places of precision. -## -## This means a [Dec] can represent whole numbers up to slightly over 170 -## quintillion, along with 18 decimal places. (To be precise, it can store -## numbers betwween `-170_141_183_460_469_231_731.687303715884105728` -## and `170_141_183_460_469_231_731.687303715884105727`.) Why 18 -## decimal places? It's the highest number of decimal places where you can still -## convert any [U64] to a [Dec] without losing information. -## -## There are some use cases where [F64] and [F32] can be better choices than [Dec] -## despite their precision issues. For example, in graphical applications they -## can be a better choice for representing coordinates because they take up -## less memory, certain relevant calculations run faster (see performance -## details, below), and decimal precision loss isn't as big a concern when -## dealing with screen coordinates as it is when dealing with currency. -## -## ## Performance -## -## [Dec] typically takes slightly less time than [F64] to perform addition and -## subtraction, but 10-20 times longer to perform multiplication and division. -## [sqrt] and trigonometry are massively slower with [Dec] than with [F64]. -Dec : Num (FloatingPoint Decimal) - -## A fixed-size number with a fractional component. -## -## Roc fractions come in two flavors: fixed-point base-10 and floating-point base-2. -## -## * [Dec] is a 128-bit [fixed-point](https://en.wikipedia.org/wiki/Fixed-point_arithmetic) base-10 number. It's a great default choice, especially when precision is important - for example when representing currency. With [Dec], 0.1 + 0.2 returns 0.3. -## * [F64] and [F32] are [floating-point](https://en.wikipedia.org/wiki/Floating-point_arithmetic) base-2 numbers. They sacrifice precision for lower memory usage and improved performance on some operations. This makes them a good fit for representing graphical coordinates. With [F64], 0.1 + 0.2 returns 0.3000000000000000444089209850062616169452667236328125. -## -## If you don't specify a type, Roc will default to using [Dec] because it's -## the least error-prone overall. For example, suppose you write this: -## -## wasItPrecise = 0.1 + 0.2 == 0.3 -## -## The value of `wasItPrecise` here will be `True`, because Roc uses [Dec] -## by default when there are no types specified. -## -## In contrast, suppose we use `f32` or `f64` for one of these numbers: -## -## wasItPrecise = 0.1f64 + 0.2 == 0.3 -## -## Here, `wasItPrecise` will be `False` because the entire calculation will have -## been done in a base-2 floating point calculation, which causes noticeable -## precision loss in this case. -## -## The floating-point numbers ([F32] and [F64]) also have three values which -## are not ordinary [finite numbers](https://en.wikipedia.org/wiki/Finite_number). -## They are: -## * ∞ ([infinity](https://en.wikipedia.org/wiki/Infinity)) -## * -∞ (negative infinity) -## * *NaN* ([not a number](https://en.wikipedia.org/wiki/NaN)) -## -## These values are different from ordinary numbers in that they only occur -## when a floating-point calculation encounters an error. For example: -## * Dividing a positive [F64] by `0.0` returns ∞. -## * Dividing a negative [F64] by `0.0` returns -∞. -## * Dividing a [F64] of `0.0` by `0.0` returns [*NaN*](Num.isNaN). -## -## These rules come from the [IEEE-754](https://en.wikipedia.org/wiki/IEEE_754) -## floating point standard. Because almost all modern processors are built to -## this standard, deviating from these rules has a significant performance -## cost! Since the most common reason to choose [F64] or [F32] over [Dec] is -## access to hardware-accelerated performance, Roc follows these rules exactly. -## -## There's no literal syntax for these error values, but you can check to see if -## you ended up with one of them by using [isNaN], [isFinite], and [isInfinite]. -## Whenever a function in this module could return one of these values, that -## possibility is noted in the function's documentation. -## -## ## Performance Notes -## -## On typical modern CPUs, performance is similar between [Dec], [F64], and [F32] -## for addition and subtraction. For example, [F32] and [F64] do addition using -## a single CPU floating-point addition instruction, which typically takes a -## few clock cycles to complete. In contrast, [Dec] does addition using a few -## CPU integer arithmetic instructions, each of which typically takes only one -## clock cycle to complete. Exact numbers will vary by CPU, but they should be -## similar overall. -## -## [Dec] is significantly slower for multiplication and division. It not only -## needs to do more arithmetic instructions than [F32] and [F64] do, but also -## those instructions typically take more clock cycles to complete. -## -## With [Num.sqrt] and trigonometry functions like [Num.cos], there is -## an even bigger performance difference. [F32] and [F64] can do these in a -## single instruction, whereas [Dec] needs entire custom procedures - which use -## loops and conditionals. If you need to do performance-critical trigonometry -## or square roots, either [F64] or [F32] is probably a better choice than the -## usual default choice of [Dec], despite the precision problems they bring. -Float range : Num (FloatingPoint range) - -## A fixed-size integer - that is, a number with no fractional component. -## -## Integers come in two flavors: signed and unsigned. Signed integers can be -## negative ("signed" refers to how they can incorporate a minus sign), -## whereas unsigned integers cannot be negative. -## -## Since integers have a fixed size, the size you choose determines both the -## range of numbers it can represent, and also how much memory it takes up. -## -## #U8 is an an example of an integer. It is an unsigned #Int that takes up 8 bits -## (aka 1 byte) in memory. The `U` is for Unsigned and the 8 is for 8 bits. -## Because it has 8 bits to work with, it can store 256 numbers (2^8), -## and because it is unsigned, its min value is 0. This means the 256 numbers -## it can store range from 0 to 255. -## -## #I8 is a signed integer that takes up 8 bits. The `I` is for Integer, since -## integers in mathematics are signed by default. Because it has 8 bits just -## like #U8, it can store 256 numbers (still 2^16), but because it is signed, -## the range is different. Its 256 numbers range from -128 to 127. -## -## Here are some other examples: -## -## * #U16 is like #U8, except it takes up 16 bytes in memory. It can store 65,536 numbers (2^16), ranging from 0 to 65,536. -## * #I16 is like #U16, except it is signed. It can still store the same 65,536 numbers (2^16), ranging from -32,768 to 32,767. -## -## This pattern continues up to #U128 and #I128. -## -## ## Performance notes -## -## In general, using smaller numeric sizes means your program will use less memory. -## However, if a mathematical operation results in an answer that is too big -## or too small to fit in the size available for that answer (which is typically -## the same size as the inputs), then you'll get an overflow error. -## -## As such, minimizing memory usage without causing overflows involves choosing -## number sizes based on your knowledge of what numbers you expect your program -## to encounter at runtime. -## -## Minimizing memory usage does not imply maximum runtime speed! -## CPUs are typically fastest at performing integer operations on integers that -## are the same size as that CPU's native machine word size. That means a 64-bit -## CPU is typically fastest at executing instructions on #U64 and #I64 values, -## whereas a 32-bit CPU is typically fastest on #U32 and #I32 values. -## -## Putting these factors together, here are some reasonable guidelines for optimizing performance through integer size choice: -## -## * Start by deciding if this integer should allow negative numbers, and choose signed or unsigned accordingly. -## * Next, think about the range of numbers you expect this number to hold. Choose the smallest size you will never expect to overflow, no matter the inputs your program receives. (Validating inputs for size, and presenting the user with an error if they are too big, can help guard against overflow.) -## * Finally, if a particular numeric calculation is running too slowly, you can try experimenting with other number sizes. This rarely makes a meaningful difference, but some processors can operate on different number sizes at different speeds. -Int range : Num (Integer range) - -## A signed 8-bit integer, ranging from -128 to 127 -I8 : Int Signed8 -U8 : Int Unsigned8 -I16 : Int Signed16 -U16 : Int Unsigned16 -I32 : Int Signed32 -U32 : Int Unsigned32 -I64 : Int Signed64 -U64 : Int Unsigned64 -I128 : Int Signed128 -U128 : Int Unsigned128 - -## A [natural number](https://en.wikipedia.org/wiki/Natural_number) represented -## as a 64-bit unsigned integer on 64-bit systems, a 32-bit unsigned integer -## on 32-bit systems, and so on. -## -## This system-specific size makes it useful for certain data structure -## functions like [List.len], because the number of elements many data strucures -## can hold is also system-specific. For example, the maximum number of elements -## a [List] can hold on a 64-bit system fits in a 64-bit unsigned integer, and -## on a 32-bit system it fits in 32-bit unsigned integer. This makes [Nat] a -## good fit for [List.len] regardless of system. -Nat : Num (Integer Natural) - -## A 64-bit signed integer. All number literals without decimal points are compatible with #Int values. -## -## >>> 1 -## -## >>> 0 -## -## You can optionally put underscores in your #Int literals. -## They have no effect on the number's value, but can make large numbers easier to read. -## -## >>> 1_000_000 -## -## Integers come in two flavors: *signed* and *unsigned*. -## -## * *Unsigned* integers can never be negative. The lowest value they can hold is zero. -## * *Signed* integers can be negative. -## -## Integers also come in different sizes. Choosing a size depends on your performance -## needs and the range of numbers you need to represent. At a high level, the -## general trade-offs are: -## -## * Larger integer sizes can represent a wider range of numbers. If you absolutely need to represent numbers in a certain range, make sure to pick an integer size that can hold them! -## * Smaller integer sizes take up less memory. This savings rarely matters in variables and function arguments, but the sizes of integers that you use in data structures can add up. This can also affect whether those data structures fit in [cache lines](https://en.wikipedia.org/wiki/CPU_cache#Cache_performance), which can be a performance bottleneck. -## * Certain CPUs work faster on some numeric sizes than others. If the CPU is taking too long to run numeric calculations, you may find a performance improvement by experimenting with numeric sizes that are larger than otherwise necessary. However, in practice, doing this typically degrades overall performance, so be careful to measure properly! -## -## Here are the different fixed size integer types: -## -## | Range | Type | Size | -## |--------------------------------------------------------|-------|----------| -## | ` -128` | [I8] | 1 Byte | -## | ` 127` | | | -## |--------------------------------------------------------|-------|----------| -## | ` 0` | [U8] | 1 Byte | -## | ` 255` | | | -## |--------------------------------------------------------|-------|----------| -## | ` -32_768` | [I16] | 2 Bytes | -## | ` 32_767` | | | -## |--------------------------------------------------------|-------|----------| -## | ` 0` | [U16] | 2 Bytes | -## | ` 65_535` | | | -## |--------------------------------------------------------|-------|----------| -## | ` -2_147_483_648` | [I32] | 4 Bytes | -## | ` 2_147_483_647` | | | -## |--------------------------------------------------------|-------|----------| -## | ` 0` | [U32] | 4 Bytes | -## | ` (over 4 billion) 4_294_967_295` | | | -## |--------------------------------------------------------|-------|----------| -## | ` -9_223_372_036_854_775_808` | [I64] | 8 Bytes | -## | ` 9_223_372_036_854_775_807` | | | -## |--------------------------------------------------------|-------|----------| -## | ` 0` | [U64] | 8 Bytes | -## | ` (over 18 quintillion) 18_446_744_073_709_551_615` | | | -## |--------------------------------------------------------|-------|----------| -## | `-170_141_183_460_469_231_731_687_303_715_884_105_728` | [I128]| 16 Bytes | -## | ` 170_141_183_460_469_231_731_687_303_715_884_105_727` | | | -## |--------------------------------------------------------|-------|----------| -## | ` (over 340 undecillion) 0` | [U128]| 16 Bytes | -## | ` 340_282_366_920_938_463_463_374_607_431_768_211_455` | | | -## -## Roc also has one variable-size integer type: [Nat]. The size of [Nat] is equal -## to the size of a memory address, which varies by system. For example, when -## compiling for a 64-bit system, [Nat] is the same as [U64]. When compiling for a -## 32-bit system, it's the same as [U32]. -## -## A common use for [Nat] is to store the length ("len" for short) of a -## collection like a [List]. 64-bit systems can represent longer -## lists in memory than 32-bit systems can, which is why the length of a list -## is represented as a [Nat] in Roc. -## -## If any operation would result in an [Int] that is either too big -## or too small to fit in that range (e.g. calling `Int.maxI32 + 1`), -## then the operation will *overflow*. When an overflow occurs, the program will crash. -## -## As such, it's very important to design your code not to exceed these bounds! -## If you need to do math outside these bounds, consider using a larger numeric size. -Int range : Num (Integer range) - -## Convert - -## Return a negative number when given a positive one, and vice versa. -## -## >>> Num.neg 5 -## -## >>> Num.neg -2.5 -## -## >>> Num.neg 0 -## -## >>> Num.neg 0.0 -## -## This is safe to use with any [Float], but it can cause overflow when used with certain #Int values. -## -## For example, calling #Num.neg on the lowest value of a signed integer (such as #Int.lowestI64 or #Int.lowestI32) will cause overflow. -## This is because, for any given size of signed integer (32-bit, 64-bit, etc.) its negated lowest value turns out to be 1 higher than -## the highest value it can represent. (For this reason, calling #Num.abs on the lowest signed value will also cause overflow.) -## -## Additionally, calling #Num.neg on any unsigned integer (such as any #U64 or #U32 value) other than zero will cause overflow. -## -## (It will never crash when given a [Float], however, because of how floating point numbers represent positive and negative numbers.) -neg : Num a -> Num a - -## Return the absolute value of the number. -## -## * For a positive number, returns the same number. -## * For a negative number, returns the same number except positive. -## * For zero, returns zero. -## -## >>> Num.abs 4 -## -## >>> Num.abs -2.5 -## -## >>> Num.abs 0 -## -## >>> Num.abs 0.0 -## -## This is safe to use with any [Float], but it can cause overflow when used with certain #Int values. -## -## For example, calling #Num.abs on the lowest value of a signed integer (such as #Int.lowestI64 or #Int.lowestI32) will cause overflow. -## This is because, for any given size of signed integer (32-bit, 64-bit, etc.) its negated lowest value turns out to be 1 higher than -## the highest value it can represent. (For this reason, calling #Num.neg on the lowest signed value will also cause overflow.) -## -## Calling this on an unsigned integer (like #U32 or #U64) never does anything. -abs : Num a -> Num a - -## Check - -## The same as using `== 0` on the number. -isZero : Num * -> Bool - -## Positive numbers are greater than 0. -isPositive : Num * -> Bool - -## Negative numbers are less than 0. -isNegative : Num * -> Bool - -## A number is even if dividing it by 2 gives a remainder of 0. -## -## Examples of even numbers: 0, 2, 4, 6, 8, -2, -4, -6, -8 -isEven : Num * -> Bool - -## A number is odd if dividing it by 2 gives a remainder of 1. -## -## Examples of odd numbers: 1, 3, 5, 7, -1, -3, -5, -7 -isOdd : Num * -> Bool - -## Arithmetic - -## Add two numbers of the same type. -## -## (To add an #Int and a [Float], first convert one so that they both have the same type. There are functions in the [`Frac`](/Frac) module that can convert both #Int to [Float] and the other way around.) -## -## `a + b` is shorthand for `Num.add a b`. -## -## >>> 5 + 7 -## -## >>> Num.add 5 7 -## -## `Num.add` can be convenient in pipelines. -## -## >>> Frac.pi -## >>> |> Num.add 1.0 -## -## If the answer to this operation can't fit in the return value (e.g. an -## [I8] answer that's higher than 127 or lower than -128), the result is an -## *overflow*. For [F64] and [F32], overflow results in an answer of either -## ∞ or -∞. For all other number types, overflow results in a panic. -add : Num a, Num a -> Num a - -## Add two numbers and check for overflow. -## -## This is the same as [Num.add] except if the operation overflows, instead of -## panicking or returning ∞ or -∞, it will return `Err Overflow`. -addChecked : Num a, Num a -> Result (Num a) [ Overflow ]* - -## Add two numbers, clamping on the maximum representable number rather than -## overflowing. -## -## This is the same as [Num.add] except for the saturating behavior if the -## addition is to overflow. -## For example, if `x : U8` is 200 and `y : U8` is 100, `addSaturated x y` will -## yield 255, the maximum value of a `U8`. -addSaturated : Num a, Num a -> Num a - -## Subtract two numbers of the same type. -## -## (To subtract an #Int and a [Float], first convert one so that they both have the same type. There are functions in the [`Frac`](/Frac) module that can convert both #Int to [Float] and the other way around.) -## -## `a - b` is shorthand for `Num.sub a b`. -## -## >>> 7 - 5 -## -## >>> Num.sub 7 5 -## -## `Num.sub` can be convenient in pipelines. -## -## >>> Frac.pi -## >>> |> Num.sub 2.0 -## -## If the answer to this operation can't fit in the return value (e.g. an -## [I8] answer that's higher than 127 or lower than -128), the result is an -## *overflow*. For [F64] and [F32], overflow results in an answer of either -## ∞ or -∞. For all other number types, overflow results in a panic. -sub : Num a, Num a -> Num a - -## Subtract two numbers and check for overflow. -## -## This is the same as [Num.sub] except if the operation overflows, instead of -## panicking or returning ∞ or -∞, it will return `Err Overflow`. -subChecked : Num a, Num a -> Result (Num a) [ Overflow ]* - -## Subtract two numbers, clamping on the minimum representable number rather -## than overflowing. -## -## This is the same as [Num.sub] except for the saturating behavior if the -## subtraction is to overflow. -## For example, if `x : U8` is 10 and `y : U8` is 20, `subSaturated x y` will -## yield 0, the minimum value of a `U8`. -subSaturated : Num a, Num a -> Num a - -## Multiply two numbers of the same type. -## -## (To multiply an #Int and a [Float], first convert one so that they both have the same type. There are functions in the [`Frac`](/Frac) module that can convert both #Int to [Float] and the other way around.) -## -## `a * b` is shorthand for `Num.mul a b`. -## -## >>> 5 * 7 -## -## >>> Num.mul 5 7 -## -## `Num.mul` can be convenient in pipelines. -## -## >>> Frac.pi -## >>> |> Num.mul 2.0 -## -## If the answer to this operation can't fit in the return value (e.g. an -## [I8] answer that's higher than 127 or lower than -128), the result is an -## *overflow*. For [F64] and [F32], overflow results in an answer of either -## ∞ or -∞. For all other number types, overflow results in a panic. -mul : Num a, Num a -> Num a - -## Multiply two numbers and check for overflow. -## -## This is the same as [Num.mul] except if the operation overflows, instead of -## panicking or returning ∞ or -∞, it will return `Err Overflow`. -mulCheckOverflow : Num a, Num a -> Result (Num a) [ Overflow ]* - -## Convert - -## Convert any [Int] to a specifically-sized [Int], without checking validity. -## These are unchecked bitwise operations, -## so if the source number is outside the target range, then these will -## effectively modulo-wrap around the target range to reach a valid value. -toI8 : Int * -> I8 -toI16 : Int * -> I16 -toI32 : Int * -> I32 -toI64 : Int * -> I64 -toI128 : Int * -> I128 -toU8 : Int * -> U8 -toU16 : Int * -> U16 -toU32 : Int * -> U32 -toU64 : Int * -> U64 -toU128 : Int * -> U128 - -## Convert a [Num] to a [F32]. If the given number can't be precisely represented in a [F32], -## there will be a loss of precision. -toF32 : Num * -> F32 - -## Convert a [Num] to a [F64]. If the given number can't be precisely represented in a [F64], -## there will be a loss of precision. -toF64 : Num * -> F64 - -## Convert any [Int] to a specifically-sized [Int], after checking validity. -## These are checked bitwise operations, -## so if the source number is outside the target range, then these will -## return `Err OutOfBounds`. -toI8Checked : Int * -> Result I8 [ OutOfBounds ]* -toI16Checked : Int * -> Result I16 [ OutOfBounds ]* -toI32Checked : Int * -> Result I32 [ OutOfBounds ]* -toI64Checked : Int * -> Result I64 [ OutOfBounds ]* -toI128Checked : Int * -> Result I128 [ OutOfBounds ]* -toU8Checked : Int * -> Result U8 [ OutOfBounds ]* -toU16Checked : Int * -> Result U16 [ OutOfBounds ]* -toU32Checked : Int * -> Result U32 [ OutOfBounds ]* -toU64Checked : Int * -> Result U64 [ OutOfBounds ]* -toU128Checked : Int * -> Result U128 [ OutOfBounds ]* - -toF32Checked : Num * -> Result F32 [ OutOfBounds ]* -toF64Checked : Num * -> Result F64 [ OutOfBounds ]* - -## Convert a number to a [Str]. -## -## This is the same as calling `Num.format {}` - so for more details on -## exact formatting, see [Num.format]. -## -## >>> Num.toStr 42 -## -## Only [Float] values will include a decimal point, and they will always include one. -## -## >>> Num.toStr 4.2 -## -## >>> Num.toStr 4.0 -## -## When this function is given a non-[finite](Num.isFinite) -## [F64] or [F32] value, the returned string will be `"NaN"`, `"∞"`, or `"-∞"`. -## -## To get strings in hexadecimal, octal, or binary format, use [Num.format]. -toStr : Num * -> Str - -## Convert a number into a [Str], formatted with the given options. -## -## Default options: -## * `base: Decimal` -## * `notation: Standard` -## * `decimalMark: HideForIntegers "."` -## * `decimalDigits: { min: 0, max: All }` -## * `minIntDigits: 1` -## * `wholeSep: { mark: ",", places: 3 }` -## -## ## Options -## -## -## ### decimalMark -## -## * `AlwaysShow` always shows the decimal mark, no matter what. -## * `HideForIntegers` hides the decimal mark if all the numbers after the decimal mark are 0. -## -## The [Str] included in either of these represents the mark itself. -## -## ### `decimalDigits -## -## With 0 decimal digits, the decimal mark will still be rendered if -## `decimalMark` is set to `AlwaysShow`. -## -## If `max` is less than `min`, then first the number will be truncated to `max` -## digits, and then zeroes will be added afterwards until it reaches `min` digits. -## -## >>> Num.format 1.23 { decPlaces: 0, decPointVis: AlwaysShow } -## -## ### minIntDigits -## -## If the integer portion of number is fewer than this many digits, zeroes will -## be added in front of it until there are at least `minWholeDigits` digits. -## -## If this is set to zero, then numbers less than 1 will begin with `"."` -## rather than `"0."`. -## -## ### wholeSep -## -## Examples: -## -## In some countries (e.g. USA and UK), a comma is used to separate thousands: -## >>> Num.format 1_000_000 { pf: Decimal, wholeSep: { mark: ",", places: 3 } } -## -## Sometimes when rendering bits, it's nice to group them into groups of 4: -## >>> Num.format 1_000_000 { pf: Binary, wholeSep: { mark: " ", places: 4 } } -## -## It's also common to render hexadecimal in groups of 2: -## >>> Num.format 1_000_000 { pf: Hexadecimal, wholeSep: { mark: " ", places: 2 } } -format : - Num *, - { - base ? [ Decimal, Hexadecimal, Octal, Binary ], - notation ? [ Standard, Scientific ], - decimalMark ? [ AlwaysShow Str, HideForIntegers ], - decimalDigits ? { min : U16, max : [ All, Trunc U16, Round U16, Floor U16, Ceil U16 ] }, - minWholeDigits ? U16, - wholeSep ? { mark : Str, places : U64 } - } - -> Str - -## Round off the given float to the nearest integer. -round : Float * -> Int * -ceil : Float * -> Int * -floor : Float * -> Int * -trunc : Float * -> Int * - -## Convert an #Int to a #Nat. If the given number doesn't fit in #Nat, it will be truncated. -## Since #Nat has a different maximum number depending on the system you're building -## for, this may give a different answer on different systems. -## -## For example, on a 32-bit system, [Num.maxNat] will return the same answer as -## #Num.maxU32. This means that calling `Num.toNat 9_000_000_000` on a 32-bit -## system will return #Num.maxU32 instead of 9 billion, because 9 billion is -## higher than #Num.maxU32 and will not fit in a #Nat on a 32-bit system. -## -## However, calling `Num.toNat 9_000_000_000` on a 64-bit system will return -## the #Nat value of 9_000_000_000. This is because on a 64-bit system, #Nat can -## hold up to #Num.maxU64, and 9_000_000_000 is lower than #Num.maxU64. -## -## To convert a [Float] to a #Nat, first call either #Num.round, #Num.ceil, or #Num.floor -## on it, then call this on the resulting #Int. -toNat : Int * -> Nat - -## Convert an #Int to an #I8. If the given number doesn't fit in #I8, it will be truncated. -## -## To convert a [Float] to an #I8, first call either #Num.round, #Num.ceil, or #Num.floor -## on it, then call this on the resulting #Int. -toI8 : Int * -> I8 -toI16 : Int * -> I16 -toI32 : Int * -> I32 -toI64 : Int * -> I64 -toI128 : Int * -> I128 - -## Convert an #Int to an #U8. If the given number doesn't fit in #U8, it will be truncated. -## Crashes if the given number is negative. -toU8 : Int * -> U8 -toU16 : Int * -> U16 -toU32 : Int * -> U32 -toU64 : Int * -> U64 -toU128 : Int * -> U128 - -## Convert a #Num to a #Dec. If the given number can't be precisely represented in a #Dec, -## there will be a loss of precision. -toDec : Num * -> Dec - -## Divide two integers, truncating the result towards zero. -## -## Division by zero is undefined in mathematics. As such, you should make -## sure never to pass zero as the denomaintor to this function! -## -## If zero does get passed as the denominator... -## -## * In a development build, you'll get an assertion failure. -## * In an optimized build, the function will return 0. -## -## `a // b` is shorthand for `Num.divTrunc a b`. -## -## >>> 5 // 7 -## -## >>> Num.divTrunc 5 7 -## -## >>> 8 // -3 -## -## >>> Num.divTrunc 8 -3 -## -## This is the same as the #// operator. -divTrunc : Int a, Int a -> Int a - -## Obtain the remainder (truncating modulo) from the division of two integers. -## -## `a % b` is shorthand for `Num.rem a b`. -## -## >>> 5 % 7 -## -## >>> Num.rem 5 7 -## -## >>> -8 % -3 -## -## >>> Num.rem -8 -3 -rem : Int a, Int a -> Int a - - -## Bitwise - -xor : Int a, Int a -> Int a - -and : Int a, Int a -> Int a - -not : Int a -> Int a - -## Limits - -## The lowest number that can be stored in a #Nat without underflowing its -## available memory and crashing. -## -## For reference, this is the number zero, because #Nat is -## [unsigned](https://en.wikipedia.org/wiki/Signed_number_representations), -## and zero is the lowest unsigned number. -## Unsigned numbers cannot be negative. -minNat : Nat - -## The highest number that can be stored in a #Nat without overflowing its -## available memory and crashing. -## -## Note that this number varies by systems. For example, when building for a -## 64-bit system, this will be equal to #Num.maxU64, but when building for a -## 32-bit system, this will be equal to #Num.maxU32. -maxNat : Nat - -## The lowest number that can be stored in an #I8 without underflowing its -## available memory and crashing. -## -## For reference, this number is `-128`. -## -## Note that the positive version of this number is larger than #Int.maxI8, -## which means if you call #Num.abs on #Int.minI8, it will overflow and crash! -minI8 : I8 - -## The highest number that can be stored in an #I8 without overflowing its -## available memory and crashing. -## -## For reference, this number is `127`. -## -## Note that this is smaller than the positive version of #Int.minI8, -## which means if you call #Num.abs on #Int.minI8, it will overflow and crash! -maxI8 : I8 - -## The lowest number that can be stored in a #U8 without underflowing its -## available memory and crashing. -## -## For reference, this number is zero, because #U8 is -## [unsigned](https://en.wikipedia.org/wiki/Signed_number_representations), -## and zero is the lowest unsigned number. -## Unsigned numbers cannot be negative. -minU8 : U8 - -## The highest number that can be stored in a #U8 without overflowing its -## available memory and crashing. -## -## For reference, this number is `255`. -maxU8 : U8 - -## The lowest number that can be stored in an #I16 without underflowing its -## available memory and crashing. -## -## For reference, this number is `-32_768`. -## -## Note that the positive version of this number is larger than #Int.maxI16, -## which means if you call #Num.abs on #Int.minI16, it will overflow and crash! -minI16 : I16 - -## The highest number that can be stored in an #I16 without overflowing its -## available memory and crashing. -## -## For reference, this number is `32_767`. -## -## Note that this is smaller than the positive version of #Int.minI16, -## which means if you call #Num.abs on #Int.minI16, it will overflow and crash! -maxI16 : I16 - -## The lowest number that can be stored in a #U16 without underflowing its -## available memory and crashing. -## -## For reference, this number is zero, because #U16 is -## [unsigned](https://en.wikipedia.org/wiki/Signed_number_representations), -## and zero is the lowest unsigned number. -## Unsigned numbers cannot be negative. -minU16 : U16 - -## The highest number that can be stored in a #U16 without overflowing its -## available memory and crashing. -## -## For reference, this number is `65_535`. -maxU16 : U16 - -## The lowest number that can be stored in an #I32 without underflowing its -## available memory and crashing. -## -## For reference, this number is `-2_147_483_648`. -## -## Note that the positive version of this number is larger than #Int.maxI32, -## which means if you call #Num.abs on #Int.minI32, it will overflow and crash! -minI32 : I32 - -## The highest number that can be stored in an #I32 without overflowing its -## available memory and crashing. -## -## For reference, this number is `2_147_483_647`, -## which is over 2 million. -## -## Note that this is smaller than the positive version of #Int.minI32, -## which means if you call #Num.abs on #Int.minI32, it will overflow and crash! -maxI32 : I32 - -## The lowest number that can be stored in a #U32 without underflowing its -## available memory and crashing. -## -## For reference, this number is zero, because #U32 is -## [unsigned](https://en.wikipedia.org/wiki/Signed_number_representations), -## and zero is the lowest unsigned number. -## Unsigned numbers cannot be negative. -minU32 : U32 - -## The highest number that can be stored in a #U32 without overflowing its -## available memory and crashing. -## -## For reference, this number is `4_294_967_295`, -## which is over 4 million. -maxU32 : U32 - -## The min number that can be stored in an #I64 without underflowing its -## available memory and crashing. -## -## For reference, this number is `-`. -## -## Note that the positive version of this number is larger than #Int.maxI64, -## which means if you call #Num.abs on #Int.minI64, it will overflow and crash! -minI64 : I64 - -## The highest number that can be stored in an #I64 without overflowing its -## available memory and crashing. -## -## For reference, this number is ``, -## which is over 2 million. -## -## Note that this is smaller than the positive version of #Int.minI64, -## which means if you call #Num.abs on #Int.minI64, it will overflow and crash! -maxI64 : I64 - -## The lowest number that can be stored in a #U64 without underflowing its -## available memory and crashing. -## -## For reference, this number is zero because #U64 is -## [unsigned](https://en.wikipedia.org/wiki/Signed_number_representations), -## and zero is the lowest unsigned number. Unsigned numbers cannot be negative. -minU64 : U64 - -## The highest number that can be stored in a #U64 without overflowing its -## available memory and crashing. -## -## For reference, this number is `18_446_744_073_709_551_615`, -## which is over 18 quintillion. -maxU64 : U64 - -## The lowest number that can be stored in an #I128 without underflowing its -## available memory and crashing. -## -## For reference, this number is `-170_141_183_460_469_231_731_687_303_715_884_105_728`. -## -## Note that the positive version of this number is larger than #Int.maxI128, -## which means if you call #Num.abs on #Int.minI128, it will overflow and crash! -minI128 : I128 - -## The highest number that can be stored in an #I128 without overflowing its -## available memory and crashing. -## -## For reference, this number is `170_141_183_460_469_231_731_687_303_715_884_105_727`, -## which is over 2 million. -## -## Note that this is smaller than the positive version of #Int.minI128, -## which means if you call #Num.abs on #Int.minI128, it will overflow and crash! -maxI128 : I128 - -## The lowest supported #F32 value you can have, which is approximately -1.8 × 10^308. -## -## If you go lower than this, your running Roc code will crash - so be careful not to! -minF32 : F32 - -## The highest supported #F32 value you can have, which is approximately 1.8 × 10^308. -## -## If you go higher than this, your running Roc code will crash - so be careful not to! -maxF32 : F32 - -## The lowest supported #F64 value you can have, which is approximately -1.8 × 10^308. -## -## If you go lower than this, your running Roc code will crash - so be careful not to! -minF64 : F64 - -## The highest supported #F64 value you can have, which is approximately 1.8 × 10^308. -## -## If you go higher than this, your running Roc code will crash - so be careful not to! -maxF64 : F64 - -## The lowest supported #Dec value you can have, -## which is precisely -170_141_183_460_469_231_731.687303715884105728. -## -## If you go lower than this, your running Roc code will crash - so be careful not to! -minDec : Dec - -## The highest supported #Dec value you can have, -## which is precisely 170_141_183_460_469_231_731.687303715884105727. -## -## If you go higher than this, your running Roc code will crash - so be careful not to! -maxDec : Dec - -## Constants - -## An approximation of e, specifically 2.718281828459045. -e : Float * - -## An approximation of pi, specifically 3.141592653589793. -pi : Float * - -## Trigonometry - -cos : Float a -> Float a - -acos : Float a -> Float a - -sin : Float a -> Float a - -asin : Float a -> Float a - -tan : Float a -> Float a - -atan : Float a -> Float a - -## Other Calculations (arithmetic?) - -## Divide one [Float] by another. -## -## `a / b` is shorthand for `Num.div a b`. -## -## [Division by zero is undefined in mathematics](https://en.wikipedia.org/wiki/Division_by_zero). -## As such, you should make sure never to pass zero as the denomaintor to this function! -## Calling [div] on a [Dec] denominator of zero will cause a panic. -## -## Calling [div] on [F32] and [F64] values follows these rules: -## * Dividing a positive [F64] or [F32] by zero returns ∞. -## * Dividing a negative [F64] or [F32] by zero returns -∞. -## * Dividing a zero [F64] or [F32] by zero returns [*NaN*](Num.isNaN). -## -## > These rules come from the [IEEE-754](https://en.wikipedia.org/wiki/IEEE_754) -## > floating point standard. Because almost all modern processors are built to -## > this standard, deviating from these rules has a significant performance -## > cost! Since the most common reason to choose [F64] or [F32] over [Dec] is -## > access to hardware-accelerated performance, Roc follows these rules exactly. -## -## To divide an [Int] and a [Float], first convert the [Int] to a [Float] using -## one of the functions in this module like [toDec]. -## -## >>> 5.0 / 7.0 -## -## >>> Num.div 5 7 -## -## `Num.div` can be convenient in pipelines. -## -## >>> Num.pi -## >>> |> Num.div 2.0 -div : Float a, Float a -> Float a - -## Raises a [Float] to the power of another [Float]. -## -## ` -## For an #Int alternative to this function, see #Num.raise. -pow : Float a, Float a -> Float a - -## Raises an integer to the power of another, by multiplying the integer by -## itself the given number of times. -## -## This process is known as [exponentiation by squaring](https://en.wikipedia.org/wiki/Exponentiation_by_squaring). -## -## For a [Float] alternative to this function, which supports negative exponents, -## see #Num.exp. -## -## >>> Num.exp 5 0 -## -## >>> Num.exp 5 1 -## -## >>> Num.exp 5 2 -## -## >>> Num.exp 5 6 -## -## ## Performance Notes -## -## Be careful! Even though this function takes only a #U8, it is very easy to -## overflow -expBySquaring : Int a, U8 -> Int a - -## Returns an approximation of the absolute value of a [Float]'s square root. -## -## The square root of a negative number is an irrational number, and [Float] only -## supports rational numbers. As such, you should make sure never to pass this -## function a negative number! Calling [sqrt] on a negative [Dec] will cause a panic. -## -## Calling [sqrt] on [F32] and [F64] values follows these rules: -## * Passing a negative [F64] or [F32] returns [*NaN*](Num.isNaN). -## * Passing [*NaN*](Num.isNaN) or -∞ also returns [*NaN*](Num.isNaN). -## * Passing ∞ returns ∞. -## -## > These rules come from the [IEEE-754](https://en.wikipedia.org/wiki/IEEE_754) -## > floating point standard. Because almost all modern processors are built to -## > this standard, deviating from these rules has a significant performance -## > cost! Since the most common reason to choose [F64] or [F32] over [Dec] is -## > access to hardware-accelerated performance, Roc follows these rules exactly. -## -## >>> Frac.sqrt 4.0 -## -## >>> Frac.sqrt 1.5 -## -## >>> Frac.sqrt 0.0 -## -## >>> Frac.sqrt -4.0f64 -## -## >>> Frac.sqrt -4.0dec -sqrt : Float a -> Float a - -## Bit shifts - -## [Logical bit shift](https://en.wikipedia.org/wiki/Bitwise_operation#Logical_shift) left. -## -## `a << b` is shorthand for `Num.shl a b`. -shl : Int a, Int a -> Int a - -## [Arithmetic bit shift](https://en.wikipedia.org/wiki/Bitwise_operation#Arithmetic_shift) left. -## -## This is called `shlWrap` because any bits shifted -## off the beginning of the number will be wrapped around to -## the end. (In contrast, [shl] replaces discarded bits with zeroes.) -shlWrap : Int a, Int a -> Int a - -## [Logical bit shift](https://en.wikipedia.org/wiki/Bitwise_operation#Logical_shift) right. -## -## `a >> b` is shorthand for `Num.shr a b`. -shr : Int a, Int a -> Int a - -## [Arithmetic bit shift](https://en.wikipedia.org/wiki/Bitwise_operation#Arithmetic_shift) right. -## -## This is called `shrWrap` because any bits shifted -## off the end of the number will be wrapped around to -## the beginning. (In contrast, [shr] replaces discarded bits with zeroes.) -shrWrap : Int a, Int a -> Int a - -## [Endianness](https://en.wikipedia.org/wiki/Endianness) -# Endi : [ Big, Little, Native ] - -## The `Endi` argument does not matter for [U8] and [I8], since they have -## only one byte. -# toBytes : Num *, Endi -> List U8 - -## when Num.parseBytes bytes Big is -## Ok { val: f64, rest } -> ... -## Err (ExpectedNum (Float Binary64)) -> ... -# parseBytes : List U8, Endi -> Result { val : Num a, rest : List U8 } [ ExpectedNum a ]* - -## when Num.fromBytes bytes Big is -## Ok f64 -> ... -## Err (ExpectedNum (Float Binary64)) -> ... -# fromBytes : List U8, Endi -> Result (Num a) [ ExpectedNum a ]* - -## Comparison - -## Returns `True` if the first number is less than the second. -## -## `a < b` is shorthand for `Num.isLt a b`. -## -## If either argument is [*NaN*](Num.isNaN), returns `False` no matter what. (*NaN* -## is [defined to be unordered](https://en.wikipedia.org/wiki/NaN#Comparison_with_NaN).) -## -## >>> 5 -## >>> |> Num.isLt 6 -isLt : Num a, Num a -> Bool - -## Returns `True` if the first number is less than or equal to the second. -## -## `a <= b` is shorthand for `Num.isLte a b`. -## -## If either argument is [*NaN*](Num.isNaN), returns `False` no matter what. (*NaN* -## is [defined to be unordered](https://en.wikipedia.org/wiki/NaN#Comparison_with_NaN).) -isLte : Num a, Num a -> Bool - -## Returns `True` if the first number is greater than the second. -## -## `a > b` is shorthand for `Num.isGt a b`. -## -## If either argument is [*NaN*](Num.isNaN), returns `False` no matter what. (*NaN* -## is [defined to be unordered](https://en.wikipedia.org/wiki/NaN#Comparison_with_NaN).) -## -## >>> 6 -## >>> |> Num.isGt 5 -isGt : Num a, Num a -> Bool - -## Returns `True` if the first number is greater than or equal to the second. -## -## `a >= b` is shorthand for `Num.isGte a b`. -## -## If either argument is [*NaN*](Num.isNaN), returns `False` no matter what. (*NaN* -## is [defined to be unordered](https://en.wikipedia.org/wiki/NaN#Comparison_with_NaN).) -isGte : Num a, Num a -> Bool - -## Returns the higher of two numbers. -## -## If either argument is [*NaN*](Num.isNaN), returns `False` no matter what. (*NaN* -## is [defined to be unordered](https://en.wikipedia.org/wiki/NaN#Comparison_with_NaN).) -higher : Num a, Num a -> Num a - -## Returns the lower of two numbers. -## -## If either argument is [*NaN*](Num.isNaN), returns `False` no matter what. (*NaN* -## is [defined to be unordered](https://en.wikipedia.org/wiki/NaN#Comparison_with_NaN).) -lower : Num a, Num a -> Num a - -# Branchless implementation that works for all numeric types: -# -# let is_lt = arg1 < arg2; -# let is_eq = arg1 == arg2; -# return (is_lt as i8 - is_eq as i8) + 1; -# -# 1, 1 -> (0 - 1) + 1 == 0 # Eq -# 5, 1 -> (0 - 0) + 1 == 1 # Gt -# 1, 5 -> (1 - 0) + 1 == 2 # Lt - -## Returns `Lt` if the first number is less than the second, `Gt` if -## the first is greater than the second, and `Eq` if they're equal. -## -## Although this can be passed to `List.sort`, you'll get better performance -## by using `List.sortAsc` or `List.sortDesc` instead. -compare : Num a, Num a -> [ Lt, Eq, Gt ] - -## Special Floating-Point Values - -## When given a [F64] or [F32] value, returns `False` if that value is -## [*NaN*](Num.isNaN), ∞ or -∞, and `True` otherwise. -## -## Always returns `True` when given a [Dec]. -## -## This is the opposite of [isInfinite], except when given [*NaN*](Num.isNaN). Both -## [isFinite] and [isInfinite] return `False` for [*NaN*](Num.isNaN). -isFinite : Float * -> Bool - -## When given a [F64] or [F32] value, returns `True` if that value is either -## ∞ or -∞, and `False` otherwise. -## -## Always returns `False` when given a [Dec]. -## -## This is the opposite of [isFinite], except when given [*NaN*](Num.isNaN). Both -## [isFinite] and [isInfinite] return `False` for [*NaN*](Num.isNaN). -isInfinite : Float * -> Bool - -## When given a [F64] or [F32] value, returns `True` if that value is -## *NaN* ([not a number](https://en.wikipedia.org/wiki/NaN)), and `False` otherwise. -## -## Always returns `False` when given a [Dec]. -## -## >>> Num.isNaN 12.3 -## -## >>> Num.isNaN (Num.pow -1 0.5) -## -## *NaN* is unusual from other numberic values in that: -## * *NaN* is not equal to any other number, even itself. [Bool.isEq] always returns `False` if either argument is *NaN*. -## * *NaN* has no ordering, so [isLt], [isLte], [isGt], and [isGte] always return `False` if either argument is *NaN*. -## -## These rules come from the [IEEE-754](https://en.wikipedia.org/wiki/IEEE_754) -## floating point standard. Because almost all modern processors are built to -## this standard, deviating from these rules has a significant performance -## cost! Since the most common reason to choose [F64] or [F32] over [Dec] is -## access to hardware-accelerated performance, Roc follows these rules exactly. -## -## Note that you should never put a *NaN* into a [Set], or use it as the key in -## a [Dict]. The result is entries that can never be removed from those -## collections! See the documentation for [Set.add] and [Dict.insert] for details. -isNaN : Float * -> Bool From b42af866bb9c036a2368f6949128a33b577873e9 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sun, 1 May 2022 21:02:01 -0400 Subject: [PATCH 730/846] Have REPL error use eprintln! over println! --- repl_cli/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repl_cli/src/lib.rs b/repl_cli/src/lib.rs index 155d3ffb81..40837ce8ac 100644 --- a/repl_cli/src/lib.rs +++ b/repl_cli/src/lib.rs @@ -443,7 +443,7 @@ pub fn main() -> io::Result<()> { break; } Err(err) => { - println!("Error: {:?}", err); + eprintln!("REPL error: {:?}", err); break; } } From 16fbaf14a1ce8e0976abd3d4d1d35aa0baa98d6d Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Mon, 2 May 2022 13:02:20 +0200 Subject: [PATCH 731/846] Earthly: copy over www folder --- Earthfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Earthfile b/Earthfile index 2d614d5bef..a8913c96ca 100644 --- a/Earthfile +++ b/Earthfile @@ -53,7 +53,7 @@ install-zig-llvm-valgrind-clippy-rustfmt: copy-dirs: FROM +install-zig-llvm-valgrind-clippy-rustfmt - COPY --dir cli cli_utils compiler docs editor ast code_markup error_macros highlight utils test_utils reporting repl_cli repl_eval repl_test repl_wasm roc_std vendor examples linker Cargo.toml Cargo.lock version.txt ./ + COPY --dir cli cli_utils compiler docs editor ast code_markup error_macros highlight utils test_utils reporting repl_cli repl_eval repl_test repl_wasm roc_std vendor examples linker Cargo.toml Cargo.lock version.txt www ./ test-zig: FROM +install-zig-llvm-valgrind-clippy-rustfmt From c0780aad923ac16f6b552bbd6e85e9f9377dce68 Mon Sep 17 00:00:00 2001 From: Jared Cone Date: Sun, 24 Apr 2022 14:42:02 -0700 Subject: [PATCH 732/846] Implemented unsigned int comparisons. --- compiler/gen_llvm/src/llvm/build.rs | 32 ++++++++++-- compiler/test_gen/src/gen_num.rs | 80 +++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+), 4 deletions(-) diff --git a/compiler/gen_llvm/src/llvm/build.rs b/compiler/gen_llvm/src/llvm/build.rs index 977bb228ba..3c5cf3494a 100644 --- a/compiler/gen_llvm/src/llvm/build.rs +++ b/compiler/gen_llvm/src/llvm/build.rs @@ -6667,10 +6667,34 @@ fn build_int_binop<'a, 'ctx, 'env>( &LLVM_MUL_WITH_OVERFLOW[int_width], &[lhs.into(), rhs.into()], ), - NumGt => bd.build_int_compare(SGT, lhs, rhs, "int_gt").into(), - NumGte => bd.build_int_compare(SGE, lhs, rhs, "int_gte").into(), - NumLt => bd.build_int_compare(SLT, lhs, rhs, "int_lt").into(), - NumLte => bd.build_int_compare(SLE, lhs, rhs, "int_lte").into(), + NumGt => { + if int_width.is_signed() { + bd.build_int_compare(SGT, lhs, rhs, "gt_int").into() + } else { + bd.build_int_compare(UGT, lhs, rhs, "gt_uint").into() + } + } + NumGte => { + if int_width.is_signed() { + bd.build_int_compare(SGE, lhs, rhs, "gte_int").into() + } else { + bd.build_int_compare(UGE, lhs, rhs, "gte_uint").into() + } + } + NumLt => { + if int_width.is_signed() { + bd.build_int_compare(SLT, lhs, rhs, "lt_int").into() + } else { + bd.build_int_compare(ULT, lhs, rhs, "lt_uint").into() + } + } + NumLte => { + if int_width.is_signed() { + bd.build_int_compare(SLE, lhs, rhs, "lte_int").into() + } else { + bd.build_int_compare(ULE, lhs, rhs, "lte_uint").into() + } + } NumRemUnchecked => { if int_width.is_signed() { bd.build_int_signed_rem(lhs, rhs, "rem_int").into() diff --git a/compiler/test_gen/src/gen_num.rs b/compiler/test_gen/src/gen_num.rs index 9e17b80111..7eb55da794 100644 --- a/compiler/test_gen/src/gen_num.rs +++ b/compiler/test_gen/src/gen_num.rs @@ -1210,6 +1210,86 @@ fn bitwise_or() { assert_evals_to!("Num.bitwiseOr 1 2", 3, i64); } +#[test] +#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] +fn lt_u8() { + assert_evals_to!("1u8 < 2u8", true, bool); + assert_evals_to!("1u8 < 1u8", false, bool); + assert_evals_to!("2u8 < 1u8", false, bool); + assert_evals_to!("0u8 < 0u8", false, bool); + assert_evals_to!("128u8 < 0u8", false, bool); +} + +#[test] +#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] +fn lte_u8() { + assert_evals_to!("1u8 <= 1u8", true, bool); + assert_evals_to!("2u8 <= 1u8", false, bool); + assert_evals_to!("1u8 <= 2u8", true, bool); + assert_evals_to!("0u8 <= 0u8", true, bool); + assert_evals_to!("128u8 <= 0u8", false, bool); +} + +#[test] +#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] +fn gt_u8() { + assert_evals_to!("2u8 > 1u8", true, bool); + assert_evals_to!("2u8 > 2u8", false, bool); + assert_evals_to!("1u8 > 1u8", false, bool); + assert_evals_to!("0u8 > 0u8", false, bool); + assert_evals_to!("0u8 > 128u8", false, bool); +} + +#[test] +#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] +fn gte_u8() { + assert_evals_to!("1u8 >= 1u8", true, bool); + assert_evals_to!("1u8 >= 2u8", false, bool); + assert_evals_to!("2u8 >= 1u8", true, bool); + assert_evals_to!("0u8 >= 0u8", true, bool); + assert_evals_to!("0u8 >= 128u8", false, bool); +} + +#[test] +#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] +fn lt_u64() { + assert_evals_to!("1u64 < 2u64", true, bool); + assert_evals_to!("1u64 < 1u64", false, bool); + assert_evals_to!("2u64 < 1u64", false, bool); + assert_evals_to!("0u64 < 0u64", false, bool); + assert_evals_to!("9223372036854775808u64 < 0u64", false, bool); +} + +#[test] +#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] +fn lte_u64() { + assert_evals_to!("1u64 <= 1u64", true, bool); + assert_evals_to!("2u64 <= 1u64", false, bool); + assert_evals_to!("1u64 <= 2u64", true, bool); + assert_evals_to!("0u64 <= 0u64", true, bool); + assert_evals_to!("9223372036854775808u64 <= 0u64", false, bool); +} + +#[test] +#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] +fn gt_u64() { + assert_evals_to!("2u64 > 1u64", true, bool); + assert_evals_to!("2u64 > 2u64", false, bool); + assert_evals_to!("1u64 > 1u64", false, bool); + assert_evals_to!("0u64 > 0u64", false, bool); + assert_evals_to!("0u64 > 9223372036854775808u64", false, bool); +} + +#[test] +#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] +fn gte_u64() { + assert_evals_to!("1u64 >= 1u64", true, bool); + assert_evals_to!("1u64 >= 2u64", false, bool); + assert_evals_to!("2u64 >= 1u64", true, bool); + assert_evals_to!("0u64 >= 0u64", true, bool); + assert_evals_to!("0u64 >= 9223372036854775808u64", false, bool); +} + #[test] #[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] fn lt_i64() { From 3263633575819924bdbb4a624d4b9f7831475960 Mon Sep 17 00:00:00 2001 From: Jared Cone Date: Sun, 24 Apr 2022 21:27:37 -0700 Subject: [PATCH 733/846] Changed list_take_last to compare list len to arg instead of different to zero. `List.takeLast [1,2] 5` was doing unsigned `2 - 5` which wraps to a large number unsigned. This was fine before `NumGt` was fixed to use unsigned compare for unsigned numbers. --- compiler/can/src/builtins.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/can/src/builtins.rs b/compiler/can/src/builtins.rs index d84646f4eb..4570a0c99d 100644 --- a/compiler/can/src/builtins.rs +++ b/compiler/can/src/builtins.rs @@ -2506,7 +2506,7 @@ fn list_take_last(symbol: Symbol, var_store: &mut VarStore) -> Def { let get_sub = RunLowLevel { op: LowLevel::NumSubWrap, - args: vec![(len_var, get_list_len), (len_var, Var(Symbol::ARG_2))], + args: vec![(len_var, get_list_len.clone()), (len_var, Var(Symbol::ARG_2))], ret_var: len_var, }; @@ -2516,7 +2516,7 @@ fn list_take_last(symbol: Symbol, var_store: &mut VarStore) -> Def { branches: vec![( no_region(RunLowLevel { op: LowLevel::NumGt, - args: vec![(len_var, get_sub.clone()), (len_var, zero.clone())], + args: vec![(len_var, get_list_len), (len_var, Var(Symbol::ARG_2))], ret_var: bool_var, }), no_region(get_sub), From 47f5b89b26bee6ff0b6b3f13402ee20d103136a8 Mon Sep 17 00:00:00 2001 From: Jared Cone Date: Sun, 24 Apr 2022 21:37:24 -0700 Subject: [PATCH 734/846] Fixed formatting --- compiler/can/src/builtins.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/compiler/can/src/builtins.rs b/compiler/can/src/builtins.rs index 4570a0c99d..9e66db45fa 100644 --- a/compiler/can/src/builtins.rs +++ b/compiler/can/src/builtins.rs @@ -2506,7 +2506,10 @@ fn list_take_last(symbol: Symbol, var_store: &mut VarStore) -> Def { let get_sub = RunLowLevel { op: LowLevel::NumSubWrap, - args: vec![(len_var, get_list_len.clone()), (len_var, Var(Symbol::ARG_2))], + args: vec![ + (len_var, get_list_len.clone()), + (len_var, Var(Symbol::ARG_2)), + ], ret_var: len_var, }; From c7459e9888a92faa785640137e427f839a6d5374 Mon Sep 17 00:00:00 2001 From: Jared Cone Date: Mon, 25 Apr 2022 18:00:10 -0700 Subject: [PATCH 735/846] Added support for unsigned gt/lt to wasm. Breaks some other tests, pushing now for sharing --- compiler/gen_wasm/src/low_level.rs | 58 +++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 8 deletions(-) diff --git a/compiler/gen_wasm/src/low_level.rs b/compiler/gen_wasm/src/low_level.rs index 367154caa5..46eae0729c 100644 --- a/compiler/gen_wasm/src/low_level.rs +++ b/compiler/gen_wasm/src/low_level.rs @@ -180,6 +180,16 @@ impl<'a> LowLevelCall<'a> { use CodeGenNumType::*; use LowLevel::*; + fn integer_symbol_is_signed(backend: &WasmBackend<'_>, symbol: Symbol) -> bool { + return match backend.storage.symbol_layouts[&symbol] { + Layout::Builtin(Builtin::Int(int_width)) => match int_width { + IntWidth::U8 | IntWidth::U16 | IntWidth::U32 | IntWidth::U64 | IntWidth::U128 => false, + IntWidth::I8 | IntWidth::I16 | IntWidth::I32 | IntWidth::I64 | IntWidth::I128 => true, + }, + _ => internal_error!("Expected integer, found {:?}", symbol), + }; + } + let panic_ret_type = || { internal_error!( "Invalid return layout for {:?}: {:?}", @@ -377,8 +387,16 @@ impl<'a> LowLevelCall<'a> { NumGt => { self.load_args(backend); match CodeGenNumType::for_symbol(backend, self.arguments[0]) { - I32 => backend.code_builder.i32_gt_s(), - I64 => backend.code_builder.i64_gt_s(), + I32 => if integer_symbol_is_signed(backend, self.arguments[0]) { + backend.code_builder.i32_gt_s() + } else { + backend.code_builder.i32_gt_u() + } + I64 => if integer_symbol_is_signed(backend, self.arguments[0]) { + backend.code_builder.i64_gt_s() + } else { + backend.code_builder.i64_gt_u() + } F32 => backend.code_builder.f32_gt(), F64 => backend.code_builder.f64_gt(), x => todo!("{:?} for {:?}", self.lowlevel, x), @@ -387,8 +405,16 @@ impl<'a> LowLevelCall<'a> { NumGte => { self.load_args(backend); match CodeGenNumType::for_symbol(backend, self.arguments[0]) { - I32 => backend.code_builder.i32_ge_s(), - I64 => backend.code_builder.i64_ge_s(), + I32 => if integer_symbol_is_signed(backend, self.arguments[0]) { + backend.code_builder.i32_ge_s() + } else { + backend.code_builder.i32_ge_u() + } + I64 => if integer_symbol_is_signed(backend, self.arguments[0]) { + backend.code_builder.i64_ge_s() + } else { + backend.code_builder.i64_ge_u() + } F32 => backend.code_builder.f32_ge(), F64 => backend.code_builder.f64_ge(), x => todo!("{:?} for {:?}", self.lowlevel, x), @@ -397,8 +423,16 @@ impl<'a> LowLevelCall<'a> { NumLt => { self.load_args(backend); match CodeGenNumType::for_symbol(backend, self.arguments[0]) { - I32 => backend.code_builder.i32_lt_s(), - I64 => backend.code_builder.i64_lt_s(), + I32 => if integer_symbol_is_signed(backend, self.arguments[0]) { + backend.code_builder.i32_lt_s() + } else { + backend.code_builder.i32_lt_u() + } + I64 => if integer_symbol_is_signed(backend, self.arguments[0]) { + backend.code_builder.i64_lt_s() + } else { + backend.code_builder.i64_lt_u() + } F32 => backend.code_builder.f32_lt(), F64 => backend.code_builder.f64_lt(), x => todo!("{:?} for {:?}", self.lowlevel, x), @@ -407,8 +441,16 @@ impl<'a> LowLevelCall<'a> { NumLte => { self.load_args(backend); match CodeGenNumType::for_symbol(backend, self.arguments[0]) { - I32 => backend.code_builder.i32_le_s(), - I64 => backend.code_builder.i64_le_s(), + I32 => if integer_symbol_is_signed(backend, self.arguments[0]) { + backend.code_builder.i32_le_s() + } else { + backend.code_builder.i32_le_u() + } + I64 => if integer_symbol_is_signed(backend, self.arguments[0]) { + backend.code_builder.i64_le_s() + } else { + backend.code_builder.i64_le_u() + } F32 => backend.code_builder.f32_le(), F64 => backend.code_builder.f64_le(), x => todo!("{:?} for {:?}", self.lowlevel, x), From 07b3c7471311be61e28a3a5dfde582f94d075457 Mon Sep 17 00:00:00 2001 From: Brian Carroll Date: Sat, 30 Apr 2022 17:39:19 +0100 Subject: [PATCH 736/846] Refactor for faster Rust compile times --- compiler/gen_wasm/src/low_level.rs | 97 +++++++++++++++++------------- 1 file changed, 55 insertions(+), 42 deletions(-) diff --git a/compiler/gen_wasm/src/low_level.rs b/compiler/gen_wasm/src/low_level.rs index 46eae0729c..9717882e64 100644 --- a/compiler/gen_wasm/src/low_level.rs +++ b/compiler/gen_wasm/src/low_level.rs @@ -116,6 +116,13 @@ impl From<&StoredValue> for CodeGenNumType { } } +fn integer_symbol_is_signed(backend: &WasmBackend<'_>, symbol: Symbol) -> bool { + return match backend.storage.symbol_layouts[&symbol] { + Layout::Builtin(Builtin::Int(int_width)) => int_width.is_signed(), + x => internal_error!("Expected integer, found {:?}", x), + }; +} + pub struct LowLevelCall<'a> { pub lowlevel: LowLevel, pub arguments: &'a [Symbol], @@ -180,16 +187,6 @@ impl<'a> LowLevelCall<'a> { use CodeGenNumType::*; use LowLevel::*; - fn integer_symbol_is_signed(backend: &WasmBackend<'_>, symbol: Symbol) -> bool { - return match backend.storage.symbol_layouts[&symbol] { - Layout::Builtin(Builtin::Int(int_width)) => match int_width { - IntWidth::U8 | IntWidth::U16 | IntWidth::U32 | IntWidth::U64 | IntWidth::U128 => false, - IntWidth::I8 | IntWidth::I16 | IntWidth::I32 | IntWidth::I64 | IntWidth::I128 => true, - }, - _ => internal_error!("Expected integer, found {:?}", symbol), - }; - } - let panic_ret_type = || { internal_error!( "Invalid return layout for {:?}: {:?}", @@ -387,15 +384,19 @@ impl<'a> LowLevelCall<'a> { NumGt => { self.load_args(backend); match CodeGenNumType::for_symbol(backend, self.arguments[0]) { - I32 => if integer_symbol_is_signed(backend, self.arguments[0]) { - backend.code_builder.i32_gt_s() - } else { - backend.code_builder.i32_gt_u() + I32 => { + if integer_symbol_is_signed(backend, self.arguments[0]) { + backend.code_builder.i32_gt_s() + } else { + backend.code_builder.i32_gt_u() + } } - I64 => if integer_symbol_is_signed(backend, self.arguments[0]) { - backend.code_builder.i64_gt_s() - } else { - backend.code_builder.i64_gt_u() + I64 => { + if integer_symbol_is_signed(backend, self.arguments[0]) { + backend.code_builder.i64_gt_s() + } else { + backend.code_builder.i64_gt_u() + } } F32 => backend.code_builder.f32_gt(), F64 => backend.code_builder.f64_gt(), @@ -405,15 +406,19 @@ impl<'a> LowLevelCall<'a> { NumGte => { self.load_args(backend); match CodeGenNumType::for_symbol(backend, self.arguments[0]) { - I32 => if integer_symbol_is_signed(backend, self.arguments[0]) { - backend.code_builder.i32_ge_s() - } else { - backend.code_builder.i32_ge_u() + I32 => { + if integer_symbol_is_signed(backend, self.arguments[0]) { + backend.code_builder.i32_ge_s() + } else { + backend.code_builder.i32_ge_u() + } } - I64 => if integer_symbol_is_signed(backend, self.arguments[0]) { - backend.code_builder.i64_ge_s() - } else { - backend.code_builder.i64_ge_u() + I64 => { + if integer_symbol_is_signed(backend, self.arguments[0]) { + backend.code_builder.i64_ge_s() + } else { + backend.code_builder.i64_ge_u() + } } F32 => backend.code_builder.f32_ge(), F64 => backend.code_builder.f64_ge(), @@ -423,15 +428,19 @@ impl<'a> LowLevelCall<'a> { NumLt => { self.load_args(backend); match CodeGenNumType::for_symbol(backend, self.arguments[0]) { - I32 => if integer_symbol_is_signed(backend, self.arguments[0]) { - backend.code_builder.i32_lt_s() - } else { - backend.code_builder.i32_lt_u() + I32 => { + if integer_symbol_is_signed(backend, self.arguments[0]) { + backend.code_builder.i32_lt_s() + } else { + backend.code_builder.i32_lt_u() + } } - I64 => if integer_symbol_is_signed(backend, self.arguments[0]) { - backend.code_builder.i64_lt_s() - } else { - backend.code_builder.i64_lt_u() + I64 => { + if integer_symbol_is_signed(backend, self.arguments[0]) { + backend.code_builder.i64_lt_s() + } else { + backend.code_builder.i64_lt_u() + } } F32 => backend.code_builder.f32_lt(), F64 => backend.code_builder.f64_lt(), @@ -441,15 +450,19 @@ impl<'a> LowLevelCall<'a> { NumLte => { self.load_args(backend); match CodeGenNumType::for_symbol(backend, self.arguments[0]) { - I32 => if integer_symbol_is_signed(backend, self.arguments[0]) { - backend.code_builder.i32_le_s() - } else { - backend.code_builder.i32_le_u() + I32 => { + if integer_symbol_is_signed(backend, self.arguments[0]) { + backend.code_builder.i32_le_s() + } else { + backend.code_builder.i32_le_u() + } } - I64 => if integer_symbol_is_signed(backend, self.arguments[0]) { - backend.code_builder.i64_le_s() - } else { - backend.code_builder.i64_le_u() + I64 => { + if integer_symbol_is_signed(backend, self.arguments[0]) { + backend.code_builder.i64_le_s() + } else { + backend.code_builder.i64_le_u() + } } F32 => backend.code_builder.f32_le(), F64 => backend.code_builder.f64_le(), From c27a15205948d4b5c3dce20dfdc4052ea2566bdc Mon Sep 17 00:00:00 2001 From: Brian Carroll Date: Sat, 30 Apr 2022 18:13:45 +0100 Subject: [PATCH 737/846] Fix confusion between isize and usize in mono code_gen_help --- compiler/mono/src/code_gen_help/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/mono/src/code_gen_help/mod.rs b/compiler/mono/src/code_gen_help/mod.rs index 7c5cb3eecc..e5799a571b 100644 --- a/compiler/mono/src/code_gen_help/mod.rs +++ b/compiler/mono/src/code_gen_help/mod.rs @@ -83,7 +83,7 @@ pub struct CodeGenHelp<'a> { impl<'a> CodeGenHelp<'a> { pub fn new(arena: &'a Bump, target_info: TargetInfo, home: ModuleId) -> Self { - let layout_isize = Layout::usize(target_info); + let layout_isize = Layout::isize(target_info); // Refcount is a boxed isize. TODO: use the new Box layout when dev backends support it let union_refcount = UnionLayout::NonNullableUnwrapped(arena.alloc([layout_isize])); From bea87d4168b01925953e2ad4b93e3ba948efdb68 Mon Sep 17 00:00:00 2001 From: Jared Cone Date: Mon, 2 May 2022 04:53:44 -0700 Subject: [PATCH 738/846] Files generated by test --- compiler/test_mono/generated/factorial.txt | 8 +-- compiler/test_mono/generated/has_none.txt | 50 +++++++++---------- compiler/test_mono/generated/ir_int_add.txt | 4 +- compiler/test_mono/generated/ir_plus.txt | 4 +- compiler/test_mono/generated/ir_round.txt | 4 +- compiler/test_mono/generated/ir_two_defs.txt | 4 +- compiler/test_mono/generated/ir_when_idiv.txt | 18 +++---- compiler/test_mono/generated/ir_when_just.txt | 4 +- compiler/test_mono/generated/is_nil.txt | 30 +++++------ ...cialize_errors_behind_unified_branches.txt | 20 ++++---- compiler/test_mono/generated/issue_2810.txt | 10 ++-- .../generated/linked_list_length_twice.txt | 40 +++++++-------- .../generated/list_cannot_update_inplace.txt | 4 +- compiler/test_mono/generated/list_len.txt | 4 +- .../generated/monomorphized_ints_aliased.txt | 4 +- .../generated/nested_pattern_match.txt | 4 +- .../test_mono/generated/optional_when.txt | 4 +- compiler/test_mono/generated/peano.txt | 8 +-- compiler/test_mono/generated/peano1.txt | 24 ++++----- compiler/test_mono/generated/peano2.txt | 44 ++++++++-------- .../test_mono/generated/quicksort_help.txt | 12 ++--- ...optional_field_function_no_use_default.txt | 4 +- ...rd_optional_field_function_use_default.txt | 4 +- ...cord_optional_field_let_no_use_default.txt | 4 +- .../record_optional_field_let_use_default.txt | 4 +- .../generated/somehow_drops_definitions.txt | 8 +-- .../generated/specialize_ability_call.txt | 10 ++-- .../generated/specialize_closures.txt | 8 +-- .../generated/specialize_lowlevel.txt | 8 +-- .../test_mono/generated/when_nested_maybe.txt | 4 +- .../test_mono/generated/when_on_record.txt | 4 +- .../generated/when_on_two_values.txt | 4 +- 32 files changed, 183 insertions(+), 183 deletions(-) diff --git a/compiler/test_mono/generated/factorial.txt b/compiler/test_mono/generated/factorial.txt index 449fcd3072..a0ad7c91ac 100644 --- a/compiler/test_mono/generated/factorial.txt +++ b/compiler/test_mono/generated/factorial.txt @@ -1,10 +1,10 @@ procedure Num.20 (#Attr.2, #Attr.3): - let Num.229 : I64 = lowlevel NumSub #Attr.2 #Attr.3; - ret Num.229; + let Num.274 : I64 = lowlevel NumSub #Attr.2 #Attr.3; + ret Num.274; procedure Num.21 (#Attr.2, #Attr.3): - let Num.228 : I64 = lowlevel NumMul #Attr.2 #Attr.3; - ret Num.228; + let Num.273 : I64 = lowlevel NumMul #Attr.2 #Attr.3; + ret Num.273; procedure Test.1 (Test.15, Test.16): joinpoint Test.7 Test.2 Test.3: diff --git a/compiler/test_mono/generated/has_none.txt b/compiler/test_mono/generated/has_none.txt index 19a2c3d273..05a4158eab 100644 --- a/compiler/test_mono/generated/has_none.txt +++ b/compiler/test_mono/generated/has_none.txt @@ -1,30 +1,30 @@ -procedure Test.3 (Test.29): - joinpoint Test.13 Test.4: - let Test.23 : Int1 = 1i64; - let Test.24 : Int1 = GetTagId Test.4; - let Test.25 : Int1 = lowlevel Eq Test.23 Test.24; - if Test.25 then - let Test.14 : Int1 = false; - ret Test.14; +procedure Test.4 (Test.30): + joinpoint Test.14 Test.5: + let Test.24 : Int1 = 1i64; + let Test.25 : Int1 = GetTagId Test.5; + let Test.26 : Int1 = lowlevel Eq Test.24 Test.25; + if Test.26 then + let Test.15 : Int1 = false; + ret Test.15; else - let Test.19 : [C I64, C ] = UnionAtIndex (Id 0) (Index 0) Test.4; - let Test.20 : U8 = 1i64; - let Test.21 : U8 = GetTagId Test.19; - let Test.22 : Int1 = lowlevel Eq Test.20 Test.21; - if Test.22 then - let Test.15 : Int1 = true; - ret Test.15; + let Test.20 : [C I64, C ] = UnionAtIndex (Id 0) (Index 0) Test.5; + let Test.21 : U8 = 1i64; + let Test.22 : U8 = GetTagId Test.20; + let Test.23 : Int1 = lowlevel Eq Test.21 Test.22; + if Test.23 then + let Test.16 : Int1 = true; + ret Test.16; else - let Test.7 : [, C [C I64, C ] *self] = UnionAtIndex (Id 0) (Index 1) Test.4; - jump Test.13 Test.7; + let Test.8 : [, C [C I64, C ] *self] = UnionAtIndex (Id 0) (Index 1) Test.5; + jump Test.14 Test.8; in - jump Test.13 Test.29; + jump Test.14 Test.30; procedure Test.0 (): - let Test.28 : I64 = 3i64; - let Test.26 : [C I64, C ] = Just Test.28; - let Test.27 : [, C [C I64, C ] *self] = Nil ; - let Test.12 : [, C [C I64, C ] *self] = Cons Test.26 Test.27; - let Test.11 : Int1 = CallByName Test.3 Test.12; - dec Test.12; - ret Test.11; + let Test.29 : I64 = 3i64; + let Test.27 : [C I64, C ] = Just Test.29; + let Test.28 : [, C [C I64, C ] *self] = Nil ; + let Test.13 : [, C [C I64, C ] *self] = Cons Test.27 Test.28; + let Test.12 : Int1 = CallByName Test.4 Test.13; + dec Test.13; + ret Test.12; diff --git a/compiler/test_mono/generated/ir_int_add.txt b/compiler/test_mono/generated/ir_int_add.txt index 76ed6d9e5d..5343090dd9 100644 --- a/compiler/test_mono/generated/ir_int_add.txt +++ b/compiler/test_mono/generated/ir_int_add.txt @@ -3,8 +3,8 @@ procedure List.6 (#Attr.2): ret List.139; procedure Num.19 (#Attr.2, #Attr.3): - let Num.230 : U64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Num.230; + let Num.275 : U64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.275; procedure Test.0 (): let Test.8 : U64 = 5i64; diff --git a/compiler/test_mono/generated/ir_plus.txt b/compiler/test_mono/generated/ir_plus.txt index 141f90d4a3..8a3eff1485 100644 --- a/compiler/test_mono/generated/ir_plus.txt +++ b/compiler/test_mono/generated/ir_plus.txt @@ -1,6 +1,6 @@ procedure Num.19 (#Attr.2, #Attr.3): - let Num.228 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Num.228; + let Num.273 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.273; procedure Test.0 (): let Test.2 : I64 = 1i64; diff --git a/compiler/test_mono/generated/ir_round.txt b/compiler/test_mono/generated/ir_round.txt index 6686a4e849..19f78559ec 100644 --- a/compiler/test_mono/generated/ir_round.txt +++ b/compiler/test_mono/generated/ir_round.txt @@ -1,6 +1,6 @@ procedure Num.45 (#Attr.2): - let Num.228 : I64 = lowlevel NumRound #Attr.2; - ret Num.228; + let Num.273 : I64 = lowlevel NumRound #Attr.2; + ret Num.273; procedure Test.0 (): let Test.2 : Float64 = 3.6f64; diff --git a/compiler/test_mono/generated/ir_two_defs.txt b/compiler/test_mono/generated/ir_two_defs.txt index a27db2c903..d99d01140c 100644 --- a/compiler/test_mono/generated/ir_two_defs.txt +++ b/compiler/test_mono/generated/ir_two_defs.txt @@ -1,6 +1,6 @@ procedure Num.19 (#Attr.2, #Attr.3): - let Num.228 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Num.228; + let Num.273 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.273; procedure Test.0 (): let Test.4 : I64 = 3i64; diff --git a/compiler/test_mono/generated/ir_when_idiv.txt b/compiler/test_mono/generated/ir_when_idiv.txt index b1fb84e522..a4c3915acf 100644 --- a/compiler/test_mono/generated/ir_when_idiv.txt +++ b/compiler/test_mono/generated/ir_when_idiv.txt @@ -1,14 +1,14 @@ procedure Num.40 (#Attr.2, #Attr.3): - let Num.233 : I64 = 0i64; - let Num.230 : Int1 = lowlevel NotEq #Attr.3 Num.233; - if Num.230 then - let Num.232 : I64 = lowlevel NumDivUnchecked #Attr.2 #Attr.3; - let Num.231 : [C {}, C I64] = Ok Num.232; - ret Num.231; + let Num.278 : I64 = 0i64; + let Num.275 : Int1 = lowlevel NotEq #Attr.3 Num.278; + if Num.275 then + let Num.277 : I64 = lowlevel NumDivUnchecked #Attr.2 #Attr.3; + let Num.276 : [C {}, C I64] = Ok Num.277; + ret Num.276; else - let Num.229 : {} = Struct {}; - let Num.228 : [C {}, C I64] = Err Num.229; - ret Num.228; + let Num.274 : {} = Struct {}; + let Num.273 : [C {}, C I64] = Err Num.274; + ret Num.273; procedure Test.0 (): let Test.8 : I64 = 1000i64; diff --git a/compiler/test_mono/generated/ir_when_just.txt b/compiler/test_mono/generated/ir_when_just.txt index e11182583b..d6619036ab 100644 --- a/compiler/test_mono/generated/ir_when_just.txt +++ b/compiler/test_mono/generated/ir_when_just.txt @@ -1,6 +1,6 @@ procedure Num.19 (#Attr.2, #Attr.3): - let Num.228 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Num.228; + let Num.273 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.273; procedure Test.0 (): let Test.10 : I64 = 41i64; diff --git a/compiler/test_mono/generated/is_nil.txt b/compiler/test_mono/generated/is_nil.txt index c12eed1f71..9b47d797ca 100644 --- a/compiler/test_mono/generated/is_nil.txt +++ b/compiler/test_mono/generated/is_nil.txt @@ -1,18 +1,18 @@ -procedure Test.2 (Test.3): - let Test.12 : Int1 = 1i64; - let Test.13 : Int1 = GetTagId Test.3; - let Test.14 : Int1 = lowlevel Eq Test.12 Test.13; - if Test.14 then - let Test.10 : Int1 = true; - ret Test.10; - else - let Test.11 : Int1 = false; +procedure Test.3 (Test.4): + let Test.13 : Int1 = 1i64; + let Test.14 : Int1 = GetTagId Test.4; + let Test.15 : Int1 = lowlevel Eq Test.13 Test.14; + if Test.15 then + let Test.11 : Int1 = true; ret Test.11; + else + let Test.12 : Int1 = false; + ret Test.12; procedure Test.0 (): - let Test.15 : I64 = 2i64; - let Test.16 : [, C I64 *self] = Nil ; - let Test.9 : [, C I64 *self] = Cons Test.15 Test.16; - let Test.8 : Int1 = CallByName Test.2 Test.9; - dec Test.9; - ret Test.8; + let Test.16 : I64 = 2i64; + let Test.17 : [, C I64 *self] = Nil ; + let Test.10 : [, C I64 *self] = Cons Test.16 Test.17; + let Test.9 : Int1 = CallByName Test.3 Test.10; + dec Test.10; + ret Test.9; diff --git a/compiler/test_mono/generated/issue_2583_specialize_errors_behind_unified_branches.txt b/compiler/test_mono/generated/issue_2583_specialize_errors_behind_unified_branches.txt index 95aed66add..ac2eaef4f3 100644 --- a/compiler/test_mono/generated/issue_2583_specialize_errors_behind_unified_branches.txt +++ b/compiler/test_mono/generated/issue_2583_specialize_errors_behind_unified_branches.txt @@ -14,17 +14,17 @@ procedure List.9 (#Attr.2): procedure Str.27 (#Attr.2): let #Attr.3 : {I64, U8} = lowlevel StrToNum #Attr.2; - let Str.69 : U8 = StructAtIndex 1 #Attr.3; - let Str.70 : U8 = 0i64; - let Str.66 : Int1 = lowlevel NumGt Str.69 Str.70; - if Str.66 then - let Str.68 : Int1 = false; - let Str.67 : [C Int1, C I64] = Err Str.68; - ret Str.67; + let Str.70 : U8 = StructAtIndex 1 #Attr.3; + let Str.71 : U8 = 0i64; + let Str.67 : Int1 = lowlevel NumGt Str.70 Str.71; + if Str.67 then + let Str.69 : Int1 = false; + let Str.68 : [C Int1, C I64] = Err Str.69; + ret Str.68; else - let Str.65 : I64 = StructAtIndex 0 #Attr.3; - let Str.64 : [C Int1, C I64] = Ok Str.65; - ret Str.64; + let Str.66 : I64 = StructAtIndex 0 #Attr.3; + let Str.65 : [C Int1, C I64] = Ok Str.66; + ret Str.65; procedure Test.0 (): let Test.4 : Int1 = true; diff --git a/compiler/test_mono/generated/issue_2810.txt b/compiler/test_mono/generated/issue_2810.txt index 60660e287c..31f6b7125e 100644 --- a/compiler/test_mono/generated/issue_2810.txt +++ b/compiler/test_mono/generated/issue_2810.txt @@ -1,6 +1,6 @@ procedure Test.0 (): - let Test.16 : [C [C [C *self, C ]], C ] = SystemTool ; - let Test.14 : [C [C *self, C ]] = Job Test.16; - let Test.13 : [C [C [C *self, C ]], C ] = FromJob Test.14; - let Test.4 : [C [C *self, C ]] = Job Test.13; - ret Test.4; + let Test.19 : [C [C [C *self, C ]], C ] = SystemTool ; + let Test.17 : [C [C *self, C ]] = Job Test.19; + let Test.16 : [C [C [C *self, C ]], C ] = FromJob Test.17; + let Test.7 : [C [C *self, C ]] = Job Test.16; + ret Test.7; diff --git a/compiler/test_mono/generated/linked_list_length_twice.txt b/compiler/test_mono/generated/linked_list_length_twice.txt index 4d99868290..dbed7f9abb 100644 --- a/compiler/test_mono/generated/linked_list_length_twice.txt +++ b/compiler/test_mono/generated/linked_list_length_twice.txt @@ -1,25 +1,25 @@ procedure Num.19 (#Attr.2, #Attr.3): - let Num.229 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Num.229; + let Num.274 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.274; -procedure Test.3 (Test.5): - let Test.15 : Int1 = 1i64; - let Test.16 : Int1 = GetTagId Test.5; - let Test.17 : Int1 = lowlevel Eq Test.15 Test.16; - if Test.17 then - let Test.11 : I64 = 0i64; - ret Test.11; - else - let Test.6 : [, C I64 *self] = UnionAtIndex (Id 0) (Index 1) Test.5; - let Test.13 : I64 = 1i64; - let Test.14 : I64 = CallByName Test.3 Test.6; - let Test.12 : I64 = CallByName Num.19 Test.13 Test.14; +procedure Test.4 (Test.6): + let Test.16 : Int1 = 1i64; + let Test.17 : Int1 = GetTagId Test.6; + let Test.18 : Int1 = lowlevel Eq Test.16 Test.17; + if Test.18 then + let Test.12 : I64 = 0i64; ret Test.12; + else + let Test.7 : [, C I64 *self] = UnionAtIndex (Id 0) (Index 1) Test.6; + let Test.14 : I64 = 1i64; + let Test.15 : I64 = CallByName Test.4 Test.7; + let Test.13 : I64 = CallByName Num.19 Test.14 Test.15; + ret Test.13; procedure Test.0 (): - let Test.2 : [, C I64 *self] = Nil ; - let Test.8 : I64 = CallByName Test.3 Test.2; - let Test.9 : I64 = CallByName Test.3 Test.2; - dec Test.2; - let Test.7 : I64 = CallByName Num.19 Test.8 Test.9; - ret Test.7; + let Test.3 : [, C I64 *self] = Nil ; + let Test.9 : I64 = CallByName Test.4 Test.3; + let Test.10 : I64 = CallByName Test.4 Test.3; + dec Test.3; + let Test.8 : I64 = CallByName Num.19 Test.9 Test.10; + ret Test.8; diff --git a/compiler/test_mono/generated/list_cannot_update_inplace.txt b/compiler/test_mono/generated/list_cannot_update_inplace.txt index fd3a3616e8..d2d0968169 100644 --- a/compiler/test_mono/generated/list_cannot_update_inplace.txt +++ b/compiler/test_mono/generated/list_cannot_update_inplace.txt @@ -20,8 +20,8 @@ procedure List.6 (#Attr.2): ret List.140; procedure Num.19 (#Attr.2, #Attr.3): - let Num.228 : U64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Num.228; + let Num.273 : U64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.273; procedure Test.1 (): let Test.8 : List I64 = Array [1i64, 2i64, 3i64]; diff --git a/compiler/test_mono/generated/list_len.txt b/compiler/test_mono/generated/list_len.txt index 9735510540..b3c1b27a5b 100644 --- a/compiler/test_mono/generated/list_len.txt +++ b/compiler/test_mono/generated/list_len.txt @@ -7,8 +7,8 @@ procedure List.6 (#Attr.2): ret List.140; procedure Num.19 (#Attr.2, #Attr.3): - let Num.228 : U64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Num.228; + let Num.273 : U64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.273; procedure Test.0 (): let Test.7 : List I64 = Array [1i64, 2i64, 3i64]; diff --git a/compiler/test_mono/generated/monomorphized_ints_aliased.txt b/compiler/test_mono/generated/monomorphized_ints_aliased.txt index f65562e3fd..d9433bf0af 100644 --- a/compiler/test_mono/generated/monomorphized_ints_aliased.txt +++ b/compiler/test_mono/generated/monomorphized_ints_aliased.txt @@ -1,6 +1,6 @@ procedure Num.19 (#Attr.2, #Attr.3): - let Num.228 : U64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Num.228; + let Num.273 : U64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.273; procedure Test.5 (Test.7, Test.8): let Test.17 : U64 = 1i64; diff --git a/compiler/test_mono/generated/nested_pattern_match.txt b/compiler/test_mono/generated/nested_pattern_match.txt index 061f72e7c9..272fa01449 100644 --- a/compiler/test_mono/generated/nested_pattern_match.txt +++ b/compiler/test_mono/generated/nested_pattern_match.txt @@ -1,6 +1,6 @@ procedure Num.19 (#Attr.2, #Attr.3): - let Num.228 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Num.228; + let Num.273 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.273; procedure Test.0 (): let Test.19 : I64 = 41i64; diff --git a/compiler/test_mono/generated/optional_when.txt b/compiler/test_mono/generated/optional_when.txt index 25ab447db4..7eaa7288b5 100644 --- a/compiler/test_mono/generated/optional_when.txt +++ b/compiler/test_mono/generated/optional_when.txt @@ -1,6 +1,6 @@ procedure Num.21 (#Attr.2, #Attr.3): - let Num.230 : I64 = lowlevel NumMul #Attr.2 #Attr.3; - ret Num.230; + let Num.275 : I64 = lowlevel NumMul #Attr.2 #Attr.3; + ret Num.275; procedure Test.1 (Test.6): let Test.21 : Int1 = false; diff --git a/compiler/test_mono/generated/peano.txt b/compiler/test_mono/generated/peano.txt index 88f73530ed..8b7370a838 100644 --- a/compiler/test_mono/generated/peano.txt +++ b/compiler/test_mono/generated/peano.txt @@ -1,6 +1,6 @@ procedure Test.0 (): - let Test.10 : [, C *self] = Z ; + let Test.11 : [, C *self] = Z ; + let Test.10 : [, C *self] = S Test.11; let Test.9 : [, C *self] = S Test.10; - let Test.8 : [, C *self] = S Test.9; - let Test.2 : [, C *self] = S Test.8; - ret Test.2; + let Test.3 : [, C *self] = S Test.9; + ret Test.3; diff --git a/compiler/test_mono/generated/peano1.txt b/compiler/test_mono/generated/peano1.txt index 2c0ab5219e..63db968efc 100644 --- a/compiler/test_mono/generated/peano1.txt +++ b/compiler/test_mono/generated/peano1.txt @@ -1,15 +1,15 @@ procedure Test.0 (): - let Test.14 : [, C *self] = Z ; + let Test.15 : [, C *self] = Z ; + let Test.14 : [, C *self] = S Test.15; let Test.13 : [, C *self] = S Test.14; - let Test.12 : [, C *self] = S Test.13; - let Test.2 : [, C *self] = S Test.12; - let Test.9 : Int1 = 1i64; - let Test.10 : Int1 = GetTagId Test.2; - dec Test.2; - let Test.11 : Int1 = lowlevel Eq Test.9 Test.10; - if Test.11 then - let Test.7 : I64 = 0i64; - ret Test.7; - else - let Test.8 : I64 = 1i64; + let Test.3 : [, C *self] = S Test.13; + let Test.10 : Int1 = 1i64; + let Test.11 : Int1 = GetTagId Test.3; + dec Test.3; + let Test.12 : Int1 = lowlevel Eq Test.10 Test.11; + if Test.12 then + let Test.8 : I64 = 0i64; ret Test.8; + else + let Test.9 : I64 = 1i64; + ret Test.9; diff --git a/compiler/test_mono/generated/peano2.txt b/compiler/test_mono/generated/peano2.txt index 466d098896..73dd42687a 100644 --- a/compiler/test_mono/generated/peano2.txt +++ b/compiler/test_mono/generated/peano2.txt @@ -1,26 +1,26 @@ procedure Test.0 (): - let Test.20 : [, C *self] = Z ; + let Test.21 : [, C *self] = Z ; + let Test.20 : [, C *self] = S Test.21; let Test.19 : [, C *self] = S Test.20; - let Test.18 : [, C *self] = S Test.19; - let Test.2 : [, C *self] = S Test.18; - let Test.15 : Int1 = 0i64; - let Test.16 : Int1 = GetTagId Test.2; - let Test.17 : Int1 = lowlevel Eq Test.15 Test.16; - if Test.17 then - let Test.11 : [, C *self] = UnionAtIndex (Id 0) (Index 0) Test.2; - inc Test.11; - dec Test.2; - let Test.12 : Int1 = 0i64; - let Test.13 : Int1 = GetTagId Test.11; - dec Test.11; - let Test.14 : Int1 = lowlevel Eq Test.12 Test.13; - if Test.14 then - let Test.7 : I64 = 1i64; - ret Test.7; - else - let Test.8 : I64 = 0i64; + let Test.3 : [, C *self] = S Test.19; + let Test.16 : Int1 = 0i64; + let Test.17 : Int1 = GetTagId Test.3; + let Test.18 : Int1 = lowlevel Eq Test.16 Test.17; + if Test.18 then + let Test.12 : [, C *self] = UnionAtIndex (Id 0) (Index 0) Test.3; + inc Test.12; + dec Test.3; + let Test.13 : Int1 = 0i64; + let Test.14 : Int1 = GetTagId Test.12; + dec Test.12; + let Test.15 : Int1 = lowlevel Eq Test.13 Test.14; + if Test.15 then + let Test.8 : I64 = 1i64; ret Test.8; + else + let Test.9 : I64 = 0i64; + ret Test.9; else - dec Test.2; - let Test.9 : I64 = 0i64; - ret Test.9; + dec Test.3; + let Test.10 : I64 = 0i64; + ret Test.10; diff --git a/compiler/test_mono/generated/quicksort_help.txt b/compiler/test_mono/generated/quicksort_help.txt index 1c286140e4..2c00aa804b 100644 --- a/compiler/test_mono/generated/quicksort_help.txt +++ b/compiler/test_mono/generated/quicksort_help.txt @@ -1,14 +1,14 @@ procedure Num.19 (#Attr.2, #Attr.3): - let Num.228 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Num.228; + let Num.273 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.273; procedure Num.20 (#Attr.2, #Attr.3): - let Num.229 : I64 = lowlevel NumSub #Attr.2 #Attr.3; - ret Num.229; + let Num.274 : I64 = lowlevel NumSub #Attr.2 #Attr.3; + ret Num.274; procedure Num.22 (#Attr.2, #Attr.3): - let Num.230 : Int1 = lowlevel NumLt #Attr.2 #Attr.3; - ret Num.230; + let Num.275 : Int1 = lowlevel NumLt #Attr.2 #Attr.3; + ret Num.275; procedure Test.1 (Test.24, Test.25, Test.26): joinpoint Test.12 Test.2 Test.3 Test.4: diff --git a/compiler/test_mono/generated/record_optional_field_function_no_use_default.txt b/compiler/test_mono/generated/record_optional_field_function_no_use_default.txt index 355268a33e..82db9ad2db 100644 --- a/compiler/test_mono/generated/record_optional_field_function_no_use_default.txt +++ b/compiler/test_mono/generated/record_optional_field_function_no_use_default.txt @@ -1,6 +1,6 @@ procedure Num.19 (#Attr.2, #Attr.3): - let Num.228 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Num.228; + let Num.273 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.273; procedure Test.1 (Test.4): let Test.2 : I64 = StructAtIndex 0 Test.4; diff --git a/compiler/test_mono/generated/record_optional_field_function_use_default.txt b/compiler/test_mono/generated/record_optional_field_function_use_default.txt index fce1b7a406..6adb8079f7 100644 --- a/compiler/test_mono/generated/record_optional_field_function_use_default.txt +++ b/compiler/test_mono/generated/record_optional_field_function_use_default.txt @@ -1,6 +1,6 @@ procedure Num.19 (#Attr.2, #Attr.3): - let Num.228 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Num.228; + let Num.273 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.273; procedure Test.1 (Test.4): let Test.8 : I64 = 10i64; diff --git a/compiler/test_mono/generated/record_optional_field_let_no_use_default.txt b/compiler/test_mono/generated/record_optional_field_let_no_use_default.txt index 864862eaef..959902f6d8 100644 --- a/compiler/test_mono/generated/record_optional_field_let_no_use_default.txt +++ b/compiler/test_mono/generated/record_optional_field_let_no_use_default.txt @@ -1,6 +1,6 @@ procedure Num.19 (#Attr.2, #Attr.3): - let Num.228 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Num.228; + let Num.273 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.273; procedure Test.1 (Test.2): let Test.3 : I64 = StructAtIndex 0 Test.2; diff --git a/compiler/test_mono/generated/record_optional_field_let_use_default.txt b/compiler/test_mono/generated/record_optional_field_let_use_default.txt index e8bf95b3e4..aad801aab9 100644 --- a/compiler/test_mono/generated/record_optional_field_let_use_default.txt +++ b/compiler/test_mono/generated/record_optional_field_let_use_default.txt @@ -1,6 +1,6 @@ procedure Num.19 (#Attr.2, #Attr.3): - let Num.228 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Num.228; + let Num.273 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.273; procedure Test.1 (Test.2): let Test.3 : I64 = 10i64; diff --git a/compiler/test_mono/generated/somehow_drops_definitions.txt b/compiler/test_mono/generated/somehow_drops_definitions.txt index 8e5dc13493..1ac4ec978e 100644 --- a/compiler/test_mono/generated/somehow_drops_definitions.txt +++ b/compiler/test_mono/generated/somehow_drops_definitions.txt @@ -1,10 +1,10 @@ procedure Num.19 (#Attr.2, #Attr.3): - let Num.229 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Num.229; + let Num.274 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.274; procedure Num.21 (#Attr.2, #Attr.3): - let Num.228 : I64 = lowlevel NumMul #Attr.2 #Attr.3; - ret Num.228; + let Num.273 : I64 = lowlevel NumMul #Attr.2 #Attr.3; + ret Num.273; procedure Test.1 (): let Test.26 : I64 = 1i64; diff --git a/compiler/test_mono/generated/specialize_ability_call.txt b/compiler/test_mono/generated/specialize_ability_call.txt index 7f4932ff35..ebc12cb8bf 100644 --- a/compiler/test_mono/generated/specialize_ability_call.txt +++ b/compiler/test_mono/generated/specialize_ability_call.txt @@ -1,7 +1,7 @@ -procedure Test.5 (Test.7): - ret Test.7; +procedure Test.7 (Test.9): + ret Test.9; procedure Test.0 (): - let Test.9 : U64 = 1234i64; - let Test.8 : U64 = CallByName Test.5 Test.9; - ret Test.8; + let Test.11 : U64 = 1234i64; + let Test.10 : U64 = CallByName Test.7 Test.11; + ret Test.10; diff --git a/compiler/test_mono/generated/specialize_closures.txt b/compiler/test_mono/generated/specialize_closures.txt index 65fbdf1102..251e80285d 100644 --- a/compiler/test_mono/generated/specialize_closures.txt +++ b/compiler/test_mono/generated/specialize_closures.txt @@ -1,10 +1,10 @@ procedure Num.19 (#Attr.2, #Attr.3): - let Num.229 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Num.229; + let Num.274 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.274; procedure Num.21 (#Attr.2, #Attr.3): - let Num.228 : I64 = lowlevel NumMul #Attr.2 #Attr.3; - ret Num.228; + let Num.273 : I64 = lowlevel NumMul #Attr.2 #Attr.3; + ret Num.273; procedure Test.1 (Test.2, Test.3): let Test.17 : U8 = GetTagId Test.2; diff --git a/compiler/test_mono/generated/specialize_lowlevel.txt b/compiler/test_mono/generated/specialize_lowlevel.txt index b6ede4db71..74bc5c3bbb 100644 --- a/compiler/test_mono/generated/specialize_lowlevel.txt +++ b/compiler/test_mono/generated/specialize_lowlevel.txt @@ -1,10 +1,10 @@ procedure Num.19 (#Attr.2, #Attr.3): - let Num.229 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Num.229; + let Num.274 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.274; procedure Num.21 (#Attr.2, #Attr.3): - let Num.228 : I64 = lowlevel NumMul #Attr.2 #Attr.3; - ret Num.228; + let Num.273 : I64 = lowlevel NumMul #Attr.2 #Attr.3; + ret Num.273; procedure Test.6 (Test.8, #Attr.12): let Test.4 : I64 = UnionAtIndex (Id 0) (Index 0) #Attr.12; diff --git a/compiler/test_mono/generated/when_nested_maybe.txt b/compiler/test_mono/generated/when_nested_maybe.txt index 061f72e7c9..272fa01449 100644 --- a/compiler/test_mono/generated/when_nested_maybe.txt +++ b/compiler/test_mono/generated/when_nested_maybe.txt @@ -1,6 +1,6 @@ procedure Num.19 (#Attr.2, #Attr.3): - let Num.228 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Num.228; + let Num.273 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.273; procedure Test.0 (): let Test.19 : I64 = 41i64; diff --git a/compiler/test_mono/generated/when_on_record.txt b/compiler/test_mono/generated/when_on_record.txt index 9dcef9aa67..71fec29389 100644 --- a/compiler/test_mono/generated/when_on_record.txt +++ b/compiler/test_mono/generated/when_on_record.txt @@ -1,6 +1,6 @@ procedure Num.19 (#Attr.2, #Attr.3): - let Num.228 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Num.228; + let Num.273 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.273; procedure Test.0 (): let Test.5 : I64 = 2i64; diff --git a/compiler/test_mono/generated/when_on_two_values.txt b/compiler/test_mono/generated/when_on_two_values.txt index c9866b76f4..f3d84fff9e 100644 --- a/compiler/test_mono/generated/when_on_two_values.txt +++ b/compiler/test_mono/generated/when_on_two_values.txt @@ -1,6 +1,6 @@ procedure Num.19 (#Attr.2, #Attr.3): - let Num.228 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; - ret Num.228; + let Num.273 : I64 = lowlevel NumAdd #Attr.2 #Attr.3; + ret Num.273; procedure Test.0 (): let Test.15 : I64 = 3i64; From 1142377b427d8cbaf1763e4c1e9f86fb7e08b2c4 Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Mon, 2 May 2022 14:12:55 +0200 Subject: [PATCH 739/846] fixed removal panic --- test_utils/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs index f5e00b7817..754f10d18f 100644 --- a/test_utils/src/lib.rs +++ b/test_utils/src/lib.rs @@ -43,6 +43,6 @@ impl TmpDir { impl Drop for TmpDir { fn drop(&mut self) { - remove_dir_all::remove_dir_all(&self.path).unwrap(); + let _ = remove_dir_all::remove_dir_all(&self.path); } } From ced9fdec3a9cc6611f2d52c52caeec5af69a222e Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Mon, 2 May 2022 15:34:00 +0200 Subject: [PATCH 740/846] also copy over repl_wasm --- Earthfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Earthfile b/Earthfile index a8913c96ca..325825050d 100644 --- a/Earthfile +++ b/Earthfile @@ -10,6 +10,7 @@ install-other-libs: RUN apt -y install libxcb-shape0-dev libxcb-xfixes0-dev # for editor clipboard RUN apt -y install libasound2-dev # for editor sounds RUN apt -y install libunwind-dev pkg-config libx11-dev zlib1g-dev + RUN apt -y install unzip # for www/build.sh install-zig-llvm-valgrind-clippy-rustfmt: FROM +install-other-libs @@ -53,7 +54,7 @@ install-zig-llvm-valgrind-clippy-rustfmt: copy-dirs: FROM +install-zig-llvm-valgrind-clippy-rustfmt - COPY --dir cli cli_utils compiler docs editor ast code_markup error_macros highlight utils test_utils reporting repl_cli repl_eval repl_test repl_wasm roc_std vendor examples linker Cargo.toml Cargo.lock version.txt www ./ + COPY --dir cli cli_utils compiler docs editor ast code_markup error_macros highlight utils test_utils reporting repl_cli repl_eval repl_test repl_wasm repl_www roc_std vendor examples linker Cargo.toml Cargo.lock version.txt www ./ test-zig: FROM +install-zig-llvm-valgrind-clippy-rustfmt From f0d52ea70da2394a67e930f6cfcab08a81afa759 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sun, 1 May 2022 23:16:33 -0400 Subject: [PATCH 741/846] Incorporate docs/Bool.roc into roc/Bool.roc --- compiler/builtins/docs/Bool.roc | 89 --------------------------------- compiler/builtins/roc/Bool.roc | 70 ++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 89 deletions(-) delete mode 100644 compiler/builtins/docs/Bool.roc diff --git a/compiler/builtins/docs/Bool.roc b/compiler/builtins/docs/Bool.roc deleted file mode 100644 index 5ac3f4e394..0000000000 --- a/compiler/builtins/docs/Bool.roc +++ /dev/null @@ -1,89 +0,0 @@ -interface Bool - exposes [ and, isEq, isNotEq, not, or, xor ] - imports [] - -## Returns `False` when given `True`, and vice versa. -not : [True, False] -> [True, False] - -## Returns `True` when given `True` and `True`, and `False` when either argument is `False`. -## -## `a && b` is shorthand for `Bool.and a b` -## -## >>> True && True -## -## >>> True && False -## -## >>> False && True -## -## >>> False && False -## -## ## Performance Notes -## -## In some languages, `&&` and `||` are special-cased in the compiler to skip -## evaluating the expression after the operator under certain circumstances. -## For example, in some languages, `enablePets && likesDogs user` would compile -## to the equivalent of: -## -## if enablePets then -## likesDogs user -## else -## False -## -## In Roc, however, `&&` and `||` are not special. They work the same way as -## other functions. Conditionals like `if` and `when` have a performance cost, -## and sometimes calling a function like `likesDogs user` can be faster across -## the board than doing an `if` to decide whether to skip calling it. -## -## (Naturally, if you expect the `if` to improve performance, you can always add -## one explicitly!) -and : Bool, Bool -> Bool - - -## Returns `True` when given `True` for either argument, and `False` only when given `False` and `False`. -## -## `a || b` is shorthand for `Bool.or a b`. -## -## >>> True || True -## -## >>> True || False -## -## >>> False || True -## -## >>> False || False -## -## ## Performance Notes -## -## In some languages, `&&` and `||` are special-cased in the compiler to skip -## evaluating the expression after the operator under certain circumstances. -## In Roc, this is not the case. See the performance notes for [Bool.and] for details. -or : Bool, Bool -> Bool - -## Exclusive or -xor : Bool, Bool -> Bool - -# TODO: removed `'` from signature because parser does not support it yet -# Original signature: `isEq : 'val, 'val -> Bool` -## Returns `True` if the two values are *structurally equal*, and `False` otherwise. -## -## `a == b` is shorthand for `Bool.isEq a b` -## -## Structural equality works as follows: -## -## 1. Tags are equal if they have the same tag name, and also their contents (if any) are equal. -## 2. Records are equal if all their fields are equal. -## 3. Collections ([Str], [List], [Dict], and [Set]) are equal if they are the same length, and also all their corresponding elements are equal. -## 4. [Num] values are equal if their numbers are equal, with one exception: if both arguments to `isEq` are *NaN*, then `isEq` returns `False`. See `Num.isNaN` for more about *NaN*. -## -## Note that `isEq` takes `'val` instead of `val`, which means `isEq` does not -## accept arguments whose types contain functions. -isEq : val, val -> Bool - -# TODO: removed `'` from signature because parser does not support it yet -# Original signature: `isNotEq : 'val, 'val -> Bool` -## Calls [isEq] on the given values, then calls [not] on the result. -## -## `a != b` is shorthand for `Bool.isNotEq a b` -## -## Note that `isNotEq` takes `'val` instead of `val`, which means `isNotEq` does not -## accept arguments whose types contain functions. -isNotEq : val, val -> Bool diff --git a/compiler/builtins/roc/Bool.roc b/compiler/builtins/roc/Bool.roc index 6853cdc5cc..dc6a15bdd8 100644 --- a/compiler/builtins/roc/Bool.roc +++ b/compiler/builtins/roc/Bool.roc @@ -4,11 +4,81 @@ interface Bool Bool : [ True, False ] +## Returns `True` when given `True` and `True`, and `False` when either argument is `False`. +## +## `a && b` is shorthand for `Bool.and a b` +## +## >>> True && True +## +## >>> True && False +## +## >>> False && True +## +## >>> False && False +## +## ## Performance Notes +## +## In some languages, `&&` and `||` are special-cased in the compiler to skip +## evaluating the expression after the operator under certain circumstances. +## For example, in some languages, `enablePets && likesDogs user` would compile +## to the equivalent of: +## +## if enablePets then +## likesDogs user +## else +## False +## +## In Roc, however, `&&` and `||` are not special. They work the same way as +## other functions. Conditionals like `if` and `when` have a performance cost, +## and sometimes calling a function like `likesDogs user` can be faster across +## the board than doing an `if` to decide whether to skip calling it. +## +## (Naturally, if you expect the `if` to improve performance, you can always add +## one explicitly!) and : Bool, Bool -> Bool + +## Returns `True` when given `True` for either argument, and `False` only when given `False` and `False`. +## +## `a || b` is shorthand for `Bool.or a b`. +## +## >>> True || True +## +## >>> True || False +## +## >>> False || True +## +## >>> False || False +## +## ## Performance Notes +## +## In some languages, `&&` and `||` are special-cased in the compiler to skip +## evaluating the expression after the operator under certain circumstances. +## In Roc, this is not the case. See the performance notes for [Bool.and] for details. or : Bool, Bool -> Bool # xor : Bool, Bool -> Bool # currently unimplemented +## Returns `False` when given `True`, and vice versa. not : Bool -> Bool +## Returns `True` if the two values are *structurally equal*, and `False` otherwise. +## +## `a == b` is shorthand for `Bool.isEq a b` +## +## Structural equality works as follows: +## +## 1. Tags are equal if they have the same tag name, and also their contents (if any) are equal. +## 2. Records are equal if all their fields are equal. +## 3. Collections ([Str], [List], [Dict], and [Set]) are equal if they are the same length, and also all their corresponding elements are equal. +## 4. [Num] values are equal if their numbers are equal, with one exception: if both arguments to `isEq` are *NaN*, then `isEq` returns `False`. See `Num.isNaN` for more about *NaN*. +## +## Note that `isEq` takes `'val` instead of `val`, which means `isEq` does not +## accept arguments whose types contain functions. isEq : a, a -> Bool + +## Calls [isEq] on the given values, then calls [not] on the result. +## +## `a != b` is shorthand for `Bool.isNotEq a b` +## +## Note that `isNotEq` takes `'val` instead of `val`, which means `isNotEq` does not +## accept arguments whose types contain functions. isNotEq : a, a -> Bool From ca965c8eacf2842c69ed2e52dbdb3f536aa24033 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 2 May 2022 09:47:41 -0400 Subject: [PATCH 742/846] Fix some autolinks in Num docs --- compiler/builtins/roc/Num.roc | 38 +++++++++++++++++------------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/compiler/builtins/roc/Num.roc b/compiler/builtins/roc/Num.roc index 204ed9502a..e4d69cbf93 100644 --- a/compiler/builtins/roc/Num.roc +++ b/compiler/builtins/roc/Num.roc @@ -173,7 +173,7 @@ interface Num ## technically has the type `Num (Integer *)`, so when you pass two of them to ## [Num.add], the answer you get is `2 : Num (Integer *)`. ## -## The type [`Float a`]([Float]) is defined to be an alias for `Num (Fraction a)`, +## The type [`Float a`](#Float) is defined to be an alias for `Num (Fraction a)`, ## so `3.0 : Num (Fraction *)` is the same value as `3.0 : Float *`. ## Similarly, the type [`Int a`](#Int) is defined to be an alias for ## `Num (Integer a)`, so `2 : Num (Integer *)` is the same value as @@ -228,23 +228,23 @@ Num range := range ## Since integers have a fixed size, the size you choose determines both the ## range of numbers it can represent, and also how much memory it takes up. ## -## #U8 is an an example of an integer. It is an unsigned #Int that takes up 8 bits +## [U8] is an an example of an integer. It is an unsigned [Int] that takes up 8 bits ## (aka 1 byte) in memory. The `U` is for Unsigned and the 8 is for 8 bits. ## Because it has 8 bits to work with, it can store 256 numbers (2^8), ## and because it is unsigned, its min value is 0. This means the 256 numbers ## it can store range from 0 to 255. ## -## #I8 is a signed integer that takes up 8 bits. The `I` is for Integer, since +## [I8] is a signed integer that takes up 8 bits. The `I` is for Integer, since ## integers in mathematics are signed by default. Because it has 8 bits just -## like #U8, it can store 256 numbers (still 2^16), but because it is signed, +## like [U8], it can store 256 numbers (still 2^16), but because it is signed, ## the range is different. Its 256 numbers range from -128 to 127. ## ## Here are some other examples: ## -## * #U16 is like #U8, except it takes up 16 bytes in memory. It can store 65,536 numbers (2^16), ranging from 0 to 65,536. -## * #I16 is like #U16, except it is signed. It can still store the same 65,536 numbers (2^16), ranging from -32,768 to 32,767. +## * [U16] is like [U8], except it takes up 16 bytes in memory. It can store 65,536 numbers (2^16), ranging from 0 to 65,536. +## * [I16] is like [U16], except it is signed. It can still store the same 65,536 numbers (2^16), ranging from -32,768 to 32,767. ## -## This pattern continues up to #U128 and #I128. +## This pattern continues up to [U128] and [I128]. ## ## ## Performance notes ## @@ -260,8 +260,8 @@ Num range := range ## Minimizing memory usage does not imply maximum runtime speed! ## CPUs are typically fastest at performing integer operations on integers that ## are the same size as that CPU's native machine word size. That means a 64-bit -## CPU is typically fastest at executing instructions on #U64 and #I64 values, -## whereas a 32-bit CPU is typically fastest on #U32 and #I32 values. +## CPU is typically fastest at executing instructions on [U64] and [I64] values, +## whereas a 32-bit CPU is typically fastest on [U32] and [I32] values. ## ## Putting these factors together, here are some reasonable guidelines for optimizing performance through integer size choice: ## @@ -269,13 +269,13 @@ Num range := range ## * Next, think about the range of numbers you expect this number to hold. Choose the smallest size you will never expect to overflow, no matter the inputs your program receives. (Validating inputs for size, and presenting the user with an error if they are too big, can help guard against overflow.) ## * Finally, if a particular numeric calculation is running too slowly, you can try experimenting with other number sizes. This rarely makes a meaningful difference, but some processors can operate on different number sizes at different speeds. ## -## All number literals without decimal points are compatible with #Int values. +## All number literals without decimal points are compatible with [Int] values. ## ## >>> 1 ## ## >>> 0 ## -## You can optionally put underscores in your #Int literals. +## You can optionally put underscores in your [Int] literals. ## They have no effect on the number's value, but can make large numbers easier to read. ## ## >>> 1_000_000 @@ -600,13 +600,13 @@ toFloat : Num * -> Float * ## ## >>> Num.abs 0.0 ## -## This is safe to use with any [Float], but it can cause overflow when used with certain #Int values. +## This is safe to use with any [Float], but it can cause overflow when used with certain [Int] values. ## ## For example, calling #Num.abs on the lowest value of a signed integer (such as [Num.minI64] or [Num.minI32]) will cause overflow. ## This is because, for any given size of signed integer (32-bit, 64-bit, etc.) its negated lowest value turns out to be 1 higher than ## the highest value it can represent. (For this reason, calling [Num.neg] on the lowest signed value will also cause overflow.) ## -## Calling this on an unsigned integer (like #U32 or #U64) never does anything. +## Calling this on an unsigned integer (like [U32] or [U64]) never does anything. abs : Num a -> Num a ## Return a negative number when given a positive one, and vice versa. @@ -619,20 +619,20 @@ abs : Num a -> Num a ## ## >>> Num.neg 0.0 ## -## This is safe to use with any [Float], but it can cause overflow when used with certain #Int values. +## This is safe to use with any [Float], but it can cause overflow when used with certain [Int] values. ## ## For example, calling #Num.neg on the lowest value of a signed integer (such as [Num.minI64] or [Num.minI32]) will cause overflow. ## This is because, for any given size of signed integer (32-bit, 64-bit, etc.) its negated lowest value turns out to be 1 higher than ## the highest value it can represent. (For this reason, calling #Num.abs on the lowest signed value will also cause overflow.) ## -## Additionally, calling #Num.neg on any unsigned integer (such as any #U64 or #U32 value) other than zero will cause overflow. +## Additionally, calling #Num.neg on any unsigned integer (such as any [U64] or [U32] value) other than zero will cause overflow. ## ## (It will never crash when given a [Float], however, because of how floating point numbers represent positive and negative numbers.) neg : Num a -> Num a ## Add two numbers of the same type. ## -## (To add an #Int and a [Float], first convert one so that they both have the same type. There are functions in the [`Frac`](/Frac) module that can convert both #Int to [Float] and the other way around.) +## (To add an [Int] and a [Float], first convert one so that they both have the same type. There are functions in this module that can convert both [Int] to [Float] and the other way around.) ## ## `a + b` is shorthand for `Num.add a b`. ## @@ -653,7 +653,7 @@ add : Num a, Num a -> Num a ## Subtract two numbers of the same type. ## -## (To subtract an #Int and a [Float], first convert one so that they both have the same type. There are functions in the [`Frac`](/Frac) module that can convert both #Int to [Float] and the other way around.) +## (To subtract an [Int] and a [Float], first convert one so that they both have the same type. There are functions in this module that can convert both [Int] to [Float] and the other way around.) ## ## `a - b` is shorthand for `Num.sub a b`. ## @@ -674,7 +674,7 @@ sub : Num a, Num a -> Num a ## Multiply two numbers of the same type. ## -## (To multiply an #Int and a [Float], first convert one so that they both have the same type. There are functions in the [`Frac`](/Frac) module that can convert both #Int to [Float] and the other way around.) +## (To multiply an [Int] and a [Float], first convert one so that they both have the same type. There are functions in this module that can convert both [Int] to [Float] and the other way around.) ## ## `a * b` is shorthand for `Num.mul a b`. ## @@ -814,7 +814,7 @@ ceiling : Float * -> Int * ## Raises a [Float] to the power of another [Float]. ## -## For an #Int alternative to this function, see [Num.powInt] +## For an [Int] alternative to this function, see [Num.powInt] pow : Float a, Float a -> Float a ## Raises an integer to the power of another, by multiplying the integer by From 59d1687d0e0543fa8fb7bee514d1b181d7526af9 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 2 May 2022 10:13:35 -0400 Subject: [PATCH 743/846] Add VecSet::iter_mut --- compiler/collections/src/vec_set.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/compiler/collections/src/vec_set.rs b/compiler/collections/src/vec_set.rs index 4869084677..09730f7e95 100644 --- a/compiler/collections/src/vec_set.rs +++ b/compiler/collections/src/vec_set.rs @@ -58,6 +58,10 @@ impl VecSet { pub fn iter(&self) -> impl Iterator { self.elements.iter() } + + pub fn iter_mut(&mut self) -> impl Iterator { + self.elements.iter_mut() + } } impl Extend for VecSet { From 353ea20569c0f622ec04b107e79838ffacd5ff1e Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 2 May 2022 10:21:01 -0400 Subject: [PATCH 744/846] Update a comment --- docs/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/src/lib.rs b/docs/src/lib.rs index 49e2a76dd3..af1f3baa39 100644 --- a/docs/src/lib.rs +++ b/docs/src/lib.rs @@ -24,8 +24,7 @@ mod html; pub fn generate_docs_html(filenames: Vec, build_dir: &Path) { let loaded_modules = load_modules_for_files(filenames); - // - // TODO: get info from a file like "elm.json" + // TODO: get info from a package module; this is all hardcoded for now. let mut package = roc_load::docs::Documentation { name: "roc/builtins".to_string(), version: "1.0.0".to_string(), From 2b67907326ee5a24ac4f7c7482ef8f1cc2e0a2d1 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 2 May 2022 10:21:08 -0400 Subject: [PATCH 745/846] Improve an error message --- docs/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/lib.rs b/docs/src/lib.rs index af1f3baa39..e9d8246101 100644 --- a/docs/src/lib.rs +++ b/docs/src/lib.rs @@ -98,7 +98,7 @@ pub fn generate_docs_html(filenames: Vec, build_dir: &Path) { ); fs::write(module_dir.join("index.html"), rendered_module) - .expect("TODO gracefully handle failing to write html"); + .expect("TODO gracefully handle failing to write index.html inside module's dir"); } } From 881fd40c23a8f5ed628f74361d03d277c6f97f85 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 2 May 2022 10:21:40 -0400 Subject: [PATCH 746/846] Use std::process::exit over panic --- docs/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/src/lib.rs b/docs/src/lib.rs index e9d8246101..25f7ead995 100644 --- a/docs/src/lib.rs +++ b/docs/src/lib.rs @@ -426,8 +426,8 @@ pub fn load_modules_for_files(filenames: Vec) -> Vec { ) { Ok(loaded) => modules.push(loaded), Err(LoadingProblem::FormattedReport(report)) => { - println!("{}", report); - panic!(); + eprintln!("{}", report); + std::process::exit(1); } Err(e) => panic!("{:?}", e), } From 929a1e0083d9034b5de85a05630aef8d47938c1b Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 2 May 2022 10:21:48 -0400 Subject: [PATCH 747/846] Use with_capacity --- docs/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/lib.rs b/docs/src/lib.rs index 25f7ead995..1274664f1a 100644 --- a/docs/src/lib.rs +++ b/docs/src/lib.rs @@ -410,7 +410,7 @@ fn render_sidebar<'a, I: Iterator, &'a ModuleDocumentation)> pub fn load_modules_for_files(filenames: Vec) -> Vec { let arena = Bump::new(); - let mut modules = vec![]; + let mut modules = Vec::with_capacity(filenames.len()); for filename in filenames { let mut src_dir = filename.clone(); From 7e0265adc23891f2786dee6e39e13c62db3e7812 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 2 May 2022 10:28:08 -0400 Subject: [PATCH 748/846] Add an explicit scope around a lock --- compiler/load_internal/src/file.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index 60b5bd7730..4dad05135d 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -293,7 +293,11 @@ fn start_phase<'a>( } } - let skip_constraint_gen = state.cached_subs.lock().contains_key(&module_id); + let skip_constraint_gen = { + // Give this its own scope to make sure that the Guard from the lock() is dropped + // immediately after contains_key returns + state.cached_subs.lock().contains_key(&module_id) + }; BuildTask::CanonicalizeAndConstrain { parsed, From 9a49f3a8764dff477de3f43e78e27f596ce88d4f Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Mon, 2 May 2022 18:23:36 +0200 Subject: [PATCH 749/846] update rust toolchain file --- rust-toolchain.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index d7f514dc9c..98a35adca6 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "1.58.0" # make sure to update the rust version in Earthfile as well +channel = "1.60.0" # make sure to update the rust version in Earthfile as well profile = "default" From c745c08071e0db67e2d7169eac1079fd545fef72 Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Mon, 2 May 2022 18:33:41 +0200 Subject: [PATCH 750/846] fmt+clippy --- compiler/can/src/module.rs | 2 +- compiler/mono/src/ir.rs | 2 +- vendor/pathfinding/src/lib.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index 183e883f85..ffba784309 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -565,7 +565,7 @@ fn fix_values_captured_in_closure_def( } fn fix_values_captured_in_closure_defs( - defs: &mut Vec, + defs: &mut [crate::def::Def], no_capture_symbols: &mut VecSet, ) { // recursive defs cannot capture each other diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 4bd609b72e..963e7761b9 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -724,7 +724,7 @@ impl<'a> Specialized<'a> { }) } - fn is_specialized(&mut self, symbol: Symbol, layout: &ProcLayout<'a>) -> bool { + fn is_specialized(&self, symbol: Symbol, layout: &ProcLayout<'a>) -> bool { for (i, s) in self.symbols.iter().enumerate() { if *s == symbol && &self.proc_layouts[i] == layout { return true; diff --git a/vendor/pathfinding/src/lib.rs b/vendor/pathfinding/src/lib.rs index 9ade5352b1..559b31843b 100644 --- a/vendor/pathfinding/src/lib.rs +++ b/vendor/pathfinding/src/lib.rs @@ -105,7 +105,7 @@ where let mut marked = HashSet::with_capacity_and_hasher(nodes.len(), default_hasher()); let mut temp = MutSet::default(); let mut sorted = VecDeque::with_capacity(nodes.len()); - while let Some(node) = unmarked.iter().cloned().next() { + while let Some(node) = unmarked.iter().next().cloned() { temp.clear(); visit( &node, From 3b7ef7b3caed179c94644da23135b181a48231ed Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Mon, 2 May 2022 20:02:46 +0200 Subject: [PATCH 751/846] update earthfile, flake.nix and shell.nix --- Earthfile | 2 +- flake.lock | 126 +++++++++++++++++++++++++++++++++++++++++++++-- flake.nix | 119 +++++++++++++++++++++++--------------------- nix/sources.json | 6 +-- 4 files changed, 190 insertions(+), 63 deletions(-) diff --git a/Earthfile b/Earthfile index 325825050d..61a0a8f3aa 100644 --- a/Earthfile +++ b/Earthfile @@ -1,4 +1,4 @@ -FROM rust:1.58.0-slim-bullseye # make sure to update rust-toolchain.toml and nixpkgs-unstable in sources.json too so that it uses the same rust version > search for cargo on unstable here: https://search.nixos.org/packages +FROM rust:1.60.0-slim-bullseye # make sure to update rust-toolchain.toml and nixpkgs-unstable in sources.json too so that it uses the same rust version > search for cargo on unstable here: https://search.nixos.org/packages WORKDIR /earthbuild prep-debian: diff --git a/flake.lock b/flake.lock index ca8c578080..ae3588179b 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,50 @@ { "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1649676176, + "narHash": "sha256-OWKJratjt2RW151VUlJPRALb7OU2S5s+f0vLj4o1bHM=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "a4b154ebbdc88c8498a5c7b01589addc9e9cb678", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "locked": { + "lastModified": 1637014545, + "narHash": "sha256-26IZAc5yzlD9FlDT54io1oqG/bBoyka+FJk5guaX4x4=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "bba5dcc8e0b20ab664967ad83d24d64cb64ec4f4", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_3": { + "locked": { + "lastModified": 1629481132, + "narHash": "sha256-JHgasjPR0/J1J3DRm4KxM4zTyAj4IOJY8vIl75v/kPI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "997f7efcb746a9c140ce1f13c72263189225f482", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1647282937, @@ -18,11 +63,43 @@ }, "nixpkgs-unstable": { "locked": { - "lastModified": 1647350163, - "narHash": "sha256-OcMI+PFEHTONthXuEQNddt16Ml7qGvanL3x8QOl2Aao=", + "lastModified": 1651369430, + "narHash": "sha256-d86uUm0s11exU9zLo2K1AwtJQJDKubFpoF0Iw767uT4=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "3eb07eeafb52bcbf02ce800f032f18d666a9498d", + "rev": "b283b64580d1872333a99af2b4cef91bb84580cf", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1637453606, + "narHash": "sha256-Gy6cwUswft9xqsjWxFYEnx/63/qzaFUwatcbV5GF/GQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "8afc4e543663ca0a6a4f496262cd05233737e732", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1631288242, + "narHash": "sha256-sXm4KiKs7qSIf5oTAmrlsEvBW193sFj+tKYVirBaXz0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "0e24c87754430cb6ad2f8c8c8021b29834a8845e", "type": "github" }, "original": { @@ -34,8 +111,49 @@ }, "root": { "inputs": { + "flake-utils": "flake-utils", "nixpkgs": "nixpkgs", - "nixpkgs-unstable": "nixpkgs-unstable" + "nixpkgs-unstable": "nixpkgs-unstable", + "rust-overlay": "rust-overlay", + "zig": "zig" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1651459928, + "narHash": "sha256-V/4b3OG7W6WgkTZXlaYXIg1lYqXy+VgRQReWE4apjgU=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "979ae5a43bdb7662c9dfd2f57826afde0ad438bb", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "zig": { + "inputs": { + "flake-utils": "flake-utils_3", + "nixpkgs": "nixpkgs_3" + }, + "locked": { + "lastModified": 1651452199, + "narHash": "sha256-lq6mTsoPeOCsji/oMFf6953/uOtOhZZ7HSdtjNVDh6I=", + "owner": "roarkanize", + "repo": "zig-overlay", + "rev": "c3bd59086dbc731c240c924fd2bc3581720d0035", + "type": "github" + }, + "original": { + "owner": "roarkanize", + "repo": "zig-overlay", + "type": "github" } } }, diff --git a/flake.nix b/flake.nix index e660b3656c..8c586a948f 100644 --- a/flake.nix +++ b/flake.nix @@ -3,68 +3,77 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-21.11"; - nixpkgs-unstable = { url = "github:NixOS/nixpkgs/nixpkgs-unstable"; }; - # zig = { url = "github:roarkanize/zig-overlay"; }; + nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + rust-overlay.url = "github:oxalica/rust-overlay"; + zig.url = "github:roarkanize/zig-overlay"; + flake-utils.url = "github:numtide/flake-utils"; }; - outputs = { self, nixpkgs, nixpkgs-unstable }: - let - pkgs = nixpkgs.legacyPackages.x86_64-linux; - unstable-pkgs = nixpkgs-unstable.legacyPackages.x86_64-linux; - llvmPkgs = pkgs.llvmPackages_12; + outputs = { self, nixpkgs, nixpkgs-unstable, rust-overlay, zig, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + overlays = [ (import rust-overlay) ]; + pkgs = import nixpkgs { inherit system overlays; }; + unstable-pkgs = nixpkgs-unstable.legacyPackages.${system}; + llvmPkgs = pkgs.llvmPackages_12; - linuxInputs = with pkgs; [ - valgrind # used in cli tests, see cli/tests/cli_run.rs - vulkan-headers - vulkan-loader - vulkan-tools - vulkan-validation-layers - xorg.libX11 - xorg.libXcursor - xorg.libXrandr - xorg.libXi - xorg.libxcb - alsa-lib - ]; + # get current working directory + cwd = builtins.toString ./.; + rust = pkgs.rust-bin.fromRustupToolchainFile "${cwd}/rust-toolchain.toml"; - sharedInputs = (with pkgs; [ - # build libraries - cmake - git - python3 - llvmPkgs.llvm.dev - llvmPkgs.clang - libxkbcommon - pkg-config - zig # roc builtins are implemented in zig, see compiler/builtins/bitcode/ + linuxInputs = with pkgs; [ + valgrind # used in cli tests, see cli/tests/cli_run.rs + vulkan-headers + vulkan-loader + vulkan-tools + vulkan-validation-layers + xorg.libX11 + xorg.libXcursor + xorg.libXrandr + xorg.libXi + xorg.libxcb + alsa-lib + ]; - # lib deps - libffi - libxml2 - ncurses - zlib - libiconv + # zig 0.8.1 from pkgs is broken on aarch64-darwin, hence the workaround + zig-toolchain = zig.packages.${system}."0.8.1"; - # faster builds - see https://github.com/rtfeldman/roc/blob/trunk/BUILDING_FROM_SOURCE.md#use-lld-for-the-linker - llvmPkgs.lld - # debugir - ]) ++ (with unstable-pkgs; [ - rustc - cargo - clippy - rustfmt - ]); - in { + sharedInputs = (with pkgs; [ + # build libraries + cmake + git + python3 + llvmPkgs.llvm.dev + llvmPkgs.clang + libxkbcommon + pkg-config + zig-toolchain # roc builtins are implemented in zig, see compiler/builtins/bitcode/ - devShell.x86_64-linux = pkgs.mkShell { - buildInputs = sharedInputs ++ linuxInputs; + # lib deps + libffi + libxml2 + ncurses + zlib + libiconv - LLVM_SYS_120_PREFIX = "${llvmPkgs.llvm.dev}"; - NIX_GLIBC_PATH = if pkgs.stdenv.isLinux then "${pkgs.glibc_multi.out}/lib" else ""; - LD_LIBRARY_PATH = with pkgs; - lib.makeLibraryPath - ([ pkg-config stdenv.cc.cc.lib libffi ncurses zlib ] ++ linuxInputs); - }; + # faster builds - see https://github.com/rtfeldman/roc/blob/trunk/BUILDING_FROM_SOURCE.md#use-lld-for-the-linker + llvmPkgs.lld + # debugir - }; + rust + ]); + in { + + devShell = pkgs.mkShell { + buildInputs = sharedInputs ++ linuxInputs; + + LLVM_SYS_120_PREFIX = "${llvmPkgs.llvm.dev}"; + NIX_GLIBC_PATH = if pkgs.stdenv.isLinux then "${pkgs.glibc_multi.out}/lib" else ""; + LD_LIBRARY_PATH = with pkgs; + lib.makeLibraryPath + ([ pkg-config stdenv.cc.cc.lib libffi ncurses zlib ] ++ linuxInputs); + }; + + } + ); } diff --git a/nix/sources.json b/nix/sources.json index 04dc2dbb42..fe360b18d1 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -29,10 +29,10 @@ "homepage": "", "owner": "NixOS", "repo": "nixpkgs", - "rev": "684c73c9e6ac8f4d0c6dea3251292e758ac375b5", - "sha256": "0hl2nzizn4pwd3sn9gxkngzn88k9in01xm14afpj7716j8y0j2qa", + "rev": "b283b64580d1872333a99af2b4cef91bb84580cf", + "sha256": "0gmrpfzc622xl1lv3ffaj104j2q3nmia7jywafqmgmrcdm9axkkp", "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/684c73c9e6ac8f4d0c6dea3251292e758ac375b5.tar.gz", + "url": "https://github.com/NixOS/nixpkgs/archive/b283b64580d1872333a99af2b4cef91bb84580cf.tar.gz", "url_template": "https://github.com///archive/.tar.gz" } } From 71cb3700890c6aab4fe3b07214fe468c093eaa54 Mon Sep 17 00:00:00 2001 From: Folkert Date: Mon, 2 May 2022 20:15:28 +0200 Subject: [PATCH 752/846] keep strings on the stack on 32-bit targets --- compiler/gen_llvm/src/llvm/build.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/compiler/gen_llvm/src/llvm/build.rs b/compiler/gen_llvm/src/llvm/build.rs index 6cffc4cb37..c49aa22edf 100644 --- a/compiler/gen_llvm/src/llvm/build.rs +++ b/compiler/gen_llvm/src/llvm/build.rs @@ -805,20 +805,24 @@ pub fn build_exp_literal<'a, 'ctx, 'env>( Bool(b) => env.context.bool_type().const_int(*b as u64, false).into(), Byte(b) => env.context.i8_type().const_int(*b as u64, false).into(), Str(str_literal) => { - let global = if str_literal.len() < env.small_str_bytes() as usize { + if str_literal.len() < env.small_str_bytes() as usize { match env.small_str_bytes() { - 24 => small_str_ptr_width_8(env, parent, str_literal), - 12 => small_str_ptr_width_4(env, parent, str_literal), + 24 => small_str_ptr_width_8(env, parent, str_literal).into(), + 12 => small_str_ptr_width_4(env, parent, str_literal).into(), _ => unreachable!("incorrect small_str_bytes"), } } else { let ptr = define_global_str_literal_ptr(env, *str_literal); let number_of_elements = env.ptr_int().const_int(str_literal.len() as u64, false); - const_str_alloca_ptr(env, parent, ptr, number_of_elements, number_of_elements) - }; + let alloca = + const_str_alloca_ptr(env, parent, ptr, number_of_elements, number_of_elements); - global.into() + match env.target_info.ptr_width() { + PtrWidth::Bytes4 => env.builder.build_load(alloca, "load_const_str"), + PtrWidth::Bytes8 => alloca.into(), + } + } } } } From 68ca014cfa8a6d5d2a18c778bdacd58a76a2204f Mon Sep 17 00:00:00 2001 From: Folkert Date: Mon, 2 May 2022 20:45:53 +0200 Subject: [PATCH 753/846] comments + proper naming --- compiler/mono/src/ir.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 50341c8003..bf6b26e81d 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -7432,14 +7432,11 @@ fn call_by_name_help<'a>( let result = build_call(env, call, assigned, *ret_layout, hole); - let field_symbols = if has_closure { - &field_symbols[..field_symbols.len() - 1] - } else { - field_symbols - }; - - let iter = loc_args.into_iter().rev().zip(field_symbols.iter().rev()); - let x = assign_to_symbols(env, procs, layout_cache, iter, result); + // NOTE: the zip omits the closure symbol, if it exists, + // because loc_args then is shorter than field_symbols + debug_assert!([0, 1].contains(&(field_symbols.len() - loc_args.len()))); + let iter = loc_args.into_iter().zip(field_symbols.iter()).rev(); + let result = assign_to_symbols(env, procs, layout_cache, iter, result); if has_closure { let partial_proc = procs.partial_procs.get_symbol(proc_name).unwrap(); @@ -7457,10 +7454,10 @@ fn call_by_name_help<'a>( proc_name, captured.iter(), closure_argument, - env.arena.alloc(x), + env.arena.alloc(result), ) } else { - x + result } } PendingSpecializations::Making => { From 85e5931ce372a6dafc0e02e3b0d170b678d5d0c7 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 2 May 2022 15:16:31 -0400 Subject: [PATCH 754/846] s/bytes/bits where appropriate --- compiler/builtins/roc/Num.roc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/builtins/roc/Num.roc b/compiler/builtins/roc/Num.roc index e4d69cbf93..4409d5988b 100644 --- a/compiler/builtins/roc/Num.roc +++ b/compiler/builtins/roc/Num.roc @@ -241,7 +241,7 @@ Num range := range ## ## Here are some other examples: ## -## * [U16] is like [U8], except it takes up 16 bytes in memory. It can store 65,536 numbers (2^16), ranging from 0 to 65,536. +## * [U16] is like [U8], except it takes up 16 bits in memory. It can store 65,536 numbers (2^16), ranging from 0 to 65,536. ## * [I16] is like [U16], except it is signed. It can still store the same 65,536 numbers (2^16), ranging from -32,768 to 32,767. ## ## This pattern continues up to [U128] and [I128]. From e6b05d463e1980aa932dea3b948f68acea84baee Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 2 May 2022 19:26:50 -0400 Subject: [PATCH 755/846] Make PRELUDE_TYPES a constant --- compiler/load_internal/src/file.rs | 76 +++++++++++++++--------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index 4dad05135d..7317dc5557 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -76,6 +76,42 @@ const MODULE_SEPARATOR: char = '.'; const EXPANDED_STACK_SIZE: usize = 8 * 1024 * 1024; +const PRELUDE_TYPES: [(&'static str, Symbol); 33] = [ + ("Num", Symbol::NUM_NUM), + ("Int", Symbol::NUM_INT), + ("Float", Symbol::NUM_FLOAT), + ("Integer", Symbol::NUM_INTEGER), + ("FloatingPoint", Symbol::NUM_FLOATINGPOINT), + ("Binary32", Symbol::NUM_BINARY32), + ("Binary64", Symbol::NUM_BINARY64), + ("Signed128", Symbol::NUM_SIGNED128), + ("Signed64", Symbol::NUM_SIGNED64), + ("Signed32", Symbol::NUM_SIGNED32), + ("Signed16", Symbol::NUM_SIGNED16), + ("Signed8", Symbol::NUM_SIGNED8), + ("Unsigned128", Symbol::NUM_UNSIGNED128), + ("Unsigned64", Symbol::NUM_UNSIGNED64), + ("Unsigned32", Symbol::NUM_UNSIGNED32), + ("Unsigned16", Symbol::NUM_UNSIGNED16), + ("Unsigned8", Symbol::NUM_UNSIGNED8), + ("Natural", Symbol::NUM_NATURAL), + ("Decimal", Symbol::NUM_DECIMAL), + ("Nat", Symbol::NUM_NAT), + ("I8", Symbol::NUM_I8), + ("I16", Symbol::NUM_I16), + ("I32", Symbol::NUM_I32), + ("I64", Symbol::NUM_I64), + ("I128", Symbol::NUM_I128), + ("U8", Symbol::NUM_U8), + ("U16", Symbol::NUM_U16), + ("U32", Symbol::NUM_U32), + ("U64", Symbol::NUM_U64), + ("U128", Symbol::NUM_U128), + ("F32", Symbol::NUM_F32), + ("F64", Symbol::NUM_F64), + ("Dec", Symbol::NUM_DEC), +]; + macro_rules! log { ($($arg:tt)*) => (dbg_do!(ROC_PRINT_LOAD_LOG, println!($($arg)*))) } @@ -1800,46 +1836,10 @@ fn update<'a>( .imported_modules .insert(ModuleId::NUM, Region::zero()); - let prelude_types = [ - (Ident::from("Num"), Symbol::NUM_NUM), - (Ident::from("Int"), Symbol::NUM_INT), - (Ident::from("Float"), Symbol::NUM_FLOAT), - (Ident::from("Integer"), Symbol::NUM_INTEGER), - (Ident::from("FloatingPoint"), Symbol::NUM_FLOATINGPOINT), - (Ident::from("Binary32"), Symbol::NUM_BINARY32), - (Ident::from("Binary64"), Symbol::NUM_BINARY64), - (Ident::from("Signed128"), Symbol::NUM_SIGNED128), - (Ident::from("Signed64"), Symbol::NUM_SIGNED64), - (Ident::from("Signed32"), Symbol::NUM_SIGNED32), - (Ident::from("Signed16"), Symbol::NUM_SIGNED16), - (Ident::from("Signed8"), Symbol::NUM_SIGNED8), - (Ident::from("Unsigned128"), Symbol::NUM_UNSIGNED128), - (Ident::from("Unsigned64"), Symbol::NUM_UNSIGNED64), - (Ident::from("Unsigned32"), Symbol::NUM_UNSIGNED32), - (Ident::from("Unsigned16"), Symbol::NUM_UNSIGNED16), - (Ident::from("Unsigned8"), Symbol::NUM_UNSIGNED8), - (Ident::from("Natural"), Symbol::NUM_NATURAL), - (Ident::from("Decimal"), Symbol::NUM_DECIMAL), - (Ident::from("Nat"), Symbol::NUM_NAT), - (Ident::from("I8"), Symbol::NUM_I8), - (Ident::from("I16"), Symbol::NUM_I16), - (Ident::from("I32"), Symbol::NUM_I32), - (Ident::from("I64"), Symbol::NUM_I64), - (Ident::from("I128"), Symbol::NUM_I128), - (Ident::from("U8"), Symbol::NUM_U8), - (Ident::from("U16"), Symbol::NUM_U16), - (Ident::from("U32"), Symbol::NUM_U32), - (Ident::from("U64"), Symbol::NUM_U64), - (Ident::from("U128"), Symbol::NUM_U128), - (Ident::from("F32"), Symbol::NUM_F32), - (Ident::from("F64"), Symbol::NUM_F64), - (Ident::from("Dec"), Symbol::NUM_DEC), - ]; - - for (ident, symbol) in prelude_types { + for (type_name, symbol) in PRELUDE_TYPES { header .exposed_imports - .insert(ident, (symbol, Region::zero())); + .insert(Ident::from(type_name), (symbol, Region::zero())); } } From b05259d8703b392d3b8fa14fc5dcbde9a1039408 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 2 May 2022 19:44:42 -0400 Subject: [PATCH 756/846] Don't try to autolink to Num from Bool This doesn't work because it would be a cyclic import --- compiler/builtins/roc/Bool.roc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/builtins/roc/Bool.roc b/compiler/builtins/roc/Bool.roc index dc6a15bdd8..0a2ad7ecfc 100644 --- a/compiler/builtins/roc/Bool.roc +++ b/compiler/builtins/roc/Bool.roc @@ -69,7 +69,7 @@ not : Bool -> Bool ## 1. Tags are equal if they have the same tag name, and also their contents (if any) are equal. ## 2. Records are equal if all their fields are equal. ## 3. Collections ([Str], [List], [Dict], and [Set]) are equal if they are the same length, and also all their corresponding elements are equal. -## 4. [Num] values are equal if their numbers are equal, with one exception: if both arguments to `isEq` are *NaN*, then `isEq` returns `False`. See `Num.isNaN` for more about *NaN*. +## 4. [Num](Num#Num) values are equal if their numbers are equal, with one exception: if both arguments to `isEq` are *NaN*, then `isEq` returns `False`. See `Num.isNaN` for more about *NaN*. ## ## Note that `isEq` takes `'val` instead of `val`, which means `isEq` does not ## accept arguments whose types contain functions. From 8435bb057e13835c5ea6a82d318f87d4992108ff Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 2 May 2022 20:02:57 -0400 Subject: [PATCH 757/846] Don't render duplicate module docs --- docs/src/lib.rs | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/docs/src/lib.rs b/docs/src/lib.rs index 1274664f1a..a6f60477d7 100644 --- a/docs/src/lib.rs +++ b/docs/src/lib.rs @@ -65,15 +65,22 @@ pub fn generate_docs_html(filenames: Vec, build_dir: &Path) { .replace( "", render_sidebar(package.modules.iter().flat_map(|loaded_module| { - loaded_module.documentation.values().map(move |d| { - let exposed_values = loaded_module - .exposed_values - .iter() - .map(|symbol| symbol.as_str(&loaded_module.interns).to_string()) - .collect::>(); + loaded_module + .documentation + .iter() + .filter_map(move |(module_id, module)| { + if *module_id == loaded_module.module_id { + let exposed_values = loaded_module + .exposed_values + .iter() + .map(|symbol| symbol.as_str(&loaded_module.interns).to_string()) + .collect::>(); - (exposed_values, d) - }) + Some((module, exposed_values)) + } else { + None + } + }) })) .as_str(), ); @@ -334,12 +341,12 @@ fn render_name_and_version(name: &str, version: &str) -> String { buf } -fn render_sidebar<'a, I: Iterator, &'a ModuleDocumentation)>>( +fn render_sidebar<'a, I: Iterator)>>( modules: I, ) -> String { let mut buf = String::new(); - for (exposed_values, module) in modules { + for (module, exposed_values) in modules { let mut sidebar_entry_content = String::new(); let name = module.name.as_str(); From 64b5c49faf94beda17aff0e311dbe4a580ba8913 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 2 May 2022 20:07:00 -0400 Subject: [PATCH 758/846] Add a comment about the documentation dictionary --- docs/src/lib.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/src/lib.rs b/docs/src/lib.rs index a6f60477d7..93a8756732 100644 --- a/docs/src/lib.rs +++ b/docs/src/lib.rs @@ -69,6 +69,11 @@ pub fn generate_docs_html(filenames: Vec, build_dir: &Path) { .documentation .iter() .filter_map(move |(module_id, module)| { + // TODO it seems this `documentation` dictionary has entries for + // every module, but only the current module has any info in it. + // We disregard the others, but probably this shouldn't bother + // being a hash map in the first place if only one of its entries + // actually has interesting information in it? if *module_id == loaded_module.module_id { let exposed_values = loaded_module .exposed_values From ddfa45eeb5b4fb44eb770753f73eb1fa2a2634b3 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 2 May 2022 20:14:48 -0400 Subject: [PATCH 759/846] Fix URLs in docs generation --- docs/src/lib.rs | 9 +++------ www/build.sh | 5 +++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/docs/src/lib.rs b/docs/src/lib.rs index 93a8756732..fc348557cf 100644 --- a/docs/src/lib.rs +++ b/docs/src/lib.rs @@ -56,12 +56,9 @@ pub fn generate_docs_html(filenames: Vec, build_dir: &Path) { .expect("TODO gracefully handle failing to make the favicon"); let template_html = include_str!("./static/index.html") - .replace("", &format!("{}search.js", base_url())) - .replace("", &format!("{}styles.css", base_url())) - .replace( - "", - &format!("{}favicon.svg", base_url()), - ) + .replace("", "/search.js") + .replace("", "/styles.css") + .replace("", "/favicon.svg") .replace( "", render_sidebar(package.modules.iter().flat_map(|loaded_module| { diff --git a/www/build.sh b/www/build.sh index cf27ae6b40..2d5d179ef0 100755 --- a/www/build.sh +++ b/www/build.sh @@ -41,7 +41,7 @@ RUSTFLAGS=-Awarnings # We set ROC_DOCS_ROOT_DIR=builtins so that links will be generated relative to # "/builtins/" rather than "/" - which is what we want based on how the server # is set up to serve them. -ROC_DOCS_URL_ROOT=builtins +export ROC_DOCS_URL_ROOT=/builtins # These just need to be defined so that some env! macros don't fail. BUILTINS_WASM32_O="" @@ -51,5 +51,6 @@ BUILTINS_HOST_O="" # "llvm" feature and therefore don't depend on LLVM being installed on the # system. (Netlify's build servers have Rust installed, but not LLVM.) cargo run -p roc_cli --no-default-features docs compiler/builtins/roc/*.roc -mv generated-docs/ www/build/builtins +mv generated-docs/*.* www/build # move all the .js, .css, etc. files to build/ +mv generated-docs/ www/build/builtins # move all the folders to build/builtins/ popd From b8f1e3176a3f093214cb16eb5f901295d47e80db Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 2 May 2022 20:26:12 -0400 Subject: [PATCH 760/846] Fix Bool docs not rendering --- docs/src/lib.rs | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/docs/src/lib.rs b/docs/src/lib.rs index fc348557cf..4a22876060 100644 --- a/docs/src/lib.rs +++ b/docs/src/lib.rs @@ -89,25 +89,28 @@ pub fn generate_docs_html(filenames: Vec, build_dir: &Path) { // Write each package's module docs html file for loaded_module in package.modules.iter_mut() { - for module_docs in loaded_module.documentation.values() { - let module_dir = build_dir.join(module_docs.name.replace('.', "/").as_str()); + for (module_id, module_docs) in loaded_module.documentation.iter() { + if *module_id == loaded_module.module_id { + let module_dir = build_dir.join(module_docs.name.replace('.', "/").as_str()); - fs::create_dir_all(&module_dir) - .expect("TODO gracefully handle not being able to create the module dir"); + fs::create_dir_all(&module_dir) + .expect("TODO gracefully handle not being able to create the module dir"); - let rendered_module = template_html - .replace( - "", - render_name_and_version(package.name.as_str(), package.version.as_str()) - .as_str(), - ) - .replace( - "", - render_module_documentation(module_docs, loaded_module).as_str(), + let rendered_module = template_html + .replace( + "", + render_name_and_version(package.name.as_str(), package.version.as_str()) + .as_str(), + ) + .replace( + "", + render_module_documentation(module_docs, loaded_module).as_str(), + ); + + fs::write(module_dir.join("index.html"), rendered_module).expect( + "TODO gracefully handle failing to write index.html inside module's dir", ); - - fs::write(module_dir.join("index.html"), rendered_module) - .expect("TODO gracefully handle failing to write index.html inside module's dir"); + } } } From e0e6f56353e686e7e712e15465bcc38ca543972d Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 2 May 2022 20:26:32 -0400 Subject: [PATCH 761/846] Render types monospaced --- docs/src/static/styles.css | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/src/static/styles.css b/docs/src/static/styles.css index 799d849a86..486fa8972a 100644 --- a/docs/src/static/styles.css +++ b/docs/src/static/styles.css @@ -53,6 +53,7 @@ a { .entry-name { white-space: pre-wrap; + font-family: var(--font-mono); } .pkg-full-name a { From dd1e8cc193a60ea5ee035ec21450ec7cc9d7a1f7 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 2 May 2022 21:18:30 -0400 Subject: [PATCH 762/846] [Shatner yell] CLIPPYYYYYYYYYYY!!!!!!! --- compiler/load_internal/src/file.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index 7317dc5557..f34afff787 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -76,7 +76,7 @@ const MODULE_SEPARATOR: char = '.'; const EXPANDED_STACK_SIZE: usize = 8 * 1024 * 1024; -const PRELUDE_TYPES: [(&'static str, Symbol); 33] = [ +const PRELUDE_TYPES: [(&str, Symbol); 33] = [ ("Num", Symbol::NUM_NUM), ("Int", Symbol::NUM_INT), ("Float", Symbol::NUM_FLOAT), From dd1d49db758422de5f27fb2416aaa4c2541b7e1d Mon Sep 17 00:00:00 2001 From: Brian Carroll Date: Sun, 1 May 2022 18:07:18 +0100 Subject: [PATCH 763/846] Build WASI libc using Zig, instead of using a checked-in binary --- Cargo.toml | 1 + compiler/build/src/link.rs | 16 +++--- compiler/builtins/bitcode/wasi-libc.a | Bin 951466 -> 0 bytes wasi-libc-sys/Cargo.toml | 8 +++ wasi-libc-sys/build.rs | 70 ++++++++++++++++++++++++++ wasi-libc-sys/src/dummy.c | 6 +++ wasi-libc-sys/src/lib.rs | 11 ++++ 7 files changed, 102 insertions(+), 10 deletions(-) delete mode 100644 compiler/builtins/bitcode/wasi-libc.a create mode 100644 wasi-libc-sys/Cargo.toml create mode 100644 wasi-libc-sys/build.rs create mode 100644 wasi-libc-sys/src/dummy.c create mode 100644 wasi-libc-sys/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 706c467a3a..2dbc0b867d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,6 +55,7 @@ exclude = [ "compiler/test_mono_macros", # `cargo build` would cause roc_std to be built with default features which errors on windows "roc_std", + "wasi-libc-sys", ] # Needed to be able to run `cargo run -p roc_cli --no-default-features` - # see www/build.sh for more. diff --git a/compiler/build/src/link.rs b/compiler/build/src/link.rs index 3acb21720d..bcee333e6e 100644 --- a/compiler/build/src/link.rs +++ b/compiler/build/src/link.rs @@ -72,16 +72,12 @@ fn find_zig_str_path() -> PathBuf { } fn find_wasi_libc_path() -> PathBuf { - let wasi_libc_path = PathBuf::from("compiler/builtins/bitcode/wasi-libc.a"); - - if std::path::Path::exists(&wasi_libc_path) { - return wasi_libc_path; - } - - // when running the tests, we start in the /cli directory - let wasi_libc_path = PathBuf::from("../compiler/builtins/bitcode/wasi-libc.a"); - if std::path::Path::exists(&wasi_libc_path) { - return wasi_libc_path; + // Environment variable defined in wasi-libc-sys/build.rs + if let Ok(wasi_libc_path) = std::env::var("WASI_LIBC_SYS_PATH") { + let wasi_libc_pathbuf = PathBuf::from(&wasi_libc_path); + if std::path::Path::exists(&wasi_libc_pathbuf) { + return wasi_libc_pathbuf; + } } panic!("cannot find `wasi-libc.a`") diff --git a/compiler/builtins/bitcode/wasi-libc.a b/compiler/builtins/bitcode/wasi-libc.a deleted file mode 100644 index 70378bcf13f31a22fd2967fc5fc1c29cddc90085..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 951466 zcmdSieVi?8RUi1L&kOgQ?mh$=gUUDrQ3=B!z29F5AqIs3f`A6m5VfgYyXu_2^c&rM zUhWMNqJ|J<)FFrrB07W^G{_KQ7(d8|5Q0k3VUQt_5G5E5G6WP2A!rQFcUA4(yU#t> zRPmY5{4w{Q+V!$)uYT&O=Vh(m`mObR#pAQ1{Mr-Nw;q1`f1NX@_3_!yhd;bKnhXck zJB4K%+LztiZp+@A*78wWn?ET?N3Tn3C*PCSuD>g- z-S~W3yY;NJ_Sc@6)?W0SwD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I!~ zJ6jzJh3qTC+Ho-Nt5xg6VS5wN7NYIpi2V$Z{WAVUKE_<|V1X4`oUqh2xOwiDgcZ39 w&jY}Ffx8Mn_qmw5nPsN1b9x76J=4x String { + match std::env::var("ROC_ZIG") { + Ok(path) => path, + Err(_) => "zig".into(), + } +} + +fn run_command>(path: P, command_str: &str, args: I) -> String +where + I: IntoIterator, + S: AsRef, +{ + let output_result = Command::new(OsStr::new(&command_str)) + .current_dir(path) + .args(args) + .output(); + match output_result { + Ok(output) => match output.status.success() { + true => std::str::from_utf8(&output.stdout).unwrap().to_string(), + false => { + let error_str = match std::str::from_utf8(&output.stderr) { + Ok(stderr) => stderr.to_string(), + Err(_) => format!("Failed to run \"{}\"", command_str), + }; + panic!("{} failed: {}", command_str, error_str); + } + }, + Err(reason) => panic!("{} failed: {}", command_str, reason), + } +} diff --git a/wasi-libc-sys/src/dummy.c b/wasi-libc-sys/src/dummy.c new file mode 100644 index 0000000000..5f247ac932 --- /dev/null +++ b/wasi-libc-sys/src/dummy.c @@ -0,0 +1,6 @@ +#include + +int main(int argc, char **argv) +{ + printf("I am a dummy C program. I only exist to help the build script to find libc.a and copy it"); +} diff --git a/wasi-libc-sys/src/lib.rs b/wasi-libc-sys/src/lib.rs new file mode 100644 index 0000000000..5fcf78879c --- /dev/null +++ b/wasi-libc-sys/src/lib.rs @@ -0,0 +1,11 @@ +use core::ffi::c_void; + +// Rust's libc crate doesn't support Wasm, so we provide an implementation from Zig +// We define Rust signatures here as we need them, rather than trying to cover all of libc +extern "C" { + pub fn malloc(size: usize) -> *mut c_void; + pub fn free(p: *mut c_void); + pub fn realloc(p: *mut c_void, size: usize) -> *mut c_void; + pub fn memcpy(dst: *mut c_void, src: *mut c_void, n: usize) -> *mut c_void; + pub fn memset(dst: *mut c_void, ch: i32, n: usize) -> *mut c_void; +} From ebf5b41ef305f2b519f9fd2d0787d9592bf578a6 Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Tue, 3 May 2022 13:27:51 +0200 Subject: [PATCH 764/846] use rust toolchain file --- flake.nix | 4 +--- shell.nix | 15 ++++++++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/flake.nix b/flake.nix index 8c586a948f..7a0b8147cf 100644 --- a/flake.nix +++ b/flake.nix @@ -3,18 +3,16 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-21.11"; - nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; rust-overlay.url = "github:oxalica/rust-overlay"; zig.url = "github:roarkanize/zig-overlay"; flake-utils.url = "github:numtide/flake-utils"; }; - outputs = { self, nixpkgs, nixpkgs-unstable, rust-overlay, zig, flake-utils }: + outputs = { self, nixpkgs, rust-overlay, zig, flake-utils }: flake-utils.lib.eachDefaultSystem (system: let overlays = [ (import rust-overlay) ]; pkgs = import nixpkgs { inherit system overlays; }; - unstable-pkgs = nixpkgs-unstable.legacyPackages.${system}; llvmPkgs = pkgs.llvmPackages_12; # get current working directory diff --git a/shell.nix b/shell.nix index ce867939ad..9541cacea7 100644 --- a/shell.nix +++ b/shell.nix @@ -2,8 +2,13 @@ let sources = import nix/sources.nix { }; - pkgs = import sources.nixpkgs { }; - unstable-pkgs = import sources.nixpkgs-unstable { }; + rust_overlay = import (builtins.fetchTarball "https://github.com/oxalica/rust-overlay/archive/master.tar.gz"); + pkgs = import sources.nixpkgs { + overlays = [ rust_overlay ]; + }; + rust_toolchain = (pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml); + + #unstable-pkgs = import sources.nixpkgs-unstable { }; darwinInputs = with pkgs; lib.optionals stdenv.isDarwin (with pkgs.darwin.apple_sdk.frameworks; [ @@ -65,9 +70,9 @@ let # tools for development environment less - ]) ++ (with unstable-pkgs; [ - rustup - ]); + ]) ++ [ + rust_toolchain + ]; in pkgs.mkShell { buildInputs = inputs ++ darwinInputs ++ linuxInputs; From 6cbdb9680c4e3d8c164257157fa731dd0c9ffcb3 Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Tue, 3 May 2022 13:39:11 +0200 Subject: [PATCH 765/846] added some comments --- flake.nix | 6 +++--- test_utils/src/lib.rs | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index 7a0b8147cf..49b553fb87 100644 --- a/flake.nix +++ b/flake.nix @@ -3,9 +3,9 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-21.11"; - rust-overlay.url = "github:oxalica/rust-overlay"; - zig.url = "github:roarkanize/zig-overlay"; - flake-utils.url = "github:numtide/flake-utils"; + rust-overlay.url = "github:oxalica/rust-overlay"; # rust from nixpkgs has some libc problems, this is patched in the rust-overlay + zig.url = "github:roarkanize/zig-overlay"; # zig 8.1 is broken on nixpkgs for M1 macs + flake-utils.url = "github:numtide/flake-utils"; # to easily make configs for all architectures }; outputs = { self, nixpkgs, rust-overlay, zig, flake-utils }: diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs index 754f10d18f..3387cedff4 100644 --- a/test_utils/src/lib.rs +++ b/test_utils/src/lib.rs @@ -43,6 +43,7 @@ impl TmpDir { impl Drop for TmpDir { fn drop(&mut self) { + // we "discard" the Result because there is no problem when a dir was already removed before we call remove_dir_all let _ = remove_dir_all::remove_dir_all(&self.path); } } From a40b055f1639c666367ce10d87a166b1f5ce55e5 Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Tue, 3 May 2022 13:46:39 +0200 Subject: [PATCH 766/846] better comments --- Earthfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Earthfile b/Earthfile index 61a0a8f3aa..a035ae24b7 100644 --- a/Earthfile +++ b/Earthfile @@ -1,5 +1,4 @@ -FROM rust:1.60.0-slim-bullseye # make sure to update rust-toolchain.toml and nixpkgs-unstable in sources.json too so that it uses the same rust version > search for cargo on unstable here: https://search.nixos.org/packages -WORKDIR /earthbuild +FROM rust:1.60.0-slim-bullseye # make sure to update rust-toolchain.toml too so that everything uses the same rust version prep-debian: RUN apt -y update From 847378a3335e78106839dc5d951153d528a61d04 Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Tue, 3 May 2022 15:04:45 +0200 Subject: [PATCH 767/846] no more earthbuild apparently --- Earthfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Earthfile b/Earthfile index a035ae24b7..33d60dfa74 100644 --- a/Earthfile +++ b/Earthfile @@ -18,7 +18,7 @@ install-zig-llvm-valgrind-clippy-rustfmt: # zig RUN wget -c https://ziglang.org/download/0.8.0/zig-linux-x86_64-0.8.0.tar.xz --no-check-certificate RUN tar -xf zig-linux-x86_64-0.8.0.tar.xz - RUN ln -s /earthbuild/zig-linux-x86_64-0.8.0/zig /usr/bin/zig + RUN ln -s /zig-linux-x86_64-0.8.0/zig /usr/bin/zig # zig builtins wasm tests RUN apt -y install build-essential RUN cargo install wasmer-cli --features "singlepass" @@ -48,7 +48,7 @@ install-zig-llvm-valgrind-clippy-rustfmt: RUN cargo install sccache RUN sccache -V ENV RUSTC_WRAPPER=/usr/local/cargo/bin/sccache - ENV SCCACHE_DIR=/earthbuild/sccache_dir + ENV SCCACHE_DIR=/sccache_dir ENV CARGO_INCREMENTAL=0 # no need to recompile package when using new function copy-dirs: From 88db62cac25c8887abfed4a8a99c226f0d8e4d73 Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Tue, 3 May 2022 15:38:47 +0200 Subject: [PATCH 768/846] undo accidental workdir removal --- Earthfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Earthfile b/Earthfile index 33d60dfa74..57d7b6a072 100644 --- a/Earthfile +++ b/Earthfile @@ -1,4 +1,5 @@ FROM rust:1.60.0-slim-bullseye # make sure to update rust-toolchain.toml too so that everything uses the same rust version +WORKDIR /earthbuild prep-debian: RUN apt -y update @@ -18,7 +19,7 @@ install-zig-llvm-valgrind-clippy-rustfmt: # zig RUN wget -c https://ziglang.org/download/0.8.0/zig-linux-x86_64-0.8.0.tar.xz --no-check-certificate RUN tar -xf zig-linux-x86_64-0.8.0.tar.xz - RUN ln -s /zig-linux-x86_64-0.8.0/zig /usr/bin/zig + RUN ln -s /earthbuild/zig-linux-x86_64-0.8.0/zig /bin/zig # zig builtins wasm tests RUN apt -y install build-essential RUN cargo install wasmer-cli --features "singlepass" @@ -48,7 +49,7 @@ install-zig-llvm-valgrind-clippy-rustfmt: RUN cargo install sccache RUN sccache -V ENV RUSTC_WRAPPER=/usr/local/cargo/bin/sccache - ENV SCCACHE_DIR=/sccache_dir + ENV SCCACHE_DIR=/earthbuild/sccache_dir ENV CARGO_INCREMENTAL=0 # no need to recompile package when using new function copy-dirs: From cc28de408c950183adaffd302f728902ee55fd29 Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Tue, 3 May 2022 18:00:29 +0200 Subject: [PATCH 769/846] update wasmer to 2.2.1 --- Cargo.lock | 466 ++++++++++++------ cli/Cargo.toml | 12 +- compiler/test_gen/Cargo.toml | 6 +- .../src/helpers/from_wasmer_memory.rs | 21 +- compiler/test_gen/src/helpers/llvm.rs | 9 +- compiler/test_gen/src/helpers/wasm.rs | 3 +- repl_test/Cargo.toml | 6 +- 7 files changed, 349 insertions(+), 174 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 00722d3728..88a24e0a73 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -178,6 +178,12 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base-x" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc19a4937b4fbd3fe3379793130e42060d10627a360f2127802b10b87e7baf74" + [[package]] name = "bincode" version = "1.3.3" @@ -320,6 +326,27 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" +[[package]] +name = "bytecheck" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a31f923c2db9513e4298b72df143e6e655a759b3d6a0966df18f81223fff54f" +dependencies = [ + "bytecheck_derive", + "ptr_meta", +] + +[[package]] +name = "bytecheck_derive" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edb17c862a905d912174daa27ae002326fff56dc8b8ada50a0a5f0976cb174f0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "bytemuck" version = "1.7.2" @@ -368,7 +395,7 @@ version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c24dab4283a142afa2fdca129b80ad2c6284e073930f964c3a1293c225ee39a" dependencies = [ - "rustc_version", + "rustc_version 0.4.0", ] [[package]] @@ -586,6 +613,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "const_fn" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbdcdcb6d86f71c5e97409ad45898af11cbc995b4ee8112d59095a28d376c935" + [[package]] name = "const_format" version = "0.2.22" @@ -746,7 +779,7 @@ dependencies = [ "nix 0.20.0", "oboe", "parking_lot 0.11.2", - "stdweb", + "stdweb 0.1.3", "thiserror", "web-sys", "winapi", @@ -763,24 +796,24 @@ dependencies = [ [[package]] name = "cranelift-bforest" -version = "0.74.0" +version = "0.76.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8ca3560686e7c9c7ed7e0fe77469f2410ba5d7781b1acaa9adc8d8deea28e3e" +checksum = "7e6bea67967505247f54fa2c85cf4f6e0e31c4e5692c9b70e4ae58e339067333" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.74.0" +version = "0.76.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf9bf1ffffb6ce3d2e5ebc83549bd2436426c99b31cc550d521364cbe35d276" +checksum = "48194035d2752bdd5bdae429e3ab88676e95f52a2b1355a5d4e809f9e39b1d74" dependencies = [ "cranelift-bforest", "cranelift-codegen-meta", "cranelift-codegen-shared", "cranelift-entity", - "gimli 0.24.0", + "gimli 0.25.0", "log", "regalloc", "smallvec", @@ -789,9 +822,9 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.74.0" +version = "0.76.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cc21936a5a6d07e23849ffe83e5c1f6f50305c074f4b2970ca50c13bf55b821" +checksum = "976efb22fcab4f2cd6bd4e9913764616a54d895c1a23530128d04e03633c555f" dependencies = [ "cranelift-codegen-shared", "cranelift-entity", @@ -799,21 +832,21 @@ dependencies = [ [[package]] name = "cranelift-codegen-shared" -version = "0.74.0" +version = "0.76.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca5b6ffaa87560bebe69a5446449da18090b126037920b0c1c6d5945f72faf6b" +checksum = "9dabb5fe66e04d4652e434195b45ae65b5c8172d520247b8f66d8df42b2b45dc" [[package]] name = "cranelift-entity" -version = "0.74.0" +version = "0.76.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d6b4a8bef04f82e4296782646f733c641d09497df2fabf791323fefaa44c64c" +checksum = "3329733e4d4b8e91c809efcaa4faee80bf66f20164e3dd16d707346bd3494799" [[package]] name = "cranelift-frontend" -version = "0.74.0" +version = "0.76.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c31b783b351f966fce33e3c03498cb116d16d97a8f9978164a60920bd0d3a99c" +checksum = "279afcc0d3e651b773f94837c3d581177b348c8d69e928104b2e9fccb226f921" dependencies = [ "cranelift-codegen", "log", @@ -1167,6 +1200,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "discard" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" + [[package]] name = "dispatch" version = "0.2.0" @@ -1265,6 +1304,26 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" +[[package]] +name = "enum-iterator" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eeac5c5edb79e4e39fe8439ef35207780a11f69c52cbe424ce3dfad4cb78de6" +dependencies = [ + "enum-iterator-derive", +] + +[[package]] +name = "enum-iterator-derive" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c134c37760b27a871ba422106eedbb8247da973a09e82558bf26d619c882b159" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "enumset" version = "1.0.8" @@ -1309,15 +1368,6 @@ dependencies = [ "termcolor", ] -[[package]] -name = "erased-serde" -version = "0.3.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3de9ad4541d99dc22b59134e7ff8dc3d6c988c89ecd7324bf10a8362b07a2afa" -dependencies = [ - "serde", -] - [[package]] name = "error-code" version = "2.3.0" @@ -1521,7 +1571,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e1d3b771574f62d0548cee0ad9057857e9fc25d7a3335f140c84f6acd0bf601" dependencies = [ "cfg-if 0.1.10", - "serde", ] [[package]] @@ -1554,22 +1603,11 @@ dependencies = [ "wasi", ] -[[package]] -name = "ghost" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a5bcf1bbeab73aa4cf2fde60a846858dc036163c7c33bec309f8d17de785479" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "gimli" -version = "0.24.0" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e4075386626662786ddb0ec9081e7c7eeb1ba31951f447ca780ef9f5d568189" +checksum = "f0a01e0497841a3b2db4f8afa483cce65f7e96a3498bd6c541734792aeac8fe7" dependencies = [ "fallible-iterator", "indexmap", @@ -1703,6 +1741,15 @@ dependencies = [ "bumpalo", ] +[[package]] +name = "hashbrown" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db0d4cf898abf0081f964436dc980e96670a0f36863e4b83aaacdb65c9d7ccc3" +dependencies = [ + "ahash 0.7.6", +] + [[package]] name = "hermit-abi" version = "0.1.19" @@ -1842,28 +1889,6 @@ dependencies = [ "web-sys", ] -[[package]] -name = "inventory" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f0f7efb804ec95e33db9ad49e4252f049e37e8b0a4652e3cd61f7999f2eff7f" -dependencies = [ - "ctor", - "ghost", - "inventory-impl", -] - -[[package]] -name = "inventory-impl" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75c094e94816723ab936484666968f5b58060492e880f3c8d00489a1e244fa51" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "itertools" version = "0.9.0" @@ -2103,15 +2128,6 @@ dependencies = [ "libc", ] -[[package]] -name = "memmap2" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "723e3ebdcdc5c023db1df315364573789f8857c11b631a2fdfad7c00f5c046b4" -dependencies = [ - "libc", -] - [[package]] name = "memmap2" version = "0.3.1" @@ -2524,17 +2540,6 @@ dependencies = [ "objc", ] -[[package]] -name = "object" -version = "0.25.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a38f2be3697a57b4060074ff41b44c16870d916ad7877c17696e063257482bc7" -dependencies = [ - "crc32fast", - "indexmap", - "memchr", -] - [[package]] name = "object" version = "0.26.2" @@ -2556,6 +2561,18 @@ dependencies = [ "memchr", ] +[[package]] +name = "object" +version = "0.28.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40bec70ba014595f99f7aa110b84331ffe1ee9aece7fe6f387cc7e3ecda4d456" +dependencies = [ + "crc32fast", + "hashbrown 0.11.2", + "indexmap", + "memchr", +] + [[package]] name = "oboe" version = "0.4.4" @@ -3276,9 +3293,9 @@ checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" [[package]] name = "region" -version = "2.2.0" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "877e54ea2adcd70d80e9179344c97f93ef0dffd6b03e1f4529e6e83ab2fa9ae0" +checksum = "76e189c2369884dce920945e2ddf79b3dff49e071a167dd1817fa9c4c00d512e" dependencies = [ "bitflags", "libc", @@ -3308,6 +3325,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "rend" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79af64b4b6362ffba04eef3a4e10829718a4896dac19daa741851c86781edf95" +dependencies = [ + "bytecheck", +] + [[package]] name = "renderdoc-sys" version = "0.7.1" @@ -3330,21 +3356,23 @@ dependencies = [ [[package]] name = "rkyv" -version = "0.6.7" +version = "0.7.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb135b3e5e3311f0a254bfb00333f4bac9ef1d89888b84242a89eb8722b09a07" +checksum = "517a3034eb2b1499714e9d1e49b2367ad567e07639b69776d35e259d9c27cca6" dependencies = [ - "memoffset", + "bytecheck", + "hashbrown 0.12.1", "ptr_meta", + "rend", "rkyv_derive", "seahash", ] [[package]] name = "rkyv_derive" -version = "0.6.7" +version = "0.7.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba8f489f6b6d8551bb15904293c1ad58a6abafa7d8390d15f7ed05a2afcd87d5" +checksum = "505c209ee04111a006431abf39696e640838364d67a107c559ababaf6fd8c9dd" dependencies = [ "proc-macro2", "quote", @@ -4064,6 +4092,15 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rustc_version" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +dependencies = [ + "semver 0.9.0", +] + [[package]] name = "rustc_version" version = "0.4.0" @@ -4154,13 +4191,22 @@ version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" +[[package]] +name = "semver" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +dependencies = [ + "semver-parser 0.7.0", +] + [[package]] name = "semver" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" dependencies = [ - "semver-parser", + "semver-parser 0.10.2", ] [[package]] @@ -4169,6 +4215,12 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "568a8e6258aa33c13358f81fd834adb854c6f7c9468520910a9b1e8fac068012" +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" + [[package]] name = "semver-parser" version = "0.10.2" @@ -4286,6 +4338,21 @@ dependencies = [ "opaque-debug 0.2.3", ] +[[package]] +name = "sha1" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1da05c97445caa12d05e848c4a4fcbbea29e748ac28f7e80e9b010392063770" +dependencies = [ + "sha1_smol", +] + +[[package]] +name = "sha1_smol" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012" + [[package]] name = "sha2" version = "0.9.8" @@ -4438,6 +4505,15 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" +[[package]] +name = "standback" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e113fb6f3de07a243d434a56ec6f186dfd51cb08448239fe7bcae73f87ff28ff" +dependencies = [ + "version_check", +] + [[package]] name = "static_assertions" version = "0.1.1" @@ -4456,6 +4532,55 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef5430c8e36b713e13b48a9f709cc21e046723fe44ce34587b73a830203b533e" +[[package]] +name = "stdweb" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d022496b16281348b52d0e30ae99e01a73d737b2f45d38fed4edf79f9325a1d5" +dependencies = [ + "discard", + "rustc_version 0.2.3", + "stdweb-derive", + "stdweb-internal-macros", + "stdweb-internal-runtime", + "wasm-bindgen", +] + +[[package]] +name = "stdweb-derive" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef" +dependencies = [ + "proc-macro2", + "quote", + "serde", + "serde_derive", + "syn", +] + +[[package]] +name = "stdweb-internal-macros" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11" +dependencies = [ + "base-x", + "proc-macro2", + "quote", + "serde", + "serde_derive", + "serde_json", + "sha1", + "syn", +] + +[[package]] +name = "stdweb-internal-runtime" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0" + [[package]] name = "str-buf" version = "1.0.5" @@ -4638,14 +4763,42 @@ dependencies = [ [[package]] name = "time" -version = "0.1.43" +version = "0.2.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" +checksum = "4752a97f8eebd6854ff91f1c1824cd6160626ac4bd44287f7f4ea2035a02a242" dependencies = [ + "const_fn", "libc", + "standback", + "stdweb 0.4.20", + "time-macros", + "version_check", "winapi", ] +[[package]] +name = "time-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "957e9c6e26f12cb6d0dd7fc776bb67a706312e7299aed74c8dd5b17ebb27e2f1" +dependencies = [ + "proc-macro-hack", + "time-macros-impl", +] + +[[package]] +name = "time-macros-impl" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd3c141a1b43194f3f56a1411225df8646c55781d5f26db825b3d98507eb482f" +dependencies = [ + "proc-macro-hack", + "proc-macro2", + "quote", + "standback", + "syn", +] + [[package]] name = "tinytemplate" version = "1.2.1" @@ -4748,30 +4901,6 @@ version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b63708a265f51345575b27fe43f9500ad611579e764c79edbc2037b1121959ec" -[[package]] -name = "typetag" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "422619e1a7299befb977a1f6d8932c499f6151dbcafae715193570860cae8f07" -dependencies = [ - "erased-serde", - "inventory", - "lazy_static", - "serde", - "typetag-impl", -] - -[[package]] -name = "typetag-impl" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "504f9626fe6cc1c376227864781996668e15c1ff251d222f63ef17f310bf1fec" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "ucd-trie" version = "0.1.3" @@ -4961,16 +5090,18 @@ checksum = "3d958d035c4438e28c70e4321a2911302f10135ce78a9c7834c0cab4123d06a2" [[package]] name = "wasmer" -version = "2.0.0" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f52e455a01d0fac439cd7a96ba9b519bdc84e923a5b96034054697ebb17cd75" +checksum = "f727a39e7161f7438ddb8eafe571b67c576a8c2fb459f666d9053b5bba4afdea" dependencies = [ "cfg-if 1.0.0", "indexmap", + "js-sys", "loupe", "more-asserts", "target-lexicon", "thiserror", + "wasm-bindgen", "wasmer-compiler", "wasmer-compiler-cranelift", "wasmer-compiler-singlepass", @@ -4980,14 +5111,15 @@ dependencies = [ "wasmer-engine-universal", "wasmer-types", "wasmer-vm", + "wat", "winapi", ] [[package]] name = "wasmer-compiler" -version = "2.0.0" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc86dda6f715f03104800be575a38382b35c3962953af9e9d8722dcf0bd2458f" +checksum = "4e9951599222eb12bd13d4d91bcded0a880e4c22c2dfdabdf5dc7e5e803b7bf3" dependencies = [ "enumset", "loupe", @@ -5004,18 +5136,19 @@ dependencies = [ [[package]] name = "wasmer-compiler-cranelift" -version = "2.0.0" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a570746cbec434179e2d53357973a34dfdb208043104e8fac3b7b0023015cf6" +checksum = "44c83273bce44e668f3a2b9ccb7f1193db918b1d6806f64acc5ff71f6ece5f20" dependencies = [ "cranelift-codegen", "cranelift-entity", "cranelift-frontend", - "gimli 0.24.0", + "gimli 0.25.0", "loupe", "more-asserts", "rayon", "smallvec", + "target-lexicon", "tracing", "wasmer-compiler", "wasmer-types", @@ -5024,9 +5157,9 @@ dependencies = [ [[package]] name = "wasmer-compiler-singlepass" -version = "2.0.0" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9429b9f7708c582d855b1787f09c7029ff23fb692550d4a1cc351c8ea84c3014" +checksum = "5432e993840cdb8e6875ddc8c9eea64e7a129579b4706bd91b8eb474d9c4a860" dependencies = [ "byteorder", "dynasm", @@ -5043,9 +5176,9 @@ dependencies = [ [[package]] name = "wasmer-derive" -version = "2.0.0" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ee7b351bcc1e782997c72dc0b5b328f3ddcad4813b8ce3cac3f25ae5a4ab56b" +checksum = "458dbd9718a837e6dbc52003aef84487d79eedef5fa28c7d28b6784be98ac08e" dependencies = [ "proc-macro-error", "proc-macro2", @@ -5055,14 +5188,15 @@ dependencies = [ [[package]] name = "wasmer-engine" -version = "2.0.0" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8454ead320a4017ba36ddd9ab4fbf7776fceea6ab0b79b5e53664a1682569fc3" +checksum = "6ed603a6d037ebbb14014d7f739ae996a78455a4b86c41cfa4e81c590a1253b9" dependencies = [ "backtrace", + "enumset", "lazy_static", "loupe", - "memmap2 0.2.3", + "memmap2 0.5.3", "more-asserts", "rustc-demangle", "serde", @@ -5076,14 +5210,17 @@ dependencies = [ [[package]] name = "wasmer-engine-dylib" -version = "2.0.0" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6aa390d123ebe23d5315c39f6063fcc18319661d03c8000f23d0fe1c011e8135" +checksum = "ccd7fdc60e252a795c849b3f78a81a134783051407e7e279c10b7019139ef8dc" dependencies = [ "cfg-if 1.0.0", + "enum-iterator", + "enumset", "leb128", "libloading 0.7.1", "loupe", + "object 0.28.3", "rkyv", "serde", "tempfile", @@ -5098,11 +5235,13 @@ dependencies = [ [[package]] name = "wasmer-engine-universal" -version = "2.0.0" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dffe8015f08915eb4939ebc8e521cde8246f272f5197ea60d46214ac5aef285" +checksum = "dcff0cd2c01a8de6009fd863b14ea883132a468a24f2d2ee59dc34453d3a31b5" dependencies = [ "cfg-if 1.0.0", + "enum-iterator", + "enumset", "leb128", "loupe", "region", @@ -5116,11 +5255,11 @@ dependencies = [ [[package]] name = "wasmer-object" -version = "2.0.0" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c541c985799fc1444702501c15d41becfb066c92d9673defc1c7417fd8739e15" +checksum = "24ce18ac2877050e59580d27ee1a88f3192d7a31e77fbba0852abc7888d6e0b5" dependencies = [ - "object 0.25.3", + "object 0.28.3", "thiserror", "wasmer-compiler", "wasmer-types", @@ -5128,9 +5267,9 @@ dependencies = [ [[package]] name = "wasmer-types" -version = "2.0.0" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c91f75d3c31f8b1f8d818ff49624fc974220243cbc07a2252f408192e97c6b51" +checksum = "659fa3dd6c76f62630deff4ac8c7657b07f0b1e4d7e0f8243a552b9d9b448e24" dependencies = [ "indexmap", "loupe", @@ -5140,14 +5279,26 @@ dependencies = [ ] [[package]] -name = "wasmer-vm" -version = "2.0.0" +name = "wasmer-vfs" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469a12346a4831e7dac639b9646d8c9b24c7d2cf0cf458b77f489edb35060c1f" +checksum = "f02fc47308cf5cf2cc039ec61c098773320b3d3c099434f20580bd143beee63b" +dependencies = [ + "libc", + "thiserror", + "tracing", +] + +[[package]] +name = "wasmer-vm" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afdc46158517c2769f9938bc222a7d41b3bb330824196279d8aa2d667cd40641" dependencies = [ "backtrace", "cc", "cfg-if 1.0.0", + "enum-iterator", "indexmap", "libc", "loupe", @@ -5163,31 +5314,30 @@ dependencies = [ [[package]] name = "wasmer-wasi" -version = "2.0.0" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a992dcafd11c584f3b8d84b7b4c6af350b63db03cf4452fc38647e8eab45994" +checksum = "3087d48fe015928118ae23f66f05b533e75fbea5dfcd64c75a74b7b5f941cc65" dependencies = [ - "bincode", + "cfg-if 1.0.0", "generational-arena", "getrandom", "libc", - "serde", "thiserror", "tracing", - "typetag", + "wasm-bindgen", "wasmer", + "wasmer-vfs", "wasmer-wasi-types", "winapi", ] [[package]] name = "wasmer-wasi-types" -version = "2.0.0" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55a275df0190f65f9e62f25b6bc8505a55cc643e433c822fb03a5e3e11fe1c29" +checksum = "69adbd8d0d89cd19fb8b1e0252c76e3f72dbc65c944f0db7a9c28c4157fbcd3a" dependencies = [ "byteorder", - "serde", "time", "wasmer-types", ] @@ -5198,6 +5348,26 @@ version = "0.78.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "52144d4c78e5cf8b055ceab8e5fa22814ce4315d6002ad32cfd914f37c12fd65" +[[package]] +name = "wast" +version = "40.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bb4f48a8b083dbc50e291e430afb8f524092bb00428957bcc63f49f856c64ac" +dependencies = [ + "leb128", + "memchr", + "unicode-width", +] + +[[package]] +name = "wat" +version = "1.0.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0401b6395ce0db91629a75b29597ccb66ea29950af9fc859f1bb3a736609c76e" +dependencies = [ + "wast", +] + [[package]] name = "wayland-client" version = "0.28.6" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 65921d9495..06f9902544 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -68,17 +68,17 @@ mimalloc = { version = "0.1.26", default-features = false } target-lexicon = "0.12.3" tempfile = "3.2.0" -wasmer-wasi = { version = "2.0.0", optional = true } +wasmer-wasi = { version = "2.2.1", optional = true } # Wasmer singlepass compiler only works on x86_64. [target.'cfg(target_arch = "x86_64")'.dependencies] -wasmer = { version = "2.0.0", optional = true, default-features = false, features = ["default-singlepass", "default-universal"] } +wasmer = { version = "2.2.1", optional = true, default-features = false, features = ["singlepass", "universal"] } [target.'cfg(not(target_arch = "x86_64"))'.dependencies] -wasmer = { version = "2.0.0", optional = true, default-features = false, features = ["default-cranelift", "default-universal"] } +wasmer = { version = "2.2.1", optional = true, default-features = false, features = ["cranelift", "universal"] } [dev-dependencies] -wasmer-wasi = "2.0.0" +wasmer-wasi = "2.2.1" pretty_assertions = "1.0.0" roc_test_utils = { path = "../test_utils" } indoc = "1.0.3" @@ -88,10 +88,10 @@ cli_utils = { path = "../cli_utils" } # Wasmer singlepass compiler only works on x86_64. [target.'cfg(target_arch = "x86_64")'.dev-dependencies] -wasmer = { version = "2.0.0", default-features = false, features = ["default-singlepass", "default-universal"] } +wasmer = { version = "2.2.1", default-features = false, features = ["singlepass", "universal"] } [target.'cfg(not(target_arch = "x86_64"))'.dev-dependencies] -wasmer = { version = "2.0.0", default-features = false, features = ["default-cranelift", "default-universal"] } +wasmer = { version = "2.2.1", default-features = false, features = ["cranelift", "universal"] } [[bench]] name = "time_bench" diff --git a/compiler/test_gen/Cargo.toml b/compiler/test_gen/Cargo.toml index e1adaa8ef4..45a7d2ddf7 100644 --- a/compiler/test_gen/Cargo.toml +++ b/compiler/test_gen/Cargo.toml @@ -39,16 +39,16 @@ libc = "0.2.106" inkwell = { path = "../../vendor/inkwell" } target-lexicon = "0.12.3" libloading = "0.7.1" -wasmer-wasi = "2.0.0" +wasmer-wasi = "2.2.1" tempfile = "3.2.0" indoc = "1.0.3" # Wasmer singlepass compiler only works on x86_64. [target.'cfg(target_arch = "x86_64")'.dev-dependencies] -wasmer = { version = "2.0.0", default-features = false, features = ["default-singlepass", "default-universal"] } +wasmer = { version = "2.2.1", default-features = false, features = ["singlepass", "universal"] } [target.'cfg(not(target_arch = "x86_64"))'.dev-dependencies] -wasmer = { version = "2.0.0", default-features = false, features = ["default-cranelift", "default-universal"] } +wasmer = { version = "2.2.1", default-features = false, features = ["cranelift", "universal"] } [features] default = ["gen-llvm"] diff --git a/compiler/test_gen/src/helpers/from_wasmer_memory.rs b/compiler/test_gen/src/helpers/from_wasmer_memory.rs index 84267772e2..20a05aab0c 100644 --- a/compiler/test_gen/src/helpers/from_wasmer_memory.rs +++ b/compiler/test_gen/src/helpers/from_wasmer_memory.rs @@ -1,5 +1,6 @@ use roc_gen_wasm::wasm32_sized::Wasm32Sized; use roc_std::{ReferenceCount, RocDec, RocList, RocOrder, RocStr}; +use std::convert::TryInto; pub trait FromWasmerMemory: Wasm32Sized { fn decode(memory: &wasmer::Memory, offset: u32) -> Self; @@ -17,9 +18,9 @@ macro_rules! from_wasm_memory_primitive_decode { let raw_ptr = ptr as *mut u8; let slice = unsafe { std::slice::from_raw_parts_mut(raw_ptr, width) }; - let ptr: wasmer::WasmPtr = wasmer::WasmPtr::new(offset); - let foobar = (ptr.deref(memory, 0, width as u32)).unwrap(); - let wasm_slice = unsafe { std::mem::transmute(foobar) }; + let memory_bytes: &[u8] = unsafe { memory.data_unchecked() }; + let index = offset as usize; + let wasm_slice = &memory_bytes[index..][..width]; slice.copy_from_slice(wasm_slice); @@ -108,12 +109,16 @@ impl FromWasmerMemory for &'_ T { impl FromWasmerMemory for [T; N] { fn decode(memory: &wasmer::Memory, offset: u32) -> Self { - let ptr: wasmer::WasmPtr = wasmer::WasmPtr::new(offset); - let width = ::SIZE_OF_WASM as u32 * N as u32; - let foobar = (ptr.deref(memory, 0, width)).unwrap(); - let wasm_slice: &[T; N] = unsafe { &*(foobar as *const _ as *const [T; N]) }; + let memory_bytes: &[u8] = unsafe { memory.data_unchecked() }; + let index = offset as usize; - wasm_slice.clone() + debug_assert!(memory_bytes.len() >= index + (N * ::SIZE_OF_WASM)); + + let slice_bytes: &[u8] = &memory_bytes[index..][..N]; + let slice: &[T] = unsafe { std::mem::transmute(slice_bytes) }; + let array: &[T; N] = slice.try_into().expect("incorrect length"); + + array.clone() } } diff --git a/compiler/test_gen/src/helpers/llvm.rs b/compiler/test_gen/src/helpers/llvm.rs index e67a612c28..aeba51ad8c 100644 --- a/compiler/test_gen/src/helpers/llvm.rs +++ b/compiler/test_gen/src/helpers/llvm.rs @@ -414,13 +414,14 @@ fn wasm_roc_panic(address: u32, tag_id: u32) { MEMORY.with(|f| { let memory = f.borrow().unwrap(); - let ptr: wasmer::WasmPtr = wasmer::WasmPtr::new(address); - let width = 100; - let c_ptr = (ptr.deref(memory, 0, width)).unwrap(); + let memory_bytes: &[u8] = unsafe { memory.data_unchecked() }; + let index = address as usize; + let slice = &memory_bytes[index..]; + let c_ptr: *const u8 = slice.as_ptr(); use std::ffi::CStr; use std::os::raw::c_char; - let slice = unsafe { CStr::from_ptr(c_ptr as *const _ as *const c_char) }; + let slice = unsafe { CStr::from_ptr(c_ptr as *const c_char) }; string = slice.to_str().unwrap(); }); diff --git a/compiler/test_gen/src/helpers/wasm.rs b/compiler/test_gen/src/helpers/wasm.rs index 0c59df3cf5..64491fcd92 100644 --- a/compiler/test_gen/src/helpers/wasm.rs +++ b/compiler/test_gen/src/helpers/wasm.rs @@ -1,4 +1,3 @@ -use core::cell::Cell; use roc_gen_wasm::wasm_module::{Export, ExportType}; use std::collections::hash_map::DefaultHasher; use std::hash::{Hash, Hasher}; @@ -280,7 +279,7 @@ where // Read the actual refcount values let refcount_ptr_array: WasmPtr, wasmer::Array> = WasmPtr::new(4 + refcount_vector_addr as u32); - let refcount_ptrs: &[Cell>] = refcount_ptr_array + let refcount_ptrs = refcount_ptr_array .deref(memory, 0, num_refcounts as u32) .unwrap(); diff --git a/repl_test/Cargo.toml b/repl_test/Cargo.toml index 7523407865..4ab8c31292 100644 --- a/repl_test/Cargo.toml +++ b/repl_test/Cargo.toml @@ -12,17 +12,17 @@ lazy_static = "1.4.0" [dev-dependencies] indoc = "1.0.3" strip-ansi-escapes = "0.1.1" -wasmer-wasi = "2.0.0" +wasmer-wasi = "2.2.1" roc_repl_cli = {path = "../repl_cli"} roc_test_utils = {path = "../test_utils"} # Wasmer singlepass compiler only works on x86_64. [target.'cfg(target_arch = "x86_64")'.dev-dependencies] -wasmer = { version = "2.0.0", default-features = false, features = ["default-singlepass", "default-universal"] } +wasmer = { version = "2.2.1", default-features = false, features = ["singlepass", "universal"] } [target.'cfg(not(target_arch = "x86_64"))'.dev-dependencies] -wasmer = { version = "2.0.0", default-features = false, features = ["default-cranelift", "default-universal"] } +wasmer = { version = "2.2.1", default-features = false, features = ["cranelift", "universal"] } [features] wasm = [] From 5fffea969a50a6af6432c652e39f76a56b9a0233 Mon Sep 17 00:00:00 2001 From: Brian Carroll Date: Tue, 3 May 2022 19:11:56 +0100 Subject: [PATCH 770/846] Provide a way for non-wasm Rust code to find the WASI libc --- Cargo.lock | 5 ++++ compiler/build/Cargo.toml | 3 ++- compiler/build/src/link.rs | 10 ++++---- wasi-libc-sys/.gitignore | 1 + wasi-libc-sys/build.rs | 51 +++++++++++++++++++++----------------- wasi-libc-sys/src/lib.rs | 12 +++++++-- 6 files changed, 51 insertions(+), 31 deletions(-) create mode 100644 wasi-libc-sys/.gitignore diff --git a/Cargo.lock b/Cargo.lock index 00722d3728..7764e98cf5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3428,6 +3428,7 @@ dependencies = [ "serde_json", "target-lexicon", "tempfile", + "wasi_libc_sys", ] [[package]] @@ -4893,6 +4894,10 @@ version = "0.10.2+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" +[[package]] +name = "wasi_libc_sys" +version = "0.1.0" + [[package]] name = "wasm-bindgen" version = "0.2.79" diff --git a/compiler/build/Cargo.toml b/compiler/build/Cargo.toml index 218f783af5..cf2f32d230 100644 --- a/compiler/build/Cargo.toml +++ b/compiler/build/Cargo.toml @@ -31,6 +31,7 @@ libloading = "0.7.1" tempfile = "3.2.0" inkwell = { path = "../../vendor/inkwell", optional = true } target-lexicon = "0.12.3" +wasi_libc_sys = { path = "../../wasi-libc-sys", optional = true } [target.'cfg(target_os = "macos")'.dependencies] serde_json = "1.0.69" @@ -40,7 +41,7 @@ target-arm = [] target-aarch64 = ["roc_gen_dev/target-aarch64"] target-x86 = [] target-x86_64 = ["roc_gen_dev/target-x86_64"] -target-wasm32 = ["roc_gen_wasm"] +target-wasm32 = ["roc_gen_wasm", "wasi_libc_sys"] # This is a separate feature because when we generate docs on Netlify, # it doesn't have LLVM installed. (Also, it doesn't need to do code gen.) diff --git a/compiler/build/src/link.rs b/compiler/build/src/link.rs index bcee333e6e..02d5ee7208 100644 --- a/compiler/build/src/link.rs +++ b/compiler/build/src/link.rs @@ -72,12 +72,12 @@ fn find_zig_str_path() -> PathBuf { } fn find_wasi_libc_path() -> PathBuf { + use wasi_libc_sys::WASI_LIBC_PATH; + // Environment variable defined in wasi-libc-sys/build.rs - if let Ok(wasi_libc_path) = std::env::var("WASI_LIBC_SYS_PATH") { - let wasi_libc_pathbuf = PathBuf::from(&wasi_libc_path); - if std::path::Path::exists(&wasi_libc_pathbuf) { - return wasi_libc_pathbuf; - } + let wasi_libc_pathbuf = PathBuf::from(WASI_LIBC_PATH); + if std::path::Path::exists(&wasi_libc_pathbuf) { + return wasi_libc_pathbuf; } panic!("cannot find `wasi-libc.a`") diff --git a/wasi-libc-sys/.gitignore b/wasi-libc-sys/.gitignore new file mode 100644 index 0000000000..9802e8fdbf --- /dev/null +++ b/wasi-libc-sys/.gitignore @@ -0,0 +1 @@ +src/generated.rs diff --git a/wasi-libc-sys/build.rs b/wasi-libc-sys/build.rs index b4d00f815d..0b318afa43 100644 --- a/wasi-libc-sys/build.rs +++ b/wasi-libc-sys/build.rs @@ -1,8 +1,8 @@ use std::env; +use std::ffi::OsStr; use std::fs; - -// Environment variable that can be used from other build scripts -const WASI_LIBC_SYS_PATH: &str = "WASI_LIBC_SYS_PATH"; +use std::path::Path; +use std::process::Command; fn main() { println!("cargo:rerun-if-changed=build.rs"); @@ -11,31 +11,36 @@ fn main() { let out_dir = env::var("OUT_DIR").unwrap(); let zig_cache_dir = format!("{}/zig-cache", out_dir); let out_file = format!("{}/wasi-libc.a", out_dir); - println!("cargo:rustc-env={}={}", WASI_LIBC_SYS_PATH, &out_file); - - // Compile a dummy C program with Zig, putting libc into our own private cache directory - let args = [ - "build-exe", - "-target", - "wasm32-wasi", - "-lc", - "-O", - "ReleaseSmall", - "--global-cache-dir", - &zig_cache_dir, - "src/dummy.c", - &format!("-femit-bin={}/dummy.wasm", out_dir), - ]; + // Compile a dummy C program with Zig, with our own private cache directory let zig = zig_executable(); + run_command( + Path::new("."), + &zig, + [ + "build-exe", + "-target", + "wasm32-wasi", + "-lc", + "-O", + "ReleaseSmall", + "--global-cache-dir", + &zig_cache_dir, + "src/dummy.c", + &format!("-femit-bin={}/dummy.wasm", out_dir), + ], + ); - // println!("{} {}", zig, args.join(" ")); + // Find the libc.a file that Zig wrote (as a side-effect of compiling the dummy program) + let find_cmd_output = run_command(Path::new("."), "find", [&zig_cache_dir, "-name", "libc.a"]); + let zig_libc_path = find_cmd_output.trim(); // get rid of a newline - run_command(Path::new("."), &zig, args); - let zig_libc_path = run_command(Path::new("."), "find", [&zig_cache_dir, "-name", "libc.a"]); + // Copy libc to where Cargo expects it + fs::copy(&zig_libc_path, &out_file).unwrap(); - // Copy libc out of Zig's cache, to where Cargo expects it - fs::copy(&zig_libc_path, &out_file); + // Generate some Rust code to indicate where the file is + let generated_rust = format!("pub const WASI_LIBC_PATH: &str = \"{}\";\n", out_file); + fs::write("src/generated.rs", generated_rust).unwrap(); } fn zig_executable() -> String { diff --git a/wasi-libc-sys/src/lib.rs b/wasi-libc-sys/src/lib.rs index 5fcf78879c..566b052ce1 100644 --- a/wasi-libc-sys/src/lib.rs +++ b/wasi-libc-sys/src/lib.rs @@ -1,7 +1,8 @@ -use core::ffi::c_void; - // Rust's libc crate doesn't support Wasm, so we provide an implementation from Zig // We define Rust signatures here as we need them, rather than trying to cover all of libc +#[cfg(target_family = "wasm")] +use core::ffi::c_void; +#[cfg(target_family = "wasm")] extern "C" { pub fn malloc(size: usize) -> *mut c_void; pub fn free(p: *mut c_void); @@ -9,3 +10,10 @@ extern "C" { pub fn memcpy(dst: *mut c_void, src: *mut c_void, n: usize) -> *mut c_void; pub fn memset(dst: *mut c_void, ch: i32, n: usize) -> *mut c_void; } + +// If a non-Wasm target is using this crate, we assume it is a build script that wants to emit Wasm +// Tell it where to find the Wasm .a file +#[cfg(not(target_family = "wasm"))] +mod generated; +#[cfg(not(target_family = "wasm"))] +pub use generated::WASI_LIBC_PATH; From fd9a92927b61614e5da862722d3a4cae5b52e99a Mon Sep 17 00:00:00 2001 From: Brian Carroll Date: Tue, 3 May 2022 19:13:32 +0100 Subject: [PATCH 771/846] Clean up a stray underscore --- compiler/test_gen/src/helpers/wasm.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/test_gen/src/helpers/wasm.rs b/compiler/test_gen/src/helpers/wasm.rs index 0c59df3cf5..d3ff03a71a 100644 --- a/compiler/test_gen/src/helpers/wasm.rs +++ b/compiler/test_gen/src/helpers/wasm.rs @@ -37,12 +37,12 @@ fn promote_expr_to_module(src: &str) -> String { pub fn compile_and_load<'a, T: Wasm32Result>( arena: &'a bumpalo::Bump, src: &str, - _test_wrapper_type_info: PhantomData, + test_wrapper_type_info: PhantomData, ) -> wasmer::Instance { let platform_bytes = load_platform_and_builtins(); let compiled_bytes = - compile_roc_to_wasm_bytes(arena, &platform_bytes, src, _test_wrapper_type_info); + compile_roc_to_wasm_bytes(arena, &platform_bytes, src, test_wrapper_type_info); if DEBUG_LOG_SETTINGS.keep_test_binary { let build_dir_hash = src_hash(src); From b3d09c9346d15a42a0f515a627c350521b8977bf Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Tue, 3 May 2022 13:52:58 -0400 Subject: [PATCH 772/846] Avoid some allocations in repl_eval --- repl_eval/src/eval.rs | 52 ++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/repl_eval/src/eval.rs b/repl_eval/src/eval.rs index 8189250917..8766d528c8 100644 --- a/repl_eval/src/eval.rs +++ b/repl_eval/src/eval.rs @@ -902,34 +902,21 @@ fn struct_to_ast<'a, M: ReplAppMemory>( let arena = env.arena; let subs = env.subs; let mut output = Vec::with_capacity_in(record_fields.len(), arena); - - let sorted_fields: Vec<_> = Vec::from_iter_in( - record_fields.sorted_iterator(env.subs, Variable::EMPTY_RECORD), - arena, - ); - let mut layout_cache = LayoutCache::new(env.target_info); - // We recalculate the layouts here because we will have compiled the record so that its fields - // are sorted by descending alignment, and then alphabetic, but the type of the record is - // always only sorted alphabetically. We want to arrange the rendered record in the order of - // the type. - let field_to_layout: MutMap = sorted_fields - .iter() - .map(|(label, field)| { - let layout = layout_cache - .from_var(arena, *field.as_inner(), env.subs) - .unwrap(); - (label.clone(), layout) - }) - .collect(); - if sorted_fields.len() == 1 { + if record_fields.len() == 1 { // this is a 1-field wrapper record around another record or 1-tag tag union - let (label, field) = sorted_fields.into_iter().next().unwrap(); + let (label, field) = record_fields + .sorted_iterator(subs, Variable::EMPTY_RECORD) + .next() + .unwrap(); let inner_content = env.subs.get_content_without_compacting(field.into_inner()); - debug_assert_eq!(field_to_layout.len(), 1); - let inner_layouts = arena.alloc([field_to_layout.into_values().next().unwrap()]); + + let layout = layout_cache + .from_var(arena, *field.as_inner(), env.subs) + .unwrap(); + let inner_layouts = arena.alloc([layout]); let loc_expr = &*arena.alloc(Loc { value: addr_to_ast( @@ -956,12 +943,27 @@ fn struct_to_ast<'a, M: ReplAppMemory>( Expr::Record(Collection::with_items(output)) } else { - debug_assert_eq!(sorted_fields.len(), field_to_layout.len()); + let sorted_fields = record_fields.sorted_iterator(subs, Variable::EMPTY_RECORD); + + // We recalculate the layouts here because we will have compiled the record so that its fields + // are sorted by descending alignment, and then alphabetic, but the type of the record is + // always only sorted alphabetically. We want to arrange the rendered record in the order of + // the type. + let field_to_layout: MutMap = sorted_fields + .map(|(label, field)| { + let layout = layout_cache + .from_var(arena, *field.as_inner(), env.subs) + .unwrap(); + (label.clone(), layout) + }) + .collect(); + + debug_assert_eq!(record_fields.len(), field_to_layout.len()); // We'll advance this as we iterate through the fields let mut field_addr = addr; - for (label, field) in sorted_fields.into_iter() { + for (label, field) in record_fields.sorted_iterator(subs, Variable::EMPTY_RECORD) { let var = field.into_inner(); let content = subs.get_content_without_compacting(var); From b14c9071f07e64c34013c018f7f5b5f87289c086 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Tue, 3 May 2022 14:12:21 -0400 Subject: [PATCH 773/846] Drop an unnecessary hash map --- repl_eval/src/eval.rs | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/repl_eval/src/eval.rs b/repl_eval/src/eval.rs index 8766d528c8..a803feb69f 100644 --- a/repl_eval/src/eval.rs +++ b/repl_eval/src/eval.rs @@ -943,38 +943,25 @@ fn struct_to_ast<'a, M: ReplAppMemory>( Expr::Record(Collection::with_items(output)) } else { - let sorted_fields = record_fields.sorted_iterator(subs, Variable::EMPTY_RECORD); + // We'll advance this as we iterate through the fields + let mut field_addr = addr; // We recalculate the layouts here because we will have compiled the record so that its fields // are sorted by descending alignment, and then alphabetic, but the type of the record is // always only sorted alphabetically. We want to arrange the rendered record in the order of // the type. - let field_to_layout: MutMap = sorted_fields - .map(|(label, field)| { - let layout = layout_cache - .from_var(arena, *field.as_inner(), env.subs) - .unwrap(); - (label.clone(), layout) - }) - .collect(); - - debug_assert_eq!(record_fields.len(), field_to_layout.len()); - - // We'll advance this as we iterate through the fields - let mut field_addr = addr; - for (label, field) in record_fields.sorted_iterator(subs, Variable::EMPTY_RECORD) { - let var = field.into_inner(); - - let content = subs.get_content_without_compacting(var); - let field_layout = field_to_layout.get(&label).unwrap(); + let content = subs.get_content_without_compacting(field.into_inner()); + let field_layout = layout_cache + .from_var(arena, field.into_inner(), env.subs) + .unwrap(); let loc_expr = &*arena.alloc(Loc { value: addr_to_ast( env, mem, field_addr, - field_layout, + &field_layout, WhenRecursive::Unreachable, content, ), From f9aeed8cc89d12c4b0ee666ca1ebdd3184df3ead Mon Sep 17 00:00:00 2001 From: Brian Carroll Date: Tue, 3 May 2022 19:23:16 +0100 Subject: [PATCH 774/846] Move wasi-libc-sys into the workspace --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 2dbc0b867d..24a4817856 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,6 +46,7 @@ members = [ "utils", "docs", "linker", + "wasi-libc-sys", ] exclude = [ "ci/bench-runner", @@ -55,7 +56,6 @@ exclude = [ "compiler/test_mono_macros", # `cargo build` would cause roc_std to be built with default features which errors on windows "roc_std", - "wasi-libc-sys", ] # Needed to be able to run `cargo run -p roc_cli --no-default-features` - # see www/build.sh for more. From 2e6047fa9a97eeb6d4aaef46094b655716ad748d Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Tue, 3 May 2022 14:26:03 -0400 Subject: [PATCH 775/846] Use into_inner over as_inner --- repl_eval/src/eval.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/repl_eval/src/eval.rs b/repl_eval/src/eval.rs index a803feb69f..55d312bfa8 100644 --- a/repl_eval/src/eval.rs +++ b/repl_eval/src/eval.rs @@ -118,8 +118,7 @@ fn unroll_newtypes_and_aliases<'a>( newtype_containers.push(NewtypeKind::RecordField( env.arena.alloc_str(label.as_str()), )); - let field_var = *field.as_inner(); - content = env.subs.get_content_without_compacting(field_var); + content = env.subs.get_content_without_compacting(field.into_inner()); } Content::Alias(_, _, real_var, _) => { // We need to pass through aliases too, because their underlying types may have @@ -912,11 +911,10 @@ fn struct_to_ast<'a, M: ReplAppMemory>( .unwrap(); let inner_content = env.subs.get_content_without_compacting(field.into_inner()); - - let layout = layout_cache - .from_var(arena, *field.as_inner(), env.subs) + let field_layout = layout_cache + .from_var(arena, field.into_inner(), env.subs) .unwrap(); - let inner_layouts = arena.alloc([layout]); + let inner_layouts = arena.alloc([field_layout]); let loc_expr = &*arena.alloc(Loc { value: addr_to_ast( From 4fad750e525a84690fc165af06acbed639f4c3ab Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Tue, 3 May 2022 14:57:47 -0400 Subject: [PATCH 776/846] clip clop clip clop clip clop --- repl_eval/src/eval.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repl_eval/src/eval.rs b/repl_eval/src/eval.rs index 55d312bfa8..8dfdacb32c 100644 --- a/repl_eval/src/eval.rs +++ b/repl_eval/src/eval.rs @@ -5,7 +5,7 @@ use std::cmp::{max_by_key, min_by_key}; use roc_builtins::bitcode::{FloatWidth, IntWidth}; use roc_collections::all::MutMap; use roc_module::called_via::CalledVia; -use roc_module::ident::{Lowercase, TagName}; +use roc_module::ident::TagName; use roc_module::symbol::{Interns, ModuleId, Symbol}; use roc_mono::ir::ProcLayout; use roc_mono::layout::{ From 46c285c43aa0c1da417ce6e5c7714ec06998e7e2 Mon Sep 17 00:00:00 2001 From: Brian Carroll Date: Wed, 4 May 2022 07:26:45 +0100 Subject: [PATCH 777/846] Add new top-level dir to Earthfile --- Earthfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Earthfile b/Earthfile index 325825050d..40b2c8ba89 100644 --- a/Earthfile +++ b/Earthfile @@ -54,7 +54,7 @@ install-zig-llvm-valgrind-clippy-rustfmt: copy-dirs: FROM +install-zig-llvm-valgrind-clippy-rustfmt - COPY --dir cli cli_utils compiler docs editor ast code_markup error_macros highlight utils test_utils reporting repl_cli repl_eval repl_test repl_wasm repl_www roc_std vendor examples linker Cargo.toml Cargo.lock version.txt www ./ + COPY --dir cli cli_utils compiler docs editor ast code_markup error_macros highlight utils test_utils reporting repl_cli repl_eval repl_test repl_wasm repl_www roc_std vendor examples linker Cargo.toml Cargo.lock version.txt www wasi-libc-sys ./ test-zig: FROM +install-zig-llvm-valgrind-clippy-rustfmt From 2845371c503ba445ee2ababf5b92a1e476bdd186 Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Wed, 4 May 2022 14:00:39 +0200 Subject: [PATCH 778/846] build before checking fmt and clippy for rust code gen --- Earthfile | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Earthfile b/Earthfile index 40b2c8ba89..5bbfa587b2 100644 --- a/Earthfile +++ b/Earthfile @@ -61,14 +61,19 @@ test-zig: COPY --dir compiler/builtins/bitcode ./ RUN cd bitcode && ./run-tests.sh && ./run-wasm-tests.sh -check-clippy: +build-rust-test: FROM +copy-dirs + RUN --mount=type=cache,target=$SCCACHE_DIR \ + cargo test --locked --release --features with_sound --workspace --no-run && sccache --show-stats + +check-clippy: + FROM +build-rust-test RUN cargo clippy -V RUN --mount=type=cache,target=$SCCACHE_DIR \ cargo clippy -- -D warnings check-rustfmt: - FROM +copy-dirs + FROM +build-rust-test RUN cargo fmt --version RUN cargo fmt --all -- --check @@ -78,7 +83,7 @@ check-typos: RUN typos test-rust: - FROM +copy-dirs + FROM +build-rust-test ENV RUST_BACKTRACE=1 # for race condition problem with cli test ENV ROC_NUM_WORKERS=1 From 2ec6f547766c4d3f23fa1e06ae389e60f779d79c Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Wed, 4 May 2022 14:22:25 +0200 Subject: [PATCH 779/846] corrected formatting of generated code --- wasi-libc-sys/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wasi-libc-sys/build.rs b/wasi-libc-sys/build.rs index 0b318afa43..5ee328f3e4 100644 --- a/wasi-libc-sys/build.rs +++ b/wasi-libc-sys/build.rs @@ -39,7 +39,7 @@ fn main() { fs::copy(&zig_libc_path, &out_file).unwrap(); // Generate some Rust code to indicate where the file is - let generated_rust = format!("pub const WASI_LIBC_PATH: &str = \"{}\";\n", out_file); + let generated_rust = format!("pub const WASI_LIBC_PATH: &str =\n\t\"{}\";\n", out_file); fs::write("src/generated.rs", generated_rust).unwrap(); } From ad1d23d0a46998f5da08057767198e7e4660fca6 Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Wed, 4 May 2022 14:39:05 +0200 Subject: [PATCH 780/846] use 4 spaces instead of tab --- wasi-libc-sys/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wasi-libc-sys/build.rs b/wasi-libc-sys/build.rs index 5ee328f3e4..d07f9c137b 100644 --- a/wasi-libc-sys/build.rs +++ b/wasi-libc-sys/build.rs @@ -39,7 +39,7 @@ fn main() { fs::copy(&zig_libc_path, &out_file).unwrap(); // Generate some Rust code to indicate where the file is - let generated_rust = format!("pub const WASI_LIBC_PATH: &str =\n\t\"{}\";\n", out_file); + let generated_rust = format!("pub const WASI_LIBC_PATH: &str =\n \"{}\";\n", out_file); fs::write("src/generated.rs", generated_rust).unwrap(); } From dc8a6abf22faf1c69cdc6ca307d1fb2e3d5cfbd7 Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Wed, 4 May 2022 14:41:02 +0200 Subject: [PATCH 781/846] updated clap --- Cargo.lock | 32 ++++++++------ ci/bench-runner/Cargo.toml | 2 +- cli/Cargo.toml | 2 +- cli/src/lib.rs | 86 +++++++++++++++++++------------------- linker/Cargo.toml | 2 +- linker/src/lib.rs | 38 ++++++++--------- 6 files changed, 84 insertions(+), 78 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 88a24e0a73..e8e441fd73 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -474,17 +474,26 @@ dependencies = [ [[package]] name = "clap" -version = "3.0.0-beta.5" +version = "3.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "feff3878564edb93745d58cf63e17b63f24142506e7a20c87a5521ed7bfb1d63" +checksum = "85a35a599b11c089a7f49105658d089b8f2cf0882993c17daf6de15285c2c35d" dependencies = [ "atty", "bitflags", + "clap_lex", "indexmap", - "os_str_bytes", "strsim 0.10.0", "termcolor", - "textwrap 0.14.2", + "textwrap 0.15.0", +] + +[[package]] +name = "clap_lex" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a37c35f1112dad5e6e0b1adaff798507497a18fceeb30cceb3bae7d1427b9213" +dependencies = [ + "os_str_bytes", ] [[package]] @@ -2640,12 +2649,9 @@ dependencies = [ [[package]] name = "os_str_bytes" -version = "4.2.0" +version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "addaa943333a514159c80c97ff4a93306530d965d27e139188283cd13e06a799" -dependencies = [ - "memchr", -] +checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64" [[package]] name = "output_vt100" @@ -3497,7 +3503,7 @@ name = "roc_cli" version = "0.1.0" dependencies = [ "bumpalo", - "clap 3.0.0-beta.5", + "clap 3.1.15", "cli_utils", "const_format", "criterion 0.3.5 (git+https://github.com/Anton-4/criterion.rs)", @@ -3756,7 +3762,7 @@ version = "0.1.0" dependencies = [ "bincode", "bumpalo", - "clap 3.0.0-beta.5", + "clap 3.1.15", "iced-x86", "memmap2 0.5.3", "object 0.26.2", @@ -4728,9 +4734,9 @@ dependencies = [ [[package]] name = "textwrap" -version = "0.14.2" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80" +checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" [[package]] name = "thiserror" diff --git a/ci/bench-runner/Cargo.toml b/ci/bench-runner/Cargo.toml index 31fcd9cdda..91b5ca7947 100644 --- a/ci/bench-runner/Cargo.toml +++ b/ci/bench-runner/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -clap = "3.0.0-beta.2" +clap = "3.1.15" regex = "1.5.4" is_executable = "1.0.1" ring = "0.16.20" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 06f9902544..4e019df2c6 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -61,7 +61,7 @@ roc_error_macros = { path = "../error_macros" } roc_editor = { path = "../editor", optional = true } roc_linker = { path = "../linker" } roc_repl_cli = { path = "../repl_cli", optional = true } -clap = { version = "3.0.0-beta.5", default-features = false, features = ["std", "color", "suggestions"] } +clap = { version = "3.1.15", default-features = false, features = ["std", "color", "suggestions"] } const_format = "0.2.22" bumpalo = { version = "3.8.0", features = ["collections"] } mimalloc = { version = "0.1.26", default-features = false } diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 25f831d1f0..4d3dc134bc 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -3,7 +3,8 @@ extern crate const_format; use build::BuiltFile; use bumpalo::Bump; -use clap::{App, AppSettings, Arg, ArgMatches}; +use clap::Command; +use clap::{Arg, ArgMatches}; use roc_build::link::LinkType; use roc_error_macros::user_error; use roc_load::LoadingProblem; @@ -13,7 +14,6 @@ use std::io; use std::path::Path; use std::path::PathBuf; use std::process; -use std::process::Command; use target_lexicon::BinaryFormat; use target_lexicon::{ Architecture, Environment, OperatingSystem, Triple, Vendor, X86_32Architecture, @@ -52,39 +52,39 @@ pub const ARGS_FOR_APP: &str = "ARGS_FOR_APP"; const VERSION: &str = include_str!("../../version.txt"); -pub fn build_app<'a>() -> App<'a> { - let app = App::new("roc") +pub fn build_app<'a>() -> Command<'a> { + let app = Command::new("roc") .version(concatcp!(VERSION, "\n")) .about("Runs the given .roc file, if there are no compilation errors.\nUse one of the SUBCOMMANDS below to do something else!") - .subcommand(App::new(CMD_BUILD) + .subcommand(Command::new(CMD_BUILD) .about("Build a binary from the given .roc file, but don't run it") .arg( Arg::new(ROC_FILE) - .about("The .roc file to build") + .help("The .roc file to build") .required(true), ) .arg( Arg::new(FLAG_OPTIMIZE) .long(FLAG_OPTIMIZE) - .about("Optimize your compiled Roc program to run faster. (Optimization takes time to complete.)") + .help("Optimize your compiled Roc program to run faster. (Optimization takes time to complete.)") .required(false), ) .arg( Arg::new(FLAG_OPT_SIZE) .long(FLAG_OPT_SIZE) - .about("Optimize your compiled Roc program to have a small binary size. (Optimization takes time to complete.)") + .help("Optimize your compiled Roc program to have a small binary size. (Optimization takes time to complete.)") .required(false), ) .arg( Arg::new(FLAG_DEV) .long(FLAG_DEV) - .about("Make compilation as fast as possible. (Runtime performance may suffer)") + .help("Make compilation as fast as possible. (Runtime performance may suffer)") .required(false), ) .arg( Arg::new(FLAG_TARGET) .long(FLAG_TARGET) - .about("Choose a different target") + .help("Choose a different target") .default_value(Target::default().as_str()) .possible_values(Target::OPTIONS) .required(false), @@ -92,66 +92,66 @@ pub fn build_app<'a>() -> App<'a> { .arg( Arg::new(FLAG_LIB) .long(FLAG_LIB) - .about("Build a C library instead of an executable.") + .help("Build a C library instead of an executable.") .required(false), ) .arg( Arg::new(FLAG_NO_LINK) .long(FLAG_NO_LINK) - .about("Does not link. Instead just outputs the `.o` file") + .help("Does not link. Instead just outputs the `.o` file") .required(false), ) .arg( Arg::new(FLAG_DEBUG) .long(FLAG_DEBUG) - .about("Store LLVM debug information in the generated program") + .help("Store LLVM debug information in the generated program") .required(false), ) .arg( Arg::new(FLAG_TIME) .long(FLAG_TIME) - .about("Prints detailed compilation time information.") + .help("Prints detailed compilation time information.") .required(false), ) .arg( Arg::new(FLAG_LINK) .long(FLAG_LINK) - .about("Deprecated in favor of --linker") + .help("Deprecated in favor of --linker") .required(false), ) .arg( Arg::new(FLAG_LINKER) .long(FLAG_LINKER) - .about("Sets which linker to use. The surgical linker is enabeld by default only when building for wasm32 or x86_64 Linux, because those are the only targets it currently supports. Otherwise the legacy linker is used by default.") + .help("Sets which linker to use. The surgical linker is enabeld by default only when building for wasm32 or x86_64 Linux, because those are the only targets it currently supports. Otherwise the legacy linker is used by default.") .possible_values(["surgical", "legacy"]) .required(false), ) .arg( Arg::new(FLAG_PRECOMPILED) .long(FLAG_PRECOMPILED) - .about("Assumes the host has been precompiled and skips recompiling the host. (Enabled by default when using a --target other than `--target host`)") + .help("Assumes the host has been precompiled and skips recompiling the host. (Enabled by default when using a --target other than `--target host`)") .possible_values(["true", "false"]) .required(false), ) .arg( Arg::new(FLAG_VALGRIND) .long(FLAG_VALGRIND) - .about("Some assembly instructions are not supported by valgrind, this flag prevents those from being output when building the host.") + .help("Some assembly instructions are not supported by valgrind, this flag prevents those from being output when building the host.") .required(false), ) ) - .subcommand(App::new(CMD_REPL) + .subcommand(Command::new(CMD_REPL) .about("Launch the interactive Read Eval Print Loop (REPL)") ) - .subcommand(App::new(CMD_RUN) + .subcommand(Command::new(CMD_RUN) .about("Run a .roc file even if it has build errors") .arg( Arg::new(ROC_FILE) - .about("The .roc file of an app to run") + .help("The .roc file of an app to run") .required(true), ) ) - .subcommand(App::new(CMD_FORMAT) + .subcommand(Command::new(CMD_FORMAT) .about("Format a .roc file using standard Roc formatting") .arg( Arg::new(DIRECTORY_OR_FILES) @@ -161,112 +161,112 @@ pub fn build_app<'a>() -> App<'a> { .arg( Arg::new(FLAG_CHECK) .long(FLAG_CHECK) - .about("Checks that specified files are formatted. If formatting is needed, it will return a non-zero exit code.") + .help("Checks that specified files are formatted. If formatting is needed, it will return a non-zero exit code.") .required(false), ) ) - .subcommand(App::new(CMD_VERSION) + .subcommand(Command::new(CMD_VERSION) .about(concatcp!("Print the Roc compiler’s version, which is currently ", VERSION))) - .subcommand(App::new(CMD_CHECK) + .subcommand(Command::new(CMD_CHECK) .about("Check the code for problems, but doesn’t build or run it") .arg( Arg::new(FLAG_TIME) .long(FLAG_TIME) - .about("Prints detailed compilation time information.") + .help("Prints detailed compilation time information.") .required(false), ) .arg( Arg::new(ROC_FILE) - .about("The .roc file of an app to check") + .help("The .roc file of an app to check") .required(true), ) ) .subcommand( - App::new(CMD_DOCS) + Command::new(CMD_DOCS) .about("Generate documentation for Roc modules (Work In Progress)") .arg(Arg::new(DIRECTORY_OR_FILES) .index(1) .multiple_values(true) .required(false) - .about("The directory or files to build documentation for") + .help("The directory or files to build documentation for") ) ) - .setting(AppSettings::TrailingVarArg) + .trailing_var_arg(true) .arg( Arg::new(FLAG_OPTIMIZE) .long(FLAG_OPTIMIZE) - .about("Optimize the compiled program to run faster. (Optimization takes time to complete.)") + .help("Optimize the compiled program to run faster. (Optimization takes time to complete.)") .requires(ROC_FILE) .required(false), ) .arg( Arg::new(FLAG_OPT_SIZE) .long(FLAG_OPT_SIZE) - .about("Optimize the compiled program to have a small binary size. (Optimization takes time to complete.)") + .help("Optimize the compiled program to have a small binary size. (Optimization takes time to complete.)") .required(false), ) .arg( Arg::new(FLAG_DEV) .long(FLAG_DEV) - .about("Make compilation finish as soon as possible, at the expense of runtime performance.") + .help("Make compilation finish as soon as possible, at the expense of runtime performance.") .required(false), ) .arg( Arg::new(FLAG_DEBUG) .long(FLAG_DEBUG) - .about("Store LLVM debug information in the generated program.") + .help("Store LLVM debug information in the generated program.") .requires(ROC_FILE) .required(false), ) .arg( Arg::new(FLAG_TIME) .long(FLAG_TIME) - .about("Prints detailed compilation time information.") + .help("Prints detailed compilation time information.") .required(false), ) .arg( Arg::new(FLAG_LINK) .long(FLAG_LINK) - .about("Deprecated in favor of --linker") + .help("Deprecated in favor of --linker") .required(false), ) .arg( Arg::new(FLAG_LINKER) .long(FLAG_LINKER) - .about("Sets which linker to use. The surgical linker is enabeld by default only when building for wasm32 or x86_64 Linux, because those are the only targets it currently supports. Otherwise the legacy linker is used by default.") + .help("Sets which linker to use. The surgical linker is enabeld by default only when building for wasm32 or x86_64 Linux, because those are the only targets it currently supports. Otherwise the legacy linker is used by default.") .possible_values(["surgical", "legacy"]) .required(false), ) .arg( Arg::new(FLAG_PRECOMPILED) .long(FLAG_PRECOMPILED) - .about("Assumes the host has been precompiled and skips recompiling the host. (Enabled by default when using `roc build` with a --target other than `--target host`)") + .help("Assumes the host has been precompiled and skips recompiling the host. (Enabled by default when using `roc build` with a --target other than `--target host`)") .possible_values(["true", "false"]) .required(false), ) .arg( Arg::new(ROC_FILE) - .about("The .roc file of an app to build and run") + .help("The .roc file of an app to build and run") .required(false), ) .arg( Arg::new(ARGS_FOR_APP) - .about("Arguments to pass into the app being run") + .help("Arguments to pass into the app being run") .requires(ROC_FILE) .multiple_values(true), ); if cfg!(feature = "editor") { app.subcommand( - App::new(CMD_EDIT) + Command::new(CMD_EDIT) .about("Launch the Roc editor (Work In Progress)") .arg( Arg::new(DIRECTORY_OR_FILES) .index(1) .multiple_values(true) .required(false) - .about("(optional) The directory or files to open on launch."), + .help("(optional) The directory or files to open on launch."), ), ) } else { @@ -570,7 +570,7 @@ fn roc_run( run_with_wasmer(generated_filename, &args); return Ok(0); } - _ => Command::new(&binary_path), + _ => std::process::Command::new(&binary_path), }; if let Architecture::Wasm32 = triple.architecture { diff --git a/linker/Cargo.toml b/linker/Cargo.toml index d71102aa95..497c8088a1 100644 --- a/linker/Cargo.toml +++ b/linker/Cargo.toml @@ -22,7 +22,7 @@ roc_mono = { path = "../compiler/mono" } roc_build = { path = "../compiler/build" } roc_collections = { path = "../compiler/collections" } bumpalo = { version = "3.8.0", features = ["collections"] } -clap = { version = "3.0.0-beta.5", default-features = false, features = ["std", "color", "suggestions"] } +clap = { version = "3.1.15", default-features = false, features = ["std", "color", "suggestions"] } iced-x86 = { version = "1.15.0", default-features = false, features = ["std", "decoder", "op_code_info", "instr_info"] } memmap2 = "0.5.3" object = { version = "0.26.2", features = ["read", "write"] } diff --git a/linker/src/lib.rs b/linker/src/lib.rs index 1b4a2a8d14..581ae2bb97 100644 --- a/linker/src/lib.rs +++ b/linker/src/lib.rs @@ -1,5 +1,5 @@ use bincode::{deserialize_from, serialize_into}; -use clap::{App, AppSettings, Arg, ArgMatches}; +use clap::{Arg, ArgMatches, Command}; use iced_x86::{Decoder, DecoderOptions, Instruction, OpCodeOperandKind, OpKind}; use memmap2::{Mmap, MmapMut}; use object::write; @@ -21,7 +21,6 @@ use std::io::{BufReader, BufWriter}; use std::mem; use std::os::raw::c_char; use std::path::Path; -use std::process::Command; use std::time::{Duration, SystemTime}; use target_lexicon::Triple; use tempfile::Builder; @@ -49,64 +48,65 @@ fn report_timing(label: &str, duration: Duration) { println!("\t{:9.3} ms {}", duration.as_secs_f64() * 1000.0, label,); } -pub fn build_app<'a>() -> App<'a> { - App::new("link") +pub fn build_app<'a>() -> Command<'a> { + Command::new("link") .about("Preprocesses a platform and surgically links it to an application.") - .setting(AppSettings::SubcommandRequiredElseHelp) + .subcommand_required(true) + .arg_required_else_help(true) .subcommand( - App::new(CMD_PREPROCESS) + Command::new(CMD_PREPROCESS) .about("Preprocesses a dynamically linked platform to prepare for linking.") .arg( Arg::new(EXEC) - .about("The dynamically linked platform executable") + .help("The dynamically linked platform executable") .required(true), ) .arg( Arg::new(METADATA) - .about("Where to save the metadata from preprocessing") + .help("Where to save the metadata from preprocessing") .required(true), ) .arg( Arg::new(OUT) - .about("The modified version of the dynamically linked platform executable") + .help("The modified version of the dynamically linked platform executable") .required(true), ) .arg( Arg::new(SHARED_LIB) - .about("The name of the shared library used in building the platform") + .help("The name of the shared library used in building the platform") .default_value("libapp.so"), ) .arg( Arg::new(FLAG_VERBOSE) .long(FLAG_VERBOSE) .short('v') - .about("Enable verbose printing") + .help("Enable verbose printing") .required(false), ) .arg( Arg::new(FLAG_TIME) .long(FLAG_TIME) .short('t') - .about("Print timing information") + .help("Print timing information") .required(false), ), ) .subcommand( - App::new(CMD_SURGERY) + Command::new(CMD_SURGERY) .about("Links a preprocessed platform with a Roc application.") .arg( Arg::new(APP) - .about("The Roc application object file waiting to be linked") + .help("The Roc application object file waiting to be linked") .required(true), ) .arg( Arg::new(METADATA) - .about("The metadata created by preprocessing the platform") + .help("The metadata created by preprocessing the platform") .required(true), ) .arg( Arg::new(OUT) - .about( + .help( "The modified version of the dynamically linked platform. \ It will be consumed to make linking faster.", ) @@ -116,14 +116,14 @@ pub fn build_app<'a>() -> App<'a> { Arg::new(FLAG_VERBOSE) .long(FLAG_VERBOSE) .short('v') - .about("Enable verbose printing") + .help("Enable verbose printing") .required(false), ) .arg( Arg::new(FLAG_TIME) .long(FLAG_TIME) .short('t') - .about("Print timing information") + .help("Print timing information") .required(false), ), ) @@ -243,7 +243,7 @@ fn generate_dynamic_lib( ) .expect("failed to write object to file"); - let output = Command::new("ld") + let output = std::process::Command::new("ld") .args(&[ "-shared", "-soname", From 92bba2efce1e0bed1a84f28ecc45f018a2f694ee Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Wed, 4 May 2022 15:51:06 +0200 Subject: [PATCH 782/846] clap bench fixes --- ci/bench-runner/Cargo.lock | 61 +++++++++++++------------------------ ci/bench-runner/Cargo.toml | 2 +- ci/bench-runner/src/main.rs | 5 ++- 3 files changed, 25 insertions(+), 43 deletions(-) diff --git a/ci/bench-runner/Cargo.lock b/ci/bench-runner/Cargo.lock index e0517c28db..3a58084af0 100644 --- a/ci/bench-runner/Cargo.lock +++ b/ci/bench-runner/Cargo.lock @@ -65,28 +65,26 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "3.0.0-beta.2" +version = "3.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bd1061998a501ee7d4b6d449020df3266ca3124b941ec56cf2005c3779ca142" +checksum = "85a35a599b11c089a7f49105658d089b8f2cf0882993c17daf6de15285c2c35d" dependencies = [ "atty", "bitflags", "clap_derive", + "clap_lex", "indexmap", "lazy_static", - "os_str_bytes", "strsim", "termcolor", "textwrap", - "unicode-width", - "vec_map", ] [[package]] name = "clap_derive" -version = "3.0.0-beta.2" +version = "3.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "370f715b81112975b1b69db93e0b56ea4cd4e5002ac43b2da8474106a54096a1" +checksum = "a3aab4734e083b809aaf5794e14e756d1c798d2c69c7f7de7a09a2f5214993c1" dependencies = [ "heck", "proc-macro-error", @@ -95,6 +93,15 @@ dependencies = [ "syn", ] +[[package]] +name = "clap_lex" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a37c35f1112dad5e6e0b1adaff798507497a18fceeb30cceb3bae7d1427b9213" +dependencies = [ + "os_str_bytes", +] + [[package]] name = "data-encoding" version = "2.3.2" @@ -109,12 +116,9 @@ checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" [[package]] name = "heck" -version = "0.3.3" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" -dependencies = [ - "unicode-segmentation", -] +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" [[package]] name = "hermit-abi" @@ -188,9 +192,9 @@ checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" [[package]] name = "os_str_bytes" -version = "2.4.0" +version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afb2e1c3ee07430c2cf76151675e583e0f19985fa6efae47d6848a3e2c824f85" +checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64" [[package]] name = "proc-macro-error" @@ -300,24 +304,9 @@ dependencies = [ [[package]] name = "textwrap" -version = "0.12.1" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "203008d98caf094106cfaba70acfed15e18ed3ddb7d94e49baec153a2b462789" -dependencies = [ - "unicode-width", -] - -[[package]] -name = "unicode-segmentation" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" - -[[package]] -name = "unicode-width" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" +checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" [[package]] name = "unicode-xid" @@ -331,17 +320,11 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" -[[package]] -name = "vec_map" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" - [[package]] name = "version_check" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "wasm-bindgen" diff --git a/ci/bench-runner/Cargo.toml b/ci/bench-runner/Cargo.toml index 91b5ca7947..02e775065f 100644 --- a/ci/bench-runner/Cargo.toml +++ b/ci/bench-runner/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -clap = "3.1.15" +clap = { version = "3.1.15", features = ["derive"] } regex = "1.5.4" is_executable = "1.0.1" ring = "0.16.20" diff --git a/ci/bench-runner/src/main.rs b/ci/bench-runner/src/main.rs index efccc69497..6cab1cf003 100644 --- a/ci/bench-runner/src/main.rs +++ b/ci/bench-runner/src/main.rs @@ -1,4 +1,4 @@ -use clap::{AppSettings, Clap}; +use clap::Parser; use data_encoding::HEXUPPER; use is_executable::IsExecutable; use regex::Regex; @@ -160,8 +160,7 @@ fn remove(file_or_folder: &str) { .unwrap_or_else(|_| panic!("Something went wrong trying to remove {}", file_or_folder)); } -#[derive(Clap)] -#[clap(setting = AppSettings::ColoredHelp)] +#[derive(Parser)] struct OptionalArgs { /// How many times to repeat the benchmarks. A single benchmark has to fail every for a regression to be reported. #[clap(long, default_value = "3")] From 108ad9bb86474d8ac73b75e538b3357e98e7bec2 Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Wed, 4 May 2022 17:45:36 +0200 Subject: [PATCH 783/846] fix docs generation --- cli/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 4d3dc134bc..b12b85a728 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -189,7 +189,7 @@ pub fn build_app<'a>() -> Command<'a> { .multiple_values(true) .required(false) .help("The directory or files to build documentation for") - + .allow_invalid_utf8(true) ) ) .trailing_var_arg(true) From 4304c2c2f0f46e69f1021a7bae48536276b36274 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 4 May 2022 12:49:07 -0400 Subject: [PATCH 784/846] Correct output type of flapping test The Roc program in this test returns a U8, but the tested type is marked as a U16, so it's possible we were just picking up garbage bytes. Closes #2997 --- compiler/test_gen/src/gen_num.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/test_gen/src/gen_num.rs b/compiler/test_gen/src/gen_num.rs index 7eb55da794..0240bb95d5 100644 --- a/compiler/test_gen/src/gen_num.rs +++ b/compiler/test_gen/src/gen_num.rs @@ -3225,7 +3225,7 @@ fn upcast_of_int_checked_is_zext() { "# ), 1, - u16 + u8 ) } From d57d9cc87ac7ed5de8231dd493fe9769977e9125 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 4 May 2022 22:42:31 +0200 Subject: [PATCH 785/846] use module_const over module_id --- compiler/module/src/symbol.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index e5822a8f89..218d4ac69a 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -736,7 +736,8 @@ macro_rules! define_builtins { let mut exposed_idents_by_module = VecMap::with_capacity(extra_capacity + $total); $( - debug_assert!(!exposed_idents_by_module.contains_key(&ModuleId($module_id)), r"Error setting up Builtins: when setting up module {} {:?} - the module ID {} is already present in the map. Check the map for duplicate module IDs!", $module_id, $module_name, $module_id); + let module_id = ModuleId::$module_const; + debug_assert!(!exposed_idents_by_module.contains_key(&module_id), r"Error setting up Builtins: when setting up module {} {:?} - the module ID {} is already present in the map. Check the map for duplicate module IDs!", $module_id, $module_name, $module_id); let ident_ids = { const TOTAL : usize = [ $($ident_name),+ ].len(); @@ -780,8 +781,6 @@ macro_rules! define_builtins { }; if cfg!(debug_assertions) { - let module_id = ModuleId($module_id); - let name = PQModuleName::Unqualified($module_name.into()); PackageModuleIds::insert_debug_name(module_id, &name); module_id.register_debug_idents(&ident_ids); @@ -789,7 +788,7 @@ macro_rules! define_builtins { exposed_idents_by_module.insert( - ModuleId($module_id), + module_id, ident_ids ); )+ @@ -833,7 +832,7 @@ macro_rules! define_builtins { }; $( - insert_both(ModuleId($module_id), $module_name); + insert_both(ModuleId::$module_const, $module_name); )+ ModuleIds { by_name, by_id } @@ -861,7 +860,7 @@ macro_rules! define_builtins { }; $( - insert_both(ModuleId($module_id), $module_name); + insert_both(ModuleId::$module_const, $module_name); )+ PackageModuleIds { by_name, by_id } @@ -871,7 +870,7 @@ macro_rules! define_builtins { impl Symbol { $( $( - pub const $ident_const: Symbol = Symbol::new(ModuleId($module_id), IdentId($ident_id)); + pub const $ident_const: Symbol = Symbol::new(ModuleId::$module_const, IdentId($ident_id)); )+ )+ @@ -892,7 +891,7 @@ macro_rules! define_builtins { let $imported = true; if $imported { - scope.insert($ident_name.into(), (Symbol::new(ModuleId($module_id), IdentId($ident_id)), Region::zero())); + scope.insert($ident_name.into(), (Symbol::new(ModuleId::$module_const, IdentId($ident_id)), Region::zero())); } )? )+ From 9854f068d9abb25748aa7c78037d77e32b44c172 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 4 May 2022 22:57:49 +0200 Subject: [PATCH 786/846] change the internal representation of Symbol to two u32's --- compiler/module/src/symbol.rs | 54 +++++++++++++++++++++++++---------- compiler/types/src/subs.rs | 8 +++--- 2 files changed, 43 insertions(+), 19 deletions(-) diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index 218d4ac69a..b587a6afd1 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -7,9 +7,31 @@ use snafu::OptionExt; use std::collections::HashMap; use std::{fmt, u32}; -// TODO: benchmark this as { ident_id: u32, module_id: u32 } and see if perf stays the same +// the packed(4) is needed for faster equality comparisons. With it, the structure is +// treated as a single u64, and comparison is one instruction +// +// example::eq_sym64: +// cmp rdi, rsi +// sete al +// ret +// +// while without it we get 2 extra instructions +// +// example::eq_sym64: +// xor edi, edx +// xor esi, ecx +// or esi, edi +// sete al +// ret +// +// #[repr(packed)] gives you #[repr(packed(1))], and then all your reads are unaligned +// so we set the alignment to (the natural) 4 #[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] -pub struct Symbol(u64); +#[repr(packed(4))] +pub struct Symbol { + ident_id: u32, + module_id: u32, +} // When this is `true` (which it normally should be), Symbol's Debug::fmt implementation // attempts to pretty print debug symbols using interns recorded using @@ -28,7 +50,7 @@ impl Symbol { // e.g. pub const NUM_NUM: Symbol = … pub const fn new(module_id: ModuleId, ident_id: IdentId) -> Symbol { - // The bit layout of the u64 inside a Symbol is: + // The bit layout of the inside of a Symbol is: // // |------ 32 bits -----|------ 32 bits -----| // | ident_id | module_id | @@ -37,20 +59,22 @@ impl Symbol { // module_id comes second because we need to query it more often, // and this way we can get it by truncating the u64 to u32, // whereas accessing the first slot requires a bit shift first. - let bits = ((ident_id.0 as u64) << 32) | (module_id.0 as u64); - Symbol(bits) + Self { + module_id: module_id.0, + ident_id: ident_id.0, + } } - pub fn module_id(self) -> ModuleId { - ModuleId(self.0 as u32) + pub const fn module_id(self) -> ModuleId { + ModuleId(self.module_id) } - pub fn ident_id(self) -> IdentId { - IdentId((self.0 >> 32) as u32) + pub const fn ident_id(self) -> IdentId { + IdentId(self.ident_id) } - pub fn is_builtin(self) -> bool { + pub const fn is_builtin(self) -> bool { self.module_id().is_builtin() } @@ -88,8 +112,8 @@ impl Symbol { }) } - pub fn as_u64(self) -> u64 { - self.0 + pub const fn as_u64(self) -> u64 { + u64::from_ne_bytes(self.to_ne_bytes()) } pub fn fully_qualified(self, interns: &Interns, home: ModuleId) -> ModuleName { @@ -109,7 +133,7 @@ impl Symbol { } pub const fn to_ne_bytes(self) -> [u8; 8] { - self.0.to_ne_bytes() + unsafe { std::mem::transmute(self) } } #[cfg(debug_assertions)] @@ -174,7 +198,7 @@ impl fmt::Display for Symbol { impl From for u64 { fn from(symbol: Symbol) -> Self { - symbol.0 + symbol.as_u64() } } @@ -800,7 +824,7 @@ macro_rules! define_builtins { } impl ModuleId { - pub fn is_builtin(&self) -> bool { + pub const fn is_builtin(self) -> bool { // This is a builtin ModuleId iff it's below the // total number of builtin modules, since they // take up the first $total ModuleId numbers. diff --git a/compiler/types/src/subs.rs b/compiler/types/src/subs.rs index 97fd484cd2..fbb4f54cf7 100644 --- a/compiler/types/src/subs.rs +++ b/compiler/types/src/subs.rs @@ -13,8 +13,8 @@ use ven_ena::unify::{InPlace, Snapshot, UnificationTable, UnifyKey}; // if your changes cause this number to go down, great! // please change it to the lower number. // if it went up, maybe check that the change is really required -roc_error_macros::assert_sizeof_all!(Descriptor, 6 * 8); -roc_error_macros::assert_sizeof_all!(Content, 4 * 8); +roc_error_macros::assert_sizeof_all!(Descriptor, 5 * 8); +roc_error_macros::assert_sizeof_all!(Content, 3 * 8 + 4); roc_error_macros::assert_sizeof_all!(FlatType, 3 * 8); roc_error_macros::assert_sizeof_all!(UnionTags, 12); roc_error_macros::assert_sizeof_all!(RecordFields, 2 * 8); @@ -2026,8 +2026,8 @@ impl From for Descriptor { } } -roc_error_macros::assert_sizeof_all!(Content, 4 * 8); -roc_error_macros::assert_sizeof_all!((Symbol, AliasVariables, Variable), 3 * 8); +roc_error_macros::assert_sizeof_all!(Content, 3 * 8 + 4); +roc_error_macros::assert_sizeof_all!((Symbol, AliasVariables, Variable), 2 * 8 + 4); roc_error_macros::assert_sizeof_all!(AliasVariables, 8); roc_error_macros::assert_sizeof_all!(FlatType, 3 * 8); From 08fdd0781edbc4aaf43724cc40157422912765a2 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 4 May 2022 23:11:14 +0200 Subject: [PATCH 787/846] use NonZeroU32 for ModuleId --- compiler/module/src/symbol.rs | 46 +++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index b587a6afd1..ef65f745cb 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -5,6 +5,7 @@ use roc_ident::IdentStr; use roc_region::all::Region; use snafu::OptionExt; use std::collections::HashMap; +use std::num::NonZeroU32; use std::{fmt, u32}; // the packed(4) is needed for faster equality comparisons. With it, the structure is @@ -30,9 +31,15 @@ use std::{fmt, u32}; #[repr(packed(4))] pub struct Symbol { ident_id: u32, - module_id: u32, + module_id: NonZeroU32, } +/// An Option will use the 0 that is not used by the NonZeroU32 module_id field to encode +/// the Nothing case. An Option hence takes no more space than a Symbol. +#[allow(dead_code)] +const SYMBOL_HAS_NICHE: () = + assert!(std::mem::size_of::() == std::mem::size_of::>()); + // When this is `true` (which it normally should be), Symbol's Debug::fmt implementation // attempts to pretty print debug symbols using interns recorded using // register_debug_idents calls (which should be made in debug mode). @@ -157,7 +164,7 @@ impl fmt::Debug for Symbol { let ident_id = self.ident_id(); match DEBUG_IDENT_IDS_BY_MODULE_ID.lock() { - Ok(names) => match &names.get(&module_id.0) { + Ok(names) => match &names.get(&(module_id.to_zero_indexed() as u32)) { Some(ident_ids) => match ident_ids.get_name(ident_id) { Some(ident_str) => write!(f, "`{:?}.{}`", module_id, ident_str), None => fallback_debug_fmt(*self, f), @@ -316,18 +323,31 @@ lazy_static! { /// A globally unique ID that gets assigned to each module as it is loaded. #[derive(Copy, Clone, PartialEq, Eq, Hash)] -pub struct ModuleId(u32); +pub struct ModuleId(NonZeroU32); impl ModuleId { // NOTE: the define_builtins! macro adds a bunch of constants to this impl, // // e.g. pub const NUM: ModuleId = … + const fn from_zero_indexed(mut id: usize) -> Self { + id += 1; + + // only happens on overflow + debug_assert!(id != 0); + + ModuleId(unsafe { NonZeroU32::new_unchecked(id as u32) }) + } + + const fn to_zero_indexed(self) -> usize { + (self.0.get() - 1) as usize + } + #[cfg(debug_assertions)] pub fn register_debug_idents(self, ident_ids: &IdentIds) { let mut all = DEBUG_IDENT_IDS_BY_MODULE_ID.lock().expect("Failed to acquire lock for Debug interning into DEBUG_MODULE_ID_NAMES, presumably because a thread panicked."); - all.insert(self.0, ident_ids.clone()); + all.insert(self.to_zero_indexed() as u32, ident_ids.clone()); } #[cfg(not(debug_assertions))] @@ -360,7 +380,7 @@ impl fmt::Debug for ModuleId { .expect("Failed to acquire lock for Debug reading from DEBUG_MODULE_ID_NAMES, presumably because a thread panicked."); if PRETTY_PRINT_DEBUG_SYMBOLS { - match names.get(&self.0) { + match names.get(&(self.to_zero_indexed() as u32)) { Some(str_ref) => write!(f, "{}", str_ref.clone()), None => { panic!( @@ -418,7 +438,7 @@ impl<'a> PackageModuleIds<'a> { Some(id) => *id, None => { let by_id = &mut self.by_id; - let module_id = ModuleId(by_id.len() as u32); + let module_id = ModuleId::from_zero_indexed(by_id.len()); by_id.push(module_name.clone()); @@ -454,7 +474,7 @@ impl<'a> PackageModuleIds<'a> { let mut names = DEBUG_MODULE_ID_NAMES.lock().expect("Failed to acquire lock for Debug interning into DEBUG_MODULE_ID_NAMES, presumably because a thread panicked."); names - .entry(module_id.0) + .entry(module_id.to_zero_indexed() as u32) .or_insert_with(|| match module_name { PQModuleName::Unqualified(module) => module.as_str().into(), PQModuleName::Qualified(package, module) => { @@ -474,7 +494,7 @@ impl<'a> PackageModuleIds<'a> { } pub fn get_name(&self, id: ModuleId) -> Option<&PQModuleName> { - self.by_id.get(id.0 as usize) + self.by_id.get(id.to_zero_indexed()) } pub fn available_modules(&self) -> impl Iterator { @@ -499,7 +519,7 @@ impl ModuleIds { Some(id) => *id, None => { let by_id = &mut self.by_id; - let module_id = ModuleId(by_id.len() as u32); + let module_id = ModuleId::from_zero_indexed(by_id.len()); by_id.push(module_name.clone()); @@ -520,7 +540,7 @@ impl ModuleIds { // TODO make sure modules are never added more than once! names - .entry(module_id.0) + .entry(module_id.to_zero_indexed() as u32) .or_insert_with(|| module_name.as_str().to_string().into()); } @@ -534,7 +554,7 @@ impl ModuleIds { } pub fn get_name(&self, id: ModuleId) -> Option<&ModuleName> { - self.by_id.get(id.0 as usize) + self.by_id.get(id.to_zero_indexed()) } pub fn available_modules(&self) -> impl Iterator { @@ -828,11 +848,11 @@ macro_rules! define_builtins { // This is a builtin ModuleId iff it's below the // total number of builtin modules, since they // take up the first $total ModuleId numbers. - self.0 < $total + self.to_zero_indexed() < $total } $( - pub const $module_const: ModuleId = ModuleId($module_id); + pub const $module_const: ModuleId = ModuleId::from_zero_indexed($module_id); )+ } From 58dc7a96352f22b960d1cce441330cdebf9e89d9 Mon Sep 17 00:00:00 2001 From: Brian Carroll Date: Wed, 4 May 2022 22:33:07 +0100 Subject: [PATCH 788/846] Make wasi_libc_sys a required dependency of roc_build to fix repl_test --- compiler/build/Cargo.toml | 4 ++-- wasi-libc-sys/src/lib.rs | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/compiler/build/Cargo.toml b/compiler/build/Cargo.toml index cf2f32d230..ce102b0e38 100644 --- a/compiler/build/Cargo.toml +++ b/compiler/build/Cargo.toml @@ -31,7 +31,7 @@ libloading = "0.7.1" tempfile = "3.2.0" inkwell = { path = "../../vendor/inkwell", optional = true } target-lexicon = "0.12.3" -wasi_libc_sys = { path = "../../wasi-libc-sys", optional = true } +wasi_libc_sys = { path = "../../wasi-libc-sys" } [target.'cfg(target_os = "macos")'.dependencies] serde_json = "1.0.69" @@ -41,7 +41,7 @@ target-arm = [] target-aarch64 = ["roc_gen_dev/target-aarch64"] target-x86 = [] target-x86_64 = ["roc_gen_dev/target-x86_64"] -target-wasm32 = ["roc_gen_wasm", "wasi_libc_sys"] +target-wasm32 = ["roc_gen_wasm"] # This is a separate feature because when we generate docs on Netlify, # it doesn't have LLVM installed. (Also, it doesn't need to do code gen.) diff --git a/wasi-libc-sys/src/lib.rs b/wasi-libc-sys/src/lib.rs index 566b052ce1..5241f4f764 100644 --- a/wasi-libc-sys/src/lib.rs +++ b/wasi-libc-sys/src/lib.rs @@ -11,9 +11,8 @@ extern "C" { pub fn memset(dst: *mut c_void, ch: i32, n: usize) -> *mut c_void; } +// Tell users of this crate where to find the Wasm .a file // If a non-Wasm target is using this crate, we assume it is a build script that wants to emit Wasm -// Tell it where to find the Wasm .a file -#[cfg(not(target_family = "wasm"))] +// For Wasm target, it won't ever be used, but we expose it just to keep things simple mod generated; -#[cfg(not(target_family = "wasm"))] pub use generated::WASI_LIBC_PATH; From c5ff1ef80373a24173c7e0a05de38a4a8b2bb0de Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 4 May 2022 17:41:29 -0400 Subject: [PATCH 789/846] Update Type2 size --- ast/src/lang/core/types.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ast/src/lang/core/types.rs b/ast/src/lang/core/types.rs index 4bfc075ace..b8607f3e22 100644 --- a/ast/src/lang/core/types.rs +++ b/ast/src/lang/core/types.rs @@ -49,7 +49,7 @@ pub enum Type2 { #[test] fn type2_size() { - assert_eq!(std::mem::size_of::(), 32); // 24B + pad + assert_eq!(std::mem::size_of::(), 28); // 24B + pad } #[derive(Debug)] From 12ed674f614af6ee5bb939f60f7b993e55cefc7c Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 4 May 2022 23:47:01 +0200 Subject: [PATCH 790/846] turn test into const assert --- ast/src/lang/core/types.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/ast/src/lang/core/types.rs b/ast/src/lang/core/types.rs index b8607f3e22..feb19f03a9 100644 --- a/ast/src/lang/core/types.rs +++ b/ast/src/lang/core/types.rs @@ -19,6 +19,8 @@ use crate::mem_pool::shallow_clone::ShallowClone; pub type TypeId = NodeId; +const TYPE2_SIZE: () = assert!(std::mem::size_of::() == 3 * 8 + 4); + #[derive(Debug)] pub enum Type2 { Variable(Variable), // 4B @@ -47,11 +49,6 @@ pub enum Type2 { Erroneous(Problem2), // 24B } -#[test] -fn type2_size() { - assert_eq!(std::mem::size_of::(), 28); // 24B + pad -} - #[derive(Debug)] pub enum Problem2 { CanonicalizationProblem, From 0f1e1d7659d007877c88a5d8bc93fa6f9798c275 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 4 May 2022 20:45:51 -0400 Subject: [PATCH 791/846] Don't pass around an unnecessary Env --- compiler/solve/src/module.rs | 3 --- compiler/solve/src/solve.rs | 12 +++--------- reporting/tests/helpers/mod.rs | 1 - 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/compiler/solve/src/module.rs b/compiler/solve/src/module.rs index c0f5f7ef94..93570bb62e 100644 --- a/compiler/solve/src/module.rs +++ b/compiler/solve/src/module.rs @@ -40,8 +40,6 @@ pub fn run_solve( Vec, AbilitiesStore, ) { - let env = solve::Env::default(); - for (var, name) in rigid_variables.named { subs.rigid_var(var, name); } @@ -61,7 +59,6 @@ pub fn run_solve( // Run the solver to populate Subs. let (solved_subs, solved_env) = solve::run( constraints, - &env, &mut problems, subs, &mut aliases, diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index a44237864b..79b86bfad1 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -496,7 +496,6 @@ struct State { pub fn run( constraints: &Constraints, - env: &Env, problems: &mut Vec, mut subs: Subs, aliases: &mut Aliases, @@ -505,7 +504,6 @@ pub fn run( ) -> (Solved, Env) { let env = run_in_place( constraints, - env, problems, &mut subs, aliases, @@ -517,9 +515,8 @@ pub fn run( } /// Modify an existing subs in-place instead -pub fn run_in_place( +fn run_in_place( constraints: &Constraints, - env: &Env, problems: &mut Vec, subs: &mut Subs, aliases: &mut Aliases, @@ -529,11 +526,10 @@ pub fn run_in_place( let mut pools = Pools::default(); let state = State { - env: env.clone(), + env: Env::default(), mark: Mark::NONE.next(), }; let rank = Rank::toplevel(); - let arena = Bump::new(); let mut deferred_must_implement_abilities = DeferredMustImplementAbility::default(); @@ -541,7 +537,6 @@ pub fn run_in_place( let state = solve( &arena, constraints, - env, state, rank, &mut pools, @@ -600,7 +595,6 @@ enum Work<'a> { fn solve( arena: &Bump, constraints: &Constraints, - env: &Env, mut state: State, rank: Rank, pools: &mut Pools, @@ -612,7 +606,7 @@ fn solve( deferred_must_implement_abilities: &mut DeferredMustImplementAbility, ) -> State { let initial = Work::Constraint { - env, + env: &Env::default(), rank, constraint, }; diff --git a/reporting/tests/helpers/mod.rs b/reporting/tests/helpers/mod.rs index 01712519e2..de5530ae70 100644 --- a/reporting/tests/helpers/mod.rs +++ b/reporting/tests/helpers/mod.rs @@ -38,7 +38,6 @@ pub fn infer_expr( let env = solve::Env::default(); let (solved, _) = solve::run( constraints, - &env, problems, subs, aliases, From 739e249a44bc014b6b5eb9ad87afb04552381e9c Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 4 May 2022 20:52:28 -0400 Subject: [PATCH 792/846] Allow `roc check` on `Package-Config.roc` --- compiler/load_internal/src/file.rs | 65 ++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 22 deletions(-) diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index f34afff787..fef510bdad 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -2494,7 +2494,7 @@ fn load_pkg_config<'a>( let pkg_config_module_msg = fabricate_pkg_config_module( arena, shorthand, - app_module_id, + Some(app_module_id), filename, parser_state, module_ids.clone(), @@ -2942,11 +2942,18 @@ fn parse_header<'a>( To::NewPackage(_package_name) => Ok((module_id, app_module_header_msg)), } } - Ok((ast::Module::Platform { header }, _parse_state)) => { - Err(LoadingProblem::UnexpectedHeader(format!( - "got an unexpected platform header\n{:?}", - header - ))) + Ok((ast::Module::Platform { header }, parse_state)) => { + Ok(fabricate_pkg_config_module( + arena, + "", // Use a shorthand of "" - it will be fine for `roc check` and bindgen + None, + filename, + parse_state, + module_ids.clone(), + ident_ids_by_module, + &header, + module_timing, + )) } Err(fail) => Err(LoadingProblem::ParsingFailed( @@ -3232,7 +3239,7 @@ struct PlatformHeaderInfo<'a> { filename: PathBuf, is_root_module: bool, shorthand: &'a str, - app_module_id: ModuleId, + opt_app_module_id: Option, packages: &'a [Loc>], provides: &'a [Loc>], requires: &'a [Loc>], @@ -3253,7 +3260,7 @@ fn send_header_two<'a>( filename, shorthand, is_root_module, - app_module_id, + opt_app_module_id, packages, provides, requires, @@ -3271,12 +3278,16 @@ fn send_header_two<'a>( let mut deps_by_name: MutMap = HashMap::with_capacity_and_hasher(num_exposes, default_hasher()); - // add standard imports - imported_modules.insert(app_module_id, Region::zero()); - deps_by_name.insert( - PQModuleName::Unqualified(ModuleName::APP.into()), - app_module_id, - ); + // Add standard imports, if there is an app module. + // (There might not be, e.g. when running `roc check Package-Config.roc` or + // when generating bindings.) + if let Some(app_module_id) = opt_app_module_id { + imported_modules.insert(app_module_id, Region::zero()); + deps_by_name.insert( + PQModuleName::Unqualified(ModuleName::APP.into()), + app_module_id, + ); + } let mut scope_size = 0; @@ -3341,14 +3352,21 @@ fn send_header_two<'a>( } { - let ident_ids = ident_ids_by_module.get_or_insert(app_module_id); + // If we don't have an app module id (e.g. because we're doing + // `roc check Package-Config.roc` or because we're doing bindgen), + // insert the `requires` symbols into the platform module's IdentIds. + // + // Otherwise, get them from the app module's IdentIds, because it + // should already have a symbol for each `requires` entry, and we + // want to make sure we're referencing the same symbols! + let module_id = opt_app_module_id.unwrap_or(home); + let ident_ids = ident_ids_by_module.get_or_insert(module_id); for entry in requires { let entry = entry.value; - let ident: Ident = entry.ident.value.into(); let ident_id = ident_ids.get_or_insert(&ident); - let symbol = Symbol::new(app_module_id, ident_id); + let symbol = Symbol::new(module_id, ident_id); // Since this value is exposed, add it to our module's default scope. debug_assert!(!scope.contains_key(&ident.clone())); @@ -3360,11 +3378,10 @@ fn send_header_two<'a>( let string: &str = entry.value.into(); let ident: Ident = string.into(); let ident_id = ident_ids.get_or_insert(&ident); - let symbol = Symbol::new(app_module_id, ident_id); + let symbol = Symbol::new(module_id, ident_id); // Since this value is exposed, add it to our module's default scope. debug_assert!(!scope.contains_key(&ident.clone())); - scope.insert(ident, (symbol, entry.region)); } } @@ -3739,7 +3756,7 @@ fn unspace<'a, T: Copy>(arena: &'a Bump, items: &[Loc>]) -> &'a [L fn fabricate_pkg_config_module<'a>( arena: &'a Bump, shorthand: &'a str, - app_module_id: ModuleId, + opt_app_module_id: Option, filename: PathBuf, parse_state: roc_parse::state::State<'a>, module_ids: Arc>>, @@ -3747,11 +3764,15 @@ fn fabricate_pkg_config_module<'a>( header: &PlatformHeader<'a>, module_timing: ModuleTiming, ) -> (ModuleId, Msg<'a>) { + // If we have an app module, then it's the root module; + // otherwise, we must be the root. + let is_root_module = opt_app_module_id.is_none(); + let info = PlatformHeaderInfo { filename, - is_root_module: false, + is_root_module, shorthand, - app_module_id, + opt_app_module_id, packages: &[], provides: unspace(arena, header.provides.items), requires: &*arena.alloc([Loc::at( From ef877364d43bcf61c48ce632be0a35fd445239e7 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 5 May 2022 09:04:34 -0400 Subject: [PATCH 793/846] Allow invalid UTF-8 for `roc format` argument Presumably with a new version of clap that was introduced, we must now specify that invalid-utf8 is permitted in order to run `matches.values_of_os` as we do on line 174 of cli/src/main.rs: ```rust Some((CMD_FORMAT, matches)) => { let maybe_values = matches.values_of_os(DIRECTORY_OR_FILES); ``` Otherwise, clap panics: ``` thread 'main' panicked at 'Must use `Arg::allow_invalid_utf8` with `_os` lookups at `DIRECTORY_OR_FILES`', cli/src/main.rs:174:40 ``` --- cli/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index b12b85a728..b9d5e60f6a 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -157,7 +157,8 @@ pub fn build_app<'a>() -> Command<'a> { Arg::new(DIRECTORY_OR_FILES) .index(1) .multiple_values(true) - .required(false)) + .required(false) + .allow_invalid_utf8(true)) .arg( Arg::new(FLAG_CHECK) .long(FLAG_CHECK) From 7182180622c4872be4c2276c8afa47bfb48d301f Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Mon, 25 Apr 2022 18:59:39 -0400 Subject: [PATCH 794/846] Pass 1 of polymorphic specialization of defs --- compiler/mono/src/ir.rs | 548 ++++++++++++++------------ compiler/solve/src/solve.rs | 4 +- compiler/test_gen/src/gen_num.rs | 9 +- compiler/test_gen/src/gen_tags.rs | 2 +- compiler/test_gen/src/helpers/llvm.rs | 3 + 5 files changed, 309 insertions(+), 257 deletions(-) diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index a8937a39d4..bbd130e07e 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -26,6 +26,7 @@ use roc_types::subs::{ Content, ExhaustiveMark, FlatType, RedundantMark, StorageSubs, Subs, Variable, VariableSubsSlice, }; +use roc_unify::unify::Mode; use std::collections::HashMap; use ven_pretty::{BoxAllocator, DocAllocator, DocBuilder}; @@ -263,80 +264,24 @@ impl<'a> PartialProc<'a> { } } -#[derive(Clone, Debug)] -enum PolymorphicExpr { - /// A root ability member, which must be specialized at a call site, for example - /// "hash" which must be specialized to an exact symbol implementing "hash" for a type. - AbilityMember(Symbol), - /// A polymorphic expression we inline at the usage site. - Expr(roc_can::expr::Expr, Variable), -} +#[derive(Clone, Copy, Debug)] +struct AbilityMember(Symbol); +/// A table of aliases of ability member symbols. #[derive(Clone, Debug)] -enum PartialExprLink { - /// The root polymorphic expression - Sink(PolymorphicExpr), - /// A hop in a partial expression alias chain - Aliases(Symbol), -} +struct AbilityAliases(BumpMap); -/// A table of symbols to polymorphic expressions. For example, in the program -/// -/// n = 1 -/// -/// asU8 : U8 -> U8 -/// asU8 = \_ -> 1 -/// -/// asU32 : U32 -> U8 -/// asU32 = \_ -> 1 -/// -/// asU8 n + asU32 n -/// -/// The expression bound by `n` doesn't have a definite layout until it is used -/// at the call sites `asU8 n`, `asU32 n`. -/// -/// Polymorphic *functions* are stored in `PartialProc`s, since functions are -/// non longer first-class once we finish lowering to the IR. -#[derive(Clone, Debug)] -struct PartialExprs(BumpMap); - -impl PartialExprs { +impl AbilityAliases { fn new_in(arena: &Bump) -> Self { Self(BumpMap::new_in(arena)) } - fn insert(&mut self, symbol: Symbol, expr: PolymorphicExpr) { - self.0.insert(symbol, PartialExprLink::Sink(expr)); + fn insert(&mut self, symbol: Symbol, member: AbilityMember) { + self.0.insert(symbol, member); } - fn insert_alias(&mut self, symbol: Symbol, aliases: Symbol) { - self.0.insert(symbol, PartialExprLink::Aliases(aliases)); - } - - fn contains(&self, symbol: Symbol) -> bool { - self.0.contains_key(&symbol) - } - - fn get(&mut self, mut symbol: Symbol) -> Option<&PolymorphicExpr> { - // In practice the alias chain is very short - loop { - match self.0.get(&symbol) { - None => { - return None; - } - Some(&PartialExprLink::Aliases(real_symbol)) => { - symbol = real_symbol; - } - Some(PartialExprLink::Sink(expr)) => { - return Some(expr); - } - } - } - } - - fn remove(&mut self, symbol: Symbol) { - debug_assert!(self.contains(symbol)); - self.0.remove(&symbol); + fn get(&self, symbol: Symbol) -> Option<&AbilityMember> { + self.0.get(&symbol) } } @@ -801,26 +746,28 @@ impl<'a> Specialized<'a> { #[derive(Clone, Debug)] pub struct Procs<'a> { pub partial_procs: PartialProcs<'a>, - partial_exprs: PartialExprs, + ability_member_aliases: AbilityAliases, pub imported_module_thunks: &'a [Symbol], pub module_thunks: &'a [Symbol], pending_specializations: PendingSpecializations<'a>, specialized: Specialized<'a>, pub runtime_errors: BumpMap, pub externals_we_need: BumpMap, + pub needed_symbol_specializations: BumpMap<(Symbol, Layout<'a>), (Variable, Symbol)>, } impl<'a> Procs<'a> { pub fn new_in(arena: &'a Bump) -> Self { Self { partial_procs: PartialProcs::new_in(arena), - partial_exprs: PartialExprs::new_in(arena), + ability_member_aliases: AbilityAliases::new_in(arena), imported_module_thunks: &[], module_thunks: &[], pending_specializations: PendingSpecializations::Finding(Suspended::new_in(arena)), specialized: Specialized::default(), runtime_errors: BumpMap::new_in(arena), externals_we_need: BumpMap::new_in(arena), + needed_symbol_specializations: BumpMap::new_in(arena), } } } @@ -4081,7 +4028,7 @@ pub fn with_hole<'a>( } CopyExisting(index) => { let record_needs_specialization = - procs.partial_exprs.contains(structure); + procs.ability_member_aliases.get(structure).is_some(); let specialized_structure_sym = if record_needs_specialization { // We need to specialize the record now; create a new one for it. // TODO: reuse this symbol for all updates @@ -4308,70 +4255,71 @@ pub fn with_hole<'a>( unreachable!("calling a non-closure layout") } }, - UnspecializedExpr(symbol) => match procs.partial_exprs.get(symbol).unwrap() - { - &PolymorphicExpr::AbilityMember(member) => { - let proc_name = get_specialization(env, fn_var, member).expect("Recorded as an ability member, but it doesn't have a specialization"); + UnspecializedExpr(symbol) => { + match procs.ability_member_aliases.get(symbol).unwrap() { + &AbilityMember(member) => { + let proc_name = get_specialization(env, fn_var, member).expect("Recorded as an ability member, but it doesn't have a specialization"); - // a call by a known name - return call_by_name( - env, - procs, - fn_var, - proc_name, - loc_args, - layout_cache, - assigned, - hole, - ); + // a call by a known name + return call_by_name( + env, + procs, + fn_var, + proc_name, + loc_args, + layout_cache, + assigned, + hole, + ); + } // TODO(POLYEXPR) + // PolymorphicExpr::Expr(lambda_expr, lambda_expr_var) => { + // match full_layout { + // RawFunctionLayout::Function( + // arg_layouts, + // lambda_set, + // ret_layout, + // ) => { + // let closure_data_symbol = env.unique_symbol(); + + // result = match_on_lambda_set( + // env, + // lambda_set, + // closure_data_symbol, + // arg_symbols, + // arg_layouts, + // ret_layout, + // assigned, + // hole, + // ); + + // let snapshot = env.subs.snapshot(); + // let cache_snapshot = layout_cache.snapshot(); + // let _unified = roc_unify::unify::unify( + // env.subs, + // fn_var, + // *lambda_expr_var, + // roc_unify::unify::Mode::EQ, + // ); + + // result = with_hole( + // env, + // lambda_expr.clone(), + // fn_var, + // procs, + // layout_cache, + // closure_data_symbol, + // env.arena.alloc(result), + // ); + // env.subs.rollback_to(snapshot); + // layout_cache.rollback_to(cache_snapshot); + // } + // RawFunctionLayout::ZeroArgumentThunk(_) => { + // unreachable!("calling a non-closure layout") + // } + // } + // } } - PolymorphicExpr::Expr(lambda_expr, lambda_expr_var) => { - match full_layout { - RawFunctionLayout::Function( - arg_layouts, - lambda_set, - ret_layout, - ) => { - let closure_data_symbol = env.unique_symbol(); - - result = match_on_lambda_set( - env, - lambda_set, - closure_data_symbol, - arg_symbols, - arg_layouts, - ret_layout, - assigned, - hole, - ); - - let snapshot = env.subs.snapshot(); - let cache_snapshot = layout_cache.snapshot(); - let _unified = roc_unify::unify::unify( - env.subs, - fn_var, - *lambda_expr_var, - roc_unify::unify::Mode::EQ, - ); - - result = with_hole( - env, - lambda_expr.clone(), - fn_var, - procs, - layout_cache, - closure_data_symbol, - env.arena.alloc(result), - ); - env.subs.rollback_to(snapshot); - layout_cache.rollback_to(cache_snapshot); - } - RawFunctionLayout::ZeroArgumentThunk(_) => { - unreachable!("calling a non-closure layout") - } - } - } - }, + } NotASymbol => { // the expression is not a symbol. That means it's an expression // evaluating to a function value. @@ -4746,8 +4694,10 @@ fn get_specialization<'a>( #[allow(clippy::too_many_arguments)] fn construct_closure_data<'a, I>( env: &mut Env<'a, '_>, - procs: &mut Procs<'a>, - layout_cache: &mut LayoutCache<'a>, + // TODO(POLYEXPR): remove? + _procs: &mut Procs<'a>, + // TODO(POLYEXPR): remove? + _layout_cache: &mut LayoutCache<'a>, lambda_set: LambdaSet<'a>, name: Symbol, symbols: I, @@ -4764,7 +4714,7 @@ where // arguments with a polymorphic type that we have to deal with let mut polymorphic_arguments = Vec::new_in(env.arena); - let mut result = match lambda_set.layout_for_member(name) { + let result = match lambda_set.layout_for_member(name) { ClosureRepresentation::Union { tag_id, alphabetic_order_fields: field_layouts, @@ -4775,9 +4725,9 @@ where // them ordered by their alignment requirements let mut combined = Vec::with_capacity_in(symbols.len(), env.arena); for ((symbol, variable), layout) in symbols.zip(field_layouts.iter()) { - if procs.partial_exprs.contains(*symbol) { - polymorphic_arguments.push((*symbol, *variable)); - } + // if procs.partial_exprs.contains(*symbol) { + // polymorphic_arguments.push((*symbol, *variable)); + // } combined.push((*symbol, layout)) } @@ -4810,9 +4760,9 @@ where // them ordered by their alignment requirements let mut combined = Vec::with_capacity_in(symbols.len(), env.arena); for ((symbol, variable), layout) in symbols.zip(field_layouts.iter()) { - if procs.partial_exprs.contains(*symbol) { - polymorphic_arguments.push((*symbol, *variable)); - } + // if procs.partial_exprs.contains(*symbol) { + // polymorphic_arguments.push((*symbol, *variable)); + // } combined.push((*symbol, layout)) } @@ -4868,9 +4818,12 @@ where // TODO: this is not quite right. What we should actually be doing is removing references to // polymorphic expressions from the captured symbols, and allowing the specializations of those // symbols to be inlined when specializing the closure body elsewhere. - for (symbol, var) in polymorphic_arguments { - result = specialize_symbol(env, procs, layout_cache, Some(var), symbol, result, symbol); - } + // TODO(POLYEXPR) + // for &&(symbol, var) in symbols { + // if procs.ability_member_aliases.contains(symbol) { + // result = specialize_symbol(env, procs, layout_cache, Some(var), symbol, result, symbol); + // } + // } result } @@ -5232,7 +5185,7 @@ fn sorted_field_symbols<'a>( let alignment = layout.alignment_bytes(env.target_info); - let symbol = possible_reuse_symbol(env, procs, &arg.value); + let symbol = possible_reuse_symbol_or_spec(env, procs, layout_cache, &arg.value, var); field_symbols_temp.push((alignment, symbol, ((var, arg), &*env.arena.alloc(symbol)))); } field_symbols_temp.sort_by(|a, b| b.0.cmp(&a.0)); @@ -5366,32 +5319,6 @@ fn register_capturing_closure<'a>( } } -fn is_literal_like(expr: &roc_can::expr::Expr) -> bool { - use roc_can::expr::Expr::*; - matches!( - expr, - Num(..) - | Int(..) - | Float(..) - | List { .. } - | Str(_) - | ZeroArgumentTag { .. } - | Tag { .. } - | Record { .. } - | Call(..) - ) -} - -fn expr_is_polymorphic<'a>( - env: &mut Env<'a, '_>, - expr: &roc_can::expr::Expr, - expr_var: Variable, -) -> bool { - // TODO: I don't think we need the `is_literal_like` check, but taking it slow for now... - let is_flex_or_rigid = |c: &Content| matches!(c, Content::FlexVar(_) | Content::RigidVar(_)); - is_literal_like(expr) && env.subs.var_contains_content(expr_var, is_flex_or_rigid) -} - pub fn from_can<'a>( env: &mut Env<'a, '_>, variable: Variable, @@ -5662,38 +5589,91 @@ pub fn from_can<'a>( return from_can(env, variable, new_outer, procs, layout_cache); } - ref body if expr_is_polymorphic(env, body, def.expr_var) => { - // This is a pattern like - // - // n = 1 - // asU8 n - // - // At the definition site `n = 1` we only know `1` to have the type `[Int *]`, - // which won't be refined until the call `asU8 n`. Add it as a partial expression - // that will be specialized at each concrete usage site. - procs.partial_exprs.insert( - *symbol, - PolymorphicExpr::Expr(def.loc_expr.value, def.expr_var), - ); + // TODO(POLYEXPR) + // ref body if expr_is_polymorphic(env, body, def.expr_var) => { + // // This is a pattern like + // // + // // n = 1 + // // asU8 n + // // + // // At the definition site `n = 1` we only know `1` to have the type `[Int *]`, + // // which won't be refined until the call `asU8 n`. Add it as a partial expression + // // that will be specialized at each concrete usage site. + // procs.ability_member_aliases.insert( + // *symbol, + // PolymorphicExpr::Expr(def.loc_expr.value, def.expr_var), + // ); - let result = from_can(env, variable, cont.value, procs, layout_cache); + // let result = from_can(env, variable, cont.value, procs, layout_cache); - // We won't see this symbol again. - procs.partial_exprs.remove(*symbol); + // // We won't see this symbol again. + // procs.ability_member_aliases.remove(*symbol); - return result; - } + // return result; + // } _ => { let rest = from_can(env, variable, cont.value, procs, layout_cache); - return with_hole( - env, - def.loc_expr.value, - def.expr_var, - procs, - layout_cache, - *symbol, - env.arena.alloc(rest), - ); + + let needs_def_specializations = procs + .needed_symbol_specializations + .keys() + .find(|(s, _)| s == symbol) + .is_some(); + + if !needs_def_specializations { + return with_hole( + env, + def.loc_expr.value, + def.expr_var, + procs, + layout_cache, + *symbol, + env.arena.alloc(rest), + ); + } + + // We do need specializations + + let mut stmt = rest; + let needed_specializations = procs + .needed_symbol_specializations + .drain_filter(|(s, _), _| s == symbol) + .collect::>(); + + for ((_, wanted_layout), (var, specialized_symbol)) in + needed_specializations + { + // let res = + // roc_unify::unify::unify(env.subs, var, def.expr_var, Mode::EQ); + let content = env.subs.get_content_without_compacting(def.expr_var); + let c = roc_types::subs::SubsFmtContent(content, env.subs); + let content2 = env.subs.get_content_without_compacting(var); + let c2 = roc_types::subs::SubsFmtContent(content2, env.subs); + let layout = layout_cache + .from_var(env.arena, def.expr_var, env.subs) + .unwrap(); + dbg!( + specialized_symbol, + c, + c2, + layout, + wanted_layout, + var, + def.expr_var, + ); + stmt = with_hole( + env, + def.loc_expr.value.clone(), + // def.expr_var, + var, + procs, + layout_cache, + specialized_symbol, + env.arena.alloc(stmt), + ); + } + + return stmt; } } } @@ -6335,19 +6315,22 @@ fn store_pattern_help<'a>( match can_pat { Identifier(symbol) => { - if let Some(&PolymorphicExpr::Expr(_, var)) = procs.partial_exprs.get(outer_symbol) { - // It might be the case that symbol we're storing hasn't been reified to a value - // yet, if it's polymorphic. Do that now. - stmt = specialize_symbol( - env, - procs, - layout_cache, - Some(var), - *symbol, - stmt, - outer_symbol, - ); - } + // TODO(POLYEXPR) + // if let Some(&PolymorphicExpr::Expr(_, var)) = + // procs.ability_member_aliases.get(outer_symbol) + // { + // // It might be the case that symbol we're storing hasn't been reified to a value + // // yet, if it's polymorphic. Do that now. + // stmt = specialize_symbol( + // env, + // procs, + // layout_cache, + // Some(var), + // *symbol, + // stmt, + // outer_symbol, + // ); + // } substitute_in_exprs(env.arena, &mut stmt, *symbol, outer_symbol); } @@ -6712,7 +6695,7 @@ fn can_reuse_symbol<'a>( Imported(symbol) } else if procs.partial_procs.contains_key(symbol) { LocalFunction(symbol) - } else if procs.partial_exprs.contains(symbol) { + } else if procs.ability_member_aliases.get(symbol).is_some() { UnspecializedExpr(symbol) } else { Value(symbol) @@ -6733,6 +6716,39 @@ fn possible_reuse_symbol<'a>( } } +// TODO(POLYEXPR): unify with possible_reuse_symbol +fn possible_reuse_symbol_or_spec<'a>( + env: &mut Env<'a, '_>, + procs: &mut Procs<'a>, + layout_cache: &mut LayoutCache<'a>, + expr: &roc_can::expr::Expr, + var: Variable, +) -> Symbol { + match can_reuse_symbol(env, procs, expr) { + ReuseSymbol::Value(symbol) => { + let wanted_layout = layout_cache.from_var(env.arena, var, env.subs).unwrap(); + + let mut fake_subs = env.subs.clone(); + let new_var = roc_types::subs::deep_copy_var_to(&mut fake_subs, env.subs, var); + let content = roc_types::subs::SubsFmtContent( + env.subs.get_content_without_compacting(new_var), + env.subs, + ); + dbg!(new_var, content); + + let (_, specialized_symbol) = procs + .needed_symbol_specializations + .entry((symbol, wanted_layout)) + .or_insert_with(|| (new_var, env.unique_symbol())); + + dbg!(symbol, *specialized_symbol, wanted_layout, var); + + *specialized_symbol + } + _ => env.unique_symbol(), + } +} + fn handle_variable_aliasing<'a, BuildRest>( env: &mut Env<'a, '_>, procs: &mut Procs<'a>, @@ -6747,15 +6763,15 @@ where { if env.abilities_store.is_ability_member_name(right) { procs - .partial_exprs - .insert(left, PolymorphicExpr::AbilityMember(right)); + .ability_member_aliases + .insert(left, AbilityMember(right)); return build_rest(env, procs, layout_cache); } - if procs.partial_exprs.contains(right) { + if let Some(&ability_member) = procs.ability_member_aliases.get(right) { // If `right` links to a partial expression, make sure we link `left` to it as well, so // that usages of it will be specialized when building the rest of the program. - procs.partial_exprs.insert_alias(left, right); + procs.ability_member_aliases.insert(left, ability_member); return build_rest(env, procs, layout_cache); } @@ -6790,7 +6806,28 @@ where } else { // This should be a fully specialized value. Replace the alias with the original symbol. let mut result = build_rest(env, procs, layout_cache); + + // We need to lift all specializations of "left" to be specializations of "right". + let to_update = procs + .needed_symbol_specializations + .drain_filter(|(s, _), _| s == &left) + .collect::>(); + let mut scratchpad_update_specializations = std::vec::Vec::new(); + for ((_, layout), (specialized_var, specialized_sym)) in to_update.into_iter() { + let old_specialized_sym = procs + .needed_symbol_specializations + .insert((right, layout), (specialized_var, specialized_sym)); + + if let Some((_, old_specialized_sym)) = old_specialized_sym { + scratchpad_update_specializations.push((old_specialized_sym, specialized_sym)); + } + } + substitute_in_exprs(env.arena, &mut result, left, right); + for (old_specialized_sym, specialized_sym) in scratchpad_update_specializations.into_iter() + { + substitute_in_exprs(env.arena, &mut result, old_specialized_sym, specialized_sym); + } result } } @@ -6829,34 +6866,36 @@ fn specialize_symbol<'a>( result: Stmt<'a>, original: Symbol, ) -> Stmt<'a> { - if let Some(PolymorphicExpr::Expr(expr, expr_var)) = procs.partial_exprs.get(original) { - // Specialize the expression type now, based off the `arg_var` we've been given. - // TODO: cache the specialized result - let snapshot = env.subs.snapshot(); - let cache_snapshot = layout_cache.snapshot(); - let _unified = roc_unify::unify::unify( - env.subs, - arg_var.unwrap(), - *expr_var, - roc_unify::unify::Mode::EQ, - ); + // TODO(POLYEXPR) + // if let Some(PolymorphicExpr::Expr(expr, expr_var)) = procs.ability_member_aliases.get(original) + // { + // // Specialize the expression type now, based off the `arg_var` we've been given. + // // TODO: cache the specialized result + // let snapshot = env.subs.snapshot(); + // let cache_snapshot = layout_cache.snapshot(); + // let _unified = roc_unify::unify::unify( + // env.subs, + // arg_var.unwrap(), + // *expr_var, + // roc_unify::unify::Mode::EQ, + // ); - let result = with_hole( - env, - expr.clone(), - *expr_var, - procs, - layout_cache, - symbol, - env.arena.alloc(result), - ); + // let result = with_hole( + // env, + // expr.clone(), + // *expr_var, + // procs, + // layout_cache, + // symbol, + // env.arena.alloc(result), + // ); - // Restore the prior state so as not to interfere with future specializations. - env.subs.rollback_to(snapshot); - layout_cache.rollback_to(cache_snapshot); + // // Restore the prior state so as not to interfere with future specializations. + // env.subs.rollback_to(snapshot); + // layout_cache.rollback_to(cache_snapshot); - return result; - } + // return result; + // } match procs.get_partial_proc(original) { None => { @@ -7040,8 +7079,17 @@ fn assign_to_symbol<'a>( original, ) } - Value(_) => { - // symbol is already defined; nothing else to do here + Value(_symbol) => { + //let wanted_layout = layout_cache.from_var(env.arena, arg_var, env.subs).unwrap(); + //let (_, specialized_symbol) = procs + // .needed_symbol_specializations + // .entry((symbol, wanted_layout)) + // .or_insert_with(|| (arg_var, env.unique_symbol())); + + //dbg!(symbol, wanted_layout); + + //let mut result = result; + //substitute_in_exprs(env.arena, &mut result, symbol, *specialized_symbol); result } NotASymbol => with_hole( @@ -7188,8 +7236,14 @@ fn call_by_name<'a>( let arena = env.arena; let arg_symbols = Vec::from_iter_in( - loc_args.iter().map(|(_, arg_expr)| { - possible_reuse_symbol(env, procs, &arg_expr.value) + loc_args.iter().map(|(arg_var, arg_expr)| { + possible_reuse_symbol_or_spec( + env, + procs, + layout_cache, + &arg_expr.value, + *arg_var, + ) }), arena, ) @@ -7280,11 +7334,9 @@ fn call_by_name_help<'a>( // the arguments given to the function, stored in symbols let mut field_symbols = Vec::with_capacity_in(loc_args.len(), arena); - field_symbols.extend( - loc_args - .iter() - .map(|(_, arg_expr)| possible_reuse_symbol(env, procs, &arg_expr.value)), - ); + field_symbols.extend(loc_args.iter().map(|(arg_var, arg_expr)| { + possible_reuse_symbol_or_spec(env, procs, layout_cache, &arg_expr.value, *arg_var) + })); // If required, add an extra argument to the layout that is the captured environment // afterwards, we MUST make sure the number of arguments in the layout matches the diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index 79b86bfad1..82ee0cfafb 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -440,7 +440,7 @@ impl Env { const DEFAULT_POOLS: usize = 8; #[derive(Clone, Debug)] -struct Pools(Vec>); +pub struct Pools(Vec>); impl Default for Pools { fn default() -> Self { @@ -2868,7 +2868,7 @@ fn instantiate_rigids_help(subs: &mut Subs, max_rank: Rank, initial: Variable) { } } -fn deep_copy_var_in( +pub fn deep_copy_var_in( subs: &mut Subs, rank: Rank, pools: &mut Pools, diff --git a/compiler/test_gen/src/gen_num.rs b/compiler/test_gen/src/gen_num.rs index 0240bb95d5..afa236c687 100644 --- a/compiler/test_gen/src/gen_num.rs +++ b/compiler/test_gen/src/gen_num.rs @@ -612,15 +612,12 @@ fn i64_abs() { #[test] #[cfg(any(feature = "gen-llvm"))] -#[should_panic( - expected = r#"Roc failed with message: "integer absolute overflowed because its argument is the minimum value"# -)] fn abs_min_int_overflow() { assert_evals_to!( indoc!( r#" - Num.abs Num.minI64 - "# + Num.abs Num.minI64 + "# ), 0, i64 @@ -3072,7 +3069,7 @@ fn sub_saturated() { #[test] #[cfg(any(feature = "gen-llvm"))] -fn monomorphized_ints() { +fn monomorphized_ints1() { assert_evals_to!( indoc!( r#" diff --git a/compiler/test_gen/src/gen_tags.rs b/compiler/test_gen/src/gen_tags.rs index 25648b37e4..170555d16b 100644 --- a/compiler/test_gen/src/gen_tags.rs +++ b/compiler/test_gen/src/gen_tags.rs @@ -1319,7 +1319,7 @@ fn monomorphized_applied_tag() { #[test] #[cfg(any(feature = "gen-llvm"))] -fn monomorphized_tag_with_polymorphic_arg() { +fn monomorphized_tag_with_polymorphic_arg1() { assert_evals_to!( indoc!( r#" diff --git a/compiler/test_gen/src/helpers/llvm.rs b/compiler/test_gen/src/helpers/llvm.rs index aeba51ad8c..37d6e48477 100644 --- a/compiler/test_gen/src/helpers/llvm.rs +++ b/compiler/test_gen/src/helpers/llvm.rs @@ -240,6 +240,9 @@ fn create_llvm_module<'a>( // Uncomment this to see the module's optimized LLVM instruction output: // env.module.print_to_stderr(); + env.module + .print_to_file(&std::path::PathBuf::from("/tmp/out.ll")) + .unwrap(); (main_fn_name, delayed_errors.join("\n"), env.module) } From 9bc6bb36644f793cc1f4978776686f0377d274dd Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Mon, 2 May 2022 18:52:07 -0400 Subject: [PATCH 795/846] Deep copy type variables --- compiler/mono/src/copy.rs | 298 ++++++++++++++++++++++++++++++++++++++ compiler/mono/src/ir.rs | 72 +++++---- compiler/mono/src/lib.rs | 1 + 3 files changed, 342 insertions(+), 29 deletions(-) create mode 100644 compiler/mono/src/copy.rs diff --git a/compiler/mono/src/copy.rs b/compiler/mono/src/copy.rs new file mode 100644 index 0000000000..6f8f4776fb --- /dev/null +++ b/compiler/mono/src/copy.rs @@ -0,0 +1,298 @@ +use bumpalo::collections::Vec; +use bumpalo::Bump; +use roc_types::subs::{ + AliasVariables, Descriptor, OptVariable, RecordFields, Subs, SubsSlice, UnionTags, Variable, + VariableSubsSlice, +}; + +pub fn deep_copy_type_vars<'a>( + arena: &'a Bump, + subs: &mut Subs, + var: Variable, +) -> Vec<'a, (Variable, Variable)> { + let mut copied = Vec::with_capacity_in(16, arena); + + let cloned_var = help(arena, subs, &mut copied, var); + + debug_assert!(match cloned_var { + Some(_) => copied.is_empty(), + None => !copied.is_empty(), + }); + + // we have tracked all visited variables, and can now traverse them + // in one go (without looking at the UnificationTable) and clear the copy field + let mut result = Vec::with_capacity_in(copied.len(), arena); + for var in copied { + let descriptor = subs.get_ref_mut(var); + + if let Some(copy) = descriptor.copy.into_variable() { + result.push((var, copy)); + descriptor.copy = OptVariable::NONE; + } else { + debug_assert!(false, "{:?} marked as copied but it wasn't", var); + } + } + + return result; + + #[must_use] + fn help( + arena: &Bump, + subs: &mut Subs, + visited: &mut Vec, + var: Variable, + ) -> Option { + use roc_types::subs::Content::*; + use roc_types::subs::FlatType::*; + + let desc = subs.get_ref_mut(var); + let content = desc.content; + let rank = desc.rank; + let mark = desc.mark; + + // Unlike `deep_copy_var` in solve, here we are cloning *all* flex and rigid vars. + // So we only want to fast-return if we've already done the cloning work for a particular + // var. + if let Some(copy) = desc.copy.into_variable() { + return Some(copy); + } + + macro_rules! descend_slice { + ($slice:expr, $needs_clone:ident) => { + for var_index in $slice { + let var = subs[var_index]; + $needs_clone = $needs_clone || help(arena, subs, visited, var).is_some(); + } + }; + } + + macro_rules! descend_var { + ($var:expr, $needs_clone:ident) => {{ + let new_var = help(arena, subs, visited, $var).unwrap_or($var); + $needs_clone = $needs_clone || new_var != $var; + new_var + }}; + } + + macro_rules! clone_var_slice { + ($slice:expr) => {{ + let new_arguments = VariableSubsSlice::reserve_into_subs(subs, $slice.len()); + for (target_index, var_index) in (new_arguments.indices()).zip($slice) { + let var = subs[var_index]; + let copy_var = subs.get_ref(var).copy.into_variable().unwrap_or(var); + subs.variables[target_index] = copy_var; + } + new_arguments + }}; + } + + // Now we recursively copy the content of the variable. + // We have already marked the variable as copied, so we + // will not repeat this work or crawl this variable again. + let opt_new_content = match content { + // The vars for which we want to do something interesting. + FlexVar(opt_name) => Some(FlexVar(opt_name)), + FlexAbleVar(opt_name, ability) => Some(FlexAbleVar(opt_name, ability)), + RigidVar(name) => Some(RigidVar(name)), + RigidAbleVar(name, ability) => Some(RigidAbleVar(name, ability)), + + // Everything else is a mechanical descent. + Structure(flat_type) => match flat_type { + EmptyRecord | EmptyTagUnion | Erroneous(_) => None, + Apply(symbol, arguments) => { + let mut needs_clone = false; + descend_slice!(arguments, needs_clone); + + if needs_clone { + let new_arguments = clone_var_slice!(arguments); + Some(Structure(Apply(symbol, new_arguments))) + } else { + None + } + } + Func(arguments, closure_var, ret_var) => { + let mut needs_clone = false; + + descend_slice!(arguments, needs_clone); + + let new_closure_var = descend_var!(closure_var, needs_clone); + let new_ret_var = descend_var!(ret_var, needs_clone); + + if needs_clone { + let new_arguments = clone_var_slice!(arguments); + Some(Structure(Func(new_arguments, new_closure_var, new_ret_var))) + } else { + None + } + } + Record(fields, ext_var) => { + let mut needs_clone = false; + + let new_ext_var = descend_var!(ext_var, needs_clone); + + descend_slice!(fields.variables(), needs_clone); + + if needs_clone { + let new_variables = clone_var_slice!(fields.variables()); + let new_fields = { + RecordFields { + length: fields.length, + field_names_start: fields.field_names_start, + variables_start: new_variables.start, + field_types_start: fields.field_types_start, + } + }; + Some(Structure(Record(new_fields, new_ext_var))) + } else { + None + } + } + TagUnion(tags, ext_var) => { + let mut needs_clone = false; + + let new_ext_var = descend_var!(ext_var, needs_clone); + + for variables_slice_index in tags.variables() { + let variables_slice = subs[variables_slice_index]; + descend_slice!(variables_slice, needs_clone); + } + + if needs_clone { + let new_variable_slices = + SubsSlice::reserve_variable_slices(subs, tags.len()); + let it = (new_variable_slices.indices()).zip(tags.variables()); + for (target_index, index) in it { + let slice = subs[index]; + let new_variables = clone_var_slice!(slice); + subs.variable_slices[target_index] = new_variables; + } + + let new_union_tags = + UnionTags::from_slices(tags.tag_names(), new_variable_slices); + + Some(Structure(TagUnion(new_union_tags, new_ext_var))) + } else { + None + } + } + RecursiveTagUnion(rec_var, tags, ext_var) => { + let mut needs_clone = false; + + let new_ext_var = descend_var!(ext_var, needs_clone); + let new_rec_var = descend_var!(rec_var, needs_clone); + + for variables_slice_index in tags.variables() { + let variables_slice = subs[variables_slice_index]; + descend_slice!(variables_slice, needs_clone); + } + + if needs_clone { + let new_variable_slices = + SubsSlice::reserve_variable_slices(subs, tags.len()); + let it = (new_variable_slices.indices()).zip(tags.variables()); + for (target_index, index) in it { + let slice = subs[index]; + let new_variables = clone_var_slice!(slice); + subs.variable_slices[target_index] = new_variables; + } + + let new_union_tags = + UnionTags::from_slices(tags.tag_names(), new_variable_slices); + + Some(Structure(RecursiveTagUnion( + new_rec_var, + new_union_tags, + new_ext_var, + ))) + } else { + None + } + } + FunctionOrTagUnion(tag_name, symbol, ext_var) => { + let mut needs_clone = false; + let new_ext_var = descend_var!(ext_var, needs_clone); + if needs_clone { + Some(Structure(FunctionOrTagUnion(tag_name, symbol, new_ext_var))) + } else { + None + } + } + }, + + RecursionVar { + opt_name, + structure, + } => { + let mut needs_clone = false; + + let new_structure = descend_var!(structure, needs_clone); + + if needs_clone { + Some(RecursionVar { + opt_name, + structure: new_structure, + }) + } else { + None + } + } + + Alias(symbol, arguments, real_type_var, kind) => { + let mut needs_clone = false; + + let new_real_type_var = descend_var!(real_type_var, needs_clone); + descend_slice!(arguments.all_variables(), needs_clone); + + if needs_clone { + let new_variables = clone_var_slice!(arguments.all_variables()); + let new_arguments = AliasVariables { + variables_start: new_variables.start, + ..arguments + }; + + Some(Alias(symbol, new_arguments, new_real_type_var, kind)) + } else { + None + } + } + + RangedNumber(typ, range_vars) => { + let mut needs_clone = false; + + let new_typ = descend_var!(typ, needs_clone); + descend_slice!(range_vars, needs_clone); + + if needs_clone { + let new_range_vars = clone_var_slice!(range_vars); + + Some(RangedNumber(new_typ, new_range_vars)) + } else { + None + } + } + Error => None, + }; + + if let Some(new_content) = opt_new_content { + visited.push(var); + + let copy_descriptor = Descriptor { + content: new_content, + rank, + mark, + copy: OptVariable::NONE, + }; + + let copy = subs.fresh(copy_descriptor); + // Set the copy on the original var + subs.get_ref_mut(var).copy = copy.into(); + + // We had to create a fresh var for this type, so anything that depends on it should be + // freshened too, and use this fresh var. + return Some(copy); + } + + // Doesn't need to be freshened; use the old var. + None + } +} diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index bbd130e07e..1fb5bfd4a2 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -4711,9 +4711,6 @@ where let lambda_set_layout = Layout::LambdaSet(lambda_set); let symbols = symbols.into_iter(); - // arguments with a polymorphic type that we have to deal with - let mut polymorphic_arguments = Vec::new_in(env.arena); - let result = match lambda_set.layout_for_member(name) { ClosureRepresentation::Union { tag_id, @@ -5635,35 +5632,18 @@ pub fn from_can<'a>( // We do need specializations let mut stmt = rest; - let needed_specializations = procs + let mut needed_specializations = procs .needed_symbol_specializations .drain_filter(|(s, _), _| s == symbol) .collect::>(); - for ((_, wanted_layout), (var, specialized_symbol)) in - needed_specializations - { - // let res = - // roc_unify::unify::unify(env.subs, var, def.expr_var, Mode::EQ); - let content = env.subs.get_content_without_compacting(def.expr_var); - let c = roc_types::subs::SubsFmtContent(content, env.subs); - let content2 = env.subs.get_content_without_compacting(var); - let c2 = roc_types::subs::SubsFmtContent(content2, env.subs); - let layout = layout_cache - .from_var(env.arena, def.expr_var, env.subs) - .unwrap(); - dbg!( - specialized_symbol, - c, - c2, - layout, - wanted_layout, - var, - def.expr_var, - ); - stmt = with_hole( + if needed_specializations.len() == 1 { + let ((_, _wanted_layout), (var, specialized_symbol)) = + needed_specializations.pop().unwrap(); + + return with_hole( env, - def.loc_expr.value.clone(), + def.loc_expr.value, // def.expr_var, var, procs, @@ -5671,9 +5651,43 @@ pub fn from_can<'a>( specialized_symbol, env.arena.alloc(stmt), ); - } + } else { + // Need to eat the cost and create a specialized version of the body for each specialization. + for ((_, wanted_layout), (var, specialized_symbol)) in + needed_specializations + { + // let res = + // roc_unify::unify::unify(env.subs, var, def.expr_var, Mode::EQ); + let content = env.subs.get_content_without_compacting(def.expr_var); + let c = roc_types::subs::SubsFmtContent(content, env.subs); + let content2 = env.subs.get_content_without_compacting(var); + let c2 = roc_types::subs::SubsFmtContent(content2, env.subs); + let layout = layout_cache + .from_var(env.arena, def.expr_var, env.subs) + .unwrap(); + dbg!( + specialized_symbol, + c, + c2, + layout, + wanted_layout, + var, + def.expr_var, + ); + stmt = with_hole( + env, + def.loc_expr.value.clone(), + // def.expr_var, + var, + procs, + layout_cache, + specialized_symbol, + env.arena.alloc(stmt), + ); + } - return stmt; + return stmt; + } } } } diff --git a/compiler/mono/src/lib.rs b/compiler/mono/src/lib.rs index d927845749..efffd4c9c9 100644 --- a/compiler/mono/src/lib.rs +++ b/compiler/mono/src/lib.rs @@ -4,6 +4,7 @@ pub mod borrow; pub mod code_gen_help; +mod copy; pub mod inc_dec; pub mod ir; pub mod layout; From 480b84bec1a5974c4df733cc61c5f3f3dc422b66 Mon Sep 17 00:00:00 2001 From: ayazhafiz Date: Mon, 2 May 2022 20:55:09 -0400 Subject: [PATCH 796/846] Cloning references in a variable may end up cloning the variable itself --- compiler/mono/src/copy.rs | 98 +++++++++++++++++++-------------------- 1 file changed, 47 insertions(+), 51 deletions(-) diff --git a/compiler/mono/src/copy.rs b/compiler/mono/src/copy.rs index 6f8f4776fb..1bb4c04eed 100644 --- a/compiler/mono/src/copy.rs +++ b/compiler/mono/src/copy.rs @@ -51,7 +51,7 @@ pub fn deep_copy_type_vars<'a>( let mark = desc.mark; // Unlike `deep_copy_var` in solve, here we are cloning *all* flex and rigid vars. - // So we only want to fast-return if we've already done the cloning work for a particular + // So we only want to short-circuit if we've already done the cloning work for a particular // var. if let Some(copy) = desc.copy.into_variable() { return Some(copy); @@ -86,6 +86,23 @@ pub fn deep_copy_type_vars<'a>( }}; } + macro_rules! perform_clone { + ($needs_clone:ident, $do_clone:expr) => { + if $needs_clone { + // It may the case that while deep-copying nested variables of this type, we + // ended up copying the type itself (notably if it was self-referencing, in a + // recursive type). In that case, short-circuit with the known copy. + if let Some(copy) = subs.get_ref(var).copy.into_variable() { + return Some(copy); + } + // Perform the clone. + Some($do_clone) + } else { + None + } + }; + } + // Now we recursively copy the content of the variable. // We have already marked the variable as copied, so we // will not repeat this work or crawl this variable again. @@ -103,12 +120,10 @@ pub fn deep_copy_type_vars<'a>( let mut needs_clone = false; descend_slice!(arguments, needs_clone); - if needs_clone { + perform_clone!(needs_clone, { let new_arguments = clone_var_slice!(arguments); - Some(Structure(Apply(symbol, new_arguments))) - } else { - None - } + Structure(Apply(symbol, new_arguments)) + }) } Func(arguments, closure_var, ret_var) => { let mut needs_clone = false; @@ -118,12 +133,10 @@ pub fn deep_copy_type_vars<'a>( let new_closure_var = descend_var!(closure_var, needs_clone); let new_ret_var = descend_var!(ret_var, needs_clone); - if needs_clone { + perform_clone!(needs_clone, { let new_arguments = clone_var_slice!(arguments); - Some(Structure(Func(new_arguments, new_closure_var, new_ret_var))) - } else { - None - } + Structure(Func(new_arguments, new_closure_var, new_ret_var)) + }) } Record(fields, ext_var) => { let mut needs_clone = false; @@ -132,7 +145,7 @@ pub fn deep_copy_type_vars<'a>( descend_slice!(fields.variables(), needs_clone); - if needs_clone { + perform_clone!(needs_clone, { let new_variables = clone_var_slice!(fields.variables()); let new_fields = { RecordFields { @@ -142,10 +155,9 @@ pub fn deep_copy_type_vars<'a>( field_types_start: fields.field_types_start, } }; - Some(Structure(Record(new_fields, new_ext_var))) - } else { - None - } + + Structure(Record(new_fields, new_ext_var)) + }) } TagUnion(tags, ext_var) => { let mut needs_clone = false; @@ -157,7 +169,7 @@ pub fn deep_copy_type_vars<'a>( descend_slice!(variables_slice, needs_clone); } - if needs_clone { + perform_clone!(needs_clone, { let new_variable_slices = SubsSlice::reserve_variable_slices(subs, tags.len()); let it = (new_variable_slices.indices()).zip(tags.variables()); @@ -170,10 +182,8 @@ pub fn deep_copy_type_vars<'a>( let new_union_tags = UnionTags::from_slices(tags.tag_names(), new_variable_slices); - Some(Structure(TagUnion(new_union_tags, new_ext_var))) - } else { - None - } + Structure(TagUnion(new_union_tags, new_ext_var)) + }) } RecursiveTagUnion(rec_var, tags, ext_var) => { let mut needs_clone = false; @@ -186,7 +196,7 @@ pub fn deep_copy_type_vars<'a>( descend_slice!(variables_slice, needs_clone); } - if needs_clone { + perform_clone!(needs_clone, { let new_variable_slices = SubsSlice::reserve_variable_slices(subs, tags.len()); let it = (new_variable_slices.indices()).zip(tags.variables()); @@ -199,23 +209,15 @@ pub fn deep_copy_type_vars<'a>( let new_union_tags = UnionTags::from_slices(tags.tag_names(), new_variable_slices); - Some(Structure(RecursiveTagUnion( - new_rec_var, - new_union_tags, - new_ext_var, - ))) - } else { - None - } + Structure(RecursiveTagUnion(new_rec_var, new_union_tags, new_ext_var)) + }) } FunctionOrTagUnion(tag_name, symbol, ext_var) => { let mut needs_clone = false; let new_ext_var = descend_var!(ext_var, needs_clone); - if needs_clone { - Some(Structure(FunctionOrTagUnion(tag_name, symbol, new_ext_var))) - } else { - None - } + perform_clone!(needs_clone, { + Structure(FunctionOrTagUnion(tag_name, symbol, new_ext_var)) + }) } }, @@ -227,14 +229,12 @@ pub fn deep_copy_type_vars<'a>( let new_structure = descend_var!(structure, needs_clone); - if needs_clone { - Some(RecursionVar { + perform_clone!(needs_clone, { + RecursionVar { opt_name, structure: new_structure, - }) - } else { - None - } + } + }) } Alias(symbol, arguments, real_type_var, kind) => { @@ -243,17 +243,15 @@ pub fn deep_copy_type_vars<'a>( let new_real_type_var = descend_var!(real_type_var, needs_clone); descend_slice!(arguments.all_variables(), needs_clone); - if needs_clone { + perform_clone!(needs_clone, { let new_variables = clone_var_slice!(arguments.all_variables()); let new_arguments = AliasVariables { variables_start: new_variables.start, ..arguments }; - Some(Alias(symbol, new_arguments, new_real_type_var, kind)) - } else { - None - } + Alias(symbol, new_arguments, new_real_type_var, kind) + }) } RangedNumber(typ, range_vars) => { @@ -262,13 +260,11 @@ pub fn deep_copy_type_vars<'a>( let new_typ = descend_var!(typ, needs_clone); descend_slice!(range_vars, needs_clone); - if needs_clone { + perform_clone!(needs_clone, { let new_range_vars = clone_var_slice!(range_vars); - Some(RangedNumber(new_typ, new_range_vars)) - } else { - None - } + RangedNumber(new_typ, new_range_vars) + }) } Error => None, }; From 79e11547beac01ea5bf42c5c9303ed58cd024c5d Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 3 May 2022 10:04:18 -0400 Subject: [PATCH 797/846] Add some copy tests --- compiler/mono/src/copy.rs | 213 +++++++++++++++++++++++++++++++++++++- 1 file changed, 211 insertions(+), 2 deletions(-) diff --git a/compiler/mono/src/copy.rs b/compiler/mono/src/copy.rs index 1bb4c04eed..d302c94d32 100644 --- a/compiler/mono/src/copy.rs +++ b/compiler/mono/src/copy.rs @@ -15,8 +15,8 @@ pub fn deep_copy_type_vars<'a>( let cloned_var = help(arena, subs, &mut copied, var); debug_assert!(match cloned_var { - Some(_) => copied.is_empty(), - None => !copied.is_empty(), + Some(_) => !copied.is_empty(), + None => copied.is_empty(), }); // we have tracked all visited variables, and can now traverse them @@ -292,3 +292,212 @@ pub fn deep_copy_type_vars<'a>( None } } + +#[cfg(test)] +mod test { + use super::deep_copy_type_vars; + use bumpalo::Bump; + use roc_module::ident::TagName; + use roc_module::symbol::Symbol; + use roc_types::{ + subs::{ + Content, Content::*, Descriptor, FlatType::*, Mark, OptVariable, Rank, RecordFields, + Subs, SubsIndex, UnionTags, Variable, + }, + types::RecordField, + }; + + #[cfg(test)] + fn new_var(subs: &mut Subs, content: Content) -> Variable { + subs.fresh(Descriptor { + content, + rank: Rank::toplevel(), + mark: Mark::NONE, + copy: OptVariable::NONE, + }) + } + + #[test] + fn copy_flex_var() { + let mut subs = Subs::new(); + let arena = Bump::new(); + + let field_name = SubsIndex::push_new(&mut subs.field_names, "a".into()); + let var = new_var(&mut subs, FlexVar(Some(field_name))); + + let mut copies = deep_copy_type_vars(&arena, &mut subs, var); + + assert_eq!(copies.len(), 1); + let (original, new) = copies.pop().unwrap(); + assert_ne!(original, new); + + assert_eq!(original, var); + match subs.get_content_without_compacting(new) { + FlexVar(Some(name)) => { + assert_eq!(subs[*name].as_str(), "a"); + } + it => assert!(false, "{:?}", it), + } + } + + #[test] + fn copy_rigid_var() { + let mut subs = Subs::new(); + let arena = Bump::new(); + + let field_name = SubsIndex::push_new(&mut subs.field_names, "a".into()); + let var = new_var(&mut subs, RigidVar(field_name)); + + let mut copies = deep_copy_type_vars(&arena, &mut subs, var); + + assert_eq!(copies.len(), 1); + let (original, new) = copies.pop().unwrap(); + assert_ne!(original, new); + + assert_eq!(original, var); + match subs.get_content_without_compacting(new) { + RigidVar(name) => { + assert_eq!(subs[*name].as_str(), "a"); + } + it => assert!(false, "{:?}", it), + } + } + + #[test] + fn copy_flex_able_var() { + let mut subs = Subs::new(); + let arena = Bump::new(); + + let field_name = SubsIndex::push_new(&mut subs.field_names, "a".into()); + let var = new_var(&mut subs, FlexAbleVar(Some(field_name), Symbol::UNDERSCORE)); + + let mut copies = deep_copy_type_vars(&arena, &mut subs, var); + + assert_eq!(copies.len(), 1); + let (original, new) = copies.pop().unwrap(); + assert_ne!(original, new); + + assert_eq!(original, var); + match subs.get_content_without_compacting(new) { + FlexAbleVar(Some(name), Symbol::UNDERSCORE) => { + assert_eq!(subs[*name].as_str(), "a"); + } + it => assert!(false, "{:?}", it), + } + } + + #[test] + fn copy_rigid_able_var() { + let mut subs = Subs::new(); + let arena = Bump::new(); + + let field_name = SubsIndex::push_new(&mut subs.field_names, "a".into()); + let var = new_var(&mut subs, RigidAbleVar(field_name, Symbol::UNDERSCORE)); + + let mut copies = deep_copy_type_vars(&arena, &mut subs, var); + + assert_eq!(copies.len(), 1); + let (original, new) = copies.pop().unwrap(); + assert_ne!(original, new); + + assert_eq!(original, var); + match subs.get_content_without_compacting(new) { + RigidAbleVar(name, Symbol::UNDERSCORE) => { + assert_eq!(subs[*name].as_str(), "a"); + } + it => assert!(false, "{:?}", it), + } + } + + #[test] + fn types_without_type_vars_should_not_be_copied() { + let mut subs = Subs::new(); + let arena = Bump::new(); + + let cases = &[ + RecursionVar { + structure: new_var(&mut subs, Structure(EmptyTagUnion)), + opt_name: None, + }, + Structure(Record( + RecordFields::insert_into_subs( + &mut subs, + [("a".into(), RecordField::Required(Variable::BOOL))], + ), + Variable::EMPTY_RECORD, + )), + Structure(TagUnion( + UnionTags::insert_into_subs( + &mut subs, + [(TagName::Tag("A".into()), [Variable::BOOL])], + ), + Variable::EMPTY_TAG_UNION, + )), + Structure(RecursiveTagUnion( + Variable::EMPTY_TAG_UNION, + UnionTags::insert_into_subs( + &mut subs, + [(TagName::Tag("A".into()), [Variable::BOOL])], + ), + Variable::EMPTY_TAG_UNION, + )), + Error, + ]; + + for &content in cases { + let var = new_var(&mut subs, content); + + let copies = deep_copy_type_vars(&arena, &mut subs, var); + + assert!(copies.is_empty()); + } + } + + #[test] + fn copy_type_with_copied_reference() { + let mut subs = Subs::new(); + let arena = Bump::new(); + + let flex_var = new_var(&mut subs, FlexVar(None)); + + let content = Structure(TagUnion( + UnionTags::insert_into_subs(&mut subs, [(TagName::Tag("A".into()), [flex_var])]), + Variable::EMPTY_TAG_UNION, + )); + + let tag_var = new_var(&mut subs, content); + + let mut copies = deep_copy_type_vars(&arena, &mut subs, tag_var); + + assert_eq!(copies.len(), 2); + let (original_flex, new_flex) = copies[0]; + assert_ne!(original_flex, new_flex); + assert_eq!(original_flex, flex_var); + + let (original_tag, new_tag) = copies[1]; + assert_ne!(original_tag, new_tag); + assert_eq!(original_tag, tag_var); + + match subs.get_content_without_compacting(new_tag) { + Structure(TagUnion(union_tags, Variable::EMPTY_TAG_UNION)) => { + let (tag_name, vars) = union_tags.iter_all().next().unwrap(); + match &subs[tag_name] { + TagName::Tag(upper) => assert_eq!(upper.as_str(), "A"), + _ => assert!(false, "{:?}", tag_name), + } + + let vars = subs[vars]; + assert_eq!(vars.len(), 1); + + let var = subs[vars.into_iter().next().unwrap()]; + assert_eq!(var, new_flex); + } + it => assert!(false, "{:?}", it), + } + + assert!(matches!( + subs.get_content_without_compacting(new_flex), + FlexVar(None) + )); + } +} From f21ce43e3045bb686a9efab9f4555f471791e72a Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 3 May 2022 11:30:52 -0400 Subject: [PATCH 798/846] Copy Expr --- compiler/mono/src/copy.rs | 370 +++++++++++++++++++++++++++++++++++++- 1 file changed, 369 insertions(+), 1 deletion(-) diff --git a/compiler/mono/src/copy.rs b/compiler/mono/src/copy.rs index d302c94d32..09ceab75d9 100644 --- a/compiler/mono/src/copy.rs +++ b/compiler/mono/src/copy.rs @@ -1,11 +1,379 @@ use bumpalo::collections::Vec; use bumpalo::Bump; +use roc_can::{ + def::Def, + expr::{AccessorData, ClosureData, Expr, Field, WhenBranch}, +}; use roc_types::subs::{ AliasVariables, Descriptor, OptVariable, RecordFields, Subs, SubsSlice, UnionTags, Variable, VariableSubsSlice, }; -pub fn deep_copy_type_vars<'a>( +/// Deep copies the type variables in the type hosted by [`var`] into [`expr`]. +/// Returns [`None`] if the expression does not need to be copied. +pub fn deep_copy_type_vars_into_expr<'a>( + arena: &'a Bump, + subs: &mut Subs, + var: Variable, + expr: &Expr, +) -> Option<(Variable, Expr)> { + let substitutions = deep_copy_type_vars(arena, subs, var); + + if substitutions.is_empty() { + return None; + } + + let new_var = substitutions + .iter() + .find_map(|&(original, new)| if original == var { Some(new) } else { None }) + .expect("Variable marked as cloned, but it isn't"); + + return Some((new_var, help(expr, &substitutions))); + + fn help(expr: &Expr, substitutions: &[(Variable, Variable)]) -> Expr { + use Expr::*; + + macro_rules! sub { + ($var:expr) => { + substitutions + .iter() + .find_map(|&(original, new)| if original == $var { Some(new) } else { None }) + .unwrap_or($var) + }; + } + + let go_help = |e: &Expr| help(e, substitutions); + + match expr { + Num(var, str, val, bound) => Num(sub!(*var), str.clone(), val.clone(), *bound), + Int(v1, v2, str, val, bound) => Int( + sub!(*v1), + sub!(*v2), + str.clone(), + val.clone(), + bound.clone(), + ), + Float(v1, v2, str, val, bound) => Float( + sub!(*v1), + sub!(*v2), + str.clone(), + val.clone(), + bound.clone(), + ), + Str(str) => Str(str.clone()), + SingleQuote(char) => SingleQuote(*char), + List { + elem_var, + loc_elems, + } => List { + elem_var: sub!(*elem_var), + loc_elems: loc_elems.iter().map(|le| le.map(go_help)).collect(), + }, + Var(sym) => Var(*sym), + When { + loc_cond, + cond_var, + expr_var, + region, + branches, + branches_cond_var, + exhaustive, + } => When { + loc_cond: Box::new(loc_cond.map(go_help)), + cond_var: sub!(*cond_var), + expr_var: sub!(*expr_var), + region: *region, + branches: branches + .iter() + .map( + |WhenBranch { + patterns, + value, + guard, + redundant, + }| WhenBranch { + patterns: patterns.clone(), + value: value.map(go_help), + guard: guard.as_ref().map(|le| le.map(go_help)), + redundant: *redundant, + }, + ) + .collect(), + branches_cond_var: sub!(*branches_cond_var), + exhaustive: *exhaustive, + }, + If { + cond_var, + branch_var, + branches, + final_else, + } => If { + cond_var: sub!(*cond_var), + branch_var: sub!(*branch_var), + branches: branches + .iter() + .map(|(c, e)| (c.map(go_help), e.map(go_help))) + .collect(), + final_else: Box::new(final_else.map(go_help)), + }, + + LetRec(defs, body, var) => LetRec( + defs.iter() + .map( + |Def { + loc_pattern, + loc_expr, + expr_var, + pattern_vars, + annotation, + }| Def { + loc_pattern: loc_pattern.clone(), + loc_expr: loc_expr.map(go_help), + expr_var: sub!(*expr_var), + pattern_vars: pattern_vars + .iter() + .map(|(s, v)| (*s, sub!(*v))) + .collect(), + annotation: annotation.clone(), + }, + ) + .collect(), + Box::new(body.map(go_help)), + sub!(*var), + ), + LetNonRec(def, body, var) => { + let Def { + loc_pattern, + loc_expr, + expr_var, + pattern_vars, + annotation, + } = &**def; + let def = Def { + loc_pattern: loc_pattern.clone(), + loc_expr: loc_expr.map(go_help), + expr_var: sub!(*expr_var), + pattern_vars: pattern_vars.iter().map(|(s, v)| (*s, sub!(*v))).collect(), + annotation: annotation.clone(), + }; + LetNonRec(Box::new(def), Box::new(body.map(go_help)), sub!(*var)) + } + + Call(f, args, called_via) => { + let (fn_var, fn_expr, clos_var, ret_var) = &**f; + Call( + Box::new(( + sub!(*fn_var), + fn_expr.map(go_help), + sub!(*clos_var), + sub!(*ret_var), + )), + args.iter() + .map(|(var, expr)| (sub!(*var), expr.map(go_help))) + .collect(), + *called_via, + ) + } + RunLowLevel { op, args, ret_var } => RunLowLevel { + op: *op, + args: args + .iter() + .map(|(var, expr)| (sub!(*var), go_help(expr))) + .collect(), + ret_var: sub!(*ret_var), + }, + ForeignCall { + foreign_symbol, + args, + ret_var, + } => ForeignCall { + foreign_symbol: foreign_symbol.clone(), + args: args + .iter() + .map(|(var, expr)| (sub!(*var), go_help(expr))) + .collect(), + ret_var: sub!(*ret_var), + }, + + Closure(ClosureData { + function_type, + closure_type, + closure_ext_var, + return_type, + name, + captured_symbols, + recursive, + arguments, + loc_body, + }) => Closure(ClosureData { + function_type: sub!(*function_type), + closure_type: sub!(*closure_type), + closure_ext_var: sub!(*closure_ext_var), + return_type: sub!(*return_type), + name: *name, + captured_symbols: captured_symbols + .iter() + .map(|(s, v)| (*s, sub!(*v))) + .collect(), + recursive: *recursive, + arguments: arguments + .iter() + .map(|(v, mark, pat)| (sub!(*v), *mark, pat.clone())) + .collect(), + loc_body: Box::new(loc_body.map(go_help)), + }), + + Record { record_var, fields } => Record { + record_var: sub!(*record_var), + fields: fields + .iter() + .map( + |( + k, + Field { + var, + region, + loc_expr, + }, + )| { + ( + k.clone(), + Field { + var: sub!(*var), + region: *region, + loc_expr: Box::new(loc_expr.map(go_help)), + }, + ) + }, + ) + .collect(), + }, + + EmptyRecord => EmptyRecord, + + Access { + record_var, + ext_var, + field_var, + loc_expr, + field, + } => Access { + record_var: sub!(*record_var), + ext_var: sub!(*ext_var), + field_var: sub!(*field_var), + loc_expr: Box::new(loc_expr.map(go_help)), + field: field.clone(), + }, + + Accessor(AccessorData { + name, + function_var, + record_var, + closure_var, + closure_ext_var, + ext_var, + field_var, + field, + }) => Accessor(AccessorData { + name: *name, + function_var: sub!(*function_var), + record_var: sub!(*record_var), + closure_var: sub!(*closure_var), + closure_ext_var: sub!(*closure_ext_var), + ext_var: sub!(*ext_var), + field_var: sub!(*field_var), + field: field.clone(), + }), + + Update { + record_var, + ext_var, + symbol, + updates, + } => Update { + record_var: sub!(*record_var), + ext_var: sub!(*ext_var), + symbol: *symbol, + updates: updates + .iter() + .map( + |( + k, + Field { + var, + region, + loc_expr, + }, + )| { + ( + k.clone(), + Field { + var: sub!(*var), + region: *region, + loc_expr: Box::new(loc_expr.map(go_help)), + }, + ) + }, + ) + .collect(), + }, + + Tag { + variant_var, + ext_var, + name, + arguments, + } => Tag { + variant_var: sub!(*variant_var), + ext_var: sub!(*ext_var), + name: name.clone(), + arguments: arguments + .iter() + .map(|(v, e)| (sub!(*v), e.map(go_help))) + .collect(), + }, + + ZeroArgumentTag { + closure_name, + variant_var, + ext_var, + name, + } => ZeroArgumentTag { + closure_name: *closure_name, + variant_var: sub!(*variant_var), + ext_var: sub!(*ext_var), + name: name.clone(), + }, + + OpaqueRef { + opaque_var, + name, + argument, + specialized_def_type, + type_arguments, + lambda_set_variables, + } => OpaqueRef { + opaque_var: sub!(*opaque_var), + name: *name, + argument: Box::new((sub!(argument.0), argument.1.map(go_help))), + // These shouldn't matter for opaques during mono, because they are only used for reporting + // and pretty-printing to the user. During mono we decay immediately into the argument. + // NB: if there are bugs, check if not substituting here is the problem! + specialized_def_type: specialized_def_type.clone(), + type_arguments: type_arguments.clone(), + lambda_set_variables: lambda_set_variables.clone(), + }, + + Expect(e1, e2) => Expect(Box::new(e1.map(go_help)), Box::new(e2.map(go_help))), + + RuntimeError(err) => RuntimeError(err.clone()), + } + } +} + +/// Deep copies the type variables in [`var`], returning a map of original -> new type variable for +/// all type variables copied. +fn deep_copy_type_vars<'a>( arena: &'a Bump, subs: &mut Subs, var: Variable, From 261df36c504f8220f274032996906f4e625ed233 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 3 May 2022 17:46:30 -0400 Subject: [PATCH 799/846] Polymorphic expression specialization works in gen tests --- compiler/can/src/expr.rs | 2 +- compiler/debug_flags/src/lib.rs | 3 +- compiler/mono/src/copy.rs | 238 ++++++------------ compiler/mono/src/ir.rs | 322 ++++++++++++++++++++---- compiler/test_gen/src/gen_num.rs | 1 + compiler/test_gen/src/gen_primitives.rs | 1 + compiler/test_gen/src/gen_tags.rs | 2 +- 7 files changed, 363 insertions(+), 206 deletions(-) diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index 4138ab07ae..b60a552f5c 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -356,7 +356,7 @@ pub struct Field { pub loc_expr: Box>, } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, PartialEq)] pub enum Recursive { NotRecursive = 0, Recursive = 1, diff --git a/compiler/debug_flags/src/lib.rs b/compiler/debug_flags/src/lib.rs index b9d66a42b1..57113222b6 100644 --- a/compiler/debug_flags/src/lib.rs +++ b/compiler/debug_flags/src/lib.rs @@ -34,7 +34,8 @@ macro_rules! dbg_do { ($flag:path, $expr:expr) => { #[cfg(debug_assertions)] { - if std::env::var($flag).as_ref() == Ok(&"0".to_string()) { + let flag = std::env::var($flag); + if !flag.is_err() && flag.as_deref() != Ok("0") { $expr } } diff --git a/compiler/mono/src/copy.rs b/compiler/mono/src/copy.rs index 09ceab75d9..5c0a148d39 100644 --- a/compiler/mono/src/copy.rs +++ b/compiler/mono/src/copy.rs @@ -17,6 +17,9 @@ pub fn deep_copy_type_vars_into_expr<'a>( var: Variable, expr: &Expr, ) -> Option<(Variable, Expr)> { + // Always deal with the root, so that aliases propagate correctly. + let var = subs.get_root_key_without_compacting(var); + let substitutions = deep_copy_type_vars(arena, subs, var); if substitutions.is_empty() { @@ -28,21 +31,23 @@ pub fn deep_copy_type_vars_into_expr<'a>( .find_map(|&(original, new)| if original == var { Some(new) } else { None }) .expect("Variable marked as cloned, but it isn't"); - return Some((new_var, help(expr, &substitutions))); + return Some((new_var, help(subs, expr, &substitutions))); - fn help(expr: &Expr, substitutions: &[(Variable, Variable)]) -> Expr { + fn help(subs: &Subs, expr: &Expr, substitutions: &[(Variable, Variable)]) -> Expr { use Expr::*; macro_rules! sub { - ($var:expr) => { + ($var:expr) => {{ + // Always deal with the root, so that aliases propagate correctly. + let root = subs.get_root_key_without_compacting($var); substitutions .iter() - .find_map(|&(original, new)| if original == $var { Some(new) } else { None }) + .find_map(|&(original, new)| if original == root { Some(new) } else { None }) .unwrap_or($var) - }; + }}; } - let go_help = |e: &Expr| help(e, substitutions); + let go_help = |e: &Expr| help(subs, e, substitutions); match expr { Num(var, str, val, bound) => Num(sub!(*var), str.clone(), val.clone(), *bound), @@ -378,15 +383,13 @@ fn deep_copy_type_vars<'a>( subs: &mut Subs, var: Variable, ) -> Vec<'a, (Variable, Variable)> { + // Always deal with the root, so that unified variables are treated the same. + let var = subs.get_root_key_without_compacting(var); + let mut copied = Vec::with_capacity_in(16, arena); let cloned_var = help(arena, subs, &mut copied, var); - debug_assert!(match cloned_var { - Some(_) => !copied.is_empty(), - None => copied.is_empty(), - }); - // we have tracked all visited variables, and can now traverse them // in one go (without looking at the UnificationTable) and clear the copy field let mut result = Vec::with_capacity_in(copied.len(), arena); @@ -404,41 +407,48 @@ fn deep_copy_type_vars<'a>( return result; #[must_use] - fn help( - arena: &Bump, - subs: &mut Subs, - visited: &mut Vec, - var: Variable, - ) -> Option { + fn help(arena: &Bump, subs: &mut Subs, visited: &mut Vec, var: Variable) -> Variable { use roc_types::subs::Content::*; use roc_types::subs::FlatType::*; + // Always deal with the root, so that unified variables are treated the same. + let var = subs.get_root_key_without_compacting(var); + let desc = subs.get_ref_mut(var); - let content = desc.content; - let rank = desc.rank; - let mark = desc.mark; // Unlike `deep_copy_var` in solve, here we are cloning *all* flex and rigid vars. // So we only want to short-circuit if we've already done the cloning work for a particular // var. if let Some(copy) = desc.copy.into_variable() { - return Some(copy); + return copy; } + let content = desc.content; + + let copy_descriptor = Descriptor { + content: Error, // we'll update this below + rank: desc.rank, + mark: desc.mark, + copy: OptVariable::NONE, + }; + + let copy = subs.fresh(copy_descriptor); + subs.get_ref_mut(var).copy = copy.into(); + + visited.push(var); + macro_rules! descend_slice { - ($slice:expr, $needs_clone:ident) => { + ($slice:expr) => { for var_index in $slice { let var = subs[var_index]; - $needs_clone = $needs_clone || help(arena, subs, visited, var).is_some(); + let _ = help(arena, subs, visited, var); } }; } macro_rules! descend_var { - ($var:expr, $needs_clone:ident) => {{ - let new_var = help(arena, subs, visited, $var).unwrap_or($var); - $needs_clone = $needs_clone || new_var != $var; - new_var + ($var:expr) => {{ + help(arena, subs, visited, $var) }}; } @@ -455,65 +465,56 @@ fn deep_copy_type_vars<'a>( } macro_rules! perform_clone { - ($needs_clone:ident, $do_clone:expr) => { - if $needs_clone { - // It may the case that while deep-copying nested variables of this type, we - // ended up copying the type itself (notably if it was self-referencing, in a - // recursive type). In that case, short-circuit with the known copy. - if let Some(copy) = subs.get_ref(var).copy.into_variable() { - return Some(copy); - } - // Perform the clone. - Some($do_clone) - } else { - None - } - }; + ($do_clone:expr) => {{ + // It may the case that while deep-copying nested variables of this type, we + // ended up copying the type itself (notably if it was self-referencing, in a + // recursive type). In that case, short-circuit with the known copy. + // if let Some(copy) = subs.get_ref(var).copy.into_variable() { + // return copy; + // } + // Perform the clone. + $do_clone + }}; } // Now we recursively copy the content of the variable. // We have already marked the variable as copied, so we // will not repeat this work or crawl this variable again. - let opt_new_content = match content { + let new_content = match content { // The vars for which we want to do something interesting. - FlexVar(opt_name) => Some(FlexVar(opt_name)), - FlexAbleVar(opt_name, ability) => Some(FlexAbleVar(opt_name, ability)), - RigidVar(name) => Some(RigidVar(name)), - RigidAbleVar(name, ability) => Some(RigidAbleVar(name, ability)), + FlexVar(opt_name) => FlexVar(opt_name), + FlexAbleVar(opt_name, ability) => FlexAbleVar(opt_name, ability), + RigidVar(name) => RigidVar(name), + RigidAbleVar(name, ability) => RigidAbleVar(name, ability), // Everything else is a mechanical descent. Structure(flat_type) => match flat_type { - EmptyRecord | EmptyTagUnion | Erroneous(_) => None, + EmptyRecord | EmptyTagUnion | Erroneous(_) => Structure(flat_type.clone()), Apply(symbol, arguments) => { - let mut needs_clone = false; - descend_slice!(arguments, needs_clone); + descend_slice!(arguments); - perform_clone!(needs_clone, { + perform_clone!({ let new_arguments = clone_var_slice!(arguments); Structure(Apply(symbol, new_arguments)) }) } Func(arguments, closure_var, ret_var) => { - let mut needs_clone = false; + descend_slice!(arguments); - descend_slice!(arguments, needs_clone); + let new_closure_var = descend_var!(closure_var); + let new_ret_var = descend_var!(ret_var); - let new_closure_var = descend_var!(closure_var, needs_clone); - let new_ret_var = descend_var!(ret_var, needs_clone); - - perform_clone!(needs_clone, { + perform_clone!({ let new_arguments = clone_var_slice!(arguments); Structure(Func(new_arguments, new_closure_var, new_ret_var)) }) } Record(fields, ext_var) => { - let mut needs_clone = false; + let new_ext_var = descend_var!(ext_var); - let new_ext_var = descend_var!(ext_var, needs_clone); + descend_slice!(fields.variables()); - descend_slice!(fields.variables(), needs_clone); - - perform_clone!(needs_clone, { + perform_clone!({ let new_variables = clone_var_slice!(fields.variables()); let new_fields = { RecordFields { @@ -528,16 +529,14 @@ fn deep_copy_type_vars<'a>( }) } TagUnion(tags, ext_var) => { - let mut needs_clone = false; - - let new_ext_var = descend_var!(ext_var, needs_clone); + let new_ext_var = descend_var!(ext_var); for variables_slice_index in tags.variables() { let variables_slice = subs[variables_slice_index]; - descend_slice!(variables_slice, needs_clone); + descend_slice!(variables_slice); } - perform_clone!(needs_clone, { + perform_clone!({ let new_variable_slices = SubsSlice::reserve_variable_slices(subs, tags.len()); let it = (new_variable_slices.indices()).zip(tags.variables()); @@ -554,17 +553,15 @@ fn deep_copy_type_vars<'a>( }) } RecursiveTagUnion(rec_var, tags, ext_var) => { - let mut needs_clone = false; - - let new_ext_var = descend_var!(ext_var, needs_clone); - let new_rec_var = descend_var!(rec_var, needs_clone); + let new_ext_var = descend_var!(ext_var); + let new_rec_var = descend_var!(rec_var); for variables_slice_index in tags.variables() { let variables_slice = subs[variables_slice_index]; - descend_slice!(variables_slice, needs_clone); + descend_slice!(variables_slice); } - perform_clone!(needs_clone, { + perform_clone!({ let new_variable_slices = SubsSlice::reserve_variable_slices(subs, tags.len()); let it = (new_variable_slices.indices()).zip(tags.variables()); @@ -581,11 +578,8 @@ fn deep_copy_type_vars<'a>( }) } FunctionOrTagUnion(tag_name, symbol, ext_var) => { - let mut needs_clone = false; - let new_ext_var = descend_var!(ext_var, needs_clone); - perform_clone!(needs_clone, { - Structure(FunctionOrTagUnion(tag_name, symbol, new_ext_var)) - }) + let new_ext_var = descend_var!(ext_var); + perform_clone!(Structure(FunctionOrTagUnion(tag_name, symbol, new_ext_var))) } }, @@ -593,11 +587,9 @@ fn deep_copy_type_vars<'a>( opt_name, structure, } => { - let mut needs_clone = false; + let new_structure = descend_var!(structure); - let new_structure = descend_var!(structure, needs_clone); - - perform_clone!(needs_clone, { + perform_clone!({ RecursionVar { opt_name, structure: new_structure, @@ -606,12 +598,10 @@ fn deep_copy_type_vars<'a>( } Alias(symbol, arguments, real_type_var, kind) => { - let mut needs_clone = false; + let new_real_type_var = descend_var!(real_type_var); + descend_slice!(arguments.all_variables()); - let new_real_type_var = descend_var!(real_type_var, needs_clone); - descend_slice!(arguments.all_variables(), needs_clone); - - perform_clone!(needs_clone, { + perform_clone!({ let new_variables = clone_var_slice!(arguments.all_variables()); let new_arguments = AliasVariables { variables_start: new_variables.start, @@ -623,41 +613,21 @@ fn deep_copy_type_vars<'a>( } RangedNumber(typ, range_vars) => { - let mut needs_clone = false; + let new_typ = descend_var!(typ); + descend_slice!(range_vars); - let new_typ = descend_var!(typ, needs_clone); - descend_slice!(range_vars, needs_clone); - - perform_clone!(needs_clone, { + perform_clone!({ let new_range_vars = clone_var_slice!(range_vars); RangedNumber(new_typ, new_range_vars) }) } - Error => None, + Error => Error, }; - if let Some(new_content) = opt_new_content { - visited.push(var); + subs.set_content(copy, new_content); - let copy_descriptor = Descriptor { - content: new_content, - rank, - mark, - copy: OptVariable::NONE, - }; - - let copy = subs.fresh(copy_descriptor); - // Set the copy on the original var - subs.get_ref_mut(var).copy = copy.into(); - - // We had to create a fresh var for this type, so anything that depends on it should be - // freshened too, and use this fresh var. - return Some(copy); - } - - // Doesn't need to be freshened; use the old var. - None + copy } } @@ -777,50 +747,6 @@ mod test { } } - #[test] - fn types_without_type_vars_should_not_be_copied() { - let mut subs = Subs::new(); - let arena = Bump::new(); - - let cases = &[ - RecursionVar { - structure: new_var(&mut subs, Structure(EmptyTagUnion)), - opt_name: None, - }, - Structure(Record( - RecordFields::insert_into_subs( - &mut subs, - [("a".into(), RecordField::Required(Variable::BOOL))], - ), - Variable::EMPTY_RECORD, - )), - Structure(TagUnion( - UnionTags::insert_into_subs( - &mut subs, - [(TagName::Tag("A".into()), [Variable::BOOL])], - ), - Variable::EMPTY_TAG_UNION, - )), - Structure(RecursiveTagUnion( - Variable::EMPTY_TAG_UNION, - UnionTags::insert_into_subs( - &mut subs, - [(TagName::Tag("A".into()), [Variable::BOOL])], - ), - Variable::EMPTY_TAG_UNION, - )), - Error, - ]; - - for &content in cases { - let var = new_var(&mut subs, content); - - let copies = deep_copy_type_vars(&arena, &mut subs, var); - - assert!(copies.is_empty()); - } - } - #[test] fn copy_type_with_copied_reference() { let mut subs = Subs::new(); diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 1fb5bfd4a2..4c9476a40f 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -4,7 +4,7 @@ use crate::layout::{ Builtin, ClosureRepresentation, LambdaSet, Layout, LayoutCache, LayoutProblem, RawFunctionLayout, TagIdIntType, UnionLayout, WrappedVariant, }; -use bumpalo::collections::Vec; +use bumpalo::collections::{CollectIn, Vec}; use bumpalo::Bump; use roc_builtins::bitcode::{FloatWidth, IntWidth}; use roc_can::abilities::AbilitiesStore; @@ -2580,6 +2580,19 @@ fn specialize_external<'a>( _ => unreachable!("to closure or not to closure?"), } + let proc_args: Vec<_> = proc_args + .iter() + .map(|&(layout, symbol)| { + let (symbol) = procs + .needed_symbol_specializations + .get(&(symbol, layout)) + .map(|(_, specialized_symbol)| *specialized_symbol) + .unwrap_or(symbol); + + (layout, symbol) + }) + .collect_in(env.arena); + // reset subs, so we don't get type errors when specializing for a different signature layout_cache.rollback_to(cache_snapshot); env.subs.rollback_to(snapshot); @@ -2591,7 +2604,7 @@ fn specialize_external<'a>( let proc = Proc { name: proc_name, - args: proc_args, + args: proc_args.into_bump_slice(), body: specialized_body, closure_data_layout, ret_layout, @@ -3246,15 +3259,135 @@ pub fn with_hole<'a>( ) } else { let rest = build_rest(env, procs, layout_cache); - with_hole( - env, - def.loc_expr.value, - def.expr_var, - procs, - layout_cache, - symbol, - env.arena.alloc(rest), - ) + // with_hole( + // env, + // def.loc_expr.value, + // def.expr_var, + // procs, + // layout_cache, + // symbol, + // env.arena.alloc(rest), + // ) + + let needs_def_specializations = procs + .needed_symbol_specializations + .keys() + .find(|(s, _)| *s == symbol) + .is_some(); + + if !needs_def_specializations { + return with_hole( + env, + def.loc_expr.value, + def.expr_var, + procs, + layout_cache, + symbol, + env.arena.alloc(rest), + ); + } + + // We do need specializations + + let mut stmt = rest; + let mut needed_specializations = procs + .needed_symbol_specializations + .drain_filter(|(s, _), _| *s == symbol) + .collect::>(); + + if needed_specializations.len() == 1 { + let ((_, _wanted_layout), (var, specialized_symbol)) = + needed_specializations.pop().unwrap(); + + // Unify the expr_var with the requested specialization once. + let _res = roc_unify::unify::unify(env.subs, var, def.expr_var, Mode::EQ); + + return with_hole( + env, + def.loc_expr.value, + def.expr_var, + procs, + layout_cache, + specialized_symbol, + env.arena.alloc(stmt), + ); + } else { + // Need to eat the cost and create a specialized version of the body for each specialization. + for ((_, wanted_layout), (var, specialized_symbol)) in + needed_specializations + { + macro_rules! p { + ($v:expr) => {{ + let content = env.subs.get_content_without_compacting($v); + let c = roc_types::subs::SubsFmtContent(content, env.subs); + c + }}; + } + // let res = + // roc_unify::unify::unify(env.subs, var, def.expr_var, Mode::EQ); + // let content = env.subs.get_content_without_compacting(def.expr_var); + // let c = roc_types::subs::SubsFmtContent(content, env.subs); + // let content2 = env.subs.get_content_without_compacting(var); + // let c2 = roc_types::subs::SubsFmtContent(content2, env.subs); + // let layout = layout_cache + // .from_var(env.arena, def.expr_var, env.subs) + // .unwrap(); + // dbg!( + // specialized_symbol, + // c, + // c2, + // layout, + // wanted_layout, + // var, + // def.expr_var, + // ); + + use crate::copy::deep_copy_type_vars_into_expr; + + let (new_def_expr_var, specialized_expr) = + deep_copy_type_vars_into_expr( + env.arena, + env.subs, + def.expr_var, + &def.loc_expr.value + ).expect("expr marked as having specializations, but it has no type variables!"); + + // dbg!(&def.loc_expr.value, &specialized_expr); + + // dbg!( + // def.expr_var, + // p!(def.expr_var), + // var, + // p!(var), + // new_def_expr_var, + // p!(new_def_expr_var) + // ); + + let _res = + roc_unify::unify::unify(env.subs, var, new_def_expr_var, Mode::EQ); + + // dbg!( + // def.expr_var, + // p!(def.expr_var), + // var, + // p!(var), + // new_def_expr_var, + // p!(new_def_expr_var) + // ); + + stmt = with_hole( + env, + specialized_expr, + new_def_expr_var, + procs, + layout_cache, + specialized_symbol, + env.arena.alloc(stmt), + ); + } + + return stmt; + } } } else { // this may be a destructure pattern @@ -3397,9 +3530,17 @@ pub fn with_hole<'a>( OpaqueRef { argument, .. } => { let (arg_var, loc_arg_expr) = *argument; + // TODO(POLYEXPR): can this just be `possible_reuse_symbol_or_spec`? match can_reuse_symbol(env, procs, &loc_arg_expr.value) { // Opaques decay to their argument. ReuseSymbol::Value(real_name) => { + let real_name = possible_reuse_symbol_or_spec( + env, + procs, + layout_cache, + &loc_arg_expr.value, + arg_var, + ); let mut result = hole.clone(); substitute_in_exprs(arena, &mut result, assigned, real_name); result @@ -3655,7 +3796,8 @@ pub fn with_hole<'a>( branches_cond_var: _, exhaustive, } => { - let cond_symbol = possible_reuse_symbol(env, procs, &loc_cond.value); + let cond_symbol = + possible_reuse_symbol_or_spec(env, procs, layout_cache, &loc_cond.value, cond_var); let id = JoinPointId(env.unique_symbol()); @@ -5335,7 +5477,8 @@ pub fn from_can<'a>( branches_cond_var: _, exhaustive, } => { - let cond_symbol = possible_reuse_symbol(env, procs, &loc_cond.value); + let cond_symbol = + possible_reuse_symbol_or_spec(env, procs, layout_cache, &loc_cond.value, cond_var); let stmt = from_can_when( env, @@ -5641,11 +5784,14 @@ pub fn from_can<'a>( let ((_, _wanted_layout), (var, specialized_symbol)) = needed_specializations.pop().unwrap(); + // Unify the expr_var with the requested specialization once. + let _res = + roc_unify::unify::unify(env.subs, var, def.expr_var, Mode::EQ); + return with_hole( env, def.loc_expr.value, - // def.expr_var, - var, + def.expr_var, procs, layout_cache, specialized_symbol, @@ -5656,29 +5802,73 @@ pub fn from_can<'a>( for ((_, wanted_layout), (var, specialized_symbol)) in needed_specializations { + macro_rules! p { + ($v:expr) => {{ + let content = env.subs.get_content_without_compacting($v); + let c = roc_types::subs::SubsFmtContent(content, env.subs); + c + }}; + } // let res = // roc_unify::unify::unify(env.subs, var, def.expr_var, Mode::EQ); - let content = env.subs.get_content_without_compacting(def.expr_var); - let c = roc_types::subs::SubsFmtContent(content, env.subs); - let content2 = env.subs.get_content_without_compacting(var); - let c2 = roc_types::subs::SubsFmtContent(content2, env.subs); - let layout = layout_cache - .from_var(env.arena, def.expr_var, env.subs) - .unwrap(); - dbg!( - specialized_symbol, - c, - c2, - layout, - wanted_layout, + // let content = env.subs.get_content_without_compacting(def.expr_var); + // let c = roc_types::subs::SubsFmtContent(content, env.subs); + // let content2 = env.subs.get_content_without_compacting(var); + // let c2 = roc_types::subs::SubsFmtContent(content2, env.subs); + // let layout = layout_cache + // .from_var(env.arena, def.expr_var, env.subs) + // .unwrap(); + // dbg!( + // specialized_symbol, + // c, + // c2, + // layout, + // wanted_layout, + // var, + // def.expr_var, + // ); + + use crate::copy::deep_copy_type_vars_into_expr; + + let (new_def_expr_var, specialized_expr) = + deep_copy_type_vars_into_expr( + env.arena, + env.subs, + def.expr_var, + &def.loc_expr.value + ).expect("expr marked as having specializations, but it has no type variables!"); + + // dbg!(&def.loc_expr.value, &specialized_expr); + + // dbg!( + // def.expr_var, + // p!(def.expr_var), + // var, + // p!(var), + // new_def_expr_var, + // p!(new_def_expr_var) + // ); + + let _res = roc_unify::unify::unify( + env.subs, var, - def.expr_var, + new_def_expr_var, + Mode::EQ, ); + + // dbg!( + // def.expr_var, + // p!(def.expr_var), + // var, + // p!(var), + // new_def_expr_var, + // p!(new_def_expr_var) + // ); + stmt = with_hole( env, - def.loc_expr.value.clone(), - // def.expr_var, - var, + specialized_expr, + new_def_expr_var, procs, layout_cache, specialized_symbol, @@ -6740,23 +6930,45 @@ fn possible_reuse_symbol_or_spec<'a>( ) -> Symbol { match can_reuse_symbol(env, procs, expr) { ReuseSymbol::Value(symbol) => { - let wanted_layout = layout_cache.from_var(env.arena, var, env.subs).unwrap(); + let wanted_layout = match layout_cache.from_var(env.arena, var, env.subs) { + Ok(layout) => layout, + // This can happen when the def symbol has a type error. In such cases just use the + // def symbol, which is erroring. + Err(_) => return symbol, + }; - let mut fake_subs = env.subs.clone(); - let new_var = roc_types::subs::deep_copy_var_to(&mut fake_subs, env.subs, var); - let content = roc_types::subs::SubsFmtContent( - env.subs.get_content_without_compacting(new_var), - env.subs, - ); - dbg!(new_var, content); + // For the first specialization, always reuse the current symbol. Two reasons for this: + // 1. More readable + // 2. Will still have bugs where we're not always specializing the original symbol + // will all specialization symbols. In such cases, just re-use the original for + // now. + let needs_fresh_symbol = procs + .needed_symbol_specializations + .keys() + .find(|(s, _)| *s == symbol) + .is_some(); let (_, specialized_symbol) = procs .needed_symbol_specializations .entry((symbol, wanted_layout)) - .or_insert_with(|| (new_var, env.unique_symbol())); - - dbg!(symbol, *specialized_symbol, wanted_layout, var); + .or_insert_with(|| { + ( + var, + if needs_fresh_symbol { + env.unique_symbol() + } else { + symbol + }, + ) + }); + // if format!("{:?}", *specialized_symbol).contains("IdentId(19)") { + // panic!(); + // } + dbg!(symbol, *specialized_symbol, wanted_layout); + // if true { + // panic!() + // } *specialized_symbol } _ => env.unique_symbol(), @@ -6820,6 +7032,8 @@ where } else { // This should be a fully specialized value. Replace the alias with the original symbol. let mut result = build_rest(env, procs, layout_cache); + // dbg!(&result); + dbg!(&procs.needed_symbol_specializations); // We need to lift all specializations of "left" to be specializations of "right". let to_update = procs @@ -6827,6 +7041,11 @@ where .drain_filter(|(s, _), _| s == &left) .collect::>(); let mut scratchpad_update_specializations = std::vec::Vec::new(); + + dbg!(left, right, &to_update); + + let left_had_specialization_symbols = !to_update.is_empty(); + for ((_, layout), (specialized_var, specialized_sym)) in to_update.into_iter() { let old_specialized_sym = procs .needed_symbol_specializations @@ -6836,12 +7055,21 @@ where scratchpad_update_specializations.push((old_specialized_sym, specialized_sym)); } } + dbg!(&procs.needed_symbol_specializations); - substitute_in_exprs(env.arena, &mut result, left, right); - for (old_specialized_sym, specialized_sym) in scratchpad_update_specializations.into_iter() - { - substitute_in_exprs(env.arena, &mut result, old_specialized_sym, specialized_sym); + if left_had_specialization_symbols { + // If the symbol is specialized, only the specializations need to be updated. + for (old_specialized_sym, specialized_sym) in + scratchpad_update_specializations.into_iter() + { + dbg!((old_specialized_sym, "->", specialized_sym)); + substitute_in_exprs(env.arena, &mut result, old_specialized_sym, specialized_sym); + } + } else { + dbg!((left, "=>", right)); + substitute_in_exprs(env.arena, &mut result, left, right); } + result } } diff --git a/compiler/test_gen/src/gen_num.rs b/compiler/test_gen/src/gen_num.rs index afa236c687..eaabeb8f20 100644 --- a/compiler/test_gen/src/gen_num.rs +++ b/compiler/test_gen/src/gen_num.rs @@ -612,6 +612,7 @@ fn i64_abs() { #[test] #[cfg(any(feature = "gen-llvm"))] +#[should_panic = "integer absolute overflowed because its argument is the minimum value"] fn abs_min_int_overflow() { assert_evals_to!( indoc!( diff --git a/compiler/test_gen/src/gen_primitives.rs b/compiler/test_gen/src/gen_primitives.rs index 8e7e86eca1..c48c91d0a2 100644 --- a/compiler/test_gen/src/gen_primitives.rs +++ b/compiler/test_gen/src/gen_primitives.rs @@ -3267,6 +3267,7 @@ fn polymophic_expression_captured_inside_closure() { #[test] #[cfg(any(feature = "gen-llvm"))] +#[ignore = "Compile polymorphic functions"] fn issue_2322() { assert_evals_to!( indoc!( diff --git a/compiler/test_gen/src/gen_tags.rs b/compiler/test_gen/src/gen_tags.rs index 170555d16b..25648b37e4 100644 --- a/compiler/test_gen/src/gen_tags.rs +++ b/compiler/test_gen/src/gen_tags.rs @@ -1319,7 +1319,7 @@ fn monomorphized_applied_tag() { #[test] #[cfg(any(feature = "gen-llvm"))] -fn monomorphized_tag_with_polymorphic_arg1() { +fn monomorphized_tag_with_polymorphic_arg() { assert_evals_to!( indoc!( r#" From c070bfed8bb99c7bea59ffd5008d3e1a495c4673 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 3 May 2022 18:03:18 -0400 Subject: [PATCH 800/846] Little bit of cleanup --- compiler/mono/src/copy.rs | 2 + compiler/mono/src/ir.rs | 413 +++----------------------------------- 2 files changed, 25 insertions(+), 390 deletions(-) diff --git a/compiler/mono/src/copy.rs b/compiler/mono/src/copy.rs index 5c0a148d39..229e3043a0 100644 --- a/compiler/mono/src/copy.rs +++ b/compiler/mono/src/copy.rs @@ -404,6 +404,8 @@ fn deep_copy_type_vars<'a>( } } + debug_assert!(result.contains(&(var, cloned_var))); + return result; #[must_use] diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 4c9476a40f..f35029bd4c 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -2583,7 +2583,7 @@ fn specialize_external<'a>( let proc_args: Vec<_> = proc_args .iter() .map(|&(layout, symbol)| { - let (symbol) = procs + let symbol = procs .needed_symbol_specializations .get(&(symbol, layout)) .map(|(_, specialized_symbol)| *specialized_symbol) @@ -3259,135 +3259,15 @@ pub fn with_hole<'a>( ) } else { let rest = build_rest(env, procs, layout_cache); - // with_hole( - // env, - // def.loc_expr.value, - // def.expr_var, - // procs, - // layout_cache, - // symbol, - // env.arena.alloc(rest), - // ) - - let needs_def_specializations = procs - .needed_symbol_specializations - .keys() - .find(|(s, _)| *s == symbol) - .is_some(); - - if !needs_def_specializations { - return with_hole( - env, - def.loc_expr.value, - def.expr_var, - procs, - layout_cache, - symbol, - env.arena.alloc(rest), - ); - } - - // We do need specializations - - let mut stmt = rest; - let mut needed_specializations = procs - .needed_symbol_specializations - .drain_filter(|(s, _), _| *s == symbol) - .collect::>(); - - if needed_specializations.len() == 1 { - let ((_, _wanted_layout), (var, specialized_symbol)) = - needed_specializations.pop().unwrap(); - - // Unify the expr_var with the requested specialization once. - let _res = roc_unify::unify::unify(env.subs, var, def.expr_var, Mode::EQ); - - return with_hole( - env, - def.loc_expr.value, - def.expr_var, - procs, - layout_cache, - specialized_symbol, - env.arena.alloc(stmt), - ); - } else { - // Need to eat the cost and create a specialized version of the body for each specialization. - for ((_, wanted_layout), (var, specialized_symbol)) in - needed_specializations - { - macro_rules! p { - ($v:expr) => {{ - let content = env.subs.get_content_without_compacting($v); - let c = roc_types::subs::SubsFmtContent(content, env.subs); - c - }}; - } - // let res = - // roc_unify::unify::unify(env.subs, var, def.expr_var, Mode::EQ); - // let content = env.subs.get_content_without_compacting(def.expr_var); - // let c = roc_types::subs::SubsFmtContent(content, env.subs); - // let content2 = env.subs.get_content_without_compacting(var); - // let c2 = roc_types::subs::SubsFmtContent(content2, env.subs); - // let layout = layout_cache - // .from_var(env.arena, def.expr_var, env.subs) - // .unwrap(); - // dbg!( - // specialized_symbol, - // c, - // c2, - // layout, - // wanted_layout, - // var, - // def.expr_var, - // ); - - use crate::copy::deep_copy_type_vars_into_expr; - - let (new_def_expr_var, specialized_expr) = - deep_copy_type_vars_into_expr( - env.arena, - env.subs, - def.expr_var, - &def.loc_expr.value - ).expect("expr marked as having specializations, but it has no type variables!"); - - // dbg!(&def.loc_expr.value, &specialized_expr); - - // dbg!( - // def.expr_var, - // p!(def.expr_var), - // var, - // p!(var), - // new_def_expr_var, - // p!(new_def_expr_var) - // ); - - let _res = - roc_unify::unify::unify(env.subs, var, new_def_expr_var, Mode::EQ); - - // dbg!( - // def.expr_var, - // p!(def.expr_var), - // var, - // p!(var), - // new_def_expr_var, - // p!(new_def_expr_var) - // ); - - stmt = with_hole( - env, - specialized_expr, - new_def_expr_var, - procs, - layout_cache, - specialized_symbol, - env.arena.alloc(stmt), - ); - } - - return stmt; - } + with_hole( + env, + def.loc_expr.value, + def.expr_var, + procs, + layout_cache, + symbol, + env.arena.alloc(rest), + ) } } else { // this may be a destructure pattern @@ -3533,7 +3413,7 @@ pub fn with_hole<'a>( // TODO(POLYEXPR): can this just be `possible_reuse_symbol_or_spec`? match can_reuse_symbol(env, procs, &loc_arg_expr.value) { // Opaques decay to their argument. - ReuseSymbol::Value(real_name) => { + ReuseSymbol::Value(_real_name) => { let real_name = possible_reuse_symbol_or_spec( env, procs, @@ -4027,16 +3907,9 @@ pub fn with_hole<'a>( ); match raw_layout { - RawFunctionLayout::Function(_, lambda_set, _) => construct_closure_data( - env, - procs, - layout_cache, - lambda_set, - name, - &[], - assigned, - hole, - ), + RawFunctionLayout::Function(_, lambda_set, _) => { + construct_closure_data(env, lambda_set, name, &[], assigned, hole) + } RawFunctionLayout::ZeroArgumentThunk(_) => unreachable!(), } } @@ -4257,8 +4130,6 @@ pub fn with_hole<'a>( construct_closure_data( env, - procs, - layout_cache, lambda_set, name, symbols.iter().copied(), @@ -4413,53 +4284,7 @@ pub fn with_hole<'a>( assigned, hole, ); - } // TODO(POLYEXPR) - // PolymorphicExpr::Expr(lambda_expr, lambda_expr_var) => { - // match full_layout { - // RawFunctionLayout::Function( - // arg_layouts, - // lambda_set, - // ret_layout, - // ) => { - // let closure_data_symbol = env.unique_symbol(); - - // result = match_on_lambda_set( - // env, - // lambda_set, - // closure_data_symbol, - // arg_symbols, - // arg_layouts, - // ret_layout, - // assigned, - // hole, - // ); - - // let snapshot = env.subs.snapshot(); - // let cache_snapshot = layout_cache.snapshot(); - // let _unified = roc_unify::unify::unify( - // env.subs, - // fn_var, - // *lambda_expr_var, - // roc_unify::unify::Mode::EQ, - // ); - - // result = with_hole( - // env, - // lambda_expr.clone(), - // fn_var, - // procs, - // layout_cache, - // closure_data_symbol, - // env.arena.alloc(result), - // ); - // env.subs.rollback_to(snapshot); - // layout_cache.rollback_to(cache_snapshot); - // } - // RawFunctionLayout::ZeroArgumentThunk(_) => { - // unreachable!("calling a non-closure layout") - // } - // } - // } + } } } NotASymbol => { @@ -4836,10 +4661,6 @@ fn get_specialization<'a>( #[allow(clippy::too_many_arguments)] fn construct_closure_data<'a, I>( env: &mut Env<'a, '_>, - // TODO(POLYEXPR): remove? - _procs: &mut Procs<'a>, - // TODO(POLYEXPR): remove? - _layout_cache: &mut LayoutCache<'a>, lambda_set: LambdaSet<'a>, name: Symbol, symbols: I, @@ -4863,11 +4684,7 @@ where // captured variables are in symbol-alphabetic order, but now we want // them ordered by their alignment requirements let mut combined = Vec::with_capacity_in(symbols.len(), env.arena); - for ((symbol, variable), layout) in symbols.zip(field_layouts.iter()) { - // if procs.partial_exprs.contains(*symbol) { - // polymorphic_arguments.push((*symbol, *variable)); - // } - + for ((symbol, _variable), layout) in symbols.zip(field_layouts.iter()) { combined.push((*symbol, layout)) } @@ -4898,11 +4715,7 @@ where // captured variables are in symbol-alphabetic order, but now we want // them ordered by their alignment requirements let mut combined = Vec::with_capacity_in(symbols.len(), env.arena); - for ((symbol, variable), layout) in symbols.zip(field_layouts.iter()) { - // if procs.partial_exprs.contains(*symbol) { - // polymorphic_arguments.push((*symbol, *variable)); - // } - + for ((symbol, _variable), layout) in symbols.zip(field_layouts.iter()) { combined.push((*symbol, layout)) } @@ -4950,20 +4763,6 @@ where _ => unreachable!(), }; - // Some of the captured symbols may be references to polymorphic expressions, - // which have not been specialized yet. We need to perform those - // specializations now so that there are real symbols to capture. - // - // TODO: this is not quite right. What we should actually be doing is removing references to - // polymorphic expressions from the captured symbols, and allowing the specializations of those - // symbols to be inlined when specializing the closure body elsewhere. - // TODO(POLYEXPR) - // for &&(symbol, var) in symbols { - // if procs.ability_member_aliases.contains(symbol) { - // result = specialize_symbol(env, procs, layout_cache, Some(var), symbol, result, symbol); - // } - // } - result } @@ -5265,16 +5064,9 @@ fn tag_union_to_function<'a>( ); match raw_layout { - RawFunctionLayout::Function(_, lambda_set, _) => construct_closure_data( - env, - procs, - layout_cache, - lambda_set, - proc_symbol, - &[], - assigned, - hole, - ), + RawFunctionLayout::Function(_, lambda_set, _) => { + construct_closure_data(env, lambda_set, proc_symbol, &[], assigned, hole) + } RawFunctionLayout::ZeroArgumentThunk(_) => unreachable!(), } } @@ -5729,28 +5521,6 @@ pub fn from_can<'a>( return from_can(env, variable, new_outer, procs, layout_cache); } - // TODO(POLYEXPR) - // ref body if expr_is_polymorphic(env, body, def.expr_var) => { - // // This is a pattern like - // // - // // n = 1 - // // asU8 n - // // - // // At the definition site `n = 1` we only know `1` to have the type `[Int *]`, - // // which won't be refined until the call `asU8 n`. Add it as a partial expression - // // that will be specialized at each concrete usage site. - // procs.ability_member_aliases.insert( - // *symbol, - // PolymorphicExpr::Expr(def.loc_expr.value, def.expr_var), - // ); - - // let result = from_can(env, variable, cont.value, procs, layout_cache); - - // // We won't see this symbol again. - // procs.ability_member_aliases.remove(*symbol); - - // return result; - // } _ => { let rest = from_can(env, variable, cont.value, procs, layout_cache); @@ -5799,35 +5569,9 @@ pub fn from_can<'a>( ); } else { // Need to eat the cost and create a specialized version of the body for each specialization. - for ((_, wanted_layout), (var, specialized_symbol)) in + for ((_original_symbol, _wanted_layout), (var, specialized_symbol)) in needed_specializations { - macro_rules! p { - ($v:expr) => {{ - let content = env.subs.get_content_without_compacting($v); - let c = roc_types::subs::SubsFmtContent(content, env.subs); - c - }}; - } - // let res = - // roc_unify::unify::unify(env.subs, var, def.expr_var, Mode::EQ); - // let content = env.subs.get_content_without_compacting(def.expr_var); - // let c = roc_types::subs::SubsFmtContent(content, env.subs); - // let content2 = env.subs.get_content_without_compacting(var); - // let c2 = roc_types::subs::SubsFmtContent(content2, env.subs); - // let layout = layout_cache - // .from_var(env.arena, def.expr_var, env.subs) - // .unwrap(); - // dbg!( - // specialized_symbol, - // c, - // c2, - // layout, - // wanted_layout, - // var, - // def.expr_var, - // ); - use crate::copy::deep_copy_type_vars_into_expr; let (new_def_expr_var, specialized_expr) = @@ -5838,17 +5582,6 @@ pub fn from_can<'a>( &def.loc_expr.value ).expect("expr marked as having specializations, but it has no type variables!"); - // dbg!(&def.loc_expr.value, &specialized_expr); - - // dbg!( - // def.expr_var, - // p!(def.expr_var), - // var, - // p!(var), - // new_def_expr_var, - // p!(new_def_expr_var) - // ); - let _res = roc_unify::unify::unify( env.subs, var, @@ -5856,15 +5589,6 @@ pub fn from_can<'a>( Mode::EQ, ); - // dbg!( - // def.expr_var, - // p!(def.expr_var), - // var, - // p!(var), - // new_def_expr_var, - // p!(new_def_expr_var) - // ); - stmt = with_hole( env, specialized_expr, @@ -6519,23 +6243,6 @@ fn store_pattern_help<'a>( match can_pat { Identifier(symbol) => { - // TODO(POLYEXPR) - // if let Some(&PolymorphicExpr::Expr(_, var)) = - // procs.ability_member_aliases.get(outer_symbol) - // { - // // It might be the case that symbol we're storing hasn't been reified to a value - // // yet, if it's polymorphic. Do that now. - // stmt = specialize_symbol( - // env, - // procs, - // layout_cache, - // Some(var), - // *symbol, - // stmt, - // outer_symbol, - // ); - // } - substitute_in_exprs(env.arena, &mut stmt, *symbol, outer_symbol); } Underscore => { @@ -6962,13 +6669,6 @@ fn possible_reuse_symbol_or_spec<'a>( ) }); - // if format!("{:?}", *specialized_symbol).contains("IdentId(19)") { - // panic!(); - // } - dbg!(symbol, *specialized_symbol, wanted_layout); - // if true { - // panic!() - // } *specialized_symbol } _ => env.unique_symbol(), @@ -7032,8 +6732,6 @@ where } else { // This should be a fully specialized value. Replace the alias with the original symbol. let mut result = build_rest(env, procs, layout_cache); - // dbg!(&result); - dbg!(&procs.needed_symbol_specializations); // We need to lift all specializations of "left" to be specializations of "right". let to_update = procs @@ -7042,8 +6740,6 @@ where .collect::>(); let mut scratchpad_update_specializations = std::vec::Vec::new(); - dbg!(left, right, &to_update); - let left_had_specialization_symbols = !to_update.is_empty(); for ((_, layout), (specialized_var, specialized_sym)) in to_update.into_iter() { @@ -7055,18 +6751,15 @@ where scratchpad_update_specializations.push((old_specialized_sym, specialized_sym)); } } - dbg!(&procs.needed_symbol_specializations); if left_had_specialization_symbols { // If the symbol is specialized, only the specializations need to be updated. for (old_specialized_sym, specialized_sym) in scratchpad_update_specializations.into_iter() { - dbg!((old_specialized_sym, "->", specialized_sym)); substitute_in_exprs(env.arena, &mut result, old_specialized_sym, specialized_sym); } } else { - dbg!((left, "=>", right)); substitute_in_exprs(env.arena, &mut result, left, right); } @@ -7108,37 +6801,6 @@ fn specialize_symbol<'a>( result: Stmt<'a>, original: Symbol, ) -> Stmt<'a> { - // TODO(POLYEXPR) - // if let Some(PolymorphicExpr::Expr(expr, expr_var)) = procs.ability_member_aliases.get(original) - // { - // // Specialize the expression type now, based off the `arg_var` we've been given. - // // TODO: cache the specialized result - // let snapshot = env.subs.snapshot(); - // let cache_snapshot = layout_cache.snapshot(); - // let _unified = roc_unify::unify::unify( - // env.subs, - // arg_var.unwrap(), - // *expr_var, - // roc_unify::unify::Mode::EQ, - // ); - - // let result = with_hole( - // env, - // expr.clone(), - // *expr_var, - // procs, - // layout_cache, - // symbol, - // env.arena.alloc(result), - // ); - - // // Restore the prior state so as not to interfere with future specializations. - // env.subs.rollback_to(snapshot); - // layout_cache.rollback_to(cache_snapshot); - - // return result; - // } - match procs.get_partial_proc(original) { None => { match arg_var { @@ -7238,8 +6900,6 @@ fn specialize_symbol<'a>( construct_closure_data( env, - procs, - layout_cache, lambda_set, original, symbols.iter().copied(), @@ -7276,8 +6936,6 @@ fn specialize_symbol<'a>( // unification may still cause it to have an extra argument construct_closure_data( env, - procs, - layout_cache, lambda_set, original, &[], @@ -7321,19 +6979,7 @@ fn assign_to_symbol<'a>( original, ) } - Value(_symbol) => { - //let wanted_layout = layout_cache.from_var(env.arena, arg_var, env.subs).unwrap(); - //let (_, specialized_symbol) = procs - // .needed_symbol_specializations - // .entry((symbol, wanted_layout)) - // .or_insert_with(|| (arg_var, env.unique_symbol())); - - //dbg!(symbol, wanted_layout); - - //let mut result = result; - //substitute_in_exprs(env.arena, &mut result, symbol, *specialized_symbol); - result - } + Value(_symbol) => result, NotASymbol => with_hole( env, loc_arg.value, @@ -7650,16 +7296,7 @@ fn call_by_name_help<'a>( // imported symbols cannot capture anything let captured = &[]; - construct_closure_data( - env, - procs, - layout_cache, - lambda_set, - proc_name, - captured, - assigned, - hole, - ) + construct_closure_data(env, lambda_set, proc_name, captured, assigned, hole) } else { debug_assert_eq!( argument_layouts.len(), @@ -7752,8 +7389,6 @@ fn call_by_name_help<'a>( construct_closure_data( env, - procs, - layout_cache, lambda_set, proc_name, captured.iter(), @@ -8042,8 +7677,6 @@ fn call_specialized_proc<'a>( let result = construct_closure_data( env, - procs, - layout_cache, lambda_set, proc_name, symbols.iter().copied(), From f4b7ea245c71fb8b433ee40abdec29f351c3bdc7 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 3 May 2022 18:31:34 -0400 Subject: [PATCH 801/846] Always specialize reuse symbol --- compiler/mono/src/ir.rs | 97 +++++++++++++++++++++++++++-------------- 1 file changed, 65 insertions(+), 32 deletions(-) diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index f35029bd4c..07636a2e2d 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -3615,8 +3615,13 @@ pub fn with_hole<'a>( ); for (loc_cond, loc_then) in branches.into_iter().rev() { - let branching_symbol = - possible_reuse_symbol(env, procs, &loc_cond.value); + let branching_symbol = possible_reuse_symbol_or_spec( + env, + procs, + layout_cache, + &loc_cond.value, + cond_var, + ); let then = with_hole( env, @@ -3766,7 +3771,13 @@ pub fn with_hole<'a>( if let Some(literal) = try_make_literal(env, &arg_expr.value) { elements.push(ListLiteralElement::Literal(literal)); } else { - let symbol = possible_reuse_symbol(env, procs, &arg_expr.value); + let symbol = possible_reuse_symbol_or_spec( + env, + procs, + layout_cache, + &arg_expr.value, + elem_var, + ); elements.push(ListLiteralElement::Symbol(symbol)); arg_symbols.push(symbol); @@ -3839,7 +3850,13 @@ pub fn with_hole<'a>( } } - let record_symbol = possible_reuse_symbol(env, procs, &loc_expr.value); + let record_symbol = possible_reuse_symbol_or_spec( + env, + procs, + layout_cache, + &loc_expr.value, + record_var, + ); let mut stmt = match field_layouts.as_slice() { [_] => { @@ -3964,9 +3981,13 @@ pub fn with_hole<'a>( field_layouts.push(field_layout); if let Some(field) = updates.get(&label) { - // TODO - let field_symbol = - possible_reuse_symbol(env, procs, &field.loc_expr.value); + let field_symbol = possible_reuse_symbol_or_spec( + env, + procs, + layout_cache, + &field.loc_expr.value, + field.var, + ); fields.push(UpdateExisting(field)); symbols.push(field_symbol); @@ -4190,8 +4211,14 @@ pub fn with_hole<'a>( // (\f, x -> f x) let arg_symbols = Vec::from_iter_in( - loc_args.iter().map(|(_, arg_expr)| { - possible_reuse_symbol(env, procs, &arg_expr.value) + loc_args.iter().map(|(var, arg_expr)| { + possible_reuse_symbol_or_spec( + env, + procs, + layout_cache, + &arg_expr.value, + *var, + ) }), arena, ) @@ -4342,8 +4369,14 @@ pub fn with_hole<'a>( } => { let mut arg_symbols = Vec::with_capacity_in(args.len(), env.arena); - for (_, arg_expr) in args.iter() { - arg_symbols.push(possible_reuse_symbol(env, procs, arg_expr)); + for (var, arg_expr) in args.iter() { + arg_symbols.push(possible_reuse_symbol_or_spec( + env, + procs, + layout_cache, + arg_expr, + *var, + )); } let arg_symbols = arg_symbols.into_bump_slice(); @@ -4372,8 +4405,14 @@ pub fn with_hole<'a>( RunLowLevel { op, args, ret_var } => { let mut arg_symbols = Vec::with_capacity_in(args.len(), env.arena); - for (_, arg_expr) in args.iter() { - arg_symbols.push(possible_reuse_symbol(env, procs, arg_expr)); + for (var, arg_expr) in args.iter() { + arg_symbols.push(possible_reuse_symbol_or_spec( + env, + procs, + layout_cache, + arg_expr, + *var, + )); } let arg_symbols = arg_symbols.into_bump_slice(); @@ -5311,7 +5350,13 @@ pub fn from_can<'a>( let mut stmt = from_can(env, branch_var, final_else.value, procs, layout_cache); for (loc_cond, loc_then) in branches.into_iter().rev() { - let branching_symbol = possible_reuse_symbol(env, procs, &loc_cond.value); + let branching_symbol = possible_reuse_symbol_or_spec( + env, + procs, + layout_cache, + &loc_cond.value, + cond_var, + ); let then = from_can(env, branch_var, loc_then.value, procs, layout_cache); stmt = cond(env, branching_symbol, cond_layout, then, stmt, ret_layout); @@ -6406,7 +6451,7 @@ fn store_tag_pattern<'a>( stmt = new; // only if we bind one of its (sub)fields to a used name should we // extract the field - stmt = Stmt::Let(symbol, load, arg_layout, env.arena.alloc(stmt)); + stmt = Stmt::Let(dbg!(symbol), load, arg_layout, env.arena.alloc(stmt)); } StorePattern::NotProductive(new) => { // do nothing @@ -6459,7 +6504,7 @@ fn store_newtype_pattern<'a>( match argument { Identifier(symbol) => { // store immediately in the given symbol - stmt = Stmt::Let(*symbol, load, arg_layout, env.arena.alloc(stmt)); + stmt = Stmt::Let(dbg!(*symbol), load, arg_layout, env.arena.alloc(stmt)); is_productive = true; } Underscore => { @@ -6482,7 +6527,7 @@ fn store_newtype_pattern<'a>( stmt = new; // only if we bind one of its (sub)fields to a used name should we // extract the field - stmt = Stmt::Let(symbol, load, arg_layout, env.arena.alloc(stmt)); + stmt = Stmt::Let(dbg!(symbol), load, arg_layout, env.arena.alloc(stmt)); } StorePattern::NotProductive(new) => { // do nothing @@ -6616,18 +6661,6 @@ fn can_reuse_symbol<'a>( } } -fn possible_reuse_symbol<'a>( - env: &mut Env<'a, '_>, - procs: &Procs<'a>, - expr: &roc_can::expr::Expr, -) -> Symbol { - match can_reuse_symbol(env, procs, expr) { - ReuseSymbol::Value(s) => s, - _ => env.unique_symbol(), - } -} - -// TODO(POLYEXPR): unify with possible_reuse_symbol fn possible_reuse_symbol_or_spec<'a>( env: &mut Env<'a, '_>, procs: &mut Procs<'a>, @@ -7057,9 +7090,9 @@ fn evaluate_arguments_then_runtime_error<'a>( // but, we also still evaluate and specialize the arguments to give better error messages let arg_symbols = Vec::from_iter_in( - loc_args - .iter() - .map(|(_, arg_expr)| possible_reuse_symbol(env, procs, &arg_expr.value)), + loc_args.iter().map(|(var, arg_expr)| { + possible_reuse_symbol_or_spec(env, procs, layout_cache, &arg_expr.value, *var) + }), arena, ) .into_bump_slice(); From 1b90f45c9dc6c9c6e38e0bc3fc447b21b7454772 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 3 May 2022 18:33:32 -0400 Subject: [PATCH 802/846] Sorry copy tests --- compiler/mono/src/copy.rs | 57 ++------------------------------------- 1 file changed, 2 insertions(+), 55 deletions(-) diff --git a/compiler/mono/src/copy.rs b/compiler/mono/src/copy.rs index 229e3043a0..ce27c195b3 100644 --- a/compiler/mono/src/copy.rs +++ b/compiler/mono/src/copy.rs @@ -637,14 +637,9 @@ fn deep_copy_type_vars<'a>( mod test { use super::deep_copy_type_vars; use bumpalo::Bump; - use roc_module::ident::TagName; use roc_module::symbol::Symbol; - use roc_types::{ - subs::{ - Content, Content::*, Descriptor, FlatType::*, Mark, OptVariable, Rank, RecordFields, - Subs, SubsIndex, UnionTags, Variable, - }, - types::RecordField, + use roc_types::subs::{ + Content, Content::*, Descriptor, Mark, OptVariable, Rank, Subs, SubsIndex, Variable, }; #[cfg(test)] @@ -748,52 +743,4 @@ mod test { it => assert!(false, "{:?}", it), } } - - #[test] - fn copy_type_with_copied_reference() { - let mut subs = Subs::new(); - let arena = Bump::new(); - - let flex_var = new_var(&mut subs, FlexVar(None)); - - let content = Structure(TagUnion( - UnionTags::insert_into_subs(&mut subs, [(TagName::Tag("A".into()), [flex_var])]), - Variable::EMPTY_TAG_UNION, - )); - - let tag_var = new_var(&mut subs, content); - - let mut copies = deep_copy_type_vars(&arena, &mut subs, tag_var); - - assert_eq!(copies.len(), 2); - let (original_flex, new_flex) = copies[0]; - assert_ne!(original_flex, new_flex); - assert_eq!(original_flex, flex_var); - - let (original_tag, new_tag) = copies[1]; - assert_ne!(original_tag, new_tag); - assert_eq!(original_tag, tag_var); - - match subs.get_content_without_compacting(new_tag) { - Structure(TagUnion(union_tags, Variable::EMPTY_TAG_UNION)) => { - let (tag_name, vars) = union_tags.iter_all().next().unwrap(); - match &subs[tag_name] { - TagName::Tag(upper) => assert_eq!(upper.as_str(), "A"), - _ => assert!(false, "{:?}", tag_name), - } - - let vars = subs[vars]; - assert_eq!(vars.len(), 1); - - let var = subs[vars.into_iter().next().unwrap()]; - assert_eq!(var, new_flex); - } - it => assert!(false, "{:?}", it), - } - - assert!(matches!( - subs.get_content_without_compacting(new_flex), - FlexVar(None) - )); - } } From b41995c2137b5b10a6a76093ca760b66cfeb8f09 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 3 May 2022 18:34:50 -0400 Subject: [PATCH 803/846] Ignore failing polymorphic closure test --- compiler/test_mono/src/tests.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/test_mono/src/tests.rs b/compiler/test_mono/src/tests.rs index 69eb86b8c0..bcbaa4812f 100644 --- a/compiler/test_mono/src/tests.rs +++ b/compiler/test_mono/src/tests.rs @@ -1228,6 +1228,7 @@ fn monomorphized_applied_tag() { } #[mono_test] +#[ignore = "Cannot compile polymorphic closures yet"] fn aliased_polymorphic_closure() { indoc!( r#" From 55d924ca8b312aa8de1f7f3b3e3da687ab6bf044 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 3 May 2022 18:35:50 -0400 Subject: [PATCH 804/846] Get rid of dbgs --- compiler/mono/src/ir.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 07636a2e2d..f965514fea 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -6451,7 +6451,7 @@ fn store_tag_pattern<'a>( stmt = new; // only if we bind one of its (sub)fields to a used name should we // extract the field - stmt = Stmt::Let(dbg!(symbol), load, arg_layout, env.arena.alloc(stmt)); + stmt = Stmt::Let(symbol, load, arg_layout, env.arena.alloc(stmt)); } StorePattern::NotProductive(new) => { // do nothing @@ -6504,7 +6504,7 @@ fn store_newtype_pattern<'a>( match argument { Identifier(symbol) => { // store immediately in the given symbol - stmt = Stmt::Let(dbg!(*symbol), load, arg_layout, env.arena.alloc(stmt)); + stmt = Stmt::Let(*symbol, load, arg_layout, env.arena.alloc(stmt)); is_productive = true; } Underscore => { @@ -6527,7 +6527,7 @@ fn store_newtype_pattern<'a>( stmt = new; // only if we bind one of its (sub)fields to a used name should we // extract the field - stmt = Stmt::Let(dbg!(symbol), load, arg_layout, env.arena.alloc(stmt)); + stmt = Stmt::Let(symbol, load, arg_layout, env.arena.alloc(stmt)); } StorePattern::NotProductive(new) => { // do nothing From 5624c492da0d2dd6760caf0205a79bb6473aac41 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 3 May 2022 19:07:08 -0400 Subject: [PATCH 805/846] Almost there... only breakout is bad now --- compiler/module/src/symbol.rs | 2 +- compiler/mono/src/ir.rs | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index e5822a8f89..c51341b8d0 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -17,7 +17,7 @@ pub struct Symbol(u64); // Set it to false if you want to see the raw ModuleId and IdentId ints, // but please set it back to true before checking in the result! #[cfg(debug_assertions)] -const PRETTY_PRINT_DEBUG_SYMBOLS: bool = true; +const PRETTY_PRINT_DEBUG_SYMBOLS: bool = false; /// In Debug builds only, Symbol has a name() method that lets /// you look up its name in a global intern table. This table is diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index f965514fea..c317fbe12d 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -6425,10 +6425,18 @@ fn store_tag_pattern<'a>( union_layout, }; + // dbg!(&argument, &load); + match argument { Identifier(symbol) => { + let symbol = procs + .needed_symbol_specializations + .get(&(*symbol, arg_layout)) + .map(|(_, sym)| *sym) + .unwrap_or(*symbol); + // store immediately in the given symbol - stmt = Stmt::Let(*symbol, load, arg_layout, env.arena.alloc(stmt)); + stmt = Stmt::Let(symbol, load, arg_layout, env.arena.alloc(stmt)); is_productive = true; } Underscore => { @@ -6670,6 +6678,22 @@ fn possible_reuse_symbol_or_spec<'a>( ) -> Symbol { match can_reuse_symbol(env, procs, expr) { ReuseSymbol::Value(symbol) => { + // TODO: for some reason, we can't attempt to specialize the built-in argument symbols. + // Figure out why. + let arguments = [ + Symbol::ARG_1, + Symbol::ARG_2, + Symbol::ARG_3, + Symbol::ARG_4, + Symbol::ARG_5, + Symbol::ARG_6, + Symbol::ARG_7, + ]; + + if arguments.contains(&symbol) { + return symbol; + } + let wanted_layout = match layout_cache.from_var(env.arena, var, env.subs) { Ok(layout) => layout, // This can happen when the def symbol has a type error. In such cases just use the @@ -6702,6 +6726,7 @@ fn possible_reuse_symbol_or_spec<'a>( ) }); + // dbg!(symbol, *specialized_symbol); *specialized_symbol } _ => env.unique_symbol(), From b05874924f519e85634e2c113a15edb7d600b59c Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 3 May 2022 19:38:25 -0400 Subject: [PATCH 806/846] Clippy --- compiler/module/src/symbol.rs | 2 +- compiler/mono/src/copy.rs | 22 +++++++--------------- compiler/mono/src/ir.rs | 9 +++++---- compiler/solve/src/solve.rs | 4 ++++ 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index c51341b8d0..e5822a8f89 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -17,7 +17,7 @@ pub struct Symbol(u64); // Set it to false if you want to see the raw ModuleId and IdentId ints, // but please set it back to true before checking in the result! #[cfg(debug_assertions)] -const PRETTY_PRINT_DEBUG_SYMBOLS: bool = false; +const PRETTY_PRINT_DEBUG_SYMBOLS: bool = true; /// In Debug builds only, Symbol has a name() method that lets /// you look up its name in a global intern table. This table is diff --git a/compiler/mono/src/copy.rs b/compiler/mono/src/copy.rs index ce27c195b3..0520429892 100644 --- a/compiler/mono/src/copy.rs +++ b/compiler/mono/src/copy.rs @@ -51,20 +51,12 @@ pub fn deep_copy_type_vars_into_expr<'a>( match expr { Num(var, str, val, bound) => Num(sub!(*var), str.clone(), val.clone(), *bound), - Int(v1, v2, str, val, bound) => Int( - sub!(*v1), - sub!(*v2), - str.clone(), - val.clone(), - bound.clone(), - ), - Float(v1, v2, str, val, bound) => Float( - sub!(*v1), - sub!(*v2), - str.clone(), - val.clone(), - bound.clone(), - ), + Int(v1, v2, str, val, bound) => { + Int(sub!(*v1), sub!(*v2), str.clone(), val.clone(), *bound) + } + Float(v1, v2, str, val, bound) => { + Float(sub!(*v1), sub!(*v2), str.clone(), *val, *bound) + } Str(str) => Str(str.clone()), SingleQuote(char) => SingleQuote(*char), List { @@ -491,7 +483,7 @@ fn deep_copy_type_vars<'a>( // Everything else is a mechanical descent. Structure(flat_type) => match flat_type { - EmptyRecord | EmptyTagUnion | Erroneous(_) => Structure(flat_type.clone()), + EmptyRecord | EmptyTagUnion | Erroneous(_) => Structure(flat_type), Apply(symbol, arguments) => { descend_slice!(arguments); diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index c317fbe12d..76d2534e12 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -3193,6 +3193,7 @@ pub fn with_hole<'a>( } LetNonRec(def, cont, _) => { if let roc_can::pattern::Pattern::Identifier(symbol) = def.loc_pattern.value { + dbg!(symbol); if let Closure(closure_data) = def.loc_expr.value { register_noncapturing_closure(env, procs, symbol, closure_data); @@ -3338,6 +3339,7 @@ pub fn with_hole<'a>( ) } Var(symbol) => { + dbg!(symbol); specialize_naked_symbol(env, variable, procs, layout_cache, assigned, hole, symbol) } Tag { @@ -5438,6 +5440,7 @@ pub fn from_can<'a>( } LetNonRec(def, cont, outer_annotation) => { if let roc_can::pattern::Pattern::Identifier(symbol) = &def.loc_pattern.value { + dbg!(symbol); match def.loc_expr.value { roc_can::expr::Expr::Closure(closure_data) => { register_capturing_closure(env, procs, layout_cache, *symbol, closure_data); @@ -5572,8 +5575,7 @@ pub fn from_can<'a>( let needs_def_specializations = procs .needed_symbol_specializations .keys() - .find(|(s, _)| s == symbol) - .is_some(); + .any(|(s, _)| s == symbol); if !needs_def_specializations { return with_hole( @@ -6709,8 +6711,7 @@ fn possible_reuse_symbol_or_spec<'a>( let needs_fresh_symbol = procs .needed_symbol_specializations .keys() - .find(|(s, _)| *s == symbol) - .is_some(); + .any(|(s, _)| *s == symbol); let (_, specialized_symbol) = procs .needed_symbol_specializations diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index 82ee0cfafb..e40ab2f743 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -457,6 +457,10 @@ impl Pools { self.0.len() } + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + pub fn get_mut(&mut self, rank: Rank) -> &mut Vec { match self.0.get_mut(rank.into_usize()) { Some(reference) => reference, From 3c2dd488a5b027519a0fc62b4f8f8662cec77d9e Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 3 May 2022 19:41:55 -0400 Subject: [PATCH 807/846] One step forward, two steps back --- compiler/mono/src/ir.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 76d2534e12..6e6880fd92 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -3002,6 +3002,16 @@ fn specialize_naked_symbol<'a>( } } + use roc_can::expr::Expr; + if let ReuseSymbol::Value(_symbol) = can_reuse_symbol(env, procs, &Expr::Var(symbol)) { + let real_symbol = + possible_reuse_symbol_or_spec(env, procs, layout_cache, &Expr::Var(symbol), variable); + return match hole { + Stmt::Jump(id, _) => Stmt::Jump(*id, env.arena.alloc([real_symbol])), + _ => Stmt::Ret(real_symbol), + }; + } + let result = match hole { Stmt::Jump(id, _) => Stmt::Jump(*id, env.arena.alloc([symbol])), _ => Stmt::Ret(symbol), @@ -3193,7 +3203,6 @@ pub fn with_hole<'a>( } LetNonRec(def, cont, _) => { if let roc_can::pattern::Pattern::Identifier(symbol) = def.loc_pattern.value { - dbg!(symbol); if let Closure(closure_data) = def.loc_expr.value { register_noncapturing_closure(env, procs, symbol, closure_data); @@ -3339,7 +3348,6 @@ pub fn with_hole<'a>( ) } Var(symbol) => { - dbg!(symbol); specialize_naked_symbol(env, variable, procs, layout_cache, assigned, hole, symbol) } Tag { @@ -3475,6 +3483,13 @@ pub fn with_hole<'a>( can_fields.push(Field::Function(symbol, variable)); } Value(reusable) => { + let reusable = possible_reuse_symbol_or_spec( + env, + procs, + layout_cache, + &roc_can::expr::Expr::Var(reusable), + field.var, + ); field_symbols.push(reusable); can_fields.push(Field::ValueSymbol); } @@ -5440,7 +5455,6 @@ pub fn from_can<'a>( } LetNonRec(def, cont, outer_annotation) => { if let roc_can::pattern::Pattern::Identifier(symbol) = &def.loc_pattern.value { - dbg!(symbol); match def.loc_expr.value { roc_can::expr::Expr::Closure(closure_data) => { register_capturing_closure(env, procs, layout_cache, *symbol, closure_data); From bc987fd4d7770ceed9af20399d19c27b7933b502 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 4 May 2022 09:13:42 -0400 Subject: [PATCH 808/846] All of test_gen works again --- .cargo/config | 13 +++++++++ compiler/mono/src/ir.rs | 59 ++++++++++++++++++++++++++++++++--------- 2 files changed, 59 insertions(+), 13 deletions(-) diff --git a/.cargo/config b/.cargo/config index 584d158f1c..44fccd9a7e 100644 --- a/.cargo/config +++ b/.cargo/config @@ -8,3 +8,16 @@ test-gen-wasm = "test -p roc_gen_wasm -p test_gen --no-default-features --featur # opt-level=s Optimizations should focus more on size than speed # lto=fat Spend extra effort on link-time optimization across crates rustflags = ["-Copt-level=s", "-Clto=fat"] + +[env] +# Debug flags. Keep this up-to-date with compiler/debug_flags/src/lib.rs. +# Set = "1" to turn a debug flag on. +ROC_PRETTY_PRINT_ALIAS_CONTENTS = "0" +ROC_PRINT_UNIFICATIONS = "0" +ROC_PRINT_MISMATCHES = "0" +ROC_PRINT_IR_AFTER_SPECIALIZATION = "0" +ROC_PRINT_IR_AFTER_RESET_REUSE = "0" +ROC_PRINT_IR_AFTER_REFCOUNT = "0" +ROC_DEBUG_ALIAS_ANALYSIS = "0" +ROC_PRINT_LLVM_FN_VERIFICATION = "0" +ROC_PRINT_LOAD_LOG = "0" diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 6e6880fd92..e3d78a2229 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -2465,6 +2465,17 @@ fn specialize_external<'a>( (Some(closure_layout), CapturedSymbols::Captured(captured)) => { // debug_assert!(!captured.is_empty()); + // An argument from the closure list may have taken on a specialized symbol + // name during the evaluation of the def body. If this is the case, load the + // specialized name rather than the original captured name! + // let get_specialized_name = |symbol, layout| { + // procs + // .needed_symbol_specializations + // .get(&(symbol, layout)) + // .map(|(_, specialized)| *specialized) + // .unwrap_or(symbol) + // }; + match closure_layout.layout_for_member(proc_name) { ClosureRepresentation::Union { alphabetic_order_fields: field_layouts, @@ -2499,6 +2510,8 @@ fn specialize_external<'a>( union_layout, }; + // let symbol = get_specialized_name(**symbol, **layout); + specialized_body = Stmt::Let( **symbol, expr, @@ -2540,6 +2553,8 @@ fn specialize_external<'a>( structure: Symbol::ARG_CLOSURE, }; + // let symbol = get_specialized_name(**symbol, **layout); + specialized_body = Stmt::Let( **symbol, expr, @@ -2585,8 +2600,9 @@ fn specialize_external<'a>( .map(|&(layout, symbol)| { let symbol = procs .needed_symbol_specializations - .get(&(symbol, layout)) - .map(|(_, specialized_symbol)| *specialized_symbol) + // We can remove the specialization since this is the definition site. + .remove(&(symbol, layout)) + .map(|(_, specialized_symbol)| specialized_symbol) .unwrap_or(symbol); (layout, symbol) @@ -3002,19 +3018,25 @@ fn specialize_naked_symbol<'a>( } } - use roc_can::expr::Expr; - if let ReuseSymbol::Value(_symbol) = can_reuse_symbol(env, procs, &Expr::Var(symbol)) { - let real_symbol = - possible_reuse_symbol_or_spec(env, procs, layout_cache, &Expr::Var(symbol), variable); - return match hole { - Stmt::Jump(id, _) => Stmt::Jump(*id, env.arena.alloc([real_symbol])), - _ => Stmt::Ret(real_symbol), - }; - } - + let mut symbol = symbol; let result = match hole { Stmt::Jump(id, _) => Stmt::Jump(*id, env.arena.alloc([symbol])), - _ => Stmt::Ret(symbol), + _ => { + use roc_can::expr::Expr; + if let ReuseSymbol::Value(_symbol) = can_reuse_symbol(env, procs, &Expr::Var(symbol)) { + let real_symbol = possible_reuse_symbol_or_spec( + env, + procs, + layout_cache, + &Expr::Var(symbol), + variable, + ); + symbol = real_symbol; + Stmt::Ret(real_symbol) + } else { + Stmt::Ret(symbol) + } + } }; // if the symbol is a function symbol, ensure it is properly specialized! @@ -4717,6 +4739,7 @@ fn get_specialization<'a>( #[allow(clippy::too_many_arguments)] fn construct_closure_data<'a, I>( env: &mut Env<'a, '_>, + // procs: &mut Procs<'a>, lambda_set: LambdaSet<'a>, name: Symbol, symbols: I, @@ -4730,6 +4753,16 @@ where let lambda_set_layout = Layout::LambdaSet(lambda_set); let symbols = symbols.into_iter(); + // It may be the case that while capturing a symbol, we actually want to capture it under a + // different name than what the + // let get_specialized_name = |symbol, layout| { + // procs + // .needed_symbol_specializations + // .get(&(symbol, layout)) + // .map(|(_, specialized)| *specialized) + // .unwrap_or(symbol) + // }; + let result = match lambda_set.layout_for_member(name) { ClosureRepresentation::Union { tag_id, From 087782f3d042eaa83f57945247ca69070b294c70 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 4 May 2022 09:15:20 -0400 Subject: [PATCH 809/846] Closure captures may take on specialized names --- compiler/mono/src/ir.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index e3d78a2229..8e3bc37ba5 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -2468,13 +2468,13 @@ fn specialize_external<'a>( // An argument from the closure list may have taken on a specialized symbol // name during the evaluation of the def body. If this is the case, load the // specialized name rather than the original captured name! - // let get_specialized_name = |symbol, layout| { - // procs - // .needed_symbol_specializations - // .get(&(symbol, layout)) - // .map(|(_, specialized)| *specialized) - // .unwrap_or(symbol) - // }; + let get_specialized_name = |symbol, layout| { + procs + .needed_symbol_specializations + .get(&(symbol, layout)) + .map(|(_, specialized)| *specialized) + .unwrap_or(symbol) + }; match closure_layout.layout_for_member(proc_name) { ClosureRepresentation::Union { @@ -2510,10 +2510,10 @@ fn specialize_external<'a>( union_layout, }; - // let symbol = get_specialized_name(**symbol, **layout); + let symbol = get_specialized_name(**symbol, **layout); specialized_body = Stmt::Let( - **symbol, + symbol, expr, **layout, env.arena.alloc(specialized_body), @@ -2553,10 +2553,10 @@ fn specialize_external<'a>( structure: Symbol::ARG_CLOSURE, }; - // let symbol = get_specialized_name(**symbol, **layout); + let symbol = get_specialized_name(**symbol, **layout); specialized_body = Stmt::Let( - **symbol, + symbol, expr, **layout, env.arena.alloc(specialized_body), From 5cef7136db85ddcc4ee9e800969b85bf8eeb0224 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 4 May 2022 10:55:37 -0400 Subject: [PATCH 810/846] Correctly ignore ignored mono tests --- compiler/test_mono_macros/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compiler/test_mono_macros/src/lib.rs b/compiler/test_mono_macros/src/lib.rs index e6646e4e36..00f023125a 100644 --- a/compiler/test_mono_macros/src/lib.rs +++ b/compiler/test_mono_macros/src/lib.rs @@ -14,9 +14,11 @@ pub fn mono_test(_args: TokenStream, item: TokenStream) -> TokenStream { let body = task_fn.block.clone(); let visibility = &task_fn.vis; + let attributes = task_fn.attrs; let result = quote! { #[test] + #(#attributes)* #visibility fn #name(#args) -> () { compiles_to_ir(#name_str, #body); From 767d76ce02d742a01f9983346b5b71e26e2fa847 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 4 May 2022 12:46:10 -0400 Subject: [PATCH 811/846] Turn off flapping test --- compiler/test_gen/src/gen_num.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/test_gen/src/gen_num.rs b/compiler/test_gen/src/gen_num.rs index eaabeb8f20..e24240b7b2 100644 --- a/compiler/test_gen/src/gen_num.rs +++ b/compiler/test_gen/src/gen_num.rs @@ -3212,6 +3212,7 @@ fn upcast_of_int_is_zext() { #[test] #[cfg(any(feature = "gen-llvm"))] +#[ignore = "https://github.com/rtfeldman/roc/issues/2997"] // https://github.com/rtfeldman/roc/issues/2696 fn upcast_of_int_checked_is_zext() { assert_evals_to!( From 2b82de1e3f725140c7630e31516ca4b41e381aa7 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 4 May 2022 13:50:35 -0400 Subject: [PATCH 812/846] Fix refcount tests --- compiler/test_gen/src/gen_refcount.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/compiler/test_gen/src/gen_refcount.rs b/compiler/test_gen/src/gen_refcount.rs index 25ade5e934..631c0635ce 100644 --- a/compiler/test_gen/src/gen_refcount.rs +++ b/compiler/test_gen/src/gen_refcount.rs @@ -59,10 +59,7 @@ fn list_int_inc() { ), RocList>, &[ - // TODO be smarter about coalescing polymorphic list values - Live(1), // list0 - Live(1), // list1 - Live(1), // list2 + Live(3), // list Live(1) // result ] ); @@ -80,10 +77,7 @@ fn list_int_dealloc() { ), usize, &[ - // TODO be smarter about coalescing polymorphic list values - Deallocated, // list0 - Deallocated, // list1 - Deallocated, // list2 + Deallocated, // list Deallocated // result ] ); From c79298ea8ea9b70ec06167cef869cbcdd025c9b6 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 5 May 2022 08:49:56 -0400 Subject: [PATCH 813/846] Fix test_gen diffs --- compiler/test_gen/src/gen_num.rs | 11 ++++++----- compiler/test_gen/src/helpers/llvm.rs | 3 --- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/compiler/test_gen/src/gen_num.rs b/compiler/test_gen/src/gen_num.rs index e24240b7b2..0240bb95d5 100644 --- a/compiler/test_gen/src/gen_num.rs +++ b/compiler/test_gen/src/gen_num.rs @@ -612,13 +612,15 @@ fn i64_abs() { #[test] #[cfg(any(feature = "gen-llvm"))] -#[should_panic = "integer absolute overflowed because its argument is the minimum value"] +#[should_panic( + expected = r#"Roc failed with message: "integer absolute overflowed because its argument is the minimum value"# +)] fn abs_min_int_overflow() { assert_evals_to!( indoc!( r#" - Num.abs Num.minI64 - "# + Num.abs Num.minI64 + "# ), 0, i64 @@ -3070,7 +3072,7 @@ fn sub_saturated() { #[test] #[cfg(any(feature = "gen-llvm"))] -fn monomorphized_ints1() { +fn monomorphized_ints() { assert_evals_to!( indoc!( r#" @@ -3212,7 +3214,6 @@ fn upcast_of_int_is_zext() { #[test] #[cfg(any(feature = "gen-llvm"))] -#[ignore = "https://github.com/rtfeldman/roc/issues/2997"] // https://github.com/rtfeldman/roc/issues/2696 fn upcast_of_int_checked_is_zext() { assert_evals_to!( diff --git a/compiler/test_gen/src/helpers/llvm.rs b/compiler/test_gen/src/helpers/llvm.rs index 37d6e48477..aeba51ad8c 100644 --- a/compiler/test_gen/src/helpers/llvm.rs +++ b/compiler/test_gen/src/helpers/llvm.rs @@ -240,9 +240,6 @@ fn create_llvm_module<'a>( // Uncomment this to see the module's optimized LLVM instruction output: // env.module.print_to_stderr(); - env.module - .print_to_file(&std::path::PathBuf::from("/tmp/out.ll")) - .unwrap(); (main_fn_name, delayed_errors.join("\n"), env.module) } From bf91e151e8b85b96991d26209ddf96e91bd5d746 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 5 May 2022 08:58:59 -0400 Subject: [PATCH 814/846] Lift reuse_symbol_or_specialize --- compiler/mono/src/ir.rs | 171 +++++++++++++++++++++------------------- 1 file changed, 90 insertions(+), 81 deletions(-) diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 8e3bc37ba5..ecfe8053d6 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -3024,7 +3024,7 @@ fn specialize_naked_symbol<'a>( _ => { use roc_can::expr::Expr; if let ReuseSymbol::Value(_symbol) = can_reuse_symbol(env, procs, &Expr::Var(symbol)) { - let real_symbol = possible_reuse_symbol_or_spec( + let real_symbol = possible_reuse_symbol_or_specialize( env, procs, layout_cache, @@ -3442,17 +3442,11 @@ pub fn with_hole<'a>( OpaqueRef { argument, .. } => { let (arg_var, loc_arg_expr) = *argument; - // TODO(POLYEXPR): can this just be `possible_reuse_symbol_or_spec`? match can_reuse_symbol(env, procs, &loc_arg_expr.value) { // Opaques decay to their argument. - ReuseSymbol::Value(_real_name) => { - let real_name = possible_reuse_symbol_or_spec( - env, - procs, - layout_cache, - &loc_arg_expr.value, - arg_var, - ); + ReuseSymbol::Value(symbol) => { + let real_name = + reuse_symbol_or_specialize(env, procs, layout_cache, symbol, arg_var); let mut result = hole.clone(); substitute_in_exprs(arena, &mut result, assigned, real_name); result @@ -3504,12 +3498,12 @@ pub fn with_hole<'a>( field_symbols.push(symbol); can_fields.push(Field::Function(symbol, variable)); } - Value(reusable) => { - let reusable = possible_reuse_symbol_or_spec( + Value(symbol) => { + let reusable = reuse_symbol_or_specialize( env, procs, layout_cache, - &roc_can::expr::Expr::Var(reusable), + symbol, field.var, ); field_symbols.push(reusable); @@ -3654,7 +3648,7 @@ pub fn with_hole<'a>( ); for (loc_cond, loc_then) in branches.into_iter().rev() { - let branching_symbol = possible_reuse_symbol_or_spec( + let branching_symbol = possible_reuse_symbol_or_specialize( env, procs, layout_cache, @@ -3720,8 +3714,13 @@ pub fn with_hole<'a>( branches_cond_var: _, exhaustive, } => { - let cond_symbol = - possible_reuse_symbol_or_spec(env, procs, layout_cache, &loc_cond.value, cond_var); + let cond_symbol = possible_reuse_symbol_or_specialize( + env, + procs, + layout_cache, + &loc_cond.value, + cond_var, + ); let id = JoinPointId(env.unique_symbol()); @@ -3810,7 +3809,7 @@ pub fn with_hole<'a>( if let Some(literal) = try_make_literal(env, &arg_expr.value) { elements.push(ListLiteralElement::Literal(literal)); } else { - let symbol = possible_reuse_symbol_or_spec( + let symbol = possible_reuse_symbol_or_specialize( env, procs, layout_cache, @@ -3889,7 +3888,7 @@ pub fn with_hole<'a>( } } - let record_symbol = possible_reuse_symbol_or_spec( + let record_symbol = possible_reuse_symbol_or_specialize( env, procs, layout_cache, @@ -4020,7 +4019,7 @@ pub fn with_hole<'a>( field_layouts.push(field_layout); if let Some(field) = updates.get(&label) { - let field_symbol = possible_reuse_symbol_or_spec( + let field_symbol = possible_reuse_symbol_or_specialize( env, procs, layout_cache, @@ -4251,7 +4250,7 @@ pub fn with_hole<'a>( let arg_symbols = Vec::from_iter_in( loc_args.iter().map(|(var, arg_expr)| { - possible_reuse_symbol_or_spec( + possible_reuse_symbol_or_specialize( env, procs, layout_cache, @@ -4409,7 +4408,7 @@ pub fn with_hole<'a>( let mut arg_symbols = Vec::with_capacity_in(args.len(), env.arena); for (var, arg_expr) in args.iter() { - arg_symbols.push(possible_reuse_symbol_or_spec( + arg_symbols.push(possible_reuse_symbol_or_specialize( env, procs, layout_cache, @@ -4445,7 +4444,7 @@ pub fn with_hole<'a>( let mut arg_symbols = Vec::with_capacity_in(args.len(), env.arena); for (var, arg_expr) in args.iter() { - arg_symbols.push(possible_reuse_symbol_or_spec( + arg_symbols.push(possible_reuse_symbol_or_specialize( env, procs, layout_cache, @@ -5205,7 +5204,7 @@ fn sorted_field_symbols<'a>( let alignment = layout.alignment_bytes(env.target_info); - let symbol = possible_reuse_symbol_or_spec(env, procs, layout_cache, &arg.value, var); + let symbol = possible_reuse_symbol_or_specialize(env, procs, layout_cache, &arg.value, var); field_symbols_temp.push((alignment, symbol, ((var, arg), &*env.arena.alloc(symbol)))); } field_symbols_temp.sort_by(|a, b| b.0.cmp(&a.0)); @@ -5358,8 +5357,13 @@ pub fn from_can<'a>( branches_cond_var: _, exhaustive, } => { - let cond_symbol = - possible_reuse_symbol_or_spec(env, procs, layout_cache, &loc_cond.value, cond_var); + let cond_symbol = possible_reuse_symbol_or_specialize( + env, + procs, + layout_cache, + &loc_cond.value, + cond_var, + ); let stmt = from_can_when( env, @@ -5400,7 +5404,7 @@ pub fn from_can<'a>( let mut stmt = from_can(env, branch_var, final_else.value, procs, layout_cache); for (loc_cond, loc_then) in branches.into_iter().rev() { - let branching_symbol = possible_reuse_symbol_or_spec( + let branching_symbol = possible_reuse_symbol_or_specialize( env, procs, layout_cache, @@ -6474,8 +6478,6 @@ fn store_tag_pattern<'a>( union_layout, }; - // dbg!(&argument, &load); - match argument { Identifier(symbol) => { let symbol = procs @@ -6718,7 +6720,62 @@ fn can_reuse_symbol<'a>( } } -fn possible_reuse_symbol_or_spec<'a>( +/// Reuses the specialized symbol for a given symbol and instance type. If no specialization symbol +/// yet exists, one is created. +fn reuse_symbol_or_specialize<'a>( + env: &mut Env<'a, '_>, + procs: &mut Procs<'a>, + layout_cache: &mut LayoutCache<'a>, + symbol: Symbol, + var: Variable, +) -> Symbol { + // TODO: for some reason, we can't attempt to specialize the built-in argument symbols. + // Figure out why. + let arguments = [ + Symbol::ARG_1, + Symbol::ARG_2, + Symbol::ARG_3, + Symbol::ARG_4, + Symbol::ARG_5, + Symbol::ARG_6, + Symbol::ARG_7, + ]; + + if arguments.contains(&symbol) { + return symbol; + } + + let wanted_layout = match layout_cache.from_var(env.arena, var, env.subs) { + Ok(layout) => layout, + // This can happen when the def symbol has a type error. In such cases just use the + // def symbol, which is erroring. + Err(_) => return symbol, + }; + + // For the first specialization, always reuse the current symbol. The vast majority of defs + // only have one instance type, so this preserves readability of the IR. + let needs_fresh_symbol = procs + .needed_symbol_specializations + .keys() + .any(|(s, _)| *s == symbol); + + let mut make_specialized_symbol = || { + if needs_fresh_symbol { + env.unique_symbol() + } else { + symbol + } + }; + + let (_, specialized_symbol) = procs + .needed_symbol_specializations + .entry((symbol, wanted_layout)) + .or_insert_with(|| (var, make_specialized_symbol())); + + *specialized_symbol +} + +fn possible_reuse_symbol_or_specialize<'a>( env: &mut Env<'a, '_>, procs: &mut Procs<'a>, layout_cache: &mut LayoutCache<'a>, @@ -6727,55 +6784,7 @@ fn possible_reuse_symbol_or_spec<'a>( ) -> Symbol { match can_reuse_symbol(env, procs, expr) { ReuseSymbol::Value(symbol) => { - // TODO: for some reason, we can't attempt to specialize the built-in argument symbols. - // Figure out why. - let arguments = [ - Symbol::ARG_1, - Symbol::ARG_2, - Symbol::ARG_3, - Symbol::ARG_4, - Symbol::ARG_5, - Symbol::ARG_6, - Symbol::ARG_7, - ]; - - if arguments.contains(&symbol) { - return symbol; - } - - let wanted_layout = match layout_cache.from_var(env.arena, var, env.subs) { - Ok(layout) => layout, - // This can happen when the def symbol has a type error. In such cases just use the - // def symbol, which is erroring. - Err(_) => return symbol, - }; - - // For the first specialization, always reuse the current symbol. Two reasons for this: - // 1. More readable - // 2. Will still have bugs where we're not always specializing the original symbol - // will all specialization symbols. In such cases, just re-use the original for - // now. - let needs_fresh_symbol = procs - .needed_symbol_specializations - .keys() - .any(|(s, _)| *s == symbol); - - let (_, specialized_symbol) = procs - .needed_symbol_specializations - .entry((symbol, wanted_layout)) - .or_insert_with(|| { - ( - var, - if needs_fresh_symbol { - env.unique_symbol() - } else { - symbol - }, - ) - }); - - // dbg!(symbol, *specialized_symbol); - *specialized_symbol + reuse_symbol_or_specialize(env, procs, layout_cache, symbol, var) } _ => env.unique_symbol(), } @@ -7164,7 +7173,7 @@ fn evaluate_arguments_then_runtime_error<'a>( // but, we also still evaluate and specialize the arguments to give better error messages let arg_symbols = Vec::from_iter_in( loc_args.iter().map(|(var, arg_expr)| { - possible_reuse_symbol_or_spec(env, procs, layout_cache, &arg_expr.value, *var) + possible_reuse_symbol_or_specialize(env, procs, layout_cache, &arg_expr.value, *var) }), arena, ) @@ -7231,7 +7240,7 @@ fn call_by_name<'a>( let arena = env.arena; let arg_symbols = Vec::from_iter_in( loc_args.iter().map(|(arg_var, arg_expr)| { - possible_reuse_symbol_or_spec( + possible_reuse_symbol_or_specialize( env, procs, layout_cache, @@ -7329,7 +7338,7 @@ fn call_by_name_help<'a>( // the arguments given to the function, stored in symbols let mut field_symbols = Vec::with_capacity_in(loc_args.len(), arena); field_symbols.extend(loc_args.iter().map(|(arg_var, arg_expr)| { - possible_reuse_symbol_or_spec(env, procs, layout_cache, &arg_expr.value, *arg_var) + possible_reuse_symbol_or_specialize(env, procs, layout_cache, &arg_expr.value, *arg_var) })); // If required, add an extra argument to the layout that is the captured environment From 143b0f61a87e57c7ca6e6f531f17bfd64fcc5210 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 5 May 2022 09:27:47 -0400 Subject: [PATCH 815/846] Add a couple tests --- compiler/test_gen/src/gen_primitives.rs | 39 +++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/compiler/test_gen/src/gen_primitives.rs b/compiler/test_gen/src/gen_primitives.rs index c48c91d0a2..509bd3e886 100644 --- a/compiler/test_gen/src/gen_primitives.rs +++ b/compiler/test_gen/src/gen_primitives.rs @@ -3397,3 +3397,42 @@ fn issue_2894() { u32 ) } + +#[test] +#[cfg(any(feature = "gen-llvm"))] +fn polymorphic_def_used_in_closure() { + assert_evals_to!( + indoc!( + r#" + a : I64 -> _ + a = \g -> + f = { r: g, h: 32 } + + h1 : U64 + h1 = (\{} -> f.h) {} + h1 + a 1 + "# + ), + 32, + u64 + ) +} + +#[test] +#[cfg(any(feature = "gen-llvm"))] +#[ignore = "This still doesn't work... yet"] +fn polymorphic_lambda_set_usage() { + assert_evals_to!( + indoc!( + r#" + id1 = \x -> x + id2 = \y -> y + id = if True then id1 else id2 + id 9u8 + "# + ), + 9, + u8 + ) +} From de924de266708813a43bc69182353c522dff9fd6 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 5 May 2022 11:12:42 -0400 Subject: [PATCH 816/846] Fix test name typo --- compiler/test_gen/src/gen_list.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/test_gen/src/gen_list.rs b/compiler/test_gen/src/gen_list.rs index 5bd5e36919..c492936129 100644 --- a/compiler/test_gen/src/gen_list.rs +++ b/compiler/test_gen/src/gen_list.rs @@ -800,7 +800,7 @@ fn list_walk_until_sum() { #[test] #[cfg(any(feature = "gen-llvm"))] -fn list_walk_imlements_position() { +fn list_walk_implements_position() { assert_evals_to!( r#" Option a : [ Some a, None ] From 19e8b37402aadfcce22c182dc110d4c5b8234493 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 5 May 2022 11:12:50 -0400 Subject: [PATCH 817/846] Bugfix handle more specialization instances --- compiler/mono/src/ir.rs | 209 +++++++++++++++++++++++++++++++--------- 1 file changed, 163 insertions(+), 46 deletions(-) diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index ecfe8053d6..ffca4f94d6 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -770,6 +770,26 @@ impl<'a> Procs<'a> { needed_symbol_specializations: BumpMap::new_in(arena), } } + + /// Expects and removes a single specialization symbol for the given requested symbol. + fn remove_single_symbol_specialization(&mut self, symbol: Symbol) -> Option { + let mut specialized_symbols = self + .needed_symbol_specializations + .drain_filter(|(sym, _), _| sym == &symbol); + + let specialization_symbol = specialized_symbols + .next() + .map(|(_, (_, specialized_symbol))| specialized_symbol); + + debug_assert_eq!( + specialized_symbols.count(), + 0, + "Symbol {:?} has multiple specializations", + symbol + ); + + specialization_symbol + } } #[derive(Clone, Debug, PartialEq)] @@ -2468,11 +2488,11 @@ fn specialize_external<'a>( // An argument from the closure list may have taken on a specialized symbol // name during the evaluation of the def body. If this is the case, load the // specialized name rather than the original captured name! - let get_specialized_name = |symbol, layout| { + let mut get_specialized_name = |symbol, layout| { procs .needed_symbol_specializations - .get(&(symbol, layout)) - .map(|(_, specialized)| *specialized) + .remove(&(symbol, layout)) + .map(|(_, specialized)| specialized) .unwrap_or(symbol) }; @@ -3304,7 +3324,7 @@ pub fn with_hole<'a>( } else { // this may be a destructure pattern let (mono_pattern, assignments) = - match from_can_pattern(env, layout_cache, &def.loc_pattern.value) { + match from_can_pattern(env, procs, layout_cache, &def.loc_pattern.value) { Ok(v) => v, Err(_runtime_error) => { // todo @@ -5492,6 +5512,7 @@ pub fn from_can<'a>( } LetNonRec(def, cont, outer_annotation) => { if let roc_can::pattern::Pattern::Identifier(symbol) = &def.loc_pattern.value { + // dbg!(symbol, &def.loc_expr.value); match def.loc_expr.value { roc_can::expr::Expr::Closure(closure_data) => { register_capturing_closure(env, procs, layout_cache, *symbol, closure_data); @@ -5706,7 +5727,7 @@ pub fn from_can<'a>( // this may be a destructure pattern let (mono_pattern, assignments) = - match from_can_pattern(env, layout_cache, &def.loc_pattern.value) { + match from_can_pattern(env, procs, layout_cache, &def.loc_pattern.value) { Ok(v) => v, Err(_) => todo!(), }; @@ -5737,8 +5758,22 @@ pub fn from_can<'a>( // layer on any default record fields for (symbol, variable, expr) in assignments { + let specialization_symbol = procs + .remove_single_symbol_specialization(symbol) + // Can happen when the symbol was never used under this body, and hence has no + // requested specialization. + .unwrap_or(symbol); + let hole = env.arena.alloc(stmt); - stmt = with_hole(env, expr, variable, procs, layout_cache, symbol, hole); + stmt = with_hole( + env, + expr, + variable, + procs, + layout_cache, + specialization_symbol, + hole, + ); } if let roc_can::expr::Expr::Var(outer_symbol) = def.loc_expr.value { @@ -5772,6 +5807,7 @@ pub fn from_can<'a>( fn to_opt_branches<'a>( env: &mut Env<'a, '_>, + procs: &mut Procs<'a>, branches: std::vec::Vec, exhaustive_mark: ExhaustiveMark, layout_cache: &mut LayoutCache<'a>, @@ -5798,7 +5834,7 @@ fn to_opt_branches<'a>( } for loc_pattern in when_branch.patterns { - match from_can_pattern(env, layout_cache, &loc_pattern.value) { + match from_can_pattern(env, procs, layout_cache, &loc_pattern.value) { Ok((mono_pattern, assignments)) => { loc_branches.push(( Loc::at(loc_pattern.region, mono_pattern.clone()), @@ -5876,7 +5912,7 @@ fn from_can_when<'a>( // We can't know what to return! return Stmt::RuntimeError("Hit a 0-branch when expression"); } - let opt_branches = to_opt_branches(env, branches, exhaustive_mark, layout_cache); + let opt_branches = to_opt_branches(env, procs, branches, exhaustive_mark, layout_cache); let cond_layout = return_on_layout_error!(env, layout_cache.from_var(env.arena, cond_var, env.subs)); @@ -6341,7 +6377,15 @@ fn store_pattern_help<'a>( match can_pat { Identifier(symbol) => { - substitute_in_exprs(env.arena, &mut stmt, *symbol, outer_symbol); + // An identifier in a pattern can define at most one specialization! + // Remove any requested specializations for this name now, since this is the definition site. + let specialization_symbol = procs + .remove_single_symbol_specialization(*symbol) + // Can happen when the symbol was never used under this body, and hence has no + // requested specialization. + .unwrap_or(*symbol); + + substitute_in_exprs(env.arena, &mut stmt, specialization_symbol, outer_symbol); } Underscore => { // do nothing @@ -6402,7 +6446,18 @@ fn store_pattern_help<'a>( for destruct in destructs { match &destruct.typ { DestructType::Required(symbol) => { - substitute_in_exprs(env.arena, &mut stmt, *symbol, outer_symbol); + let specialization_symbol = procs + .remove_single_symbol_specialization(*symbol) + // Can happen when the symbol was never used under this body, and hence has no + // requested specialization. + .unwrap_or(*symbol); + + substitute_in_exprs( + env.arena, + &mut stmt, + specialization_symbol, + outer_symbol, + ); } DestructType::Guard(guard_pattern) => { return store_pattern_help( @@ -6480,10 +6535,11 @@ fn store_tag_pattern<'a>( match argument { Identifier(symbol) => { + // TODO: use procs.remove_single_symbol_specialization let symbol = procs .needed_symbol_specializations - .get(&(*symbol, arg_layout)) - .map(|(_, sym)| *sym) + .remove(&(*symbol, arg_layout)) + .map(|(_, sym)| sym) .unwrap_or(*symbol); // store immediately in the given symbol @@ -6562,8 +6618,19 @@ fn store_newtype_pattern<'a>( match argument { Identifier(symbol) => { - // store immediately in the given symbol - stmt = Stmt::Let(*symbol, load, arg_layout, env.arena.alloc(stmt)); + // store immediately in the given symbol, removing it specialization if it had any + let specialization_symbol = procs + .remove_single_symbol_specialization(*symbol) + // Can happen when the symbol was never used under this body, and hence has no + // requested specialization. + .unwrap_or(*symbol); + + stmt = Stmt::Let( + specialization_symbol, + load, + arg_layout, + env.arena.alloc(stmt), + ); is_productive = true; } Underscore => { @@ -6625,11 +6692,35 @@ fn store_record_destruct<'a>( match &destruct.typ { DestructType::Required(symbol) => { - stmt = Stmt::Let(*symbol, load, destruct.layout, env.arena.alloc(stmt)); + // A destructure can define at most one specialization! + // Remove any requested specializations for this name now, since this is the definition site. + let specialization_symbol = procs + .remove_single_symbol_specialization(*symbol) + // Can happen when the symbol was never used under this body, and hence has no + // requested specialization. + .unwrap_or(*symbol); + + stmt = Stmt::Let( + specialization_symbol, + load, + destruct.layout, + env.arena.alloc(stmt), + ); } DestructType::Guard(guard_pattern) => match &guard_pattern { Identifier(symbol) => { - stmt = Stmt::Let(*symbol, load, destruct.layout, env.arena.alloc(stmt)); + let specialization_symbol = procs + .remove_single_symbol_specialization(*symbol) + // Can happen when the symbol was never used under this body, and hence has no + // requested specialization. + .unwrap_or(*symbol); + + stmt = Stmt::Let( + specialization_symbol, + load, + destruct.layout, + env.arena.alloc(stmt), + ); } Underscore => { // important that this is special-cased to do nothing: mono record patterns will extract all the @@ -6816,48 +6907,53 @@ where return build_rest(env, procs, layout_cache); } - // Otherwise we're dealing with an alias to something that doesn't need to be specialized, or - // whose usages will already be specialized in the rest of the program. - if procs.is_imported_module_thunk(right) { - let result = build_rest(env, procs, layout_cache); + if procs.partial_procs.contains_key(right) { + // This is an alias to a function defined in this module. + // Attach the alias, then build the rest of the module, so that we reference and specialize + // the correct proc. + procs.partial_procs.insert_alias(left, right); + return build_rest(env, procs, layout_cache); + } + // Otherwise we're dealing with an alias whose usages will tell us what specializations we + // need. So let's figure those out first. + let result = build_rest(env, procs, layout_cache); + + // The specializations we wanted of the symbol on the LHS of this alias. + let needed_specializations_of_left = procs + .needed_symbol_specializations + .drain_filter(|(s, _), _| s == &left) + .collect::>(); + + if procs.is_imported_module_thunk(right) { // if this is an imported symbol, then we must make sure it is // specialized, and wrap the original in a function pointer. - add_needed_external(procs, env, variable, right); + let mut result = result; + for (_, (variable, left)) in needed_specializations_of_left.into_iter() { + add_needed_external(procs, env, variable, right); - let res_layout = layout_cache.from_var(env.arena, variable, env.subs); - let layout = return_on_layout_error!(env, res_layout); + let res_layout = layout_cache.from_var(env.arena, variable, env.subs); + let layout = return_on_layout_error!(env, res_layout); - force_thunk(env, right, layout, left, env.arena.alloc(result)) + result = force_thunk(env, right, layout, left, env.arena.alloc(result)); + } + result } else if env.is_imported_symbol(right) { - let result = build_rest(env, procs, layout_cache); - // if this is an imported symbol, then we must make sure it is // specialized, and wrap the original in a function pointer. add_needed_external(procs, env, variable, right); // then we must construct its closure; since imported symbols have no closure, we use the empty struct let_empty_struct(left, env.arena.alloc(result)) - } else if procs.partial_procs.contains_key(right) { - // This is an alias to a function defined in this module. - // Attach the alias, then build the rest of the module, so that we reference and specialize - // the correct proc. - procs.partial_procs.insert_alias(left, right); - build_rest(env, procs, layout_cache) } else { - // This should be a fully specialized value. Replace the alias with the original symbol. - let mut result = build_rest(env, procs, layout_cache); - // We need to lift all specializations of "left" to be specializations of "right". - let to_update = procs - .needed_symbol_specializations - .drain_filter(|(s, _), _| s == &left) - .collect::>(); let mut scratchpad_update_specializations = std::vec::Vec::new(); - let left_had_specialization_symbols = !to_update.is_empty(); + let left_had_specialization_symbols = !needed_specializations_of_left.is_empty(); - for ((_, layout), (specialized_var, specialized_sym)) in to_update.into_iter() { + for ((_, layout), (specialized_var, specialized_sym)) in + needed_specializations_of_left.into_iter() + { let old_specialized_sym = procs .needed_symbol_specializations .insert((right, layout), (specialized_var, specialized_sym)); @@ -6867,6 +6963,7 @@ where } } + let mut result = result; if left_had_specialization_symbols { // If the symbol is specialized, only the specializations need to be updated. for (old_specialized_sym, specialized_sym) in @@ -7894,6 +7991,7 @@ pub struct WhenBranch<'a> { #[allow(clippy::type_complexity)] fn from_can_pattern<'a>( env: &mut Env<'a, '_>, + procs: &mut Procs<'a>, layout_cache: &mut LayoutCache<'a>, can_pattern: &roc_can::pattern::Pattern, ) -> Result< @@ -7904,13 +8002,14 @@ fn from_can_pattern<'a>( RuntimeError, > { let mut assignments = Vec::new_in(env.arena); - let pattern = from_can_pattern_help(env, layout_cache, can_pattern, &mut assignments)?; + let pattern = from_can_pattern_help(env, procs, layout_cache, can_pattern, &mut assignments)?; Ok((pattern, assignments)) } fn from_can_pattern_help<'a>( env: &mut Env<'a, '_>, + procs: &mut Procs<'a>, layout_cache: &mut LayoutCache<'a>, can_pattern: &roc_can::pattern::Pattern, assignments: &mut Vec<'a, (Symbol, Variable, roc_can::expr::Expr)>, @@ -8105,7 +8204,13 @@ fn from_can_pattern_help<'a>( let mut mono_args = Vec::with_capacity_in(arguments.len(), env.arena); for ((_, loc_pat), layout) in arguments.iter().zip(field_layouts.iter()) { mono_args.push(( - from_can_pattern_help(env, layout_cache, &loc_pat.value, assignments)?, + from_can_pattern_help( + env, + procs, + layout_cache, + &loc_pat.value, + assignments, + )?, *layout, )); } @@ -8183,6 +8288,7 @@ fn from_can_pattern_help<'a>( mono_args.push(( from_can_pattern_help( env, + procs, layout_cache, &loc_pat.value, assignments, @@ -8228,6 +8334,7 @@ fn from_can_pattern_help<'a>( mono_args.push(( from_can_pattern_help( env, + procs, layout_cache, &loc_pat.value, assignments, @@ -8271,6 +8378,7 @@ fn from_can_pattern_help<'a>( mono_args.push(( from_can_pattern_help( env, + procs, layout_cache, &loc_pat.value, assignments, @@ -8344,6 +8452,7 @@ fn from_can_pattern_help<'a>( mono_args.push(( from_can_pattern_help( env, + procs, layout_cache, &loc_pat.value, assignments, @@ -8400,6 +8509,7 @@ fn from_can_pattern_help<'a>( mono_args.push(( from_can_pattern_help( env, + procs, layout_cache, &loc_pat.value, assignments, @@ -8430,8 +8540,13 @@ fn from_can_pattern_help<'a>( let arg_layout = layout_cache .from_var(env.arena, *arg_var, env.subs) .unwrap(); - let mono_arg_pattern = - from_can_pattern_help(env, layout_cache, &loc_arg_pattern.value, assignments)?; + let mono_arg_pattern = from_can_pattern_help( + env, + procs, + layout_cache, + &loc_arg_pattern.value, + assignments, + )?; Ok(Pattern::OpaqueUnwrap { opaque: *opaque, argument: Box::new((mono_arg_pattern, arg_layout)), @@ -8474,6 +8589,7 @@ fn from_can_pattern_help<'a>( // this field is destructured by the pattern mono_destructs.push(from_can_record_destruct( env, + procs, layout_cache, &destruct.value, field_layout, @@ -8565,6 +8681,7 @@ fn from_can_pattern_help<'a>( fn from_can_record_destruct<'a>( env: &mut Env<'a, '_>, + procs: &mut Procs<'a>, layout_cache: &mut LayoutCache<'a>, can_rd: &roc_can::pattern::RecordDestruct, field_layout: Layout<'a>, @@ -8581,7 +8698,7 @@ fn from_can_record_destruct<'a>( DestructType::Required(can_rd.symbol) } roc_can::pattern::DestructType::Guard(_, loc_pattern) => DestructType::Guard( - from_can_pattern_help(env, layout_cache, &loc_pattern.value, assignments)?, + from_can_pattern_help(env, procs, layout_cache, &loc_pattern.value, assignments)?, ), }, }) From a1eb65b1697e87c75da6a6898d0739da447b0e43 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 5 May 2022 11:13:09 -0400 Subject: [PATCH 818/846] Debug assert needed specializations are empty after leaving mono --- compiler/mono/src/ir.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index ffca4f94d6..68c0898e20 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -2156,6 +2156,12 @@ pub fn specialize_all<'a>( specialize_host_specializations(env, &mut procs, layout_cache, specializations_for_host); + debug_assert!( + procs.needed_symbol_specializations.is_empty(), + "{:?}", + &procs.needed_symbol_specializations + ); + procs } From 8d6b86efc7799dc1ce167790494d640683e42834 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 5 May 2022 11:20:23 -0400 Subject: [PATCH 819/846] Minor cleanup --- compiler/mono/src/ir.rs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 68c0898e20..4015d66cc9 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -4778,16 +4778,6 @@ where let lambda_set_layout = Layout::LambdaSet(lambda_set); let symbols = symbols.into_iter(); - // It may be the case that while capturing a symbol, we actually want to capture it under a - // different name than what the - // let get_specialized_name = |symbol, layout| { - // procs - // .needed_symbol_specializations - // .get(&(symbol, layout)) - // .map(|(_, specialized)| *specialized) - // .unwrap_or(symbol) - // }; - let result = match lambda_set.layout_for_member(name) { ClosureRepresentation::Union { tag_id, @@ -5670,6 +5660,9 @@ pub fn from_can<'a>( // We do need specializations let mut stmt = rest; + + // Remove all the requested symbol specializations now, since this is the + // def site and hence we won't need them any higher up. let mut needed_specializations = procs .needed_symbol_specializations .drain_filter(|(s, _), _| s == symbol) @@ -6541,11 +6534,9 @@ fn store_tag_pattern<'a>( match argument { Identifier(symbol) => { - // TODO: use procs.remove_single_symbol_specialization + // Pattern can define only one specialization let symbol = procs - .needed_symbol_specializations - .remove(&(*symbol, arg_layout)) - .map(|(_, sym)| sym) + .remove_single_symbol_specialization(*symbol) .unwrap_or(*symbol); // store immediately in the given symbol From 8f593480e56d3b38288cdd3b7d29b5b7d0936e7e Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 5 May 2022 11:23:47 -0400 Subject: [PATCH 820/846] Simplify specialize_naked_symbol with value variables --- compiler/mono/src/ir.rs | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 4015d66cc9..a59d352f1c 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -3044,25 +3044,9 @@ fn specialize_naked_symbol<'a>( } } - let mut symbol = symbol; let result = match hole { Stmt::Jump(id, _) => Stmt::Jump(*id, env.arena.alloc([symbol])), - _ => { - use roc_can::expr::Expr; - if let ReuseSymbol::Value(_symbol) = can_reuse_symbol(env, procs, &Expr::Var(symbol)) { - let real_symbol = possible_reuse_symbol_or_specialize( - env, - procs, - layout_cache, - &Expr::Var(symbol), - variable, - ); - symbol = real_symbol; - Stmt::Ret(real_symbol) - } else { - Stmt::Ret(symbol) - } - } + _ => Stmt::Ret(symbol), }; // if the symbol is a function symbol, ensure it is properly specialized! @@ -3395,7 +3379,16 @@ pub fn with_hole<'a>( hole, ) } - Var(symbol) => { + Var(mut symbol) => { + // If this symbol is a raw value, find the real name we gave to its specialized usage. + if let ReuseSymbol::Value(_symbol) = + can_reuse_symbol(env, procs, &roc_can::expr::Expr::Var(symbol)) + { + let real_symbol = + reuse_symbol_or_specialize(env, procs, layout_cache, symbol, variable); + symbol = real_symbol; + } + specialize_naked_symbol(env, variable, procs, layout_cache, assigned, hole, symbol) } Tag { From 8228df55c79912647100fcebdc6e768dfbca4cfc Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 5 May 2022 11:28:26 -0400 Subject: [PATCH 821/846] Remove resolved stopgap --- compiler/mono/src/ir.rs | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index a59d352f1c..405143d1cd 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -6810,22 +6810,6 @@ fn reuse_symbol_or_specialize<'a>( symbol: Symbol, var: Variable, ) -> Symbol { - // TODO: for some reason, we can't attempt to specialize the built-in argument symbols. - // Figure out why. - let arguments = [ - Symbol::ARG_1, - Symbol::ARG_2, - Symbol::ARG_3, - Symbol::ARG_4, - Symbol::ARG_5, - Symbol::ARG_6, - Symbol::ARG_7, - ]; - - if arguments.contains(&symbol) { - return symbol; - } - let wanted_layout = match layout_cache.from_var(env.arena, var, env.subs) { Ok(layout) => layout, // This can happen when the def symbol has a type error. In such cases just use the From 674ec3beaecc8461e71001828e9c878671ea1a28 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 5 May 2022 11:46:29 -0400 Subject: [PATCH 822/846] Verify layouts of extracted specialization symbols --- compiler/mono/src/decision_tree.rs | 21 ++++- compiler/mono/src/ir.rs | 133 ++++++++++++++++++++++++----- 2 files changed, 131 insertions(+), 23 deletions(-) diff --git a/compiler/mono/src/decision_tree.rs b/compiler/mono/src/decision_tree.rs index 8e3f3816b8..fbdea41a24 100644 --- a/compiler/mono/src/decision_tree.rs +++ b/compiler/mono/src/decision_tree.rs @@ -1210,8 +1210,15 @@ pub fn optimize_when<'a>( // bind the fields referenced in the pattern. For guards this happens separately, so // the pattern variables are defined when evaluating the guard. if !has_guard { - branch = - crate::ir::store_pattern(env, procs, layout_cache, &pattern, cond_symbol, branch); + branch = crate::ir::store_pattern( + env, + procs, + layout_cache, + &pattern, + cond_layout, + cond_symbol, + branch, + ); } let ((branch_index, choice), opt_jump) = create_choices(&target_counts, index, branch); @@ -1723,7 +1730,15 @@ fn decide_to_branching<'a>( body: arena.alloc(decide), }; - crate::ir::store_pattern(env, procs, layout_cache, &pattern, cond_symbol, join) + crate::ir::store_pattern( + env, + procs, + layout_cache, + &pattern, + cond_layout, + cond_symbol, + join, + ) } Chain { test_chain, diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 405143d1cd..8077e8f030 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -772,14 +772,23 @@ impl<'a> Procs<'a> { } /// Expects and removes a single specialization symbol for the given requested symbol. - fn remove_single_symbol_specialization(&mut self, symbol: Symbol) -> Option { + /// In debug builds, we assert that the layout of the specialization is the layout expected by + /// the requested symbol. + fn remove_single_symbol_specialization( + &mut self, + symbol: Symbol, + layout: Layout, + ) -> Option { let mut specialized_symbols = self .needed_symbol_specializations .drain_filter(|(sym, _), _| sym == &symbol); let specialization_symbol = specialized_symbols .next() - .map(|(_, (_, specialized_symbol))| specialized_symbol); + .map(|((_, specialized_layout), (_, specialized_symbol))| { + debug_assert_eq!(specialized_layout, layout, "Requested the single specialization of {:?}, but the specialization layout ({:?}) doesn't match the expected layout ({:?})", symbol, specialized_layout, layout); + specialized_symbol + }); debug_assert_eq!( specialized_symbols.count(), @@ -3342,7 +3351,18 @@ pub fn with_hole<'a>( ); let outer_symbol = env.unique_symbol(); - stmt = store_pattern(env, procs, layout_cache, &mono_pattern, outer_symbol, stmt); + let pattern_layout = layout_cache + .from_var(env.arena, def.expr_var, env.subs) + .expect("Pattern has no layout"); + stmt = store_pattern( + env, + procs, + layout_cache, + &mono_pattern, + pattern_layout, + outer_symbol, + stmt, + ); // convert the def body, store in outer_symbol with_hole( @@ -5750,8 +5770,11 @@ pub fn from_can<'a>( // layer on any default record fields for (symbol, variable, expr) in assignments { + let layout = layout_cache + .from_var(env.arena, variable, env.subs) + .expect("Default field has no layout"); let specialization_symbol = procs - .remove_single_symbol_specialization(symbol) + .remove_single_symbol_specialization(symbol, layout) // Can happen when the symbol was never used under this body, and hence has no // requested specialization. .unwrap_or(symbol); @@ -5768,12 +5791,30 @@ pub fn from_can<'a>( ); } + let pattern_layout = layout_cache + .from_var(env.arena, def.expr_var, env.subs) + .expect("Pattern has no layout"); if let roc_can::expr::Expr::Var(outer_symbol) = def.loc_expr.value { - store_pattern(env, procs, layout_cache, &mono_pattern, outer_symbol, stmt) + store_pattern( + env, + procs, + layout_cache, + &mono_pattern, + pattern_layout, + outer_symbol, + stmt, + ) } else { let outer_symbol = env.unique_symbol(); - stmt = - store_pattern(env, procs, layout_cache, &mono_pattern, outer_symbol, stmt); + stmt = store_pattern( + env, + procs, + layout_cache, + &mono_pattern, + pattern_layout, + outer_symbol, + stmt, + ); // convert the def body, store in outer_symbol with_hole( @@ -6339,10 +6380,19 @@ pub fn store_pattern<'a>( procs: &mut Procs<'a>, layout_cache: &mut LayoutCache<'a>, can_pat: &Pattern<'a>, + pattern_layout: Layout, outer_symbol: Symbol, stmt: Stmt<'a>, ) -> Stmt<'a> { - match store_pattern_help(env, procs, layout_cache, can_pat, outer_symbol, stmt) { + match store_pattern_help( + env, + procs, + layout_cache, + can_pat, + pattern_layout, + outer_symbol, + stmt, + ) { StorePattern::Productive(new) => new, StorePattern::NotProductive(new) => new, } @@ -6362,6 +6412,7 @@ fn store_pattern_help<'a>( procs: &mut Procs<'a>, layout_cache: &mut LayoutCache<'a>, can_pat: &Pattern<'a>, + pattern_layout: Layout, outer_symbol: Symbol, mut stmt: Stmt<'a>, ) -> StorePattern<'a> { @@ -6372,7 +6423,7 @@ fn store_pattern_help<'a>( // An identifier in a pattern can define at most one specialization! // Remove any requested specializations for this name now, since this is the definition site. let specialization_symbol = procs - .remove_single_symbol_specialization(*symbol) + .remove_single_symbol_specialization(*symbol, pattern_layout) // Can happen when the symbol was never used under this body, and hence has no // requested specialization. .unwrap_or(*symbol); @@ -6393,8 +6444,16 @@ fn store_pattern_help<'a>( return StorePattern::NotProductive(stmt); } NewtypeDestructure { arguments, .. } => match arguments.as_slice() { - [single] => { - return store_pattern_help(env, procs, layout_cache, &single.0, outer_symbol, stmt); + [(pattern, layout)] => { + return store_pattern_help( + env, + procs, + layout_cache, + pattern, + *layout, + outer_symbol, + stmt, + ); } _ => { let mut fields = Vec::with_capacity_in(arguments.len(), env.arena); @@ -6431,7 +6490,16 @@ fn store_pattern_help<'a>( ); } OpaqueUnwrap { argument, .. } => { - return store_pattern_help(env, procs, layout_cache, &argument.0, outer_symbol, stmt); + let (pattern, layout) = &**argument; + return store_pattern_help( + env, + procs, + layout_cache, + pattern, + *layout, + outer_symbol, + stmt, + ); } RecordDestructure(destructs, [_single_field]) => { @@ -6439,7 +6507,7 @@ fn store_pattern_help<'a>( match &destruct.typ { DestructType::Required(symbol) => { let specialization_symbol = procs - .remove_single_symbol_specialization(*symbol) + .remove_single_symbol_specialization(*symbol, destruct.layout) // Can happen when the symbol was never used under this body, and hence has no // requested specialization. .unwrap_or(*symbol); @@ -6457,6 +6525,7 @@ fn store_pattern_help<'a>( procs, layout_cache, guard_pattern, + destruct.layout, outer_symbol, stmt, ); @@ -6529,7 +6598,7 @@ fn store_tag_pattern<'a>( Identifier(symbol) => { // Pattern can define only one specialization let symbol = procs - .remove_single_symbol_specialization(*symbol) + .remove_single_symbol_specialization(*symbol, arg_layout) .unwrap_or(*symbol); // store immediately in the given symbol @@ -6550,7 +6619,15 @@ fn store_tag_pattern<'a>( let symbol = env.unique_symbol(); // first recurse, continuing to unpack symbol - match store_pattern_help(env, procs, layout_cache, argument, symbol, stmt) { + match store_pattern_help( + env, + procs, + layout_cache, + argument, + arg_layout, + symbol, + stmt, + ) { StorePattern::Productive(new) => { is_productive = true; stmt = new; @@ -6610,7 +6687,7 @@ fn store_newtype_pattern<'a>( Identifier(symbol) => { // store immediately in the given symbol, removing it specialization if it had any let specialization_symbol = procs - .remove_single_symbol_specialization(*symbol) + .remove_single_symbol_specialization(*symbol, arg_layout) // Can happen when the symbol was never used under this body, and hence has no // requested specialization. .unwrap_or(*symbol); @@ -6637,7 +6714,15 @@ fn store_newtype_pattern<'a>( let symbol = env.unique_symbol(); // first recurse, continuing to unpack symbol - match store_pattern_help(env, procs, layout_cache, argument, symbol, stmt) { + match store_pattern_help( + env, + procs, + layout_cache, + argument, + arg_layout, + symbol, + stmt, + ) { StorePattern::Productive(new) => { is_productive = true; stmt = new; @@ -6685,7 +6770,7 @@ fn store_record_destruct<'a>( // A destructure can define at most one specialization! // Remove any requested specializations for this name now, since this is the definition site. let specialization_symbol = procs - .remove_single_symbol_specialization(*symbol) + .remove_single_symbol_specialization(*symbol, destruct.layout) // Can happen when the symbol was never used under this body, and hence has no // requested specialization. .unwrap_or(*symbol); @@ -6700,7 +6785,7 @@ fn store_record_destruct<'a>( DestructType::Guard(guard_pattern) => match &guard_pattern { Identifier(symbol) => { let specialization_symbol = procs - .remove_single_symbol_specialization(*symbol) + .remove_single_symbol_specialization(*symbol, destruct.layout) // Can happen when the symbol was never used under this body, and hence has no // requested specialization. .unwrap_or(*symbol); @@ -6738,7 +6823,15 @@ fn store_record_destruct<'a>( _ => { let symbol = env.unique_symbol(); - match store_pattern_help(env, procs, layout_cache, guard_pattern, symbol, stmt) { + match store_pattern_help( + env, + procs, + layout_cache, + guard_pattern, + destruct.layout, + symbol, + stmt, + ) { StorePattern::Productive(new) => { stmt = new; stmt = Stmt::Let(symbol, load, destruct.layout, env.arena.alloc(stmt)); From be55398d3c5ad2cc712ea7b54d47f4b15d305ad7 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 5 May 2022 11:52:41 -0400 Subject: [PATCH 823/846] Revert solve changes --- compiler/solve/src/solve.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index e40ab2f743..79b86bfad1 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -440,7 +440,7 @@ impl Env { const DEFAULT_POOLS: usize = 8; #[derive(Clone, Debug)] -pub struct Pools(Vec>); +struct Pools(Vec>); impl Default for Pools { fn default() -> Self { @@ -457,10 +457,6 @@ impl Pools { self.0.len() } - pub fn is_empty(&self) -> bool { - self.len() == 0 - } - pub fn get_mut(&mut self, rank: Rank) -> &mut Vec { match self.0.get_mut(rank.into_usize()) { Some(reference) => reference, @@ -2872,7 +2868,7 @@ fn instantiate_rigids_help(subs: &mut Subs, max_rank: Rank, initial: Variable) { } } -pub fn deep_copy_var_in( +fn deep_copy_var_in( subs: &mut Subs, rank: Rank, pools: &mut Pools, From 76fb5308e7237098b63dfd7dfbcd97d91c116666 Mon Sep 17 00:00:00 2001 From: Folkert Date: Thu, 5 May 2022 17:57:02 +0200 Subject: [PATCH 824/846] update wasm type size asserts --- compiler/module/src/ident.rs | 2 +- compiler/mono/src/ir.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/module/src/ident.rs b/compiler/module/src/ident.rs index 064f061974..56adb96189 100644 --- a/compiler/module/src/ident.rs +++ b/compiler/module/src/ident.rs @@ -63,7 +63,7 @@ pub enum TagName { } roc_error_macros::assert_sizeof_aarch64!(TagName, 24); -roc_error_macros::assert_sizeof_wasm!(TagName, 16); +roc_error_macros::assert_sizeof_wasm!(TagName, 12); roc_error_macros::assert_sizeof_default!(TagName, 24); impl TagName { diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index a8937a39d4..db380ce851 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -56,11 +56,11 @@ roc_error_macros::assert_sizeof_aarch64!(Call, 7 * 8); roc_error_macros::assert_sizeof_aarch64!(CallType, 5 * 8); roc_error_macros::assert_sizeof_wasm!(Literal, 24); -roc_error_macros::assert_sizeof_wasm!(Expr, 56); +roc_error_macros::assert_sizeof_wasm!(Expr, 48); roc_error_macros::assert_sizeof_wasm!(Stmt, 120); roc_error_macros::assert_sizeof_wasm!(ProcLayout, 32); -roc_error_macros::assert_sizeof_wasm!(Call, 40); -roc_error_macros::assert_sizeof_wasm!(CallType, 32); +roc_error_macros::assert_sizeof_wasm!(Call, 36); +roc_error_macros::assert_sizeof_wasm!(CallType, 28); roc_error_macros::assert_sizeof_default!(Literal, 3 * 8); roc_error_macros::assert_sizeof_default!(Expr, 10 * 8); From a760510be0217def34794269c04196b99e008d27 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 5 May 2022 12:06:09 -0400 Subject: [PATCH 825/846] Consolidate and improve debug_flags --- Cargo.lock | 1 + compiler/debug_flags/src/lib.rs | 23 ++++++++++++++++++++++- compiler/solve/Cargo.toml | 1 + compiler/solve/src/solve.rs | 5 +++-- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a28f5dc79f..8b4691a883 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4004,6 +4004,7 @@ dependencies = [ "roc_builtins", "roc_can", "roc_collections", + "roc_debug_flags", "roc_error_macros", "roc_exhaustive", "roc_load", diff --git a/compiler/debug_flags/src/lib.rs b/compiler/debug_flags/src/lib.rs index b9d66a42b1..5af06aff4c 100644 --- a/compiler/debug_flags/src/lib.rs +++ b/compiler/debug_flags/src/lib.rs @@ -24,17 +24,22 @@ //! ROC_PRINT_IR_AFTER_RESET_REUSE=0 \ //! ROC_PRINT_IR_AFTER_REFCOUNT=0 \ //! ROC_PRETTY_PRINT_IR_SYMBOLS=0 \ +//! # ...other flags //! cargo" //! ``` //! //! Now you can turn debug flags on and off as you like. +//! +//! These flags are also set in .cargo/config found at the repository root. You can modify them +//! there to avoid maintaining a separate script. #[macro_export] macro_rules! dbg_do { ($flag:path, $expr:expr) => { #[cfg(debug_assertions)] { - if std::env::var($flag).as_ref() == Ok(&"0".to_string()) { + let flag = std::env::var($flag); + if !flag.is_err() && flag.as_deref() != Ok("0") { $expr } } @@ -62,6 +67,22 @@ flags! { /// Prints all type mismatches hit during type unification. ROC_PRINT_MISMATCHES + /// Verifies that after let-generalization of a def, any rigid variables in the type annotation + /// of the def are indeed generalized. + /// + /// Note that rigids need not always be generalized in a def. For example, they may be + /// constrained by a type from a lower rank, as `b` is in the following def: + /// + /// F a : { foo : a } + /// foo = \arg -> + /// x : F b + /// x = arg + /// x.foo + /// + /// Instead, this flag is useful for checking that in general, introduction is correct, when + /// chainging how defs are constrained. + ROC_VERIFY_RIGID_LET_GENERALIZED + // ===Mono=== /// Writes a pretty-printed mono IR to stderr after function specialization. diff --git a/compiler/solve/Cargo.toml b/compiler/solve/Cargo.toml index 6b32bc14a8..d083f524fa 100644 --- a/compiler/solve/Cargo.toml +++ b/compiler/solve/Cargo.toml @@ -14,6 +14,7 @@ roc_module = { path = "../module" } roc_types = { path = "../types" } roc_can = { path = "../can" } roc_unify = { path = "../unify" } +roc_debug_flags = { path = "../debug_flags" } arrayvec = "0.7.2" bumpalo = { version = "3.8.0", features = ["collections"] } diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index 79b86bfad1..b35e08c205 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -5,6 +5,7 @@ use roc_can::constraint::Constraint::{self, *}; use roc_can::constraint::{Constraints, LetConstraint}; use roc_can::expected::{Expected, PExpected}; use roc_collections::all::MutMap; +use roc_debug_flags::{dbg_do, ROC_VERIFY_RIGID_LET_GENERALIZED}; use roc_error_macros::internal_error; use roc_module::ident::TagName; use roc_module::symbol::Symbol; @@ -740,7 +741,7 @@ fn solve( pools.get_mut(next_rank).clear(); // check that things went well - if cfg!(debug_assertions) && std::env::var("ROC_VERIFY_RIGID_RANKS").is_ok() { + dbg_do!(ROC_VERIFY_RIGID_LET_GENERALIZED, { let rigid_vars = &constraints.variables[let_con.rigid_vars.indices()]; // NOTE the `subs.redundant` check does not come from elm. @@ -758,7 +759,7 @@ fn solve( println!("Failing {:?}", failing); debug_assert!(false); } - } + }); let mut new_env = env.clone(); for (symbol, loc_var) in local_def_vars.iter() { From 64b87576d3748587761f9add6c28c2be3a29bf57 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 5 May 2022 12:08:34 -0400 Subject: [PATCH 826/846] Add debug flags to cargo config --- .cargo/config | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.cargo/config b/.cargo/config index 584d158f1c..3890df744a 100644 --- a/.cargo/config +++ b/.cargo/config @@ -8,3 +8,17 @@ test-gen-wasm = "test -p roc_gen_wasm -p test_gen --no-default-features --featur # opt-level=s Optimizations should focus more on size than speed # lto=fat Spend extra effort on link-time optimization across crates rustflags = ["-Copt-level=s", "-Clto=fat"] + +[env] +# Debug flags. Keep this up-to-date with compiler/debug_flags/src/lib.rs. +# Set = "1" to turn a debug flag on. +ROC_PRETTY_PRINT_ALIAS_CONTENTS = "0" +ROC_PRINT_UNIFICATIONS = "0" +ROC_PRINT_MISMATCHES = "0" +ROC_VERIFY_RIGID_LET_GENERALIZED = "0" +ROC_PRINT_IR_AFTER_SPECIALIZATION = "0" +ROC_PRINT_IR_AFTER_RESET_REUSE = "0" +ROC_PRINT_IR_AFTER_REFCOUNT = "0" +ROC_DEBUG_ALIAS_ANALYSIS = "0" +ROC_PRINT_LLVM_FN_VERIFICATION = "0" +ROC_PRINT_LOAD_LOG = "0" From e6a72578c10d1f472f7be8e6364ab36a00a415db Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 5 May 2022 16:17:49 -0400 Subject: [PATCH 827/846] Add Annotation::add_to --- compiler/can/src/annotation.rs | 22 +++++++++++++++++++ compiler/can/src/def.rs | 40 +++++++++------------------------- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index d1063d628b..97cc04ee9a 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -1,4 +1,5 @@ use crate::env::Env; +use crate::procedure::References; use crate::scope::Scope; use roc_collections::{ImMap, MutSet, SendMap, VecMap, VecSet}; use roc_module::ident::{Ident, Lowercase, TagName}; @@ -20,6 +21,27 @@ pub struct Annotation { pub aliases: SendMap, } +impl Annotation { + pub fn add_to( + &self, + aliases: &mut VecMap, + references: &mut References, + introduced_variables: &mut IntroducedVariables, + ) { + for symbol in self.references.iter() { + references.insert_type_lookup(*symbol); + } + + introduced_variables.union(&self.introduced_variables); + + for (name, alias) in self.aliases.iter() { + if !aliases.contains_key(name) { + aliases.insert(*name, alias.clone()); + } + } + } +} + #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] pub enum NamedOrAbleVariable<'a> { Named(&'a NamedVariable), diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index ea0448e31e..d21462e08b 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -966,17 +966,6 @@ fn single_can_def( } } -fn add_annotation_aliases( - type_annotation: &crate::annotation::Annotation, - aliases: &mut VecMap, -) { - for (name, alias) in type_annotation.aliases.iter() { - if !aliases.contains_key(name) { - aliases.insert(*name, alias.clone()); - } - } -} - // Functions' references don't count in defs. // See 3d5a2560057d7f25813112dfa5309956c0f9e6a9 and its // parent commit for the bug this fixed! @@ -1029,16 +1018,11 @@ fn canonicalize_pending_value_def<'a>( ); // Record all the annotation's references in output.references.lookups - - for symbol in type_annotation.references.iter() { - output.references.insert_type_lookup(*symbol); - } - - add_annotation_aliases(&type_annotation, aliases); - - output - .introduced_variables - .union(&type_annotation.introduced_variables); + type_annotation.add_to( + aliases, + &mut output.references, + &mut output.introduced_variables, + ); pattern_to_vars_by_symbol(&mut vars_by_symbol, &loc_can_pattern.value, expr_var); @@ -1131,15 +1115,11 @@ fn canonicalize_pending_value_def<'a>( ); // Record all the annotation's references in output.references.lookups - for symbol in type_annotation.references.iter() { - output.references.insert_type_lookup(*symbol); - } - - add_annotation_aliases(&type_annotation, aliases); - - output - .introduced_variables - .union(&type_annotation.introduced_variables); + type_annotation.add_to( + aliases, + &mut output.references, + &mut output.introduced_variables, + ); canonicalize_pending_body( env, From 59023d2a8877a3fc5fad700deb40373b5fc8f0a9 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 5 May 2022 16:18:38 -0400 Subject: [PATCH 828/846] Add VecSet::insert_all --- compiler/collections/src/vec_set.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/compiler/collections/src/vec_set.rs b/compiler/collections/src/vec_set.rs index 09730f7e95..d139272e89 100644 --- a/compiler/collections/src/vec_set.rs +++ b/compiler/collections/src/vec_set.rs @@ -40,6 +40,17 @@ impl VecSet { } } + /// Returns true iff any of the given elements previoously existed in the set. + pub fn insert_all>(&mut self, values: I) -> bool { + let mut any_existed = false; + + for value in values { + any_existed = any_existed || self.insert(value); + } + + any_existed + } + pub fn contains(&self, value: &T) -> bool { self.elements.contains(value) } From 1421aebcd38af5a5294d88eb0245f303091344be Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 5 May 2022 16:18:47 -0400 Subject: [PATCH 829/846] Thread through symbols_from_requires --- compiler/can/src/def.rs | 6 ++++- compiler/can/src/expr.rs | 1 + compiler/can/src/module.rs | 40 +++++++++++++++++++++++++++--- compiler/constrain/src/module.rs | 36 ++++++++++++++++++++++++++- compiler/load_internal/src/file.rs | 17 ++++++++++--- 5 files changed, 91 insertions(+), 9 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index d21462e08b..cd7d5e2981 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -54,7 +54,7 @@ pub struct Annotation { pub(crate) struct CanDefs { defs: Vec>, def_ordering: DefOrdering, - + pub(crate) abilities_in_scope: Vec, aliases: VecMap, } @@ -523,6 +523,7 @@ pub(crate) fn canonicalize_defs<'a>( CanDefs { defs, def_ordering, + abilities_in_scope, // The result needs a thread-safe `SendMap` aliases, }, @@ -766,8 +767,11 @@ pub(crate) fn sort_can_defs( mut defs, def_ordering, aliases, + abilities_in_scope, } = defs; + output.abilities_in_scope = abilities_in_scope; + for (symbol, alias) in aliases.into_iter() { output.aliases.insert(symbol, alias); } diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index b60a552f5c..12748b16ec 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -30,6 +30,7 @@ pub struct Output { pub introduced_variables: IntroducedVariables, pub aliases: VecMap, pub non_closures: VecSet, + pub abilities_in_scope: Vec, } impl Output { diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index ffba784309..a9fecd2323 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -1,4 +1,5 @@ use crate::abilities::AbilitiesStore; +use crate::annotation::canonicalize_annotation; use crate::def::{canonicalize_defs, sort_can_defs, Declaration, Def}; use crate::effect_module::HostedGeneratedFunctions; use crate::env::Env; @@ -11,7 +12,7 @@ use roc_collections::{MutMap, SendMap, VecSet}; use roc_module::ident::Ident; use roc_module::ident::Lowercase; use roc_module::symbol::{IdentIds, IdentIdsByModule, ModuleId, ModuleIds, Symbol}; -use roc_parse::ast; +use roc_parse::ast::{self, TypeAnnotation}; use roc_parse::header::HeaderFor; use roc_parse::pattern::PatternType; use roc_problem::can::{Problem, RuntimeError}; @@ -49,6 +50,7 @@ pub struct ModuleOutput { pub problems: Vec, pub referenced_values: VecSet, pub referenced_types: VecSet, + pub symbols_from_requires: Vec<(Symbol, Loc)>, pub scope: Scope, } @@ -156,16 +158,17 @@ fn has_no_implementation(expr: &Expr) -> bool { // TODO trim these down #[allow(clippy::too_many_arguments)] pub fn canonicalize_module_defs<'a>( - arena: &Bump, + arena: &'a Bump, loc_defs: &'a [Loc>], header_for: &roc_parse::header::HeaderFor, home: ModuleId, - module_ids: &ModuleIds, + module_ids: &'a ModuleIds, exposed_ident_ids: IdentIds, dep_idents: &'a IdentIdsByModule, aliases: MutMap, exposed_imports: MutMap, exposed_symbols: &VecSet, + symbols_from_requires: &[(Symbol, Loc>)], var_store: &mut VarStore, ) -> Result { let mut can_exposed_imports = MutMap::default(); @@ -349,9 +352,37 @@ pub fn canonicalize_module_defs<'a>( }; match sort_can_defs(&mut env, defs, new_output) { - (Ok(mut declarations), output) => { + (Ok(mut declarations), mut output) => { use crate::def::Declaration::*; + let symbols_from_requires = symbols_from_requires + .iter() + .map(|(symbol, loc_ann)| { + let ann = canonicalize_annotation( + &mut env, + &mut scope, + &loc_ann.value, + loc_ann.region, + var_store, + &output.abilities_in_scope, + ); + + ann.add_to( + &mut output.aliases, + &mut output.references, + &mut output.introduced_variables, + ); + + ( + *symbol, + Loc { + value: ann.typ, + region: loc_ann.region, + }, + ) + }) + .collect(); + if let GeneratedInfo::Hosted { effect_symbol, generated_functions, @@ -545,6 +576,7 @@ pub fn canonicalize_module_defs<'a>( referenced_types, exposed_imports: can_exposed_imports, problems: env.problems, + symbols_from_requires, lookups, }; diff --git a/compiler/constrain/src/module.rs b/compiler/constrain/src/module.rs index f0761ea965..c193405bea 100644 --- a/compiler/constrain/src/module.rs +++ b/compiler/constrain/src/module.rs @@ -94,12 +94,14 @@ pub enum ExposedModuleTypes { pub fn constrain_module( constraints: &mut Constraints, + symbols_from_requires: Vec<(Symbol, Loc)>, abilities_store: &AbilitiesStore, declarations: &[Declaration], home: ModuleId, ) -> Constraint { let constraint = crate::expr::constrain_decls(constraints, home, declarations); - + let constraint = + constrain_symbols_from_requires(constraints, symbols_from_requires, home, constraint); let constraint = frontload_ability_constraints(constraints, abilities_store, constraint); // The module constraint should always save the environment at the end. @@ -108,6 +110,38 @@ pub fn constrain_module( constraint } +fn constrain_symbols_from_requires( + constraints: &mut Constraints, + symbols_from_requires: Vec<(Symbol, Loc)>, + home: ModuleId, + constraint: Constraint, +) -> Constraint { + // TODO thread through rigid_vars and flex_vars + let rigid_vars = std::iter::empty(); + let flex_vars = std::iter::empty(); + + symbols_from_requires + .into_iter() + .fold(constraint, |constraint, (symbol, loc_type)| { + if symbol.module_id() == home { + constraints.let_constraint( + rigid_vars.clone(), + flex_vars.clone(), + std::iter::once((symbol, loc_type)), + Constraint::True, + constraint, + ) + } else { + constraints.lookup( + symbol, + // TODO give it a real expectation, so errors can be helpful + Expected::NoExpectation(loc_type.value), + loc_type.region, + ) + } + }) +} + pub fn frontload_ability_constraints( constraints: &mut Constraints, abilities_store: &AbilitiesStore, diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index fef510bdad..f0a82ef6e8 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -30,7 +30,7 @@ use roc_mono::ir::{ UpdateModeIds, }; use roc_mono::layout::{Layout, LayoutCache, LayoutProblem}; -use roc_parse::ast::{self, ExtractSpaces, Spaced, StrLiteral}; +use roc_parse::ast::{self, ExtractSpaces, Spaced, StrLiteral, TypeAnnotation}; use roc_parse::header::{ExposedName, ImportsEntry, PackageEntry, PlatformHeader, To, TypedIdent}; use roc_parse::header::{HeaderFor, ModuleNameEnum, PackageName}; use roc_parse::ident::UppercaseIdent; @@ -512,8 +512,9 @@ struct ModuleHeader<'a> { exposes: Vec, exposed_imports: MutMap, parse_state: roc_parse::state::State<'a>, - module_timing: ModuleTiming, header_for: HeaderFor<'a>, + symbols_from_requires: Vec<(Symbol, Loc>)>, + module_timing: ModuleTiming, } #[derive(Debug)] @@ -603,6 +604,7 @@ struct ParsedModule<'a> { exposed_imports: MutMap, parsed_defs: &'a [Loc>], module_name: ModuleNameEnum<'a>, + symbols_from_requires: Vec<(Symbol, Loc>)>, header_for: HeaderFor<'a>, } @@ -3228,8 +3230,9 @@ fn send_header<'a>( exposes: exposed, parse_state, exposed_imports: scope, - module_timing, + symbols_from_requires: Vec::new(), header_for: extra, + module_timing, }), ) } @@ -3269,6 +3272,7 @@ fn send_header_two<'a>( } = info; let declared_name: ModuleName = "".into(); + let mut symbols_from_requires = Vec::with_capacity(requires.len()); let mut imported: Vec<(QualifiedModuleName, Vec, Region)> = Vec::with_capacity(imports.len()); @@ -3372,6 +3376,7 @@ fn send_header_two<'a>( debug_assert!(!scope.contains_key(&ident.clone())); scope.insert(ident, (symbol, entry.ident.region)); + symbols_from_requires.push((symbol, entry.ann)); } for entry in requires_types { @@ -3471,6 +3476,7 @@ fn send_header_two<'a>( parse_state, exposed_imports: scope, module_timing, + symbols_from_requires, header_for: extra, }), ) @@ -3814,6 +3820,7 @@ fn canonicalize_and_constrain<'a>( exposed_imports, imported_modules, mut module_timing, + symbols_from_requires, .. } = parsed; @@ -3831,6 +3838,7 @@ fn canonicalize_and_constrain<'a>( aliases, exposed_imports, &exposed_symbols, + &symbols_from_requires, &mut var_store, ); @@ -3875,6 +3883,7 @@ fn canonicalize_and_constrain<'a>( } else { constrain_module( &mut constraints, + module_output.symbols_from_requires, &module_output.scope.abilities_store, &module_output.declarations, module_id, @@ -3986,6 +3995,7 @@ fn parse<'a>(arena: &'a Bump, header: ModuleHeader<'a>) -> Result, Loadi exposed_imports, module_path, header_for, + symbols_from_requires, .. } = header; @@ -4000,6 +4010,7 @@ fn parse<'a>(arena: &'a Bump, header: ModuleHeader<'a>) -> Result, Loadi exposed_ident_ids, exposed_imports, parsed_defs, + symbols_from_requires, header_for, }; From 8ac1dfac1aaa71f10e9dcd01bb6be94a99a9d5ee Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 5 May 2022 16:19:34 -0400 Subject: [PATCH 830/846] Revert "Thread through symbols_from_requires" This reverts commit 1421aebcd38af5a5294d88eb0245f303091344be. --- compiler/can/src/def.rs | 6 +---- compiler/can/src/expr.rs | 1 - compiler/can/src/module.rs | 40 +++--------------------------- compiler/constrain/src/module.rs | 36 +-------------------------- compiler/load_internal/src/file.rs | 17 +++---------- 5 files changed, 9 insertions(+), 91 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index cd7d5e2981..d21462e08b 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -54,7 +54,7 @@ pub struct Annotation { pub(crate) struct CanDefs { defs: Vec>, def_ordering: DefOrdering, - pub(crate) abilities_in_scope: Vec, + aliases: VecMap, } @@ -523,7 +523,6 @@ pub(crate) fn canonicalize_defs<'a>( CanDefs { defs, def_ordering, - abilities_in_scope, // The result needs a thread-safe `SendMap` aliases, }, @@ -767,11 +766,8 @@ pub(crate) fn sort_can_defs( mut defs, def_ordering, aliases, - abilities_in_scope, } = defs; - output.abilities_in_scope = abilities_in_scope; - for (symbol, alias) in aliases.into_iter() { output.aliases.insert(symbol, alias); } diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index 12748b16ec..b60a552f5c 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -30,7 +30,6 @@ pub struct Output { pub introduced_variables: IntroducedVariables, pub aliases: VecMap, pub non_closures: VecSet, - pub abilities_in_scope: Vec, } impl Output { diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index a9fecd2323..ffba784309 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -1,5 +1,4 @@ use crate::abilities::AbilitiesStore; -use crate::annotation::canonicalize_annotation; use crate::def::{canonicalize_defs, sort_can_defs, Declaration, Def}; use crate::effect_module::HostedGeneratedFunctions; use crate::env::Env; @@ -12,7 +11,7 @@ use roc_collections::{MutMap, SendMap, VecSet}; use roc_module::ident::Ident; use roc_module::ident::Lowercase; use roc_module::symbol::{IdentIds, IdentIdsByModule, ModuleId, ModuleIds, Symbol}; -use roc_parse::ast::{self, TypeAnnotation}; +use roc_parse::ast; use roc_parse::header::HeaderFor; use roc_parse::pattern::PatternType; use roc_problem::can::{Problem, RuntimeError}; @@ -50,7 +49,6 @@ pub struct ModuleOutput { pub problems: Vec, pub referenced_values: VecSet, pub referenced_types: VecSet, - pub symbols_from_requires: Vec<(Symbol, Loc)>, pub scope: Scope, } @@ -158,17 +156,16 @@ fn has_no_implementation(expr: &Expr) -> bool { // TODO trim these down #[allow(clippy::too_many_arguments)] pub fn canonicalize_module_defs<'a>( - arena: &'a Bump, + arena: &Bump, loc_defs: &'a [Loc>], header_for: &roc_parse::header::HeaderFor, home: ModuleId, - module_ids: &'a ModuleIds, + module_ids: &ModuleIds, exposed_ident_ids: IdentIds, dep_idents: &'a IdentIdsByModule, aliases: MutMap, exposed_imports: MutMap, exposed_symbols: &VecSet, - symbols_from_requires: &[(Symbol, Loc>)], var_store: &mut VarStore, ) -> Result { let mut can_exposed_imports = MutMap::default(); @@ -352,37 +349,9 @@ pub fn canonicalize_module_defs<'a>( }; match sort_can_defs(&mut env, defs, new_output) { - (Ok(mut declarations), mut output) => { + (Ok(mut declarations), output) => { use crate::def::Declaration::*; - let symbols_from_requires = symbols_from_requires - .iter() - .map(|(symbol, loc_ann)| { - let ann = canonicalize_annotation( - &mut env, - &mut scope, - &loc_ann.value, - loc_ann.region, - var_store, - &output.abilities_in_scope, - ); - - ann.add_to( - &mut output.aliases, - &mut output.references, - &mut output.introduced_variables, - ); - - ( - *symbol, - Loc { - value: ann.typ, - region: loc_ann.region, - }, - ) - }) - .collect(); - if let GeneratedInfo::Hosted { effect_symbol, generated_functions, @@ -576,7 +545,6 @@ pub fn canonicalize_module_defs<'a>( referenced_types, exposed_imports: can_exposed_imports, problems: env.problems, - symbols_from_requires, lookups, }; diff --git a/compiler/constrain/src/module.rs b/compiler/constrain/src/module.rs index c193405bea..f0761ea965 100644 --- a/compiler/constrain/src/module.rs +++ b/compiler/constrain/src/module.rs @@ -94,14 +94,12 @@ pub enum ExposedModuleTypes { pub fn constrain_module( constraints: &mut Constraints, - symbols_from_requires: Vec<(Symbol, Loc)>, abilities_store: &AbilitiesStore, declarations: &[Declaration], home: ModuleId, ) -> Constraint { let constraint = crate::expr::constrain_decls(constraints, home, declarations); - let constraint = - constrain_symbols_from_requires(constraints, symbols_from_requires, home, constraint); + let constraint = frontload_ability_constraints(constraints, abilities_store, constraint); // The module constraint should always save the environment at the end. @@ -110,38 +108,6 @@ pub fn constrain_module( constraint } -fn constrain_symbols_from_requires( - constraints: &mut Constraints, - symbols_from_requires: Vec<(Symbol, Loc)>, - home: ModuleId, - constraint: Constraint, -) -> Constraint { - // TODO thread through rigid_vars and flex_vars - let rigid_vars = std::iter::empty(); - let flex_vars = std::iter::empty(); - - symbols_from_requires - .into_iter() - .fold(constraint, |constraint, (symbol, loc_type)| { - if symbol.module_id() == home { - constraints.let_constraint( - rigid_vars.clone(), - flex_vars.clone(), - std::iter::once((symbol, loc_type)), - Constraint::True, - constraint, - ) - } else { - constraints.lookup( - symbol, - // TODO give it a real expectation, so errors can be helpful - Expected::NoExpectation(loc_type.value), - loc_type.region, - ) - } - }) -} - pub fn frontload_ability_constraints( constraints: &mut Constraints, abilities_store: &AbilitiesStore, diff --git a/compiler/load_internal/src/file.rs b/compiler/load_internal/src/file.rs index f0a82ef6e8..fef510bdad 100644 --- a/compiler/load_internal/src/file.rs +++ b/compiler/load_internal/src/file.rs @@ -30,7 +30,7 @@ use roc_mono::ir::{ UpdateModeIds, }; use roc_mono::layout::{Layout, LayoutCache, LayoutProblem}; -use roc_parse::ast::{self, ExtractSpaces, Spaced, StrLiteral, TypeAnnotation}; +use roc_parse::ast::{self, ExtractSpaces, Spaced, StrLiteral}; use roc_parse::header::{ExposedName, ImportsEntry, PackageEntry, PlatformHeader, To, TypedIdent}; use roc_parse::header::{HeaderFor, ModuleNameEnum, PackageName}; use roc_parse::ident::UppercaseIdent; @@ -512,9 +512,8 @@ struct ModuleHeader<'a> { exposes: Vec, exposed_imports: MutMap, parse_state: roc_parse::state::State<'a>, - header_for: HeaderFor<'a>, - symbols_from_requires: Vec<(Symbol, Loc>)>, module_timing: ModuleTiming, + header_for: HeaderFor<'a>, } #[derive(Debug)] @@ -604,7 +603,6 @@ struct ParsedModule<'a> { exposed_imports: MutMap, parsed_defs: &'a [Loc>], module_name: ModuleNameEnum<'a>, - symbols_from_requires: Vec<(Symbol, Loc>)>, header_for: HeaderFor<'a>, } @@ -3230,9 +3228,8 @@ fn send_header<'a>( exposes: exposed, parse_state, exposed_imports: scope, - symbols_from_requires: Vec::new(), - header_for: extra, module_timing, + header_for: extra, }), ) } @@ -3272,7 +3269,6 @@ fn send_header_two<'a>( } = info; let declared_name: ModuleName = "".into(); - let mut symbols_from_requires = Vec::with_capacity(requires.len()); let mut imported: Vec<(QualifiedModuleName, Vec, Region)> = Vec::with_capacity(imports.len()); @@ -3376,7 +3372,6 @@ fn send_header_two<'a>( debug_assert!(!scope.contains_key(&ident.clone())); scope.insert(ident, (symbol, entry.ident.region)); - symbols_from_requires.push((symbol, entry.ann)); } for entry in requires_types { @@ -3476,7 +3471,6 @@ fn send_header_two<'a>( parse_state, exposed_imports: scope, module_timing, - symbols_from_requires, header_for: extra, }), ) @@ -3820,7 +3814,6 @@ fn canonicalize_and_constrain<'a>( exposed_imports, imported_modules, mut module_timing, - symbols_from_requires, .. } = parsed; @@ -3838,7 +3831,6 @@ fn canonicalize_and_constrain<'a>( aliases, exposed_imports, &exposed_symbols, - &symbols_from_requires, &mut var_store, ); @@ -3883,7 +3875,6 @@ fn canonicalize_and_constrain<'a>( } else { constrain_module( &mut constraints, - module_output.symbols_from_requires, &module_output.scope.abilities_store, &module_output.declarations, module_id, @@ -3995,7 +3986,6 @@ fn parse<'a>(arena: &'a Bump, header: ModuleHeader<'a>) -> Result, Loadi exposed_imports, module_path, header_for, - symbols_from_requires, .. } = header; @@ -4010,7 +4000,6 @@ fn parse<'a>(arena: &'a Bump, header: ModuleHeader<'a>) -> Result, Loadi exposed_ident_ids, exposed_imports, parsed_defs, - symbols_from_requires, header_for, }; From a836570a7b2a00baf481b95cc30ccbec8de2aa1b Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 5 May 2022 17:36:25 -0400 Subject: [PATCH 831/846] Remove --link option from CLI --- cli/src/lib.rs | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index b9d5e60f6a..1f8169e641 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -40,7 +40,6 @@ pub const FLAG_LIB: &str = "lib"; pub const FLAG_NO_LINK: &str = "no-link"; pub const FLAG_TARGET: &str = "target"; pub const FLAG_TIME: &str = "time"; -pub const FLAG_LINK: &str = "roc-linker"; pub const FLAG_LINKER: &str = "linker"; pub const FLAG_PRECOMPILED: &str = "precompiled-host"; pub const FLAG_VALGRIND: &str = "valgrind"; @@ -113,12 +112,6 @@ pub fn build_app<'a>() -> Command<'a> { .help("Prints detailed compilation time information.") .required(false), ) - .arg( - Arg::new(FLAG_LINK) - .long(FLAG_LINK) - .help("Deprecated in favor of --linker") - .required(false), - ) .arg( Arg::new(FLAG_LINKER) .long(FLAG_LINKER) @@ -226,12 +219,6 @@ pub fn build_app<'a>() -> Command<'a> { .help("Prints detailed compilation time information.") .required(false), ) - .arg( - Arg::new(FLAG_LINK) - .long(FLAG_LINK) - .help("Deprecated in favor of --linker") - .required(false), - ) .arg( Arg::new(FLAG_LINKER) .long(FLAG_LINKER) @@ -331,12 +318,6 @@ pub fn build(matches: &ArgMatches, config: BuildConfig) -> io::Result { (false, false) => LinkType::Executable, }; - // TODO remove FLAG_LINK from the code base anytime after the end of May 2022 - if matches.is_present(FLAG_LINK) { - eprintln!("ERROR: The --roc-linker flag has been deprecated because the roc linker is now used automatically where it's supported. (Currently that's only x64 Linux.) No need to use --roc-linker anymore, but you can use the --linker flag to switch linkers."); - process::exit(1); - } - // Use surgical linking when supported, or when explicitly requested with --linker surgical let surgically_link = if matches.is_present(FLAG_LINKER) { matches.value_of(FLAG_LINKER) == Some("surgical") From 9dc05ac6d71e41be0daf5755796123f1fecf98a0 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 5 May 2022 17:36:36 -0400 Subject: [PATCH 832/846] Drop unused variable --- reporting/tests/helpers/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/reporting/tests/helpers/mod.rs b/reporting/tests/helpers/mod.rs index de5530ae70..9729112a75 100644 --- a/reporting/tests/helpers/mod.rs +++ b/reporting/tests/helpers/mod.rs @@ -35,7 +35,6 @@ pub fn infer_expr( abilities_store: &mut AbilitiesStore, expr_var: Variable, ) -> (Content, Subs) { - let env = solve::Env::default(); let (solved, _) = solve::run( constraints, problems, From da3490be8bfa1a0f5ddc7c68a8582baf54361523 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 5 May 2022 17:47:01 -0400 Subject: [PATCH 833/846] Make sure CLI subcommands support the right flags --- cli/src/lib.rs | 208 +++++++++++++++++++----------------------------- cli/src/main.rs | 41 ++++++++-- 2 files changed, 117 insertions(+), 132 deletions(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 1f8169e641..11469c82aa 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -52,34 +52,63 @@ pub const ARGS_FOR_APP: &str = "ARGS_FOR_APP"; const VERSION: &str = include_str!("../../version.txt"); pub fn build_app<'a>() -> Command<'a> { + let flag_optimize = Arg::new(FLAG_OPTIMIZE) + .long(FLAG_OPTIMIZE) + .help("Optimize the compiled program to run faster. (Optimization takes time to complete.)") + .requires(ROC_FILE) + .required(false); + + let flag_opt_size = Arg::new(FLAG_OPT_SIZE) + .long(FLAG_OPT_SIZE) + .help("Optimize the compiled program to have a small binary size. (Optimization takes time to complete.)") + .required(false); + + let flag_dev = Arg::new(FLAG_DEV) + .long(FLAG_DEV) + .help("Make compilation finish as soon as possible, at the expense of runtime performance.") + .required(false); + + let flag_debug = Arg::new(FLAG_DEBUG) + .long(FLAG_DEBUG) + .help("Store LLVM debug information in the generated program.") + .requires(ROC_FILE) + .required(false); + + let flag_valgrind = Arg::new(FLAG_VALGRIND) + .long(FLAG_VALGRIND) + .help("Some assembly instructions are not supported by valgrind, this flag prevents those from being output when building the host.") + .required(false); + + let flag_time = Arg::new(FLAG_TIME) + .long(FLAG_TIME) + .help("Prints detailed compilation time information.") + .required(false); + + let flag_linker = Arg::new(FLAG_LINKER) + .long(FLAG_LINKER) + .help("Sets which linker to use. The surgical linker is enabled by default only when building for wasm32 or x86_64 Linux, because those are the only targets it currently supports. Otherwise the legacy linker is used by default.") + .possible_values(["surgical", "legacy"]) + .required(false); + + let flag_precompiled = Arg::new(FLAG_PRECOMPILED) + .long(FLAG_PRECOMPILED) + .help("Assumes the host has been precompiled and skips recompiling the host. (Enabled by default when using `roc build` with a --target other than `--target host`)") + .possible_values(["true", "false"]) + .required(false); + let app = Command::new("roc") .version(concatcp!(VERSION, "\n")) .about("Runs the given .roc file, if there are no compilation errors.\nUse one of the SUBCOMMANDS below to do something else!") .subcommand(Command::new(CMD_BUILD) .about("Build a binary from the given .roc file, but don't run it") - .arg( - Arg::new(ROC_FILE) - .help("The .roc file to build") - .required(true), - ) - .arg( - Arg::new(FLAG_OPTIMIZE) - .long(FLAG_OPTIMIZE) - .help("Optimize your compiled Roc program to run faster. (Optimization takes time to complete.)") - .required(false), - ) - .arg( - Arg::new(FLAG_OPT_SIZE) - .long(FLAG_OPT_SIZE) - .help("Optimize your compiled Roc program to have a small binary size. (Optimization takes time to complete.)") - .required(false), - ) - .arg( - Arg::new(FLAG_DEV) - .long(FLAG_DEV) - .help("Make compilation as fast as possible. (Runtime performance may suffer)") - .required(false), - ) + .arg(flag_optimize.clone()) + .arg(flag_opt_size.clone()) + .arg(flag_dev.clone()) + .arg(flag_debug.clone()) + .arg(flag_time.clone()) + .arg(flag_linker.clone()) + .arg(flag_precompiled.clone()) + .arg(flag_valgrind.clone()) .arg( Arg::new(FLAG_TARGET) .long(FLAG_TARGET) @@ -101,36 +130,9 @@ pub fn build_app<'a>() -> Command<'a> { .required(false), ) .arg( - Arg::new(FLAG_DEBUG) - .long(FLAG_DEBUG) - .help("Store LLVM debug information in the generated program") - .required(false), - ) - .arg( - Arg::new(FLAG_TIME) - .long(FLAG_TIME) - .help("Prints detailed compilation time information.") - .required(false), - ) - .arg( - Arg::new(FLAG_LINKER) - .long(FLAG_LINKER) - .help("Sets which linker to use. The surgical linker is enabeld by default only when building for wasm32 or x86_64 Linux, because those are the only targets it currently supports. Otherwise the legacy linker is used by default.") - .possible_values(["surgical", "legacy"]) - .required(false), - ) - .arg( - Arg::new(FLAG_PRECOMPILED) - .long(FLAG_PRECOMPILED) - .help("Assumes the host has been precompiled and skips recompiling the host. (Enabled by default when using a --target other than `--target host`)") - .possible_values(["true", "false"]) - .required(false), - ) - .arg( - Arg::new(FLAG_VALGRIND) - .long(FLAG_VALGRIND) - .help("Some assembly instructions are not supported by valgrind, this flag prevents those from being output when building the host.") - .required(false), + Arg::new(ROC_FILE) + .help("The .roc file to build") + .required(true), ) ) .subcommand(Command::new(CMD_REPL) @@ -138,6 +140,14 @@ pub fn build_app<'a>() -> Command<'a> { ) .subcommand(Command::new(CMD_RUN) .about("Run a .roc file even if it has build errors") + .arg(flag_optimize.clone()) + .arg(flag_opt_size.clone()) + .arg(flag_dev.clone()) + .arg(flag_debug.clone()) + .arg(flag_time.clone()) + .arg(flag_linker.clone()) + .arg(flag_precompiled.clone()) + .arg(flag_valgrind.clone()) .arg( Arg::new(ROC_FILE) .help("The .roc file of an app to run") @@ -163,12 +173,7 @@ pub fn build_app<'a>() -> Command<'a> { .about(concatcp!("Print the Roc compiler’s version, which is currently ", VERSION))) .subcommand(Command::new(CMD_CHECK) .about("Check the code for problems, but doesn’t build or run it") - .arg( - Arg::new(FLAG_TIME) - .long(FLAG_TIME) - .help("Prints detailed compilation time information.") - .required(false), - ) + .arg(flag_time.clone()) .arg( Arg::new(ROC_FILE) .help("The .roc file of an app to check") @@ -187,52 +192,14 @@ pub fn build_app<'a>() -> Command<'a> { ) ) .trailing_var_arg(true) - .arg( - Arg::new(FLAG_OPTIMIZE) - .long(FLAG_OPTIMIZE) - .help("Optimize the compiled program to run faster. (Optimization takes time to complete.)") - .requires(ROC_FILE) - .required(false), - ) - .arg( - Arg::new(FLAG_OPT_SIZE) - .long(FLAG_OPT_SIZE) - .help("Optimize the compiled program to have a small binary size. (Optimization takes time to complete.)") - .required(false), - ) - .arg( - Arg::new(FLAG_DEV) - .long(FLAG_DEV) - .help("Make compilation finish as soon as possible, at the expense of runtime performance.") - .required(false), - ) - .arg( - Arg::new(FLAG_DEBUG) - .long(FLAG_DEBUG) - .help("Store LLVM debug information in the generated program.") - .requires(ROC_FILE) - .required(false), - ) - .arg( - Arg::new(FLAG_TIME) - .long(FLAG_TIME) - .help("Prints detailed compilation time information.") - .required(false), - ) - .arg( - Arg::new(FLAG_LINKER) - .long(FLAG_LINKER) - .help("Sets which linker to use. The surgical linker is enabeld by default only when building for wasm32 or x86_64 Linux, because those are the only targets it currently supports. Otherwise the legacy linker is used by default.") - .possible_values(["surgical", "legacy"]) - .required(false), - ) - .arg( - Arg::new(FLAG_PRECOMPILED) - .long(FLAG_PRECOMPILED) - .help("Assumes the host has been precompiled and skips recompiling the host. (Enabled by default when using `roc build` with a --target other than `--target host`)") - .possible_values(["true", "false"]) - .required(false), - ) + .arg(flag_optimize) + .arg(flag_opt_size) + .arg(flag_dev) + .arg(flag_debug) + .arg(flag_time) + .arg(flag_linker) + .arg(flag_precompiled) + .arg(flag_valgrind) .arg( Arg::new(ROC_FILE) .help("The .roc file of an app to build and run") @@ -278,18 +245,15 @@ pub enum FormatMode { CheckOnly, } -pub fn build(matches: &ArgMatches, config: BuildConfig) -> io::Result { +pub fn build( + matches: &ArgMatches, + config: BuildConfig, + triple: Triple, + link_type: LinkType, +) -> io::Result { use build::build_file; - use std::str::FromStr; use BuildConfig::*; - let target = match matches.value_of(FLAG_TARGET) { - Some(name) => Target::from_str(name).unwrap(), - None => Target::default(), - }; - - let triple = target.to_triple(); - let arena = Bump::new(); let filename = matches.value_of(ROC_FILE).unwrap(); @@ -308,16 +272,6 @@ pub fn build(matches: &ArgMatches, config: BuildConfig) -> io::Result { let emit_debug_info = matches.is_present(FLAG_DEBUG); let emit_timings = matches.is_present(FLAG_TIME); - let link_type = match ( - matches.is_present(FLAG_LIB), - matches.is_present(FLAG_NO_LINK), - ) { - (true, false) => LinkType::Dylib, - (true, true) => user_error!("build can only be one of `--lib` or `--no-link`"), - (false, true) => LinkType::None, - (false, false) => LinkType::Executable, - }; - // Use surgical linking when supported, or when explicitly requested with --linker surgical let surgically_link = if matches.is_present(FLAG_LINKER) { matches.value_of(FLAG_LINKER) == Some("surgical") @@ -330,7 +284,7 @@ pub fn build(matches: &ArgMatches, config: BuildConfig) -> io::Result { } else { // When compiling for a different target, default to assuming a precompiled host. // Otherwise compilation would most likely fail! - target != Target::System + triple != Triple::host() }; let path = Path::new(filename); @@ -639,7 +593,7 @@ fn run_with_wasmer(_wasm_path: &std::path::Path, _args: &[String]) { } #[derive(Debug, Copy, Clone, PartialEq, Eq)] -enum Target { +pub enum Target { System, Linux32, Linux64, @@ -672,7 +626,7 @@ impl Target { Target::Wasm32.as_str(), ]; - fn to_triple(self) -> Triple { + pub fn to_triple(self) -> Triple { use Target::*; match self { diff --git a/cli/src/main.rs b/cli/src/main.rs index b38445980b..3c2c413f0b 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -1,13 +1,16 @@ +use roc_build::link::LinkType; use roc_cli::build::check_file; use roc_cli::{ - build_app, docs, format, BuildConfig, FormatMode, CMD_BUILD, CMD_CHECK, CMD_DOCS, CMD_EDIT, - CMD_FORMAT, CMD_REPL, CMD_RUN, CMD_VERSION, DIRECTORY_OR_FILES, FLAG_CHECK, FLAG_TIME, - ROC_FILE, + build_app, docs, format, BuildConfig, FormatMode, Target, CMD_BUILD, CMD_CHECK, CMD_DOCS, + CMD_EDIT, CMD_FORMAT, CMD_REPL, CMD_RUN, CMD_VERSION, DIRECTORY_OR_FILES, FLAG_CHECK, FLAG_LIB, + FLAG_NO_LINK, FLAG_TARGET, FLAG_TIME, ROC_FILE, }; +use roc_error_macros::user_error; use roc_load::LoadingProblem; use std::fs::{self, FileType}; use std::io; use std::path::{Path, PathBuf}; +use target_lexicon::Triple; #[macro_use] extern crate const_format; @@ -31,6 +34,8 @@ fn main() -> io::Result<()> { build( &matches, BuildConfig::BuildAndRunIfNoErrors { roc_file_arg_index }, + Triple::host(), + LinkType::Executable, ) } @@ -46,7 +51,12 @@ fn main() -> io::Result<()> { Some(arg_index) => { let roc_file_arg_index = arg_index + 1; // Not sure why this +1 is necessary, but it is! - build(matches, BuildConfig::BuildAndRun { roc_file_arg_index }) + build( + matches, + BuildConfig::BuildAndRun { roc_file_arg_index }, + Triple::host(), + LinkType::Executable, + ) } None => { @@ -56,7 +66,28 @@ fn main() -> io::Result<()> { } } } - Some((CMD_BUILD, matches)) => Ok(build(matches, BuildConfig::BuildOnly)?), + Some((CMD_BUILD, matches)) => { + use std::str::FromStr; + + let target = match matches.value_of(FLAG_TARGET) { + Some(name) => Target::from_str(name).unwrap(), + None => Target::default(), + }; + + let triple = target.to_triple(); + + let link_type = match ( + matches.is_present(FLAG_LIB), + matches.is_present(FLAG_NO_LINK), + ) { + (true, false) => LinkType::Dylib, + (true, true) => user_error!("build can only be one of `--lib` or `--no-link`"), + (false, true) => LinkType::None, + (false, false) => LinkType::Executable, + }; + + Ok(build(matches, BuildConfig::BuildOnly, triple, link_type)?) + } Some((CMD_CHECK, matches)) => { let arena = bumpalo::Bump::new(); From d337a80ff5b2646c0cf44923bc4ddbaacc8eddb5 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 5 May 2022 18:00:47 -0400 Subject: [PATCH 834/846] Use matches.value_of_t --- cli/src/lib.rs | 8 ++++---- cli/src/main.rs | 16 +++++++--------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 11469c82aa..dbeab8b027 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -669,15 +669,15 @@ impl std::fmt::Display for Target { } impl std::str::FromStr for Target { - type Err = (); + type Err = String; - fn from_str(s: &str) -> Result { - match s { + fn from_str(string: &str) -> Result { + match string { "system" => Ok(Target::System), "linux32" => Ok(Target::Linux32), "linux64" => Ok(Target::Linux64), "wasm32" => Ok(Target::Wasm32), - _ => Err(()), + _ => Err(format!("Roc does not know how to compile to {}", string)), } } } diff --git a/cli/src/main.rs b/cli/src/main.rs index 3c2c413f0b..0a21c66ed5 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -67,14 +67,7 @@ fn main() -> io::Result<()> { } } Some((CMD_BUILD, matches)) => { - use std::str::FromStr; - - let target = match matches.value_of(FLAG_TARGET) { - Some(name) => Target::from_str(name).unwrap(), - None => Target::default(), - }; - - let triple = target.to_triple(); + let target: Target = matches.value_of_t(FLAG_TARGET).unwrap_or_default(); let link_type = match ( matches.is_present(FLAG_LIB), @@ -86,7 +79,12 @@ fn main() -> io::Result<()> { (false, false) => LinkType::Executable, }; - Ok(build(matches, BuildConfig::BuildOnly, triple, link_type)?) + Ok(build( + matches, + BuildConfig::BuildOnly, + target.to_triple(), + link_type, + )?) } Some((CMD_CHECK, matches)) => { let arena = bumpalo::Bump::new(); From a0ec98f36a59cae2a639e58c5510e8ca17edf1d3 Mon Sep 17 00:00:00 2001 From: Nuno Ferreira Date: Fri, 6 May 2022 00:16:13 +0200 Subject: [PATCH 835/846] Moved over all Str functions that are still the same There's a few which seem to have been removed but some docs remained. I read through them and thought they didn't make sense to migrate as the types changed. Please let me know if this is correct. Deleted old Str.roc file --- compiler/builtins/docs/Str.roc | 225 --------------------------------- compiler/builtins/roc/Str.roc | 90 ------------- 2 files changed, 315 deletions(-) delete mode 100644 compiler/builtins/roc/Str.roc diff --git a/compiler/builtins/docs/Str.roc b/compiler/builtins/docs/Str.roc index 0bfa3ca2af..8cad7105b6 100644 --- a/compiler/builtins/docs/Str.roc +++ b/compiler/builtins/docs/Str.roc @@ -18,169 +18,21 @@ interface Str ] imports [] -## # Types -## -## Dealing with text is a deep topic, so by design, Roc's `Str` module sticks -## to the basics. -## -## _For more advanced use cases like working with raw [code points](https://unicode.org/glossary/#code_point), -## see the [roc/unicode](roc/unicode) package. For locale-specific text -## functions (including uppercasing strings, as capitalization rules vary by locale; -## in English, `"i"` capitalizes to `"I"`, but [in Turkish](https://en.wikipedia.org/wiki/Dotted_and_dotless_I#In_computing), -## the same `"i"` capitalizes to `"İ"` - as well as sorting strings, which also varies -## by locale; `"ö"` is sorted differently in German and Swedish) see the [roc/locale](roc/locale) package._ -## -## ### Unicode -## -## Unicode can represent text values which span multiple languages, symbols, and emoji. -## Here are some valid Roc strings: -## -## "Roc!" -## "鹏" -## "🕊" -## -## Every Unicode string is a sequence of [extended grapheme clusters](http://www.unicode.org/glossary/#extended_grapheme_cluster). -## An extended grapheme cluster represents what a person reading a string might -## call a "character" - like "A" or "ö" or "👩‍👩‍👦‍👦". -## Because the term "character" means different things in different areas of -## programming, and "extended grapheme cluster" is a mouthful, in Roc we use the -## term "grapheme" as a shorthand for the more precise "extended grapheme cluster." -## -## You can get the number of graphemes in a string by calling [Str.countGraphemes] on it: -## -## Str.countGraphemes "Roc!" -## Str.countGraphemes "折り紙" -## Str.countGraphemes "🕊" -## -## > The `countGraphemes` function walks through the entire string to get its answer, -## > so if you want to check whether a string is empty, you'll get much better performance -## > by calling `Str.isEmpty myStr` instead of `Str.countGraphemes myStr == 0`. -## -## ### Escape sequences -## -## If you put a `\` in a Roc string literal, it begins an *escape sequence*. -## An escape sequence is a convenient way to insert certain strings into other strings. -## For example, suppose you write this Roc string: -## -## "I took the one less traveled by,\nAnd that has made all the difference." -## -## The `"\n"` in the middle will insert a line break into this string. There are -## other ways of getting a line break in there, but `"\n"` is the most common. -## -## Another way you could insert a newlines is by writing `\u{0x0A}` instead of `\n`. -## That would result in the same string, because the `\u` escape sequence inserts -## [Unicode code points](https://unicode.org/glossary/#code_point) directly into -## the string. The Unicode code point 10 is a newline, and 10 is `0A` in hexadecimal. -## `0x0A` is a Roc hexadecimal literal, and `\u` escape sequences are always -## followed by a hexadecimal literal inside `{` and `}` like this. -## -## As another example, `"R\u{0x6F}c"` is the same string as `"Roc"`, because -## `"\u{0x6F}"` corresponds to the Unicode code point for lowercase `o`. If you -## want to [spice things up a bit](https://en.wikipedia.org/wiki/Metal_umlaut), -## you can write `"R\u{0xF6}c"` as an alternative way to get the string `"Röc"\. -## -## Roc strings also support these escape sequences: -## -## * `\\` - an actual backslash (writing a single `\` always begins an escape sequence!) -## * `\"` - an actual quotation mark (writing a `"` without a `\` ends the string) -## * `\r` - [carriage return](https://en.wikipedia.org/wiki/Carriage_Return) -## * `\t` - [horizontal tab](https://en.wikipedia.org/wiki/Tab_key#Tab_characters) -## * `\v` - [vertical tab](https://en.wikipedia.org/wiki/Tab_key#Tab_characters) -## -## You can also use escape sequences to insert named strings into other strings, like so: -## -## name = "Lee" -## city = "Roctown" -## -## greeting = "Hello there, \(name)! Welcome to \(city)." -## -## Here, `greeting` will become the string `"Hello there, Lee! Welcome to Roctown."`. -## This is known as [string interpolation](https://en.wikipedia.org/wiki/String_interpolation), -## and you can use it as many times as you like inside a string. The name -## between the parentheses must refer to a `Str` value that is currently in -## scope, and it must be a name - it can't be an arbitrary expression like a function call. -## -## ### Encoding -## -## Roc strings are not coupled to any particular -## [encoding](https://en.wikipedia.org/wiki/Character_encoding). As it happens, -## they are currently encoded in UTF-8, but this module is intentionally designed -## not to rely on that implementation detail so that a future release of Roc can -## potentially change it without breaking existing Roc applications. (UTF-8 -## seems pretty great today, but so did UTF-16 at an earlier point in history.) -## -## This module has functions to can convert a [Str] to a [List] of raw [code unit](https://unicode.org/glossary/#code_unit) -## integers (not to be confused with the [code points](https://unicode.org/glossary/#code_point) -## mentioned earlier) in a particular encoding. If you need encoding-specific functions, -## you should take a look at the [roc/unicode](roc/unicode) package. -## It has many more tools than this module does! - -## A [Unicode](https://unicode.org) text value. -Str := [ Str ] - -## Convert - -## Convert a [Float] to a decimal string, rounding off to the given number of decimal places. -## -## If you want to keep all the digits, use [Str.num] instead. decimal : Float *, Nat -> Str -## Convert a [Num] to a string. num : Float *, Nat -> Str -## Split a string around a separator. -## -## >>> Str.split "1,2,3" "," -## -## Passing `""` for the separator is not useful; it returns the original string -## wrapped in a list. -## -## >>> Str.split "1,2,3" "" -## -## To split a string into its individual graphemes, use `Str.graphemes` split : Str, Str -> List Str -## Split a string around newlines. -## -## On strings that use `"\n"` for their line endings, this gives the same answer -## as passing `"\n"` to [Str.split]. However, on strings that use `"\n\r"` (such -## as [in Windows files](https://en.wikipedia.org/wiki/Newline#History)), this -## will consume the entire `"\n\r"` instead of just the `"\n"`. -## -## >>> Str.lines "Hello, World!\nNice to meet you!" -## -## >>> Str.lines "Hello, World!\n\rNice to meet you!" -## -## To split a string using a custom separator, use [Str.split]. For more advanced -## string splitting, use a #Parser. lines : Str, Str -> List Str ## Check -## Returns `True` if the string is empty, and `False` otherwise. -## -## >>> Str.isEmpty "hi!" -## -## >>> Str.isEmpty "" isEmpty : Str -> Bool startsWith : Str, Str -> Bool -## If the string begins with a [Unicode code point](http://www.unicode.org/glossary/#code_point) -## equal to the given [U32], return `True`. Otherwise return `False`. -## -## If the given [Str] is empty, or if the given [U32] is not a valid -## code point, this will return `False`. -## -## **Performance Note:** This runs slightly faster than [Str.startsWith], so -## if you want to check whether a string begins with something that's representable -## in a single code point, you can use (for example) `Str.startsWithCodePt '鹏'` -## instead of `Str.startsWithCodePt "鹏"`. ('鹏' evaluates to the [U32] -## value `40527`.) This will not work for graphemes which take up multiple code -## points, however; `Str.startsWithCodePt '👩‍👩‍👦‍👦'` would be a compiler error -## because 👩‍👩‍👦‍👦 takes up multiple code points and cannot be represented as a -## single [U32]. You'd need to use `Str.startsWithCodePt "🕊"` instead. startsWithCodePt : Str, U32 -> Bool endsWith : Str, Str -> Bool @@ -193,71 +45,22 @@ allGraphemes : Str, (Str -> Bool) -> Bool ## Combine -## Combine a list of strings into a single string. -## -## >>> Str.join [ "a", "bc", "def" ] join : List Str -> Str -## Combine a list of strings into a single string, with a separator -## string in between each. -## -## >>> Str.joinWith [ "one", "two", "three" ] ", " joinWith : List Str, Str -> Str -## Add to the start of a string until it has at least the given number of -## graphemes. -## -## >>> Str.padGraphemesStart "0" 5 "36" -## -## >>> Str.padGraphemesStart "0" 1 "36" -## -## >>> Str.padGraphemesStart "0" 5 "12345" -## -## >>> Str.padGraphemesStart "✈️"" 5 "👩‍👩‍👦‍👦👩‍👩‍👦‍👦👩‍👩‍👦‍👦" padGraphemesStart : Str, Nat, Str -> Str -## Add to the end of a string until it has at least the given number of -## graphemes. -## -## >>> Str.padGraphemesStart "0" 5 "36" -## -## >>> Str.padGraphemesStart "0" 1 "36" -## -## >>> Str.padGraphemesStart "0" 5 "12345" -## -## >>> Str.padGraphemesStart "✈️"" 5 "👩‍👩‍👦‍👦👩‍👩‍👦‍👦👩‍👩‍👦‍👦" padGraphemesEnd : Str, Nat, Str -> Str ## Graphemes -## Split a string into its individual graphemes. -## -## >>> Str.graphemes "1,2,3" -## -## >>> Str.graphemes "👍👍👍" -## graphemes : Str -> List Str -## Count the number of [extended grapheme clusters](http://www.unicode.org/glossary/#extended_grapheme_cluster) -## in the string. -## -## Str.countGraphemes "Roc!" # 4 -## Str.countGraphemes "七巧板" # 3 -## Str.countGraphemes "🕊" # 1 countGraphemes : Str -> Nat -## Reverse the order of the string's individual graphemes. -## -## >>> Str.reverseGraphemes "1-2-3" -## -## >>> Str.reverseGraphemes "🐦✈️"👩‍👩‍👦‍👦" -## -## >>> Str.reversegraphemes "Crème Brûlée" reverseGraphemes : Str -> Str -## Returns `True` if the two strings are equal when ignoring case. -## -## >>> Str.caseInsensitiveEq "hi" "Hi" isCaseInsensitiveEq : Str, Str -> Bool isCaseInsensitiveNeq : Str, Str -> Bool @@ -334,39 +137,14 @@ isAllUppercase : Str -> Bool ## >>> Str.isAllLowercase "" isAllLowercase : Str -> Bool -## Return the string with any blank spaces removed from both the beginning -## as well as the end. trim : Str -> Str -## If the given [U32] is a valid [Unicode Scalar Value](http://www.unicode.org/glossary/#unicode_scalar_value), -## return a [Str] containing only that scalar. fromScalar : U32 -> Result Str [ BadScalar ]* fromCodePts : List U32 -> Result Str [ BadCodePt U32 ]* fromUtf8 : List U8 -> Result Str [ BadUtf8 ]* -## Create a [Str] from bytes encoded as [UTF-16LE](https://en.wikipedia.org/wiki/UTF-16#Byte-order_encoding_schemes). -# fromUtf16Le : List U8 -> Result Str [ BadUtf16Le Endi ]* -# ## Create a [Str] from bytes encoded as [UTF-16BE](https://en.wikipedia.org/wiki/UTF-16#Byte-order_encoding_schemes). -# fromUtf16Be : List U8 -> Result Str [ BadUtf16Be Endi ]* -# ## Create a [Str] from bytes encoded as UTF-16 with a [Byte Order Mark](https://en.wikipedia.org/wiki/Byte_order_mark). -# fromUtf16Bom : List U8 -> Result Str [ BadUtf16 Endi, NoBom ]* - -# ## Create a [Str] from bytes encoded as [UTF-32LE](https://web.archive.org/web/20120322145307/http://mail.apps.ietf.org/ietf/charsets/msg01095.html) -# fromUtf32Le : List U8 -> Result Str [ BadUtf32Le Endi ]* - -# ## Create a [Str] from bytes encoded as [UTF-32BE](https://web.archive.org/web/20120322145307/http://mail.apps.ietf.org/ietf/charsets/msg01095.html) -# fromUtf32Be : List U8 -> Result Str [ BadUtf32Be Endi ]* - -# ## Create a [Str] from bytes encoded as UTF-32 with a [Byte Order Mark](https://en.wikipedia.org/wiki/Byte_order_mark). -# fromUtf32Bom : List U8 -> Result Str [ BadUtf32 Endi, NoBom ]* - -# ## Convert from UTF-8, substituting the replacement character ("�") for any -# ## invalid sequences encountered. -# fromUtf8Sub : List U8 -> Str -# fromUtf16Sub : List U8, Endi -> Str -# fromUtf16BomSub : List U8 -> Result Str [ NoBom ]* ## Return a [List] of the string's [U8] UTF-8 [code units](https://unicode.org/glossary/#code_unit). ## (To split the string into a [List] of smaller [Str] values instead of [U8] values, @@ -406,9 +184,6 @@ parseUtf8Grapheme : List U8 -> Result { grapheme : Str, bytesParsed: Nat } [ Inv ## empty or began with an invalid code point, return an `Err`. parseUtf8CodePt : List U8 -> Result { codePt : U32, bytesParsed: Nat } [ InvalidCodePt ]* -## If the string represents a valid [U8] number, return that number. -## -## For more advanced options, see [parseU8]. toU8 : Str -> Result U8 [ InvalidU8 ]* toI8 : Str -> Result I8 [ InvalidI8 ]* toU16 : Str -> Result U16 [ InvalidU16 ]* diff --git a/compiler/builtins/roc/Str.roc b/compiler/builtins/roc/Str.roc deleted file mode 100644 index fae59869c1..0000000000 --- a/compiler/builtins/roc/Str.roc +++ /dev/null @@ -1,90 +0,0 @@ -interface Str - exposes - [ - concat, - Utf8Problem, - Utf8ByteProblem, - isEmpty, - joinWith, - split, - repeat, - countGraphemes, - startsWithCodePt, - toUtf8, - fromUtf8, - fromUtf8Range, - startsWith, - endsWith, - trim, - trimLeft, - trimRight, - - toDec, - toF64, - toF32, - toNat, - toU128, - toI128, - toU64, - toI64, - toU32, - toI32, - toU16, - toI16, - toU8, - toI8, - ] - imports [ Bool.{ Bool }, Result.{ Result } ] - - - -Utf8ByteProblem : - [ - InvalidStartByte, - UnexpectedEndOfSequence, - ExpectedContinuation, - OverlongEncoding, - CodepointTooLarge, - EncodesSurrogateHalf, - ] - -Utf8Problem : { byteIndex : Nat, problem : Utf8ByteProblem } - -isEmpty : Str -> Bool -concat : Str, Str -> Str - -joinWith : List Str, Str -> Str -split : Str, Str -> List Str -repeat : Str, Nat -> Str -countGraphemes : Str -> Nat -startsWithCodePt : Str, U32 -> Bool - -toUtf8 : Str -> List U8 - -# fromUtf8 : List U8 -> Result Str [ BadUtf8 Utf8Problem ]* -# fromUtf8Range : List U8 -> Result Str [ BadUtf8 Utf8Problem Nat, OutOfBounds ]* - -fromUtf8 : List U8 -> Result Str [ BadUtf8 Utf8ByteProblem Nat ]* -fromUtf8Range : List U8, { start : Nat, count : Nat } -> Result Str [ BadUtf8 Utf8ByteProblem Nat, OutOfBounds ]* - -startsWith : Str, Str -> Bool -endsWith : Str, Str -> Bool - -trim : Str -> Str -trimLeft : Str -> Str -trimRight : Str -> Str - -toDec : Str -> Result Dec [ InvalidNumStr ]* -toF64 : Str -> Result F64 [ InvalidNumStr ]* -toF32 : Str -> Result F32 [ InvalidNumStr ]* -toNat : Str -> Result Nat [ InvalidNumStr ]* -toU128 : Str -> Result U128 [ InvalidNumStr ]* -toI128 : Str -> Result I128 [ InvalidNumStr ]* -toU64 : Str -> Result U64 [ InvalidNumStr ]* -toI64 : Str -> Result I64 [ InvalidNumStr ]* -toU32 : Str -> Result U32 [ InvalidNumStr ]* -toI32 : Str -> Result I32 [ InvalidNumStr ]* -toU16 : Str -> Result U16 [ InvalidNumStr ]* -toI16 : Str -> Result I16 [ InvalidNumStr ]* -toU8 : Str -> Result U8 [ InvalidNumStr ]* -toI8 : Str -> Result I8 [ InvalidNumStr ]* From ea2a6bfb29794b31298f5ccf9def6662c712b0c0 Mon Sep 17 00:00:00 2001 From: Nuno Ferreira Date: Fri, 6 May 2022 00:22:36 +0200 Subject: [PATCH 836/846] Migrated Set --- compiler/builtins/docs/Set.roc | 59 ---------------------------------- compiler/builtins/roc/Set.roc | 7 ++++ 2 files changed, 7 insertions(+), 59 deletions(-) delete mode 100644 compiler/builtins/docs/Set.roc diff --git a/compiler/builtins/docs/Set.roc b/compiler/builtins/docs/Set.roc deleted file mode 100644 index 6f7f87e9c4..0000000000 --- a/compiler/builtins/docs/Set.roc +++ /dev/null @@ -1,59 +0,0 @@ -interface Set - exposes - [ - Set, - contains, - difference, - empty, - fromList, - insert, - intersection, - len, - remove, - single, - toList, - union, - walk - ] - imports [] - -## A Set is an unordered collection of unique elements. -Set elem := [ Set elem ] - -## An empty set. -empty : Set * - -## Check - -isEmpty : Set * -> Bool - -len : Set * -> Nat - -## Modify - -# TODO: removed `'` from signature because parser does not support it yet -# Original signature: `add : Set 'elem, 'elem -> Set 'elem` -## Make sure never to add a *NaN* to a [Set]! Because *NaN* is defined to be -## unequal to *NaN*, adding a *NaN* results in an entry that can never be -## retrieved or removed from the [Set]. -add : Set elem, elem -> Set elem - -## Drops the given element from the set. -# TODO: removed `'` from signature because parser does not support it yet -# Original signature: `drop : Set 'elem, 'elem -> Set 'elem` -drop : Set elem, elem -> Set elem - -## Transform - -## Convert each element in the set to something new, by calling a conversion -## function on each of them. Then return a new set of the converted values. -## -## >>> Set.map {: -1, 1, 3 :} Num.negate -## -## >>> Set.map {: "", "a", "bc" :} Str.isEmpty -## -## `map` functions like this are common in Roc, and they all work similarly. -## See for example [List.map], `Dict.map`, and [Result.map]. -# TODO: removed `'` from signature because parser does not support it yet -# Original signature: `map : Set 'elem, ('before -> 'after) -> Set 'after` -map : Set elem, (before -> after) -> Set after diff --git a/compiler/builtins/roc/Set.roc b/compiler/builtins/roc/Set.roc index f19d80eb2d..6545518141 100644 --- a/compiler/builtins/roc/Set.roc +++ b/compiler/builtins/roc/Set.roc @@ -16,10 +16,17 @@ interface Set ] imports [ List, Bool.{ Bool }, Dict.{ values } ] +## An empty set. empty : Set k single : k -> Set k + +## Make sure never to insert a *NaN* to a [Set]! Because *NaN* is defined to be +## unequal to *NaN*, adding a *NaN* results in an entry that can never be +## retrieved or removed from the [Set]. insert : Set k, k -> Set k len : Set k -> Nat + +## Drops the given element from the set. remove : Set k, k -> Set k contains : Set k, k -> Bool From 53f9de3180c92f686b240969c9a7aa919c13e926 Mon Sep 17 00:00:00 2001 From: Nuno Ferreira Date: Fri, 6 May 2022 00:29:59 +0200 Subject: [PATCH 837/846] Revert "Moved over all Str functions that are still the same" This reverts commit a0ec98f36a59cae2a639e58c5510e8ca17edf1d3. --- compiler/builtins/docs/Str.roc | 225 +++++++++++++++++++++++++++++++++ compiler/builtins/roc/Str.roc | 90 +++++++++++++ 2 files changed, 315 insertions(+) create mode 100644 compiler/builtins/roc/Str.roc diff --git a/compiler/builtins/docs/Str.roc b/compiler/builtins/docs/Str.roc index 8cad7105b6..0bfa3ca2af 100644 --- a/compiler/builtins/docs/Str.roc +++ b/compiler/builtins/docs/Str.roc @@ -18,21 +18,169 @@ interface Str ] imports [] +## # Types +## +## Dealing with text is a deep topic, so by design, Roc's `Str` module sticks +## to the basics. +## +## _For more advanced use cases like working with raw [code points](https://unicode.org/glossary/#code_point), +## see the [roc/unicode](roc/unicode) package. For locale-specific text +## functions (including uppercasing strings, as capitalization rules vary by locale; +## in English, `"i"` capitalizes to `"I"`, but [in Turkish](https://en.wikipedia.org/wiki/Dotted_and_dotless_I#In_computing), +## the same `"i"` capitalizes to `"İ"` - as well as sorting strings, which also varies +## by locale; `"ö"` is sorted differently in German and Swedish) see the [roc/locale](roc/locale) package._ +## +## ### Unicode +## +## Unicode can represent text values which span multiple languages, symbols, and emoji. +## Here are some valid Roc strings: +## +## "Roc!" +## "鹏" +## "🕊" +## +## Every Unicode string is a sequence of [extended grapheme clusters](http://www.unicode.org/glossary/#extended_grapheme_cluster). +## An extended grapheme cluster represents what a person reading a string might +## call a "character" - like "A" or "ö" or "👩‍👩‍👦‍👦". +## Because the term "character" means different things in different areas of +## programming, and "extended grapheme cluster" is a mouthful, in Roc we use the +## term "grapheme" as a shorthand for the more precise "extended grapheme cluster." +## +## You can get the number of graphemes in a string by calling [Str.countGraphemes] on it: +## +## Str.countGraphemes "Roc!" +## Str.countGraphemes "折り紙" +## Str.countGraphemes "🕊" +## +## > The `countGraphemes` function walks through the entire string to get its answer, +## > so if you want to check whether a string is empty, you'll get much better performance +## > by calling `Str.isEmpty myStr` instead of `Str.countGraphemes myStr == 0`. +## +## ### Escape sequences +## +## If you put a `\` in a Roc string literal, it begins an *escape sequence*. +## An escape sequence is a convenient way to insert certain strings into other strings. +## For example, suppose you write this Roc string: +## +## "I took the one less traveled by,\nAnd that has made all the difference." +## +## The `"\n"` in the middle will insert a line break into this string. There are +## other ways of getting a line break in there, but `"\n"` is the most common. +## +## Another way you could insert a newlines is by writing `\u{0x0A}` instead of `\n`. +## That would result in the same string, because the `\u` escape sequence inserts +## [Unicode code points](https://unicode.org/glossary/#code_point) directly into +## the string. The Unicode code point 10 is a newline, and 10 is `0A` in hexadecimal. +## `0x0A` is a Roc hexadecimal literal, and `\u` escape sequences are always +## followed by a hexadecimal literal inside `{` and `}` like this. +## +## As another example, `"R\u{0x6F}c"` is the same string as `"Roc"`, because +## `"\u{0x6F}"` corresponds to the Unicode code point for lowercase `o`. If you +## want to [spice things up a bit](https://en.wikipedia.org/wiki/Metal_umlaut), +## you can write `"R\u{0xF6}c"` as an alternative way to get the string `"Röc"\. +## +## Roc strings also support these escape sequences: +## +## * `\\` - an actual backslash (writing a single `\` always begins an escape sequence!) +## * `\"` - an actual quotation mark (writing a `"` without a `\` ends the string) +## * `\r` - [carriage return](https://en.wikipedia.org/wiki/Carriage_Return) +## * `\t` - [horizontal tab](https://en.wikipedia.org/wiki/Tab_key#Tab_characters) +## * `\v` - [vertical tab](https://en.wikipedia.org/wiki/Tab_key#Tab_characters) +## +## You can also use escape sequences to insert named strings into other strings, like so: +## +## name = "Lee" +## city = "Roctown" +## +## greeting = "Hello there, \(name)! Welcome to \(city)." +## +## Here, `greeting` will become the string `"Hello there, Lee! Welcome to Roctown."`. +## This is known as [string interpolation](https://en.wikipedia.org/wiki/String_interpolation), +## and you can use it as many times as you like inside a string. The name +## between the parentheses must refer to a `Str` value that is currently in +## scope, and it must be a name - it can't be an arbitrary expression like a function call. +## +## ### Encoding +## +## Roc strings are not coupled to any particular +## [encoding](https://en.wikipedia.org/wiki/Character_encoding). As it happens, +## they are currently encoded in UTF-8, but this module is intentionally designed +## not to rely on that implementation detail so that a future release of Roc can +## potentially change it without breaking existing Roc applications. (UTF-8 +## seems pretty great today, but so did UTF-16 at an earlier point in history.) +## +## This module has functions to can convert a [Str] to a [List] of raw [code unit](https://unicode.org/glossary/#code_unit) +## integers (not to be confused with the [code points](https://unicode.org/glossary/#code_point) +## mentioned earlier) in a particular encoding. If you need encoding-specific functions, +## you should take a look at the [roc/unicode](roc/unicode) package. +## It has many more tools than this module does! + +## A [Unicode](https://unicode.org) text value. +Str := [ Str ] + +## Convert + +## Convert a [Float] to a decimal string, rounding off to the given number of decimal places. +## +## If you want to keep all the digits, use [Str.num] instead. decimal : Float *, Nat -> Str +## Convert a [Num] to a string. num : Float *, Nat -> Str +## Split a string around a separator. +## +## >>> Str.split "1,2,3" "," +## +## Passing `""` for the separator is not useful; it returns the original string +## wrapped in a list. +## +## >>> Str.split "1,2,3" "" +## +## To split a string into its individual graphemes, use `Str.graphemes` split : Str, Str -> List Str +## Split a string around newlines. +## +## On strings that use `"\n"` for their line endings, this gives the same answer +## as passing `"\n"` to [Str.split]. However, on strings that use `"\n\r"` (such +## as [in Windows files](https://en.wikipedia.org/wiki/Newline#History)), this +## will consume the entire `"\n\r"` instead of just the `"\n"`. +## +## >>> Str.lines "Hello, World!\nNice to meet you!" +## +## >>> Str.lines "Hello, World!\n\rNice to meet you!" +## +## To split a string using a custom separator, use [Str.split]. For more advanced +## string splitting, use a #Parser. lines : Str, Str -> List Str ## Check +## Returns `True` if the string is empty, and `False` otherwise. +## +## >>> Str.isEmpty "hi!" +## +## >>> Str.isEmpty "" isEmpty : Str -> Bool startsWith : Str, Str -> Bool +## If the string begins with a [Unicode code point](http://www.unicode.org/glossary/#code_point) +## equal to the given [U32], return `True`. Otherwise return `False`. +## +## If the given [Str] is empty, or if the given [U32] is not a valid +## code point, this will return `False`. +## +## **Performance Note:** This runs slightly faster than [Str.startsWith], so +## if you want to check whether a string begins with something that's representable +## in a single code point, you can use (for example) `Str.startsWithCodePt '鹏'` +## instead of `Str.startsWithCodePt "鹏"`. ('鹏' evaluates to the [U32] +## value `40527`.) This will not work for graphemes which take up multiple code +## points, however; `Str.startsWithCodePt '👩‍👩‍👦‍👦'` would be a compiler error +## because 👩‍👩‍👦‍👦 takes up multiple code points and cannot be represented as a +## single [U32]. You'd need to use `Str.startsWithCodePt "🕊"` instead. startsWithCodePt : Str, U32 -> Bool endsWith : Str, Str -> Bool @@ -45,22 +193,71 @@ allGraphemes : Str, (Str -> Bool) -> Bool ## Combine +## Combine a list of strings into a single string. +## +## >>> Str.join [ "a", "bc", "def" ] join : List Str -> Str +## Combine a list of strings into a single string, with a separator +## string in between each. +## +## >>> Str.joinWith [ "one", "two", "three" ] ", " joinWith : List Str, Str -> Str +## Add to the start of a string until it has at least the given number of +## graphemes. +## +## >>> Str.padGraphemesStart "0" 5 "36" +## +## >>> Str.padGraphemesStart "0" 1 "36" +## +## >>> Str.padGraphemesStart "0" 5 "12345" +## +## >>> Str.padGraphemesStart "✈️"" 5 "👩‍👩‍👦‍👦👩‍👩‍👦‍👦👩‍👩‍👦‍👦" padGraphemesStart : Str, Nat, Str -> Str +## Add to the end of a string until it has at least the given number of +## graphemes. +## +## >>> Str.padGraphemesStart "0" 5 "36" +## +## >>> Str.padGraphemesStart "0" 1 "36" +## +## >>> Str.padGraphemesStart "0" 5 "12345" +## +## >>> Str.padGraphemesStart "✈️"" 5 "👩‍👩‍👦‍👦👩‍👩‍👦‍👦👩‍👩‍👦‍👦" padGraphemesEnd : Str, Nat, Str -> Str ## Graphemes +## Split a string into its individual graphemes. +## +## >>> Str.graphemes "1,2,3" +## +## >>> Str.graphemes "👍👍👍" +## graphemes : Str -> List Str +## Count the number of [extended grapheme clusters](http://www.unicode.org/glossary/#extended_grapheme_cluster) +## in the string. +## +## Str.countGraphemes "Roc!" # 4 +## Str.countGraphemes "七巧板" # 3 +## Str.countGraphemes "🕊" # 1 countGraphemes : Str -> Nat +## Reverse the order of the string's individual graphemes. +## +## >>> Str.reverseGraphemes "1-2-3" +## +## >>> Str.reverseGraphemes "🐦✈️"👩‍👩‍👦‍👦" +## +## >>> Str.reversegraphemes "Crème Brûlée" reverseGraphemes : Str -> Str +## Returns `True` if the two strings are equal when ignoring case. +## +## >>> Str.caseInsensitiveEq "hi" "Hi" isCaseInsensitiveEq : Str, Str -> Bool isCaseInsensitiveNeq : Str, Str -> Bool @@ -137,14 +334,39 @@ isAllUppercase : Str -> Bool ## >>> Str.isAllLowercase "" isAllLowercase : Str -> Bool +## Return the string with any blank spaces removed from both the beginning +## as well as the end. trim : Str -> Str +## If the given [U32] is a valid [Unicode Scalar Value](http://www.unicode.org/glossary/#unicode_scalar_value), +## return a [Str] containing only that scalar. fromScalar : U32 -> Result Str [ BadScalar ]* fromCodePts : List U32 -> Result Str [ BadCodePt U32 ]* fromUtf8 : List U8 -> Result Str [ BadUtf8 ]* +## Create a [Str] from bytes encoded as [UTF-16LE](https://en.wikipedia.org/wiki/UTF-16#Byte-order_encoding_schemes). +# fromUtf16Le : List U8 -> Result Str [ BadUtf16Le Endi ]* +# ## Create a [Str] from bytes encoded as [UTF-16BE](https://en.wikipedia.org/wiki/UTF-16#Byte-order_encoding_schemes). +# fromUtf16Be : List U8 -> Result Str [ BadUtf16Be Endi ]* +# ## Create a [Str] from bytes encoded as UTF-16 with a [Byte Order Mark](https://en.wikipedia.org/wiki/Byte_order_mark). +# fromUtf16Bom : List U8 -> Result Str [ BadUtf16 Endi, NoBom ]* + +# ## Create a [Str] from bytes encoded as [UTF-32LE](https://web.archive.org/web/20120322145307/http://mail.apps.ietf.org/ietf/charsets/msg01095.html) +# fromUtf32Le : List U8 -> Result Str [ BadUtf32Le Endi ]* + +# ## Create a [Str] from bytes encoded as [UTF-32BE](https://web.archive.org/web/20120322145307/http://mail.apps.ietf.org/ietf/charsets/msg01095.html) +# fromUtf32Be : List U8 -> Result Str [ BadUtf32Be Endi ]* + +# ## Create a [Str] from bytes encoded as UTF-32 with a [Byte Order Mark](https://en.wikipedia.org/wiki/Byte_order_mark). +# fromUtf32Bom : List U8 -> Result Str [ BadUtf32 Endi, NoBom ]* + +# ## Convert from UTF-8, substituting the replacement character ("�") for any +# ## invalid sequences encountered. +# fromUtf8Sub : List U8 -> Str +# fromUtf16Sub : List U8, Endi -> Str +# fromUtf16BomSub : List U8 -> Result Str [ NoBom ]* ## Return a [List] of the string's [U8] UTF-8 [code units](https://unicode.org/glossary/#code_unit). ## (To split the string into a [List] of smaller [Str] values instead of [U8] values, @@ -184,6 +406,9 @@ parseUtf8Grapheme : List U8 -> Result { grapheme : Str, bytesParsed: Nat } [ Inv ## empty or began with an invalid code point, return an `Err`. parseUtf8CodePt : List U8 -> Result { codePt : U32, bytesParsed: Nat } [ InvalidCodePt ]* +## If the string represents a valid [U8] number, return that number. +## +## For more advanced options, see [parseU8]. toU8 : Str -> Result U8 [ InvalidU8 ]* toI8 : Str -> Result I8 [ InvalidI8 ]* toU16 : Str -> Result U16 [ InvalidU16 ]* diff --git a/compiler/builtins/roc/Str.roc b/compiler/builtins/roc/Str.roc new file mode 100644 index 0000000000..fae59869c1 --- /dev/null +++ b/compiler/builtins/roc/Str.roc @@ -0,0 +1,90 @@ +interface Str + exposes + [ + concat, + Utf8Problem, + Utf8ByteProblem, + isEmpty, + joinWith, + split, + repeat, + countGraphemes, + startsWithCodePt, + toUtf8, + fromUtf8, + fromUtf8Range, + startsWith, + endsWith, + trim, + trimLeft, + trimRight, + + toDec, + toF64, + toF32, + toNat, + toU128, + toI128, + toU64, + toI64, + toU32, + toI32, + toU16, + toI16, + toU8, + toI8, + ] + imports [ Bool.{ Bool }, Result.{ Result } ] + + + +Utf8ByteProblem : + [ + InvalidStartByte, + UnexpectedEndOfSequence, + ExpectedContinuation, + OverlongEncoding, + CodepointTooLarge, + EncodesSurrogateHalf, + ] + +Utf8Problem : { byteIndex : Nat, problem : Utf8ByteProblem } + +isEmpty : Str -> Bool +concat : Str, Str -> Str + +joinWith : List Str, Str -> Str +split : Str, Str -> List Str +repeat : Str, Nat -> Str +countGraphemes : Str -> Nat +startsWithCodePt : Str, U32 -> Bool + +toUtf8 : Str -> List U8 + +# fromUtf8 : List U8 -> Result Str [ BadUtf8 Utf8Problem ]* +# fromUtf8Range : List U8 -> Result Str [ BadUtf8 Utf8Problem Nat, OutOfBounds ]* + +fromUtf8 : List U8 -> Result Str [ BadUtf8 Utf8ByteProblem Nat ]* +fromUtf8Range : List U8, { start : Nat, count : Nat } -> Result Str [ BadUtf8 Utf8ByteProblem Nat, OutOfBounds ]* + +startsWith : Str, Str -> Bool +endsWith : Str, Str -> Bool + +trim : Str -> Str +trimLeft : Str -> Str +trimRight : Str -> Str + +toDec : Str -> Result Dec [ InvalidNumStr ]* +toF64 : Str -> Result F64 [ InvalidNumStr ]* +toF32 : Str -> Result F32 [ InvalidNumStr ]* +toNat : Str -> Result Nat [ InvalidNumStr ]* +toU128 : Str -> Result U128 [ InvalidNumStr ]* +toI128 : Str -> Result I128 [ InvalidNumStr ]* +toU64 : Str -> Result U64 [ InvalidNumStr ]* +toI64 : Str -> Result I64 [ InvalidNumStr ]* +toU32 : Str -> Result U32 [ InvalidNumStr ]* +toI32 : Str -> Result I32 [ InvalidNumStr ]* +toU16 : Str -> Result U16 [ InvalidNumStr ]* +toI16 : Str -> Result I16 [ InvalidNumStr ]* +toU8 : Str -> Result U8 [ InvalidNumStr ]* +toI8 : Str -> Result I8 [ InvalidNumStr ]* From 92a691ad0fe08f32e01977eca6d39374aa4e8e03 Mon Sep 17 00:00:00 2001 From: Nuno Ferreira Date: Fri, 6 May 2022 00:40:17 +0200 Subject: [PATCH 838/846] Migrated Str --- compiler/builtins/docs/Str.roc | 470 --------------------------------- compiler/builtins/roc/Str.roc | 130 +++++++++ 2 files changed, 130 insertions(+), 470 deletions(-) delete mode 100644 compiler/builtins/docs/Str.roc diff --git a/compiler/builtins/docs/Str.roc b/compiler/builtins/docs/Str.roc deleted file mode 100644 index 0bfa3ca2af..0000000000 --- a/compiler/builtins/docs/Str.roc +++ /dev/null @@ -1,470 +0,0 @@ -interface Str - exposes - [ - Str, - append, - concat, - countGraphemes, - endsWith, - fromUtf8, - isEmpty, - joinWith, - split, - startsWith, - startsWithCodePt, - toUtf8, - Utf8Problem, - Utf8ByteProblem - ] - imports [] - -## # Types -## -## Dealing with text is a deep topic, so by design, Roc's `Str` module sticks -## to the basics. -## -## _For more advanced use cases like working with raw [code points](https://unicode.org/glossary/#code_point), -## see the [roc/unicode](roc/unicode) package. For locale-specific text -## functions (including uppercasing strings, as capitalization rules vary by locale; -## in English, `"i"` capitalizes to `"I"`, but [in Turkish](https://en.wikipedia.org/wiki/Dotted_and_dotless_I#In_computing), -## the same `"i"` capitalizes to `"İ"` - as well as sorting strings, which also varies -## by locale; `"ö"` is sorted differently in German and Swedish) see the [roc/locale](roc/locale) package._ -## -## ### Unicode -## -## Unicode can represent text values which span multiple languages, symbols, and emoji. -## Here are some valid Roc strings: -## -## "Roc!" -## "鹏" -## "🕊" -## -## Every Unicode string is a sequence of [extended grapheme clusters](http://www.unicode.org/glossary/#extended_grapheme_cluster). -## An extended grapheme cluster represents what a person reading a string might -## call a "character" - like "A" or "ö" or "👩‍👩‍👦‍👦". -## Because the term "character" means different things in different areas of -## programming, and "extended grapheme cluster" is a mouthful, in Roc we use the -## term "grapheme" as a shorthand for the more precise "extended grapheme cluster." -## -## You can get the number of graphemes in a string by calling [Str.countGraphemes] on it: -## -## Str.countGraphemes "Roc!" -## Str.countGraphemes "折り紙" -## Str.countGraphemes "🕊" -## -## > The `countGraphemes` function walks through the entire string to get its answer, -## > so if you want to check whether a string is empty, you'll get much better performance -## > by calling `Str.isEmpty myStr` instead of `Str.countGraphemes myStr == 0`. -## -## ### Escape sequences -## -## If you put a `\` in a Roc string literal, it begins an *escape sequence*. -## An escape sequence is a convenient way to insert certain strings into other strings. -## For example, suppose you write this Roc string: -## -## "I took the one less traveled by,\nAnd that has made all the difference." -## -## The `"\n"` in the middle will insert a line break into this string. There are -## other ways of getting a line break in there, but `"\n"` is the most common. -## -## Another way you could insert a newlines is by writing `\u{0x0A}` instead of `\n`. -## That would result in the same string, because the `\u` escape sequence inserts -## [Unicode code points](https://unicode.org/glossary/#code_point) directly into -## the string. The Unicode code point 10 is a newline, and 10 is `0A` in hexadecimal. -## `0x0A` is a Roc hexadecimal literal, and `\u` escape sequences are always -## followed by a hexadecimal literal inside `{` and `}` like this. -## -## As another example, `"R\u{0x6F}c"` is the same string as `"Roc"`, because -## `"\u{0x6F}"` corresponds to the Unicode code point for lowercase `o`. If you -## want to [spice things up a bit](https://en.wikipedia.org/wiki/Metal_umlaut), -## you can write `"R\u{0xF6}c"` as an alternative way to get the string `"Röc"\. -## -## Roc strings also support these escape sequences: -## -## * `\\` - an actual backslash (writing a single `\` always begins an escape sequence!) -## * `\"` - an actual quotation mark (writing a `"` without a `\` ends the string) -## * `\r` - [carriage return](https://en.wikipedia.org/wiki/Carriage_Return) -## * `\t` - [horizontal tab](https://en.wikipedia.org/wiki/Tab_key#Tab_characters) -## * `\v` - [vertical tab](https://en.wikipedia.org/wiki/Tab_key#Tab_characters) -## -## You can also use escape sequences to insert named strings into other strings, like so: -## -## name = "Lee" -## city = "Roctown" -## -## greeting = "Hello there, \(name)! Welcome to \(city)." -## -## Here, `greeting` will become the string `"Hello there, Lee! Welcome to Roctown."`. -## This is known as [string interpolation](https://en.wikipedia.org/wiki/String_interpolation), -## and you can use it as many times as you like inside a string. The name -## between the parentheses must refer to a `Str` value that is currently in -## scope, and it must be a name - it can't be an arbitrary expression like a function call. -## -## ### Encoding -## -## Roc strings are not coupled to any particular -## [encoding](https://en.wikipedia.org/wiki/Character_encoding). As it happens, -## they are currently encoded in UTF-8, but this module is intentionally designed -## not to rely on that implementation detail so that a future release of Roc can -## potentially change it without breaking existing Roc applications. (UTF-8 -## seems pretty great today, but so did UTF-16 at an earlier point in history.) -## -## This module has functions to can convert a [Str] to a [List] of raw [code unit](https://unicode.org/glossary/#code_unit) -## integers (not to be confused with the [code points](https://unicode.org/glossary/#code_point) -## mentioned earlier) in a particular encoding. If you need encoding-specific functions, -## you should take a look at the [roc/unicode](roc/unicode) package. -## It has many more tools than this module does! - -## A [Unicode](https://unicode.org) text value. -Str := [ Str ] - -## Convert - -## Convert a [Float] to a decimal string, rounding off to the given number of decimal places. -## -## If you want to keep all the digits, use [Str.num] instead. -decimal : Float *, Nat -> Str - - -## Convert a [Num] to a string. -num : Float *, Nat -> Str - -## Split a string around a separator. -## -## >>> Str.split "1,2,3" "," -## -## Passing `""` for the separator is not useful; it returns the original string -## wrapped in a list. -## -## >>> Str.split "1,2,3" "" -## -## To split a string into its individual graphemes, use `Str.graphemes` -split : Str, Str -> List Str - -## Split a string around newlines. -## -## On strings that use `"\n"` for their line endings, this gives the same answer -## as passing `"\n"` to [Str.split]. However, on strings that use `"\n\r"` (such -## as [in Windows files](https://en.wikipedia.org/wiki/Newline#History)), this -## will consume the entire `"\n\r"` instead of just the `"\n"`. -## -## >>> Str.lines "Hello, World!\nNice to meet you!" -## -## >>> Str.lines "Hello, World!\n\rNice to meet you!" -## -## To split a string using a custom separator, use [Str.split]. For more advanced -## string splitting, use a #Parser. -lines : Str, Str -> List Str - -## Check - -## Returns `True` if the string is empty, and `False` otherwise. -## -## >>> Str.isEmpty "hi!" -## -## >>> Str.isEmpty "" -isEmpty : Str -> Bool - -startsWith : Str, Str -> Bool - -## If the string begins with a [Unicode code point](http://www.unicode.org/glossary/#code_point) -## equal to the given [U32], return `True`. Otherwise return `False`. -## -## If the given [Str] is empty, or if the given [U32] is not a valid -## code point, this will return `False`. -## -## **Performance Note:** This runs slightly faster than [Str.startsWith], so -## if you want to check whether a string begins with something that's representable -## in a single code point, you can use (for example) `Str.startsWithCodePt '鹏'` -## instead of `Str.startsWithCodePt "鹏"`. ('鹏' evaluates to the [U32] -## value `40527`.) This will not work for graphemes which take up multiple code -## points, however; `Str.startsWithCodePt '👩‍👩‍👦‍👦'` would be a compiler error -## because 👩‍👩‍👦‍👦 takes up multiple code points and cannot be represented as a -## single [U32]. You'd need to use `Str.startsWithCodePt "🕊"` instead. -startsWithCodePt : Str, U32 -> Bool - -endsWith : Str, Str -> Bool - -contains : Str, Str -> Bool - -anyGraphemes : Str, (Str -> Bool) -> Bool - -allGraphemes : Str, (Str -> Bool) -> Bool - -## Combine - -## Combine a list of strings into a single string. -## -## >>> Str.join [ "a", "bc", "def" ] -join : List Str -> Str - -## Combine a list of strings into a single string, with a separator -## string in between each. -## -## >>> Str.joinWith [ "one", "two", "three" ] ", " -joinWith : List Str, Str -> Str - -## Add to the start of a string until it has at least the given number of -## graphemes. -## -## >>> Str.padGraphemesStart "0" 5 "36" -## -## >>> Str.padGraphemesStart "0" 1 "36" -## -## >>> Str.padGraphemesStart "0" 5 "12345" -## -## >>> Str.padGraphemesStart "✈️"" 5 "👩‍👩‍👦‍👦👩‍👩‍👦‍👦👩‍👩‍👦‍👦" -padGraphemesStart : Str, Nat, Str -> Str - -## Add to the end of a string until it has at least the given number of -## graphemes. -## -## >>> Str.padGraphemesStart "0" 5 "36" -## -## >>> Str.padGraphemesStart "0" 1 "36" -## -## >>> Str.padGraphemesStart "0" 5 "12345" -## -## >>> Str.padGraphemesStart "✈️"" 5 "👩‍👩‍👦‍👦👩‍👩‍👦‍👦👩‍👩‍👦‍👦" -padGraphemesEnd : Str, Nat, Str -> Str - -## Graphemes - -## Split a string into its individual graphemes. -## -## >>> Str.graphemes "1,2,3" -## -## >>> Str.graphemes "👍👍👍" -## -graphemes : Str -> List Str - -## Count the number of [extended grapheme clusters](http://www.unicode.org/glossary/#extended_grapheme_cluster) -## in the string. -## -## Str.countGraphemes "Roc!" # 4 -## Str.countGraphemes "七巧板" # 3 -## Str.countGraphemes "🕊" # 1 -countGraphemes : Str -> Nat - -## Reverse the order of the string's individual graphemes. -## -## >>> Str.reverseGraphemes "1-2-3" -## -## >>> Str.reverseGraphemes "🐦✈️"👩‍👩‍👦‍👦" -## -## >>> Str.reversegraphemes "Crème Brûlée" -reverseGraphemes : Str -> Str - -## Returns `True` if the two strings are equal when ignoring case. -## -## >>> Str.caseInsensitiveEq "hi" "Hi" -isCaseInsensitiveEq : Str, Str -> Bool - -isCaseInsensitiveNeq : Str, Str -> Bool - -walkGraphemes : Str, { start: state, step: (state, Str -> state) } -> state -walkGraphemesUntil : Str, { start: state, step: (state, Str -> [ Continue state, Done state ]) } -> state -walkGraphemesBackwards : Str, { start: state, step: (state, Str -> state) } -> state -walkGraphemesBackwardsUntil : Str, { start: state, step: (state, Str -> [ Continue state, Done state ]) } -> state - -## Returns `True` if the string begins with an uppercase letter. -## -## >>> Str.isCapitalized "Hi" -## -## >>> Str.isCapitalized " Hi" -## -## >>> Str.isCapitalized "hi" -## -## >>> Str.isCapitalized "Česká" -## -## >>> Str.isCapitalized "Э" -## -## >>> Str.isCapitalized "東京" -## -## >>> Str.isCapitalized "🐦" -## -## >>> Str.isCapitalized "" -## -## Since the rules for how to capitalize a string vary by locale, -## (for example, in English, `"i"` capitalizes to `"I"`, but -## [in Turkish](https://en.wikipedia.org/wiki/Dotted_and_dotless_I#In_computing), -## the same `"i"` capitalizes to `"İ"`) see the [roc/locale](roc/locale) package -## package for functions which capitalize strings. -isCapitalized : Str -> Bool - -## Returns `True` if the string consists entirely of uppercase letters. -## -## >>> Str.isAllUppercase "hi" -## -## >>> Str.isAllUppercase "Hi" -## -## >>> Str.isAllUppercase "HI" -## -## >>> Str.isAllUppercase " Hi" -## -## >>> Str.isAllUppercase "Česká" -## -## >>> Str.isAllUppercase "Э" -## -## >>> Str.isAllUppercase "東京" -## -## >>> Str.isAllUppercase "🐦" -## -## >>> Str.isAllUppercase "" -isAllUppercase : Str -> Bool - -## Returns `True` if the string consists entirely of lowercase letters. -## -## >>> Str.isAllLowercase "hi" -## -## >>> Str.isAllLowercase "Hi" -## -## >>> Str.isAllLowercase "HI" -## -## >>> Str.isAllLowercase " Hi" -## -## >>> Str.isAllLowercase "Česká" -## -## >>> Str.isAllLowercase "Э" -## -## >>> Str.isAllLowercase "東京" -## -## >>> Str.isAllLowercase "🐦" -## -## >>> Str.isAllLowercase "" -isAllLowercase : Str -> Bool - -## Return the string with any blank spaces removed from both the beginning -## as well as the end. -trim : Str -> Str - -## If the given [U32] is a valid [Unicode Scalar Value](http://www.unicode.org/glossary/#unicode_scalar_value), -## return a [Str] containing only that scalar. -fromScalar : U32 -> Result Str [ BadScalar ]* -fromCodePts : List U32 -> Result Str [ BadCodePt U32 ]* -fromUtf8 : List U8 -> Result Str [ BadUtf8 ]* - -## Create a [Str] from bytes encoded as [UTF-16LE](https://en.wikipedia.org/wiki/UTF-16#Byte-order_encoding_schemes). -# fromUtf16Le : List U8 -> Result Str [ BadUtf16Le Endi ]* - -# ## Create a [Str] from bytes encoded as [UTF-16BE](https://en.wikipedia.org/wiki/UTF-16#Byte-order_encoding_schemes). -# fromUtf16Be : List U8 -> Result Str [ BadUtf16Be Endi ]* - -# ## Create a [Str] from bytes encoded as UTF-16 with a [Byte Order Mark](https://en.wikipedia.org/wiki/Byte_order_mark). -# fromUtf16Bom : List U8 -> Result Str [ BadUtf16 Endi, NoBom ]* - -# ## Create a [Str] from bytes encoded as [UTF-32LE](https://web.archive.org/web/20120322145307/http://mail.apps.ietf.org/ietf/charsets/msg01095.html) -# fromUtf32Le : List U8 -> Result Str [ BadUtf32Le Endi ]* - -# ## Create a [Str] from bytes encoded as [UTF-32BE](https://web.archive.org/web/20120322145307/http://mail.apps.ietf.org/ietf/charsets/msg01095.html) -# fromUtf32Be : List U8 -> Result Str [ BadUtf32Be Endi ]* - -# ## Create a [Str] from bytes encoded as UTF-32 with a [Byte Order Mark](https://en.wikipedia.org/wiki/Byte_order_mark). -# fromUtf32Bom : List U8 -> Result Str [ BadUtf32 Endi, NoBom ]* - -# ## Convert from UTF-8, substituting the replacement character ("�") for any -# ## invalid sequences encountered. -# fromUtf8Sub : List U8 -> Str -# fromUtf16Sub : List U8, Endi -> Str -# fromUtf16BomSub : List U8 -> Result Str [ NoBom ]* - -## Return a [List] of the string's [U8] UTF-8 [code units](https://unicode.org/glossary/#code_unit). -## (To split the string into a [List] of smaller [Str] values instead of [U8] values, -## see [Str.split] and `Str.graphemes`.) -## -## >>> Str.toUtf8 "👩‍👩‍👦‍👦" -## -## >>> Str.toUtf8 "Roc" -## -## >>> Str.toUtf8 "鹏" -## -## >>> Str.toUtf8 "🐦" -## -## For a more flexible function that walks through each of these [U8] code units -## without creating a [List], see `Str.walkUtf8` and `Str.walkRevUtf8`. -toUtf8 : Str -> List U8 -toUtf16Be : Str -> List U8 -toUtf16Le : Str -> List U8 -# toUtf16Bom : Str, Endi -> List U8 -toUtf32Be : Str -> List U8 -toUtf32Le : Str -> List U8 -# toUtf32Bom : Str, Endi -> List U8 - -# Parsing - -## If the bytes begin with a valid [extended grapheme cluster](http://www.unicode.org/glossary/#extended_grapheme_cluster) -## encoded as [UTF-8](https://en.wikipedia.org/wiki/UTF-8), return it along with the number of bytes it took up. -## -## If the bytes do not begin with a valid grapheme, for example because the list was -## empty or began with an invalid grapheme, return `Err`. -parseUtf8Grapheme : List U8 -> Result { grapheme : Str, bytesParsed: Nat } [ InvalidGrapheme ]* - -## If the bytes begin with a valid [Unicode code point](http://www.unicode.org/glossary/#code_point) -## encoded as [UTF-8](https://en.wikipedia.org/wiki/UTF-8), return it along with the number of bytes it took up. -## -## If the string does not begin with a valid code point, for example because the list was -## empty or began with an invalid code point, return an `Err`. -parseUtf8CodePt : List U8 -> Result { codePt : U32, bytesParsed: Nat } [ InvalidCodePt ]* - -## If the string represents a valid [U8] number, return that number. -## -## For more advanced options, see [parseU8]. -toU8 : Str -> Result U8 [ InvalidU8 ]* -toI8 : Str -> Result I8 [ InvalidI8 ]* -toU16 : Str -> Result U16 [ InvalidU16 ]* -toI16 : Str -> Result I16 [ InvalidI16 ]* -toU32 : Str -> Result U32 [ InvalidU32 ]* -toI32 : Str -> Result I32 [ InvalidI32 ]* -toU64 : Str -> Result U64 [ InvalidU64 ]* -toI64 : Str -> Result I64 [ InvalidI64 ]* -toU128 : Str -> Result U128 [ InvalidU128 ]* -toI128 : Str -> Result I128 [ InvalidI128 ]* -toF64 : Str -> Result U128 [ InvalidF64 ]* -toF32 : Str -> Result I128 [ InvalidF32 ]* -toDec : Str -> Result Dec [ InvalidDec ]* - -## If the string represents a valid number, return that number. -## -## The exact number type to look for will be inferred from usage. -## In the example below, the usage of I64 in the type signature will require that type instead of (Num *). -## -## >>> strToI64 : Str -> Result I64 [ InvalidNumStr ]* -## >>> strToI64 = \inputStr -> -## >>> Str.toNum inputStr -## -## If the string is exactly `"NaN"`, `"∞"`, or `"-∞"`, they will be accepted -## only when converting to [F64] or [F32] numbers, and will be translated accordingly. -## -## This never accepts numbers with underscores or commas in them. For more -## advanced options, see [parseNum]. -toNum : Str -> Result (Num *) [ InvalidNumStr ]* - -## If the string begins with an [Int] or a [finite](Num.isFinite) [Frac], return -## that number along with the rest of the string after it. -## -## The exact number type to look for will be inferred from usage. -## In the example below, the usage of Float64 in the type signature will require that type instead of (Num *). -## -## >>> parseFloat64 : Str -> Result { val: Float64, rest: Str } [ InvalidNumStr ]* -## >>> Str.parseNum input {} -## -## If the string begins with `"NaN"`, `"∞"`, and `"-∞"` (which do not represent -## [finite](Num.isFinite) numbers), they will be accepted only when parsing -## [F64] or [F32] numbers, and translated accordingly. -# parseNum : Str, NumParseConfig -> Result { val : Num *, rest : Str } [ InvalidNumStr ]* - -## Notes: -## * You can allow a decimal mark for integers; they'll only parse if the numbers after it are all 0. -## * For `wholeSep`, `Required` has a payload for how many digits (e.g. "required every 3 digits") -## * For `wholeSep`, `Allowed` allows the separator to appear anywhere. -# NumParseConfig : -# { -# base ? [ Decimal, Hexadecimal, Octal, Binary ], -# notation ? [ Standard, Scientific, Any ], -# decimalMark ? [ Allowed Str, Required Str, Disallowed ], -# decimalDigits ? [ Any, AtLeast U16, Exactly U16 ], -# wholeDigits ? [ Any, AtLeast U16, Exactly U16 ], -# leadingZeroes ? [ Allowed, Disallowed ], -# trailingZeroes ? [ Allowed, Disallowed ], -# wholeSep ? { mark : Str, policy : [ Allowed, Required U64 ] } -# } diff --git a/compiler/builtins/roc/Str.roc b/compiler/builtins/roc/Str.roc index fae59869c1..06d59eac53 100644 --- a/compiler/builtins/roc/Str.roc +++ b/compiler/builtins/roc/Str.roc @@ -36,6 +36,81 @@ interface Str ] imports [ Bool.{ Bool }, Result.{ Result } ] +## # Types +## +## Dealing with text is a deep topic, so by design, Roc's `Str` module sticks +## to the basics. +## + +## ### Unicode +## +## Unicode can represent text values which span multiple languages, symbols, and emoji. +## Here are some valid Roc strings: +## +## "Roc!" +## "鹏" +## "🕊" +## +## Every Unicode string is a sequence of [extended grapheme clusters](http://www.unicode.org/glossary/#extended_grapheme_cluster). +## An extended grapheme cluster represents what a person reading a string might +## call a "character" - like "A" or "ö" or "👩‍👩‍👦‍👦". +## Because the term "character" means different things in different areas of +## programming, and "extended grapheme cluster" is a mouthful, in Roc we use the +## term "grapheme" as a shorthand for the more precise "extended grapheme cluster." +## +## You can get the number of graphemes in a string by calling [Str.countGraphemes] on it: +## +## Str.countGraphemes "Roc!" +## Str.countGraphemes "折り紙" +## Str.countGraphemes "🕊" +## +## > The `countGraphemes` function walks through the entire string to get its answer, +## > so if you want to check whether a string is empty, you'll get much better performance +## > by calling `Str.isEmpty myStr` instead of `Str.countGraphemes myStr == 0`. +## +## ### Escape sequences +## +## If you put a `\` in a Roc string literal, it begins an *escape sequence*. +## An escape sequence is a convenient way to insert certain strings into other strings. +## For example, suppose you write this Roc string: +## +## "I took the one less traveled by,\nAnd that has made all the difference." +## +## The `"\n"` in the middle will insert a line break into this string. There are +## other ways of getting a line break in there, but `"\n"` is the most common. +## +## Another way you could insert a newlines is by writing `\u{0x0A}` instead of `\n`. +## That would result in the same string, because the `\u` escape sequence inserts +## [Unicode code points](https://unicode.org/glossary/#code_point) directly into +## the string. The Unicode code point 10 is a newline, and 10 is `0A` in hexadecimal. +## `0x0A` is a Roc hexadecimal literal, and `\u` escape sequences are always +## followed by a hexadecimal literal inside `{` and `}` like this. +## +## As another example, `"R\u{0x6F}c"` is the same string as `"Roc"`, because +## `"\u{0x6F}"` corresponds to the Unicode code point for lowercase `o`. If you +## want to [spice things up a bit](https://en.wikipedia.org/wiki/Metal_umlaut), +## you can write `"R\u{0xF6}c"` as an alternative way to get the string `"Röc"\. +## +## Roc strings also support these escape sequences: +## +## * `\\` - an actual backslash (writing a single `\` always begins an escape sequence!) +## * `\"` - an actual quotation mark (writing a `"` without a `\` ends the string) +## * `\r` - [carriage return](https://en.wikipedia.org/wiki/Carriage_Return) +## * `\t` - [horizontal tab](https://en.wikipedia.org/wiki/Tab_key#Tab_characters) +## * `\v` - [vertical tab](https://en.wikipedia.org/wiki/Tab_key#Tab_characters) +## +## You can also use escape sequences to insert named strings into other strings, like so: +## +## name = "Lee" +## city = "Roctown" +## +## greeting = "Hello there, \(name)! Welcome to \(city)." +## +## Here, `greeting` will become the string `"Hello there, Lee! Welcome to Roctown."`. +## This is known as [string interpolation](https://en.wikipedia.org/wiki/String_interpolation), +## and you can use it as many times as you like inside a string. The name +## between the parentheses must refer to a `Str` value that is currently in +## scope, and it must be a name - it can't be an arbitrary expression like a function call. Utf8ByteProblem : @@ -50,15 +125,68 @@ Utf8ByteProblem : Utf8Problem : { byteIndex : Nat, problem : Utf8ByteProblem } +## Returns `True` if the string is empty, and `False` otherwise. +## +## >>> Str.isEmpty "hi!" +## +## >>> Str.isEmpty "" isEmpty : Str -> Bool concat : Str, Str -> Str +## Combine a list of strings into a single string, with a separator +## string in between each. +## +## >>> Str.joinWith [ "one", "two", "three" ] ", " joinWith : List Str, Str -> Str + +## Split a string around a separator. +## +## >>> Str.split "1,2,3" "," +## +## Passing `""` for the separator is not useful; it returns the original string +## wrapped in a list. +## +## >>> Str.split "1,2,3" "" +## +## To split a string into its individual graphemes, use `Str.graphemes` split : Str, Str -> List Str repeat : Str, Nat -> Str + +## Count the number of [extended grapheme clusters](http://www.unicode.org/glossary/#extended_grapheme_cluster) +## in the string. +## +## Str.countGraphemes "Roc!" # 4 +## Str.countGraphemes "‰∏ÉÂ∑ßÊùø" # 3 +## Str.countGraphemes "üïä" # 1 countGraphemes : Str -> Nat + +## If the string begins with a [Unicode code point](http://www.unicode.org/glossary/#code_point) +## equal to the given [U32], return `True`. Otherwise return `False`. +## +## If the given [Str] is empty, or if the given [U32] is not a valid +## code point, this will return `False`. +## +## **Performance Note:** This runs slightly faster than [Str.startsWith], so +## if you want to check whether a string begins with something that's representable +## in a single code point, you can use (for example) `Str.startsWithCodePt '鹏'` +## instead of `Str.startsWithCodePt "鹏"`. ('鹏' evaluates to the [U32] +## value `40527`.) This will not work for graphemes which take up multiple code +## points, however; `Str.startsWithCodePt '👩‍👩‍👦‍👦'` would be a compiler error +## because 👩‍👩‍👦‍👦 takes up multiple code points and cannot be represented as a +## single [U32]. You'd need to use `Str.startsWithCodePt "🕊"` instead. startsWithCodePt : Str, U32 -> Bool +## Return a [List] of the string's [U8] UTF-8 [code units](https://unicode.org/glossary/#code_unit). +## (To split the string into a [List] of smaller [Str] values instead of [U8] values, +## see [Str.split].) +## +## >>> Str.toUtf8 "👩‍👩‍👦‍👦" +## +## >>> Str.toUtf8 "Roc" +## +## >>> Str.toUtf8 "鹏" +## +## >>> Str.toUtf8 "🐦" toUtf8 : Str -> List U8 # fromUtf8 : List U8 -> Result Str [ BadUtf8 Utf8Problem ]* @@ -70,6 +198,8 @@ fromUtf8Range : List U8, { start : Nat, count : Nat } -> Result Str [ BadUtf8 Ut startsWith : Str, Str -> Bool endsWith : Str, Str -> Bool +## Return the string with any blank spaces removed from both the beginning +## as well as the end. trim : Str -> Str trimLeft : Str -> Str trimRight : Str -> Str From 0b094cfab1fa1e837533e613497d43deed6578e2 Mon Sep 17 00:00:00 2001 From: Nuno Ferreira Date: Fri, 6 May 2022 10:39:46 +0200 Subject: [PATCH 839/846] Migrated List.roc docs over to builtins/roc/List.roc --- compiler/builtins/roc/List.roc | 449 +++++++++++++++++++++++++++++++++ 1 file changed, 449 insertions(+) diff --git a/compiler/builtins/roc/List.roc b/compiler/builtins/roc/List.roc index 42de7f03ef..483fdbf601 100644 --- a/compiler/builtins/roc/List.roc +++ b/compiler/builtins/roc/List.roc @@ -56,6 +56,152 @@ interface List Bool.{ Bool } ] +## Types + +## A sequential list of values. +## +## >>> [ 1, 2, 3 ] # a list of numbers +## >>> [ "a", "b", "c" ] # a list of strings +## >>> [ [ 1.1 ], [], [ 2.2, 3.3 ] ] # a list of lists of numbers +## +## The list `[ 1, "a" ]` gives an error, because each element in a list must have +## the same type. If you want to put a mix of [I64] and [Str] values into a list, try this: +## +## ``` +## mixedList : List [ IntElem I64, StrElem Str ]* +## mixedList = [ IntElem 1, IntElem 2, StrElem "a", StrElem "b" ] +## ``` +## +## The maximum size of a [List] is limited by the amount of heap memory available +## to the current process. If there is not enough memory available, attempting to +## create the list could crash. (On Linux, where [overcommit](https://www.etalabs.net/overcommit.html) +## is normally enabled, not having enough memory could result in the list appearing +## to be created just fine, but then crashing later.) +## +## > The theoretical maximum length for a list created in Roc is half of +## > `Num.maxNat`. Attempting to create a list bigger than that +## > in Roc code will always fail, although in practice it is likely to fail +## > at much smaller lengths due to insufficient memory being available. +## +## ## Performance Details +## +## Under the hood, a list is a record containing a `len : Nat` field as well +## as a pointer to a reference count and a flat array of bytes. Unique lists +## store a capacity #Nat instead of a reference count. +## +## ## Shared Lists +## +## Shared lists are [reference counted](https://en.wikipedia.org/wiki/Reference_counting). +## +## Each time a given list gets referenced, its reference count ("refcount" for short) +## gets incremented. Each time a list goes out of scope, its refcount count gets +## decremented. Once a refcount, has been decremented more times than it has been +## incremented, we know nothing is referencing it anymore, and the list's memory +## will be immediately freed. +## +## Let's look at an example. +## +## ratings = [ 5, 4, 3 ] +## +## { foo: ratings, bar: ratings } +## +## The first line binds the name `ratings` to the list `[ 5, 4, 3 ]`. The list +## begins with a refcount of 1, because so far only `ratings` is referencing it. +## +## The second line alters this refcount. `{ foo: ratings` references +## the `ratings` list, which will result in its refcount getting incremented +## from 0 to 1. Similarly, `bar: ratings }` also references the `ratings` list, +## which will result in its refcount getting incremented from 1 to 2. +## +## Let's turn this example into a function. +## +## getRatings = \first -> +## ratings = [ first, 4, 3 ] +## +## { foo: ratings, bar: ratings } +## +## getRatings 5 +## +## At the end of the `getRatings` function, when the record gets returned, +## the original `ratings =` binding has gone out of scope and is no longer +## accessible. (Trying to reference `ratings` outside the scope of the +## `getRatings` function would be an error!) +## +## Since `ratings` represented a way to reference the list, and that way is no +## longer accessible, the list's refcount gets decremented when `ratings` goes +## out of scope. It will decrease from 2 back down to 1. +## +## Putting these together, when we call `getRatings 5`, what we get back is +## a record with two fields, `foo`, and `bar`, each of which refers to the same +## list, and that list has a refcount of 1. +## +## Let's change the last line to be `(getRatings 5).bar` instead of `getRatings 5`: +## +## getRatings = \first -> +## ratings = [ first, 4, 3 ] +## +## { foo: ratings, bar: ratings } +## +## (getRatings 5).bar +## +## Now, when this expression returns, only the `bar` field of the record will +## be returned. This will mean that the `foo` field becomes inaccessible, causing +## the list's refcount to get decremented from 2 to 1. At this point, the list is back +## where it started: there is only 1 reference to it. +## +## Finally let's suppose the final line were changed to this: +## +## List.first (getRatings 5).bar +## +## This call to [List.first] means that even the list in the `bar` field has become +## inaccessible. As such, this line will cause the list's refcount to get +## decremented all the way to 0. At that point, nothing is referencing the list +## anymore, and its memory will get freed. +## +## Things are different if this is a list of lists instead of a list of numbers. +## Let's look at a simpler example using [List.first] - first with a list of numbers, +## and then with a list of lists, to see how they differ. +## +## Here's the example using a list of numbers. +## +## nums = [ 1, 2, 3, 4, 5, 6, 7 ] +## +## first = List.first nums +## last = List.last nums +## +## first +## +## It makes a list, calls [List.first] and [List.last] on it, and then returns `first`. +## +## Here's the equivalent code with a list of lists: +## +## lists = [ [ 1 ], [ 2, 3 ], [], [ 4, 5, 6, 7 ] ] +## +## first = List.first lists +## last = List.last lists +## +## first +## +## TODO explain how in the former example, when we go to free `nums` at the end, +## we can free it immediately because there are no other refcounts. However, +## in the case of `lists`, we have to iterate through the list and decrement +## the refcounts of each of its contained lists - because they, too, have +## refcounts! Importantly, because the first element had its refcount incremented +## because the function returned `first`, that element will actually end up +## *not* getting freed at the end - but all the others will be. +## +## In the `lists` example, `lists = [ ... ]` also creates a list with an initial +## refcount of 1. Separately, it also creates several other lists - each with +## their own refcounts - to go inside that list. (The empty list at the end +## does not use heap memory, and thus has no refcount.) +## +## At the end, we once again call [List.first] on the list, but this time +## +## * Copying small lists (64 elements or fewer) is typically slightly faster than copying small persistent data structures. This is because, at small sizes, persistent data structures tend to be thin wrappers around flat arrays anyway. They don't have any copying advantage until crossing a certain minimum size threshold. +## * Even when copying is faster, other list operations may still be slightly slower with persistent data structures. For example, even if it were a persistent data structure, [List.map], [List.walk], and [List.keepIf] would all need to traverse every element in the list and build up the result from scratch. These operations are all +## * Roc's compiler optimizes many list operations into in-place mutations behind the scenes, depending on how the list is being used. For example, [List.map], [List.keepIf], and [List.set] can all be optimized to perform in-place mutations. +## * If possible, it is usually best for performance to use large lists in a way where the optimizer can turn them into in-place mutations. If this is not possible, a persistent data structure might be faster - but this is a rare enough scenario that it would not be good for the average Roc program's performance if this were the way [List] worked by default. Instead, you can look outside Roc's standard modules for an implementation of a persistent data structure - likely built using [List] under the hood! +List elem := [ List elem ] isEmpty : List a -> Bool isEmpty = \list -> List.len list == 0 @@ -63,22 +209,134 @@ isEmpty = \list -> get : List a, Nat -> Result a [ OutOfBounds ]* replace : List a, Nat, a -> { list : List a, value : a } +## Replaces the element at the given index with a replacement. +## +## >>> List.set [ "a", "b", "c" ] 1 "B" +## +## If the given index is outside the bounds of the list, returns the original +## list unmodified. +## +## To drop the element at a given index, instead of replacing it, see [List.dropAt]. set : List a, Nat, a -> List a set = \list, index, value -> (List.replace list index value).list +## Add a single element to the end of a list. +## +## >>> List.append [ 1, 2, 3 ] 4 +## +## >>> [ 0, 1, 2 ] +## >>> |> List.append 3 append : List a, a -> List a + +## Add a single element to the beginning of a list. +## +## >>> List.prepend [ 1, 2, 3 ] 0 +## +## >>> [ 2, 3, 4 ] +## >>> |> List.prepend 1 prepend : List a, a -> List a + +## Returns the length of the list - the number of elements it contains. +## +## One [List] can store up to 2,147,483,648 elements (just over 2 billion), which +## is exactly equal to the highest valid #I32 value. This means the #U32 this function +## returns can always be safely converted to an #I32 without losing any data. len : List a -> Nat + +## Put two lists together. +## +## >>> List.concat [ 1, 2, 3 ] [ 4, 5 ] +## +## >>> [ 0, 1, 2 ] +## >>> |> List.concat [ 3, 4 ] concat : List a, List a -> List a + +## Returns the last element in the list, or `ListWasEmpty` if it was empty. last : List a -> Result a [ ListWasEmpty ]* + +## A list with a single element in it. +## +## This is useful in pipelines, like so: +## +## websites = +## Str.concat domain ".com" +## |> List.single +## single : a -> List a +## Returns a list with the given length, where every element is the given value. +## +## repeat : a, Nat -> List a + +## Returns the list with its elements reversed. +## +## >>> List.reverse [ 1, 2, 3 ] reverse : List a -> List a + +## Join the given lists together into one list. +## +## >>> List.join [ [ 1, 2, 3 ], [ 4, 5 ], [], [ 6, 7 ] ] +## +## >>> List.join [ [], [] ] +## +## >>> List.join [] join : List (List a) -> List a contains : List a, a -> Bool + +## Build a value using each element in the list. +## +## Starting with a given `state` value, this walks through each element in the +## list from first to last, running a given `step` function on that element +## which updates the `state`. It returns the final `state` at the end. +## +## You can use it in a pipeline: +## +## [ 2, 4, 8 ] +## |> List.walk { start: 0, step: Num.add } +## +## This returns 14 because: +## * `state` starts at 0 (because of `start: 0`) +## * Each `step` runs `Num.add state elem`, and the return value becomes the new `state`. +## +## Here is a table of how `state` changes as [List.walk] walks over the elements +## `[ 2, 4, 8 ]` using #Num.add as its `step` function to determine the next `state`. +## +## `state` | `elem` | `step state elem` (`Num.add state elem`) +## --------+--------+----------------------------------------- +## 0 | | +## 0 | 2 | 2 +## 2 | 4 | 6 +## 6 | 8 | 14 +## +## So `state` goes through these changes: +## 1. `0` (because of `start: 0`) +## 2. `1` (because of `Num.add state elem` with `state` = 0 and `elem` = 1 +## +## [ 1, 2, 3 ] +## |> List.walk { start: 0, step: Num.sub } +## +## This returns -6 because +## +## Note that in other languages, `walk` is sometimes called `reduce`, +## `fold`, `foldLeft`, or `foldl`. walk : List elem, state, (state, elem -> state) -> state + +## Note that in other languages, `walkBackwards` is sometimes called `reduceRight`, +## `fold`, `foldRight`, or `foldr`. walkBackwards : List elem, state, (state, elem -> state) -> state + +## Same as [List.walk], except you can stop walking early. +## +## ## Performance Details +## +## Compared to [List.walk], this can potentially visit fewer elements (which can +## improve performance) at the cost of making each step take longer. +## However, the added cost to each step is extremely small, and can easily +## be outweighed if it results in skipping even a small number of elements. +## +## As such, it is typically better for performance to use this over [List.walk] +## if returning `Done` earlier than the last element is expected to be common. walkUntil : List elem, state, (state, elem -> [ Continue state, Stop state ]) -> state sum : List (Num a) -> Num a @@ -89,40 +347,201 @@ product : List (Num a) -> Num a product = \list -> List.walk list 1 Num.mul +## Run the given predicate on each element of the list, returning `True` if +## any of the elements satisfy it. any : List a, (a -> Bool) -> Bool + +## Run the given predicate on each element of the list, returning `True` if +## all of the elements satisfy it. all : List a, (a -> Bool) -> Bool +## Run the given function on each element of a list, and return all the +## elements for which the function returned `True`. +## +## >>> List.keepIf [ 1, 2, 3, 4 ] (\num -> num > 2) +## +## ## Performance Details +## +## [List.keepIf] always returns a list that takes up exactly the same amount +## of memory as the original, even if its length decreases. This is because it +## can't know in advance exactly how much space it will need, and if it guesses a +## length that's too low, it would have to re-allocate. +## +## (If you want to do an operation like this which reduces the memory footprint +## of the resulting list, you can do two passes over the lis with [List.walk] - one +## to calculate the precise new size, and another to populate the new list.) +## +## If given a unique list, [List.keepIf] will mutate it in place to assemble the appropriate list. +## If that happens, this function will not allocate any new memory on the heap. +## If all elements in the list end up being kept, Roc will return the original +## list unaltered. +## keepIf : List a, (a -> Bool) -> List a + +## Run the given function on each element of a list, and return all the +## elements for which the function returned `False`. +## +## >>> List.dropIf [ 1, 2, 3, 4 ] (\num -> num > 2) +## +## ## Performance Details +## +## `List.dropIf` has the same performance characteristics as [List.keepIf]. +## See its documentation for details on those characteristics! dropIf : List a, (a -> Bool) -> List a dropIf = \list, predicate -> List.keepIf list (\e -> Bool.not (predicate e)) +## This works like [List.map], except only the transformed values that are +## wrapped in `Ok` are kept. Any that are wrapped in `Err` are dropped. +## +## >>> List.keepOks [ [ "a", "b" ], [], [], [ "c", "d", "e" ] ] List.last +## +## >>> fn = \str -> if Str.isEmpty str then Err StrWasEmpty else Ok (Str.len str) +## >>> +## >>> List.keepOks [ "", "a", "bc", "", "d", "ef", "" ] keepOks : List before, (before -> Result after *) -> List after + +## This works like [List.map], except only the transformed values that are +## wrapped in `Err` are kept. Any that are wrapped in `Ok` are dropped. +## +## >>> List.keepErrs [ [ "a", "b" ], [], [], [ "c", "d", "e" ] ] List.last +## +## >>> fn = \str -> if Str.isEmpty str then Err StrWasEmpty else Ok (Str.len str) +## >>> +## >>> List.keepErrs [ "", "a", "bc", "", "d", "ef", "" ] keepErrs: List before, (before -> Result * after) -> List after + +## Convert each element in the list to something new, by calling a conversion +## function on each of them. Then return a new list of the converted values. +## +## > List.map [ 1, 2, 3 ] (\num -> num + 1) +## +## > List.map [ "", "a", "bc" ] Str.isEmpty map : List a, (a -> b) -> List b + +## Run a transformation function on the first element of each list, +## and use that as the first element in the returned list. +## Repeat until a list runs out of elements. +## +## Some languages have a function named `zip`, which does something similar to +## calling [List.map2] passing two lists and `Pair`: +## +## >>> zipped = List.map2 [ "a", "b", "c" ] [ 1, 2, 3 ] Pair map2 : List a, List b, (a, b -> c) -> List c + +## Run a transformation function on the first element of each list, +## and use that as the first element in the returned list. +## Repeat until a list runs out of elements. map3 : List a, List b, List c, (a, b, c -> d) -> List d + +## Run a transformation function on the first element of each list, +## and use that as the first element in the returned list. +## Repeat until a list runs out of elements. map4 : List a, List b, List c, List d, (a, b, c, d -> e) -> List e + +## This works like [List.map], except it also passes the index +## of the element to the conversion function. mapWithIndex : List a, (a, Nat -> b) -> List b + +## Returns a list of all the integers between one and another, +## including both of the given numbers. +## +## >>> List.range 2 8 range : Int a, Int a -> List (Int a) sortWith : List a, (a, a -> [ LT, EQ, GT ] ) -> List a + +## Sorts a list in ascending order (lowest to highest), using a function which +## specifies a way to represent each element as a number. +## +## To sort in descending order (highest to lowest), use [List.sortDesc] instead. sortAsc : List (Num a) -> List (Num a) sortAsc = \list -> List.sortWith list Num.compare +## Sorts a list in descending order (highest to lowest), using a function which +## specifies a way to represent each element as a number. +## +## To sort in ascending order (lowest to highest), use [List.sortAsc] instead. sortDesc : List (Num a) -> List (Num a) sortDesc = \list -> List.sortWith list (\a, b -> Num.compare b a) swap : List a, Nat, Nat -> List a +## Returns the first element in the list, or `ListWasEmpty` if it was empty. first : List a -> Result a [ ListWasEmpty ]* +## Remove the first element from the list. +## +## Returns the new list (with the removed element missing). dropFirst : List elem -> List elem + +## Remove the last element from the list. +## +## Returns the new list (with the removed element missing). dropLast : List elem -> List elem +## Returns the given number of elements from the beginning of the list. +## +## >>> List.takeFirst 4 [ 1, 2, 3, 4, 5, 6, 7, 8 ] +## +## If there are fewer elements in the list than the requested number, +## returns the entire list. +## +## >>> List.takeFirst 5 [ 1, 2 ] +## +## To *remove* elements from the beginning of the list, use `List.takeLast`. +## +## To remove elements from both the beginning and end of the list, +## use `List.sublist`. +## +## To split the list into two lists, use `List.split`. +## +## ## Performance Details +## +## When given a Unique list, this runs extremely fast. It sets the list's length +## to the given length value, and frees the leftover elements. This runs very +## slightly faster than `List.takeLast`. +## +## In fact, `List.takeFirst 1 list` runs faster than `List.first list` when given +## a Unique list, because [List.first] returns the first element as well - +## which introduces a conditional bounds check as well as a memory load. takeFirst : List elem, Nat -> List elem + +## Returns the given number of elements from the end of the list. +## +## >>> List.takeLast 4 [ 1, 2, 3, 4, 5, 6, 7, 8 ] +## +## If there are fewer elements in the list than the requested number, +## returns the entire list. +## +## >>> List.takeLast 5 [ 1, 2 ] +## +## To *remove* elements from the end of the list, use `List.takeFirst`. +## +## To remove elements from both the beginning and end of the list, +## use `List.sublist`. +## +## To split the list into two lists, use `List.split`. +## +## ## Performance Details +## +## When given a Unique list, this runs extremely fast. It moves the list's +## pointer to the index at the given length value, updates its length, +## and frees the leftover elements. This runs very nearly as fast as +## `List.takeFirst` on a Unique list. +## +## In fact, `List.takeLast 1 list` runs faster than `List.first list` when given +## a Unique list, because [List.first] returns the first element as well - +## which introduces a conditional bounds check as well as a memory load. takeLast : List elem, Nat -> List elem +## Drops n elements from the beginning of the list. drop : List elem, Nat -> List elem + +## Drops the element at the given index from the list. +## +## This has no effect if the given index is outside the bounds of the list. +## +## To replace the element at a given index, instead of dropping it, see [List.set]. dropAt : List elem, Nat -> List elem min : List (Num a) -> Result (Num a) [ ListWasEmpty ]* @@ -163,11 +582,41 @@ maxHelp = \list, initial -> else bestSoFar +## Like [List.map], except the transformation function wraps the return value +## in a list. At the end, all the lists get joined together into one list. +## +## You may know a similar function named `concatMap` in other languages. joinMap : List a, (a -> List b) -> List b joinMap = \list, mapper -> List.walk list [] (\state, elem -> List.concat state (mapper elem)) +## Returns the first element of the list satisfying a predicate function. +## If no satisfying element is found, an `Err NotFound` is returned. find : List elem, (elem -> Bool) -> Result elem [ NotFound ]* + +## Returns a subsection of the given list, beginning at the `start` index and +## including a total of `len` elements. +## +## If `start` is outside the bounds of the given list, returns the empty list. +## +## >>> List.sublist { start: 4, len: 0 } [ 1, 2, 3 ] +## +## If more elements are requested than exist in the list, returns as many as it can. +## +## >>> List.sublist { start: 2, len: 10 } [ 1, 2, 3, 4, 5 ] +## +## > If you want a sublist which goes all the way to the end of the list, no +## > matter how long the list is, `List.takeLast` can do that more efficiently. +## +## Some languages have a function called **`slice`** which works similarly to this. sublist : List elem, { start : Nat, len : Nat } -> List elem intersperse : List elem, elem -> List elem + +## Splits the list into two lists, around the given index. +## +## The returned lists are labeled `before` and `others`. The `before` list will +## contain all the elements whose index in the original list was **less than** +## than the given index, # and the `others` list will be all the others. (This +## means if you give an index of 0, the `before` list will be empty and the +## `others` list will have the same elements as the original list.) split : List elem, Nat -> { before: List elem, others: List elem } From a4b0664d16b0de7224eb81dbd7ad1a960c81bb54 Mon Sep 17 00:00:00 2001 From: Nuno Ferreira Date: Fri, 6 May 2022 10:39:46 +0200 Subject: [PATCH 840/846] Migrated List.roc docs over to builtins/roc/List.roc --- compiler/builtins/docs/List.roc | 705 -------------------------------- compiler/builtins/roc/List.roc | 449 ++++++++++++++++++++ 2 files changed, 449 insertions(+), 705 deletions(-) delete mode 100644 compiler/builtins/docs/List.roc diff --git a/compiler/builtins/docs/List.roc b/compiler/builtins/docs/List.roc deleted file mode 100644 index 3a57d27235..0000000000 --- a/compiler/builtins/docs/List.roc +++ /dev/null @@ -1,705 +0,0 @@ -interface List - exposes - [ - List, - append, - concat, - contains, - drop, - dropAt, - dropLast, - first, - get, - isEmpty, - join, - keepErrs, - keepIf, - keepOks, - last, - len, - map, - map2, - map3, - map4, - mapJoin, - mapOrDrop, - mapWithIndex, - prepend, - product, - range, - repeat, - reverse, - set, - single, - sortWith, - split, - sublist, - sum, - swap, - walk, - walkBackwards, - walkUntil - ] - imports [] - -## Types - -## A sequential list of values. -## -## >>> [ 1, 2, 3 ] # a list of numbers -## >>> [ "a", "b", "c" ] # a list of strings -## >>> [ [ 1.1 ], [], [ 2.2, 3.3 ] ] # a list of lists of numbers -## -## The list `[ 1, "a" ]` gives an error, because each element in a list must have -## the same type. If you want to put a mix of [I64] and [Str] values into a list, try this: -## -## ``` -## mixedList : List [ IntElem I64, StrElem Str ]* -## mixedList = [ IntElem 1, IntElem 2, StrElem "a", StrElem "b" ] -## ``` -## -## The maximum size of a [List] is limited by the amount of heap memory available -## to the current process. If there is not enough memory available, attempting to -## create the list could crash. (On Linux, where [overcommit](https://www.etalabs.net/overcommit.html) -## is normally enabled, not having enough memory could result in the list appearing -## to be created just fine, but then crashing later.) -## -## > The theoretical maximum length for a list created in Roc is half of -## > `Num.maxNat`. Attempting to create a list bigger than that -## > in Roc code will always fail, although in practice it is likely to fail -## > at much smaller lengths due to insufficient memory being available. -## -## ## Performance Details -## -## Under the hood, a list is a record containing a `len : Nat` field as well -## as a pointer to a reference count and a flat array of bytes. Unique lists -## store a capacity #Nat instead of a reference count. -## -## ## Shared Lists -## -## Shared lists are [reference counted](https://en.wikipedia.org/wiki/Reference_counting). -## -## Each time a given list gets referenced, its reference count ("refcount" for short) -## gets incremented. Each time a list goes out of scope, its refcount count gets -## decremented. Once a refcount, has been decremented more times than it has been -## incremented, we know nothing is referencing it anymore, and the list's memory -## will be immediately freed. -## -## Let's look at an example. -## -## ratings = [ 5, 4, 3 ] -## -## { foo: ratings, bar: ratings } -## -## The first line binds the name `ratings` to the list `[ 5, 4, 3 ]`. The list -## begins with a refcount of 1, because so far only `ratings` is referencing it. -## -## The second line alters this refcount. `{ foo: ratings` references -## the `ratings` list, which will result in its refcount getting incremented -## from 0 to 1. Similarly, `bar: ratings }` also references the `ratings` list, -## which will result in its refcount getting incremented from 1 to 2. -## -## Let's turn this example into a function. -## -## getRatings = \first -> -## ratings = [ first, 4, 3 ] -## -## { foo: ratings, bar: ratings } -## -## getRatings 5 -## -## At the end of the `getRatings` function, when the record gets returned, -## the original `ratings =` binding has gone out of scope and is no longer -## accessible. (Trying to reference `ratings` outside the scope of the -## `getRatings` function would be an error!) -## -## Since `ratings` represented a way to reference the list, and that way is no -## longer accessible, the list's refcount gets decremented when `ratings` goes -## out of scope. It will decrease from 2 back down to 1. -## -## Putting these together, when we call `getRatings 5`, what we get back is -## a record with two fields, `foo`, and `bar`, each of which refers to the same -## list, and that list has a refcount of 1. -## -## Let's change the last line to be `(getRatings 5).bar` instead of `getRatings 5`: -## -## getRatings = \first -> -## ratings = [ first, 4, 3 ] -## -## { foo: ratings, bar: ratings } -## -## (getRatings 5).bar -## -## Now, when this expression returns, only the `bar` field of the record will -## be returned. This will mean that the `foo` field becomes inaccessible, causing -## the list's refcount to get decremented from 2 to 1. At this point, the list is back -## where it started: there is only 1 reference to it. -## -## Finally let's suppose the final line were changed to this: -## -## List.first (getRatings 5).bar -## -## This call to [List.first] means that even the list in the `bar` field has become -## inaccessible. As such, this line will cause the list's refcount to get -## decremented all the way to 0. At that point, nothing is referencing the list -## anymore, and its memory will get freed. -## -## Things are different if this is a list of lists instead of a list of numbers. -## Let's look at a simpler example using [List.first] - first with a list of numbers, -## and then with a list of lists, to see how they differ. -## -## Here's the example using a list of numbers. -## -## nums = [ 1, 2, 3, 4, 5, 6, 7 ] -## -## first = List.first nums -## last = List.last nums -## -## first -## -## It makes a list, calls [List.first] and [List.last] on it, and then returns `first`. -## -## Here's the equivalent code with a list of lists: -## -## lists = [ [ 1 ], [ 2, 3 ], [], [ 4, 5, 6, 7 ] ] -## -## first = List.first lists -## last = List.last lists -## -## first -## -## TODO explain how in the former example, when we go to free `nums` at the end, -## we can free it immediately because there are no other refcounts. However, -## in the case of `lists`, we have to iterate through the list and decrement -## the refcounts of each of its contained lists - because they, too, have -## refcounts! Importantly, because the first element had its refcount incremented -## because the function returned `first`, that element will actually end up -## *not* getting freed at the end - but all the others will be. -## -## In the `lists` example, `lists = [ ... ]` also creates a list with an initial -## refcount of 1. Separately, it also creates several other lists - each with -## their own refcounts - to go inside that list. (The empty list at the end -## does not use heap memory, and thus has no refcount.) -## -## At the end, we once again call [List.first] on the list, but this time -## -## * Copying small lists (64 elements or fewer) is typically slightly faster than copying small persistent data structures. This is because, at small sizes, persistent data structures tend to be thin wrappers around flat arrays anyway. They don't have any copying advantage until crossing a certain minimum size threshold. -## * Even when copying is faster, other list operations may still be slightly slower with persistent data structures. For example, even if it were a persistent data structure, [List.map], [List.walk], and [List.keepIf] would all need to traverse every element in the list and build up the result from scratch. These operations are all -## * Roc's compiler optimizes many list operations into in-place mutations behind the scenes, depending on how the list is being used. For example, [List.map], [List.keepIf], and [List.set] can all be optimized to perform in-place mutations. -## * If possible, it is usually best for performance to use large lists in a way where the optimizer can turn them into in-place mutations. If this is not possible, a persistent data structure might be faster - but this is a rare enough scenario that it would not be good for the average Roc program's performance if this were the way [List] worked by default. Instead, you can look outside Roc's standard modules for an implementation of a persistent data structure - likely built using [List] under the hood! -List elem := [ List elem ] - -## Initialize - -## A list with a single element in it. -## -## This is useful in pipelines, like so: -## -## websites = -## Str.concat domain ".com" -## |> List.single -## -single : elem -> List elem - -## An empty list. -empty : List * - -## Returns a list with the given length, where every element is the given value. -## -## -repeat : elem, Nat -> List elem - -## Returns a list of all the integers between one and another, -## including both of the given numbers. -## -## >>> List.range 2 8 -range : Int a, Int a -> List (Int a) - -## Transform - -## Returns the list with its elements reversed. -## -## >>> List.reverse [ 1, 2, 3 ] -reverse : List elem -> List elem - -## Sorts a list using a function which specifies how two elements are ordered. -## -## When sorting by numeric values, it's more efficient to use [sortAsc] or -## [sortDesc] instead. -sort : List elem, (elem, elem -> [ Lt, Eq, Gt ]) -> List elem - -## Sorts a list in ascending order (lowest to highest), using a function which -## specifies a way to represent each element as a number. -## -## This is more efficient than [sort] because it skips -## calculating the `[ Lt, Eq, Gt ]` value and uses the number directly instead. -## -## To sort in descending order (highest to lowest), use [List.sortDesc] instead. -sortAsc : List elem, (elem -> Num *) -> List elem - -## Sorts a list in descending order (highest to lowest), using a function which -## specifies a way to represent each element as a number. -## -## This is more efficient than [sort] because it skips -## calculating the `[ Lt, Eq, Gt ]` value and uses the number directly instead. -## -## To sort in ascending order (lowest to highest), use [List.sortAsc] instead. -sortDesc : List elem, (elem -> Num *) -> List elem - -## Convert each element in the list to something new, by calling a conversion -## function on each of them. Then return a new list of the converted values. -## -## > List.map [ 1, 2, 3 ] (\num -> num + 1) -## -## > List.map [ "", "a", "bc" ] Str.isEmpty -## -## `map` functions like this are common in Roc, and they all work similarly. -## See for example `Set.map`, `Dict.map`, and [Result.map]. -map : List before, (before -> after) -> List after - -## Run a transformation function on the first element of each list, -## and use that as the first element in the returned list. -## Repeat until a list runs out of elements. -## -## Some languages have a function named `zip`, which does something similar to -## calling [List.map2] passing two lists and `Pair`: -## -## >>> zipped = List.map2 [ "a", "b", "c" ] [ 1, 2, 3 ] Pair -map2 : List a, List b, (a, b -> c) -> List c - -## Run a transformation function on the first element of each list, -## and use that as the first element in the returned list. -## Repeat until a list runs out of elements. -map3 : List a, List b, List c, (a, b, c -> d) -> List d - -## Run a transformation function on the first element of each list, -## and use that as the first element in the returned list. -## Repeat until a list runs out of elements. -map4 : List a, List b, List c, List d, (a, b, c, d -> e) -> List e - -## This works like [List.map], except it also passes the index -## of the element to the conversion function. -mapWithIndex : List before, (before, Nat -> after) -> List after - -## This works like [List.map], except at any time you can return `Err` to -## cancel the entire operation immediately, and return that #Err. -mapOrCancel : List before, (before -> Result after err) -> Result (List after) err - -## Like [List.map], except the transformation function specifies whether to -## `Keep` or `Drop` each element from the final [List]. -## -## You may know a similar function named `filterMap` in other languages. -mapOrDrop : List before, (before -> [ Keep after, Drop ]) -> List after - -## Like [List.map], except the transformation function wraps the return value -## in a list. At the end, all the lists get joined together into one list. -## -## You may know a similar function named `concatMap` in other languages. -mapJoin : List before, (before -> List after) -> List after - -## This works like [List.map], except only the transformed values that are -## wrapped in `Ok` are kept. Any that are wrapped in `Err` are dropped. -## -## >>> List.mapOks [ [ "a", "b" ], [], [], [ "c", "d", "e" ] ] List.last -## -## >>> fn = \str -> if Str.isEmpty str then Err StrWasEmpty else Ok (Str.len str) -## >>> -## >>> List.mapOks [ "", "a", "bc", "", "d", "ef", "" ] -mapOks : List before, (before -> Result after *) -> List after - -## Returns a list with the element at the given index having been transformed by -## the given function. -## -## For a version of this which gives you more control over when to perform -## the transformation, see `List.updater` -## -## ## Performance notes -## -## In particular when updating nested collections, this is potentially much more -## efficient than using [List.get] to obtain the element, transforming it, -## and then putting it back in the same place. -update : List elem, Nat, (elem -> elem) -> List elem - -## A more flexible version of `List.update`, which returns an "updater" function -## that lets you delay performing the update until later. -updater : List elem, Nat -> { elem, new : (elem -> List elem) } - -## If all the elements in the list are #Ok, return a new list containing the -## contents of those #Ok tags. If any elements are #Err, return #Err. -allOks : List (Result ok err) -> Result (List ok) err - -## Add a single element to the end of a list. -## -## >>> List.append [ 1, 2, 3 ] 4 -## -## >>> [ 0, 1, 2 ] -## >>> |> List.append 3 -append : List elem, elem -> List elem - -## Add a single element to the beginning of a list. -## -## >>> List.prepend [ 1, 2, 3 ] 0 -## -## >>> [ 2, 3, 4 ] -## >>> |> List.prepend 1 -prepend : List elem, elem -> List elem - -## Put two lists together. -## -## >>> List.concat [ 1, 2, 3 ] [ 4, 5 ] -## -## >>> [ 0, 1, 2 ] -## >>> |> List.concat [ 3, 4 ] -concat : List elem, List elem -> List elem - -## Join the given lists together into one list. -## -## >>> List.join [ [ 1, 2, 3 ], [ 4, 5 ], [], [ 6, 7 ] ] -## -## >>> List.join [ [], [] ] -## -## >>> List.join [] -join : List (List elem) -> List elem - -## Like [List.join], but only keeps elements tagged with `Ok`. Elements -## tagged with `Err` are dropped. -## -## This can be useful after using an operation that returns a #Result -## on each element of a list, for example [List.first]: -## -## >>> [ [ 1, 2, 3 ], [], [], [ 4, 5 ] ] -## >>> |> List.map List.first -## >>> |> List.joinOks -## -## Eventually, `oks` type signature will be `List [Ok elem]* -> List elem`. -## The implementation for that is a lot tricker then `List (Result elem *)` -## so we're sticking with `Result` for now. -oks : List (Result elem *) -> List elem - -## Filter - -## Run the given function on each element of a list, and return all the -## elements for which the function returned `True`. -## -## >>> List.keepIf [ 1, 2, 3, 4 ] (\num -> num > 2) -## -## ## Performance Details -## -## [List.keepIf] always returns a list that takes up exactly the same amount -## of memory as the original, even if its length decreases. This is because it -## can't know in advance exactly how much space it will need, and if it guesses a -## length that's too low, it would have to re-allocate. -## -## (If you want to do an operation like this which reduces the memory footprint -## of the resulting list, you can do two passes over the lis with [List.walk] - one -## to calculate the precise new size, and another to populate the new list.) -## -## If given a unique list, [List.keepIf] will mutate it in place to assemble the appropriate list. -## If that happens, this function will not allocate any new memory on the heap. -## If all elements in the list end up being kept, Roc will return the original -## list unaltered. -## -keepIf : List elem, (elem -> Bool) -> List elem - -## Run the given function on each element of a list, and return all the -## elements for which the function returned `False`. -## -## >>> List.dropIf [ 1, 2, 3, 4 ] (\num -> num > 2) -## -## ## Performance Details -## -## `List.dropIf` has the same performance characteristics as [List.keepIf]. -## See its documentation for details on those characteristics! -dropIf : List elem, (elem -> Bool) -> List elem - -## Access - -## Returns the first element in the list, or `ListWasEmpty` if it was empty. -first : List elem -> Result elem [ ListWasEmpty ]* - -## Returns the last element in the list, or `ListWasEmpty` if it was empty. -last : List elem -> Result elem [ ListWasEmpty ]* - -get : List elem, Nat -> Result elem [ OutOfBounds ]* - -max : List (Num a) -> Result (Num a) [ ListWasEmpty ]* - -min : List (Num a) -> Result (Num a) [ ListWasEmpty ]* - -## Modify - -## Replaces the element at the given index with a replacement. -## -## >>> List.set [ "a", "b", "c" ] 1 "B" -## -## If the given index is outside the bounds of the list, returns the original -## list unmodified. -## -## To drop the element at a given index, instead of replacing it, see [List.dropAt]. -set : List elem, Nat, elem -> List elem - -## Drops n elements from the beginning of the list. -drop : List elem, Nat -> List elem - -## Drops the element at the given index from the list. -## -## This has no effect if the given index is outside the bounds of the list. -## -## To replace the element at a given index, instead of dropping it, see [List.set]. -dropAt : List elem, Nat -> List elem - -## Adds a new element to the end of the list. -## -## >>> List.append [ "a", "b" ] "c" -## -## ## Performance Details -## -## When given a Unique list, this adds the new element in-place if possible. -## This is only possible if the list has enough capacity. Otherwise, it will -## have to *clone and grow*. See the section on [capacity](#capacity) in this -## module's documentation. -append : List elem, elem -> List elem - -## Adds a new element to the beginning of the list. -## -## >>> List.prepend [ "b", "c" ] "a" -## -## ## Performance Details -## -## This always clones the entire list, even when given a Unique list. That means -## it runs about as fast as `List.addLast` when both are given a Shared list. -## -## If you have a Unique list instead, [List.append] will run much faster than -## [List.append] except in the specific case where the list has no excess capacity, -## and needs to *clone and grow*. In that uncommon case, both [List.append] and -## [List.append] will run at about the same speed—since [List.append] always -## has to clone and grow. -## -## | Unique list | Shared list | -##---------+--------------------------------+----------------+ -## append | in-place given enough capacity | clone and grow | -## prepend | clone and grow | clone and grow | -prepend : List elem, elem -> List elem - -## Remove the last element from the list. -## -## Returns both the removed element as well as the new list (with the removed -## element missing), or `Err ListWasEmpty` if the list was empty. -## -## Here's one way you can use this: -## -## when List.pop list is -## Ok { others, last } -> ... -## Err ListWasEmpty -> ... -## -## ## Performance Details -## -## Calling `List.pop` on a Unique list runs extremely fast. It's essentially -## the same as a [List.last] except it also returns the [List] it was given, -## with its length decreased by 1. -## -## In contrast, calling `List.pop` on a Shared list creates a new list, then -## copies over every element in the original list except the last one. This -## takes much longer. -dropLast : List elem -> Result { others : List elem, last : elem } [ ListWasEmpty ]* - -## -## Here's one way you can use this: -## -## when List.pop list is -## Ok { others, last } -> ... -## Err ListWasEmpty -> ... -## -## ## Performance Details -## -## When calling either `List.dropFirst` or `List.dropLast` on a Unique list, `List.dropLast` -## runs *much* faster. This is because for `List.dropLast`, removing the last element -## in-place is as easy as reducing the length of the list by 1. In contrast, -## removing the first element from the list involves copying every other element -## in the list into the index before it - which is massively more costly. -## -## In the case of a Shared list, -## -## | Unique list | Shared list | -##-----------+----------------------------------+---------------------------------+ -## dropFirst | [List.last] + length change | [List.last] + clone rest of list | -## dropLast | [List.last] + clone rest of list | [List.last] + clone rest of list | -dropFirst : List elem -> Result { first: elem, others : List elem } [ ListWasEmpty ]* - -## Returns the given number of elements from the beginning of the list. -## -## >>> List.takeFirst 4 [ 1, 2, 3, 4, 5, 6, 7, 8 ] -## -## If there are fewer elements in the list than the requested number, -## returns the entire list. -## -## >>> List.takeFirst 5 [ 1, 2 ] -## -## To *remove* elements from the beginning of the list, use `List.takeLast`. -## -## To remove elements from both the beginning and end of the list, -## use `List.sublist`. -## -## To split the list into two lists, use `List.split`. -## -## ## Performance Details -## -## When given a Unique list, this runs extremely fast. It sets the list's length -## to the given length value, and frees the leftover elements. This runs very -## slightly faster than `List.takeLast`. -## -## In fact, `List.takeFirst 1 list` runs faster than `List.first list` when given -## a Unique list, because [List.first] returns the first element as well - -## which introduces a conditional bounds check as well as a memory load. -takeFirst : List elem, Nat -> List elem - -## Returns the given number of elements from the end of the list. -## -## >>> List.takeLast 4 [ 1, 2, 3, 4, 5, 6, 7, 8 ] -## -## If there are fewer elements in the list than the requested number, -## returns the entire list. -## -## >>> List.takeLast 5 [ 1, 2 ] -## -## To *remove* elements from the end of the list, use `List.takeFirst`. -## -## To remove elements from both the beginning and end of the list, -## use `List.sublist`. -## -## To split the list into two lists, use `List.split`. -## -## ## Performance Details -## -## When given a Unique list, this runs extremely fast. It moves the list's -## pointer to the index at the given length value, updates its length, -## and frees the leftover elements. This runs very nearly as fast as -## `List.takeFirst` on a Unique list. -## -## In fact, `List.takeLast 1 list` runs faster than `List.first list` when given -## a Unique list, because [List.first] returns the first element as well - -## which introduces a conditional bounds check as well as a memory load. -takeLast : List elem, Nat -> List elem - -## Deconstruct - -## Splits the list into two lists, around the given index. -## -## The returned lists are labeled `before` and `others`. The `before` list will -## contain all the elements whose index in the original list was **less than** -## than the given index, # and the `others` list will be all the others. (This -## means if you give an index of 0, the `before` list will be empty and the -## `others` list will have the same elements as the original list.) -split : List elem, Nat -> { before: List elem, others: List elem } - -## Returns a subsection of the given list, beginning at the `start` index and -## including a total of `len` elements. -## -## If `start` is outside the bounds of the given list, returns the empty list. -## -## >>> List.sublist { start: 4, len: 0 } [ 1, 2, 3 ] -## -## If more elements are requested than exist in the list, returns as many as it can. -## -## >>> List.sublist { start: 2, len: 10 } [ 1, 2, 3, 4, 5 ] -## -## > If you want a sublist which goes all the way to the end of the list, no -## > matter how long the list is, `List.takeLast` can do that more efficiently. -## -## Some languages have a function called **`slice`** which works similarly to this. -sublist : List elem, { start : Nat, len : Nat } -> List elem - -## Build a value using each element in the list. -## -## Starting with a given `state` value, this walks through each element in the -## list from first to last, running a given `step` function on that element -## which updates the `state`. It returns the final `state` at the end. -## -## You can use it in a pipeline: -## -## [ 2, 4, 8 ] -## |> List.walk { start: 0, step: Num.add } -## -## This returns 14 because: -## * `state` starts at 0 (because of `start: 0`) -## * Each `step` runs `Num.add state elem`, and the return value becomes the new `state`. -## -## Here is a table of how `state` changes as [List.walk] walks over the elements -## `[ 2, 4, 8 ]` using #Num.add as its `step` function to determine the next `state`. -## -## `state` | `elem` | `step state elem` (`Num.add state elem`) -## --------+--------+----------------------------------------- -## 0 | | -## 0 | 2 | 2 -## 2 | 4 | 6 -## 6 | 8 | 14 -## -## So `state` goes through these changes: -## 1. `0` (because of `start: 0`) -## 2. `1` (because of `Num.add state elem` with `state` = 0 and `elem` = 1 -## -## [ 1, 2, 3 ] -## |> List.walk { start: 0, step: Num.sub } -## -## This returns -6 because -## -## Note that in other languages, `walk` is sometimes called `reduce`, -## `fold`, `foldLeft`, or `foldl`. -walk : List elem, state, (state, elem -> state) -> state - -## Note that in other languages, `walkBackwards` is sometimes called `reduceRight`, -## `fold`, `foldRight`, or `foldr`. -walkBackwards : List elem, state, (state, elem -> state) -> state - -## Same as [List.walk], except you can stop walking early. -## -## ## Performance Details -## -## Compared to [List.walk], this can potentially visit fewer elements (which can -## improve performance) at the cost of making each step take longer. -## However, the added cost to each step is extremely small, and can easily -## be outweighed if it results in skipping even a small number of elements. -## -## As such, it is typically better for performance to use this over [List.walk] -## if returning `Done` earlier than the last element is expected to be common. -walkUntil : List elem, state, (state, elem -> [ Continue state, Done state ]) -> state - -# Same as [List.walk]Backwards, except you can stop walking early. -walkBackwardsUntil : List elem, state, (state, elem -> [ Continue state, Done state ]) -> state - -## Check - -## Returns the length of the list - the number of elements it contains. -## -## One [List] can store up to 2,147,483,648 elements (just over 2 billion), which -## is exactly equal to the highest valid #I32 value. This means the #U32 this function -## returns can always be safely converted to an #I32 without losing any data. -len : List * -> Nat - -isEmpty : List * -> Bool - -contains : List elem, elem -> Bool - -startsWith : List elem, List elem -> Bool - -endsWith : List elem, List elem -> Bool - -## Run the given predicate on each element of the list, returning `True` if -## any of the elements satisfy it. -any : List elem, (elem -> Bool) -> Bool - -## Run the given predicate on each element of the list, returning `True` if -## all of the elements satisfy it. -all : List elem, (elem -> Bool) -> Bool - -## Returns the first element of the list satisfying a predicate function. -## If no satisfying element is found, an `Err NotFound` is returned. -find : List elem, (elem -> Bool) -> Result elem [ NotFound ]* - -## Apply a function that returns a Result on a list, only successful -## Results are kept and returned unwrapped. -keepOks : List before, (before -> Result after *) -> List after - -## Apply a function that returns a Result on a list, only unsuccessful -## Results are kept and returned unwrapped. -keepErrs : List before, (before -> Result * after) -> List after diff --git a/compiler/builtins/roc/List.roc b/compiler/builtins/roc/List.roc index 42de7f03ef..483fdbf601 100644 --- a/compiler/builtins/roc/List.roc +++ b/compiler/builtins/roc/List.roc @@ -56,6 +56,152 @@ interface List Bool.{ Bool } ] +## Types + +## A sequential list of values. +## +## >>> [ 1, 2, 3 ] # a list of numbers +## >>> [ "a", "b", "c" ] # a list of strings +## >>> [ [ 1.1 ], [], [ 2.2, 3.3 ] ] # a list of lists of numbers +## +## The list `[ 1, "a" ]` gives an error, because each element in a list must have +## the same type. If you want to put a mix of [I64] and [Str] values into a list, try this: +## +## ``` +## mixedList : List [ IntElem I64, StrElem Str ]* +## mixedList = [ IntElem 1, IntElem 2, StrElem "a", StrElem "b" ] +## ``` +## +## The maximum size of a [List] is limited by the amount of heap memory available +## to the current process. If there is not enough memory available, attempting to +## create the list could crash. (On Linux, where [overcommit](https://www.etalabs.net/overcommit.html) +## is normally enabled, not having enough memory could result in the list appearing +## to be created just fine, but then crashing later.) +## +## > The theoretical maximum length for a list created in Roc is half of +## > `Num.maxNat`. Attempting to create a list bigger than that +## > in Roc code will always fail, although in practice it is likely to fail +## > at much smaller lengths due to insufficient memory being available. +## +## ## Performance Details +## +## Under the hood, a list is a record containing a `len : Nat` field as well +## as a pointer to a reference count and a flat array of bytes. Unique lists +## store a capacity #Nat instead of a reference count. +## +## ## Shared Lists +## +## Shared lists are [reference counted](https://en.wikipedia.org/wiki/Reference_counting). +## +## Each time a given list gets referenced, its reference count ("refcount" for short) +## gets incremented. Each time a list goes out of scope, its refcount count gets +## decremented. Once a refcount, has been decremented more times than it has been +## incremented, we know nothing is referencing it anymore, and the list's memory +## will be immediately freed. +## +## Let's look at an example. +## +## ratings = [ 5, 4, 3 ] +## +## { foo: ratings, bar: ratings } +## +## The first line binds the name `ratings` to the list `[ 5, 4, 3 ]`. The list +## begins with a refcount of 1, because so far only `ratings` is referencing it. +## +## The second line alters this refcount. `{ foo: ratings` references +## the `ratings` list, which will result in its refcount getting incremented +## from 0 to 1. Similarly, `bar: ratings }` also references the `ratings` list, +## which will result in its refcount getting incremented from 1 to 2. +## +## Let's turn this example into a function. +## +## getRatings = \first -> +## ratings = [ first, 4, 3 ] +## +## { foo: ratings, bar: ratings } +## +## getRatings 5 +## +## At the end of the `getRatings` function, when the record gets returned, +## the original `ratings =` binding has gone out of scope and is no longer +## accessible. (Trying to reference `ratings` outside the scope of the +## `getRatings` function would be an error!) +## +## Since `ratings` represented a way to reference the list, and that way is no +## longer accessible, the list's refcount gets decremented when `ratings` goes +## out of scope. It will decrease from 2 back down to 1. +## +## Putting these together, when we call `getRatings 5`, what we get back is +## a record with two fields, `foo`, and `bar`, each of which refers to the same +## list, and that list has a refcount of 1. +## +## Let's change the last line to be `(getRatings 5).bar` instead of `getRatings 5`: +## +## getRatings = \first -> +## ratings = [ first, 4, 3 ] +## +## { foo: ratings, bar: ratings } +## +## (getRatings 5).bar +## +## Now, when this expression returns, only the `bar` field of the record will +## be returned. This will mean that the `foo` field becomes inaccessible, causing +## the list's refcount to get decremented from 2 to 1. At this point, the list is back +## where it started: there is only 1 reference to it. +## +## Finally let's suppose the final line were changed to this: +## +## List.first (getRatings 5).bar +## +## This call to [List.first] means that even the list in the `bar` field has become +## inaccessible. As such, this line will cause the list's refcount to get +## decremented all the way to 0. At that point, nothing is referencing the list +## anymore, and its memory will get freed. +## +## Things are different if this is a list of lists instead of a list of numbers. +## Let's look at a simpler example using [List.first] - first with a list of numbers, +## and then with a list of lists, to see how they differ. +## +## Here's the example using a list of numbers. +## +## nums = [ 1, 2, 3, 4, 5, 6, 7 ] +## +## first = List.first nums +## last = List.last nums +## +## first +## +## It makes a list, calls [List.first] and [List.last] on it, and then returns `first`. +## +## Here's the equivalent code with a list of lists: +## +## lists = [ [ 1 ], [ 2, 3 ], [], [ 4, 5, 6, 7 ] ] +## +## first = List.first lists +## last = List.last lists +## +## first +## +## TODO explain how in the former example, when we go to free `nums` at the end, +## we can free it immediately because there are no other refcounts. However, +## in the case of `lists`, we have to iterate through the list and decrement +## the refcounts of each of its contained lists - because they, too, have +## refcounts! Importantly, because the first element had its refcount incremented +## because the function returned `first`, that element will actually end up +## *not* getting freed at the end - but all the others will be. +## +## In the `lists` example, `lists = [ ... ]` also creates a list with an initial +## refcount of 1. Separately, it also creates several other lists - each with +## their own refcounts - to go inside that list. (The empty list at the end +## does not use heap memory, and thus has no refcount.) +## +## At the end, we once again call [List.first] on the list, but this time +## +## * Copying small lists (64 elements or fewer) is typically slightly faster than copying small persistent data structures. This is because, at small sizes, persistent data structures tend to be thin wrappers around flat arrays anyway. They don't have any copying advantage until crossing a certain minimum size threshold. +## * Even when copying is faster, other list operations may still be slightly slower with persistent data structures. For example, even if it were a persistent data structure, [List.map], [List.walk], and [List.keepIf] would all need to traverse every element in the list and build up the result from scratch. These operations are all +## * Roc's compiler optimizes many list operations into in-place mutations behind the scenes, depending on how the list is being used. For example, [List.map], [List.keepIf], and [List.set] can all be optimized to perform in-place mutations. +## * If possible, it is usually best for performance to use large lists in a way where the optimizer can turn them into in-place mutations. If this is not possible, a persistent data structure might be faster - but this is a rare enough scenario that it would not be good for the average Roc program's performance if this were the way [List] worked by default. Instead, you can look outside Roc's standard modules for an implementation of a persistent data structure - likely built using [List] under the hood! +List elem := [ List elem ] isEmpty : List a -> Bool isEmpty = \list -> List.len list == 0 @@ -63,22 +209,134 @@ isEmpty = \list -> get : List a, Nat -> Result a [ OutOfBounds ]* replace : List a, Nat, a -> { list : List a, value : a } +## Replaces the element at the given index with a replacement. +## +## >>> List.set [ "a", "b", "c" ] 1 "B" +## +## If the given index is outside the bounds of the list, returns the original +## list unmodified. +## +## To drop the element at a given index, instead of replacing it, see [List.dropAt]. set : List a, Nat, a -> List a set = \list, index, value -> (List.replace list index value).list +## Add a single element to the end of a list. +## +## >>> List.append [ 1, 2, 3 ] 4 +## +## >>> [ 0, 1, 2 ] +## >>> |> List.append 3 append : List a, a -> List a + +## Add a single element to the beginning of a list. +## +## >>> List.prepend [ 1, 2, 3 ] 0 +## +## >>> [ 2, 3, 4 ] +## >>> |> List.prepend 1 prepend : List a, a -> List a + +## Returns the length of the list - the number of elements it contains. +## +## One [List] can store up to 2,147,483,648 elements (just over 2 billion), which +## is exactly equal to the highest valid #I32 value. This means the #U32 this function +## returns can always be safely converted to an #I32 without losing any data. len : List a -> Nat + +## Put two lists together. +## +## >>> List.concat [ 1, 2, 3 ] [ 4, 5 ] +## +## >>> [ 0, 1, 2 ] +## >>> |> List.concat [ 3, 4 ] concat : List a, List a -> List a + +## Returns the last element in the list, or `ListWasEmpty` if it was empty. last : List a -> Result a [ ListWasEmpty ]* + +## A list with a single element in it. +## +## This is useful in pipelines, like so: +## +## websites = +## Str.concat domain ".com" +## |> List.single +## single : a -> List a +## Returns a list with the given length, where every element is the given value. +## +## repeat : a, Nat -> List a + +## Returns the list with its elements reversed. +## +## >>> List.reverse [ 1, 2, 3 ] reverse : List a -> List a + +## Join the given lists together into one list. +## +## >>> List.join [ [ 1, 2, 3 ], [ 4, 5 ], [], [ 6, 7 ] ] +## +## >>> List.join [ [], [] ] +## +## >>> List.join [] join : List (List a) -> List a contains : List a, a -> Bool + +## Build a value using each element in the list. +## +## Starting with a given `state` value, this walks through each element in the +## list from first to last, running a given `step` function on that element +## which updates the `state`. It returns the final `state` at the end. +## +## You can use it in a pipeline: +## +## [ 2, 4, 8 ] +## |> List.walk { start: 0, step: Num.add } +## +## This returns 14 because: +## * `state` starts at 0 (because of `start: 0`) +## * Each `step` runs `Num.add state elem`, and the return value becomes the new `state`. +## +## Here is a table of how `state` changes as [List.walk] walks over the elements +## `[ 2, 4, 8 ]` using #Num.add as its `step` function to determine the next `state`. +## +## `state` | `elem` | `step state elem` (`Num.add state elem`) +## --------+--------+----------------------------------------- +## 0 | | +## 0 | 2 | 2 +## 2 | 4 | 6 +## 6 | 8 | 14 +## +## So `state` goes through these changes: +## 1. `0` (because of `start: 0`) +## 2. `1` (because of `Num.add state elem` with `state` = 0 and `elem` = 1 +## +## [ 1, 2, 3 ] +## |> List.walk { start: 0, step: Num.sub } +## +## This returns -6 because +## +## Note that in other languages, `walk` is sometimes called `reduce`, +## `fold`, `foldLeft`, or `foldl`. walk : List elem, state, (state, elem -> state) -> state + +## Note that in other languages, `walkBackwards` is sometimes called `reduceRight`, +## `fold`, `foldRight`, or `foldr`. walkBackwards : List elem, state, (state, elem -> state) -> state + +## Same as [List.walk], except you can stop walking early. +## +## ## Performance Details +## +## Compared to [List.walk], this can potentially visit fewer elements (which can +## improve performance) at the cost of making each step take longer. +## However, the added cost to each step is extremely small, and can easily +## be outweighed if it results in skipping even a small number of elements. +## +## As such, it is typically better for performance to use this over [List.walk] +## if returning `Done` earlier than the last element is expected to be common. walkUntil : List elem, state, (state, elem -> [ Continue state, Stop state ]) -> state sum : List (Num a) -> Num a @@ -89,40 +347,201 @@ product : List (Num a) -> Num a product = \list -> List.walk list 1 Num.mul +## Run the given predicate on each element of the list, returning `True` if +## any of the elements satisfy it. any : List a, (a -> Bool) -> Bool + +## Run the given predicate on each element of the list, returning `True` if +## all of the elements satisfy it. all : List a, (a -> Bool) -> Bool +## Run the given function on each element of a list, and return all the +## elements for which the function returned `True`. +## +## >>> List.keepIf [ 1, 2, 3, 4 ] (\num -> num > 2) +## +## ## Performance Details +## +## [List.keepIf] always returns a list that takes up exactly the same amount +## of memory as the original, even if its length decreases. This is because it +## can't know in advance exactly how much space it will need, and if it guesses a +## length that's too low, it would have to re-allocate. +## +## (If you want to do an operation like this which reduces the memory footprint +## of the resulting list, you can do two passes over the lis with [List.walk] - one +## to calculate the precise new size, and another to populate the new list.) +## +## If given a unique list, [List.keepIf] will mutate it in place to assemble the appropriate list. +## If that happens, this function will not allocate any new memory on the heap. +## If all elements in the list end up being kept, Roc will return the original +## list unaltered. +## keepIf : List a, (a -> Bool) -> List a + +## Run the given function on each element of a list, and return all the +## elements for which the function returned `False`. +## +## >>> List.dropIf [ 1, 2, 3, 4 ] (\num -> num > 2) +## +## ## Performance Details +## +## `List.dropIf` has the same performance characteristics as [List.keepIf]. +## See its documentation for details on those characteristics! dropIf : List a, (a -> Bool) -> List a dropIf = \list, predicate -> List.keepIf list (\e -> Bool.not (predicate e)) +## This works like [List.map], except only the transformed values that are +## wrapped in `Ok` are kept. Any that are wrapped in `Err` are dropped. +## +## >>> List.keepOks [ [ "a", "b" ], [], [], [ "c", "d", "e" ] ] List.last +## +## >>> fn = \str -> if Str.isEmpty str then Err StrWasEmpty else Ok (Str.len str) +## >>> +## >>> List.keepOks [ "", "a", "bc", "", "d", "ef", "" ] keepOks : List before, (before -> Result after *) -> List after + +## This works like [List.map], except only the transformed values that are +## wrapped in `Err` are kept. Any that are wrapped in `Ok` are dropped. +## +## >>> List.keepErrs [ [ "a", "b" ], [], [], [ "c", "d", "e" ] ] List.last +## +## >>> fn = \str -> if Str.isEmpty str then Err StrWasEmpty else Ok (Str.len str) +## >>> +## >>> List.keepErrs [ "", "a", "bc", "", "d", "ef", "" ] keepErrs: List before, (before -> Result * after) -> List after + +## Convert each element in the list to something new, by calling a conversion +## function on each of them. Then return a new list of the converted values. +## +## > List.map [ 1, 2, 3 ] (\num -> num + 1) +## +## > List.map [ "", "a", "bc" ] Str.isEmpty map : List a, (a -> b) -> List b + +## Run a transformation function on the first element of each list, +## and use that as the first element in the returned list. +## Repeat until a list runs out of elements. +## +## Some languages have a function named `zip`, which does something similar to +## calling [List.map2] passing two lists and `Pair`: +## +## >>> zipped = List.map2 [ "a", "b", "c" ] [ 1, 2, 3 ] Pair map2 : List a, List b, (a, b -> c) -> List c + +## Run a transformation function on the first element of each list, +## and use that as the first element in the returned list. +## Repeat until a list runs out of elements. map3 : List a, List b, List c, (a, b, c -> d) -> List d + +## Run a transformation function on the first element of each list, +## and use that as the first element in the returned list. +## Repeat until a list runs out of elements. map4 : List a, List b, List c, List d, (a, b, c, d -> e) -> List e + +## This works like [List.map], except it also passes the index +## of the element to the conversion function. mapWithIndex : List a, (a, Nat -> b) -> List b + +## Returns a list of all the integers between one and another, +## including both of the given numbers. +## +## >>> List.range 2 8 range : Int a, Int a -> List (Int a) sortWith : List a, (a, a -> [ LT, EQ, GT ] ) -> List a + +## Sorts a list in ascending order (lowest to highest), using a function which +## specifies a way to represent each element as a number. +## +## To sort in descending order (highest to lowest), use [List.sortDesc] instead. sortAsc : List (Num a) -> List (Num a) sortAsc = \list -> List.sortWith list Num.compare +## Sorts a list in descending order (highest to lowest), using a function which +## specifies a way to represent each element as a number. +## +## To sort in ascending order (lowest to highest), use [List.sortAsc] instead. sortDesc : List (Num a) -> List (Num a) sortDesc = \list -> List.sortWith list (\a, b -> Num.compare b a) swap : List a, Nat, Nat -> List a +## Returns the first element in the list, or `ListWasEmpty` if it was empty. first : List a -> Result a [ ListWasEmpty ]* +## Remove the first element from the list. +## +## Returns the new list (with the removed element missing). dropFirst : List elem -> List elem + +## Remove the last element from the list. +## +## Returns the new list (with the removed element missing). dropLast : List elem -> List elem +## Returns the given number of elements from the beginning of the list. +## +## >>> List.takeFirst 4 [ 1, 2, 3, 4, 5, 6, 7, 8 ] +## +## If there are fewer elements in the list than the requested number, +## returns the entire list. +## +## >>> List.takeFirst 5 [ 1, 2 ] +## +## To *remove* elements from the beginning of the list, use `List.takeLast`. +## +## To remove elements from both the beginning and end of the list, +## use `List.sublist`. +## +## To split the list into two lists, use `List.split`. +## +## ## Performance Details +## +## When given a Unique list, this runs extremely fast. It sets the list's length +## to the given length value, and frees the leftover elements. This runs very +## slightly faster than `List.takeLast`. +## +## In fact, `List.takeFirst 1 list` runs faster than `List.first list` when given +## a Unique list, because [List.first] returns the first element as well - +## which introduces a conditional bounds check as well as a memory load. takeFirst : List elem, Nat -> List elem + +## Returns the given number of elements from the end of the list. +## +## >>> List.takeLast 4 [ 1, 2, 3, 4, 5, 6, 7, 8 ] +## +## If there are fewer elements in the list than the requested number, +## returns the entire list. +## +## >>> List.takeLast 5 [ 1, 2 ] +## +## To *remove* elements from the end of the list, use `List.takeFirst`. +## +## To remove elements from both the beginning and end of the list, +## use `List.sublist`. +## +## To split the list into two lists, use `List.split`. +## +## ## Performance Details +## +## When given a Unique list, this runs extremely fast. It moves the list's +## pointer to the index at the given length value, updates its length, +## and frees the leftover elements. This runs very nearly as fast as +## `List.takeFirst` on a Unique list. +## +## In fact, `List.takeLast 1 list` runs faster than `List.first list` when given +## a Unique list, because [List.first] returns the first element as well - +## which introduces a conditional bounds check as well as a memory load. takeLast : List elem, Nat -> List elem +## Drops n elements from the beginning of the list. drop : List elem, Nat -> List elem + +## Drops the element at the given index from the list. +## +## This has no effect if the given index is outside the bounds of the list. +## +## To replace the element at a given index, instead of dropping it, see [List.set]. dropAt : List elem, Nat -> List elem min : List (Num a) -> Result (Num a) [ ListWasEmpty ]* @@ -163,11 +582,41 @@ maxHelp = \list, initial -> else bestSoFar +## Like [List.map], except the transformation function wraps the return value +## in a list. At the end, all the lists get joined together into one list. +## +## You may know a similar function named `concatMap` in other languages. joinMap : List a, (a -> List b) -> List b joinMap = \list, mapper -> List.walk list [] (\state, elem -> List.concat state (mapper elem)) +## Returns the first element of the list satisfying a predicate function. +## If no satisfying element is found, an `Err NotFound` is returned. find : List elem, (elem -> Bool) -> Result elem [ NotFound ]* + +## Returns a subsection of the given list, beginning at the `start` index and +## including a total of `len` elements. +## +## If `start` is outside the bounds of the given list, returns the empty list. +## +## >>> List.sublist { start: 4, len: 0 } [ 1, 2, 3 ] +## +## If more elements are requested than exist in the list, returns as many as it can. +## +## >>> List.sublist { start: 2, len: 10 } [ 1, 2, 3, 4, 5 ] +## +## > If you want a sublist which goes all the way to the end of the list, no +## > matter how long the list is, `List.takeLast` can do that more efficiently. +## +## Some languages have a function called **`slice`** which works similarly to this. sublist : List elem, { start : Nat, len : Nat } -> List elem intersperse : List elem, elem -> List elem + +## Splits the list into two lists, around the given index. +## +## The returned lists are labeled `before` and `others`. The `before` list will +## contain all the elements whose index in the original list was **less than** +## than the given index, # and the `others` list will be all the others. (This +## means if you give an index of 0, the `before` list will be empty and the +## `others` list will have the same elements as the original list.) split : List elem, Nat -> { before: List elem, others: List elem } From c0b04e28001166a11dc31dcf6e3c617c99b3a1f3 Mon Sep 17 00:00:00 2001 From: Nuno Ferreira Date: Fri, 6 May 2022 11:11:00 +0200 Subject: [PATCH 841/846] Migrated builtins/docs/Result.roc docs over to builtins/roc/Result.roc --- compiler/builtins/roc/Result.roc | 41 ++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/compiler/builtins/roc/Result.roc b/compiler/builtins/roc/Result.roc index a857a6c456..06046299a2 100644 --- a/compiler/builtins/roc/Result.roc +++ b/compiler/builtins/roc/Result.roc @@ -2,38 +2,79 @@ interface Result exposes [ Result, isOk, isErr, map, mapErr, after, withDefault ] imports [ Bool.{ Bool } ] +## The result of an operation that could fail: either the operation went +## okay, or else there was an error of some sort. Result ok err : [ Ok ok, Err err ] +## Return True if the result indicates a success, else return False +## +## >>> Result.isOk (Ok 5) isOk : Result ok err -> Bool isOk = \result -> when result is Ok _ -> True Err _ -> False +## Return True if the result indicates a failure, else return False +## +## >>> Result.isErr (Err "uh oh") isErr : Result ok err -> Bool isErr = \result -> when result is Ok _ -> False Err _ -> True +## If the result is `Ok`, return the value it holds. Otherwise, return +## the given default value. +## +## >>> Result.withDefault (Ok 7) 42 +## +## >>> Result.withDefault (Err "uh oh") 42 withDefault : Result ok err, ok -> ok withDefault = \result, default -> when result is Ok value -> value Err _ -> default +## If the result is `Ok`, transform the value it holds by running a conversion +## function on it. Then return a new `Ok` holding the transformed value. +## +## (If the result is `Err`, this has no effect. Use [mapErr] to transform an `Err`.) +## +## >>> Result.map (Ok 12) Num.negate +## +## >>> Result.map (Err "yipes!") Num.negate +## +## `map` functions like this are common in Roc, and they all work similarly. +## See for example [List.map], `Set.map`, and `Dict.map`. map : Result a err, (a -> b) -> Result b err map = \result, transform -> when result is Ok v -> Ok (transform v) Err e -> Err e +## If the result is `Err`, transform the value it holds by running a conversion +## function on it. Then return a new `Err` holding the transformed value. +## +## (If the result is `Ok`, this has no effect. Use [map] to transform an `Ok`.) +## +## >>> Result.mapErr (Err "yipes!") Str.isEmpty +## +## >>> Result.mapErr (Ok 12) Str.isEmpty mapErr : Result ok a, (a -> b) -> Result ok b mapErr = \result, transform -> when result is Ok v -> Ok v Err e -> Err (transform e) +## If the result is `Ok`, transform the entire result by running a conversion +## function on the value the `Ok` holds. Then return that new result. +## +## (If the result is `Err`, this has no effect. Use `afterErr` to transform an `Err`.) +## +## >>> Result.after (Ok -1) \num -> if num < 0 then Err "negative!" else Ok -num +## +## >>> Result.after (Err "yipes!") \num -> if num < 0 then Err "negative!" else Ok -num after : Result a err, (a -> Result b err) -> Result b err after = \result, transform -> when result is From 6e69349dc0f43bf16e56f8b30b77b442c439e647 Mon Sep 17 00:00:00 2001 From: Nuno Ferreira Date: Fri, 6 May 2022 11:24:33 +0200 Subject: [PATCH 842/846] Migrated Dict --- compiler/builtins/docs/Dict.roc | 210 ------------------------------ compiler/builtins/docs/Result.roc | 67 ---------- compiler/builtins/roc/Dict.roc | 55 ++++++++ 3 files changed, 55 insertions(+), 277 deletions(-) delete mode 100644 compiler/builtins/docs/Dict.roc delete mode 100644 compiler/builtins/docs/Result.roc diff --git a/compiler/builtins/docs/Dict.roc b/compiler/builtins/docs/Dict.roc deleted file mode 100644 index 8e0bba0a41..0000000000 --- a/compiler/builtins/docs/Dict.roc +++ /dev/null @@ -1,210 +0,0 @@ -interface Dict - exposes - [ - Dict, - contains, - difference, - empty, - get, - keys, - insert, - intersection, - len, - remove, - single, - union, - values, - walk - ] - imports [] - -## A [dictionary](https://en.wikipedia.org/wiki/Associative_array) that lets you can associate keys with values. -## -## ### Inserting -## -## The most basic way to use a dictionary is to start with an empty one and then: -## 1. Call [Dict.insert] passing a key and a value, to associate that key with that value in the dictionary. -## 2. Later, call [Dict.get] passing the same key as before, and it will return the value you stored. -## -## Here's an example of a dictionary which uses a city's name as the key, and its population as the associated value. -## -## populationByCity = -## Dict.empty -## |> Dict.insert "London" 8_961_989 -## |> Dict.insert "Philadelphia" 1_603_797 -## |> Dict.insert "Shanghai" 24_870_895 -## |> Dict.insert "Delhi" 16_787_941 -## |> Dict.insert "Amsterdam" 872_680 -## -## ### Converting to a [List] -## -## We can call [Dict.toList] on `populationByCity` to turn it into a list of key-value pairs: -## -## Dict.toList populationByCity == [ -## { k: "London", v: 8961989 }, -## { k: "Philadelphia", v: 1603797 }, -## { k: "Shanghai", v: 24870895 }, -## { k: "Delhi", v: 16787941 }, -## { k: "Amsterdam", v: 872680 }, -## ] -## -## We can use the similar [Dict.keyList] and [Dict.values] functions to get only the keys or only the values, -## instead of getting these `{ k, v }` records that contain both. -## -## You may notice that these lists have the same order as the original insertion order. This will be true if -## all you ever do is [insert] and [get] operations on the dictionary, but [remove] operations can change this order. -## Let's see how that looks. -## -## ### Removing -## -## We can remove an element from the dictionary, like so: -## -## populationByCity -## |> Dict.remove "Philadelphia" -## |> Dict.toList -## == -## [ -## { k: "London", v: 8961989 }, -## { k: "Amsterdam", v: 872680 }, -## { k: "Shanghai", v: 24870895 }, -## { k: "Delhi", v: 16787941 }, -## ] -## -## Notice that the order changed! Philadelphia has been not only removed from the list, but Amsterdam - the last -## entry we inserted - has been moved into the spot where Philadelphia was previously. This is exactly what -## [Dict.remove] does: it removes an element and moves the most recent insertion into the vacated spot. -## -## This move is done as a performance optimization, and it lets [remove] have -## [constant time complexity](https://en.wikipedia.org/wiki/Time_complexity#Constant_time). If you need a removal -## operation which preserves ordering, [Dict.removeShift] will remove the element and then shift everything after it -## over one spot. Be aware that this shifting requires copying every single entry after the removed element, though, -## so it can be massively more costly than [remove]! This makes [remove] the recommended default choice; -## [removeShift] should only be used if maintaining original insertion order is absolutely necessary. -## -## -## ### Removing -## -## ### Equality -## -## When comparing two dictionaries for equality, they are `==` only if their both their contents and their -## orderings match. This preserves the property that if `dict1 == dict2`, you should be able to rely on -## `fn dict1 == fn dict2` also being `True`, even if `fn` relies on the dictionary's ordering (for example, if -## `fn` is `Dict.toList` or calls it internally.) -## -## The [Dict.hasSameContents] function gives an alternative to `==` which ignores ordering -## and returns `True` if both dictionaries have the same keys and associated values. -Dict k v := [ Dict k v ] # TODO k should require a hashing and equating constraint - -## An empty dictionary. -empty : Dict * * - -size : Dict * * -> Nat - -isEmpty : Dict * * -> Bool - -## Returns a [List] of the dictionary's key/value pairs. -## -## See [walk] to walk over the key/value pairs without creating an intermediate data structure. -toList : Dict k v -> List { k, v } - -## Returns a [List] of the dictionary's keys. -## -## See [keySet] to get a [Set] of keys instead, or [walkKeys] to walk over the keys without creating -## an intermediate data structure. -keyList : Dict key * -> List key - -## Returns a [Set] of the dictionary's keys. -## -## See [keyList] to get a [List] of keys instead, or [walkKeys] to walk over the keys without creating -## an intermediate data structure. -keySet : Dict key * -> Set key - -## Returns a [List] of the dictionary's values. -## -## See [walkValues] to walk over the values without creating an intermediate data structure. -values : Dict * value -> List value - -walk : Dict k v, state, (state, k, v -> state) -> state - -walkKeys : Dict key *, state, (state, key -> state) -> state - -walkValues : Dict * value, state, (state, value -> state) -> state - -## Convert each key and value in the #Dict to something new, by calling a conversion -## function on each of them. Then return a new #Map of the converted keys and values. -## -## >>> Dict.map {{ 3.14 => "pi", 1.0 => "one" }} \{ key, value } -> { key: -## -## >>> Dict.map {[ "", "a", "bc" ]} Str.isEmpty -## -## `map` functions like this are common in Roc, and they all work similarly. -## See for example [List.map], [Result.map], and `Set.map`. -map : - Dict beforeKey beforeVal, - ({ k: beforeKey, v: beforeVal } -> { k: afterKey, v: afterVal }) - -> Dict afterKey afterVal - -# DESIGN NOTES: The reason for panicking when given NaN is that: -# * If we allowed NaN in, Dict.insert would no longer be idempotent. -# * If we allowed NaN but overrode its semantics to make it feel like "NaN == NaN" we'd need isNaN checks in all hashing operations as well as all equality checks (during collision detection), not just insert. This would be much worse for performance than panicking on insert, which only requires one extra conditional on insert. -# * It's obviously invalid; the whole point of NaN is that an error occurred. Giving a runtime error notifies you when this problem happens. Giving it only on insert is the best for performance, because it means you aren't paying for isNaN checks on lookups as well. - -# TODO: removed `'` from signature because parser does not support it yet -# Original signature: insert : Dict 'key val, 'key, val -> Dict 'key val -## Make sure never to insert a key of *NaN* into a [Dict]! Because *NaN* is -## defined to be unequal to *NaN*, inserting a *NaN* key results in an entry -## that can never be retrieved or removed from the [Dict]. -insert : Dict key val, key, val -> Dict key val - -## Removes a key from the dictionary in [constant time](https://en.wikipedia.org/wiki/Time_complexity#Constant_time), without preserving insertion order. -## -## Since the internal [List] which determines the order of operations like [toList] and [walk] cannot have gaps in it, -## whenever an element is removed from the middle of that list, something must be done to eliminate the resulting gap. -## -## * [removeShift] eliminates the gap by shifting over every element after the removed one. This takes [linear time](https://en.wikipedia.org/wiki/Time_complexity#Linear_time), -## and preserves the original ordering. -## * [remove] eliminates the gap by replacing the removed element with the one at the end of the list - that is, the most recent insertion. This takes [constant time](https://en.wikipedia.org/wiki/Time_complexity#Constant_time), but does not preserve the original ordering. -## -## For example, suppose we have a `populationByCity` with these contents: -## -## Dict.toList populationByCity == [ -## { k: "London", v: 8961989 }, -## { k: "Philadelphia", v: 1603797 }, -## { k: "Shanghai", v: 24870895 }, -## { k: "Delhi", v: 16787941 }, -## { k: "Amsterdam", v: 872680 }, -## ] -## -## Using `Dict.remove "Philadelphia"` on this will replace the `"Philadelphia"` entry with the most recent insertion, -## which is `"Amsterdam"` in this case. -## -## populationByCity -## |> Dict.remove "Philadelphia" -## |> Dict.toList -## == -## [ -## { k: "London", v: 8961989 }, -## { k: "Amsterdam", v: 872680 }, -## { k: "Shanghai", v: 24870895 }, -## { k: "Delhi", v: 16787941 }, -## ] -## -## Both [remove] and [removeShift] leave the dictionary with the same contents; they only differ in ordering and in -## performance. Since ordering only affects operations like [toList] and [walk], [remove] is the better default -## choice because it has much better performance characteristics; [removeShift] should only be used when it's -## absolutely necessary for operations like [toList] and [walk] to preserve the exact original insertion order. -remove : Dict k v, k -> Dict k v - -## Removes a key from the dictionary in [linear time](https://en.wikipedia.org/wiki/Time_complexity#Linear_time), while preserving insertion order. -## -## It's better to use [remove] than this by default, since [remove] has [constant time complexity](https://en.wikipedia.org/wiki/Time_complexity#Constant_time), -## which commonly leads [removeShift] to take many times as long to run as [remove] does. However, [remove] does not -## preserve insertion order, so the slower [removeShift] exists only for use cases where it's abolutely necessary for -## ordering-sensitive functions like [toList] and [walk] to preserve the exact original insertion order. -## -## See the [remove] documentation for more details about the differences between [remove] and [removeShift]. -removeShift : Dict k v, k -> Dict k v - -## Returns whether both dictionaries have the same keys, and the same values associated with those keys. -## This is different from `==` in that it disregards the ordering of the keys and values. -hasSameContents : Dict k v, Dict k v -> Bool diff --git a/compiler/builtins/docs/Result.roc b/compiler/builtins/docs/Result.roc deleted file mode 100644 index 230c5f9fd1..0000000000 --- a/compiler/builtins/docs/Result.roc +++ /dev/null @@ -1,67 +0,0 @@ -interface Result - exposes - [ - Result, - after, - isOk, - isErr, - map, - mapErr, - withDefault - ] - imports [] - -## The result of an operation that could fail: either the operation went -## okay, or else there was an error of some sort. -Result ok err : [ Ok ok, Err err ] - -## Return True if the result indicates a success, else return False -## -## >>> Result.isOk (Ok 5) -isOk : Result * * -> bool - -## Return True if the result indicates a failure, else return False -## -## >>> Result.isErr (Err "uh oh") -isErr : Result * * -> bool - -## If the result is `Ok`, return the value it holds. Otherwise, return -## the given default value. -## -## >>> Result.withDefault (Ok 7) 42 -## -## >>> Result.withDefault (Err "uh oh") 42 -withDefault : Result ok err, ok -> ok - -## If the result is `Ok`, transform the entire result by running a conversion -## function on the value the `Ok` holds. Then return that new result. -## -## (If the result is `Err`, this has no effect. Use `afterErr` to transform an `Err`.) -## -## >>> Result.after (Ok -1) \num -> if num < 0 then Err "negative!" else Ok -num -## -## >>> Result.after (Err "yipes!") \num -> if num < 0 then Err "negative!" else Ok -num -after : Result before err, (before -> Result after err) -> Result after err - -## If the result is `Ok`, transform the value it holds by running a conversion -## function on it. Then return a new `Ok` holding the transformed value. -## -## (If the result is `Err`, this has no effect. Use [mapErr] to transform an `Err`.) -## -## >>> Result.map (Ok 12) Num.negate -## -## >>> Result.map (Err "yipes!") Num.negate -## -## `map` functions like this are common in Roc, and they all work similarly. -## See for example [List.map], `Set.map`, and `Dict.map`. -map : Result before err, (before -> after) -> Result after err - -## If the result is `Err`, transform the value it holds by running a conversion -## function on it. Then return a new `Err` holding the transformed value. -## -## (If the result is `Ok`, this has no effect. Use [map] to transform an `Ok`.) -## -## >>> Result.mapErr (Err "yipes!") Str.isEmpty -## -## >>> Result.mapErr (Ok 12) Str.isEmpty -mapErr : Result ok before, (before -> after) -> Result ok after diff --git a/compiler/builtins/roc/Dict.roc b/compiler/builtins/roc/Dict.roc index aa457cee0e..d5b1ba07e2 100644 --- a/compiler/builtins/roc/Dict.roc +++ b/compiler/builtins/roc/Dict.roc @@ -20,6 +20,57 @@ interface Dict Bool.{ Bool } ] +## A [dictionary](https://en.wikipedia.org/wiki/Associative_array) that lets you can associate keys with values. +## +## ### Inserting +## +## The most basic way to use a dictionary is to start with an empty one and then: +## 1. Call [Dict.insert] passing a key and a value, to associate that key with that value in the dictionary. +## 2. Later, call [Dict.get] passing the same key as before, and it will return the value you stored. +## +## Here's an example of a dictionary which uses a city's name as the key, and its population as the associated value. +## +## populationByCity = +## Dict.empty +## |> Dict.insert "London" 8_961_989 +## |> Dict.insert "Philadelphia" 1_603_797 +## |> Dict.insert "Shanghai" 24_870_895 +## |> Dict.insert "Delhi" 16_787_941 +## |> Dict.insert "Amsterdam" 872_680 +## +## ### Accessing keys or values +## +## We can use [Dict.keys] and [Dict.values] functions to get only the keys or only the values. +## +## You may notice that these lists have the same order as the original insertion order. This will be true if +## all you ever do is [insert] and [get] operations on the dictionary, but [remove] operations can change this order. +## Let's see how that looks. +## +## ### Removing +## +## We can remove an element from the dictionary, like so: +## +## populationByCity +## |> Dict.remove "Philadelphia" +## |> Dict.keys +## == +## [ "London", "Amsterdam", "Shanghai", "Delhi" ] +## +## Notice that the order changed! Philadelphia has been not only removed from the list, but Amsterdam - the last +## entry we inserted - has been moved into the spot where Philadelphia was previously. This is exactly what +## [Dict.remove] does: it removes an element and moves the most recent insertion into the vacated spot. +## +## This move is done as a performance optimization, and it lets [remove] have +## [constant time complexity](https://en.wikipedia.org/wiki/Time_complexity#Constant_time). ## +## +## ### Equality +## +## When comparing two dictionaries for equality, they are `==` only if their both their contents and their +## orderings match. This preserves the property that if `dict1 == dict2`, you should be able to rely on +## `fn dict1 == fn dict2` also being `True`, even if `fn` relies on the dictionary's ordering. + + +## An empty dictionary. empty : Dict k v single : k, v -> Dict k v get : Dict k v, k -> Result v [ KeyNotFound ]* @@ -28,7 +79,11 @@ insert : Dict k v, k, v -> Dict k v len : Dict k v -> Nat remove : Dict k v, k -> Dict k v contains : Dict k v, k -> Bool + +## Returns a [List] of the dictionary's keys. keys : Dict k v -> List k + +## Returns a [List] of the dictionary's values. values : Dict k v -> List v union : Dict k v, Dict k v -> Dict k v intersection : Dict k v, Dict k v -> Dict k v From a46555d14ca787cedd8299edf8e36d48a93e09bf Mon Sep 17 00:00:00 2001 From: Nuno Ferreira Date: Fri, 6 May 2022 12:02:57 +0200 Subject: [PATCH 843/846] Fixed mistake when porting over List docs --- compiler/builtins/roc/List.roc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/builtins/roc/List.roc b/compiler/builtins/roc/List.roc index 483fdbf601..1b479dfa6a 100644 --- a/compiler/builtins/roc/List.roc +++ b/compiler/builtins/roc/List.roc @@ -201,7 +201,12 @@ interface List ## * Even when copying is faster, other list operations may still be slightly slower with persistent data structures. For example, even if it were a persistent data structure, [List.map], [List.walk], and [List.keepIf] would all need to traverse every element in the list and build up the result from scratch. These operations are all ## * Roc's compiler optimizes many list operations into in-place mutations behind the scenes, depending on how the list is being used. For example, [List.map], [List.keepIf], and [List.set] can all be optimized to perform in-place mutations. ## * If possible, it is usually best for performance to use large lists in a way where the optimizer can turn them into in-place mutations. If this is not possible, a persistent data structure might be faster - but this is a rare enough scenario that it would not be good for the average Roc program's performance if this were the way [List] worked by default. Instead, you can look outside Roc's standard modules for an implementation of a persistent data structure - likely built using [List] under the hood! -List elem := [ List elem ] + +## Check if the list is empty. +## +## >>> List.isEmpty [ 1, 2, 3 ] +## +## >>> List.isEmpty [] isEmpty : List a -> Bool isEmpty = \list -> List.len list == 0 From 5755475b3aa9deb28e388f20668d6b5cf5c5955d Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 6 May 2022 13:56:35 +0200 Subject: [PATCH 844/846] add ListIsUnique lowlevel operation --- compiler/builtins/bitcode/src/list.zig | 6 ++++++ compiler/builtins/bitcode/src/main.zig | 1 + compiler/builtins/src/bitcode.rs | 1 + compiler/can/src/builtins.rs | 6 ++++++ compiler/gen_llvm/src/llvm/build.rs | 9 +++++++++ compiler/gen_wasm/src/low_level.rs | 2 ++ compiler/module/src/low_level.rs | 1 + compiler/module/src/symbol.rs | 1 + compiler/mono/src/borrow.rs | 2 ++ 9 files changed, 29 insertions(+) diff --git a/compiler/builtins/bitcode/src/list.zig b/compiler/builtins/bitcode/src/list.zig index 4b52eabbcd..dcff377f3e 100644 --- a/compiler/builtins/bitcode/src/list.zig +++ b/compiler/builtins/bitcode/src/list.zig @@ -1355,3 +1355,9 @@ pub fn listFindUnsafe( return .{ .value = null, .found = false }; } } + +pub fn listIsUnique( + list: RocList, +) callconv(.C) bool { + return list.isEmpty() or list.isUnique(); +} diff --git a/compiler/builtins/bitcode/src/main.zig b/compiler/builtins/bitcode/src/main.zig index 85f35fbca2..38bdb0af3f 100644 --- a/compiler/builtins/bitcode/src/main.zig +++ b/compiler/builtins/bitcode/src/main.zig @@ -56,6 +56,7 @@ comptime { exportListFn(list.listAny, "any"); exportListFn(list.listAll, "all"); exportListFn(list.listFindUnsafe, "find_unsafe"); + exportListFn(list.listIsUnique, "is_unique"); } // Dict Module diff --git a/compiler/builtins/src/bitcode.rs b/compiler/builtins/src/bitcode.rs index 73de5d2452..db46330d51 100644 --- a/compiler/builtins/src/bitcode.rs +++ b/compiler/builtins/src/bitcode.rs @@ -345,6 +345,7 @@ pub const LIST_REPLACE_IN_PLACE: &str = "roc_builtins.list.replace_in_place"; pub const LIST_ANY: &str = "roc_builtins.list.any"; pub const LIST_ALL: &str = "roc_builtins.list.all"; pub const LIST_FIND_UNSAFE: &str = "roc_builtins.list.find_unsafe"; +pub const LIST_IS_UNIQUE: &str = "roc_builtins.list.is_unique"; pub const DEC_FROM_STR: &str = "roc_builtins.dec.from_str"; pub const DEC_FROM_F64: &str = "roc_builtins.dec.from_f64"; diff --git a/compiler/can/src/builtins.rs b/compiler/can/src/builtins.rs index 9e66db45fa..a3e8be5817 100644 --- a/compiler/can/src/builtins.rs +++ b/compiler/can/src/builtins.rs @@ -150,6 +150,7 @@ pub fn builtin_defs_map(symbol: Symbol, var_store: &mut VarStore) -> Option LIST_ANY => list_any, LIST_ALL => list_all, LIST_FIND => list_find, + LIST_IS_UNIQUE => list_is_unique, DICT_LEN => dict_len, DICT_EMPTY => dict_empty, DICT_SINGLE => dict_single, @@ -3773,6 +3774,11 @@ fn list_find(symbol: Symbol, var_store: &mut VarStore) -> Def { ) } +/// List.isUnique : List * -> Bool +fn list_is_unique(symbol: Symbol, var_store: &mut VarStore) -> Def { + lowlevel_1(symbol, LowLevel::ListIsUnique, var_store) +} + /// Dict.len : Dict * * -> Nat fn dict_len(symbol: Symbol, var_store: &mut VarStore) -> Def { let arg1_var = var_store.fresh(); diff --git a/compiler/gen_llvm/src/llvm/build.rs b/compiler/gen_llvm/src/llvm/build.rs index c17349656b..d82488f932 100644 --- a/compiler/gen_llvm/src/llvm/build.rs +++ b/compiler/gen_llvm/src/llvm/build.rs @@ -5667,6 +5667,15 @@ fn run_low_level<'a, 'ctx, 'env>( update_mode, ) } + ListIsUnique => { + // List.isUnique : List a -> Bool + debug_assert_eq!(args.len(), 1); + + let list = load_symbol(scope, &args[0]); + let list = list_to_c_abi(env, list).into(); + + call_bitcode_fn(env, &[list], bitcode::LIST_IS_UNIQUE) + } NumToStr => { // Num.toStr : Num a -> Str debug_assert_eq!(args.len(), 1); diff --git a/compiler/gen_wasm/src/low_level.rs b/compiler/gen_wasm/src/low_level.rs index 9717882e64..e169b7dc5f 100644 --- a/compiler/gen_wasm/src/low_level.rs +++ b/compiler/gen_wasm/src/low_level.rs @@ -277,6 +277,8 @@ impl<'a> LowLevelCall<'a> { _ => internal_error!("invalid storage for List"), }, + ListIsUnique => self.load_args_and_call_zig(backend, bitcode::LIST_IS_UNIQUE), + ListMap | ListMap2 | ListMap3 | ListMap4 | ListMapWithIndex | ListKeepIf | ListWalk | ListWalkUntil | ListWalkBackwards | ListKeepOks | ListKeepErrs | ListSortWith | ListAny | ListAll | ListFindUnsafe | DictWalk => { diff --git a/compiler/module/src/low_level.rs b/compiler/module/src/low_level.rs index 36f0f0c77b..6b97878686 100644 --- a/compiler/module/src/low_level.rs +++ b/compiler/module/src/low_level.rs @@ -53,6 +53,7 @@ pub enum LowLevel { ListAny, ListAll, ListFindUnsafe, + ListIsUnique, DictSize, DictEmpty, DictInsert, diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index ef65f745cb..487c0a9d95 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -1252,6 +1252,7 @@ define_builtins! { 55 LIST_SORT_DESC: "sortDesc" 56 LIST_SORT_DESC_COMPARE: "#sortDescCompare" 57 LIST_REPLACE: "replace" + 58 LIST_IS_UNIQUE: "#isUnique" } 5 RESULT: "Result" => { 0 RESULT_RESULT: "Result" // the Result.Result type alias diff --git a/compiler/mono/src/borrow.rs b/compiler/mono/src/borrow.rs index a883797efb..66d15fcdff 100644 --- a/compiler/mono/src/borrow.rs +++ b/compiler/mono/src/borrow.rs @@ -1031,6 +1031,8 @@ pub fn lowlevel_borrow_signature(arena: &Bump, op: LowLevel) -> &[bool] { ExpectTrue => arena.alloc_slice_copy(&[irrelevant]), + ListIsUnique => arena.alloc_slice_copy(&[borrowed]), + BoxExpr | UnboxExpr => { unreachable!("These lowlevel operations are turned into mono Expr's") } From 2c29a46968f85f1f807483fef5c2009df86f17b1 Mon Sep 17 00:00:00 2001 From: Nuno Ferreira Date: Fri, 6 May 2022 15:18:07 +0200 Subject: [PATCH 845/846] removed code example as it was breaking CI --- compiler/builtins/roc/List.roc | 8 -------- 1 file changed, 8 deletions(-) diff --git a/compiler/builtins/roc/List.roc b/compiler/builtins/roc/List.roc index 1b479dfa6a..33c3cc415d 100644 --- a/compiler/builtins/roc/List.roc +++ b/compiler/builtins/roc/List.roc @@ -64,14 +64,6 @@ interface List ## >>> [ "a", "b", "c" ] # a list of strings ## >>> [ [ 1.1 ], [], [ 2.2, 3.3 ] ] # a list of lists of numbers ## -## The list `[ 1, "a" ]` gives an error, because each element in a list must have -## the same type. If you want to put a mix of [I64] and [Str] values into a list, try this: -## -## ``` -## mixedList : List [ IntElem I64, StrElem Str ]* -## mixedList = [ IntElem 1, IntElem 2, StrElem "a", StrElem "b" ] -## ``` -## ## The maximum size of a [List] is limited by the amount of heap memory available ## to the current process. If there is not enough memory available, attempting to ## create the list could crash. (On Linux, where [overcommit](https://www.etalabs.net/overcommit.html) From 5bf5b260610c7e5f35014e22c2ae14d1dd9a3ab0 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 6 May 2022 11:35:50 -0400 Subject: [PATCH 846/846] Add Nuno Ferreira to AUTHORS --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 2c21c5fb3d..1c6750ef8e 100644 --- a/AUTHORS +++ b/AUTHORS @@ -78,3 +78,4 @@ Jared Cone Sean Hagstrom Kas Buunk Oskar Hahn +Nuno Ferreira

rA$iMlyWKMQ!1oXOsSNTn39xI zIVCy8n^GmEYD%?~>M7UU>+TKrrhCi%&%N#5aqqhK-23hW_o4g9ee6DQpSsW7=dS5m zZX%EbR0fg(FHi-j3RDBC18eF{Po0svG<8|(^3+wSXH&1I-b(#1^=>MVl@ZH~Ww?on zDfM2sg(_vbw(GcmfhE9F;2)3$r-p1Z0-lpDW z-savG-j?20-qzkW-nQO$-uB)O-j3c*-p<}G-mczm-uRc!zrQd_C307^Y2RcW9! zRGKQyl;%ncrM1#VX{)qT+AAHDj!Gw`v(iQBs&rGjD?OE7N*^Un>8JEp1}KA+bOlr( z1y&FRReb+v0|Wo}`Ur(oC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