Code Monkey home page Code Monkey logo

core's Introduction

moonbitlang/core

check codecov

moonbitlang/core is the standard library of the MoonBit language. It is released alongside the compiler. You can view the documentation for the latest official release at https://mooncakes.io/docs/#/moonbitlang/core/. This repository serves as the development repository.

Current status

It is experimental and under active development. At this early stage, our primary focus is on enhancing the functionality of moonbitlang/core.

⚠️The API is subject to change.

Timeline

Prior to 05/01/2024, we mainly focus on adding new libs. We will go through a consistency review in May and expect basic API stability before 07/01/2024

Contributing

We are actively developing moonbitlang/core and appreciate your help!

To contribute, please read the contribution guidelines at CONTRIBUTING.md.

Being a collaborator

Note we regularly evaluate external contributions and invite activate contributors to join us as collaborators, thank you! To keep the contributors managebable, we will revoke commit rights if external collaborators are not active for over 6 months.

core's People

Contributors

bobzhang avatar lampese avatar yj-qin avatar caimeox avatar jialunzhang-psu avatar hackwaly avatar lynzrand avatar lijunchen avatar guest0x0 avatar peter-jerry-ye avatar yu-zh avatar fantix avatar zxch3n avatar muqiuhan avatar yoorkin avatar diamondmofeng avatar wanteatfruit avatar bzy-debug avatar young-flash avatar he1pa avatar lgxbslgx avatar minglluo avatar pd4d10 avatar codezhangborui avatar tonyfettes avatar mng12345 avatar qazxcdswe123 avatar blqis avatar npmstudy avatar

Stargazers

Li Xingjian avatar Asphodelus avatar Thompson avatar Jelly Terra avatar cc avatar Mochizuki Haruka avatar  avatar  avatar Lucas de Ávila Martins avatar Glomzzz avatar  avatar Enoch avatar Maxtune Lee avatar LuoTat avatar  avatar Andy Lu avatar  avatar Magnus Jurdal avatar  avatar  avatar Thiha avatar Vadim avatar eczn* avatar Alexandre avatar Maxime Alardo avatar Daniel Kloimwieder avatar Michael Bitokhov avatar Roohullah Afzali avatar Takuya Fukuju avatar lushiqiang avatar Devon 'fire' Adkisson avatar Paul Bacchus avatar Yuji Sugiura avatar Luis Flores avatar dai avatar Yu Fan avatar Jiefeng Li avatar  avatar ohmycloud avatar Ryuta Suzuki avatar WeZZard avatar  avatar LI CHENXI avatar Li YuBei avatar Taisei Mima avatar gTF avatar lessmost avatar Hamad Binqali avatar  avatar Guillaume Dumoulin avatar Chris Wu avatar Fatih Kalifa avatar ShiftWeight avatar Jeff Chiang avatar Yiwei Yang avatar Howard Zhang avatar Meng Zhuo avatar  avatar Charlie avatar Shotaro Nakamura avatar syuilo avatar sang avatar  avatar たいち ひ avatar kazuya kawaguchi avatar 底なし沼の魔女 avatar SUZUKI Sosuke avatar  avatar Sumit Parakh avatar The web walker avatar Jonathan Beri avatar  avatar goozp avatar ayawen avatar  avatar Ji Tao avatar rkmdsxmds avatar flyingtimeice avatar chnykn avatar lzxb avatar  avatar steven avatar Saniko avatar  avatar 稻谷 avatar  avatar BenjaminWang avatar ishiko avatar  avatar tanimon avatar sayhi-x avatar Soata avatar shina avatar  avatar Haruki Eguchi avatar Paul Tsnobiladzé avatar Toshimaru avatar Shota Minami avatar Ryo Uchino avatar Masaya Watanabe avatar

Watchers

题叶 avatar  avatar 午夜 avatar Christopher Serr avatar  avatar hbinr avatar  avatar  avatar  avatar Magnus Jurdal avatar

core's Issues

