Skip to content

Commit 6b429d0

Browse files
sfackleralexcrichton
authored andcommittedFeb 13, 2014
Stop unloading syntax libraries
Externally loaded libraries are able to do things that cause references to them to survive past the expansion phase (e.g. creating @-box cycles, launching a task or storing something in task local data). As such, the library has to stay loaded for the lifetime of the process.
1 parent cfb87f1 commit 6b429d0

File tree

4 files changed

+63
-11
lines changed

4 files changed

+63
-11
lines changed
 

‎src/libsyntax/ext/base.rs

-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use parse::token::{InternedString, intern, str_to_ident};
2020
use util::small_vector::SmallVector;
2121

2222
use std::hashmap::HashMap;
23-
use std::unstable::dynamic_lib::DynamicLibrary;
2423

2524
// new-style macro! tt code:
2625
//
@@ -143,16 +142,13 @@ pub struct BlockInfo {
143142
macros_escape : bool,
144143
// what are the pending renames?
145144
pending_renames : RenameList,
146-
// references for crates loaded in this scope
147-
macro_crates: ~[DynamicLibrary],
148145
}
149146

150147
impl BlockInfo {
151148
pub fn new() -> BlockInfo {
152149
BlockInfo {
153150
macros_escape: false,
154151
pending_renames: ~[],
155-
macro_crates: ~[],
156152
}
157153
}
158154
}
@@ -551,10 +547,6 @@ impl SyntaxEnv {
551547
self.find_escape_frame().map.insert(k, v);
552548
}
553549

554-
pub fn insert_macro_crate(&mut self, lib: DynamicLibrary) {
555-
self.find_escape_frame().info.macro_crates.push(lib);
556-
}
557-
558550
pub fn info<'a>(&'a mut self) -> &'a mut BlockInfo {
559551
&mut self.chain[self.chain.len()-1].info
560552
}

‎src/libsyntax/ext/expand.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -28,6 +28,7 @@ use visit;
2828
use visit::Visitor;
2929
use util::small_vector::SmallVector;
3030

31+
use std::cast;
3132
use std::vec;
3233
use std::unstable::dynamic_lib::DynamicLibrary;
3334
use std::os;
@@ -469,9 +470,12 @@ fn load_extern_macros(crate: &ast::ViewItem, fld: &mut MacroExpander) {
469470
};
470471
fld.extsbox.insert(name, extension);
471472
});
472-
}
473473

474-
fld.extsbox.insert_macro_crate(lib);
474+
// Intentionally leak the dynamic library. We can't ever unload it
475+
// since the library can do things that will outlive the expansion
476+
// phase (e.g. make an @-box cycle or launch a task).
477+
cast::forget(lib);
478+
}
475479
}
476480

477481
// expand a stmt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// force-host
12+
13+
#[feature(macro_registrar)];
14+
15+
extern mod syntax;
16+
17+
use std::any::Any;
18+
use std::local_data;
19+
use syntax::ast::Name;
20+
use syntax::ext::base::SyntaxExtension;
21+
22+
struct Foo {
23+
foo: int
24+
}
25+
26+
impl Drop for Foo {
27+
fn drop(&mut self) {}
28+
}
29+
30+
#[macro_registrar]
31+
pub fn registrar(_: |Name, SyntaxExtension|) {
32+
local_data_key!(foo: ~Any);
33+
local_data::set(foo, ~Foo { foo: 10 } as ~Any);
34+
}
35+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// aux-build:macro_crate_outlive_expansion_phase.rs
12+
// ignore-stage1
13+
// ignore-fast
14+
// ignore-android
15+
16+
#[feature(phase)];
17+
18+
#[phase(syntax)]
19+
extern mod macro_crate_outlive_expansion_phase;
20+
21+
pub fn main() {}

0 commit comments

Comments
 (0)
Please sign in to comment.