1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/changelogs0.x/0.4.md

419 lines
21 KiB
Markdown
Raw Normal View History

2023-07-01 13:47:57 +03:00
## V 0.4
*1 July 2023*
2023-07-01 14:00:16 +03:00
#### Improvements in the language
2023-07-01 13:47:57 +03:00
- **Coroutines with a scheduler**. Only Linux/macOS for now, requires `-use-coroutines` and
`coroutines.sleep()` instead of `time.sleep()`. They work with IO and net, but not with GC
for now.
- `spawn` now spawns system threads, `go` spawns coroutines.
- Static type methods: `Foo.new()` to replace factory functions like `new_foo()`.
- Smartcasting with complex conditions:
`if sum_type is Foo && !sum_type.is_info && get_name(sum_type.info.name) == 'foo' `.
2023-07-01 13:47:57 +03:00
- Functions can now return fixed size arrays.
- Enum values now can have attributes.
- Generic functions as function parameters are now supported: `fn f[T](x T, i int, f_ Fn[T]) T { `.
- Anonymous structs can no longer have attributes.
- A new `[spawn_stack: 131072]` function attribute for controlling the max size of the stack
of the spawned threads.
2023-07-01 13:47:57 +03:00
- Channel pop now works with an `or` block: `ch := <-self.item or { return none }`
- `it` has been renamed to `index` in array inits.
- String interpolation simplified to just '${name}', enforced by vfmt,
and updated in the entire code base.
2023-07-01 13:47:57 +03:00
- `go foo()` has been replaced with `spawn foo()` (launches an OS thread, `go` will be used for
upcoming coroutines instead).
- vfmt now supports `// vfmt off` and `// vfmt on` for turning off the formatting locally
for short snippets of code.
2023-07-01 13:47:57 +03:00
Useful for keeping your carefully arranged matrices intact.
- Match branch range expressions with consts: `match x { const1...const2 {} }`
- Hot code reloading via `[live]` is now supported in imported modules, not just the main module.
- Syntax sugar for map inits without needing explicit casts for interfaces:
`all.children := { "abc": rect, "def": ui.rectangle()}`.
2023-07-01 13:47:57 +03:00
- `$embed_file()` fixes, including variable args support.
- `none` fixes: no longer allowed to be used as a separate type, `dump()` support,
not allowed inside `unsafe`.
2023-07-01 13:47:57 +03:00
- Const functions: `const y = term.yellow`, then `println(y('abc'))`.
- Builtin type names can no longer be used as identifiers.
- Generic `typeof[T]()`, `sizeof[T]()`, `isreftype[T]()` functions.
- Deprecated `-error-limit` in favour of the documented `-message-limit` option.
- Maps now support aliased keys.
- Operator overloading now works with reference types.
- Generic struct inits with nested generic structs and generic optional types are now allowed.
- During array creation, `len:` is required when using default values for the array.
- Optimized one byte `[]u8` arrays creation.
- Recursive aliasing is no longer allowed (e.g. `type Alias = map[string]Alias`).
- Easier custom error creation: `return MyCustomErr{}` instead of `return IError(MyCustomErr)`.
- All floats outputs now have `.0` conditionally appended to them to improve clarity.
- Custom integer enum types: `enum Xyz as u64 {`.
- AST transformer fixes and optimizations.
- Stylistic improvements and bug fixes in vfmt.
- Casting integers to enums now requires `unsafe{}`.
- Improved error and warning messages.
- Parallel compilation now uses `sync.Pool`.
- `-skip-unused` fixes, soon to be made the default.
- Anonymous structs.
- Lots of bug fixes: 90% of all bugs ever submitted are closed.
- New keyword/type: `nil`. Only to be used inside `unsafe`. Replaces `voidptr(0)`.
- V can now find code in the `src/` directory. This allows making V repos much cleaner.
- Support `assert condition, extra_message`, where the `extra_message` will be evaluated
and shown if the assertion fails.
2023-07-01 13:47:57 +03:00
- Operator overloading now works with aliases and generics.
- Scanner optimizations.
- Using C's #define is no longer allowed in normal V code, only in `.c.v` files.
2023-07-01 14:00:16 +03:00
#### Breaking changes
2023-07-01 13:47:57 +03:00
- `byte` deprecated in favor of `u8` (`byte` is automatically converted to `u8` by vfmt).
- `json`: enums are serialized as strings by default, `[json_as_number]` attribute can be used for
the old behavior.
- Variable shadowing has been completely banned (previously variable names could conflict with
module names).
- `[]` is now used for generics instead of `<>`.
- Accessing a pointer map value requires an `or {}` block outside `unsafe`.
- Anonymous sumtypes have been removed (deprecated for now) due to complicating the language
and the compiler too much.
2023-07-01 13:47:57 +03:00
2023-07-01 14:00:16 +03:00
#### Checker improvements/fixes
2023-07-01 13:47:57 +03:00
- Disallow `Result` type aliases (`type Foo = !Bar`) and `Result` in maps (`map[key]!Type`).
- Add a missing check for taking address of literal value member.
- Fixed map initialization for maps with option values.
- Allow `a << none`, where `a` is `[]?&int`.
- Disallow multiple `else` branches in a match.
- Fix index expression with sumtype of array types.
- Remove hardcoded check for function calls for `C.stat`, `C.sigaction`, etc.
- Fix multiple embedded external module interface.
- Fix missing check for diff type on map value declaration.
- Simplify error handling in the checker (#18507).
- Option alias fixes.
- Fix alias to struct ptr on struct init.
- Sumtypes can no longer hold references.
- Fix a bug checking generic closures.
- A hard to reach limit of 1 million iterations for resolving all generics.
- Fix missing check for unwrapped shift operation.
- Fix enum max value validation.
- Add a missing mutability check for `array.delete` calls.
- Disallow `_ = <- quit`.
- Disallow type matching with primitive vars.
- Warning instead of error for unnecessary brackets in if/match.
- Include import aliases when checking for import duplicates.
- Fix infering generic array type in nested call.
- Allow casted `enum val` and `const` as fixed array size.
- Disallow multiple return values in const declarations.
- Fix contains() with array of interfaces.
- Disallow mut for blank idents.
- If guards now work with struct fields which are `Option` functions.
Such fields can now also be assigned to other fields/variables.
- Option receivers can no longer have methods.
- `none` can now be cast to all `Option` types, including aliases.
- Option references are now supported: `?&Type`.
- Arrays of `Option`s are now allowed.
- Allow `foo := Foo{}`, when `Foo` has an Option field, that is a struct, that has a `[required]`
tag on its fields.
- Enums can no longer be initialized like structs.
- Capture variables can no longer shadow anonymous function params.
- Mixing multi-return results with other types in return statements is no longer allowed.
- Assigning anonymous structs to named structs is no longer allowed.
- `[required]` fields are now checked for embedded structs.
- Fixed a bug with closures with fixed array variables.
- Builtin methods `first/last/repeat` can now be used in custom user types (previously they only
worked in builtin arrays).
- Generic struct initialization no longer needs explicit types to be provided:
```v
struct Foo[T, U] {
a T
b U
}
foo := Foo{
a: 2
b: 'x'
}
println(foo)
```
- unsafe: dereferencing nil references is no longer allowed in the following case:
```v
a := unsafe { nil }
println(*a)
```
- Lots of fixes in the type checker.
- Int signedness mismatch is now checked: `cannot use literal signed integer as u8`.
- Improved type checker: lots of new type checks and fixed checker bugs.
- Unused last expression in `if` is now checked.
- Anonymous structs visibility issues fixed.
- More type checks.
- Lots of fixes in `shared` types.
2023-07-01 14:00:16 +03:00
#### Standard library
2023-07-01 13:47:57 +03:00
- json: Enum value string serialization supports `[json:'alias']` to change its string values.
- Struct fields can now be skipped during JSON/ORM serialization via `[json:'-']` and `[sql:'-']`,
in addition to `[skip]`. This allows having custom behavior for different serialization methods.
- builtin: heap usage API (gc_memory_use() and gc_heap_usage())
- math.big: refactoring, gcd fixes/improvements, overflow fixes, `mod_inverse`.
- flag: fix finalize with multiple shortargs.
- runtime: add new functions total_memory/0 and free_memory/0.
- time: small cleanup of parse_iso8601 comments, make the C.strftime declaration forwards compatible
- stbi: allow customization of number of channels in `stbi.load()`.
- stbi: add a `resize_uint8` function for resizing images in memory.
- time, x.json2: improve iso8601 time decoding.
- builtin: zero out internal map/array pointers on m.free(), to reduce the work for the GC
mark phase for non escaping maps/arrays, used in hot loops.
- time: add more detailed error descriptions, add custom format parsing with time.parse_format.
- sync: add Mutex.destroy and RwMutex.destroy methods.
- datatypes: add Bloom filter.
- rand: add missing rand.u16(), update doc comments, add test.
- builtin: speed up string methods with vmemcpy instead of `for` loop for copying data.
- Added new `termios` module.
- `net.ssl`: types using ssl contexts can now be converted to strings via `.str()`/printed
via `println()`.
- `v.reflection`: added type symbol info metadata.
- `crypto` and `math` modules have been updated to use `Result` instead of `Option`.
- `datatypes.LinkedList[map]` now works correctly.
- `urllib.Values.get()` now returns an Option.
- `strconv`: `v_printf()` was made private, `v_sprintf()` was deprecated. String interpolation
should be used instead.
- `net.http`: mime types have been updated to include all official types.
- `gg`: `create_image()` now returns `!Image` instead of `Image`, allowing to handle errors.
- `sokol`: errors during image creation no longer result in a panic, but can be handled by the
programmer.
- `sokol`: macOS apps can now be quit using **Cmd+Q**.
- `os.hostname()` and `os.loginname()` now return `Result`.
- `strconv.atoi` optimizations.
- `println()` now supports arrays with recursive references.
- `termux`: support for cross-compilation from termux to other platforms.
- `readline` module now works much better on macOS: key navigation, history, etc (now on par with
Linux).
- `os`: fixed a memleak in `getline()`.
- `os.Process` now has a `create_no_window` option (Windows only).
- `os.Process` now has a `set_work_folder()` method to set the initial working folder of the new
child process.
- `math.vec` module for generic vector math including 2D, 3D, and 4D vector operations.
- Builtin stb_image.h used by gg has been updated to the latest v2.28.
- All of vlib has been updated to use separate Option/Result types.
- To avoid confusion, all references in the code and documentation to `Optional` have been
replaced with `Option`.
2023-07-01 13:47:57 +03:00
- `gg.Context` pipeline has more effects, including the `additive` effect.
- Much cleaner eof checks in `os`: refactor `err == IError(os.Eof{})` to `err is os.Eof`.
- Lots of work on `x.json2`, the pure V json encoder, soon to become official.
- New `v.reflection` module for runtime reflection.
- Improved `os.mv()`, which now works consistently even across different
windows drives/mount points.
- `string.trim_indent()`, useful with multi line strings, that start/end with new lines
and indentation.
2023-07-01 13:47:57 +03:00
- Reduced memory consumption in the `crypto` modules.
- Official V UI library is now licensed under MIT.
- Deprecated `math.util` and `math.mathutil` have been removed.
- New time format support: `time.format_rfc3339()`.
- `encoding.html.escape()`.
- All public functions in the `hash` and `encoding.base32` modules have been documented.
- New `crypto.pem` module.
- New `map.reserve()` method.
- `net.ssl` has been migrated from a dynamically linked OpenSSL to a statically linked Mbed TLS.
This means that V binaries will no longer have an OpenSSL dependency.
OpenSSL can still be enabled via `-d use_openssl`.
2023-07-01 13:47:57 +03:00
- msgpack module for decoding/encoding msgpack. (`v install msgpack`)
- Most of vlib has been updated to use the new Option/Result types.
- net, net.http, vweb bugs and fixes.
- QuadTree and RingBuffer types in `datatypes`.
- Forward iterator for `datatypes.LinkedList<T>`, forward and backward iterators
for `datatypes.DoublyLinkedList<T>`.
- A new `maps` module, similar to existing `arrays`. It has generic `filter`, `flatten`,
`invert`, `to_map`, `to_array`, `from_array` functions.
2023-07-01 13:47:57 +03:00
- `utf8.is_number()`, `utf8.is_space()` functions.
- New `encoding.base32` module.
- `gg.TouchPoint` to differentiate between different types of touch input.
- `str.int()` conversion speedup (without -prod).
- `os.mkdir()` now has an optional `mode` parameter.
- `encoding.csv` is now generic, supports bools, accepts a custom delimiter,
and is compatible with io.Reader/io.Writer.
2023-07-01 13:47:57 +03:00
- `datatypes` module now uses operator overloading.
- All `datatypes` types can be converted to V arrays.
- `smtp` improvements including multiple recipients and base64/utf8 support.
- `arrays.carray_to_varray<T>()` for converting C arrays to V arrays.
- `strconv.v_sprintf()` has been deprecated in favor of string interpolation.
- TOML module now supports `[toml:...]` attributes, just like the JSON module.
- `os.walk()` is no longer recursive (still works the same).
- `io` has been migrated to `Result`.
- Third party window control in Sokol.
- `string.replace_char()`, `math.round_sig()`.
- Improved multiplication performance in `math.big`.
2023-07-01 14:00:16 +03:00
#### Web
2023-07-01 13:47:57 +03:00
- The builtin websocket library is now thread safe.
- Enhanced builtin csrf protection in vweb.
- vweb: ability to set and get values on vweb.Context.
- vweb: support for host specific static files.
- vweb: host option added to controller, and a new host attribute.
- vweb: middleware docs improved; same with docs for `[vweb_global]` and `shared`.
- vweb: return 404 on file not found.
- net.http: copy IANA's list of methods to the http.Method enum.
- net.conv: use a pure V implementation instead of C.hton etc.
- net.html: `get_tag()` methods to find first tag occurrence.
- net.html: fixed text parsing for inline tags.
- net.html: fix parsing of nested quoted strings in code tags.
- picoev: FreeBSD support.
- vweb now supports live page reloading.
The web app is instantly updated in the browser (no need to refresh the page)
every time a **.v** or a **.html** file is changed.
- vweb is now significantly faster and more stable under load, due to a new multithreaded worker
pool, which is much more efficient at spreading the workload among all threads equally.
- vweb now supports middleware.
- vweb now supports controllers.
It's now possible to have multiple app structs to better separate logic.
- vweb now supports overridable `.not_found()` method for custom 404 pages in vweb.
- vweb now uses database pool.
- Fixed multipart form parsing in vweb.
- Improved vweb stability under load.
- `vweb.csrf` module.
- `net.urllib` ipv6 support.
- `net.Http.Response.text` renamed to `body`.
- `net.websocket` timeout is now configurable.
2023-07-01 14:00:16 +03:00
#### ORM
2023-07-01 13:47:57 +03:00
- Fixed a foreign key bug that could result in an extra insert.
- Comptime bug with `[skip]` and `[sql:'-']` fixed.
- Checker error for unsupported field types.
- Allow structs without the id field, more flexible primary keys.
- Improved docs and examples.
- Uninitialized structs are no longer inserted into related tables.
- All ORM queries now return `![]` (`Result` of an array).
This allows handling/propagating DB errors and simplifies working with ORM (one way).
- Many ORM improvements: type checks for `limit/offset/order by/where`; support of reference objects
in `insert`; struct fields can be used with `limit/offset`; `Connection` interface.
- ORM now supports the `like` operator:
```v
users := sql db {
select from User where name like 'Bob%'
}
```
- A new `-d trace_orm` option to see all SQL queries generated and used by V ORM and
`-d trace_pg_error` to trace PG errors.
- Various ORM fixes and improvements, including string interpolation support, type checks,
fn calls in `where`.
- Support parenthesized expressions like
`select from User where (name == 'Sam' && is_customer == true) || id == 1`.
2023-07-01 13:47:57 +03:00
- ORM functions now return `Result`, so the errors can be handled.
2023-07-01 14:00:16 +03:00
#### Database drivers
2023-07-01 13:47:57 +03:00
- mysql: TIMESTAMP support.
- mysql: allocate memory for each string and blob dynamically depending on its value length.
- mysql: add the ability to commit transactions.
- VFS support in the builtin `sqlite` module; `sqlite.get_affected_rows_count()`.
- Improved `pg` compatibility with older PostgreSQL versions before 2014.
- `sqlite`, `pg`, `mysql` have been moved to `db.sqlite`, `db.pg`, `db.mysql`.
2023-07-01 14:00:16 +03:00
#### Native backend
2023-07-01 13:47:57 +03:00
- Refactoring, splitting large files into multiple.
- Lots of fixes and new features in the native backend, including making codegen logic
platform independent.
2023-07-01 13:47:57 +03:00
- Operator support for floats, multi return.
- Lots of native backend improvements, including library calls, comptime conditionals,
enums, method definitions/calls, structs.
- Major improvements to the fast native backend including linking support on Linux.
The goal is to be able to self host V soon.
2023-07-01 13:47:57 +03:00
2023-07-01 14:00:16 +03:00
#### V interpreter
2023-07-01 13:47:57 +03:00
- Some further interpreter work.
2023-07-01 14:00:16 +03:00
#### C backend
2023-07-01 13:47:57 +03:00
- Fix code generation for generic unions.
- Fix `[N]chan` (fixed arrays of channels).
- Fix nested fixed array instantiation.
- Fix fixed array of map.
- Fix stringification of usize struct fields (before, they were treated as 32 bit *signed* numbers).
- Now code generated by the С backend, can be compiled by a C++20 compiler.
- C backend does not generate unused interface functions now.
- Parallelized cc step. Speeds up -prod and clang/gcc compilation by 300-500% (depending on
the number of cores). Experimental and hidden behind a -parallel-cc flag, soon to be the default.
- Intel C compiler support.
- Go backend fixes.
- `#preinclude` for low level C interop.
2023-07-01 14:00:16 +03:00
#### WASM backend
- A new pure WASM backend, based on binaryen, a WASM `builtin` module, and a pure V WASM
serialization library.
2023-07-01 13:47:57 +03:00
2023-07-01 14:00:16 +03:00
#### Comptime
2023-07-01 13:47:57 +03:00
- A new `$res` comptime function to get returned value in defer block (#18382).
- Fix comptimeselector option propagation.
- A mutability check for comptime assignments.
- Fix comptime assigning to sumtype or indexexpr.
- Make comptime calls work with or-block.
- Compile-time interface fields evaluation.
- Compile-time enum evaluation:
```v
$for item in MyEnum.fields {
println(item.value)
println(item.name)
}
```
- Added `$option` as a compile-time reflection type representing an any Option type.
- All special compile-time reflection types are now lowercase (`$int`, `$enum`, `$option`, etc).
- Improved compile time checks, like `$if x is Type {`;
`$if T in [$Array, $Struct, $Alias, $Function] {`.
2023-07-01 13:47:57 +03:00
- `$for in` works with alias types.
- New comptime features for fields: `field.is_<field>`, `field.is_alias`, `field.is_enum`.
2023-07-01 14:00:16 +03:00
#### Compiler CLI
2023-07-01 13:47:57 +03:00
- `v share file.v` for sharing code via the playground.
- `v up` speed up for when it hasn't been run for a long time (**vc/** bootstrapping has been
optimized).
- `v init` no longer overwrites existing `src/main.v`.
- `v self` now uses a faster TCC backend on macOS (Intel/Apple Silicon), just like on Windows/Linux.
- A new command line flag `-e` for running short V programs on command line: `v -e "println(2+5)"` (
works just like in Perl).
- A new `-ldflags` option, in addition to `-cflags`. Works just like LDFLAGS in C.
2023-07-01 14:00:16 +03:00
#### OS support
2023-07-01 13:47:57 +03:00
- Added basic QNX support.
- Installation instructions for using V on NixOS.
- Better `make` support for OpenBSD.
- Much improved experience for `v install pcre` on Windows
(it now bundles its own .c files, so it compiles cleanly, even if the platform does not have
another pcre package installed).
2023-07-01 13:47:57 +03:00
- V can now be compiled with tcc on latest macOS and Apple Silicon.
- Removed the need for the `[console]` attribute in Windows GUI apps.
- More precise WINAPI declarations for easier integration on Windows.
- More CI tests on FreeBSD.
- Full termux support via `$if termux {`, more predictable logging on Android.
- Older macOS support (<10.12).
- Windows code has been removed from `v.c` distributed on non-Windows systems.
(`v_windows.c` is used on Windows.)
2023-07-01 13:47:57 +03:00
2023-07-01 14:00:16 +03:00
#### Tooling
- A new VPM site: vpm.vlang.io. A better design, discoverability of packages, descriptions,
most downloaded packages etc.
2023-07-01 13:47:57 +03:00
- vpm: installation of mixed modules.
- `v ls --install -p D:\path\vls.exe` to install a local vls executable.
- vdoc: highlight comments with gray color.
- vet: allow vetting files with global variables.
- Make util.launch_tool/3 more robust, by recompiling V tools always in a known current
working folder.
2023-07-01 13:47:57 +03:00
- Lots of documentation/readme improvements.
- Lots of playground improvements: [play.vlang.io](https://play.vlang.io), including a really cool
feature: "Show generated C code".
- "Is V still fast?" web-page has been sped up by splitting the result table into multiple years.
- GitHub Copilot summaries in PRs.
- fast.vlang.io fixes & improvements, new server.
- New official IntelliJ plugin: https://intellij-v.github.io.
- Lots of new language documentation, a nicer table of contents.
- Improved documentation for most of the vlib modules
- `make.bat` & `v up` improvements on Windows.
- TeamCity test runner support via `v -test-runner teamcity foo_test.v`.
- CI optimizations for faster runs.
- New official AdventOfCode repo with AOC solutions, also added to CI.
- More detailed timings in `v -show-timings`.
- `v new <name> web` for quickly scaffolding new web projects.
- New stunning playground with an improved look and feel, a much better and more responsive editor,
code sharing by link, more convenient keyboard control, reusability for potential embedding:
https://play.vlang.io.
- Improved call tracing via `-trace-calls`.
- Lots of documentation improvements, including a better documentation of
the recent Option/Result split.
2023-07-01 13:47:57 +03:00
- V REPL: Home/End keys support. Lots of clean up.
- DOOM is now translated/compiled and launched on CI servers. A screenshot of the running game
is made via `vgret` and is compared to the expected result.
- VLS performance improvements, especially on Windows.
- `v ls` tool for installing, for updating, and for launching VLS (V Language Server).
- `v doc` now has syntax highlighting.