Coverage should be smarter

  • The test block should not be counted as coverage.
  • There are some abort statements that will never run, is there a way to ignore them?

Weird warning message

I got a weird warning message when running moon check on this commit

:0:0-0:0 Warning 010: Unused pattern
:0:0-0:0 Warning 012: Unreachable code

Proposal: Develop a uniform naming convention

The existing Pull requests are slightly different from the existing code in the core repository in terms of function names and test names. Is it necessary to develop a unified standard to manage?

The CI should catch warnings

/Users/hongbozhang/git/core/array/array.mbt:626:13-626:14 Warning 013: The type of this expression is (Array[_/0], Array[_/0]) -> Array[_/0], which contains unresolved type variables. The type variable is default to Unit.
/Users/hongbozhang/git/core/array/array.mbt:626:13-626:14 Warning 013: The type of this expression is (Array[_/0], Array[_/0]) -> Array[_/0], which contains unresolved type variables. The type variable is default to Unit.
/Users/hongbozhang/git/core/vec/vec.mbt:190:18-190:19 Warning 013: The type of this expression is (Vec[_/0], Vec[_/0]) -> Vec[_/0], which contains unresolved type variables. The type variable is default to Unit.
/Users/hongbozhang/git/core/vec/vec.mbt:190:18-190:19 Warning 013: The type of this expression is (Vec[_/0], Vec[_/0]) -> Vec[_/0], which contains unresolved type variables. The type variable is default to Unit.
Total tests: 376, passed: 376, failed: 0.

Dependency circle misjudged

Here I have imported list using vec and imported vec using list, but the compiler gives me the error error: cyclic dependency detected in package moonbitlang/core/option.

For this reason, I mapped the whole set of dependencies to check and found that option has no dependency on them.

graph LR
assertion --> deque
assertion --> array
assertion --> bytes
assertion --> coverage
assertion --> double
assertion --> hashmap
assertion --> immutable_hashmap
assertion --> immutable_set
assertion --> map
assertion --> int
assertion --> int64
assertion --> list
assertion --> math
assertion --> queue
assertion --> priority_queue
assertion --> id(option)
style id fill:#bbf,stroke:#f66,stroke-width:2px,color:#fff,stroke-
double --> math
string --> coverage
math --> array
num --> double
num --> int
num --> int64
int --> hashmap
list --> hashmap
list --> immutable_hashset
array --> list
array --> hashmap
array --> immutable_hashmap
array --> immutable_set
vec --circle--> list
vec --> map
list --> map
assertion --> ref
num --> ref
int --> ref
assertion --> result
list --> stack
array --> stack
assertion --> stack
assertion --> strconv
assertion --> tuple
assertion --> vec
string --> vec
list --circle--> vec

Coverage CI fails to upload coverage results

Coverage CI sometimes fails with the error message 'Unable to locate build via Github Actions API. Please upload with the Codecov repository upload token to resolve issue.. An example can be seen here: https://github.com/moonbitlang/core/actions/runs/8587025232/job/23530155946?pr=205#step:7:66

The issue seens to be related to codecov/feedback#126. If that's the case, it's because the GitHub token for CodeCov itself being rate limited, and we are unable to do anything about that on our side.

A possible two-workflow workaround is described in codecov/feedback#301 (comment)

bug report: mut check

I'm trying to implement a stable sorting algorithm. Is this error in the picture a bug? I changed the runs in the while block, but when defined with mut, an error will be prompted, and the moon check also failed
image

moon add --version

➜  core git:(main) moon --version
error: unexpected argument '--version' found

Usage: moon <COMMAND>

For more information, try '--help'.
➜  core git:(main) moon bundle --source-dir ~/.moon/lib/core
error: no such command: `bundle`

Formatter exception when formatting string.mbt

In #232 we find that string.mbt has undergone a binary change after formatting.

Here are further tests.

The string.mbt is the file in the latest branch, and the string_old.mbt is the file before merge #232.

Input:

