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

Stop unloading syntax libraries #12206

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 0 additions & 8 deletions src/libsyntax/ext/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use parse::token::{InternedString, intern, str_to_ident};
use util::small_vector::SmallVector;

use std::hashmap::HashMap;
use std::unstable::dynamic_lib::DynamicLibrary;

// new-style macro! tt code:
//
Expand Down Expand Up @@ -143,16 +142,13 @@ pub struct BlockInfo {
macros_escape : bool,
// what are the pending renames?
pending_renames : RenameList,
// references for crates loaded in this scope
macro_crates: ~[DynamicLibrary],
}

impl BlockInfo {
pub fn new() -> BlockInfo {
BlockInfo {
macros_escape: false,
pending_renames: ~[],
macro_crates: ~[],
}
}
}
Expand Down Expand Up @@ -551,10 +547,6 @@ impl SyntaxEnv {
self.find_escape_frame().map.insert(k, v);
}

pub fn insert_macro_crate(&mut self, lib: DynamicLibrary) {
self.find_escape_frame().info.macro_crates.push(lib);
}

pub fn info<'a>(&'a mut self) -> &'a mut BlockInfo {
&mut self.chain[self.chain.len()-1].info
}
Expand Down
10 changes: 7 additions & 3 deletions src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand Down Expand Up @@ -28,6 +28,7 @@ use visit;
use visit::Visitor;
use util::small_vector::SmallVector;

use std::cast;
use std::vec;
use std::unstable::dynamic_lib::DynamicLibrary;
use std::os;
Expand Down Expand Up @@ -469,9 +470,12 @@ fn load_extern_macros(crate: &ast::ViewItem, fld: &mut MacroExpander) {
};
fld.extsbox.insert(name, extension);
});
}

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

// expand a stmt
Expand Down
35 changes: 35 additions & 0 deletions src/test/auxiliary/macro_crate_outlive_expansion_phase.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// force-host

#[feature(macro_registrar)];

extern mod syntax;

use std::any::Any;
use std::local_data;
use syntax::ast::Name;
use syntax::ext::base::SyntaxExtension;

struct Foo {
foo: int
}

impl Drop for Foo {
fn drop(&mut self) {}
}

#[macro_registrar]
pub fn registrar(_: |Name, SyntaxExtension|) {
local_data_key!(foo: ~Any);
local_data::set(foo, ~Foo { foo: 10 } as ~Any);
}

21 changes: 21 additions & 0 deletions src/test/run-pass-fulldeps/macro-crate-outlive-expansion-phase.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// aux-build:macro_crate_outlive_expansion_phase.rs
// ignore-stage1
// ignore-fast
// ignore-android

#[feature(phase)];

#[phase(syntax)]
extern mod macro_crate_outlive_expansion_phase;

pub fn main() {}