Skip to content

Commit 6e469b9

Browse files
author
Markus Westerlind
committed
fix: Allow find_type etc to work without calling global
1 parent 14e8f1d commit 6e469b9

File tree

4 files changed

+61
-44
lines changed

4 files changed

+61
-44
lines changed

rustfmt.toml

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/lib.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,14 @@ pub trait ThreadExt: Send + Sync {
487487
let mut db = vm.get_database();
488488

489489
let TypecheckValue { expr, typ, .. } = db
490-
.typechecked_module(file.into(), expected_type.cloned())
490+
.typechecked_source_module(file.into(), expected_type.cloned())
491491
.await
492492
.map_err(|t| t.1)?;
493+
494+
// Ensure the type is stored in the database so we can collect typechecked_module later
495+
db.module_type(file.into(), None).await?;
496+
db.module_metadata(file.into(), None).await?;
497+
493498
Ok((expr, typ))
494499
}
495500

@@ -587,10 +592,14 @@ pub trait ThreadExt: Send + Sync {
587592
metadata,
588593
..
589594
} = db
590-
.typechecked_module(module_name, None)
595+
.typechecked_source_module(module_name.clone(), None)
591596
.await
592597
.map_err(|(_, err)| err)?;
593598

599+
// Ensure the type is stored in the database so we can collect typechecked_module later
600+
db.module_type(module_name.clone(), None).await?;
601+
db.module_metadata(module_name.clone(), None).await?;
602+
594603
if db.compiler_settings().full_metadata {
595604
Ok((expr, typ, metadata))
596605
} else {

src/query.rs

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use {
2929
macros,
3030
thread::{RootedThread, RootedValue, Thread, ThreadInternal},
3131
vm::VmEnv,
32-
ExternLoader, ExternModule,
32+
ExternLoader,
3333
},
3434
};
3535

@@ -203,8 +203,11 @@ impl crate::query::CompilationBase for CompilerDatabase {
203203
state.add_filemap(&module, &contents[..]);
204204
}
205205

