Skip to content

Commit 992fb4f

Browse files
committed
Merge branch 'main' of github.com:roc-lang/basic-cli into split-update
2 parents c51e7fd + 397c9d3 commit 992fb4f

File tree

6 files changed

+30
-16
lines changed

6 files changed

+30
-16
lines changed

Cargo.toml

+3-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ members = ["crates/roc_host", "crates/roc_host_lib", "crates/roc_host_bin"]
55
[profile.release]
66
lto = true
77
strip = "debuginfo"
8-
# Enabling this triggered a segmentation fault (see issue github.com/roc-lang/roc/issues/6121).
9-
# That issue is notoriously fickle, so disableing this may just happen to shuffle the code enough to avoid it.
10-
# Try re-enableing this again in the future after some code changes, it may no longer trigger this issue.
11-
# Setting it to 1 should improve execution speed by making things easier to optimize for LLVM.
12-
# codegen-units = 1
8+
# You can comment this out if you hit a segmentation fault similar to the one in see issue github.com/roc-lang/roc/issues/6121
9+
# Setting this to 1 should improve execution speed by making things easier to optimize for LLVM.
10+
codegen-units = 1
1311

1412
[workspace.dependencies]
1513
roc_std = { git = "https://github.com/roc-lang/roc.git" }

crates/roc_host/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ pub fn init() {
301301
roc_fx_exePath as _,
302302
roc_fx_stdinLine as _,
303303
roc_fx_stdinBytes as _,
304+
roc_fx_stdinReadToEnd as _,
304305
roc_fx_stdoutLine as _,
305306
roc_fx_stdoutWrite as _,
306307
roc_fx_stderrLine as _,
@@ -462,8 +463,9 @@ pub extern "C" fn roc_fx_stdinLine() -> RocResult<RocStr, RocStr> {
462463

463464
#[no_mangle]
464465
pub extern "C" fn roc_fx_stdinBytes() -> RocResult<RocList<u8>, ()> {
466+
const BUF_SIZE: usize = 16_384; // 16 KiB = 16 * 1024 = 16,384 bytes
465467
let stdin = std::io::stdin();
466-
let mut buffer: [u8; 256] = [0; 256];
468+
let mut buffer: [u8; BUF_SIZE] = [0; BUF_SIZE];
467469

468470
match stdin.lock().read(&mut buffer) {
469471
Ok(bytes_read) => RocResult::ok(RocList::from(&buffer[0..bytes_read])),

examples/stdin.roc

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import pf.Stdin
66

77
main =
88
Stdout.line! "Enter a series of number characters (0-9):"
9-
numberBytes = takeNumberBytes!
9+
numberBytes = readNumberBytes!
1010

1111
if List.isEmpty numberBytes then
1212
Stderr.line "Expected a series of number characters (0-9)"
@@ -18,8 +18,8 @@ main =
1818
Err _ ->
1919
Stderr.line "Error, bad utf8"
2020

21-
takeNumberBytes : Task (List U8) _
22-
takeNumberBytes =
21+
readNumberBytes : Task (List U8) _
22+
readNumberBytes =
2323
bytesRead = Stdin.bytes! {}
2424

2525
numberBytes =

platform/File.roc

+9-3
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ readUtf8 = \path ->
153153
# Path.read (Path.fromStr path) fmt
154154

155155
## Returns true if the path exists on disk and is pointing at a directory.
156-
## Any error will return false.
156+
## Returns `Task.ok false` if the path exists and it is not a directory. If the path does not exist,
157+
## this function will return `Task.err PathErr PathDoesNotExist`.
158+
##
157159
## This uses [rust's std::path::is_dir](https://doc.rust-lang.org/std/path/struct.Path.html#method.is_dir).
158160
##
159161
## > [Path.isDir] does the same thing, except it takes a [Path] instead of a [Str].
@@ -162,7 +164,9 @@ isDir = \path ->
162164
Path.isDir (Path.fromStr path)
163165

164166
## Returns true if the path exists on disk and is pointing at a regular file.
165-
## Any error will return false.
167+
## Returns `Task.ok false` if the path exists and it is not a file. If the path does not exist,
168+
## this function will return `Task.err PathErr PathDoesNotExist`.
169+
##
166170
## This uses [rust's std::path::is_file](https://doc.rust-lang.org/std/path/struct.Path.html#method.is_file).
167171
##
168172
## > [Path.isFile] does the same thing, except it takes a [Path] instead of a [Str].
@@ -171,7 +175,9 @@ isFile = \path ->
171175
Path.isFile (Path.fromStr path)
172176

173177
## Returns true if the path exists on disk and is pointing at a symbolic link.
174-
## Any error will return false.
178+
## Returns `Task.ok false` if the path exists and it is not a symbolic link. If the path does not exist,
179+
## this function will return `Task.err PathErr PathDoesNotExist`.
180+
##
175181
## This uses [rust's std::path::is_symlink](https://doc.rust-lang.org/std/path/struct.Path.html#method.is_symlink).
176182
##
177183
## > [Path.isSymLink] does the same thing, except it takes a [Path] instead of a [Str].

platform/Path.roc

+11-3
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,10 @@ display = \path ->
418418
# Path.isDir, etc.
419419

420420
## Returns true if the path exists on disk and is pointing at a directory.
421-
## Any error will return false.
421+
## Returns `Task.ok false` if the path exists and it is not a directory. If the path does not exist,
422+
## this function will return `Task.err PathErr PathDoesNotExist`.
423+
##
424+
## This uses [rust's std::path::is_dir](https://doc.rust-lang.org/std/path/struct.Path.html#method.is_dir).
422425
##
423426
## > [`File.isDir`](File#isDir) does the same thing, except it takes a [Str] instead of a [Path].
424427
isDir : Path -> Task Bool [PathErr MetadataErr]
@@ -427,7 +430,9 @@ isDir = \path ->
427430
Task.ok (res == IsDir)
428431

429432
## Returns true if the path exists on disk and is pointing at a regular file.
430-
## Any error will return false.
433+
## Returns `Task.ok false` if the path exists and it is not a file. If the path does not exist,
434+
## this function will return `Task.err PathErr PathDoesNotExist`.
435+
##
431436
## This uses [rust's std::path::is_file](https://doc.rust-lang.org/std/path/struct.Path.html#method.is_file).
432437
##
433438
## > [`File.isFile`](File#isFile) does the same thing, except it takes a [Str] instead of a [Path].
@@ -437,7 +442,10 @@ isFile = \path ->
437442
Task.ok (res == IsFile)
438443

439444
## Returns true if the path exists on disk and is pointing at a symbolic link.
440-
## Any error will return false.
445+
## Returns `Task.ok false` if the path exists and it is not a symbolic link. If the path does not exist,
446+
## this function will return `Task.err PathErr PathDoesNotExist`.
447+
##
448+
## This uses [rust's std::path::is_symlink](https://doc.rust-lang.org/std/path/struct.Path.html#method.is_symlink).
441449
##
442450
## > [`File.isSymLink`](File#isSymLink) does the same thing, except it takes a [Str] instead of a [Path].
443451
isSymLink : Path -> Task Bool [PathErr MetadataErr]

platform/Stdin.roc

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ line =
6464
|> Task.mapErr handleErr
6565

6666
## Read bytes from [standard input](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)).
67-
## ‼️ This function can read no more than 256 bytes at a time. Use [readToEnd] if you need more.
67+
## ‼️ This function can read no more than 16,384 bytes at a time. Use [readToEnd] if you need more.
6868
##
6969
## > This is typically used in combintation with [Tty.enableRawMode],
7070
## which disables defaults terminal bevahiour and allows reading input

0 commit comments

Comments
 (0)