Skip to content

Unsafe post snapshot #1036

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

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
00bf461
expand purity to include unsafe
nikomatsakis Oct 6, 2011
60ce53c
Extend the unchecked block stuff to allow unsafe blocks as well.
nikomatsakis Oct 6, 2011
a2582b2
Add unsafe blocks, unsafe functions, and two rudimentary tests
nikomatsakis Oct 7, 2011
a0efd30
it is also legal to call unsafe functions from other unsafe functions
nikomatsakis Oct 7, 2011
91a039c
fix test to include a main() function
nikomatsakis Oct 7, 2011
6ec4b8b
add 'u' to decoder (kinda' important)
nikomatsakis Oct 7, 2011
f829894
add 'u' to one other place it was missing
nikomatsakis Oct 7, 2011
4450a82
make treatment of unchecked/unsafe blocks more uniform; also
nikomatsakis Oct 7, 2011
66c3bbd
enable unsafe checking but only with a flag --check-unsafe
nikomatsakis Oct 10, 2011
234263d
correct lines over 78 chars
nikomatsakis Oct 10, 2011
7a12d54
skip test, remove whitespace
nikomatsakis Oct 11, 2011
9886fc0
make native functions markable as unsafe and incorporate that
nikomatsakis Oct 11, 2011
26c2a6e
Add unsafe tags to usage of LLVM funcs
nikomatsakis Oct 7, 2011
9eff1a0
add unsafe tags into various points in the translation chains
nikomatsakis Oct 7, 2011
816548b
continue to annotate trans functions as unsafe where neccessary
nikomatsakis Oct 10, 2011
d961094
continue to annotate trans functions as unsafe where neccessary
nikomatsakis Oct 10, 2011
37a8c1b
continue to annotate functions as unsafe where neccessary
nikomatsakis Oct 10, 2011
e4bd3cc
all tests pass
nikomatsakis Oct 10, 2011
01490a4
all tests pass
nikomatsakis Oct 10, 2011
0746572
add pass to check that unsafe fns cannot be used as values
nikomatsakis Oct 12, 2011
7dbf2e9
improve the span used in test generation
nikomatsakis Oct 12, 2011
f273250
make a good error msg if you try to use an unsafe fn for a test
nikomatsakis Oct 12, 2011
76e25c0
convert a few tests from unsafe fns to fns with unsafe bodies
nikomatsakis Oct 12, 2011
6ebbe72
add some new tests
nikomatsakis Oct 12, 2011
140a467
fix error msg
nikomatsakis Oct 12, 2011
3866463
prohibit ptr deref unless in unsafe code
nikomatsakis Oct 12, 2011
991314c
make compiler emit more than 1 error in the case of unsafe
nikomatsakis Oct 12, 2011
b70e41c
new test
nikomatsakis Oct 12, 2011
8029ce8
remove unsafe tags
nikomatsakis Oct 12, 2011
f5f9e2d
reimplement some of the unsafe stuff which got lost:
nikomatsakis Oct 12, 2011
7f92f88
make treatment of unchecked/unsafe blocks more uniform; also
nikomatsakis Oct 7, 2011
d394bdc
Add unsafe tags to usage of LLVM funcs
nikomatsakis Oct 7, 2011
1e206cd
add unsafe tags into various points in the translation chains
nikomatsakis Oct 7, 2011
5f288f2
continue to annotate trans functions as unsafe where neccessary
nikomatsakis Oct 10, 2011
7a0d10f
continue to annotate trans functions as unsafe where neccessary
nikomatsakis Oct 10, 2011
cab76a5
continue to annotate functions as unsafe where neccessary
nikomatsakis Oct 10, 2011
777dd6a
all tests pass
nikomatsakis Oct 10, 2011
a6cd35e
all tests pass
nikomatsakis Oct 10, 2011
c5d671c
add pass to check that unsafe fns cannot be used as values
nikomatsakis Oct 12, 2011
4ad03cc
improve the span used in test generation
nikomatsakis Oct 12, 2011
2771e94
make a good error msg if you try to use an unsafe fn for a test
nikomatsakis Oct 12, 2011
8000ac3
convert a few tests from unsafe fns to fns with unsafe bodies
nikomatsakis Oct 12, 2011
98ee7ff
add some new tests
nikomatsakis Oct 12, 2011
d3ecc46
fix error msg
nikomatsakis Oct 12, 2011
63eee8f
prohibit ptr deref unless in unsafe code
nikomatsakis Oct 12, 2011
fece625
make compiler emit more than 1 error in the case of unsafe
nikomatsakis Oct 12, 2011
70c69f7
new test
nikomatsakis Oct 12, 2011
4173916
remove unsafe tags
nikomatsakis Oct 12, 2011
f804562
reimplement some of the unsafe stuff which got lost:
nikomatsakis Oct 12, 2011
fca04a9
Merge branch 'unsafe-post-snapshot' of github.com:nikomatsakis/rust i…
nikomatsakis Oct 12, 2011
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
Prev Previous commit
Next Next commit
make native functions markable as unsafe and incorporate that
into the type check
  • Loading branch information
nikomatsakis committed Oct 12, 2011
commit 9886fc0bcff4eee6b26e70f97e53c8e557bf01d3
4 changes: 3 additions & 1 deletion src/comp/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ fn lookup_def(cnum: ast::crate_num, data: @[u8], did_: ast::def_id) ->
'u' { ast::def_fn(did, ast::unsafe_fn) }
'f' { ast::def_fn(did, ast::impure_fn) }
'p' { ast::def_fn(did, ast::pure_fn) }
'F' { ast::def_native_fn(did) }
'U' { ast::def_native_fn(did, ast::unsafe_fn) }
'F' { ast::def_native_fn(did, ast::impure_fn) }
'P' { ast::def_native_fn(did, ast::pure_fn) }
'y' { ast::def_ty(did) }
'T' { ast::def_native_ty(did) }
't' { ast::def_ty(did) }
Expand Down
10 changes: 8 additions & 2 deletions src/comp/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,15 @@ fn encode_info_for_native_item(ecx: @encode_ctxt, ebml_w: ebml::writer,
encode_type(ecx, ebml_w,
ty::mk_native(ecx.ccx.tcx, local_def(nitem.id)));
}
native_item_fn(_, _, tps) {
native_item_fn(_, fn_decl, tps) {
let letter =
alt fn_decl.purity {
unsafe_fn. { 'U' }
pure_fn. { 'P' } // this is currently impossible, but hey.
impure_fn. { 'F' }
} as u8;
encode_def_id(ebml_w, local_def(nitem.id));
encode_family(ebml_w, 'F' as u8);
encode_family(ebml_w, letter);
encode_type_param_kinds(ebml_w, tps);
encode_type(ecx, ebml_w, node_id_to_monotype(ecx.ccx.tcx, nitem.id));
encode_symbol(ecx, ebml_w, nitem.id);
Expand Down
8 changes: 5 additions & 3 deletions src/comp/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1059,9 +1059,11 @@ fn lookup_in_mie(e: env, mie: mod_index_entry, ns: namespace) ->
ret some(ast::def_native_ty(local_def(native_item.id)));
}
}
ast::native_item_fn(_, _, _) {
ast::native_item_fn(_, decl, _) {
if ns == ns_value {
ret some(ast::def_native_fn(local_def(native_item.id)));
ret some(ast::def_native_fn(
local_def(native_item.id),
decl.purity));
}
}
}
Expand Down Expand Up @@ -1163,7 +1165,7 @@ fn ns_for_def(d: def) -> namespace {
ast::def_binding(_) { ns_type }
ast::def_use(_) { ns_module }
ast::def_native_ty(_) { ns_type }
ast::def_native_fn(_) { ns_value }
ast::def_native_fn(_, _) { ns_value }
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/comp/middle/trans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3095,7 +3095,7 @@ fn trans_var(cx: @block_ctxt, sp: span, def: ast::def, id: ast::node_id)
-> lval_maybe_callee {
let ccx = bcx_ccx(cx);
alt def {
ast::def_fn(did, _) | ast::def_native_fn(did) {
ast::def_fn(did, _) | ast::def_native_fn(did, _) {
let tyt = ty::lookup_item_type(ccx.tcx, did);
ret lval_static_fn(cx, tyt, did, id);
}
Expand Down
2 changes: 1 addition & 1 deletion src/comp/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2602,7 +2602,7 @@ fn def_has_ty_params(def: ast::def) -> bool {
ast::def_binding(_) { ret false; }
ast::def_use(_) { ret false; }
ast::def_native_ty(_) { ret false; }
ast::def_native_fn(_) { ret true; }
ast::def_native_fn(_, _) { ret true; }
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/comp/middle/typeck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ fn ty_param_kinds_and_ty_for_def(fcx: @fn_ctxt, sp: span, defn: ast::def) ->
ret {kinds: no_kinds, ty: typ};
}
ast::def_fn(id, _) { ret ty::lookup_item_type(fcx.ccx.tcx, id); }
ast::def_native_fn(id) { ret ty::lookup_item_type(fcx.ccx.tcx, id); }
ast::def_native_fn(id, _) { ret ty::lookup_item_type(fcx.ccx.tcx, id); }
ast::def_const(id) { ret ty::lookup_item_type(fcx.ccx.tcx, id); }
ast::def_variant(_, vid) { ret ty::lookup_item_type(fcx.ccx.tcx, vid); }
ast::def_binding(id) {
Expand Down Expand Up @@ -1560,7 +1560,7 @@ fn require_pure_call(ccx: @crate_ctxt, caller_purity: ast::purity,
"safe function calls function marked unsafe");
}
}
some(ast::def_native_fn(_)) {
some(ast::def_native_fn(_, ast::unsafe_fn.)) {
if sess.get_opts().check_unsafe {
ccx.tcx.sess.span_fatal(
sp,
Expand Down Expand Up @@ -1893,6 +1893,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
}
ast::expr_path(pth) {
let defn = lookup_def(fcx, pth.span, id);

let tpt = ty_param_kinds_and_ty_for_def(fcx, expr.span, defn);
if ty::def_has_ty_params(defn) {
let path_tpot = instantiate_path(fcx, pth, tpt, expr.span);
Expand Down
2 changes: 1 addition & 1 deletion src/comp/syntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ tag def {
def_binding(def_id);
def_use(def_id);
def_native_ty(def_id);
def_native_fn(def_id);
def_native_fn(def_id, purity);
def_upvar(def_id, @def, /* writable */bool);
}

Expand Down
2 changes: 1 addition & 1 deletion src/comp/syntax/ast_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn def_id_of_def(d: def) -> def_id {
def_binding(id) { ret id; }
def_use(id) { ret id; }
def_native_ty(id) { ret id; }
def_native_fn(id) { ret id; }
def_native_fn(id, _) { ret id; }
def_upvar(id, _, _) { ret id; }
}
}
Expand Down
11 changes: 7 additions & 4 deletions src/comp/syntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1972,11 +1972,11 @@ fn parse_item_native_type(p: parser, attrs: [ast::attribute]) ->
span: ast_util::mk_sp(t.lo, hi)};
}

fn parse_item_native_fn(p: parser, attrs: [ast::attribute]) ->
@ast::native_item {
fn parse_item_native_fn(p: parser, attrs: [ast::attribute],
purity: ast::purity) -> @ast::native_item {
let lo = p.get_last_lo_pos();
let t = parse_fn_header(p);
let decl = parse_fn_decl(p, ast::impure_fn, ast::il_normal);
let decl = parse_fn_decl(p, purity, ast::il_normal);
let link_name = none;
if p.peek() == token::EQ { p.bump(); link_name = some(parse_str(p)); }
let hi = p.get_hi_pos();
Expand All @@ -1993,7 +1993,10 @@ fn parse_native_item(p: parser, attrs: [ast::attribute]) ->
if eat_word(p, "type") {
ret parse_item_native_type(p, attrs);
} else if eat_word(p, "fn") {
ret parse_item_native_fn(p, attrs);
ret parse_item_native_fn(p, attrs, ast::impure_fn);
} else if eat_word(p, "unsafe") {
expect_word(p, "fn");
ret parse_item_native_fn(p, attrs, ast::unsafe_fn);
} else { unexpected(p, p.peek()); }
}

Expand Down