2013-06-14 20:21:47 -05:00
|
|
|
// Copyright 2012 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.
|
|
|
|
|
|
|
|
// Finds items that are externally reachable, to determine which items
|
|
|
|
// need to have their metadata (and possibly their AST) serialized.
|
|
|
|
// All items that can be referred to through an exported name are
|
|
|
|
// reachable, and when a reachable thing is inline or generic, it
|
|
|
|
// makes all other generics or inline functions that it references
|
|
|
|
// reachable as well.
|
|
|
|
|
|
|
|
use middle::ty;
|
|
|
|
use middle::typeck;
|
2013-10-09 23:16:51 -05:00
|
|
|
use middle::privacy;
|
|
|
|
use middle::resolve;
|
2013-06-14 20:21:47 -05:00
|
|
|
|
2013-06-28 17:32:26 -05:00
|
|
|
use std::hashmap::HashSet;
|
2013-10-21 12:37:36 -05:00
|
|
|
use syntax::ast;
|
2013-06-14 20:21:47 -05:00
|
|
|
use syntax::ast_map;
|
2013-10-21 12:37:36 -05:00
|
|
|
use syntax::ast_util::{def_id_of_def, is_local, local_def};
|
2013-06-14 20:21:47 -05:00
|
|
|
use syntax::attr;
|
|
|
|
use syntax::parse::token;
|
2013-08-13 06:53:13 -05:00
|
|
|
use syntax::visit::Visitor;
|
|
|
|
use syntax::visit;
|
2013-06-14 20:21:47 -05:00
|
|
|
|
|
|
|
// Returns true if the given set of attributes contains the `#[inline]`
|
|
|
|
// attribute.
|
2013-10-21 12:37:36 -05:00
|
|
|
fn attributes_specify_inlining(attrs: &[ast::Attribute]) -> bool {
|
2013-07-19 06:51:37 -05:00
|
|
|
attr::contains_name(attrs, "inline")
|
2013-06-14 20:21:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns true if the given set of generics implies that the item it's
|
|
|
|
// associated with must be inlined.
|
2013-10-21 12:37:36 -05:00
|
|
|
fn generics_require_inlining(generics: &ast::Generics) -> bool {
|
2013-06-14 20:21:47 -05:00
|
|
|
!generics.ty_params.is_empty()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns true if the given item must be inlined because it may be
|
|
|
|
// monomorphized or it was marked with `#[inline]`. This will only return
|
|
|
|
// true for functions.
|
2013-10-21 12:37:36 -05:00
|
|
|
fn item_might_be_inlined(item: @ast::item) -> bool {
|
2013-06-14 20:21:47 -05:00
|
|
|
if attributes_specify_inlining(item.attrs) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
match item.node {
|
2013-10-31 22:47:23 -05:00
|
|
|
ast::item_impl(ref generics, _, _, _) |
|
2013-10-21 12:37:36 -05:00
|
|
|
ast::item_fn(_, _, _, ref generics, _) => {
|
2013-06-14 20:21:47 -05:00
|
|
|
generics_require_inlining(generics)
|
|
|
|
}
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns true if the given type method must be inlined because it may be
|
|
|
|
// monomorphized or it was marked with `#[inline]`.
|
2013-10-21 12:37:36 -05:00
|
|
|
fn ty_method_might_be_inlined(ty_method: &ast::TypeMethod) -> bool {
|
2013-06-14 20:21:47 -05:00
|
|
|
attributes_specify_inlining(ty_method.attrs) ||
|
|
|
|
generics_require_inlining(&ty_method.generics)
|
|
|
|
}
|
|
|
|
|
2013-10-31 22:47:23 -05:00
|
|
|
fn method_might_be_inlined(tcx: ty::ctxt, method: &ast::method,
|
|
|
|
impl_src: ast::DefId) -> bool {
|
|
|
|
if attributes_specify_inlining(method.attrs) ||
|
|
|
|
generics_require_inlining(&method.generics) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if is_local(impl_src) {
|
|
|
|
match tcx.items.find(&impl_src.node) {
|
|
|
|
Some(&ast_map::node_item(item, _)) => item_might_be_inlined(item),
|
|
|
|
Some(*) | None => {
|
|
|
|
tcx.sess.span_bug(method.span, "impl did is not an item")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
tcx.sess.span_bug(method.span, "found a foreign impl as a parent of a \
|
|
|
|
local method")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-14 20:21:47 -05:00
|
|
|
// Returns true if the given trait method must be inlined because it may be
|
|
|
|
// monomorphized or it was marked with `#[inline]`.
|
2013-10-21 12:37:36 -05:00
|
|
|
fn trait_method_might_be_inlined(trait_method: &ast::trait_method) -> bool {
|
2013-06-14 20:21:47 -05:00
|
|
|
match *trait_method {
|
2013-10-21 12:37:36 -05:00
|
|
|
ast::required(ref ty_method) => ty_method_might_be_inlined(ty_method),
|
|
|
|
ast::provided(_) => true
|
2013-06-14 20:21:47 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Information needed while computing reachability.
|
|
|
|
struct ReachableContext {
|
|
|
|
// The type context.
|
|
|
|
tcx: ty::ctxt,
|
|
|
|
// The method map, which links node IDs of method call expressions to the
|
|
|
|
// methods they've been resolved to.
|
|
|
|
method_map: typeck::method_map,
|
|
|
|
// The set of items which must be exported in the linkage sense.
|
2013-10-21 12:37:36 -05:00
|
|
|
reachable_symbols: @mut HashSet<ast::NodeId>,
|
2013-06-14 20:21:47 -05:00
|
|
|
// A worklist of item IDs. Each item ID in this worklist will be inlined
|
|
|
|
// and will be scanned for further references.
|
2013-10-21 12:37:36 -05:00
|
|
|
worklist: @mut ~[ast::NodeId],
|
2013-10-09 23:16:51 -05:00
|
|
|
// Known reexports of modules
|
|
|
|
exp_map2: resolve::ExportMap2,
|
2013-08-13 06:53:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
struct MarkSymbolVisitor {
|
2013-10-21 12:37:36 -05:00
|
|
|
worklist: @mut ~[ast::NodeId],
|
2013-08-13 06:53:13 -05:00
|
|
|
method_map: typeck::method_map,
|
|
|
|
tcx: ty::ctxt,
|
2013-10-21 12:37:36 -05:00
|
|
|
reachable_symbols: @mut HashSet<ast::NodeId>,
|
2013-08-13 06:53:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Visitor<()> for MarkSymbolVisitor {
|
2013-06-14 20:21:47 -05:00
|
|
|
|
2013-10-21 12:37:36 -05:00
|
|
|
fn visit_expr(&mut self, expr:@ast::Expr, _:()) {
|
2013-08-13 06:53:13 -05:00
|
|
|
|
2013-10-31 22:47:23 -05:00
|
|
|
match expr.node {
|
|
|
|
ast::ExprPath(_) => {
|
|
|
|
let def = match self.tcx.def_map.find(&expr.id) {
|
|
|
|
Some(&def) => def,
|
|
|
|
None => {
|
|
|
|
self.tcx.sess.span_bug(expr.span,
|
|
|
|
"def ID not in def map?!")
|
|
|
|
}
|
|
|
|
};
|
2013-08-13 06:53:13 -05:00
|
|
|
|
2013-10-31 22:47:23 -05:00
|
|
|
let def_id = def_id_of_def(def);
|
|
|
|
if ReachableContext::
|
|
|
|
def_id_represents_local_inlined_item(self.tcx, def_id) {
|
|
|
|
self.worklist.push(def_id.node)
|
|
|
|
}
|
|
|
|
self.reachable_symbols.insert(def_id.node);
|
|
|
|
}
|
|
|
|
ast::ExprMethodCall(*) => {
|
|
|
|
match self.method_map.find(&expr.id) {
|
|
|
|
Some(&typeck::method_map_entry {
|
|
|
|
origin: typeck::method_static(def_id),
|
|
|
|
_
|
|
|
|
}) => {
|
2013-08-13 06:53:13 -05:00
|
|
|
if ReachableContext::
|
2013-10-31 22:47:23 -05:00
|
|
|
def_id_represents_local_inlined_item(
|
|
|
|
self.tcx,
|
|
|
|
def_id) {
|
|
|
|
self.worklist.push(def_id.node)
|
|
|
|
}
|
2013-08-13 06:53:13 -05:00
|
|
|
self.reachable_symbols.insert(def_id.node);
|
|
|
|
}
|
2013-10-31 22:47:23 -05:00
|
|
|
Some(_) => {}
|
|
|
|
None => {
|
|
|
|
self.tcx.sess.span_bug(expr.span,
|
|
|
|
"method call expression \
|
2013-08-13 06:53:13 -05:00
|
|
|
not in method map?!")
|
|
|
|
}
|
|
|
|
}
|
2013-10-31 22:47:23 -05:00
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
2013-08-13 06:53:13 -05:00
|
|
|
|
2013-10-31 22:47:23 -05:00
|
|
|
visit::walk_expr(self, expr, ())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_item(&mut self, _item: @ast::item, _: ()) {
|
|
|
|
// Do not recurse into items. These items will be added to the worklist
|
|
|
|
// and recursed into manually if necessary.
|
2013-08-13 06:53:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ReachableContext {
|
|
|
|
// Creates a new reachability computation context.
|
2013-10-09 23:16:51 -05:00
|
|
|
fn new(tcx: ty::ctxt, method_map: typeck::method_map,
|
|
|
|
exp_map2: resolve::ExportMap2) -> ReachableContext {
|
2013-08-13 06:53:13 -05:00
|
|
|
ReachableContext {
|
|
|
|
tcx: tcx,
|
|
|
|
method_map: method_map,
|
|
|
|
reachable_symbols: @mut HashSet::new(),
|
|
|
|
worklist: @mut ~[],
|
2013-10-09 23:16:51 -05:00
|
|
|
exp_map2: exp_map2,
|
2013-08-13 06:53:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-14 20:21:47 -05:00
|
|
|
// Returns true if the given def ID represents a local item that is
|
|
|
|
// eligible for inlining and false otherwise.
|
2013-10-21 12:37:36 -05:00
|
|
|
fn def_id_represents_local_inlined_item(tcx: ty::ctxt, def_id: ast::DefId)
|
2013-06-14 20:21:47 -05:00
|
|
|
-> bool {
|
2013-10-21 12:37:36 -05:00
|
|
|
if def_id.crate != ast::LOCAL_CRATE {
|
2013-06-14 20:21:47 -05:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
let node_id = def_id.node;
|
|
|
|
match tcx.items.find(&node_id) {
|
|
|
|
Some(&ast_map::node_item(item, _)) => {
|
|
|
|
match item.node {
|
2013-10-21 12:37:36 -05:00
|
|
|
ast::item_fn(*) => item_might_be_inlined(item),
|
2013-06-14 20:21:47 -05:00
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Some(&ast_map::node_trait_method(trait_method, _, _)) => {
|
|
|
|
match *trait_method {
|
2013-10-21 12:37:36 -05:00
|
|
|
ast::required(_) => false,
|
|
|
|
ast::provided(_) => true,
|
2013-06-14 20:21:47 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Some(&ast_map::node_method(method, impl_did, _)) => {
|
|
|
|
if generics_require_inlining(&method.generics) ||
|
|
|
|
attributes_specify_inlining(method.attrs) {
|
|
|
|
true
|
|
|
|
} else {
|
|
|
|
// Check the impl. If the generics on the self type of the
|
|
|
|
// impl require inlining, this method does too.
|
2013-10-21 12:37:36 -05:00
|
|
|
assert!(impl_did.crate == ast::LOCAL_CRATE);
|
2013-06-14 20:21:47 -05:00
|
|
|
match tcx.items.find(&impl_did.node) {
|
|
|
|
Some(&ast_map::node_item(item, _)) => {
|
|
|
|
match item.node {
|
2013-10-21 12:37:36 -05:00
|
|
|
ast::item_impl(ref generics, _, _, _) => {
|
2013-06-14 20:21:47 -05:00
|
|
|
generics_require_inlining(generics)
|
|
|
|
}
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Some(_) => {
|
|
|
|
tcx.sess.span_bug(method.span,
|
|
|
|
"method is not inside an \
|
|
|
|
impl?!")
|
|
|
|
}
|
|
|
|
None => {
|
|
|
|
tcx.sess.span_bug(method.span,
|
|
|
|
"the impl that this method is \
|
|
|
|
supposedly inside of doesn't \
|
|
|
|
exist in the AST map?!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Some(_) => false,
|
2013-06-18 11:39:16 -05:00
|
|
|
None => false // This will happen for default methods.
|
2013-06-14 20:21:47 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Helper function to set up a visitor for `propagate()` below.
|
2013-08-13 06:53:13 -05:00
|
|
|
fn init_visitor(&self) -> MarkSymbolVisitor {
|
2013-06-14 20:21:47 -05:00
|
|
|
let (worklist, method_map) = (self.worklist, self.method_map);
|
|
|
|
let (tcx, reachable_symbols) = (self.tcx, self.reachable_symbols);
|
|
|
|
|
2013-08-13 06:53:13 -05:00
|
|
|
MarkSymbolVisitor {
|
|
|
|
worklist: worklist,
|
|
|
|
method_map: method_map,
|
|
|
|
tcx: tcx,
|
|
|
|
reachable_symbols: reachable_symbols,
|
|
|
|
}
|
2013-06-14 20:21:47 -05:00
|
|
|
}
|
|
|
|
|
2013-10-21 12:37:36 -05:00
|
|
|
fn propagate_mod(&self, id: ast::NodeId) {
|
2013-10-09 23:16:51 -05:00
|
|
|
match self.exp_map2.find(&id) {
|
|
|
|
Some(l) => {
|
|
|
|
for reexport in l.iter() {
|
|
|
|
if reexport.reexport && is_local(reexport.def_id) {
|
|
|
|
self.worklist.push(reexport.def_id.node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-14 20:21:47 -05:00
|
|
|
// Step 2: Mark all symbols that the symbols on the worklist touch.
|
|
|
|
fn propagate(&self) {
|
2013-08-13 06:53:13 -05:00
|
|
|
let mut visitor = self.init_visitor();
|
2013-06-14 20:21:47 -05:00
|
|
|
let mut scanned = HashSet::new();
|
|
|
|
while self.worklist.len() > 0 {
|
|
|
|
let search_item = self.worklist.pop();
|
|
|
|
if scanned.contains(&search_item) {
|
2013-10-01 16:31:03 -05:00
|
|
|
continue
|
2013-06-14 20:21:47 -05:00
|
|
|
}
|
|
|
|
scanned.insert(search_item);
|
|
|
|
self.reachable_symbols.insert(search_item);
|
|
|
|
|
|
|
|
// Find the AST block corresponding to the item and visit it,
|
|
|
|
// marking all path expressions that resolve to something
|
|
|
|
// interesting.
|
|
|
|
match self.tcx.items.find(&search_item) {
|
|
|
|
Some(&ast_map::node_item(item, _)) => {
|
|
|
|
match item.node {
|
2013-10-21 12:37:36 -05:00
|
|
|
ast::item_fn(_, _, _, _, ref search_block) => {
|
2013-10-31 22:47:23 -05:00
|
|
|
if item_might_be_inlined(item) {
|
|
|
|
visit::walk_block(&mut visitor, search_block, ())
|
|
|
|
}
|
2013-06-14 20:21:47 -05:00
|
|
|
}
|
2013-10-31 22:47:23 -05:00
|
|
|
|
2013-10-09 23:16:51 -05:00
|
|
|
// Our recursion into modules involves looking up their
|
|
|
|
// public reexports and the destinations of those
|
|
|
|
// exports. Privacy will put them in the worklist, but
|
|
|
|
// we won't find them in the ast_map, so this is where
|
|
|
|
// we deal with publicly re-exported items instead.
|
2013-10-21 12:37:36 -05:00
|
|
|
ast::item_mod(*) => self.propagate_mod(item.id),
|
|
|
|
|
|
|
|
// Implementations of exported structs/enums need to get
|
|
|
|
// added to the worklist (as all their methods should be
|
|
|
|
// accessible)
|
|
|
|
ast::item_struct(*) | ast::item_enum(*) => {
|
|
|
|
let def = local_def(item.id);
|
|
|
|
let impls = match self.tcx.inherent_impls.find(&def) {
|
|
|
|
Some(&impls) => impls,
|
|
|
|
None => continue
|
|
|
|
};
|
|
|
|
for imp in impls.iter() {
|
|
|
|
if is_local(imp.did) {
|
|
|
|
self.worklist.push(imp.did.node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Propagate through this impl
|
|
|
|
ast::item_impl(_, _, _, ref methods) => {
|
|
|
|
for method in methods.iter() {
|
|
|
|
self.worklist.push(method.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Default methods of exported traits need to all be
|
|
|
|
// accessible.
|
|
|
|
ast::item_trait(_, _, ref methods) => {
|
|
|
|
for method in methods.iter() {
|
|
|
|
match *method {
|
|
|
|
ast::required(*) => {}
|
|
|
|
ast::provided(ref method) => {
|
|
|
|
self.worklist.push(method.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-09 23:16:51 -05:00
|
|
|
// These are normal, nothing reachable about these
|
|
|
|
// inherently and their children are already in the
|
|
|
|
// worklist
|
2013-10-21 12:37:36 -05:00
|
|
|
ast::item_static(*) | ast::item_ty(*) |
|
|
|
|
ast::item_foreign_mod(*) => {}
|
|
|
|
|
2013-06-14 20:21:47 -05:00
|
|
|
_ => {
|
|
|
|
self.tcx.sess.span_bug(item.span,
|
|
|
|
"found non-function item \
|
|
|
|
in worklist?!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Some(&ast_map::node_trait_method(trait_method, _, _)) => {
|
|
|
|
match *trait_method {
|
2013-10-21 12:37:36 -05:00
|
|
|
ast::required(*) => {
|
2013-10-09 23:16:51 -05:00
|
|
|
// Keep going, nothing to get exported
|
2013-06-14 20:21:47 -05:00
|
|
|
}
|
2013-10-21 12:37:36 -05:00
|
|
|
ast::provided(ref method) => {
|
2013-08-13 06:53:13 -05:00
|
|
|
visit::walk_block(&mut visitor, &method.body, ())
|
2013-06-14 20:21:47 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-10-31 22:47:23 -05:00
|
|
|
Some(&ast_map::node_method(method, did, _)) => {
|
|
|
|
if method_might_be_inlined(self.tcx, method, did) {
|
|
|
|
visit::walk_block(&mut visitor, &method.body, ())
|
|
|
|
}
|
2013-06-14 20:21:47 -05:00
|
|
|
}
|
2013-10-09 23:16:51 -05:00
|
|
|
// Nothing to recurse on for these
|
|
|
|
Some(&ast_map::node_foreign_item(*)) |
|
|
|
|
Some(&ast_map::node_variant(*)) |
|
|
|
|
Some(&ast_map::node_struct_ctor(*)) => {}
|
2013-06-14 20:21:47 -05:00
|
|
|
Some(_) => {
|
|
|
|
let ident_interner = token::get_ident_interner();
|
|
|
|
let desc = ast_map::node_id_to_str(self.tcx.items,
|
|
|
|
search_item,
|
|
|
|
ident_interner);
|
2013-09-28 00:38:08 -05:00
|
|
|
self.tcx.sess.bug(format!("found unexpected thingy in \
|
|
|
|
worklist: {}",
|
|
|
|
desc))
|
2013-06-14 20:21:47 -05:00
|
|
|
}
|
2013-10-21 12:37:36 -05:00
|
|
|
None if search_item == ast::CRATE_NODE_ID => {
|
2013-10-09 23:16:51 -05:00
|
|
|
self.propagate_mod(search_item);
|
|
|
|
}
|
2013-06-14 20:21:47 -05:00
|
|
|
None => {
|
2013-09-28 00:38:08 -05:00
|
|
|
self.tcx.sess.bug(format!("found unmapped ID in worklist: \
|
|
|
|
{}",
|
|
|
|
search_item))
|
2013-06-14 20:21:47 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Step 3: Mark all destructors as reachable.
|
|
|
|
//
|
|
|
|
// XXX(pcwalton): This is a conservative overapproximation, but fixing
|
|
|
|
// this properly would result in the necessity of computing *type*
|
|
|
|
// reachability, which might result in a compile time loss.
|
|
|
|
fn mark_destructors_reachable(&self) {
|
2013-08-03 11:45:23 -05:00
|
|
|
for (_, destructor_def_id) in self.tcx.destructor_for_type.iter() {
|
2013-10-21 12:37:36 -05:00
|
|
|
if destructor_def_id.crate == ast::LOCAL_CRATE {
|
2013-06-14 20:21:47 -05:00
|
|
|
self.reachable_symbols.insert(destructor_def_id.node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn find_reachable(tcx: ty::ctxt,
|
|
|
|
method_map: typeck::method_map,
|
2013-10-09 23:16:51 -05:00
|
|
|
exp_map2: resolve::ExportMap2,
|
|
|
|
exported_items: &privacy::ExportedItems)
|
2013-10-21 12:37:36 -05:00
|
|
|
-> @mut HashSet<ast::NodeId> {
|
2013-10-09 23:16:51 -05:00
|
|
|
let reachable_context = ReachableContext::new(tcx, method_map, exp_map2);
|
2013-06-14 20:21:47 -05:00
|
|
|
|
2013-10-09 23:16:51 -05:00
|
|
|
// Step 1: Seed the worklist with all nodes which were found to be public as
|
|
|
|
// a result of the privacy pass
|
|
|
|
for &id in exported_items.iter() {
|
|
|
|
reachable_context.worklist.push(id);
|
|
|
|
}
|
2013-06-14 20:21:47 -05:00
|
|
|
|
|
|
|
// Step 2: Mark all symbols that the symbols on the worklist touch.
|
|
|
|
reachable_context.propagate();
|
|
|
|
|
|
|
|
// Step 3: Mark all destructors as reachable.
|
|
|
|
reachable_context.mark_destructors_reachable();
|
|
|
|
|
|
|
|
// Return the set of reachable symbols.
|
|
|
|
reachable_context.reachable_symbols
|
|
|
|
}
|