Skip to content
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

move io out of system #19442

Merged
merged 13 commits into from
Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
- `addr` is now available for all addressable locations, `unsafeAddr` is deprecated and
becomes an alias for `addr`.

- io is about to move out of system; use `-d:nimPreviewSlimSystem` and import `std/syncio`.

## Standard library additions and changes

- `macros.parseExpr` and `macros.parseStmt` now accept an optional
Expand Down
3 changes: 3 additions & 0 deletions compiler/pathutils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

import os, pathnorm

when defined(nimSlimSystem):
import std/syncio

type
AbsoluteFile* = distinct string
AbsoluteDir* = distinct string
Expand Down
2 changes: 1 addition & 1 deletion compiler/vmops.nim
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ template systemop(op) {.dirty.} =
registerCallback(c, "stdlib.system." & astToStr(op), `op Wrapper`)

template ioop(op) {.dirty.} =
registerCallback(c, "stdlib.io." & astToStr(op), `op Wrapper`)
registerCallback(c, "stdlib.syncio." & astToStr(op), `op Wrapper`)

template macrosop(op) {.dirty.} =
registerCallback(c, "stdlib.macros." & astToStr(op), `op Wrapper`)
Expand Down
8 changes: 4 additions & 4 deletions doc/tut1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ done with spaces only, tabulators are not allowed.

String literals are enclosed in double-quotes. The `var` statement declares
a new variable named `name` of type `string` with the value that is
returned by the `readLine <io.html#readLine,File>`_ procedure. Since the
compiler knows that `readLine <io.html#readLine,File>`_ returns a string,
returned by the `readLine <syncio.html#readLine,File>`_ procedure. Since the
compiler knows that `readLine <syncio.html#readLine,File>`_ returns a string,
you can leave out the type in the declaration (this is called `local type
inference`:idx:). So this will work too:

Expand All @@ -97,7 +97,7 @@ Note that this is basically the only form of type inference that exists in
Nim: it is a good compromise between brevity and readability.

The "hello world" program contains several identifiers that are already known
to the compiler: `echo`, `readLine <io.html#readLine,File>`_, etc.
to the compiler: `echo`, `readLine <syncio.html#readLine,File>`_, etc.
These built-ins are declared in the system_ module which is implicitly
imported by any other module.

Expand Down Expand Up @@ -594,7 +594,7 @@ Procedures
==========

To define new commands like `echo <system.html#echo,varargs[typed,]>`_
and `readLine <io.html#readLine,File>`_ in the examples, the concept of a
and `readLine <syncio.html#readLine,File>`_ in the examples, the concept of a
*procedure* is needed. You might be used to them being called *methods* or
*functions* in other languages, but Nim
`differentiates these concepts <tut1.html#procedures-funcs-and-methods>`_. In
Expand Down
3 changes: 3 additions & 0 deletions lib/posix/posix.nim
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
when defined(nimHasStyleChecks):
{.push styleChecks: off.}

when defined(nimSlimSystem):
import std/syncio

# TODO these constants don't seem to be fetched from a header file for unknown
# platforms - where do they come from and why are they here?
when false:
Expand Down
3 changes: 3 additions & 0 deletions lib/pure/htmlparser.nim
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@

import strutils, streams, parsexml, xmltree, unicode, strtabs

when defined(nimPreviewSlimSystem):
import std/syncio

type
HtmlTag* = enum ## list of all supported HTML tags; order will always be
## alphabetically
Expand Down
3 changes: 3 additions & 0 deletions lib/pure/json.nim
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ import hashes, tables, strutils, lexbase, streams, macros, parsejson
import options # xxx remove this dependency using same approach as https://github.com/nim-lang/Nim/pull/14563
import std/private/since

when defined(nimPreviewSlimSystem):
import std/syncio

export
tables.`$`

Expand Down
11 changes: 7 additions & 4 deletions lib/pure/logging.nim
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
## .. warning::
## For loggers that log to a console or to files, only error and fatal
## messages will cause their output buffers to be flushed immediately.
## Use the `flushFile proc <io.html#flushFile,File>`_ to flush the buffer
## Use the `flushFile proc <syncio.html#flushFile,File>`_ to flush the buffer
## manually if needed.
##
## Handlers
Expand Down Expand Up @@ -146,6 +146,9 @@ import strutils, times
when not defined(js):
import os

when defined(nimPreviewSlimSystem):
import std/syncio