xxd string.mbt > new.hex
xxd string_old.mbt > old.hex
diff new.hex old.hex

Output:

139,184c139,184
< 000008a0: 7d0a 0a20 2040 6173 7365 7274 696f 6e2e  }..  @assertion.
< 000008b0: 6173 7365 7274 5f65 7128 7265 7072 2822  assert_eq(repr("
< 000008c0: 6122 292c 2022 5c22 615c 2222 293f 0a20  a"), "\"a\"")?.
< 000008d0: 2040 6173 7365 7274 696f 6e2e 6173 7365   @assertion.asse
< 000008e0: 7274 5f65 7128 7265 7072 2822 2722 292c  rt_eq(repr("'"),
< 000008f0: 2022 5c22 275c 2222 293f 0a20 2040 6173   "\"'\"")?.  @as
< 00000900: 7365 7274 696f 6e2e 6173 7365 7274 5f65  sertion.assert_e
< 00000910: 7128 7265 7072 2822 5c22 2229 2c20 225c  q(repr("\""), "\
< 00000920: 225c 5c5c 225c 2222 293f 0a20 2040 6173  "\\\"\"")?.  @as
< 00000930: 7365 7274 696f 6e2e 6173 7365 7274 5f65  sertion.assert_e
< 00000940: 7128 7265 7072 2822 5c5c 2229 2c20 225c  q(repr("\\"), "\
< 00000950: 225c 5c5c 5c5c 2222 293f 0a20 2040 6173  "\\\\\"")?.  @as
< 00000960: 7365 7274 696f 6e2e 6173 7365 7274 5f65  sertion.assert_e
< 00000970: 7128 7265 7072 2822 5c6e 2229 2c20 225c  q(repr("\n"), "\
< 00000980: 225c 5c6e 5c22 2229 3f0a 2020 4061 7373  "\\n\"")?.  @ass
< 00000990: 6572 7469 6f6e 2e61 7373 6572 745f 6571  ertion.assert_eq
< 000009a0: 2872 6570 7228 225c 7222 292c 2022 5c22  (repr("\r"), "\"
< 000009b0: 5c5c 725c 2222 293f 0a20 2040 6173 7365  \\r\"")?.  @asse
< 000009c0: 7274 696f 6e2e 6173 7365 7274 5f65 7128  rtion.assert_eq(
< 000009d0: 7265 7072 2822 5c62 2229 2c20 225c 225c  repr("\b"), "\"\
< 000009e0: 5c62 5c22 2229 3f0a 2020 4061 7373 6572  \b\"")?.  @asser
< 000009f0: 7469 6f6e 2e61 7373 6572 745f 6571 2872  tion.assert_eq(r
< 00000a00: 6570 7228 225c 7422 292c 2022 5c22 5c5c  epr("\t"), "\"\\
< 00000a10: 745c 2222 293f 0a20 2040 6173 7365 7274  t\"")?.  @assert
< 00000a20: 696f 6e2e 6173 7365 7274 5f65 7128 7265  ion.assert_eq(re
< 00000a30: 7072 2822 0022 292c 2022 5c22 5c5c 7830  pr("."), "\"\\x0
< 00000a40: 305c 2222 293f 0a20 2040 6173 7365 7274  0\"")?.  @assert
< 00000a50: 696f 6e2e 6173 7365 7274 5f65 7128 7265  ion.assert_eq(re
< 00000a60: 7072 2822 6162 6327 5c22 6465 665c 5c22  pr("abc'\"def\\"
< 00000a70: 292c 2022 5c22 6162 6327 5c5c 5c22 6465  ), "\"abc'\\\"de
< 00000a80: 665c 5c5c 5c5c 2222 293f 0a7d 0a0a 2f2f  f\\\\\"")?.}..//
< 00000a90: 2074 6573 7420 6865 7265 2074 6f20 6176   test here to av
< 00000aa0: 6c69 6420 6379 636c 6963 2064 6570 656e  lid cyclic depen
< 00000ab0: 6465 6e63 7920 6265 7477 6565 6e20 6173  dency between as
< 00000ac0: 7365 7274 696f 6e20 616e 6420 6275 696c  sertion and buil
< 00000ad0: 7469 6e0a 7465 7374 2022 4275 6666 6572  tin.test "Buffer
< 00000ae0: 3a3a 746f 5f62 7974 6573 2220 7b0a 2020  ::to_bytes" {.
< 00000af0: 6c65 7420 6275 6666 6572 203d 2042 7566  let buffer = Buf
< 00000b00: 6665 723a 3a6d 616b 6528 3136 290a 2020  fer::make(16).
< 00000b10: 6275 6666 6572 2e77 7269 7465 5f73 7472  buffer.write_str
< 00000b20: 696e 6728 22e4 b8ad e696 8722 290a 2020  ing("......").
< 00000b30: 4061 7373 6572 7469 6f6e 2e61 7373 6572  @assertion.asser
< 00000b40: 745f 6571 2862 7566 6665 722e 746f 5f62  t_eq(buffer.to_b
< 00000b50: 7974 6573 2829 2e74 6f5f 7374 7269 6e67  ytes().to_string
< 00000b60: 2829 2c20 22e4 b8ad e696 8722 293f 0a7d  (), "......")?.}
< 00000b70: 0a                                       .
---
> 000008a0: 7d0a 2020 4061 7373 6572 7469 6f6e 2e61  }.  @assertion.a
> 000008b0: 7373 6572 745f 6571 2872 6570 7228 2261  ssert_eq(repr("a
> 000008c0: 2229 2c20 225c 2261 5c22 2229 3f0a 2020  "), "\"a\"")?.
> 000008d0: 4061 7373 6572 7469 6f6e 2e61 7373 6572  @assertion.asser
> 000008e0: 745f 6571 2872 6570 7228 2227 2229 2c20  t_eq(repr("'"),
> 000008f0: 225c 2227 5c22 2229 3f0a 2020 4061 7373  "\"'\"")?.  @ass
> 00000900: 6572 7469 6f6e 2e61 7373 6572 745f 6571  ertion.assert_eq
> 00000910: 2872 6570 7228 225c 2222 292c 2022 5c22  (repr("\""), "\"
> 00000920: 5c5c 5c22 5c22 2229 3f0a 2020 4061 7373  \\\"\"")?.  @ass
> 00000930: 6572 7469 6f6e 2e61 7373 6572 745f 6571  ertion.assert_eq
> 00000940: 2872 6570 7228 225c 5c22 292c 2022 5c22  (repr("\\"), "\"
> 00000950: 5c5c 5c5c 5c22 2229 3f0a 2020 4061 7373  \\\\\"")?.  @ass
> 00000960: 6572 7469 6f6e 2e61 7373 6572 745f 6571  ertion.assert_eq
> 00000970: 2872 6570 7228 225c 6e22 292c 2022 5c22  (repr("\n"), "\"
> 00000980: 5c5c 6e5c 2222 293f 0a20 2040 6173 7365  \\n\"")?.  @asse
> 00000990: 7274 696f 6e2e 6173 7365 7274 5f65 7128  rtion.assert_eq(
> 000009a0: 7265 7072 2822 5c72 2229 2c20 225c 225c  repr("\r"), "\"\
> 000009b0: 5c72 5c22 2229 3f0a 2020 4061 7373 6572  \r\"")?.  @asser
> 000009c0: 7469 6f6e 2e61 7373 6572 745f 6571 2872  tion.assert_eq(r
> 000009d0: 6570 7228 225c 6222 292c 2022 5c22 5c5c  epr("\b"), "\"\\
> 000009e0: 625c 2222 293f 0a20 2040 6173 7365 7274  b\"")?.  @assert
> 000009f0: 696f 6e2e 6173 7365 7274 5f65 7128 7265  ion.assert_eq(re
> 00000a00: 7072 2822 5c74 2229 2c20 225c 225c 5c74  pr("\t"), "\"\\t
> 00000a10: 5c22 2229 3f0a 2020 4061 7373 6572 7469  \"")?.  @asserti
> 00000a20: 6f6e 2e61 7373 6572 745f 6571 2872 6570  on.assert_eq(rep
> 00000a30: 7228 225c 7830 3022 292c 2022 5c22 5c5c  r("\x00"), "\"\\
> 00000a40: 7830 305c 2222 293f 0a20 2040 6173 7365  x00\"")?.  @asse
> 00000a50: 7274 696f 6e2e 6173 7365 7274 5f65 7128  rtion.assert_eq(
> 00000a60: 7265 7072 2822 6162 6327 5c22 6465 665c  repr("abc'\"def\
> 00000a70: 5c22 292c 2022 5c22 6162 6327 5c5c 5c22  \"), "\"abc'\\\"
> 00000a80: 6465 665c 5c5c 5c5c 2222 293f 0a7d 0a0a  def\\\\\"")?.}..
> 00000a90: 2f2f 2074 6573 7420 6865 7265 2074 6f20  // test here to
> 00000aa0: 6176 6c69 6420 6379 636c 6963 2064 6570  avlid cyclic dep
> 00000ab0: 656e 6465 6e63 7920 6265 7477 6565 6e20  endency between
> 00000ac0: 6173 7365 7274 696f 6e20 616e 6420 6275  assertion and bu
> 00000ad0: 696c 7469 6e0a 7465 7374 2022 4275 6666  iltin.test "Buff
> 00000ae0: 6572 3a3a 746f 5f62 7974 6573 2220 7b0a  er::to_bytes" {.
> 00000af0: 2020 6c65 7420 6275 6666 6572 203d 2042    let buffer = B
> 00000b00: 7566 6665 723a 3a6d 616b 6528 3136 290a  uffer::make(16).
> 00000b10: 2020 6275 6666 6572 2e77 7269 7465 5f73    buffer.write_s
> 00000b20: 7472 696e 6728 22e4 b8ad e696 8722 290a  tring("......").
> 00000b30: 2020 4061 7373 6572 7469 6f6e 2e61 7373    @assertion.ass
> 00000b40: 6572 745f 6571 2862 7566 6665 722e 746f  ert_eq(buffer.to
> 00000b50: 5f62 7974 6573 2829 2e74 6f5f 7374 7269  _bytes().to_stri
> 00000b60: 6e67 2829 2c20 22e4 b8ad e696 8722 293f  ng(), "......")?
> 00000b70: 0a7d

Before:
bc1570f628238b40d9a39587e3fd0fbd
After:
7fb20e12785ba0d28c07e0b782502f92

Proposal: replace the naive quick sort for vec with sort for array

In this pr #72 , author implemented an optimized quick sort algorithm like the std:sort in C++

But for vec, it already has a naive quick sort implementation

core/vec/vec.mbt

Lines 619 to 639 in bcb5d5c

/// Quicksort helper
fn quicksort[T : Compare](self : Vec[T], left : Int, right : Int) -> Unit {
if left <= right {
let idx = self.partition(0, right)
self.quicksort(left, idx - 1)
self.quicksort(idx + 1, right)
}
}
/// Sort the vector in place.
///
/// This implementation uses the quicksort algorithm.
///
/// # Example
/// ```
/// let v = Vec::[3, 4, 5, 1, 2]
/// v.sort()
/// ```
pub fn sort[T : Compare](self : Vec[T]) -> Unit {
self.quicksort(0, self.len - 1)
}

I think we can replace the vec sort with directly using the sort impl from array module, not implementing it twice.

support cross package renaming in a project

instead of just local package renaming, we should try to support cross package renaming,
e.g, change @pkg.a -> @pkg.b a inside package is renamed into b while @pkg.a outside is also renamed into @pkg.b

compile false alarm warning

fn op_equal[T : Eq](self : Cell[T], other : Cell[T]) -> Bool {
  loop self, other {
    Nil, Nil => true
    Cons({ content: x, next: xs }), Cons({ content: y, next: ys }) =>
       x == y &&
        continue xs, ys
      
    _, _ => false
  }
}

Warning 018: There is no [continue] in this loop expression, so [loop] is useless here.

Add utility functions for char

We may need some utility functions for char such as

  • get high surrogate of a char
  • get low surrogate of a char
  • check if a char is a surrogate unit

No error message when trying to access the negative index of a vec

core/vec/vec.mbt

Lines 119 to 123 in 4b67410

pub fn op_get[T](self : Vec[T], index : Int) -> T {
if index >= self.len {
let len = self.len
abort("index out of bounds: the len is \(len) but the index is \(index)")
}

test "op_set" {
  let v = Vec::new()
  v[3] = 4
}

// > moon test
// index out of bounds: the len is 0 but the index is 3
test "op_set" {
  let v = Vec::new()
  v[-1] = 2
}

// > moon test
// error while executing at wasm backtrace:

support uint64 and uint32 natively

it seems the effort is small, we only add some intrinsics to support them,
the performance of handwritten one is not as good as we expect

add ci badge

[![check](https://github.com/moonbitlang/core/actions/workflows/check.yml/badge.svg)](https://github.com/moonbitlang/core/actions/workflows/check.yml)

Support custom sorting rules

For users who want to use custom sorting rules, or sort a type that doesn't implement Compare (e.g., tuple (Int, Int)) the default sort() is not sufficient.

Formatter adds unexpected ending comma

Before

struct A {
  body : String
  abc : Int
}

fn foo() -> A {
  let a0 = { body: "hello", abc: 1 }
  { ..a0 }
}

After

struct A {
  body : String
  abc : Int
}

fn foo() -> A {
  let a0 = { body: "hello", abc: 1 }
  { ..a0,  }
}

Proposal: A New Type for Unicode Scalar Value

Char is one byte and may not be a valid Unicode scalar value. The new type (maybe we can call it Rune like Go) is 32bit and stands for a valid Unicode scalar value.

  • It can make converting a String to/from a UTF-16/UTF-32 easier
  • It makes the interactions between js strings easier. For example, if you emit a string-related event from Moonbit to js, the length and index inside the event need to be converted from UTF-8 to UTF-16
  • It makes handling tasks like moving a cursor on a string easier, which should not be based on UTF-8 index

Question about array out-of-bound checking

Hi all,

I added the + 1 to the function Array::iter to trigger the out-of-bound error. But all the tests passed locally (x86 & Linux). Whether the compiler do such check? Or is it a bug?

 /// @intrinsic %array.iter
 pub fn iter[T](self : Array[T], f : (T) -> Unit) -> Unit {
-  for i = 0; i < self.length(); i = i + 1 {
+  for i = 0; i < self.length() + 1; i = i + 1 {
     f(self[i])
   }
 }

Best Regards,
-- Guoxiong

Proposal: Early exit protocol for Collection::iter

Since we do not support pull based iterator for now, and we have no exception mechanism. I think it's better to make iter ability to early exit.

enum IterAction {
  Break
  Continue
}

fn iter[T](self: Array[T], f: (T) -> IterAction) -> Unit {
  for i = 0; i < self.length(); i = i + 1 {
    match f(self[i]) {
      Break => break
      Continue => ()
    }
  }
}
fn for_each[T](self: Array[T], f: (T) -> Unit) -> Unit {
  self.iter(fn(it) { f(it); Continue })
}

Deque: bad reads after realloc/wrap

After the deque wraps around, the reads seem broken:

  let dq = Deque::[1, 2, 3, 4, 5]
  @assertion.assert_eq(dq.pop_front(), Some(1))?
  @assertion.assert_eq(dq.pop_front(), Some(2))?
  @assertion.assert_eq(dq.pop_front(), Some(3))?
  dq.push_back(6)
  dq.push_back(7)
  let result = Array::make(4, 0)
  let mut i = 0
  dq.iter(fn(x) { 
    result[i] = x
    i += 1
  })
  @assertion.assert_eq(result, [4, 5, 6, 7])?
FAILED: `[4, 5, 7, 7] == [4, 5, 6, 7]`

error: cannot add `moonbitlang/core` as dependency

Tried to add the core library, but I receive a generic error. Not sure what to try. This is with the latest stable release of moon CLI.

image
$ moon add moonbitlang/core 

error: cannot add `moonbitlang/core` as dependency

Using a blank project created by moon new

TODO list

  • add as_iter for each data structure
  • coverage > 95%
  • map
  • set
  • hashmap
  • hashset
  • efficient hash function for built in type
  • json
  • json5
    // this may be a good example to showcase moonbit's perf over handwritten js
  • mutable map // mutable map
  • mutable set
  • array missing method
    • sort
    • stable sort
  • README.md for each package
  • random
  • strconv
  • move most builtin utilities to its belonged package
    • float ryu
    • buffer
  • rational
  • bigint
  • persistent vector

An Apache project?

Being an Apache project is obviously different than just adopting the Apache open-source license.

At the beginning of each source file in this repository, I'm reading:

// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.

Does that mean the MoonBit standard library is or will be an Apache project? Or this is simply a copy-paste mistake and - according to the ICLA - should really be like:

Copyright 2024 International Digital Economy Academy

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

add `moon test --target js` to CI


test moonbitlang/core/assertion/assertion.mbt::assert_is.is.not failed: FAILED:/Users/hongbozhang/git/core/assertion/assertion.mbt:154:3-154:39 `Ok(()) != Ok(())`
test moonbitlang/core/assertion/assertion.mbt::assert_is_not.is.not failed: FAILED:/Users/hongbozhang/git/core/assertion/assertion.mbt:197:3-197:43 `Err("FAILED:/Users/hongbozhang/git/core/assertion/assertion.mbt:197:13-197:34 `not(\"x:1\" is \"x:1\")`") == Ok(())`






/Users/hongbozhang/git/core/target/js/release/test/double/double.internal_test.js:705
  const $42$bind = moonbitlang$core$builtin$$inspect({ $42$label0: moonbitlang$core$double$$Double$to_string(0), $42$label1: $$to_string$7$ }, "0.0", "/Users/hongbozhang/git/core/double/ryu.mbt:663:3-663:43", [new Option$Some$8$("/Users/hongbozhang/git/core/double/ryu.mbt:663:11-663:26"), new Option$Some$8$("/Users/hongbozhang/git/core/double/ryu.mbt:663:37-663:42"), Option$None$8$, Option$None$8$]);
                                                                   ^

ReferenceError: moonbitlang$core$double$$Double$to_string is not defined
    at moonbitlang$core$double$$__test_7279752e6d6274_0 (/Users/hongbozhang/git/core/target/js/release/test/double/double.internal_test.js:705:68)
    at /Users/hongbozhang/git/core/target/js/release/test/double/double.internal_test.js:801:22
    at Object.<anonymous> (/Users/hongbozhang/git/core/target/js/release/test/double/double.internal_test.js:830:2)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
    at node:internal/main/run_main_module:28:49

Node.js v20.10.0
Error when running /Users/hongbozhang/git/core/target/js/release/test/double/double.internal_test.js: Failed to run the test







/Users/hongbozhang/git/core/target/js/release/test/math/math.internal_test.js:18
  throw new Error(a);
  ^

Error: called `Result::unwrap()` on an `Err` value
    at $raise (/Users/hongbozhang/git/core/target/js/release/test/math/math.internal_test.js:18:9)
    at moonbitlang$core$result$$Result$unwrap$0$ (/Users/hongbozhang/git/core/target/js/release/test/math/math.internal_test.js:108:7)
    at moonbitlang$core$math$$__test_616c676562726169632e6d6274_1 (/Users/hongbozhang/git/core/target/js/release/test/math/math.internal_test.js:471:3)
    at /Users/hongbozhang/git/core/target/js/release/test/math/math.internal_test.js:704:22
    at Object.<anonymous> (/Users/hongbozhang/git/core/target/js/release/test/math/math.internal_test.js:733:2)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)

Node.js v20.10.0
Error when running /Users/hongbozhang/git/core/target/js/release/test/math/math.internal_test.js: Failed to run the test









test moonbitlang/core/strconv/traits.mbt::parse_int64_base failed: FAILED:/Users/hongbozhang/git/core/strconv/int.mbt:364:5-364:59 `Ok(-9223372036854775808) == Ok(9223372036854775808)`




Total tests: 364, passed: 361, failed: 3.

Coverage test action cannot add result comment to the corresponding PR

Permission settings caused the coverage test action added in #155 being unable to comment the result in the corresponding PR. The token issued from the action is readonly, although the action requested write permissions to PRs.

Possibly related documentation: https://docs.github.com/en/actions/security-guides/automatic-token-authentication#how-the-permissions-are-calculated-for-a-workflow-job

Finally, if the workflow was triggered by a pull request from a forked repository, and the Send write tokens to workflows from pull requests setting is not selected, the permissions are adjusted to change any write permissions to read only.

Unfortunately, I can't find the highlighted setting in the settings page when looking for it in my repository, so I have no idea how to turn it on.

cc @bobzhang

clean up the design of Char

Char is a unicode code point in MoonBit, it is encoding agnostics, it is not tied to utf16, so we should not provide APIs like this:

fn Char::is_surrogate(Char) -> Bool

We should provide String.as_iter which returns Iter[Char]

“A😊𠮷B"
   .as_iter()
   .reduce(init=Vec::[], fn {acc, x -> acc.push(x)})
// expected output
[65, 128522, 134071, 66]

cc @yj-qin

Proposal: rename `assertion` to `test`

Motivations

  • assert_*() no longer panics, returning a test-specific Result[Unit, String] now.

    I remember the @assertion package was added to the stdlib before tests were switched to return Results. This indicates the assert_*() functions are not "assertions" that don't get in the way of non-test user code. Now the users have to handle the Results properly in production code, especially to deal with the String errors.

    With that said, a "proper" assertion would have to be like:

    @assertion.assert_eq(1, 1).unwrap()
    

    However, this explicitness of unwrap() defeats the idea of calling the package @assertion.

  • There is no way to turn off assertions.

    This is debatable - Java and Python provide options to turn off assertions at runtime, C/C++ could use some macro tricks, and Rust disallows turning off std::assert calls but provides std::debug_assert that is excluded in release builds. The @assertion package in MoonBit looks more like a testing library to me, especially since it covers eq, ne, true, false, and likely more to add.

    In addition, we could borrow debug_assert from Rust that 1) panics if evaluated false, 2) is excluded from release builds, 3) does not live in the @assertion (or @test) package, and 4) has no siblings like eq, ne and so on.

  • @assertion.assert... is redundant to type.

    Typing @test.assert_eq() feels much more natural than repeating the "assert" word twice.

Strange formatting behavior

When formatting the code, the formatter removes parentheses, but the comment was wrongly put outside the scope

Before

fn foo() -> Int {
  (233)
  // Comment
}

After

fn foo() -> Int {
  233
}
// Comment

Proposal: integrate benchmark utils

Currently, there is no easy way to get the timestamp. Users inevitably need to interact with FFI to benchmark a module, which is not ideal.

HashEq does not imply Hash+Eq or vice versa

suppose we have a trait

pub trait HashEq : Hash + Eq {}

now I have a function

pub fn set[K : HashEq, V](self : HashMap[K, V], key : K, value : V) -> Unit
pub fn op_set[K : Hash + Eq, V](
  self : HashMap[K, V],
  key : K,
  value : V
) -> Unit {
  self.set(key, value) // type error
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.