Skip to content

Commit 2fcf81c

Browse files
committed
Revert "Move the option type to its own module"
1 parent a58016d commit 2fcf81c

File tree

11 files changed

+46
-68
lines changed

11 files changed

+46
-68
lines changed

src/comp/driver/rustc.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import front.token;
55
import middle.trans;
66
import middle.resolve;
77

8-
import std.option;
9-
import std.option.some;
10-
import std.option.none;
8+
import std.util.option;
9+
import std.util.some;
10+
import std.util.none;
1111
import std._str;
1212
import std._vec;
1313

@@ -39,8 +39,8 @@ fn usage(session.session sess, str argv0) {
3939
impure fn main(vec[str] args) {
4040

4141
auto sess = session.session();
42-
let option.t[str] input_file = none[str];
43-
let option.t[str] output_file = none[str];
42+
let option[str] input_file = none[str];
43+
let option[str] output_file = none[str];
4444
let bool do_warn = true;
4545

4646
auto i = 1u;

src/comp/front/ast.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
import util.common.option;
23
import std.map.hashmap;
34
import std.util.option;
45
import util.common.span;

src/comp/front/parser.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import std._io;
2-
import std.option.some;
3-
import std.option.none;
4-
import std.map.hashmap;
52
import std.util.option;
3+
import std.util.some;
4+
import std.util.none;
5+
import std.map.hashmap;
66

77
import driver.session;
88
import util.common;

src/comp/middle/fold.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import std.map.hashmap;
2-
import std.option.some;
3-
import std.option.none;
42
import std.util.option;
3+
import std.util.some;
4+
import std.util.none;
55

66
import util.common.new_str_hash;
77
import util.common.spanned;

src/comp/middle/resolve.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import std.map.hashmap;
88
import std.list.list;
99
import std.list.nil;
1010
import std.list.cons;
11-
import std.option.some;
12-
import std.option.none;
1311
import std.util.option;
12+
import std.util.some;
13+
import std.util.none;
1414
import std._str;
1515

1616
tag scope {

src/comp/middle/trans.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import std._vec;
33
import std._str.rustrt.sbuf;
44
import std._vec.rustrt.vbuf;
55
import std.map.hashmap;
6-
import std.option.some;
7-
import std.option.none;
86
import std.util.option;
7+
import std.util.some;
8+
import std.util.none;
99

1010
import front.ast;
1111
import driver.session;

src/lib/deque.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* A deque, for fun. Untested as of yet. Likely buggy.
33
*/
44

5-
import std.option;
5+
import std.util;
66
import std._vec;
77
import std._int;
88

@@ -23,7 +23,7 @@ type t[T] = obj {
2323

2424
fn create[T]() -> t[T] {
2525

26-
type cell[T] = mutable option.t[T];
26+
type cell[T] = mutable util.option[T];
2727

2828
let uint initial_capacity = 32u; // 2^5
2929

@@ -39,7 +39,7 @@ fn create[T]() -> t[T] {
3939
if (i < nelts) {
4040
ret old.((lo + i) % nelts);
4141
} else {
42-
ret option.none;
42+
ret util.none[T];
4343
}
4444
}
4545

@@ -50,7 +50,7 @@ fn create[T]() -> t[T] {
5050

5151
fn get[T](vec[cell[T]] elts, uint i) -> T {
5252
alt (elts.(i)) {
53-
case (option.some[T](?t)) { ret t; }
53+
case (util.some[T](?t)) { ret t; }
5454
case (_) { fail; }
5555
}
5656
}
@@ -77,7 +77,7 @@ fn create[T]() -> t[T] {
7777
hi = nelts;
7878
}
7979

80-
elts.(lo) = option.some[T](t);
80+
elts.(lo) = util.some[T](t);
8181
nelts += 1u;
8282
}
8383

@@ -88,7 +88,7 @@ fn create[T]() -> t[T] {
8888
hi = nelts;
8989
}
9090

91-
elts.(hi) = option.some[T](t);
91+
elts.(hi) = util.some[T](t);
9292
hi = (hi + 1u) % _vec.len[cell[T]](elts);
9393
nelts += 1u;
9494
}
@@ -99,7 +99,7 @@ fn create[T]() -> t[T] {
9999
*/
100100
fn pop_front() -> T {
101101
let T t = get[T](elts, lo);
102-
elts.(lo) = option.none[T];
102+
elts.(lo) = util.none[T];
103103
lo = (lo + 1u) % _vec.len[cell[T]](elts);
104104
nelts -= 1u;
105105
ret t;
@@ -113,7 +113,7 @@ fn create[T]() -> t[T] {
113113
}
114114

115115
let T t = get[T](elts, hi);
116-
elts.(hi) = option.none[T];
116+
elts.(hi) = util.none[T];
117117
nelts -= 1u;
118118
ret t;
119119
}
@@ -132,7 +132,7 @@ fn create[T]() -> t[T] {
132132
}
133133

134134
}
135-
let vec[cell[T]] v = _vec.init_elt[cell[T]](option.none[T],
135+
let vec[cell[T]] v = _vec.init_elt[cell[T]](util.none[T],
136136
initial_capacity);
137137

138138
ret deque[T](0u, 0u, 0u, v);

src/lib/list.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

2-
import option;
3-
import option.some;
4-
import option.none;
2+
import util.option;
3+
import util.some;
4+
import util.none;
55

66
// FIXME: It would probably be more appealing to define this as
77
// type list[T] = rec(T hd, option[@list[T]] tl), but at the moment
@@ -27,7 +27,7 @@ fn foldl[T,U](&list[T] ls, &U u, fn(&T t, U u) -> U f) -> U {
2727
}
2828

2929
fn find[T,U](&list[T] ls,
30-
(fn(&T) -> option.t[U]) f) -> option.t[U] {
30+
(fn(&T) -> option[U]) f) -> option[U] {
3131
alt(ls) {
3232
case (cons[T](?hd, ?tl)) {
3333
alt (f(hd)) {

src/lib/option.rs

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/lib/std.rc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ mod _task;
2020

2121
// Utility modules.
2222

23-
mod option;
2423
mod util;
2524

2625
// Authorize various rule-bendings.

src/lib/util.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
tag option[T] {
2+
none;
3+
some(T);
4+
}
5+
6+
type operator[T, U] = fn(&T) -> U;
7+
8+
fn option_map[T, U](&operator[T, U] f, &option[T] opt) -> option[U] {
9+
alt (opt) {
10+
case (some[T](?x)) {
11+
ret some[U](f(x));
12+
}
13+
case (none[T]) {
14+
ret none[U];
15+
}
16+
}
17+
}
18+
119
fn id[T](&T x) -> T {
220
ret x;
321
}

0 commit comments

Comments
 (0)