Skip to content

Commit cec1f38

Browse files
committed
auto merge of #5077 : jbclements/rust/increase-monomorphization-depth-limit, r=catamorphism
It appears that using deriving_eq/auto_encode on ASTs bumps up against the "gee this looks like infinite unfolding" limit of 10 in monomorphization. Increasing it to 30 seems to solve this problem for me.... Also, commenting and a few renames.
2 parents e7924ce + 1869df3 commit cec1f38

File tree

6 files changed

+77
-25
lines changed

6 files changed

+77
-25
lines changed

src/librustc/middle/trans/monomorphize.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ pub fn monomorphic_fn(ccx: @CrateContext,
137137

138138
let depth = option::get_or_default(ccx.monomorphizing.find(&fn_id), 0u);
139139
// Random cut-off -- code that needs to instantiate the same function
140-
// recursively more than ten times can probably safely be assumed to be
140+
// recursively more than thirty times can probably safely be assumed to be
141141
// causing an infinite expansion.
142-
if depth > 10 {
142+
if depth > 30 {
143143
ccx.sess.span_fatal(
144144
span, ~"overly deep expansion of inlined function");
145145
}

src/libstd/json.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,8 +1294,6 @@ mod tests {
12941294
}
12951295
}
12961296

1297-
// testing both auto_encode's calling patterns
1298-
// and json... not sure where to put these tests.
12991297
#[test]
13001298
fn test_write_enum () {
13011299
let bw = @io::BytesWriter();

src/libsyntax/diagnostic.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,9 @@ use std::term;
2626
pub type Emitter = fn@(cmsp: Option<(@codemap::CodeMap, span)>,
2727
msg: &str, lvl: level);
2828

29-
30-
pub trait span_handler {
31-
fn span_fatal(@mut self, sp: span, msg: &str) -> !;
32-
fn span_err(@mut self, sp: span, msg: &str);
33-
fn span_warn(@mut self, sp: span, msg: &str);
34-
fn span_note(@mut self, sp: span, msg: &str);
35-
fn span_bug(@mut self, sp: span, msg: &str) -> !;
36-
fn span_unimpl(@mut self, sp: span, msg: &str) -> !;
37-
fn handler(@mut self) -> handler;
38-
}
39-
29+
// a handler deals with errors; certain errors
30+
// (fatal, bug, unimpl) may cause immediate exit,
31+
// others log errors for later reporting.
4032
pub trait handler {
4133
fn fatal(@mut self, msg: &str) -> !;
4234
fn err(@mut self, msg: &str);
@@ -45,6 +37,7 @@ pub trait handler {
4537
fn abort_if_errors(@mut self);
4638
fn warn(@mut self, msg: &str);
4739
fn note(@mut self, msg: &str);
40+
// used to indicate a bug in the compiler:
4841
fn bug(@mut self, msg: &str) -> !;
4942
fn unimpl(@mut self, msg: &str) -> !;
5043
fn emit(@mut self,
@@ -53,6 +46,19 @@ pub trait handler {
5346
lvl: level);
5447
}
5548

49+
// a span-handler is like a handler but also
50+
// accepts span information for source-location
51+
// reporting.
52+
pub trait span_handler {
53+
fn span_fatal(@mut self, sp: span, msg: &str) -> !;
54+
fn span_err(@mut self, sp: span, msg: &str);
55+
fn span_warn(@mut self, sp: span, msg: &str);
56+
fn span_note(@mut self, sp: span, msg: &str);
57+
fn span_bug(@mut self, sp: span, msg: &str) -> !;
58+
fn span_unimpl(@mut self, sp: span, msg: &str) -> !;
59+
fn handler(@mut self) -> handler;
60+
}
61+
5662
struct HandlerT {
5763
err_count: uint,
5864
emit: Emitter,

src/libsyntax/parse/attr.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use parse::token;
1818

1919
use core::either::{Either, Left, Right};
2020

21+
// a parser that can parse attributes.
2122
pub trait parser_attr {
2223
fn parse_outer_attributes() -> ~[ast::attribute];
2324
fn parse_attribute(style: ast::attr_style) -> ast::attribute;
@@ -81,6 +82,9 @@ impl parser_attr for Parser {
8182
// attribute of the next item (since we can't know whether the attribute
8283
// is an inner attribute of the containing item or an outer attribute of
8384
// the first contained item until we see the semi).
85+
86+
// you can make the 'next' field an Option, but the result is going to be
87+
// more useful as a vector.
8488
fn parse_inner_attrs_and_next() ->
8589
(~[ast::attribute], ~[ast::attribute]) {
8690
let mut inner_attrs: ~[ast::attribute] = ~[];

src/libsyntax/parse/mod.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,18 @@ pub fn new_parse_sess_special_handler(sh: span_handler, cm: @codemap::CodeMap)
7474
}
7575
}
7676

77+
// a bunch of utility functions of the form parse_<thing>_from_<source>
78+
// where <thing> includes crate, expr, item, stmt, tts, and one that
79+
// uses a HOF to parse anything, and <source> includes file and
80+
// source_str.
81+
82+
// this appears to be the main entry point for rust parsing by
83+
// rustc and crate:
7784
pub fn parse_crate_from_file(input: &Path, cfg: ast::crate_cfg,
7885
sess: @mut ParseSess) -> @ast::crate {
79-
let p = new_crate_parser_from_file(sess, cfg, input);
80-
let r = p.parse_crate_mod(cfg);
81-
return r;
86+
let p = new_parser_from_file(sess, cfg, input);
87+
p.parse_crate_mod(cfg)
88+
// why is there no p.abort_if_errors here?
8289
}
8390

8491
pub fn parse_crate_from_source_str(name: ~str,
@@ -174,7 +181,9 @@ pub fn new_parser_from_source_str(sess: @mut ParseSess, cfg: ast::crate_cfg,
174181
return Parser(sess, cfg, srdr as reader);
175182
}
176183

177-
pub fn new_parser_from_file(sess: @mut ParseSess,
184+
// Read the entire source file, return a parser
185+
// that draws from that string
186+
pub fn new_parser_result_from_file(sess: @mut ParseSess,
178187
cfg: ast::crate_cfg,
179188
path: &Path)
180189
-> Result<Parser, ~str> {
@@ -194,9 +203,9 @@ pub fn new_parser_from_file(sess: @mut ParseSess,
194203

195204
/// Create a new parser for an entire crate, handling errors as appropriate
196205
/// if the file doesn't exist
197-
pub fn new_crate_parser_from_file(sess: @mut ParseSess, cfg: ast::crate_cfg,
206+
pub fn new_parser_from_file(sess: @mut ParseSess, cfg: ast::crate_cfg,
198207
path: &Path) -> Parser {
199-
match new_parser_from_file(sess, cfg, path) {
208+
match new_parser_result_from_file(sess, cfg, path) {
200209
Ok(parser) => parser,
201210
Err(e) => {
202211
sess.span_diagnostic.handler().fatal(e)
@@ -208,7 +217,7 @@ pub fn new_crate_parser_from_file(sess: @mut ParseSess, cfg: ast::crate_cfg,
208217
/// error messages correctly when the file does not exist.
209218
pub fn new_sub_parser_from_file(sess: @mut ParseSess, cfg: ast::crate_cfg,
210219
path: &Path, sp: span) -> Parser {
211-
match new_parser_from_file(sess, cfg, path) {
220+
match new_parser_result_from_file(sess, cfg, path) {
212221
Ok(parser) => parser,
213222
Err(e) => {
214223
sess.span_diagnostic.span_fatal(sp, e)

src/libsyntax/parse/parser.rs

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ type arg_or_capture_item = Either<arg, ()>;
110110
type item_info = (ident, item_, Option<~[attribute]>);
111111

112112
pub enum item_or_view_item {
113+
// indicates a failure to parse any kind of item:
113114
iovi_none,
114115
iovi_item(@item),
115116
iovi_foreign_item(@foreign_item),
@@ -2666,7 +2667,8 @@ pub impl Parser {
26662667
_ => None
26672668
}
26682669
}
2669-
_ => fail!()
2670+
_ => self.bug(
2671+
~"is_ident() said this would be an identifier")
26702672
};
26712673

26722674
match maybe_bound {
@@ -3204,9 +3206,12 @@ pub impl Parser {
32043206
self.eat_keyword(~"static")
32053207
}
32063208

3209+
// given a termination token and a vector of already-parsed
3210+
// attributes (of length 0 or 1), parse all of the items in a module
32073211
fn parse_mod_items(term: token::Token,
32083212
+first_item_attrs: ~[attribute]) -> _mod {
3209-
// Shouldn't be any view items since we've already parsed an item attr
3213+
// parse all of the items up to closing or an attribute.
3214+
// view items are legal here.
32103215
let ParsedItemsAndViewItems {
32113216
attrs_remaining: attrs_remaining,
32123217
view_items: view_items,
@@ -3217,6 +3222,9 @@ pub impl Parser {
32173222
true);
32183223
let mut items: ~[@item] = starting_items;
32193224

3225+
// looks like this code depends on the invariant that
3226+
// outer attributes can't occur on view items (or macros
3227+
// invocations?)
32203228
let mut first = true;
32213229
while self.token != term {
32223230
let mut attrs = self.parse_outer_attributes();
@@ -3751,6 +3759,8 @@ pub impl Parser {
37513759
}
37523760
}
37533761

3762+
// parse one of the items or view items allowed by the
3763+
// flags; on failure, return iovi_none.
37543764
fn parse_item_or_view_item(+attrs: ~[attribute], items_allowed: bool,
37553765
foreign_items_allowed: bool,
37563766
macros_allowed: bool)
@@ -3770,14 +3780,17 @@ pub impl Parser {
37703780
}
37713781

37723782
if items_allowed && self.eat_keyword(~"const") {
3783+
// CONST ITEM
37733784
let (ident, item_, extra_attrs) = self.parse_item_const();
37743785
return iovi_item(self.mk_item(lo, self.last_span.hi, ident, item_,
37753786
visibility,
37763787
maybe_append(attrs, extra_attrs)));
37773788
} else if foreign_items_allowed && self.is_keyword(~"const") {
3789+
// FOREIGN CONST ITEM
37783790
let item = self.parse_item_foreign_const(visibility, attrs);
37793791
return iovi_foreign_item(item);
37803792
} else if items_allowed &&
3793+
// FUNCTION ITEM (not sure about lookahead condition...)
37813794
self.is_keyword(~"fn") &&
37823795
!self.fn_expr_lookahead(self.look_ahead(1u)) {
37833796
self.bump();
@@ -3786,6 +3799,7 @@ pub impl Parser {
37863799
visibility,
37873800
maybe_append(attrs, extra_attrs)));
37883801
} else if items_allowed && self.eat_keyword(~"pure") {
3802+
// PURE FUNCTION ITEM
37893803
self.expect_keyword(~"fn");
37903804
let (ident, item_, extra_attrs) = self.parse_item_fn(pure_fn);
37913805
return iovi_item(self.mk_item(lo, self.last_span.hi, ident, item_,
@@ -3794,10 +3808,12 @@ pub impl Parser {
37943808
} else if foreign_items_allowed &&
37953809
(self.is_keyword(~"fn") || self.is_keyword(~"pure") ||
37963810
self.is_keyword(~"unsafe")) {
3811+
// FOREIGN FUNCTION ITEM (no items allowed)
37973812
let item = self.parse_item_foreign_fn(attrs);
37983813
return iovi_foreign_item(item);
37993814
} else if items_allowed && self.is_keyword(~"unsafe")
38003815
&& self.look_ahead(1u) != token::LBRACE {
3816+
// UNSAFE FUNCTION ITEM (where items are allowed)
38013817
self.bump();
38023818
self.expect_keyword(~"fn");
38033819
let (ident, item_, extra_attrs) = self.parse_item_fn(unsafe_fn);
@@ -3806,46 +3822,55 @@ pub impl Parser {
38063822
maybe_append(attrs, extra_attrs)));
38073823
} else if self.eat_keyword(~"extern") {
38083824
if items_allowed && self.eat_keyword(~"fn") {
3825+
// EXTERN FUNCTION ITEM
38093826
let (ident, item_, extra_attrs) =
38103827
self.parse_item_fn(extern_fn);
38113828
return iovi_item(self.mk_item(lo, self.last_span.hi, ident,
38123829
item_, visibility,
38133830
maybe_append(attrs,
38143831
extra_attrs)));
38153832
}
3833+
// EXTERN MODULE ITEM
38163834
return self.parse_item_foreign_mod(lo, visibility, attrs,
38173835
items_allowed);
38183836
} else if items_allowed && self.eat_keyword(~"mod") {
3837+
// MODULE ITEM
38193838
let (ident, item_, extra_attrs) = self.parse_item_mod(attrs);
38203839
return iovi_item(self.mk_item(lo, self.last_span.hi, ident, item_,
38213840
visibility,
38223841
maybe_append(attrs, extra_attrs)));
38233842
} else if items_allowed && self.eat_keyword(~"type") {
3843+
// TYPE ITEM
38243844
let (ident, item_, extra_attrs) = self.parse_item_type();
38253845
return iovi_item(self.mk_item(lo, self.last_span.hi, ident, item_,
38263846
visibility,
38273847
maybe_append(attrs, extra_attrs)));
38283848
} else if items_allowed && self.eat_keyword(~"enum") {
3849+
// ENUM ITEM
38293850
let (ident, item_, extra_attrs) = self.parse_item_enum();
38303851
return iovi_item(self.mk_item(lo, self.last_span.hi, ident, item_,
38313852
visibility,
38323853
maybe_append(attrs, extra_attrs)));
38333854
} else if items_allowed && self.eat_keyword(~"trait") {
3855+
// TRAIT ITEM
38343856
let (ident, item_, extra_attrs) = self.parse_item_trait();
38353857
return iovi_item(self.mk_item(lo, self.last_span.hi, ident, item_,
38363858
visibility,
38373859
maybe_append(attrs, extra_attrs)));
38383860
} else if items_allowed && self.eat_keyword(~"impl") {
3861+
// IMPL ITEM
38393862
let (ident, item_, extra_attrs) = self.parse_item_impl();
38403863
return iovi_item(self.mk_item(lo, self.last_span.hi, ident, item_,
38413864
visibility,
38423865
maybe_append(attrs, extra_attrs)));
38433866
} else if items_allowed && self.eat_keyword(~"struct") {
3867+
// STRUCT ITEM
38443868
let (ident, item_, extra_attrs) = self.parse_item_struct();
38453869
return iovi_item(self.mk_item(lo, self.last_span.hi, ident, item_,
38463870
visibility,
38473871
maybe_append(attrs, extra_attrs)));
38483872
} else if self.eat_keyword(~"use") {
3873+
// USE ITEM
38493874
let view_item = self.parse_use();
38503875
self.expect(token::SEMI);
38513876
return iovi_view_item(@ast::view_item {
@@ -3859,6 +3884,7 @@ pub impl Parser {
38593884
&& (is_plain_ident(self.look_ahead(2))
38603885
|| self.look_ahead(2) == token::LPAREN
38613886
|| self.look_ahead(2) == token::LBRACE) {
3887+
// MACRO INVOCATION ITEM
38623888
if attrs.len() > 0 {
38633889
self.fatal(~"attrs on macros are not yet supported");
38643890
}
@@ -3875,6 +3901,7 @@ pub impl Parser {
38753901
} else {
38763902
token::special_idents::invalid // no special identifier
38773903
};
3904+
// eat a matched-delimiter token tree:
38783905
let tts = match self.token {
38793906
token::LPAREN | token::LBRACE => {
38803907
let ket = token::flip_delimiter(copy self.token);
@@ -3884,6 +3911,7 @@ pub impl Parser {
38843911
}
38853912
_ => self.fatal(~"expected open delimiter")
38863913
};
3914+
// single-variant-enum... :
38873915
let m = ast::mac_invoc_tt(pth, tts);
38883916
let m: ast::mac = codemap::spanned { node: m,
38893917
span: mk_sp(self.span.lo,
@@ -3892,6 +3920,7 @@ pub impl Parser {
38923920
return iovi_item(self.mk_item(lo, self.last_span.hi, id, item_,
38933921
visibility, attrs));
38943922
} else {
3923+
// FAILURE TO PARSE ITEM
38953924
if visibility != inherited {
38963925
let mut s = ~"unmatched visibility `";
38973926
s += if visibility == public { ~"pub" } else { ~"priv" };
@@ -4030,6 +4059,7 @@ pub impl Parser {
40304059
self.token_is_keyword(~"mod", next_tok))
40314060
}
40324061

4062+
// parse a view item.
40334063
fn parse_view_item(+attrs: ~[attribute], vis: visibility) -> @view_item {
40344064
let lo = self.span.lo;
40354065
let node = if self.eat_keyword(~"use") {
@@ -4040,7 +4070,7 @@ pub impl Parser {
40404070
let metadata = self.parse_optional_meta();
40414071
view_item_extern_mod(ident, metadata, self.get_id())
40424072
} else {
4043-
fail!();
4073+
self.bug(~"expected view item");
40444074
};
40454075
self.expect(token::SEMI);
40464076
@ast::view_item { node: node,
@@ -4049,6 +4079,8 @@ pub impl Parser {
40494079
span: mk_sp(lo, self.last_span.hi) }
40504080
}
40514081

4082+
// Parses a sequence of items. Stops when it finds program
4083+
// text that can't be parsed as an item
40524084
fn parse_items_and_view_items(+first_item_attrs: ~[attribute],
40534085
mode: view_item_parse_mode,
40544086
macros_allowed: bool)
@@ -4114,8 +4146,11 @@ pub impl Parser {
41144146
// Parses a source module as a crate
41154147
fn parse_crate_mod(_cfg: crate_cfg) -> @crate {
41164148
let lo = self.span.lo;
4149+
// parse the crate's inner attrs, maybe (oops) one
4150+
// of the attrs of an item:
41174151
let (inner, next) = self.parse_inner_attrs_and_next();
41184152
let first_item_outer_attrs = next;
4153+
// parse the items inside the crate:
41194154
let m = self.parse_mod_items(token::EOF, first_item_outer_attrs);
41204155
@spanned(lo, self.span.lo,
41214156
ast::crate_ { module: m,

0 commit comments

Comments
 (0)