Skip to content

Commit aaca739

Browse files
committed
---
yaml --- r: 7367 b: refs/heads/master c: 08c16b1 h: refs/heads/master i: 7365: 894e65f 7363: ce1aaca 7359: dc74fe0 v: v3
1 parent 0f48c4f commit aaca739

File tree

3 files changed

+65
-56
lines changed

3 files changed

+65
-56
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: ca8fe6446b52073b11e7717012e7e9dfa32f1938
2+
refs/heads/master: 08c16b17e906958ce8e3902a3962e9d801fb6e8c

trunk/src/comp/driver/driver.rs

Lines changed: 63 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import back::{x86, x86_64};
2020

2121
tag pp_mode { ppm_normal; ppm_expanded; ppm_typed; ppm_identified; }
2222

23-
fn default_configuration(sess: session::session, argv0: str, input: str) ->
23+
fn default_configuration(sess: session, argv0: str, input: str) ->
2424
ast::crate_cfg {
2525
let libc =
2626
alt sess.targ_cfg.os {
@@ -48,7 +48,7 @@ fn default_configuration(sess: session::session, argv0: str, input: str) ->
4848
mk("build_input", input)];
4949
}
5050

51-
fn build_configuration(sess: session::session, argv0: str, input: str) ->
51+
fn build_configuration(sess: session, argv0: str, input: str) ->
5252
ast::crate_cfg {
5353
// Combine the configuration requested by the session (command line) with
5454
// some default and generated configuration items
@@ -76,31 +76,27 @@ fn parse_cfgspecs(cfgspecs: [str]) -> ast::crate_cfg {
7676

7777
fn input_is_stdin(filename: str) -> bool { filename == "-" }
7878

79-
fn parse_input(sess: session::session, cfg: ast::crate_cfg, input: str) ->
79+
fn parse_input(sess: session, cfg: ast::crate_cfg, input: str) ->
8080
@ast::crate {
8181
if !input_is_stdin(input) {
8282
parser::parse_crate_from_file(input, cfg, sess.parse_sess)
83-
} else { parse_input_src(sess, cfg, input).crate }
83+
} else {
84+
let srcbytes = get_input_stream(sess, input).read_whole_stream();
85+
let srcstring = str::unsafe_from_bytes(srcbytes);
86+
parser::parse_crate_from_source_str(input, srcstring, cfg,
87+
sess.parse_sess)
88+
}
8489
}
8590

86-
fn parse_input_src(sess: session::session, cfg: ast::crate_cfg, infile: str)
87-
-> {crate: @ast::crate, src: str} {
88-
let src_stream = if infile != "-" {
91+
fn get_input_stream(sess: session, infile: str) -> io::reader {
92+
if !input_is_stdin(infile) {
8993
alt io::file_reader(infile) {
9094
result::ok(reader) { reader }
9195
result::err(e) {
9296
sess.fatal(e)
9397
}
9498
}
95-
} else {
96-
io::stdin()
97-
};
98-
let srcbytes = src_stream.read_whole_stream();
99-
let src = str::unsafe_from_bytes(srcbytes);
100-
let crate =
101-
parser::parse_crate_from_source_str(infile, src, cfg,
102-
sess.parse_sess);
103-
ret {crate: crate, src: src};
99+
} else { io::stdin() }
104100
}
105101

106102
fn time<T>(do_it: bool, what: str, thunk: fn@() -> T) -> T {
@@ -113,7 +109,7 @@ fn time<T>(do_it: bool, what: str, thunk: fn@() -> T) -> T {
113109
ret rv;
114110
}
115111

116-
fn inject_libcore_reference(sess: session::session,
112+
fn inject_libcore_reference(sess: session,
117113
crate: @ast::crate) -> @ast::crate {
118114

119115
fn spanned<T: copy>(x: T) -> @ast::spanned<T> {
@@ -134,14 +130,22 @@ fn inject_libcore_reference(sess: session::session,
134130
with crate.node} with *crate }
135131
}
136132

133+
enum compile_upto {
134+
cu_parse;
135+
cu_expand;
136+
cu_typeck;
137+
cu_no_trans;
138+
cu_everything;
139+
}
137140

138-
fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: str,
139-
outdir: option::t<str>, output: option::t<str>) {
140-
141+
fn compile_upto(sess: session, cfg: ast::crate_cfg,
142+
input: str, upto: compile_upto,
143+
outputs: option::t<output_filenames>)
144+
-> {crate: @ast::crate, tcx: option::t<ty::ctxt>} {
141145
let time_passes = sess.opts.time_passes;
142146
let crate =
143147
time(time_passes, "parsing", bind parse_input(sess, cfg, input));
144-
if sess.opts.parse_only { ret; }
148+
if upto == cu_parse { ret {crate: crate, tcx: none}; }
145149

146150
sess.building_library =
147151
session::building_library(sess.opts.crate_type, crate);
@@ -156,6 +160,7 @@ fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: str,
156160
time(time_passes, "expansion",
157161
bind syntax::ext::expand::expand_crate(sess, crate));
158162

163+
if upto == cu_expand { ret {crate: crate, tcx: none}; }
159164
if sess.opts.libcore {
160165
crate = inject_libcore_reference(sess, crate);
161166
}
@@ -177,6 +182,9 @@ fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: str,
177182
let (method_map, dict_map) =
178183
time(time_passes, "typechecking",
179184
bind typeck::check_crate(ty_cx, impl_map, crate));
185+
186+
if upto == cu_typeck { ret {crate: crate, tcx: some(ty_cx)}; }
187+
180188
time(time_passes, "block-use checking",
181189
bind middle::block_use::check_crate(ty_cx, crate));
182190
time(time_passes, "function usage",
@@ -195,9 +203,9 @@ fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: str,
195203
bind last_use::find_last_uses(crate, def_map, ref_map, ty_cx));
196204
time(time_passes, "kind checking",
197205
bind kind::check_crate(ty_cx, method_map, last_uses, crate));
198-
if sess.opts.no_trans { ret; }
199206

200-
let outputs = build_output_filenames(input, outdir, output, sess);
207+
if upto == cu_no_trans { ret {crate: crate, tcx: some(ty_cx)}; }
208+
let outputs = option::get(outputs);
201209

202210
let (llmod, link_meta) =
203211
time(time_passes, "translation",
@@ -212,14 +220,25 @@ fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: str,
212220
sess.opts.output_type != link::output_type_exe ||
213221
sess.opts.static && sess.building_library;
214222

215-
if stop_after_codegen { ret; }
223+
if stop_after_codegen { ret {crate: crate, tcx: some(ty_cx)}; }
216224

217225
time(time_passes, "Linking",
218226
bind link::link_binary(sess, outputs.obj_filename,
219227
outputs.out_filename, link_meta));
228+
ret {crate: crate, tcx: some(ty_cx)};
220229
}
221230

222-
fn pretty_print_input(sess: session::session, cfg: ast::crate_cfg, input: str,
231+
fn compile_input(sess: session, cfg: ast::crate_cfg, input: str,
232+
outdir: option::t<str>, output: option::t<str>) {
233+
234+
let upto = if sess.opts.parse_only { cu_parse }
235+
else if sess.opts.no_trans { cu_no_trans }
236+
else { cu_everything };
237+
let outputs = build_output_filenames(input, outdir, output, sess);
238+
compile_upto(sess, cfg, input, upto, some(outputs));
239+
}
240+
241+
fn pretty_print_input(sess: session, cfg: ast::crate_cfg, input: str,
223242
ppm: pp_mode) {
224243
fn ann_paren_for_expr(node: pprust::ann_node) {
225244
alt node { pprust::node_expr(s, expr) { pprust::popen(s); } _ { } }
@@ -260,33 +279,27 @@ fn pretty_print_input(sess: session::session, cfg: ast::crate_cfg, input: str,
260279
// to collect comments and literals, and we need to support reading
261280
// from stdin, we're going to just suck the source into a string
262281
// so both the parser and pretty-printer can use it.
263-
let crate_src = parse_input_src(sess, cfg, input);
264-
let crate = crate_src.crate;
265-
let src = crate_src.src;
282+
let upto = alt ppm {
283+
ppm_expanded. { cu_expand }
284+
ppm_typed. { cu_typeck }
285+
_ { cu_parse }
286+
};
287+
let {crate, tcx} = compile_upto(sess, cfg, input, upto, none);
288+
let src = get_input_stream(sess, input);
266289

267-
let ann;
290+
let ann: pprust::pp_ann = pprust::no_ann();
268291
alt ppm {
269-
ppm_expanded. {
270-
crate = syntax::ext::expand::expand_crate(sess, crate);
271-
ann = pprust::no_ann();
272-
}
273292
ppm_typed. {
274-
crate = syntax::ext::expand::expand_crate(sess, crate);
275-
let amap = middle::ast_map::map_crate(*crate);
276-
let {def_map, impl_map, _} =
277-
resolve::resolve_crate(sess, amap, crate);
278-
let freevars = freevars::annotate_freevars(def_map, crate);
279-
let ty_cx = ty::mk_ctxt(sess, def_map, amap, freevars);
280-
typeck::check_crate(ty_cx, impl_map, crate);
281-
ann = {pre: ann_paren_for_expr, post: bind ann_typed_post(ty_cx, _)};
293+
ann = {pre: ann_paren_for_expr,
294+
post: bind ann_typed_post(option::get(tcx), _)};
282295
}
283296
ppm_identified. {
284297
ann = {pre: ann_paren_for_expr, post: ann_identified_post};
285298
}
286-
ppm_normal. { ann = pprust::no_ann(); }
299+
ppm_expanded. | ppm_normal. {}
287300
}
288301
pprust::print_crate(sess.codemap, sess.diagnostic, crate, input,
289-
io::string_reader(src), io::stdout(), ann);
302+
src, io::stdout(), ann);
290303
}
291304

292305
fn get_os(triple: str) -> option<session::os> {
@@ -453,7 +466,7 @@ fn build_session_options(match: getopts::match,
453466
}
454467

455468
fn build_session(sopts: @session::options, input: str,
456-
demitter: diagnostic::emitter) -> session::session {
469+
demitter: diagnostic::emitter) -> session {
457470
let target_cfg = build_target_config(sopts, demitter);
458471
let cstore = cstore::mk_cstore();
459472
let filesearch = filesearch::mk_filesearch(
@@ -480,7 +493,7 @@ fn build_session(sopts: @session::options, input: str,
480493
working_dir: fs::dirname(input)}
481494
}
482495

483-
fn parse_pretty(sess: session::session, &&name: str) -> pp_mode {
496+
fn parse_pretty(sess: session, &&name: str) -> pp_mode {
484497
if str::eq(name, "normal") {
485498
ret ppm_normal;
486499
} else if str::eq(name, "expanded") {
@@ -509,11 +522,13 @@ fn opts() -> [getopts::opt] {
509522
optflag("warn-unused-imports")];
510523
}
511524

525+
type output_filenames = @{out_filename: str, obj_filename:str};
526+
512527
fn build_output_filenames(ifile: str,
513528
odir: option::t<str>,
514529
ofile: option::t<str>,
515-
sess: session::session)
516-
-> @{out_filename: str, obj_filename:str} {
530+
sess: session)
531+
-> output_filenames {
517532
let obj_path = "";
518533
let out_path: str = "";
519534
let sopts = sess.opts;
@@ -599,7 +614,7 @@ fn early_error(emitter: diagnostic::emitter, msg: str) -> ! {
599614
fail;
600615
}
601616

602-
fn list_metadata(sess: session::session, path: str, out: io::writer) {
617+
fn list_metadata(sess: session, path: str, out: io::writer) {
603618
metadata::creader::list_file_metadata(sess, path, out);
604619
}
605620

trunk/src/etc/snapshot.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,7 @@ def local_rev_committer_date():
117117
return local_rev_info("ci")
118118

119119
def get_url_to_file(u,f):
120-
tmpf = f + '.tmp' # no security issue, just to stop partial download leaving a stale file
121-
try:
122-
subprocess.check_call(["curl", "-o", tmpf, u])
123-
except subprocess.CalledProcessError:
124-
os.unlink(tmpf)
125-
raise
126-
os.rename(tmpf, f)
120+
subprocess.check_call(["curl", "-o", f, u])
127121

128122
def snap_filename_hash_part(snap):
129123
match = re.match(r".*([a-fA-F\d]{40}).tar.bz2$", snap)

0 commit comments

Comments
 (0)