Skip to content

Commit

Permalink
Rust migration (#30)
Browse files Browse the repository at this point in the history
The migration is motivated by very poor
performance of Python implementation. This was caused partially by the
ANTLR parser having a general runtime that couldn't be tailored in any
way, and mainly because of the inherent slowness of Python.

New Rust implementation was around 50x faster. After including better
and more detailed heuristics it is still between 30-40x faster without
any performance tweaks. This both creates significant performance
savings that can be spent in the future on more advanced features like
HTML formatting, and opens possibilities of performance gains through
multithreading etc.

Few long existing bugs were fixed along the way. There are some minor
changes in the style applied by `mofmt`. Refer to the `code-style.md`.

Fixes #26
Fixes #27
  • Loading branch information
ErykMroczek authored Feb 5, 2024
2 parents 9a8927d + 0c76a0a commit 0041d0b
Show file tree
Hide file tree
Showing 62 changed files with 3,838 additions and 30,284 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: CI

on:
workflow_dispatch:
pull_request:
branches: [ "main" ]

jobs:

format:
name: Rustfmt
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
components: rustfmt
- run: cargo fmt --all --check

clippy:
name: Clippy
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
components: clippy
- run: cargo clippy --workspace --all-features -- -D warnings

build_and_test_linux:
name: Build and Test (Linux)
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
run: cargo test --all-targets

build_and_test_win:
name: Build and Test (Windows)
runs-on: windows-latest
timeout-minutes: 10
steps:
- name: Prepare symlink configuration
run: git config --global core.symlinks true

- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
run: cargo test --all-targets
33 changes: 0 additions & 33 deletions .github/workflows/workflows.yml

This file was deleted.

6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,9 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/


# Added by cargo

/target
/Cargo.lock
10 changes: 0 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,3 @@ repos:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml

- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
4 changes: 2 additions & 2 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
name: mofmt
description: Make your Modelica code pretty
entry: mofmt
language: python
files: '.*\.mo$'
language: rust
files: '.*\.mo$'
33 changes: 33 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,39 @@
All important changes will be described in this file. Or rather I will
try to document them here.

## [0.4.0] - 2024-02-XX

This release marks an important milestone. From now on `mofmt` will be
implemented in Rust. The migration was motivated by very poor
performance of Python implementation. This was caused partially by the
ANTLR parser having a general runtime that couldn't be tailored in any
way, and mainly because of the inherent slowness of Python.

New Rust implementation was around 50x faster. After including better
and more detailed heuristics it is still between 30-40x faster without
any performance tweaks. This both creates significant performance
savings that can be spent in the future on more advanced features like
HTML formatting, and opens possibilities of performance gains through
multithreading etc.

Few long exisisting bugs were fixed along the way. There are some minor
changes in the style applied by `mofmt`. Refer to the `code-style.md`.

### Added

- support for new syntactical constructs from Modelica 3.7
- cover *output-expression-list* production

### Changed

- expressions are now wrapped at every operator inside the precedence
level where the original wrap occured as well as in all outer levels

### Fixed

- enum lists and argument lists are now wrapped if they contain
descriptions without the need to run formatter twice

## [0.3.6] - 2024-01-09

Bugfixes and performance improvements.
Expand Down
15 changes: 15 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "mofmt"
description = "Modelica language formatter"
authors = ["Eryk Mroczek <[email protected]>"]
version = "0.4.0"
edition = "2021"
license = "MPL-2.0"
readme = "README.md"
repository = "https://github.com/ErykMroczek/mofmt"
keywords = ["Modelica", "development", "formatter"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
moparse = "0.1.4-rc4"
Loading

0 comments on commit 0041d0b

Please sign in to comment.