Skip to content

Commit

Permalink
[stdlib] Use InlineArray over StaticTuple in os module
Browse files Browse the repository at this point in the history
Replace uses of `StaticTuple` with `InlineArray`.  Soon, `StaticTuple`
will be deprecated.  This requires removing some reg-passable annotations on
types since `StaticTuple` was register passable trivial, but `InlineArray` is of
course not.

As a bonus, this should speed up compile times a little bit since in some cases,
we were using a `StaticTuple` of size `1024` which would not compile very fast.
See #2425.

MODULAR_ORIG_COMMIT_REV_ID: 004b5334e3bd78a8a8054d6762501efc557df716
  • Loading branch information
JoeLoser committed May 11, 2024
1 parent 0549e41 commit 021b895
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 17 deletions.
7 changes: 3 additions & 4 deletions stdlib/src/os/_linux_aarch64.mojo
Expand Up @@ -13,7 +13,7 @@

from time.time import _CTimeSpec

from utils import StaticTuple
from utils import InlineArray

from .fstat import stat_result

Expand All @@ -29,7 +29,6 @@ alias blksize_t = Int32


@value
@register_passable("trivial")
struct _c_stat(Stringable):
var st_dev: dev_t # ID of device containing file
var st_ino: Int64 # File serial number
Expand All @@ -47,7 +46,7 @@ struct _c_stat(Stringable):
var st_mtimespec: _CTimeSpec # time of last data modification
var st_ctimespec: _CTimeSpec # time of last status change
var st_birthtimespec: _CTimeSpec # time of file creation(birth)
var unused: StaticTuple[Int64, 2] # RESERVED: DO NOT USE!
var unused: InlineArray[Int64, 2] # RESERVED: DO NOT USE!

fn __init__(inout self):
self.st_dev = 0
Expand All @@ -66,7 +65,7 @@ struct _c_stat(Stringable):
self.st_mtimespec = _CTimeSpec()
self.st_ctimespec = _CTimeSpec()
self.st_birthtimespec = _CTimeSpec()
self.unused = StaticTuple[Int64, 2](0, 0)
self.unused = InlineArray[Int64, 2](0, 0)

fn __str__(self) -> String:
var res = String("{\n")
Expand Down
7 changes: 3 additions & 4 deletions stdlib/src/os/_linux_x86.mojo
Expand Up @@ -13,7 +13,7 @@

from time.time import _CTimeSpec

from utils.index import StaticTuple
from utils.index import InlineArray

from .fstat import stat_result

Expand All @@ -29,7 +29,6 @@ alias blksize_t = Int64


@value
@register_passable("trivial")
struct _c_stat(Stringable):
var st_dev: dev_t # ID of device containing file
var st_ino: Int64 # File serial number
Expand All @@ -46,7 +45,7 @@ struct _c_stat(Stringable):
var st_mtimespec: _CTimeSpec # time of last data modification
var st_ctimespec: _CTimeSpec # time of last status change
var st_birthtimespec: _CTimeSpec # time of file creation(birth)
var unused: StaticTuple[Int64, 3] # RESERVED: DO NOT USE!
var unused: InlineArray[Int64, 3] # RESERVED: DO NOT USE!

fn __init__(inout self):
self.st_dev = 0
Expand All @@ -64,7 +63,7 @@ struct _c_stat(Stringable):
self.st_mtimespec = _CTimeSpec()
self.st_ctimespec = _CTimeSpec()
self.st_birthtimespec = _CTimeSpec()
self.unused = StaticTuple[Int64, 3](0, 0, 0)
self.unused = InlineArray[Int64, 3](0, 0, 0)

fn __str__(self) -> String:
var res = String("{\n")
Expand Down
7 changes: 3 additions & 4 deletions stdlib/src/os/_macos.mojo
Expand Up @@ -13,7 +13,7 @@

from time.time import _CTimeSpec

from utils import StaticTuple
from utils import InlineArray

from .fstat import stat_result

Expand All @@ -30,7 +30,6 @@ alias blksize_t = Int32


@value
@register_passable("trivial")
struct _c_stat(Stringable):
var st_dev: dev_t # ID of device containing file
var st_mode: mode_t # Mode of file
Expand All @@ -49,7 +48,7 @@ struct _c_stat(Stringable):
var st_flags: UInt32 # user defined flags for file
var st_gen: UInt32 # file generation number
var st_lspare: Int32 # RESERVED: DO NOT USE!
var st_qspare: StaticTuple[Int64, 2] # RESERVED: DO NOT USE!
var st_qspare: InlineArray[Int64, 2] # RESERVED: DO NOT USE!

fn __init__(inout self):
self.st_dev = 0
Expand All @@ -69,7 +68,7 @@ struct _c_stat(Stringable):
self.st_flags = 0
self.st_gen = 0
self.st_lspare = 0
self.st_qspare = StaticTuple[Int64, 2](0, 0)
self.st_qspare = InlineArray[Int64, 2](0, 0)

fn __str__(self) -> String:
var res = String("{\n")
Expand Down
8 changes: 3 additions & 5 deletions stdlib/src/os/os.mojo
Expand Up @@ -27,7 +27,7 @@ from memory import (
)
from memory.unsafe_pointer import move_from_pointee

from utils import StringRef, StaticTuple
from utils import StringRef, InlineArray

from .path import isdir
from .pathlike import PathLike
Expand All @@ -52,7 +52,6 @@ alias SEEK_END: UInt8 = 2


@value
@register_passable("trivial")
struct _dirent_linux:
alias MAX_NAME_SIZE = 256
var d_ino: Int64
Expand All @@ -63,12 +62,11 @@ struct _dirent_linux:
"""Length of the record."""
var d_type: Int8
"""Type of file."""
var name: StaticTuple[Int8, Self.MAX_NAME_SIZE]
var name: InlineArray[Int8, Self.MAX_NAME_SIZE]
"""Name of entry."""


@value
@register_passable("trivial")
struct _dirent_macos:
alias MAX_NAME_SIZE = 1024
var d_ino: Int64
Expand All @@ -81,7 +79,7 @@ struct _dirent_macos:
"""Length of the name."""
var d_type: Int8
"""Type of file."""
var name: StaticTuple[Int8, Self.MAX_NAME_SIZE]
var name: InlineArray[Int8, Self.MAX_NAME_SIZE]
"""Name of entry."""


Expand Down

0 comments on commit 021b895

Please sign in to comment.