type
Level* = enum ## \
## Enumeration of logging levels.
Expand Down Expand Up @@ -346,7 +349,7 @@ method log*(logger: ConsoleLogger, level: Level, args: varargs[string, `$`]) =
##
## **Note:** Only error and fatal messages will cause the output buffer
## to be flushed immediately. Use the `flushFile proc
## <io.html#flushFile,File>`_ to flush the buffer manually if needed.
## <syncio.html#flushFile,File>`_ to flush the buffer manually if needed.
##
## See also:
## * `log method<#log.e,FileLogger,Level,varargs[string,]>`_
Expand Down Expand Up @@ -422,7 +425,7 @@ when not defined(js):
## **Notes:**
## * Only error and fatal messages will cause the output buffer
## to be flushed immediately. Use the `flushFile proc
## <io.html#flushFile,File>`_ to flush the buffer manually if needed.
## <syncio.html#flushFile,File>`_ to flush the buffer manually if needed.
## * This method is not available for the JavaScript backend.
##
## See also:
Expand Down Expand Up @@ -600,7 +603,7 @@ when not defined(js):
## **Notes:**
## * Only error and fatal messages will cause the output buffer
## to be flushed immediately. Use the `flushFile proc
## <io.html#flushFile,File>`_ to flush the buffer manually if needed.
## <syncio.html#flushFile,File>`_ to flush the buffer manually if needed.
## * This method is not available for the JavaScript backend.
##
## See also:
Expand Down
4 changes: 2 additions & 2 deletions lib/pure/memfiles.nim
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ iterator memSlices*(mfile: MemFile, delim = '\l', eat = '\r'): MemSlice {.inline
iterator lines*(mfile: MemFile, buf: var string, delim = '\l',
eat = '\r'): string {.inline.} =
## Replace contents of passed buffer with each new line, like
## `readLine(File) <io.html#readLine,File,string>`_.
## `readLine(File) <syncio.html#readLine,File,string>`_.
## `delim`, `eat`, and delimiting logic is exactly as for `memSlices
## <#memSlices.i,MemFile,char,char>`_, but Nim strings are returned.
##
Expand All @@ -450,7 +450,7 @@ iterator lines*(mfile: MemFile, buf: var string, delim = '\l',

iterator lines*(mfile: MemFile, delim = '\l', eat = '\r'): string {.inline.} =
## Return each line in a file as a Nim string, like
## `lines(File) <io.html#lines.i,File>`_.
## `lines(File) <syncio.html#lines.i,File>`_.
## `delim`, `eat`, and delimiting logic is exactly as for `memSlices
## <#memSlices.i,MemFile,char,char>`_, but Nim strings are returned.
##
Expand Down
3 changes: 3 additions & 0 deletions lib/pure/os.nim
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ import std/private/since

import strutils, pathnorm

when defined(nimPreviewSlimSystem):
import std/syncio

const weirdTarget = defined(nimscript) or defined(js)

since (1, 1):
Expand Down
4 changes: 4 additions & 0 deletions lib/pure/parsecfg.nim
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,12 @@ import strutils, lexbase, streams, tables
import std/private/decode_helpers
import std/private/since

when defined(nimPreviewSlimSystem):
import std/syncio

include "system/inclrtl"


type
CfgEventKind* = enum ## enumeration of all events that may occur when parsing
cfgEof, ## end of file reached
Expand Down
3 changes: 3 additions & 0 deletions lib/pure/parsecsv.nim
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@

import lexbase, streams

when defined(nimPreviewSlimSystem):
import std/syncio

type
CsvRow* = seq[string] ## A row in a CSV file.
CsvParser* = object of BaseLexer ## The parser object.
Expand Down
2 changes: 2 additions & 0 deletions lib/pure/pegs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
##

include "system/inclrtl"
when defined(nimPreviewSlimSystem):
import std/syncio

const
useUnicode = true ## change this to deactivate proper UTF-8 support
Expand Down
3 changes: 3 additions & 0 deletions lib/pure/ropes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
include system/inclrtl
import streams

when defined(nimPreviewSlimSystem):
import std/syncio

{.push debugger: off.} # the user does not want to trace a part
# of the standard library!

Expand Down
9 changes: 6 additions & 3 deletions lib/pure/streams.nim
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,13 @@
## See also
## ========
## * `asyncstreams module <asyncstreams.html>`_
## * `io module <io.html>`_ for `FileMode enum <io.html#FileMode>`_
## * `io module <syncio.html>`_ for `FileMode enum <syncio.html#FileMode>`_

import std/private/since

when defined(nimPreviewSlimSystem):
import std/syncio

proc newEIO(msg: string): owned(ref IOError) =
new(result)
result.msg = msg
Expand Down Expand Up @@ -1331,7 +1334,7 @@ proc newFileStream*(f: File): owned FileStream =
## * `newStringStream proc <#newStringStream,string>`_ creates a new stream
## from string.
## * `newFileStream proc <#newFileStream,string,FileMode,int>`_ is the same
## as using `open proc <io.html#open,File,string,FileMode,int>`_
## as using `open proc <syncio.html#open,File,string,FileMode,int>`_
## on Examples.
## * `openFileStream proc <#openFileStream,string,FileMode,int>`_ creates a
## file stream from the file name and the mode.
Expand Down Expand Up @@ -1370,7 +1373,7 @@ proc newFileStream*(filename: string, mode: FileMode = fmRead,
## Creates a new stream from the file named `filename` with the mode `mode`.
##
## If the file cannot be opened, `nil` is returned. See the `io module
## <io.html>`_ for a list of available `FileMode enums <io.html#FileMode>`_.
## <syncio.html>`_ for a list of available `FileMode enums <syncio.html#FileMode>`_.
##
## **Note:**
## * **This function returns nil in case of failure.**
Expand Down
3 changes: 3 additions & 0 deletions lib/pure/terminal.nim
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ import colors
when defined(windows):
import winlean

when defined(nimPreviewSlimSystem):
import std/syncio

type
PTerminal = ref object
trueColorIsSupported: bool
Expand Down
3 changes: 3 additions & 0 deletions lib/pure/xmlparser.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

import streams, parsexml, strtabs, xmltree

when defined(nimPreviewSlimSystem):
import std/syncio

type
XmlError* = object of ValueError ## Exception that is raised
## for invalid XML.
Expand Down
Loading