206-
fn peek_typechecked_module(&self, key: &str) -> Option<TypecheckValue<Arc<OwnedExpr<Symbol>>>> {
207-
self.query(TypecheckedModuleQuery)
206+
fn peek_typechecked_source_module(
207+
&self,
208+
key: &str,
209+
) -> Option<TypecheckValue<Arc<OwnedExpr<Symbol>>>> {
210+
self.query(TypecheckedSourceModuleQuery)
208211
.peek(&(key.into(), None))
209212
.and_then(|r| r.ok())
210213
}
@@ -327,7 +330,7 @@ impl CompilerDatabase {
327330
.sweep_all_revisions();
328331

329332
self.query(ModuleTextQuery).sweep(strategy);
330-
self.query(TypecheckedModuleQuery).sweep(strategy);
333+
self.query(TypecheckedSourceModuleQuery).sweep(strategy);
331334
self.query(CoreExprQuery).sweep(strategy);
332335
self.query(CompiledModuleQuery).sweep(strategy);
333336
}
@@ -338,7 +341,10 @@ pub trait CompilationBase: Send {
338341
fn thread(&self) -> &Thread;
339342
fn add_module(&mut self, module: String, contents: &str);
340343

341-
fn peek_typechecked_module(&self, key: &str) -> Option<TypecheckValue<Arc<OwnedExpr<Symbol>>>>;
344+
fn peek_typechecked_source_module(
345+
&self,
346+
key: &str,
347+
) -> Option<TypecheckValue<Arc<OwnedExpr<Symbol>>>>;
342348
fn peek_module_type(&self, key: &str) -> Option<ArcType>;
343349
fn peek_module_metadata(&self, key: &str) -> Option<Arc<Metadata>>;
344350
fn peek_core_expr(&self, key: &str) -> Option<interpreter::Global<CoreExpr>>;
@@ -357,9 +363,9 @@ pub trait Compilation: CompilationBase {
357363
#[salsa::input]
358364
fn extern_global(&self, name: String) -> UnrootedGlobal;
359365

366+
#[doc(hidden)]
360367
#[salsa::cycle(recover_cycle)]
361-
#[salsa::dependencies] // FIXME
362-
async fn extern_module(&self, module: String) -> Result<PtrEq<(Symbol, ExternModule)>>;
368+
async fn extern_module(&self, module: String) -> Result<UnrootedGlobal>;
363369

364370
#[salsa::transparent]
365371
fn get_extern_global(&self, name: &str) -> Option<DatabaseGlobal>;
@@ -368,7 +374,7 @@ pub trait Compilation: CompilationBase {
368374
fn module_text(&self, module: String) -> StdResult<Arc<Cow<'static, str>>, Error>;
369375

370376
#[salsa::cycle(recover_cycle_typecheck)]
371-
async fn typechecked_module(
377+
async fn typechecked_source_module(
372378
&self,
373379
module: String,
374380
expected_type: Option<ArcType>,
@@ -496,7 +502,7 @@ fn module_text(
496502
Ok(contents)
497503
}
498504

499-
async fn typechecked_module(
505+
async fn typechecked_source_module(
500506
db: &mut (impl Compilation + salsa::Database),
501507
module: String,
502508
expected_type: Option<ArcType>,
@@ -530,10 +536,10 @@ async fn module_type(
530536
expected_type: Option<ArcType>,
531537
) -> StdResult<ArcType, Error> {
532538
if db.compiler().query(ExternLoaderQuery).peek(&name).is_some() {
533-
let (_id, module) = &*db.extern_module(name).await?;
534-
return Ok(module.typ.clone());
539+
let global = db.extern_module(name).await?;
540+
return Ok(global.typ.clone());
535541
}
536-
db.typechecked_module(name, expected_type)
542+
db.typechecked_source_module(name, expected_type)
537543
.await
538544
.map(|module| module.typ)
539545
.map_err(|(_, err)| err)
@@ -545,10 +551,10 @@ async fn module_metadata(
545551
expected_type: Option<ArcType>,
546552
) -> StdResult<Arc<Metadata>, Error> {
547553
if db.compiler().query(ExternLoaderQuery).peek(&name).is_some() {
548-
let (_id, module) = &*db.extern_module(name.clone()).await?;
549-
return Ok(Arc::new(module.metadata.clone()));
554+
let global = db.extern_module(name).await?;
555+
return Ok(global.metadata.clone());
550556
}
551-
db.typechecked_module(name, expected_type)
557+
db.typechecked_source_module(name, expected_type)
552558
.await
553559
.map(|module| module.metadata)
554560
.map_err(|(_, err)| err)
@@ -562,11 +568,11 @@ async fn core_expr(
562568
db.salsa_runtime_mut().report_untracked_read();
563569

564570
let value = db
565-
.typechecked_module(module.clone(), expected_type.clone())
571+
.typechecked_source_module(module.clone(), expected_type.clone())
566572
.await
567573
.map_err(|(_, err)| err)?;
568574

569-
// Ensure the type is stored in the database so we can collect typechecked_module later
575+
// Ensure the type is stored in the database so we can collect typechecked_source_module later
570576
db.module_type(module.clone(), expected_type.clone())
571577
.await?;
572578
db.module_metadata(module.clone(), expected_type).await?;
@@ -660,23 +666,21 @@ async fn import(
660666

661667
async fn global_inner(db: &mut dyn Compilation, name: String) -> Result<UnrootedGlobal> {
662668
if db.compiler().query(ExternLoaderQuery).peek(&name).is_some() {
663-
let (id, module) = &*db.extern_module(name).await?;
664-
let mut value = module.value.clone();
665-
unsafe { value.vm_mut().unroot() }; // FIXME
666-
return Ok(UnrootedGlobal {
667-
id: id.clone(),
668-
typ: module.typ.clone(),
669-
metadata: Arc::new(module.metadata.clone()),
670-
value: UnrootedValue(value),
671-
});
669+
let global = db.extern_module(name.clone()).await?;
670+
671+
// Ensure the type is stored in the database so we can collect typechecked_source_module later
672+
db.module_type(name.clone(), None).await?;
673+
db.module_metadata(name, None).await?;
674+
675+
return Ok(global);
672676
}
673677

674678
let TypecheckValue { metadata, typ, .. } = db
675-
.typechecked_module(name.clone(), None)
679+
.typechecked_source_module(name.clone(), None)
676680
.await
677681
.map_err(|(_, err)| err)?;
678682

679-
// Ensure the type is stored in the database so we can collect typechecked_module later
683+
// Ensure the type is stored in the database so we can collect typechecked_source_module later
680684
db.module_type(name.clone(), None).await?;
681685
db.module_metadata(name.clone(), None).await?;
682686

@@ -725,22 +729,26 @@ async fn global_inner(db: &mut dyn Compilation, name: String) -> Result<Unrooted
725729
})
726730
}
727731

728-
async fn extern_module(
729-
db: &mut dyn Compilation,
730-
name: String,
731-
) -> Result<PtrEq<(Symbol, ExternModule)>> {
732-
let symbol = Symbol::from(format!("@{}", name));
732+
async fn extern_module(db: &mut dyn Compilation, name: String) -> Result<UnrootedGlobal> {
733+
let id = Symbol::from(format!("@{}", name));
733734
let loader = db.extern_loader(name);
734735

735736
for dep in &loader.dependencies {
736737
db.import(dep.clone()).await?;
737738
}
738739

739740
let vm = db.thread();
740-
Ok(PtrEq(Arc::new((
741-
symbol, // TODO
742-
(loader.load_fn)(vm)?,
743-
))))
741+
742+
let module = (loader.load_fn)(vm)?;
743+
let mut value = module.value.clone();
744+
unsafe { value.vm_mut().unroot() }; // FIXME
745+
746+
Ok(UnrootedGlobal {
747+
id,
748+
typ: module.typ.clone(),
749+
metadata: Arc::new(module.metadata),
750+
value: UnrootedValue(value),
751+
})
744752
}
745753

746754
async fn global(db: &mut dyn Compilation, name: String) -> Result<DatabaseGlobal> {
@@ -864,8 +872,7 @@ where
864872
if id.is_global() {
865873
self.0
866874
.borrow_mut()
867-
.peek_typechecked_module(id.definition_name())
868-
.map(|v| v.metadata.clone())
875+
.peek_module_metadata(id.definition_name())
869876
} else {
870877
None
871878
}

src/std_lib/http.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ impl<'vm, 'value> Getable<'vm, 'value> for Headers {
9090
Collect::from_value(vm, value)
9191
// TODO Error somehow on invalid headers
9292
.filter_map(|(name, value): (&str, &[u8])| {
93-
match (HeaderName::from_bytes(name.as_bytes()), HeaderValue::from_bytes(value)) {
93+
match (
94+
HeaderName::from_bytes(name.as_bytes()),
95+
HeaderValue::from_bytes(value),
96+
) {
9497
(Ok(name), Ok(value)) => Some((name, value)),
9598
_ => None,
9699
}

0 commit comments

Comments
 (0)