Skip to content

Commit

Permalink
Merge #835
Browse files Browse the repository at this point in the history
835: refactor: Store ExternLoaders in salsa r=Marwes a=Marwes

One less thing that is untracked by salsa.

Co-authored-by: Markus Westerlind <[email protected]>
  • Loading branch information
bors[bot] and Marwes authored Jun 6, 2020
2 parents 77652ab + c59e8f2 commit e9f115b
Show file tree
Hide file tree
Showing 17 changed files with 487 additions and 550 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 16 additions & 21 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
extern crate gluon_base;
extern crate itertools;
extern crate walkdir;
use std::{
env,
fs::File,
io::{Read, Write},
path::Path,
};

use std::env;
use std::fs::File;
use std::io::{Read, Write};
use std::path::Path;

use itertools::Itertools;

use walkdir::WalkDir;
use {itertools::Itertools, walkdir::WalkDir};

use gluon_base::filename_to_module;

#[cfg(feature = "test")]
mod gen_skeptic {
extern crate little_skeptic as skeptic;
extern crate walkdir;
use little_skeptic as skeptic;

use std::env;
use std::fs::{self, File};
use std::io::prelude::*;
use std::path::{Path, PathBuf};
use std::{
env,
fs::{self, File},
io::Read,
path::{Path, PathBuf},
};

/// skeptic templates look for `rust` after the opening code fences so writing
/// ```f#,rust
Expand Down Expand Up @@ -64,14 +61,12 @@ return;
File::open(file)
.and_then(|mut raw_file| raw_file.read_to_end(&mut contents))
.unwrap();
File::create(&out_file_name)
.and_then(|mut out_file| out_file.write_all(&contents))
.unwrap();
fs::write(&out_file_name, contents).unwrap();
out_file_name.to_str().expect("UTF-8 string").into()
}

pub fn generate() {
let test_locations: Vec<_> = self::walkdir::WalkDir::new("book/src")
let test_locations: Vec<_> = walkdir::WalkDir::new("book/src")
.into_iter()
.filter_map(|e| {
let e = e.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion doc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ impl DocCollector<'_> {
);

let (expr, typ) = thread.typecheck_str(&name, &content, None)?;
let (meta, _) = metadata(&thread.get_database(), &expr.expr());
let (meta, _) = metadata(&thread.get_database().as_env(), &expr.expr());

create_dir_all(out_path.join(module_path.parent().unwrap_or(Path::new(""))))?;

Expand Down
41 changes: 26 additions & 15 deletions repl/src/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ use crate::vm::{
IO,
},
internal::ValuePrinter,
thread::{ActiveThread, RootedValue, Thread, ThreadInternal},
thread::{ActiveThread, RootedValue, Thread},
{self, Error as VMError, Result as VMResult},
};

use gluon::{
compiler_pipeline::{Executable, ExecuteValue},
import::add_extern_module,
query::CompilerDatabase,
Error as GluonError, Result as GluonResult, RootedThread, ThreadExt,
};

Expand Down Expand Up @@ -436,6 +437,9 @@ async fn eval_line_(vm: RootedThread, line: &str) -> gluon::Result<()> {
let ExecuteValue { value, typ, .. } = (&mut eval_expr)
.run_expr(&mut module_compiler, vm.clone(), "line", line, None)
.await?;

drop(db);

if is_let_binding {
let mut expr = eval_expr.expr();
let mut last_bind = None;
Expand All @@ -448,7 +452,13 @@ async fn eval_line_(vm: RootedThread, line: &str) -> gluon::Result<()> {
_ => break,
}
}
set_globals(&vm, &last_bind.unwrap().name, &typ, &value.as_ref())?;
set_globals(
&vm,
&mut vm.get_database_mut(),
&last_bind.unwrap().name,
&typ,
&value.as_ref(),
)?;
}
let vm = value.vm();
let env = vm.get_env();
Expand All @@ -464,33 +474,34 @@ async fn eval_line_(vm: RootedThread, line: &str) -> gluon::Result<()> {

fn set_globals(
vm: &Thread,
db: &mut CompilerDatabase,
pattern: &SpannedPattern<Symbol>,
typ: &ArcType,
value: &RootedValue<&Thread>,
) -> GluonResult<()> {
match pattern.value {
Pattern::Ident(ref id) => {
vm.set_global(
Symbol::from(format!("@{}", id.name.declared_name())),
db.set_global(
id.name.declared_name(),
typ.clone(),
Default::default(),
value.get_value(),
)?;
);
Ok(())
}
Pattern::Tuple { ref elems, .. } => {
let iter = elems
.iter()
.zip(crate::vm::dynamic::field_iter(&value, typ, vm));
for (elem_pattern, (elem_value, elem_type)) in iter {
set_globals(vm, elem_pattern, &elem_type, &elem_value)?;
set_globals(vm, db, elem_pattern, &elem_type, &elem_value)?;
}
Ok(())
}
Pattern::Record { ref fields, .. } => {
let resolved_type = {
let mut type_cache = vm.global_env().type_cache();
let env = vm.get_env();
let env = db.as_env();
resolve::remove_aliases_cow(&env, &mut type_cache, typ)
};

Expand All @@ -517,26 +528,26 @@ fn set_globals(
.clone();
match pattern_value {
Some(ref sub_pattern) => {
set_globals(vm, sub_pattern, &field_type, &field_value)?
set_globals(vm, db, sub_pattern, &field_type, &field_value)?
}
None => vm.set_global(
Symbol::from(format!("@{}", name.value.declared_name())),
None => db.set_global(
name.value.declared_name(),
field_type.to_owned(),
Default::default(),
field_value.get_value(),
)?,
),
}
}
Ok(())
}
Pattern::As(ref id, ref pattern) => {
vm.set_global(
Symbol::from(format!("@{}", id.value.declared_name())),
db.set_global(
id.value.declared_name(),
typ.clone(),
Default::default(),
value.get_value(),
)?;
set_globals(vm, pattern, typ, value)
);
set_globals(vm, db, pattern, typ, value)
}
Pattern::Constructor(..) | Pattern::Literal(_) | Pattern::Error => {
Err(VMError::Message("The repl cannot bind variables from this pattern".into()).into())
Expand Down
Loading

0 comments on commit e9f115b

Please sign in to comment.