Skip to content

Commit 2891726

Browse files
committed
Merge branch 'develop'
2 parents 8b70ff4 + b68a846 commit 2891726

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1665
-1662
lines changed

.gitignore

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ src/libmilonert/hashmap.h
1212

1313
# Generated files.
1414
*.a
15+
*.fsi
16+
*.generated.*
1517
*.o
18+
*.obj
1619
*.out
20+
*.pdb
1721
*.so
1822
.ninja_log
1923

@@ -23,6 +27,13 @@ tests/**/build.ninja
2327
tests/**/MiloneCore_*.c
2428
tests/**/MiloneDerive_*.c
2529
tests/**/Std_*.c
30+
tests/**/*.exe
31+
tests/*/*/x86_64-unknown-linux-gnu-debug/
32+
tests/*/*/x86_64-pc-windows-msvc-debug/
33+
tests/*/*/x86_64-pc-windows-msvc-debug-obj/
34+
tests/**/*.sln
35+
tests/**/*.vcxproj
36+
tests/**/guid.txt
2637

2738
tests/examples/*/*.c
2839
!tests/examples/factorial/factorial.c
@@ -31,7 +42,6 @@ tests/primitives/std_*/*.c
3142

3243

3344
# Deprecated: These rules are no longer used.
34-
*.generated.*
3545
*.timestamp
3646
runtime/hashmap.h
3747
tests/**/MiloneStd_*.c

CHANGELOG.md

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,39 @@
44
55
## [Unreleased]
66

7-
[Unreleased]: https://github.com/vain0x/milone-lang/compare/v0.6.0...develop
7+
[Unreleased]: https://github.com/vain0x/milone-lang/compare/v0.6.1...develop
8+
9+
10+
11+
## [v0.6.1] - 2024-01-07
12+
13+
[v0.6.1]: https://github.com/vain0x/milone-lang/compare/v0.6.0...develop
14+
15+
This version fixes a build issue. It also provides .NET tool version upgrade and some performance improvement.
16+
17+
### CLI Tools
18+
19+
- (*Windows*) `milone` command now generates VS2022 project files to build C code.
20+
21+
### LSP Server
22+
23+
- Parse results are now memoized
24+
- Some refactoring
25+
26+
### Internal Changes
27+
28+
Compiler:
29+
30+
- Type synonym expansions is now faster
31+
- Preparations for workspaces:
32+
- Multiple `main` functions are now allowed
33+
- (*Windows*) MSBuild backend supports multi-projects
34+
35+
Others:
36+
37+
- Use `--allsig` options in F# projects (to reduce compilation time)
38+
- Add `scripts/prof` and `docs/internals/profiling.md`
39+
- Fix build/pack scripts
840

941
## [v0.6.0] - 2023-02-15
1042

@@ -19,8 +51,8 @@
1951
### Language Features
2052

2153
- Support generic records
22-
- Fixed type check bugs
23-
- Fixed unicode string literals broken
54+
- Fix type check bugs
55+
- Fix unicode string literals broken
2456
- Add `never` type
2557
- Add primitives:
2658
- Add byte literals (`'a'B` syntax)
@@ -37,7 +69,7 @@
3769
- `binary staticlib` (`*.a`, `*.lib`)
3870
- Add `subsystem windows` directive (only on Windows)
3971

40-
## Standard Libraries
72+
### Standard Libraries
4173

4274
- Add `Std.CStr`, `Std.CMemory` modules for native interop
4375
- Add `Std.StringBuffer` module

Makefile

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,28 @@ src/libmilonert/hashmap.h:
3131
# MyBuildTool wrapper
3232
# ------------------------------------------------
3333

34-
MY_BUILD := src/MyBuildTool/bin/Debug/net6.0/MyBuildTool
34+
DOTNET_RESTORE_TIMESTAMP := target/.timestamp/dotnet_restore
35+
36+
MY_BUILD := src/MyBuildTool/bin/Debug/net8.0/MyBuildTool
37+
3538
MY_BUILD_TIMESTAMP := target/.timestamp/my_build_tool
3639

37-
.PHONY: dotnet_restore gen2 gen3 integration_tests my_build self test_self
40+
# Compiler to be used for bootstrapping, built by .NET version.
41+
# (This will become outdated over development. Delete the file to rebuild.)
42+
MILONE_BOOTSTRAP := target/bootstrap/bin/milone
43+
44+
# Compiler to be used for testing, built from source files in the worktree with MILONE_BOOTSTRAP.
45+
MILONE_WORKTREE := target/MiloneCli/bin/milone
3846

39-
target/.timestamp/dotnet_restore: $(wildcard src/*/*.fsproj)
47+
.PHONY: bootstrap building_tests dotnet_restore my_build self test_self
48+
49+
${DOTNET_RESTORE_TIMESTAMP}: $(wildcard src/*/*.fsproj)
4050
dotnet restore && mkdir -p $(shell dirname $@) && touch $@
4151

42-
${MY_BUILD_TIMESTAMP}: target/.timestamp/dotnet_restore \
52+
${MY_BUILD_TIMESTAMP}: ${DOTNET_RESTORE_TIMESTAMP} \
4353
$(wildcard src/MyBuildTool/*.fs) \
4454
$(wildcard src/MyBuildTool/*.fsproj)
45-
dotnet build -nologo src/MyBuildTool && mkdir -p $(shell dirname $@) && touch $@
55+
dotnet build -nologo --no-restore src/MyBuildTool && mkdir -p $(shell dirname $@) && touch $@
4656

4757
my_build: ${MY_BUILD_TIMESTAMP}
4858

@@ -55,31 +65,39 @@ uninstall: ${MY_BUILD_TIMESTAMP}
5565
pack: ${MY_BUILD_TIMESTAMP}
5666
${MY_BUILD} pack
5767

58-
target/milone: bin/ninja ${MY_BUILD_TIMESTAMP} \
68+
${MILONE_BOOTSTRAP}: bin/ninja ${DOTNET_RESTORE_TIMESTAMP}
69+
env MILONE_HOME=${PWD} dotnet run --project src/MiloneCli -- build src/MiloneCli --target-dir target/bootstrap -o $@ && touch $@
70+
71+
bootstrap: ${MILONE_BOOTSTRAP}
72+
73+
${MILONE_WORKTREE}: bin/ninja \
74+
${MILONE_BOOTSTRAP} \
75+
${MY_BUILD_TIMESTAMP} \
5976
src/libmilonert/hashmap.h \
6077
src/libmilonert/milone.h \
6178
src/libmilonert/milone.c \
6279
src/libmilonert/milone_platform.c \
6380
$(wildcard src/*/*.fs) \
6481
$(wildcard src/*/*.fsproj) \
6582
$(wildcard src/*/*.milone)
66-
${MY_BUILD} gen2 && mkdir -p $(shell dirname $@) && touch $@
67-
68-
gen2: target/milone
83+
env MILONE_HOME=${PWD} ${MILONE_BOOTSTRAP} build src/MiloneCli -o $@ && touch $@
6984

70-
target/.timestamp/gen3: bin/ninja ${MY_BUILD_TIMESTAMP} target/milone
71-
${MY_BUILD} gen3 && mkdir -p $(shell dirname $@) && touch $@
85+
worktree: ${MILONE_WORKTREE}
7286

73-
gen3: target/.timestamp/gen3
87+
target/milone: ${MILONE_WORKTREE}
88+
cp ${MILONE_WORKTREE} $@
7489

75-
self: gen2
90+
# Building tests: Testing by building projects in the tests directory.
91+
target/.timestamp/building_tests: ${MY_BUILD_TIMESTAMP} ${MILONE_WORKTREE} \
92+
$(shell find tests -type f -mtime -1)
93+
env MILONE=${MILONE_WORKTREE} ${MY_BUILD} building-tests && mkdir -p $(shell dirname $@) && touch $@
7694

77-
test_self: gen3
95+
building_tests: target/.timestamp/building_tests
7896

79-
target/.timestamp/integration_tests: bin/ninja ${MY_BUILD_TIMESTAMP} target/milone \
80-
$(shell find tests -type f -mtime -1)
81-
${MY_BUILD} tests && mkdir -p $(shell dirname $@) && touch $@
97+
# Self-hosting tests: Testing by running the self-hosted compiler to verify the generated code equality.
98+
target/.timestamp/self_hosting_tests: ${MY_BUILD_TIMESTAMP} ${MILONE_WORKTREE}
99+
MILONE=${MILONE_WORKTREE} ${MY_BUILD} self-hosting-tests && mkdir -p $(shell dirname $@) && touch $@
82100

83-
integration_tests: target/.timestamp/integration_tests
101+
self_hosting_tests: target/.timestamp/self_hosting_tests
84102

85-
test: test_self integration_tests
103+
test: building_tests self_hosting_tests

docs/internals/profiling.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Profiling
2+
3+
This is a note how to profile the compiler.
4+
5+
## Prerequisites
6+
7+
- Ubuntu (Linux)
8+
- `gprof` (GNU prof)
9+
- `python3`
10+
- `graphviz`
11+
- [gprof2dot](https://github.com/jrfonseca/gprof2dot), visualizer
12+
13+
```sh
14+
sudo apt install python3 graphviz
15+
16+
GPROF2DOT='https://raw.githubusercontent.com/jrfonseca/gprof2dot/master/gprof2dot.py'
17+
curl -sL "$GPROF2DOT" -o ~/.local/bin/gprof2dot && chmod +x ~/.local/bin/gprof2dot
18+
```
19+
20+
## Script
21+
22+
In a nutshell, do on the repository root:
23+
24+
```sh
25+
scripts/prof
26+
```
27+
28+
and `target/prof.png` is generated.
29+
30+
---
31+
32+
## Explanation
33+
34+
> 1\. `make worktree && test -f "$MILONE_CMD"`
35+
36+
We need to have a pre-built milone-lang compiler. Generate one by building the worktree:
37+
38+
> 2\.
39+
> ```sh
40+
> CC='gcc -pg' MILONE_HOME=$PWD "$MILONE_CMD" build --release 'src/MiloneCli' --target-dir 'target/MiloneProf' -o 'target/milone-prof'
41+
> ```
42+
43+
Next, compile the milone-lang compiler with *instrumentation* enabled by passing `-pg` flag to GCC.
44+
The environment variable `CC` is used to compile C source files internally.
45+
46+
Target directory is modified to another directory (`target/MiloneProf`) than the default one (`target/MiloneCli`).
47+
This avoids overwriting intermediate object files in that directory.
48+
49+
`-o` is specified to ensure the output executable is available at the specified path.
50+
51+
> 3\.
52+
> ```sh
53+
> MILONE_HOME=$PWD target/milone-prof check src/MiloneCli && \
54+
> test -f gmon.out && \
55+
> mv gmon.out target/gmon.out
56+
> ```
57+
58+
This runs the compiler built on the previous step.
59+
As an effect of `-pg` flag, the command will emit an extra file named `gmon.out` on the working directory after successful exit.
60+
`test` command makes it explicit.
61+
The following `mv` command move that file to the target directory just because we don't want to scatter files in the repository root and ensure not to commit.
62+
63+
The `gmon.out` file records the profiling data while the command is running.
64+
Data, what functions are called, how many times they are called, how long they spend time, etc.
65+
66+
> 4\.
67+
> ```sh
68+
> gprof target/milone-prof target/gmon.out | \
69+
> tee target/prof.txt | \
70+
> gprof2dot | \
71+
> dot -Tpng -o target/prof.png
72+
> ```
73+
74+
Finally convert the record to a human-readable format.
75+
`gprof` command generates a plain text file, which is written to `target/prof.txt`.
76+
77+
`gprof2dot` command converts the text (piped from gprof) to another format called dot language, which describes relationship of entities, i.e.
78+
a graph that consists of functions and connection from callee ones to callers.
79+
`dot` command (from graphviz package) converts the dot to a PNG image, which is a visualized form of the profiling data.
80+
81+
#### Legends
82+
83+
In the image, functions are associated with several numbers.
84+
85+
```
86+
SomeFun
87+
42%
88+
(5.3%)
89+
64x
90+
```
91+
92+
- First row (`SomeFun`): Mangled name of the function
93+
- Second row (`42%`): Total time spent while the function is called, including other functions that it called to
94+
- Third row (`(5.3%)`): Time spent while the function is called itself, excluding the other functions
95+
- Last row (`64x`): The number of times the function is called

nursery/.vscode/c_cpp_properties.json

Lines changed: 0 additions & 16 deletions
This file was deleted.

nursery/AppGtk/.vscode/c_cpp_properties.json

Lines changed: 0 additions & 19 deletions
This file was deleted.

nursery/AppGtk/AppGtk.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net6.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
</PropertyGroup>
77

88
<ItemGroup>

nursery/CmdCat/.vscode/c_cpp_properties.json

Lines changed: 0 additions & 17 deletions
This file was deleted.

scripts/install-dev

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ mkdir -p "$MILONE_HOME/src"
4040

4141
# Make symbolic links.
4242
ln -fs "$PWD/target/milone" "$MILONE_HOME/bin/milone_native"
43-
ln -fs "$PWD/src/MiloneCli/bin/Debug/net6.0/MiloneCli" "$MILONE_HOME/bin/milone_dotnet/MiloneCli"
44-
ln -fs "$PWD/src/MiloneLspServer/bin/Debug/net6.0/MiloneLspServer" "$MILONE_HOME/bin/milone_lsp/MiloneLspServer"
43+
ln -fs "$PWD/src/MiloneCli/bin/Debug/net8.0/MiloneCli" "$MILONE_HOME/bin/milone_dotnet/MiloneCli"
44+
ln -fs "$PWD/src/MiloneLspServer/bin/Debug/net8.0/MiloneLspServer" "$MILONE_HOME/bin/milone_lsp/MiloneLspServer"
4545
ln -fs "$PWD/src/libmilonert" "$MILONE_HOME/src/libmilonert"
4646
ln -fs "$PWD/src/MiloneCore" "$MILONE_HOME/src/MiloneCore"
4747
ln -fs "$PWD/src/Std" "$MILONE_HOME/src/Std"

scripts/prof

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/sh
2+
# See also internals/profiling.md
3+
4+
set -eux
5+
6+
MILONE_CMD='target/MiloneCli/bin/milone'
7+
8+
# build compiler
9+
make worktree && test -f "$MILONE_CMD"
10+
11+
# build the optimized compiler with instrumentation enabled (-pg flag)
12+
CC='gcc -pg' MILONE_HOME=$PWD "$MILONE_CMD" build --release src/MiloneCli --target-dir target/MiloneProf -o target/milone-prof
13+
14+
# run the compiler for profiling
15+
MILONE_HOME=$PWD target/milone-prof check src/MiloneCli && \
16+
test -f gmon.out && \
17+
mv gmon.out target/gmon.out
18+
19+
gprof target/milone-prof target/gmon.out | \
20+
tee target/prof.txt | \
21+
gprof2dot | \
22+
dot -Tpng -o target/prof.png

0 commit comments

Comments
 (0)