Skip to content

Commit 908dd24

Browse files
committed
Disable the inliner completely
1 parent 97b63c4 commit 908dd24

File tree

8 files changed

+98
-119
lines changed

8 files changed

+98
-119
lines changed

codegen/src/functor.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
extern crate proc_macro;
2+
13
use proc_macro2::{Ident, Span, TokenStream};
24
use syn::{self, Data, DeriveInput, Generics};
35

repl/src/repl.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,6 @@ async fn eval_line_(vm: RootedThread, line: &str) -> gluon::Result<()> {
377377
let mut eval_expr;
378378
let value = {
379379
let mut db = vm.get_database();
380-
let mut db = gluon::salsa::OwnedDb::<dyn gluon::query::Compilation>::from(&mut db);
381380
let mut module_compiler = vm.module_compiler(&mut db);
382381
eval_expr = {
383382
let eval_expr = {

src/import.rs

Lines changed: 39 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -104,40 +104,6 @@ impl Importer for DefaultImporter {
104104
}
105105
}
106106

107-
pub struct DatabaseSnapshot {
108-
snapshot: Option<salsa::Snapshot<CompilerDatabase>>,
109-
}
110-
111-
impl Deref for DatabaseSnapshot {
112-
type Target = CompilerDatabase;
113-
fn deref(&self) -> &Self::Target {
114-
self.snapshot.as_ref().unwrap()
115-
}
116-
}
117-
118-
impl<'a> From<&'a mut DatabaseSnapshot> for salsa::OwnedDb<'a, dyn Compilation> {
119-
fn from(db: &'a mut DatabaseSnapshot) -> Self {
120-
salsa::cast_owned_db!(salsa::OwnedDb::<CompilerDatabase>::from(db.snapshot.as_mut().unwrap()) => &mut dyn Compilation)
121-
}
122-
}
123-
124-
pub struct DatabaseFork {
125-
fork: Option<salsa::Snapshot<CompilerDatabase>>,
126-
}
127-
128-
impl Deref for DatabaseFork {
129-
type Target = CompilerDatabase;
130-
fn deref(&self) -> &Self::Target {
131-
self.fork.as_ref().unwrap()
132-
}
133-
}
134-
135-
impl<'a> From<&'a mut DatabaseFork> for salsa::OwnedDb<'a, dyn Compilation> {
136-
fn from(db: &'a mut DatabaseFork) -> Self {
137-
salsa::cast_owned_db!(salsa::OwnedDb::<CompilerDatabase>::from(db.fork.as_mut().unwrap()) => &mut dyn Compilation)
138-
}
139-
}
140-
141107
pub struct DatabaseMut {
142108
// Only needed to ensure that the the `Compiler` the guard points to lives long enough
143109
_import: Arc<dyn Macro>,
@@ -181,8 +147,12 @@ pub(crate) trait ImportApi: Send + Sync {
181147
vm: &Thread,
182148
module_id: &Symbol,
183149
) -> SalvageResult<ArcType>;
184-
fn snapshot(&self, thread: RootedThread) -> DatabaseSnapshot;
185-
fn fork(&mut self, forker: salsa::ForkState, thread: RootedThread) -> DatabaseFork;
150+
fn snapshot(&self, thread: RootedThread) -> salsa::Snapshot<CompilerDatabase>;
151+
fn fork(
152+
&mut self,
153+
forker: salsa::ForkState,
154+
thread: RootedThread,
155+
) -> salsa::Snapshot<CompilerDatabase>;
186156
}
187157

188158
#[async_trait]
@@ -209,10 +179,14 @@ where
209179

210180
self.importer.import(compiler, vm, &modulename).await
211181
}
212-
fn snapshot(&self, thread: RootedThread) -> DatabaseSnapshot {
182+
fn snapshot(&self, thread: RootedThread) -> salsa::Snapshot<CompilerDatabase> {
213183
Self::snapshot(self, thread)
214184
}
215-
fn fork(&mut self, forker: salsa::ForkState, thread: RootedThread) -> DatabaseFork {
185+
fn fork(
186+
&mut self,
187+
forker: salsa::ForkState,
188+
thread: RootedThread,
189+
) -> salsa::Snapshot<CompilerDatabase> {
216190
Self::fork(self, forker, thread)
217191
}
218192
}
@@ -309,18 +283,16 @@ impl<I> Import<I> {
309283
compiler
310284
}
311285

312-
pub fn snapshot(&self, thread: RootedThread) -> DatabaseSnapshot {
313-
let snapshot = self.compiler.lock().unwrap().snapshot(thread);
314-
315-
DatabaseSnapshot {
316-
snapshot: Some(snapshot),
317-
}
286+
pub fn snapshot(&self, thread: RootedThread) -> salsa::Snapshot<CompilerDatabase> {
287+
self.compiler.lock().unwrap().snapshot(thread)
318288
}
319289

320-
pub fn fork(&self, forker: salsa::ForkState, thread: RootedThread) -> DatabaseFork {
321-
let fork = self.compiler.lock().unwrap().fork(forker, thread);
322-
323-
DatabaseFork { fork: Some(fork) }
290+
pub fn fork(
291+
&mut self,
292+
forker: salsa::ForkState,
293+
thread: RootedThread,
294+
) -> salsa::Snapshot<CompilerDatabase> {
295+
self.compiler.lock().unwrap().fork(forker, thread)
324296
}
325297

326298
pub(crate) fn get_module_source(
@@ -489,7 +461,7 @@ where
489461
Some(Box::new(
490462
arc_self.clone().downcast_arc::<Self>().ok().unwrap() as Arc<dyn ImportApi>,
491463
))
492-
} else if id == TypeId::of::<DatabaseSnapshot>() {
464+
} else if id == TypeId::of::<salsa::Snapshot<CompilerDatabase>>() {
493465
Some(Box::new(self.snapshot(thread.root_thread())))
494466
} else if id == TypeId::of::<DatabaseMut>() {
495467
Some(Box::new(
@@ -541,14 +513,13 @@ where
541513

542514
info!("import! {}", modulename);
543515

544-
let db = try_future!(macros
516+
let mut db = try_future!(macros
545517
.userdata
546518
.fork(macros.vm.root_thread())
547519
.downcast::<salsa::Snapshot<CompilerDatabase>>()
548520
.map_err(|_| MacroError::new(Error::String(
549521
"`import` requires a `CompilerDatabase` as user data during macro expansion".into(),
550522
))));
551-
let mut db = DatabaseFork { fork: Some(*db) };
552523

553524
let span = args[0].span;
554525

@@ -559,23 +530,18 @@ where
559530
let (tx, rx) = tokio::sync::oneshot::channel();
560531
spawn
561532
.spawn(Box::pin(async move {
562-
let result = {
563-
let mut db = salsa::OwnedDb::<dyn Compilation>::from(&mut db);
564-
std::panic::AssertUnwindSafe(db.import(modulename))
565-
.catch_unwind()
566-
.await
567-
.map(|r| r.map_err(|err| MacroError::message(err.to_string())))
568-
.unwrap_or_else(|err| {
569-
Err(MacroError::message(
570-
err.downcast::<String>()
571-
.map(|s| *s)
572-
.or_else(|e| {
573-
e.downcast::<&str>().map(|s| String::from(&s[..]))
574-
})
575-
.unwrap_or_else(|_| "Unknown panic".to_string()),
576-
))
577-
})
578-
};
533+
let result = std::panic::AssertUnwindSafe(db.import(modulename))
534+
.catch_unwind()
535+
.await
536+
.map(|r| r.map_err(|err| MacroError::message(err.to_string())))
537+
.unwrap_or_else(|err| {
538+
Err(MacroError::message(
539+
err.downcast::<String>()
540+
.map(|s| *s)
541+
.or_else(|e| e.downcast::<&str>().map(|s| String::from(&s[..])))
542+
.unwrap_or_else(|_| "Unknown panic".to_string()),
543+
))
544+
});
579545
// Drop the database before sending the result, otherwise the forker may drop before the forked database
580546
drop(db);
581547
let _ = tx.send(result);
@@ -595,13 +561,11 @@ where
595561
Box::pin(async move {
596562
Ok(From::from(move || {
597563
async move {
598-
let result = {
599-
let mut db = salsa::OwnedDb::<dyn Compilation>::from(&mut db);
600-
db.import(modulename)
601-
.await
602-
.map_err(|err| MacroError::message(err.to_string()))
603-
.map(move |id| pos::spanned(span, Expr::Ident(id)))
604-
};
564+
let result = db
565+
.import(modulename)
566+
.await
567+
.map_err(|err| MacroError::message(err.to_string()))
568+
.map(move |id| pos::spanned(span, Expr::Ident(id)));
605569
drop(db);
606570
result
607571
}

src/lib.rs

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ use crate::vm::{
8787
use crate::{
8888
compiler_pipeline::*,
8989
import::{add_extern_module, add_extern_module_with_deps, DefaultImporter, Import},
90-
query::{AsyncCompilation, Compilation, CompilationBase},
90+
query::{AsyncCompilation, Compilation, CompilationBase, CompilerDatabase},
9191
};
9292

9393
quick_error! {
@@ -305,15 +305,38 @@ impl Default for Settings {
305305
}
306306
}
307307

308+
#[doc(hidden)]
309+
pub trait IntoDb<'a, 'b> {
310+
fn into_db(self) -> salsa::OwnedDb<'a, dyn Compilation + 'b>;
311+
}
312+
313+
impl<'a, 'b> IntoDb<'a, 'b> for &'a mut salsa::OwnedDb<'_, dyn Compilation + 'b> {
314+
fn into_db(self) -> salsa::OwnedDb<'a, dyn Compilation + 'b> {
315+
self.into()
316+
}
317+
}
318+
319+
impl<'a, 'b> IntoDb<'a, 'b> for salsa::OwnedDb<'a, dyn Compilation + 'b> {
320+
fn into_db(self) -> salsa::OwnedDb<'a, dyn Compilation + 'b> {
321+
self
322+
}
323+
}
324+
325+
impl<'a, 'b> IntoDb<'a, 'b> for &'a mut salsa::Snapshot<CompilerDatabase> {
326+
fn into_db(self) -> salsa::OwnedDb<'a, dyn Compilation + 'b> {
327+
salsa::cast_owned_db!(salsa::OwnedDb::<CompilerDatabase>::from(self) => &mut dyn Compilation)
328+
}
329+
}
330+
308331
pub struct ModuleCompiler<'a, 'b> {
309332
pub database: salsa::OwnedDb<'a, dyn Compilation + 'b>,
310333
symbols: Symbols,
311334
}
312335

313336
impl<'a, 'b> ModuleCompiler<'a, 'b> {
314-
fn new(database: impl Into<salsa::OwnedDb<'a, dyn Compilation + 'b>>) -> Self {
337+
fn new(database: impl IntoDb<'a, 'b>) -> Self {
315338
Self {
316-
database: database.into(),
339+
database: database.into_db(),
317340
symbols: Symbols::default(),
318341
}
319342
}
@@ -405,7 +428,7 @@ impl import::DatabaseMut {
405428
406429
#[async_trait::async_trait]
407430
pub trait ThreadExt: Send + Sync {
408-
fn get_database(&self) -> import::DatabaseSnapshot;
431+
fn get_database(&self) -> salsa::Snapshot<CompilerDatabase>;
409432
fn get_database_mut(&self) -> import::DatabaseMut;
410433

411434
fn run_io(&self, run: bool) {
@@ -415,10 +438,7 @@ pub trait ThreadExt: Send + Sync {
415438
#[doc(hidden)]
416439
fn thread(&self) -> &Thread;
417440

418-
fn module_compiler<'a, 'b>(
419-
&'a self,
420-
database: impl Into<salsa::OwnedDb<'a, dyn Compilation + 'b>>,
421-
) -> ModuleCompiler<'a, 'b> {
441+
fn module_compiler<'a, 'b>(&'a self, database: impl IntoDb<'a, 'b>) -> ModuleCompiler<'a, 'b> {
422442
ModuleCompiler::new(database)
423443
}
424444

@@ -490,7 +510,6 @@ pub trait ThreadExt: Send + Sync {
490510
db.add_module(file.into(), expr_str.into());
491511
}
492512
let mut db = vm.get_database();
493-
let mut db = salsa::OwnedDb::<dyn Compilation>::from(&mut db);
494513

495514
let TypecheckValue { expr, typ, .. } = db
496515
.typechecked_source_module(file.into(), expected_type.cloned())
@@ -591,7 +610,6 @@ pub trait ThreadExt: Send + Sync {
591610
}
592611

593612
let mut db = vm.get_database();
594-
let mut db = salsa::OwnedDb::<dyn Compilation>::from(&mut db);
595613

596614
let TypecheckValue {
597615
expr,
@@ -632,7 +650,6 @@ pub trait ThreadExt: Send + Sync {
632650
db.add_module(module_name.clone(), input.into());
633651
}
634652
let mut db = vm.get_database();
635-
let mut db = salsa::OwnedDb::<dyn Compilation>::from(&mut db);
636653

637654
db.import(module_name).await.map(|_| ())
638655
}
@@ -793,7 +810,7 @@ fn skip_implicit_prelude<'a, 'ast>(
793810
}
794811

795812
impl ThreadExt for Thread {
796-
fn get_database(&self) -> import::DatabaseSnapshot {
813+
fn get_database(&self) -> salsa::Snapshot<CompilerDatabase> {
797814
self.global_env()
798815
.get_capability(self)
799816
.expect("Database is missing")

src/query.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use {
3636

3737
use crate::{compiler_pipeline::*, import::PtrEq, Error, ModuleCompiler, Result, Settings};
3838

39-
pub use {crate::import::DatabaseSnapshot, salsa};
39+
pub use salsa;
4040

4141
#[derive(Debug, Trace)]
4242
#[gluon(crate_name = "gluon_vm")]

std/cmp.glu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ let (/=) ?eq l r : [Eq a] -> a -> a -> Bool = if (eq.(==) l r) then False else T
2424
type Ord a = {
2525
eq : Eq a,
2626
/// Compares two values and returns wheter the first is less than, equal or greater than the second.
27-
compare : a -> a -> Ordering,
27+
compare : a -> a -> Ordering
2828
}
2929

3030
let compare ?ord : [Ord a] -> a -> a -> Ordering = ord.compare

0 commit comments

Comments
 (0)