mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00
Fix compile errors
This commit is contained in:
parent
ada4b0ea43
commit
d63eb23664
7 changed files with 39 additions and 57 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -3963,6 +3963,7 @@ dependencies = [
|
||||||
"roc_collections",
|
"roc_collections",
|
||||||
"roc_gen_wasm",
|
"roc_gen_wasm",
|
||||||
"roc_load",
|
"roc_load",
|
||||||
|
"roc_mono",
|
||||||
"roc_parse",
|
"roc_parse",
|
||||||
"roc_repl_eval",
|
"roc_repl_eval",
|
||||||
"roc_reporting",
|
"roc_reporting",
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::types::{Env, Types};
|
use crate::types::{Env, Types};
|
||||||
use bumpalo::Bump;
|
use bumpalo::Bump;
|
||||||
use roc_load::{LoadedModule, Threading};
|
use roc_load::{LoadedModule, Threading};
|
||||||
|
use roc_mono::layout::MultimorphicNames;
|
||||||
use roc_reporting::report::RenderTarget;
|
use roc_reporting::report::RenderTarget;
|
||||||
use roc_target::{Architecture, TargetInfo};
|
use roc_target::{Architecture, TargetInfo};
|
||||||
use std::io;
|
use std::io;
|
||||||
|
@ -36,6 +37,8 @@ pub fn load_types(
|
||||||
)
|
)
|
||||||
.expect("Problem loading platform module");
|
.expect("Problem loading platform module");
|
||||||
|
|
||||||
|
let mut multimorphic_names = MultimorphicNames::default();
|
||||||
|
|
||||||
let decls = declarations_by_id.remove(&home).unwrap();
|
let decls = declarations_by_id.remove(&home).unwrap();
|
||||||
let subs = solved.inner_mut();
|
let subs = solved.inner_mut();
|
||||||
|
|
||||||
|
@ -74,7 +77,13 @@ pub fn load_types(
|
||||||
let types_and_targets = Architecture::iter()
|
let types_and_targets = Architecture::iter()
|
||||||
.map(|arch| {
|
.map(|arch| {
|
||||||
let target_info = arch.into();
|
let target_info = arch.into();
|
||||||
let mut env = Env::new(home, arena, subs, &mut interns, target_info);
|
let mut env = Env::new(
|
||||||
|
arena,
|
||||||
|
subs,
|
||||||
|
&mut interns,
|
||||||
|
target_info,
|
||||||
|
&mut multimorphic_names,
|
||||||
|
);
|
||||||
|
|
||||||
(env.vars_to_types(variables.clone()), target_info)
|
(env.vars_to_types(variables.clone()), target_info)
|
||||||
})
|
})
|
||||||
|
|
|
@ -6,10 +6,10 @@ use roc_builtins::bitcode::{
|
||||||
IntWidth::{self, *},
|
IntWidth::{self, *},
|
||||||
};
|
};
|
||||||
use roc_collections::VecMap;
|
use roc_collections::VecMap;
|
||||||
use roc_module::symbol::{Interns, ModuleId, Symbol};
|
use roc_module::symbol::{Interns, Symbol};
|
||||||
use roc_mono::layout::{
|
use roc_mono::layout::{
|
||||||
cmp_fields, ext_var_is_empty_tag_union, round_up_to_alignment, Builtin, Layout, LayoutCache,
|
cmp_fields, ext_var_is_empty_tag_union, round_up_to_alignment, Builtin, Layout, LayoutCache,
|
||||||
UnionLayout,
|
MultimorphicNames, UnionLayout,
|
||||||
};
|
};
|
||||||
use roc_target::TargetInfo;
|
use roc_target::TargetInfo;
|
||||||
use roc_types::{
|
use roc_types::{
|
||||||
|
@ -410,41 +410,26 @@ pub struct Env<'a> {
|
||||||
arena: &'a Bump,
|
arena: &'a Bump,
|
||||||
subs: &'a Subs,
|
subs: &'a Subs,
|
||||||
layout_cache: LayoutCache<'a>,
|
layout_cache: LayoutCache<'a>,
|
||||||
home: ModuleId,
|
|
||||||
interns: &'a mut Interns,
|
interns: &'a mut Interns,
|
||||||
struct_names: Structs,
|
struct_names: Structs,
|
||||||
enum_names: Enums,
|
enum_names: Enums,
|
||||||
pending_recursive_types: VecMap<TypeId, Layout<'a>>,
|
pending_recursive_types: VecMap<TypeId, Layout<'a>>,
|
||||||
known_recursive_types: VecMap<Layout<'a>, TypeId>,
|
known_recursive_types: VecMap<Layout<'a>, TypeId>,
|
||||||
target: TargetInfo,
|
target: TargetInfo,
|
||||||
}
|
multimorphic_names: &'a mut MultimorphicNames,
|
||||||
|
|
||||||
macro_rules! fresh_multimorphic_symbol {
|
|
||||||
($env:expr) => {
|
|
||||||
&mut || {
|
|
||||||
let ident_id = $env
|
|
||||||
.interns
|
|
||||||
.all_ident_ids
|
|
||||||
.get_mut(&$env.home)
|
|
||||||
.unwrap()
|
|
||||||
.gen_unique();
|
|
||||||
Symbol::new($env.home, ident_id)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Env<'a> {
|
impl<'a> Env<'a> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
home: ModuleId,
|
|
||||||
arena: &'a Bump,
|
arena: &'a Bump,
|
||||||
subs: &'a Subs,
|
subs: &'a Subs,
|
||||||
interns: &'a mut Interns,
|
interns: &'a mut Interns,
|
||||||
target: TargetInfo,
|
target: TargetInfo,
|
||||||
|
multimorphic_names: &'a mut MultimorphicNames,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Env {
|
Env {
|
||||||
arena,
|
arena,
|
||||||
subs,
|
subs,
|
||||||
home,
|
|
||||||
interns,
|
interns,
|
||||||
struct_names: Default::default(),
|
struct_names: Default::default(),
|
||||||
enum_names: Default::default(),
|
enum_names: Default::default(),
|
||||||
|
@ -452,6 +437,7 @@ impl<'a> Env<'a> {
|
||||||
known_recursive_types: Default::default(),
|
known_recursive_types: Default::default(),
|
||||||
layout_cache: LayoutCache::new(target),
|
layout_cache: LayoutCache::new(target),
|
||||||
target,
|
target,
|
||||||
|
multimorphic_names,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -473,7 +459,7 @@ impl<'a> Env<'a> {
|
||||||
fn add_type(&mut self, var: Variable, types: &mut Types) -> TypeId {
|
fn add_type(&mut self, var: Variable, types: &mut Types) -> TypeId {
|
||||||
let layout = self
|
let layout = self
|
||||||
.layout_cache
|
.layout_cache
|
||||||
.from_var(self.arena, var, self.subs, fresh_multimorphic_symbol!(self))
|
.from_var(self.arena, var, self.subs, self.multimorphic_names)
|
||||||
.expect("Something weird ended up in the content");
|
.expect("Something weird ended up in the content");
|
||||||
|
|
||||||
add_type_help(self, layout, var, None, types)
|
add_type_help(self, layout, var, None, types)
|
||||||
|
@ -609,7 +595,7 @@ fn add_type_help<'a>(
|
||||||
let type_id = types.add(RocType::RecursivePointer(TypeId::PENDING), layout);
|
let type_id = types.add(RocType::RecursivePointer(TypeId::PENDING), layout);
|
||||||
let structure_layout = env
|
let structure_layout = env
|
||||||
.layout_cache
|
.layout_cache
|
||||||
.from_var(env.arena, *structure, subs, fresh_multimorphic_symbol!(env))
|
.from_var(env.arena, *structure, subs, env.multimorphic_names)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
env.pending_recursive_types
|
env.pending_recursive_types
|
||||||
|
@ -717,7 +703,7 @@ where
|
||||||
label,
|
label,
|
||||||
field_var,
|
field_var,
|
||||||
env.layout_cache
|
env.layout_cache
|
||||||
.from_var(env.arena, field_var, subs, fresh_multimorphic_symbol!(env))
|
.from_var(env.arena, field_var, subs, env.multimorphic_names)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -787,12 +773,7 @@ fn add_tag_union<'a>(
|
||||||
let payload_var = payload_vars.get(0).unwrap();
|
let payload_var = payload_vars.get(0).unwrap();
|
||||||
let payload_layout = env
|
let payload_layout = env
|
||||||
.layout_cache
|
.layout_cache
|
||||||
.from_var(
|
.from_var(env.arena, *payload_var, env.subs, env.multimorphic_names)
|
||||||
env.arena,
|
|
||||||
*payload_var,
|
|
||||||
env.subs,
|
|
||||||
fresh_multimorphic_symbol!(env),
|
|
||||||
)
|
|
||||||
.expect("Something weird ended up in the content");
|
.expect("Something weird ended up in the content");
|
||||||
let payload_id = add_type_help(env, payload_layout, *payload_var, None, types);
|
let payload_id = add_type_help(env, payload_layout, *payload_var, None, types);
|
||||||
|
|
||||||
|
@ -943,7 +924,7 @@ fn struct_fields_needed<I: IntoIterator<Item = Variable>>(env: &mut Env<'_>, var
|
||||||
vars.into_iter().fold(0, |count, var| {
|
vars.into_iter().fold(0, |count, var| {
|
||||||
let layout = env
|
let layout = env
|
||||||
.layout_cache
|
.layout_cache
|
||||||
.from_var(arena, var, subs, fresh_multimorphic_symbol!(env))
|
.from_var(arena, var, subs, env.multimorphic_names)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
if layout.is_dropped_because_empty() {
|
if layout.is_dropped_because_empty() {
|
||||||
|
|
|
@ -2,6 +2,7 @@ use bumpalo::Bump;
|
||||||
use const_format::concatcp;
|
use const_format::concatcp;
|
||||||
use inkwell::context::Context;
|
use inkwell::context::Context;
|
||||||
use libloading::Library;
|
use libloading::Library;
|
||||||
|
use roc_mono::layout::MultimorphicNames;
|
||||||
use rustyline::highlight::{Highlighter, PromptInfo};
|
use rustyline::highlight::{Highlighter, PromptInfo};
|
||||||
use rustyline::validate::{self, ValidationContext, ValidationResult, Validator};
|
use rustyline::validate::{self, ValidationContext, ValidationResult, Validator};
|
||||||
use rustyline_derive::{Completer, Helper, Hinter};
|
use rustyline_derive::{Completer, Helper, Hinter};
|
||||||
|
@ -305,7 +306,8 @@ fn gen_and_eval_llvm<'a>(
|
||||||
|
|
||||||
let app = CliApp { lib };
|
let app = CliApp { lib };
|
||||||
|
|
||||||
let mut env = env;
|
let mut multimorphic_names = MultimorphicNames::default();
|
||||||
|
|
||||||
let res_answer = jit_to_ast(
|
let res_answer = jit_to_ast(
|
||||||
&arena,
|
&arena,
|
||||||
&app,
|
&app,
|
||||||
|
@ -313,8 +315,7 @@ fn gen_and_eval_llvm<'a>(
|
||||||
main_fn_layout,
|
main_fn_layout,
|
||||||
content,
|
content,
|
||||||
&subs,
|
&subs,
|
||||||
home,
|
&mut multimorphic_names,
|
||||||
env.interns.all_ident_ids.get_mut(&home).unwrap(),
|
|
||||||
target_info,
|
target_info,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
use bumpalo::collections::Vec;
|
use bumpalo::collections::Vec;
|
||||||
use bumpalo::Bump;
|
use bumpalo::Bump;
|
||||||
use roc_mono::fresh_multimorphic_symbol;
|
|
||||||
use std::cmp::{max_by_key, min_by_key};
|
use std::cmp::{max_by_key, min_by_key};
|
||||||
|
|
||||||
use roc_builtins::bitcode::{FloatWidth, IntWidth};
|
use roc_builtins::bitcode::{FloatWidth, IntWidth};
|
||||||
use roc_collections::all::MutMap;
|
use roc_collections::all::MutMap;
|
||||||
use roc_module::called_via::CalledVia;
|
use roc_module::called_via::CalledVia;
|
||||||
use roc_module::ident::TagName;
|
use roc_module::ident::TagName;
|
||||||
use roc_module::symbol::{IdentIds, ModuleId, Symbol};
|
use roc_module::symbol::Symbol;
|
||||||
use roc_mono::ir::ProcLayout;
|
use roc_mono::ir::ProcLayout;
|
||||||
use roc_mono::layout::{
|
use roc_mono::layout::{
|
||||||
union_sorted_tags_help, Builtin, Layout, LayoutCache, UnionLayout, UnionVariant, WrappedVariant,
|
union_sorted_tags_help, Builtin, Layout, LayoutCache, MultimorphicNames, UnionLayout,
|
||||||
|
UnionVariant, WrappedVariant,
|
||||||
};
|
};
|
||||||
use roc_parse::ast::{AssignedField, Collection, Expr, StrLiteral};
|
use roc_parse::ast::{AssignedField, Collection, Expr, StrLiteral};
|
||||||
use roc_region::all::{Loc, Region};
|
use roc_region::all::{Loc, Region};
|
||||||
|
@ -21,11 +21,10 @@ use roc_types::subs::{Content, FlatType, GetSubsSlice, RecordFields, Subs, Union
|
||||||
use crate::{ReplApp, ReplAppMemory};
|
use crate::{ReplApp, ReplAppMemory};
|
||||||
|
|
||||||
struct Env<'a> {
|
struct Env<'a> {
|
||||||
home: ModuleId,
|
|
||||||
arena: &'a Bump,
|
arena: &'a Bump,
|
||||||
subs: &'a Subs,
|
subs: &'a Subs,
|
||||||
target_info: TargetInfo,
|
target_info: TargetInfo,
|
||||||
ident_ids: &'a mut IdentIds,
|
multimorphic_names: &'a mut MultimorphicNames,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum ToAstProblem {
|
pub enum ToAstProblem {
|
||||||
|
@ -48,16 +47,14 @@ pub fn jit_to_ast<'a, A: ReplApp<'a>>(
|
||||||
layout: ProcLayout<'a>,
|
layout: ProcLayout<'a>,
|
||||||
content: &'a Content,
|
content: &'a Content,
|
||||||
subs: &'a Subs,
|
subs: &'a Subs,
|
||||||
module_id: ModuleId,
|
multimorphic_names: &'a mut MultimorphicNames,
|
||||||
ident_ids: &'a mut IdentIds,
|
|
||||||
target_info: TargetInfo,
|
target_info: TargetInfo,
|
||||||
) -> Result<Expr<'a>, ToAstProblem> {
|
) -> Result<Expr<'a>, ToAstProblem> {
|
||||||
let mut env = Env {
|
let mut env = Env {
|
||||||
arena,
|
arena,
|
||||||
subs,
|
subs,
|
||||||
target_info,
|
target_info,
|
||||||
home: module_id,
|
multimorphic_names,
|
||||||
ident_ids,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
match layout {
|
match layout {
|
||||||
|
@ -193,7 +190,7 @@ fn get_tags_vars_and_variant<'a>(
|
||||||
opt_rec_var,
|
opt_rec_var,
|
||||||
env.subs,
|
env.subs,
|
||||||
env.target_info,
|
env.target_info,
|
||||||
fresh_multimorphic_symbol!(env),
|
env.multimorphic_names,
|
||||||
);
|
);
|
||||||
|
|
||||||
(vars_of_tag, union_variant)
|
(vars_of_tag, union_variant)
|
||||||
|
@ -913,12 +910,7 @@ fn struct_to_ast<'a, M: ReplAppMemory>(
|
||||||
|
|
||||||
let inner_content = env.subs.get_content_without_compacting(field.into_inner());
|
let inner_content = env.subs.get_content_without_compacting(field.into_inner());
|
||||||
let field_layout = layout_cache
|
let field_layout = layout_cache
|
||||||
.from_var(
|
.from_var(arena, field.into_inner(), env.subs, env.multimorphic_names)
|
||||||
arena,
|
|
||||||
field.into_inner(),
|
|
||||||
env.subs,
|
|
||||||
fresh_multimorphic_symbol!(env),
|
|
||||||
)
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let inner_layouts = arena.alloc([field_layout]);
|
let inner_layouts = arena.alloc([field_layout]);
|
||||||
|
|
||||||
|
@ -957,12 +949,7 @@ fn struct_to_ast<'a, M: ReplAppMemory>(
|
||||||
for (label, field) in record_fields.sorted_iterator(subs, Variable::EMPTY_RECORD) {
|
for (label, field) in record_fields.sorted_iterator(subs, Variable::EMPTY_RECORD) {
|
||||||
let content = subs.get_content_without_compacting(field.into_inner());
|
let content = subs.get_content_without_compacting(field.into_inner());
|
||||||
let field_layout = layout_cache
|
let field_layout = layout_cache
|
||||||
.from_var(
|
.from_var(arena, field.into_inner(), env.subs, env.multimorphic_names)
|
||||||
arena,
|
|
||||||
field.into_inner(),
|
|
||||||
env.subs,
|
|
||||||
fresh_multimorphic_symbol!(env),
|
|
||||||
)
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let loc_expr = &*arena.alloc(Loc {
|
let loc_expr = &*arena.alloc(Loc {
|
||||||
|
@ -1162,7 +1149,7 @@ fn byte_to_ast<'a, M: ReplAppMemory>(
|
||||||
None,
|
None,
|
||||||
env.subs,
|
env.subs,
|
||||||
env.target_info,
|
env.target_info,
|
||||||
fresh_multimorphic_symbol!(env),
|
env.multimorphic_names,
|
||||||
);
|
);
|
||||||
|
|
||||||
match union_variant {
|
match union_variant {
|
||||||
|
|
|
@ -26,6 +26,7 @@ roc_repl_eval = {path = "../repl_eval"}
|
||||||
roc_reporting = {path = "../reporting"}
|
roc_reporting = {path = "../reporting"}
|
||||||
roc_target = {path = "../compiler/roc_target"}
|
roc_target = {path = "../compiler/roc_target"}
|
||||||
roc_types = {path = "../compiler/types"}
|
roc_types = {path = "../compiler/types"}
|
||||||
|
roc_mono = {path = "../compiler/mono"}
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
wasmer = ["futures"]
|
wasmer = ["futures"]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use bumpalo::{collections::vec::Vec, Bump};
|
use bumpalo::{collections::vec::Vec, Bump};
|
||||||
|
use roc_mono::layout::MultimorphicNames;
|
||||||
use std::mem::size_of;
|
use std::mem::size_of;
|
||||||
|
|
||||||
use roc_collections::all::MutSet;
|
use roc_collections::all::MutSet;
|
||||||
|
@ -241,6 +242,7 @@ pub async fn entrypoint_from_js(src: String) -> Result<String, String> {
|
||||||
.map_err(|js| format!("{:?}", js))?;
|
.map_err(|js| format!("{:?}", js))?;
|
||||||
|
|
||||||
let app = WasmReplApp { arena };
|
let app = WasmReplApp { arena };
|
||||||
|
let mut multimorphic_names = MultimorphicNames::default();
|
||||||
|
|
||||||
// Run the app and transform the result value to an AST `Expr`
|
// Run the app and transform the result value to an AST `Expr`
|
||||||
// Restore type constructor names, and other user-facing info that was erased during compilation.
|
// Restore type constructor names, and other user-facing info that was erased during compilation.
|
||||||
|
@ -251,7 +253,7 @@ pub async fn entrypoint_from_js(src: String) -> Result<String, String> {
|
||||||
main_fn_layout,
|
main_fn_layout,
|
||||||
content,
|
content,
|
||||||
&subs,
|
&subs,
|
||||||
module_id, interns.all_ident_ids.get_mut(&module_id).unwrap(),
|
&mut multimorphic_names,
|
||||||
target_info,
|
target_info,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue