Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor engine structure #273

Merged
merged 27 commits into from
Oct 24, 2024
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix build
mattwparas committed Oct 15, 2024

Verified

This commit was signed with the committer’s verified signature.
commit 40df7e1d5ea6a8e3c639fb291da4705617c51211
72 changes: 0 additions & 72 deletions crates/steel-core/src/compiler/modules.rs
Original file line number Diff line number Diff line change
@@ -342,78 +342,6 @@ impl ModuleManager {
ExprKind::List(l) => {
if let Some(qualifier) = l.first_ident() {
match *qualifier {
// x if x == *CONTRACT_OUT => {
// // Directly expand into define/contract, but with the value just being the hash get below

// // (bind/c contract name 'name)

// let name = l.args.get(1).unwrap();

// if !explicit_requires.is_empty()
// && !name
// .atom_identifier()
// .map(|x| explicit_requires.contains_key(x))
// .unwrap_or_default()
// {
// continue;
// }

// // TODO: This should surface an error - cannot use contract
// // out on a macro
// if module
// .macro_map
// .contains_key(name.atom_identifier().unwrap())
// {
// continue;
// }

// // TODO: THe contract has to get mangled with the prefix as well?
// let _contract = l.args.get(2).unwrap();

// let hash_get = expr_list![
// ExprKind::atom(*PROTO_HASH_GET),
// ExprKind::atom(
// "__module-".to_string() + &other_module_prefix
// ),
// ExprKind::Quote(Box::new(Quote::new(
// name.clone(),
// SyntaxObject::default(TokenType::Quote)
// ))),
// ];

// let mut owned_name = name.clone();

// // If we have the alias listed, we should use it
// if !explicit_requires.is_empty() {
// if let Some(alias) = explicit_requires
// .get(name.atom_identifier().unwrap())
// .copied()
// .flatten()
// {
// *owned_name.atom_identifier_mut().unwrap() =
// alias.clone();
// }
// }

// if let Some(prefix) = &require_object.prefix {
// if let Some(existing) = owned_name.atom_identifier_mut()
// {
// let mut prefixed_identifier = prefix.clone();
// prefixed_identifier.push_str(existing.resolve());

// // Update the existing identifier to point to a new one with the prefix applied
// *existing = prefixed_identifier.into();
// }
// }

// let define = ExprKind::Define(Box::new(Define::new(
// owned_name,
// hash_get,
// SyntaxObject::default(TokenType::Define),
// )));

// require_defines.push(define);
// }
x if x == *REQUIRE_IDENT_SPEC => {
// Directly expand into define/contract, but with the value just being the hash get below

4 changes: 2 additions & 2 deletions crates/steel-core/src/parser/kernel.rs
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@

#[cfg(not(feature = "sync"))]
{
KERNEL_IMAGE_SB.with(|x| x.clone())
KERNEL_IMAGE_SB.with(|x| x.deep_clone())
}
} else {
#[cfg(feature = "sync")]
@@ -63,7 +63,7 @@

#[cfg(not(feature = "sync"))]
{
KERNEL_IMAGE.with(|x| x.clone())
KERNEL_IMAGE.with(|x| x.deep_clone())
}
}
}
@@ -156,7 +156,7 @@
}
}

pub(crate) fn bootstrap(_engine: Engine) -> (Self, RawProgramWithSymbols) {

Check warning on line 159 in crates/steel-core/src/parser/kernel.rs

GitHub Actions / Test Suite (sync)

associated functions `bootstrap` and `initialize_post_bootstrap` are never used

Check warning on line 159 in crates/steel-core/src/parser/kernel.rs

GitHub Actions / Test Suite

associated functions `bootstrap` and `initialize_post_bootstrap` are never used
todo!()

// let transformers = Transformers {
59 changes: 27 additions & 32 deletions crates/steel-core/src/steel_vm/engine.rs
Original file line number Diff line number Diff line change
@@ -411,6 +411,29 @@ impl Engine {
self.virtual_machine.id
}

#[cfg(not(feature = "sync"))]
pub(crate) fn deep_clone(&self) -> Self {
let mut engine = self.clone();

let compiler_copy = engine.virtual_machine.compiler.read().clone();
engine.virtual_machine.compiler = Arc::new(RwLock::new(compiler_copy));

let constant_map = engine
.virtual_machine
.compiler
.read()
.constant_map
.deep_clone();
engine.virtual_machine.compiler.write().constant_map = constant_map;

let heap_copy = Arc::new(Mutex::new(
engine.virtual_machine.heap.lock().unwrap().clone(),
));

engine.virtual_machine.heap = heap_copy;
engine
}

#[cfg(feature = "sync")]
pub(crate) fn deep_clone(&self) -> Self {
let mut engine = self.clone();
@@ -1326,7 +1349,9 @@ impl Engine {
pub fn new() -> Self {
let mut engine = fresh_kernel_image(false);

engine.virtual_machine.compiler.write().kernel = Some(Kernel::new());
{
engine.virtual_machine.compiler.write().kernel = Some(Kernel::new());
}

#[cfg(feature = "profiling")]
let now = std::time::Instant::now();
@@ -1754,37 +1779,7 @@ impl Engine {
.increment_generation();
}

// TODO: This isn't my favorite pattern.
// I'd prefer to just use a weak reference, but I don't think
// it is really worth it.

// {
// let constants = self.constants();
// let mut guard = self.virtual_machine.compiler.lock().unwrap();
// let compiler = &mut self.compiler as *mut _;

// let compiler_value = SelfCompiler {
// compiler: Some(compiler),
// sources: self.sources.clone(),
// modules: self.modules.clone(),
// constants,
// };
// *guard = Some(compiler_value);
// }

let res = self.virtual_machine.run_executable(&executable);

// Overwrite the compiler reference
// self.virtual_machine
// .compiler
// .lock()
// .unwrap()
// .as_mut()
// .unwrap()
// .compiler
// .take();

res
self.virtual_machine.run_executable(&executable)
}

pub fn run_executable(&mut self, executable: &Executable) -> Result<Vec<SteelVal>> {

Unchanged files with check annotations Beta

#[test]
fn test_nan() {
// nan does not equal nan so we have to run the is_nan predicate.
let got = TokenStream::new("+nan.0", true, SourceId::none())

Check warning on line 929 in crates/steel-parser/src/lexer.rs

GitHub Actions / Test Suite (sync)

unused variable: `got`
.next()
.unwrap();
}
impl SerializableCompiler {
pub(crate) fn into_compiler(self) -> Compiler {

Check warning on line 319 in crates/steel-core/src/compiler/compiler.rs

GitHub Actions / Test Suite (sync)

method `into_compiler` is never used

Check warning on line 319 in crates/steel-core/src/compiler/compiler.rs

GitHub Actions / Test Suite

method `into_compiler` is never used
let mut compiler = Compiler::default();
compiler.symbol_map = self.symbol_map;
}
impl Compiler {
pub(crate) fn into_serializable_compiler(self) -> Result<SerializableCompiler> {

Check warning on line 333 in crates/steel-core/src/compiler/compiler.rs

GitHub Actions / Test Suite (sync)

method `into_serializable_compiler` is never used

Check warning on line 333 in crates/steel-core/src/compiler/compiler.rs

GitHub Actions / Test Suite

method `into_serializable_compiler` is never used
Ok(SerializableCompiler {
symbol_map: self.symbol_map,
constant_map: self.constant_map.into_serializable_map(),
}
}
pub(crate) fn into_serializable_map(self) -> SerializableConstantMap {

Check warning on line 66 in crates/steel-core/src/compiler/constants.rs

GitHub Actions / Test Suite (sync)

method `into_serializable_map` is never used

Check warning on line 66 in crates/steel-core/src/compiler/constants.rs

GitHub Actions / Test Suite

method `into_serializable_map` is never used
SerializableConstantMap(self.to_bytes().unwrap())
}
use std::rc::Rc;

Check warning on line 1 in libs/steel-markdown/src/lib.rs

GitHub Actions / Test Suite (sync)

unused import: `std::rc::Rc`

Check warning on line 1 in libs/steel-markdown/src/lib.rs

GitHub Actions / Test Suite

unused import: `std::rc::Rc`
use abi_stable::std_types::RBoxError;

Check warning on line 3 in libs/steel-markdown/src/lib.rs

GitHub Actions / Test Suite (sync)

unused import: `abi_stable::std_types::RBoxError`

Check warning on line 3 in libs/steel-markdown/src/lib.rs

GitHub Actions / Test Suite

unused import: `abi_stable::std_types::RBoxError`
use steel::{
gc::Shared,
rvals::{Custom, SerializableSteelVal},

Check warning on line 6 in libs/steel-markdown/src/lib.rs

GitHub Actions / Test Suite (sync)

unused import: `SerializableSteelVal`
steel_vm::ffi::{FFIModule, FFIValue, IntoFFIVal, RegisterFFIFn},
};
struct AsyncRequest(Option<http::request::Builder>);
struct FinalizedAsyncRequest(Option<http::request::Request<String>>);
struct AsyncResponse(isahc::Response<String>);

Check warning on line 89 in libs/steel-async-webrequests/src/lib.rs

GitHub Actions / Test Suite

struct `AsyncResponse` is never constructed
#[derive(Clone)]
struct Client(isahc::HttpClient);
#[derive(Clone)]
struct BlockingRequest(Option<Request>);
struct BlockingResponse(Response);

Check warning on line 47 in libs/steel-webrequests/src/lib.rs

GitHub Actions / Test Suite

struct `BlockingResponse` is never constructed
#[derive(Clone)]
struct Client(ureq::Agent);
#[derive(Debug)]
enum BlockingError {
Ureq(ureq::Error),

Check warning on line 54 in libs/steel-webrequests/src/lib.rs

GitHub Actions / Test Suite

field `0` is never read
ResponseAlreadyUsed,
}