Skip to content

Commit 142a99d

Browse files
powerboat9dkm
authored andcommitted
Load modules during CfgStrip phase
TopLevel would ignore just-loaded modules but Early and ExpandVisitor wouldn't. The latter would produce errors when it hit attributes which should have been indirectly CfgStrip'd away. gcc/rust/ChangeLog: * expand/rust-cfg-strip.cc (CfgStrip::visit): Load unloaded modules. * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Assume modules have been loaded by CfgStrip. Signed-off-by: Owen Avery <[email protected]>
1 parent d6f6955 commit 142a99d

File tree

2 files changed

+10
-30
lines changed

2 files changed

+10
-30
lines changed

gcc/rust/expand/rust-cfg-strip.cc

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,16 +1765,17 @@ CfgStrip::visit (AST::Module &module)
17651765
return;
17661766
}
17671767

1768-
// A loaded module might have inner attributes
1769-
if (module.get_kind () == AST::Module::ModuleKind::LOADED)
1768+
if (module.get_kind () == AST::Module::UNLOADED)
17701769
{
1771-
// strip test based on inner attrs
1772-
expand_cfg_attrs (module.get_inner_attrs ());
1773-
if (fails_cfg_with_expand (module.get_inner_attrs ()))
1774-
{
1775-
module.mark_for_strip ();
1776-
return;
1777-
}
1770+
module.load_items ();
1771+
}
1772+
1773+
// strip test based on inner attrs
1774+
expand_cfg_attrs (module.get_inner_attrs ());
1775+
if (fails_cfg_with_expand (module.get_inner_attrs ()))
1776+
{
1777+
module.mark_for_strip ();
1778+
return;
17781779
}
17791780

17801781
// strip items if required

gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -101,27 +101,6 @@ TopLevel::go (AST::Crate &crate)
101101
void
102102
TopLevel::visit (AST::Module &module)
103103
{
104-
// Parse the module's items if they haven't been expanded and the file
105-
// should be parsed (i.e isn't hidden behind an untrue or impossible cfg
106-
// directive
107-
// TODO: make sure this is right
108-
// TODO: avoid loading items if cfg attributes are present?
109-
// might not be needed if this runs after early resolution?
110-
// This was copied from the old early resolver method
111-
// 'accumulate_escaped_macros'
112-
if (module.get_kind () == AST::Module::UNLOADED)
113-
{
114-
module.load_items ();
115-
116-
// If the module was previously unloaded, then we don't want to visit it
117-
// this time around as the CfgStrip hasn't run on its inner items yet.
118-
// Skip it for now, mark the visitor as dirty and try again
119-
120-
dirty = true;
121-
122-
return;
123-
}
124-
125104
DefaultResolver::visit (module);
126105

127106
if (Analysis::Mappings::get ().lookup_ast_module (module.get_node_id ())

0 commit comments

Comments
 (0)