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_gen_wasm",
|
||||
"roc_load",
|
||||
"roc_mono",
|
||||
"roc_parse",
|
||||
"roc_repl_eval",
|
||||
"roc_reporting",
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use crate::types::{Env, Types};
|
||||
use bumpalo::Bump;
|
||||
use roc_load::{LoadedModule, Threading};
|
||||
use roc_mono::layout::MultimorphicNames;
|
||||
use roc_reporting::report::RenderTarget;
|
||||
use roc_target::{Architecture, TargetInfo};
|
||||
use std::io;
|
||||
|
@ -36,6 +37,8 @@ pub fn load_types(
|
|||
)
|
||||
.expect("Problem loading platform module");
|
||||
|
||||
let mut multimorphic_names = MultimorphicNames::default();
|
||||
|
||||
let decls = declarations_by_id.remove(&home).unwrap();
|
||||
let subs = solved.inner_mut();
|
||||
|
||||
|
@ -74,7 +77,13 @@ pub fn load_types(
|
|||
let types_and_targets = Architecture::iter()
|
||||
.map(|arch| {
|
||||
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)
|
||||
})
|
||||
|
|
|
@ -6,10 +6,10 @@ use roc_builtins::bitcode::{
|
|||
IntWidth::{self, *},
|
||||
};
|
||||
use roc_collections::VecMap;
|
||||
use roc_module::symbol::{Interns, ModuleId, Symbol};
|
||||
use roc_module::symbol::{Interns, Symbol};
|
||||
use roc_mono::layout::{
|
||||
cmp_fields, ext_var_is_empty_tag_union, round_up_to_alignment, Builtin, Layout, LayoutCache,
|
||||
UnionLayout,
|
||||
MultimorphicNames, UnionLayout,
|
||||
};
|
||||
use roc_target::TargetInfo;
|
||||
use roc_types::{
|
||||
|
@ -410,41 +410,26 @@ pub struct Env<'a> {
|
|||
arena: &'a Bump,
|
||||
subs: &'a Subs,
|
||||
layout_cache: LayoutCache<'a>,
|
||||
home: ModuleId,
|
||||
interns: &'a mut Interns,
|
||||
struct_names: Structs,
|
||||
enum_names: Enums,
|
||||
pending_recursive_types: VecMap<TypeId, Layout<'a>>,
|
||||
known_recursive_types: VecMap<Layout<'a>, TypeId>,
|
||||
target: TargetInfo,
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
};
|
||||
multimorphic_names: &'a mut MultimorphicNames,
|
||||
}
|
||||
|
||||
impl<'a> Env<'a> {
|
||||
pub fn new(
|
||||
home: ModuleId,
|
||||
arena: &'a Bump,
|
||||
subs: &'a Subs,
|
||||
interns: &'a mut Interns,
|
||||
target: TargetInfo,
|
||||
multimorphic_names: &'a mut MultimorphicNames,
|
||||
) -> Self {
|
||||
Env {
|
||||
arena,
|
||||
subs,
|
||||
home,
|
||||
interns,
|
||||
struct_names: Default::default(),
|
||||
enum_names: Default::default(),
|
||||
|
@ -452,6 +437,7 @@ impl<'a> Env<'a> {
|
|||
known_recursive_types: Default::default(),
|
||||
layout_cache: LayoutCache::new(target),
|
||||
target,
|
||||
multimorphic_names,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -473,7 +459,7 @@ impl<'a> Env<'a> {
|
|||
fn add_type(&mut self, var: Variable, types: &mut Types) -> TypeId {
|
||||
let layout = self
|
||||
.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");
|
||||
|
||||
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 structure_layout = env
|
||||
.layout_cache
|
||||
.from_var(env.arena, *structure, subs, fresh_multimorphic_symbol!(env))
|
||||
.from_var(env.arena, *structure, subs, env.multimorphic_names)
|
||||
.unwrap();
|
||||
|
||||
env.pending_recursive_types
|
||||
|
@ -717,7 +703,7 @@ where
|
|||
label,
|
||||
field_var,
|
||||
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(),
|
||||
));
|
||||
}
|
||||
|
@ -787,12 +773,7 @@ fn add_tag_union<'a>(
|
|||
let payload_var = payload_vars.get(0).unwrap();
|
||||
let payload_layout = env
|
||||
.layout_cache
|
||||
.from_var(
|
||||
env.arena,
|
||||
*payload_var,
|
||||
env.subs,
|
||||
fresh_multimorphic_symbol!(env),
|
||||
)
|
||||
.from_var(env.arena, *payload_var, env.subs, env.multimorphic_names)
|
||||
.expect("Something weird ended up in the content");
|
||||
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| {
|
||||
let layout = env
|
||||
.layout_cache
|
||||
.from_var(arena, var, subs, fresh_multimorphic_symbol!(env))
|
||||
.from_var(arena, var, subs, env.multimorphic_names)
|
||||
.unwrap();
|
||||
|
||||
if layout.is_dropped_because_empty() {
|
||||
|
|
|
@ -2,6 +2,7 @@ use bumpalo::Bump;
|
|||
use const_format::concatcp;
|
||||
use inkwell::context::Context;
|
||||
use libloading::Library;
|
||||
use roc_mono::layout::MultimorphicNames;
|
||||
use rustyline::highlight::{Highlighter, PromptInfo};
|
||||
use rustyline::validate::{self, ValidationContext, ValidationResult, Validator};
|
||||
use rustyline_derive::{Completer, Helper, Hinter};
|
||||
|
@ -305,7 +306,8 @@ fn gen_and_eval_llvm<'a>(
|
|||
|
||||
let app = CliApp { lib };
|
||||
|
||||
let mut env = env;
|
||||
let mut multimorphic_names = MultimorphicNames::default();
|
||||
|
||||
let res_answer = jit_to_ast(
|
||||
&arena,
|
||||
&app,
|
||||
|
@ -313,8 +315,7 @@ fn gen_and_eval_llvm<'a>(
|
|||
main_fn_layout,
|
||||
content,
|
||||
&subs,
|
||||
home,
|
||||
env.interns.all_ident_ids.get_mut(&home).unwrap(),
|
||||
&mut multimorphic_names,
|
||||
target_info,
|
||||
);
|
||||
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
use bumpalo::collections::Vec;
|
||||
use bumpalo::Bump;
|
||||
use roc_mono::fresh_multimorphic_symbol;
|
||||
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::TagName;
|
||||
use roc_module::symbol::{IdentIds, ModuleId, Symbol};
|
||||
use roc_module::symbol::Symbol;
|
||||
use roc_mono::ir::ProcLayout;
|
||||
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_region::all::{Loc, Region};
|
||||
|
@ -21,11 +21,10 @@ use roc_types::subs::{Content, FlatType, GetSubsSlice, RecordFields, Subs, Union
|
|||
use crate::{ReplApp, ReplAppMemory};
|
||||
|
||||
struct Env<'a> {
|
||||
home: ModuleId,
|
||||
arena: &'a Bump,
|
||||
subs: &'a Subs,
|
||||
target_info: TargetInfo,
|
||||
ident_ids: &'a mut IdentIds,
|
||||
multimorphic_names: &'a mut MultimorphicNames,
|
||||
}
|
||||
|
||||
pub enum ToAstProblem {
|
||||
|
@ -48,16 +47,14 @@ pub fn jit_to_ast<'a, A: ReplApp<'a>>(
|
|||
layout: ProcLayout<'a>,
|
||||
content: &'a Content,
|
||||
subs: &'a Subs,
|
||||
module_id: ModuleId,
|
||||
ident_ids: &'a mut IdentIds,
|
||||
multimorphic_names: &'a mut MultimorphicNames,
|
||||
target_info: TargetInfo,
|
||||
) -> Result<Expr<'a>, ToAstProblem> {
|
||||
let mut env = Env {
|
||||
arena,
|
||||
subs,
|
||||
target_info,
|
||||
home: module_id,
|
||||
ident_ids,
|
||||
multimorphic_names,
|
||||
};
|
||||
|
||||
match layout {
|
||||
|
@ -193,7 +190,7 @@ fn get_tags_vars_and_variant<'a>(
|
|||
opt_rec_var,
|
||||
env.subs,
|
||||
env.target_info,
|
||||
fresh_multimorphic_symbol!(env),
|
||||
env.multimorphic_names,
|
||||
);
|
||||
|
||||
(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 field_layout = layout_cache
|
||||
.from_var(
|
||||
arena,
|
||||
field.into_inner(),
|
||||
env.subs,
|
||||
fresh_multimorphic_symbol!(env),
|
||||
)
|
||||
.from_var(arena, field.into_inner(), env.subs, env.multimorphic_names)
|
||||
.unwrap();
|
||||
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) {
|
||||
let content = subs.get_content_without_compacting(field.into_inner());
|
||||
let field_layout = layout_cache
|
||||
.from_var(
|
||||
arena,
|
||||
field.into_inner(),
|
||||
env.subs,
|
||||
fresh_multimorphic_symbol!(env),
|
||||
)
|
||||
.from_var(arena, field.into_inner(), env.subs, env.multimorphic_names)
|
||||
.unwrap();
|
||||
|
||||
let loc_expr = &*arena.alloc(Loc {
|
||||
|
@ -1162,7 +1149,7 @@ fn byte_to_ast<'a, M: ReplAppMemory>(
|
|||
None,
|
||||
env.subs,
|
||||
env.target_info,
|
||||
fresh_multimorphic_symbol!(env),
|
||||
env.multimorphic_names,
|
||||
);
|
||||
|
||||
match union_variant {
|
||||
|
|
|
@ -26,6 +26,7 @@ roc_repl_eval = {path = "../repl_eval"}
|
|||
roc_reporting = {path = "../reporting"}
|
||||
roc_target = {path = "../compiler/roc_target"}
|
||||
roc_types = {path = "../compiler/types"}
|
||||
roc_mono = {path = "../compiler/mono"}
|
||||
|
||||
[features]
|
||||
wasmer = ["futures"]
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use bumpalo::{collections::vec::Vec, Bump};
|
||||
use roc_mono::layout::MultimorphicNames;
|
||||
use std::mem::size_of;
|
||||
|
||||
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))?;
|
||||
|
||||
let app = WasmReplApp { arena };
|
||||
let mut multimorphic_names = MultimorphicNames::default();
|
||||
|
||||
// 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.
|
||||
|
@ -251,7 +253,7 @@ pub async fn entrypoint_from_js(src: String) -> Result<String, String> {
|
|||
main_fn_layout,
|
||||
content,
|
||||
&subs,
|
||||
module_id, interns.all_ident_ids.get_mut(&module_id).unwrap(),
|
||||
&mut multimorphic_names,
|
||||
target_info,
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue