diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd.yaml new file mode 100644 index 0000000..3ff9d9f --- /dev/null +++ b/.github/workflows/cd.yaml @@ -0,0 +1,32 @@ +name: "CD" +on: + push: + branches: + - "master" +jobs: + changelog: + name: Generate changelog + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Generate a changelog + uses: orhun/git-cliff-action@v3 + with: + config: cliff.toml + args: --verbose + env: + OUTPUT: CHANGELOG.md + GITHUB_REPO: ${{ github.repository }} + + - name: Commit + run: | + git config user.name 'github-actions[bot]' + git config user.email 'github-actions[bot]@users.noreply.github.com' + set +e + git add CHANGELOG.md + git commit -m "Update changelog" + git push https://${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git master diff --git a/CHANGELOG.md b/CHANGELOG.md index 37eeba1..9c2d683 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,171 +1,288 @@ # Changelog -### [v0.0.2](https://github.com/ElaraLang/elara/compare/v0.0.1...v0.0.2) (2024-06-01) - -#### Features - -* **renamer:** Add a nice pretty error report for when the renamer catches -ambiguous names -([f31a6cd](https://github.com/ElaraLang/elara/commit/f31a6cd94be1e86fcd419fcc2d0a47b79e08e086)) - -#### Fixes - -* **renamer:** Fix heavy-handed ambiguous name checking reporting ambiguity -when there actually isn't any! Fixes variable shadowing -([ecb3481](https://github.com/ElaraLang/elara/commit/ecb3481cd8580e8b1ac9cfca42413f0996e5ad81)) - -#### Other - -* **renamer:** Change renaming backend to allow multiple names with the same -unqualified name -([f61f155](https://github.com/ElaraLang/elara/commit/f61f155c4f2c57e069ff82fa1cf7149d69d0dbdf)) - -#### Documentation - -* **changelog:** Update CHANGELOG.md -([0882b33](https://github.com/ElaraLang/elara/commit/0882b339938554cd083a197b1a4b7092f23b905c)) - -### [v0.0.1](https://github.com/ElaraLang/elara/compare/v0.0.0...v0.0.1) (2024-06-01) - -#### Features - -* **tocore:** Improve reporting of `UnknownConstructor` error in ToCore -([8fda8b3](https://github.com/ElaraLang/elara/commit/8fda8b31a101f0e70c70e5cdd21ae9967f475a66)) -* **stdlib:** Add Option module to stdlib -([646f1ae](https://github.com/ElaraLang/elara/commit/646f1aefa5b2e6d9ef88c4401acfac24b91369e7)) -* **stdlib:** Load all the stdlib files dynamically based on what's in the new -stdlib folder -([47e0e90](https://github.com/ElaraLang/elara/commit/47e0e90b71f41d830fe269f7cb99224ef7c0b1b9)) - -#### Fixes - -* **tocore:** Fix ToCore not being invoked in topological order, causing -unknown name errors -([8737b28](https://github.com/ElaraLang/elara/commit/8737b281c63b8b59055d0c3d1d319f8c31a41119)) - -#### Other - -* **actions:** that seemed to work - now remove the logging -([31478e6](https://github.com/ElaraLang/elara/commit/31478e679894b86feb899a8fa50e3b18babde244)) -* **actions:** Log big files -([282fb34](https://github.com/ElaraLang/elara/commit/282fb34aec3685f45f1a086d3a4fc418a1412624)) -* **actions:** nevermind let's not do that -([a30d954](https://github.com/ElaraLang/elara/commit/a30d954a686e116764c127e77b0b9d228af40a3c)) -* **actions:** Run linux builds on self-hosted runner -([9f8f291](https://github.com/ElaraLang/elara/commit/9f8f291e6e3dab4d50b3682a02e9b7a0c2c6fb42)) -* **actions:** Remove blank line -([20b7d8a](https://github.com/ElaraLang/elara/commit/20b7d8a958a29db2a324fc8987980873f8270807)) -* **actions:** Change the script...? -([4ab2c8f](https://github.com/ElaraLang/elara/commit/4ab2c8fa44b3aa0f910bced1b8e663c853594d99)), -closes [#19](https://github.com/ElaraLang/elara/issues/19) -* **actions:** Try deleting this folder -([c35171c](https://github.com/ElaraLang/elara/commit/c35171c71d049f4b468ceedea39f97c8407cbcaf)) -* **stdlib:** Make main file a bit more fully-fledged -([32b919c](https://github.com/ElaraLang/elara/commit/32b919c8358bb844b74228c2148dac3cd53a94d0)) -* **stdlib:** Move all stdlib files into new folder -([e7cd134](https://github.com/ElaraLang/elara/commit/e7cd1344aa8c04dafc79c2ff8f537985cc62708c)) - -## v0.0.0 (2024-06-01) - -### โš  BREAKING CHANGE - -* stdlib signature changed - - -### Features - -* **type-infer:** Add a new error message in the case of multiple tyapps being -detected (which shouldn't happen?) -([7486ea1](https://github.com/ElaraLang/elara/commit/7486ea12c758a85334ff48556be6365bc63302fa)) -* **logging:** Determine the log level based on elaraDebug variable -([93f8f8a](https://github.com/ElaraLang/elara/commit/93f8f8aefbe115ccd7bedaac3a404d15e3ececce)) -* **pretty-printing:** Remove the domain when printing foralls (as it will -only ever be type) -([2b5158e](https://github.com/ElaraLang/elara/commit/2b5158e3eb9459fb67079669025794a7fa81910a)) -* **pretty-printing:** Improve colourisation of pretty-printer output -([28492c5](https://github.com/ElaraLang/elara/commit/28492c57370c98ea8142574261dc36d1b80185b9)) -* **stdlib:** Add primitive functions for working with strings -([a582f06](https://github.com/ElaraLang/elara/commit/a582f0619b44bd20fc8fbbcfef4c744eb06a58fb)) -* **stdlib:** Restore the stdlib to its former glo -([0fc83e9](https://github.com/ElaraLang/elara/commit/0fc83e918b2ecf1422cf08c226d7f49442f175b7)) - -### Fixes - -* **type-infer:** Improve algorithm for detecting tyapps, fixing some edge -cases -([8503c23](https://github.com/ElaraLang/elara/commit/8503c23109a8f79180a70b77393040141d6527df)) -* **codegen:** Fix stringLength primitive not boxing integers -([85fcf5a](https://github.com/ElaraLang/elara/commit/85fcf5a6e72d2cd27f68c0854de3bf54e7b54b80)) -* **logging:** Remove old debugPretty calls -([64edc03](https://github.com/ElaraLang/elara/commit/64edc0310f539740bc81138b6b042b9333501617)) -* **type-infer:** Fix if/else type inference not always unifying correctly and -throwing errors -([33a72c2](https://github.com/ElaraLang/elara/commit/33a72c2103a1657dc9626176c2eb683513e9d4bf)) -* **tests:** Fix unit tests not compiling for various reasons -([e0a2955](https://github.com/ElaraLang/elara/commit/e0a2955d618e7a6ea1d244d2cf4672fb476c51ed)) -* **type-infer:** Fix type inference logging _always_ being on debug -([3b34bb1](https://github.com/ElaraLang/elara/commit/3b34bb1e216fafad98cf08c1d0dec4f242b61587)) -* **type-infer:** Fix constructor patterns not being completely solved -([1dc7624](https://github.com/ElaraLang/elara/commit/1dc7624f1dbaeab084a4fb7e3ae23170eb92337a)) -* **type-infer:** Fix conversion between types when explicitly applying type -constructors (eg `def x : Option Int`) -([940e960](https://github.com/ElaraLang/elara/commit/940e9608a699d06b9324f169cc1367afc43907d9)) -* Fix code generation for constructor patterns with multiple arguments -breaking -([6de3e20](https://github.com/ElaraLang/elara/commit/6de3e203a2d6ac90b98e7aea835062189a717621)) -* **type-infer:** Fix constructor pattern arguments being reversed in type -inference -([321fdd6](https://github.com/ElaraLang/elara/commit/321fdd6fbe6aaad25a547006d753a97f616e18d9)) - -### Other - -* **actions:** that seemed to work - now remove the logging -([f9a9294](https://github.com/ElaraLang/elara/commit/f9a9294cc28589d3204c5c1e3c4e84f0a95764cf)) -* **actions:** Log big files -([e0158fd](https://github.com/ElaraLang/elara/commit/e0158fd46eb94fcaaf9df45b06dd4ceb8526e4fc)) -* **actions:** nevermind let's not do that -([c684cb9](https://github.com/ElaraLang/elara/commit/c684cb95ab3c53c4a2508ccc8a8b676b5c6f7cc7)) -* **actions:** Run linux builds on self-hosted runner -([e47fa1a](https://github.com/ElaraLang/elara/commit/e47fa1acbdc2e180788bd8c008331baaa665392a)) -* **actions:** Remove blank line -([9b61673](https://github.com/ElaraLang/elara/commit/9b6167309e788bcaa4adc40493db610ef88a70c3)) -* **actions:** Change the script...? -([27dc8ea](https://github.com/ElaraLang/elara/commit/27dc8eaac5a23a955ae7336e96320b95663906d2)), -closes [#19](https://github.com/ElaraLang/elara/issues/19) -* **actions:** Try deleting this folder -([fb8c8bd](https://github.com/ElaraLang/elara/commit/fb8c8bd56ee9b231b39e1004123883934913c0a6)) -* **stdlib:** Change `readFile` to return String rather than EList -([01f4048](https://github.com/ElaraLang/elara/commit/01f40486c687c47d8f17a7795931d65c4f606e11)) -* **type-infer:** Uncomment test for `forall a. a` tyapps -([e2786a0](https://github.com/ElaraLang/elara/commit/e2786a056b7ab8ba46b96616cc953f6da3e84736)) -* **stdlib:** Remove random list from main file -([85524a1](https://github.com/ElaraLang/elara/commit/85524a108d84963b0b7090093ffb952e9d4ff4f8)) -* **type-infer:** Add new tests for type application insertion -([a341c65](https://github.com/ElaraLang/elara/commit/a341c6597677d6ff814d73cd6896231e7ed3f8b4)) -* **nix:** Update nix flake -([f95de02](https://github.com/ElaraLang/elara/commit/f95de028cc2349f71901f8c5c7e7b0cd8e4b1558)) -* **stdlib:** Refactor Elara Stdlib and add list length function -([2fa03be](https://github.com/ElaraLang/elara/commit/2fa03be4f9acc294bc2d0a41f5314fb9aceba625)) -* **stdlib:** Move ALL mentions of lists to the stdlib - they are no longer a -primitive! -([8e3d367](https://github.com/ElaraLang/elara/commit/8e3d367d94078552ea642851654c7abe7b7ff42e)) -* **logging:** Change back to info logging (really need to make this -configurable at runtime) -([7666ae9](https://github.com/ElaraLang/elara/commit/7666ae96126238a5f453a4462aedb692d0316093)) -* **tocore:** Change weird usage of =<< in ToCore -([936ab2a](https://github.com/ElaraLang/elara/commit/936ab2a3ec0b740fabae2c0954cc29d1f4cb4b24)) -* Begin work refactoring lambda generation - keep track of parameter names -_eerywhere_ -([9f8ed70](https://github.com/ElaraLang/elara/commit/9f8ed708d95cab1b5106606d15e96aa9d3aecd91)) -* Slightly tidy up generation of lambdas -([4654676](https://github.com/ElaraLang/elara/commit/4654676b73c2fa3258d9b3bf044f56e7a2f6e677)) -* **nix:** Add the old mission-control scripts back to the justfile -([1508631](https://github.com/ElaraLang/elara/commit/15086319ecb703d2774a436775312f7409df0489)) -* **nix:** Move from mission-control to just -([ba41767](https://github.com/ElaraLang/elara/commit/ba4176752274ae6b6cdbc870d8bc1d808378380d)) - -### Documentation - -* **stdlib:** Remove mention of EList from readme compiling guide -([624a156](https://github.com/ElaraLang/elara/commit/624a156569ef71567788a0d380ea13212dd5d9c5)), -closes [#12](https://github.com/ElaraLang/elara/issues/12) +All notable changes to this project will be documented in this file. + +Note that while Elara follows SemVer where possible, most of the source code is not considered public API with regards to breaking changes. +As such, breaking changes may occur between minor versions until a stable release of the language. + +## [unreleased] + +### ๐Ÿ“š Documentation + +- *(changelog)* Update CHANGELOG.md - ([31c62a7](https://github.com/ElaraLang/elara/commit/31c62a74c4273f360f1b8cbb88a57c166ae942c9)) +- *(changelog)* Use the git-cliff format for current changelog - ([f52b80b](https://github.com/ElaraLang/elara/commit/f52b80b26ba811767b4c0e4cc7059b8c24df8601)) + +### ๐Ÿงช Testing + +- *(shunter)* Fix shunting tests no longer compiling - ([4e9d196](https://github.com/ElaraLang/elara/commit/4e9d196c4ab64695f7c0c2440abf5a90ddfa8f8d)) + +### โš™๏ธ Miscellaneous Tasks + +- *(cd)* Add action to generate changelogs whenever you push to main - ([cea8bae](https://github.com/ElaraLang/elara/commit/cea8bae0ec2d7fba47b7831ac720f8cc21fce308)) + +### Build + +- *(changelog)* Add cliff.toml - ([682cc9f](https://github.com/ElaraLang/elara/commit/682cc9f771b49de35f2f4d70f4829d2e4bd31523)) +- *(nix)* Add `git-cliff` to devshell - ([8a6187e](https://github.com/ElaraLang/elara/commit/8a6187e4038f9dc73e756983c6abd9aaec4eb4d9)) + +## [0.0.2](https://github.com/ElaraLang/elara/compare/v0.0.1..v0.0.2) - 2024-06-01 + +### ๐Ÿš€ Features + +- *(renamer)* Add a nice pretty error report for when the renamer catches ambiguous names - ([f31a6cd](https://github.com/ElaraLang/elara/commit/f31a6cd94be1e86fcd419fcc2d0a47b79e08e086)) + +### ๐Ÿ› Bug Fixes + +- *(renamer)* Fix heavy-handed ambiguous name checking reporting ambiguity when there actually isn't any! Fixes variable shadowing - ([ecb3481](https://github.com/ElaraLang/elara/commit/ecb3481cd8580e8b1ac9cfca42413f0996e5ad81)) + +### ๐Ÿšœ Refactor + +- *(renamer)* Change renaming backend to allow multiple names with the same unqualified name - ([f61f155](https://github.com/ElaraLang/elara/commit/f61f155c4f2c57e069ff82fa1cf7149d69d0dbdf)) + +### ๐Ÿ“š Documentation + +- *(changelog)* Update CHANGELOG.md - ([0882b33](https://github.com/ElaraLang/elara/commit/0882b339938554cd083a197b1a4b7092f23b905c)) + +## [0.0.1](https://github.com/ElaraLang/elara/compare/v0.0.0..v0.0.1) - 2024-06-01 + +### ๐Ÿš€ Features + +- *(stdlib)* Load all the stdlib files dynamically based on what's in the new stdlib folder - ([47e0e90](https://github.com/ElaraLang/elara/commit/47e0e90b71f41d830fe269f7cb99224ef7c0b1b9)) +- *(stdlib)* Add Option module to stdlib - ([646f1ae](https://github.com/ElaraLang/elara/commit/646f1aefa5b2e6d9ef88c4401acfac24b91369e7)) +- *(tocore)* Improve reporting of `UnknownConstructor` error in ToCore - ([8fda8b3](https://github.com/ElaraLang/elara/commit/8fda8b31a101f0e70c70e5cdd21ae9967f475a66)) + +### ๐Ÿ› Bug Fixes + +- *(tocore)* Fix ToCore not being invoked in topological order, causing unknown name errors - ([8737b28](https://github.com/ElaraLang/elara/commit/8737b281c63b8b59055d0c3d1d319f8c31a41119)) + +### ๐Ÿšœ Refactor + +- *(stdlib)* Move all stdlib files into new folder - ([e7cd134](https://github.com/ElaraLang/elara/commit/e7cd1344aa8c04dafc79c2ff8f537985cc62708c)) + +### ๐ŸŽจ Styling + +- *(actions)* Remove blank line - ([20b7d8a](https://github.com/ElaraLang/elara/commit/20b7d8a958a29db2a324fc8987980873f8270807)) +- *(stdlib)* Make main file a bit more fully-fledged - ([32b919c](https://github.com/ElaraLang/elara/commit/32b919c8358bb844b74228c2148dac3cd53a94d0)) + +### โš™๏ธ Miscellaneous Tasks + +- *(actions)* Try deleting this folder - ([c35171c](https://github.com/ElaraLang/elara/commit/c35171c71d049f4b468ceedea39f97c8407cbcaf)) +- *(actions)* Change the script...? - ([4ab2c8f](https://github.com/ElaraLang/elara/commit/4ab2c8fa44b3aa0f910bced1b8e663c853594d99)) +- *(actions)* Run linux builds on self-hosted runner - ([9f8f291](https://github.com/ElaraLang/elara/commit/9f8f291e6e3dab4d50b3682a02e9b7a0c2c6fb42)) +- *(actions)* Nevermind let's not do that - ([a30d954](https://github.com/ElaraLang/elara/commit/a30d954a686e116764c127e77b0b9d228af40a3c)) +- *(actions)* Log big files - ([282fb34](https://github.com/ElaraLang/elara/commit/282fb34aec3685f45f1a086d3a4fc418a1412624)) +- *(actions)* That seemed to work - now remove the logging - ([31478e6](https://github.com/ElaraLang/elara/commit/31478e679894b86feb899a8fa50e3b18babde244)) + +## [0.0.0] - 2024-06-01 + +### ๐Ÿš€ Features + +- *(logging)* Determine the log level based on elaraDebug variable - ([93f8f8a](https://github.com/ElaraLang/elara/commit/93f8f8aefbe115ccd7bedaac3a404d15e3ececce)) +- *(pretty-printing)* Improve colourisation of pretty-printer output - ([28492c5](https://github.com/ElaraLang/elara/commit/28492c57370c98ea8142574261dc36d1b80185b9)) +- *(pretty-printing)* Remove the domain when printing foralls (as it will only ever be type) - ([2b5158e](https://github.com/ElaraLang/elara/commit/2b5158e3eb9459fb67079669025794a7fa81910a)) +- *(stdlib)* Restore the stdlib to its former glo - ([0fc83e9](https://github.com/ElaraLang/elara/commit/0fc83e918b2ecf1422cf08c226d7f49442f175b7)) +- *(stdlib)* Add primitive functions for working with strings - ([a582f06](https://github.com/ElaraLang/elara/commit/a582f0619b44bd20fc8fbbcfef4c744eb06a58fb)) +- *(type-infer)* Add a new error message in the case of multiple tyapps being detected (which shouldn't happen?) - ([7486ea1](https://github.com/ElaraLang/elara/commit/7486ea12c758a85334ff48556be6365bc63302fa)) + +### ๐Ÿ› Bug Fixes + +- *(codegen)* Fix stringLength primitive not boxing integers - ([85fcf5a](https://github.com/ElaraLang/elara/commit/85fcf5a6e72d2cd27f68c0854de3bf54e7b54b80)) +- *(logging)* Remove old debugPretty calls - ([64edc03](https://github.com/ElaraLang/elara/commit/64edc0310f539740bc81138b6b042b9333501617)) +- *(tests)* Fix unit tests not compiling for various reasons - ([e0a2955](https://github.com/ElaraLang/elara/commit/e0a2955d618e7a6ea1d244d2cf4672fb476c51ed)) +- *(type-infer)* Fix constructor pattern arguments being reversed in type inference - ([321fdd6](https://github.com/ElaraLang/elara/commit/321fdd6fbe6aaad25a547006d753a97f616e18d9)) +- *(type-infer)* Fix conversion between types when explicitly applying type constructors (eg `def x : Option Int`) - ([940e960](https://github.com/ElaraLang/elara/commit/940e9608a699d06b9324f169cc1367afc43907d9)) +- *(type-infer)* Fix constructor patterns not being completely solved - ([1dc7624](https://github.com/ElaraLang/elara/commit/1dc7624f1dbaeab084a4fb7e3ae23170eb92337a)) +- *(type-infer)* Fix type inference logging _always_ being on debug - ([3b34bb1](https://github.com/ElaraLang/elara/commit/3b34bb1e216fafad98cf08c1d0dec4f242b61587)) +- *(type-infer)* Fix if/else type inference not always unifying correctly and throwing errors - ([33a72c2](https://github.com/ElaraLang/elara/commit/33a72c2103a1657dc9626176c2eb683513e9d4bf)) +- *(type-infer)* Improve algorithm for detecting tyapps, fixing some edge cases - ([8503c23](https://github.com/ElaraLang/elara/commit/8503c23109a8f79180a70b77393040141d6527df)) +- Fix the tests + - ([1273624](https://github.com/ElaraLang/elara/commit/1273624f5efd8a4dc9a52df073e199c03a180874)) +- Fix name shadowing in inspection + - ([56dc353](https://github.com/ElaraLang/elara/commit/56dc3534dfa22b5aee0582788784570c7560486e)) +- Fix haddock comment + - ([945cd39](https://github.com/ElaraLang/elara/commit/945cd398eaccb880d36017ba8f06279ba93880ae)) +- Fix latex + - ([57cb4ac](https://github.com/ElaraLang/elara/commit/57cb4ac62336eea9cddb65e24c730b70d3533801)) +- Fix a bunch of warnings :D + - ([bef63d7](https://github.com/ElaraLang/elara/commit/bef63d70b55ed5e988bd822513df2ed95c44bdde)) +- Fix some more warnings + - ([ea6b295](https://github.com/ElaraLang/elara/commit/ea6b295a211c57609665f2c23833578738d485a2)) +- Fix more warnings + - ([877fa2d](https://github.com/ElaraLang/elara/commit/877fa2df71692775c9cba46f92c361fae38b747b)) +- Fix a naughty parser edge case, but now indentation is broken + - ([fb64659](https://github.com/ElaraLang/elara/commit/fb646599f65db122aa30e5cea8a250e055de5429)) +- Fix local let bindings not being annotated properly + - ([5437b1b](https://github.com/ElaraLang/elara/commit/5437b1bc0f789b89090689919a0cda3e3f873684)) +- Fix parsing tests, make let-binding names unqualified + - ([16221a2](https://github.com/ElaraLang/elara/commit/16221a2b96fd9ddf7dc6e80b1523c8ae08376253)) +- Fix funny quickcheck edge cases + - ([c231e2a](https://github.com/ElaraLang/elara/commit/c231e2ac6872efe1d4aac5590087f6f01c0ea446)) +- Fix some haddock typos + - ([543a982](https://github.com/ElaraLang/elara/commit/543a982fb6c6c2bb9e288465ace248b64eb73ba0)) +- Fix let-in error + - ([9b60ec8](https://github.com/ElaraLang/elara/commit/9b60ec83ea45e08cfd022832c64c890a0f748a88)) +- Fix prettyprint infinite loop lol + - ([ace5c19](https://github.com/ElaraLang/elara/commit/ace5c19e65adf51e119efa3af67a99eaa8addc66)) +- Fix unification with type declarations + - ([24e2278](https://github.com/ElaraLang/elara/commit/24e2278773432462e072d1e412e530ac30d52026)) +- Fix da nix + - ([7ed19ef](https://github.com/ElaraLang/elara/commit/7ed19ef155b2f56e03544e06de7bdef3ac6aeee4)) +- Fix da stack (doesnt rhyme sorry) + - ([79018aa](https://github.com/ElaraLang/elara/commit/79018aabb9594ee3aef344f8b92c03fbba2b1583)) +- Fix type inference? + - ([b05c98a](https://github.com/ElaraLang/elara/commit/b05c98a9ff0afeabb47155c88ab6c1643253c3fd)) +- Fix hie + - ([2b53f88](https://github.com/ElaraLang/elara/commit/2b53f88ee07827d67cf0c7ccce5520ffeb38b7bc)) +- Fix unit tests + - ([2ef17dd](https://github.com/ElaraLang/elara/commit/2ef17dd60ebfabbec9f05a7b67fcfb2528e02db2)) +- Fix doctests + - ([f2543c7](https://github.com/ElaraLang/elara/commit/f2543c7bd40427ad91488df1dc959d6df58c8774)) +- Fix the pattern parser & add a lot of tests + - ([94d1669](https://github.com/ElaraLang/elara/commit/94d1669fa7c151d4d36964fa3a05ca185173cb1b)) +- Fix lots of bugs! + - ([438e69f](https://github.com/ElaraLang/elara/commit/438e69f744c68b730aa625e891e593d57a5aaff7)) +- Fix subtyping on custom types + - ([c790d2f](https://github.com/ElaraLang/elara/commit/c790d2f756aef3386a5f54ff8fd32898f11dbd27)) +- Fix stupid ugly CI (maybe) + - ([ad7a872](https://github.com/ElaraLang/elara/commit/ad7a87227ce7a506a5903c228ea390f17fb517e7)) +- Fix some warnings and refactor even more + - ([1d96b4d](https://github.com/ElaraLang/elara/commit/1d96b4d7d96379084a914f3d8090bf4de9078be1)) +- Fix a morbillion more warnings + - ([be1c891](https://github.com/ElaraLang/elara/commit/be1c891aadf9850bb817aa0aaca5216b1ba6568b)) +- Fix almost all the warnings + - ([351f7fb](https://github.com/ElaraLang/elara/commit/351f7fb55ed24254401eb88894cc790719a3069d)) +- Fix a very rare lexer edge case + - ([b0369fc](https://github.com/ElaraLang/elara/commit/b0369fcc435934d20876ae0dd08e0c165acc8e11)) +- Fix build error + - ([c154b25](https://github.com/ElaraLang/elara/commit/c154b25657399e75d675761e97f0baf597714dbb)) +- Fix the tests not compiling (oops) + - ([4a620ee](https://github.com/ElaraLang/elara/commit/4a620ee9f3549ce4592ca06a88cfe8f57b9497a4)) +- Fix the tests not compiling (oops) + - ([4ff8661](https://github.com/ElaraLang/elara/commit/4ff8661e822452390a0ebc402a7055c152a638f8)) +- Fix let-in constructs being given the wrong type in core + - ([e52396e](https://github.com/ElaraLang/elara/commit/e52396e44274be57da41a52fe7189040cbd40a57)) +- Fix maxLocals for + - ([1a09f30](https://github.com/ElaraLang/elara/commit/1a09f30c220e563ca60d2d610e7b7ab65838a580)) +- Fix bug in renaming let statements + - ([4825d10](https://github.com/ElaraLang/elara/commit/4825d102860a0a61c8dae696875b42cff7eb6c44)) +- Fix the cons type + - ([8813151](https://github.com/ElaraLang/elara/commit/8813151a17505b3224514a429c93df1220e03302)) +- Fix parse error with higher order functions + - ([4452451](https://github.com/ElaraLang/elara/commit/44524515c89c7a84dd3578228fee0c609a539b04)) +- Fix unnecessary type applications being added + - ([09dc4ba](https://github.com/ElaraLang/elara/commit/09dc4ba5e96d93dc09cebe79a170815b0c479d4a)) +- Fix variables in ToCore using the wrong types + - ([d3da4bb](https://github.com/ElaraLang/elara/commit/d3da4bb60b3ee3e376b19939fa067a85819aae95)) +- Fix (?) type inference for list literals + - ([8a20d85](https://github.com/ElaraLang/elara/commit/8a20d856748c3472b488fa719b3c117074a5b07f)) +- Fix CI + - ([34bbcb0](https://github.com/ElaraLang/elara/commit/34bbcb0fe09c74121a723c2da76c6aff86e3887c)) +- Fix undefined handling + - ([85a0df4](https://github.com/ElaraLang/elara/commit/85a0df48b54f9cb6e76ff487150f840d0a4d1cdc)) +- Fix |> and emitting higher order functions + - ([69b3236](https://github.com/ElaraLang/elara/commit/69b3236708023b15ea9aed0b011d324bf7990ae5)) +- Fix more tyapps + - ([70aae06](https://github.com/ElaraLang/elara/commit/70aae06edb2a4ea2ebdcc31707532b1a68624ff3)) +- Fix redundant pattern match warning with Local' & Global' + - ([cd0ca0c](https://github.com/ElaraLang/elara/commit/cd0ca0c8b7982a9083c20ea2adfbfed25ad1a331)) +- Fix core type instantiation being incorrect + - ([97427ab](https://github.com/ElaraLang/elara/commit/97427ab1a7731e19bb4ccec1170c5f4350158e0a)) +- Fix match expressions inferring to the wrong type + - ([ad97cef](https://github.com/ElaraLang/elara/commit/ad97cefc9f91e5385977692e78b78b83974825d1)) +- Fix ci running + - ([a858457](https://github.com/ElaraLang/elara/commit/a8584571399ee3ff27f7fcae80546b012a5945eb)) +- Fix shunt tests + - ([d017534](https://github.com/ElaraLang/elara/commit/d017534f7c17767811bd2663d4167d2b8a30b782)) +- Fix a bunch of warnings + - ([aa811c7](https://github.com/ElaraLang/elara/commit/aa811c7ccc41b085aa58a78cdeb59bfbf57762fe)) +- Fix the unit tests compiling + - ([b2e838d](https://github.com/ElaraLang/elara/commit/b2e838dc9ee35e6a9f8abb7a9a01064904d1c682)) +- Fix all tests + - ([216af73](https://github.com/ElaraLang/elara/commit/216af73edfeb5da214999f961bcbc52bdc73591b)) +- Fix gh workflow + - ([143afe5](https://github.com/ElaraLang/elara/commit/143afe5adb1f55a401bcdd4cda9a545d12e5828f)) +- Fix order of lambda params + - ([34b992c](https://github.com/ElaraLang/elara/commit/34b992c8b58d478dbacf68e54398ecbaa7d384eb)) +- Fix weird deveshell bug + - ([018ad04](https://github.com/ElaraLang/elara/commit/018ad047f2573e477a51b63b0058a554ef5fcc7a)) +- Fix Show instance for UniqueID + - ([69abce6](https://github.com/ElaraLang/elara/commit/69abce637f21705340360d45bb5b247826c50aa9)) +- Fix a bunch of warnings + - ([ca5bada](https://github.com/ElaraLang/elara/commit/ca5badadb5429e8eea76dee44db34eb2aa4bbef0)) +- Fix tests too + - ([8ac8089](https://github.com/ElaraLang/elara/commit/8ac8089176bc12bea0878ab39e202a6a2252c289)) +- Fix unix build + - ([02d1936](https://github.com/ElaraLang/elara/commit/02d1936da432f7fe6c75bfe28c9898fab7e25509)) +- Fix crlf endings breaking lexer + - ([5c23b0c](https://github.com/ElaraLang/elara/commit/5c23b0cc250289fcd99b224df6f54fd34fd559a1)) +- Fix unit tests + - ([164dc28](https://github.com/ElaraLang/elara/commit/164dc284d4d83ecb063bd8208f036811f3f5fed9)) +- Fix jvm separator on windows + - ([59674d7](https://github.com/ElaraLang/elara/commit/59674d7c3bf625dc84c8176d43aa0034b198cbb7)) +- Fix parsing of constructor patterns with args without parens + - ([aadac49](https://github.com/ElaraLang/elara/commit/aadac49e00acf5d3e60b13bef214be081f38b919)) +- Fix graph topology due from constructor patterns + - ([5184f39](https://github.com/ElaraLang/elara/commit/5184f393679f5b66a4f3ac5357a5439382f3cfe8)) +- Fix constructors with multiple fields being invalidly generated + - ([6fd72ae](https://github.com/ElaraLang/elara/commit/6fd72ae0a78a4aabf87112f7e81741669f7b6a05)) +- Fix wrong toString append being used + - ([a668e0a](https://github.com/ElaraLang/elara/commit/a668e0a3530bc5a264e16a15a42ee58e6dabb4f0)) +- Fix adt match calling in the wrong order + - ([a396b22](https://github.com/ElaraLang/elara/commit/a396b224f317bd16b17ce88e849f5c1a4a2ce0ce)) +- Fix type / kind inference and such + - ([49fcb62](https://github.com/ElaraLang/elara/commit/49fcb624a679122d726b5c7b08685b86f6d4a127)) +- Fix the prettyprinter changes breaking the unit tests + - ([207856e](https://github.com/ElaraLang/elara/commit/207856e27346683d85001b2ad8cbb49c66d6b618)) +- Fix code generation for constructor patterns with multiple arguments breaking - ([6de3e20](https://github.com/ElaraLang/elara/commit/6de3e203a2d6ac90b98e7aea835062189a717621)) + +### ๐Ÿšœ Refactor + +- *(stdlib)* Move ALL mentions of lists to the stdlib - they are no longer a primitive! - ([8e3d367](https://github.com/ElaraLang/elara/commit/8e3d367d94078552ea642851654c7abe7b7ff42e)) +- *(stdlib)* Refactor Elara Stdlib and add list length function - ([2fa03be](https://github.com/ElaraLang/elara/commit/2fa03be4f9acc294bc2d0a41f5314fb9aceba625)) +- *(stdlib)* [**breaking**] Change `readFile` to return String rather than EList - ([01f4048](https://github.com/ElaraLang/elara/commit/01f40486c687c47d8f17a7795931d65c4f606e11)) +- Refactor tests + - ([8151cfd](https://github.com/ElaraLang/elara/commit/8151cfde6fec3c8cc106c20ce0ffc7885a507f63)) +- Refactors + - ([718aa8a](https://github.com/ElaraLang/elara/commit/718aa8aa8e3f4a33ede2375f3854c7a33e6948cc)) +- Refactor HasDependencies to allow multiple keys + - ([5d1490e](https://github.com/ElaraLang/elara/commit/5d1490e75e41ad492164850c909a7c96fb2c9619)) +- Refactor how type constructors are handled in core + - ([ba962be](https://github.com/ElaraLang/elara/commit/ba962be52873f8093166170256650c681b48c715)) +- Slightly tidy up generation of lambdas - ([4654676](https://github.com/ElaraLang/elara/commit/4654676b73c2fa3258d9b3bf044f56e7a2f6e677)) +- Begin work refactoring lambda generation - keep track of parameter names _eerywhere_ - ([9f8ed70](https://github.com/ElaraLang/elara/commit/9f8ed708d95cab1b5106606d15e96aa9d3aecd91)) + +### ๐Ÿ“š Documentation + +- *(stdlib)* Remove mention of EList from readme compiling guide - ([624a156](https://github.com/ElaraLang/elara/commit/624a156569ef71567788a0d380ea13212dd5d9c5)) +- Document the pipeline a bit + - ([efd41ea](https://github.com/ElaraLang/elara/commit/efd41ea37b869d5249de26cf3eee44fb6176915c)) + +### ๐ŸŽจ Styling + +- *(actions)* Remove blank line - ([9b61673](https://github.com/ElaraLang/elara/commit/9b6167309e788bcaa4adc40493db610ef88a70c3)) +- *(tocore)* Change weird usage of =<< in ToCore - ([936ab2a](https://github.com/ElaraLang/elara/commit/936ab2a3ec0b740fabae2c0954cc29d1f4cb4b24)) + +### ๐Ÿงช Testing + +- *(type-infer)* Add new tests for type application insertion - ([a341c65](https://github.com/ElaraLang/elara/commit/a341c6597677d6ff814d73cd6896231e7ed3f8b4)) +- *(type-infer)* Uncomment test for `forall a. a` tyapps - ([e2786a0](https://github.com/ElaraLang/elara/commit/e2786a056b7ab8ba46b96616cc953f6da3e84736)) +- Test - ([dd1a893](https://github.com/ElaraLang/elara/commit/dd1a8930c50658d46009a6690db05244acd81532)) + +### โš™๏ธ Miscellaneous Tasks + +- *(actions)* Try deleting this folder - ([fb8c8bd](https://github.com/ElaraLang/elara/commit/fb8c8bd56ee9b231b39e1004123883934913c0a6)) +- *(actions)* Change the script...? - ([27dc8ea](https://github.com/ElaraLang/elara/commit/27dc8eaac5a23a955ae7336e96320b95663906d2)) +- *(actions)* Run linux builds on self-hosted runner - ([e47fa1a](https://github.com/ElaraLang/elara/commit/e47fa1acbdc2e180788bd8c008331baaa665392a)) +- *(actions)* Nevermind let's not do that - ([c684cb9](https://github.com/ElaraLang/elara/commit/c684cb95ab3c53c4a2508ccc8a8b676b5c6f7cc7)) +- *(actions)* Log big files - ([e0158fd](https://github.com/ElaraLang/elara/commit/e0158fd46eb94fcaaf9df45b06dd4ceb8526e4fc)) +- *(actions)* That seemed to work - now remove the logging - ([f9a9294](https://github.com/ElaraLang/elara/commit/f9a9294cc28589d3204c5c1e3c4e84f0a95764cf)) +- *(logging)* Change back to info logging (really need to make this configurable at runtime) - ([7666ae9](https://github.com/ElaraLang/elara/commit/7666ae96126238a5f453a4462aedb692d0316093)) +- *(nix)* Move from mission-control to just - ([ba41767](https://github.com/ElaraLang/elara/commit/ba4176752274ae6b6cdbc870d8bc1d808378380d)) +- *(nix)* Add the old mission-control scripts back to the justfile - ([1508631](https://github.com/ElaraLang/elara/commit/15086319ecb703d2774a436775312f7409df0489)) +- *(stdlib)* Remove random list from main file - ([85524a1](https://github.com/ElaraLang/elara/commit/85524a108d84963b0b7090093ffb952e9d4ff4f8)) + +### Build + +- *(nix)* Update nix flake - ([f95de02](https://github.com/ElaraLang/elara/commit/f95de028cc2349f71901f8c5c7e7b0cd8e4b1558)) + + diff --git a/app/Main.hs b/app/Main.hs index fd753ac..5526455 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -193,8 +193,7 @@ processModules graph (dumpShunted, dumpTyped) = >=> traverseGraphRevTopologically inferModule >=> dumpIf fst dumpTyped (view (_Unwrapped % unlocated % field' @"name" % to nameText)) ".typed.elr" >=> traverseGraphRevTopologically (\(a, b) -> moduleToCore b a) - >=> pure - . mapGraph coreToCore + >=> (pure . mapGraph coreToCore) $ graph ) where diff --git a/cliff.toml b/cliff.toml new file mode 100644 index 0000000..cb41ef9 --- /dev/null +++ b/cliff.toml @@ -0,0 +1,119 @@ +# git-cliff ~ default configuration file +# https://git-cliff.org/docs/configuration +# +# Lines starting with "#" are comments. +# Configuration options are organized into tables and keys. +# See documentation for more information on available options. + +[changelog] +# changelog header +header = """ +# Changelog\n +All notable changes to this project will be documented in this file.\n +Note that while Elara follows SemVer where possible, most of the source code is not considered public API with regards to breaking changes. +As such, breaking changes may occur between minor versions until a stable release of the language.\n +""" +# template for the changelog body +# https://keats.github.io/tera/docs/#introduction +body = """ +{%- macro remote_url() -%} + https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }} +{%- endmacro -%} + +{% macro print_commit(commit) -%} + - {% if commit.scope %}*({{ commit.scope }})* {% endif %}\ + {% if commit.breaking %}[**breaking**] {% endif %}\ + {{ commit.message | upper_first }} - \ + ([{{ commit.id | truncate(length=7, end="") }}]({{ self::remote_url() }}/commit/{{ commit.id }}))\ + {% if commit.github.pr_number %} in #{{ commit.github.pr_number }}{%- endif %} \ +{% endmacro -%} + +{% if version %}\ + {% if previous.version %}\ + ## [{{ version | trim_start_matches(pat="v") }}]\ + ({{ self::remote_url() }}/compare/{{ previous.version }}..{{ version }}) - {{ timestamp | date(format="%Y-%m-%d") }} + {% else %}\ + ## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }} + {% endif %}\ +{% else %}\ + ## [unreleased] +{% endif %}\ + +{% for group, commits in commits | group_by(attribute="group") %} + ### {{ group | striptags | trim | upper_first }} + {% for commit in commits + | filter(attribute="scope") + | sort(attribute="scope") %} + {{ self::print_commit(commit=commit) }} + {%- endfor -%} + {% raw %}\n{% endraw %}\ + {%- for commit in commits %} + {%- if not commit.scope -%} + {{ self::print_commit(commit=commit) }} + {% endif -%} + {% endfor -%} +{% endfor %}\n +""" +# template for the changelog footer +footer = """ + +""" +# remove the leading and trailing s +trim = true +# postprocessors +postprocessors = [ + # { pattern = '', replace = "https://github.com/orhun/git-cliff" }, # replace repository URL +] + +[git] +# parse the commits based on https://www.conventionalcommits.org +conventional_commits = true +# filter out the commits that are not conventional +filter_unconventional = false +# process each line of a commit as an individual commit +split_commits = false +# regex for preprocessing the commit messages +commit_preprocessors = [ + # Replace issue numbers + { pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](/issues/${2}))"}, + # Check spelling of the commit with https://github.com/crate-ci/typos + # If the spelling is incorrect, it will be automatically fixed. + #{ pattern = '.*', replace_command = 'typos --write-changes -' }, +] +# regex for parsing and grouping commits +commit_parsers = [ + { message = "^feat", group = "๐Ÿš€ Features" }, + { message = "^fix", group = "๐Ÿ› Bug Fixes" }, + { message = "^doc", group = "๐Ÿ“š Documentation" }, + { message = "^perf", group = "โšก Performance" }, + { message = "^refactor", group = "๐Ÿšœ Refactor" }, + { message = "^style", group = "๐ŸŽจ Styling" }, + { message = "^test", group = "๐Ÿงช Testing" }, + { message = "^chore\\(release\\): prepare for", skip = true }, + { message = "^chore\\(deps.*\\)", skip = true }, + { message = "^chore\\(pr\\)", skip = true }, + { message = "^chore\\(pull\\)", skip = true }, + { message = "^chore|^ci", group = "โš™๏ธ Miscellaneous Tasks" }, + { body = ".*security", group = "๐Ÿ›ก๏ธ Security" }, + { message = "^revert", group = "โ—€๏ธ Revert" }, +] +# protect breaking changes from being skipped due to matching a skipping commit_parser +protect_breaking_commits = false +# filter out the commits that are not matched by commit parsers +filter_commits = false +# regex for matching git tags +# tag_pattern = "v[0-9].*" +# regex for skipping tags +# skip_tags = "" +# regex for ignoring tags +# ignore_tags = "" +# sort the tags topologically +topo_order = false +# sort the commits inside sections by oldest/newest order +sort_commits = "oldest" +# limit the number of commits included in the changelog. +# limit_commits = 42 + +[remote.github] +owner="elaralang" +repo="elara" \ No newline at end of file diff --git a/elara.cabal b/elara.cabal index dea22c7..43b370a 100644 --- a/elara.cabal +++ b/elara.cabal @@ -175,6 +175,7 @@ library , safe-exceptions , stringsearch , terminal-size + , text-metrics , utf8-string mixins: base hiding (Prelude) @@ -231,6 +232,7 @@ executable elara , safe-exceptions , stringsearch , terminal-size + , text-metrics , utf8-string mixins: base hiding (Prelude) @@ -312,6 +314,7 @@ test-suite elara-test , safe-exceptions , stringsearch , terminal-size + , text-metrics , utf8-string mixins: base hiding (Prelude) diff --git a/flake.nix b/flake.nix index a0522c9..e4055c3 100644 --- a/flake.nix +++ b/flake.nix @@ -103,7 +103,6 @@ just-flake.features = { treefmt.enable = true; - convco.enable = true; }; @@ -156,6 +155,7 @@ pkgs.haskellPackages.haskell-debug-adapter pkgs.haskellPackages.ghci-dap pkgs.haskellPackages.hpack + pkgs.git-cliff ]; }; diff --git a/package.yaml b/package.yaml index 8fa8da8..7975bc3 100644 --- a/package.yaml +++ b/package.yaml @@ -46,6 +46,7 @@ dependencies: - hashable - process - stringsearch + - text-metrics ghc-options: - -Wall diff --git a/release.sh b/release.sh new file mode 100755 index 0000000..438d19b --- /dev/null +++ b/release.sh @@ -0,0 +1,30 @@ +# inspired by https://github.com/orhun/git-cliff/blob/main/release.sh + +new_version=$(git cliff --bumped-version) +echo "New version: $new_version" + +# update package.yaml version +sed -E -i '' "s/^version: \"[^\"]*\"$/version: \"${new_version#v}\"/" package.yaml +# and the cabal file +hpack + + +# Update changelog +git cliff --tag "${new_version}" > CHANGELOG.md +git add -A && git commit -m "chore(release): prepare for ${new_version}" +git show + +# generate a changelog for the tag message +export GIT_CLIFF_TEMPLATE="\ + {% for group, commits in commits | group_by(attribute=\"group\") %} + {{ group | upper_first }}\ + {% for commit in commits %} + - {% if commit.breaking %}(breaking) {% endif %}{{ commit.message | upper_first }} ({{ commit.id | truncate(length=7, end=\"\") }})\ + {% endfor %} + {% endfor %}" +changelog=$(git cliff --unreleased --strip all) + +git tag -s -a "${new_version}" -m "Release ${new_version}" -m "${changelog}" +git tag -v "${new_version}" + +echo "Release ready. Run 'git push --follow-tags' to push the changes and tags." diff --git a/source.elr b/source.elr index d12ca06..882a9d0 100644 --- a/source.elr +++ b/source.elr @@ -1,8 +1,8 @@ import Prelude import Option -import List +import Elara.Prim let inc x = x + 1 let main = - print (Option.map inc (Some 5)) + print (map incc (Some 5)) diff --git a/src/Elara/Rename.hs b/src/Elara/Rename.hs index 627e392..6dcd030 100644 --- a/src/Elara/Rename.hs +++ b/src/Elara/Rename.hs @@ -10,48 +10,57 @@ This stage handles: -} module Elara.Rename where -import Data.Generics.Product +import Data.Generics.Product hiding (list) +import Data.Generics.Sum (AsAny (_As)) import Data.Generics.Wrapped import Data.List.NonEmpty qualified as NonEmpty import Data.Map qualified as Map +import Data.Text.Metrics (levenshtein) import Elara.AST.Desugared -import Elara.AST.Generic +import Elara.AST.Generic hiding (moduleName) import Elara.AST.Generic.Common import Elara.AST.Module -import Elara.AST.Name (LowerAlphaName (..), MaybeQualified (MaybeQualified), ModuleName, Name (NTypeName, NVarName), Qualified (Qualified), ToName (toName), TypeName, VarName (NormalVarName, OperatorVarName), VarOrConName (..)) +import Elara.AST.Name (HasQualifier (qualifier), LowerAlphaName (..), MaybeQualified (MaybeQualified), ModuleName, Name (NTypeName, NVarName), NameLike (..), Qualified (Qualified), ToName (toName), TypeName, VarName (NormalVarName, OperatorVarName), VarOrConName (..)) import Elara.AST.Region (Located (Located), enclosingRegion', sourceRegion, sourceRegionToDiagnosePosition, spanningRegion', unlocated, withLocationOf) import Elara.AST.Renamed import Elara.AST.Select (LocatedAST (Desugared, Renamed)) -import Elara.AST.VarRef (VarRef, VarRef' (Global, Local)) +import Elara.AST.VarRef (VarRef, VarRef' (Global, Local), varRefVal) import Elara.Data.Pretty import Elara.Data.TopologicalGraph import Elara.Data.Unique (Unique, UniqueGen, makeUnique, uniqueGenToIO) import Elara.Error (ReportableError (report), runErrorOrReport, writeReport) -import Elara.Error.Codes qualified as Codes (nonExistentModuleDeclaration, unknownModule) +import Elara.Error.Codes qualified as Codes import Elara.Pipeline import Elara.Prim.Core (consCtorName, emptyListCtorName) import Error.Diagnose (Marker (This, Where), Note (..), Report (Err)) import Optics (anyOf, filteredBy, traverseOf_) -import Polysemy (Member, Members, Sem) +import Polysemy (Member, Members, Sem, subsume) import Polysemy.Error (Error, note, throw) +import Polysemy.Log qualified as Log import Polysemy.Reader hiding (Local) import Polysemy.State import Polysemy.State.Extra import Polysemy.Utils (withModified) +import Print (showPretty) data RenameError = UnknownModule ModuleName | QualifiedInWrongModule ModuleName ModuleName | NonExistentModuleDeclaration ModuleName (Located Name) | UnknownTypeVariable LowerAlphaName - | UnknownName (Located Name) + | forall name. + ToName name => + UnknownName + -- | The name that was unknown + (Located Name) + -- | The module we're renaming that the unknown name was referenced in + (Maybe (Module 'Desugared)) + -- | All known names + (Map name (NonEmpty (VarRef name))) | AmbiguousVarName (Located Name) (NonEmpty (VarRef VarName)) | AmbiguousTypeName (Located Name) (NonEmpty (VarRef TypeName)) | NativeDefUnsupported (Located DesugaredDeclaration') | BlockEndsWithLet DesugaredExpr (Maybe DesugaredDeclarationBody) - deriving (Show) - -instance Exception RenameError instance ReportableError RenameError where report (UnknownModule mn) = @@ -83,17 +92,55 @@ instance ReportableError RenameError where ("Unknown type variable: " <> pretty n) [] [] - report (UnknownName n) = + report (UnknownName n m names) = do let nameKind = case n of Located _ (NVarName (NormalVarName _)) -> "variable" Located _ (NVarName (OperatorVarName _)) -> "operator" Located _ (NTypeName _) -> "type" - in writeReport $ - Err - Nothing - ("Unknown" <+> nameKind <+> "name: " <> pretty n) - [(n ^. sourceRegion % to sourceRegionToDiagnosePosition, This "referenced here")] - [] + -- search all names to suggest imports / similar names + let namesMap = Map.mapKeys toName names + let allNames = maybe [] toList (fmap toName <<$>> Map.lookup (n ^. unlocated) namesMap) + let namesThatMightveBeenIntendedButNotImported = + case m of + Nothing -> [] + Just m -> case filter (not . isImportedBy m) allNames of + [] -> [] + ns -> + [ Hint $ + vsep + [ "This name is defined in the following modules, but none of them are imported:" + , hsep (punctuate comma (ns ^.. each % _As @"Global" % unlocated % qualifier % to pretty)) + , "Try importing one of the modules." + ] + ] + let + prettyVarRef n@(Local{}) = pretty (toName $ view unlocated $ varRefVal n) <+> "(local variable)" + prettyVarRef (Global (Located _ (Qualified n m))) = pretty (toName n) <+> "(imported from" <+> pretty m <> ")" + possibleTypos = case m of + Nothing -> [] + Just m -> + let intendedText = nameText n + isTypo name = levenshtein (nameText name) intendedText < 3 + typos = + Map.filterWithKey + (\k _ -> isTypo k) + (NonEmpty.filter (\x -> isImportedBy m (toName <$> x)) <$> namesMap) + in case join (Map.elems typos) of + [] -> [] + ts -> + [ Hint $ + vsep + [ "You may have meant one of:" + , listToText (prettyVarRef <$> ts) + ] + ] + + writeReport $ + Err + (Just Codes.unknownName) + ("Unknown" <+> nameKind <+> "name: " <> pretty n) + [(n ^. sourceRegion % to sourceRegionToDiagnosePosition, This "referenced here")] + (namesThatMightveBeenIntendedButNotImported <> possibleTypos) report (NativeDefUnsupported _) = writeReport $ Err @@ -167,9 +214,14 @@ type RenamePipelineEffects = , Error RenameError , Reader (TopologicalGraph (Module 'Desugared)) , UniqueGen + , Log.Log ] type Rename r = Members RenamePipelineEffects r +type InnerRename r = + ( Members RenamePipelineEffects r + , Member (Reader (Maybe (Module 'Desugared))) r -- the module we're renaming + ) runRenamePipeline :: IsPipeline r => @@ -178,7 +230,8 @@ runRenamePipeline :: Sem (EffectsAsPrefixOf RenamePipelineEffects r) a -> Sem r a runRenamePipeline graph st = - uniqueGenToIO + subsume + . uniqueGenToIO . runReader graph . runErrorOrReport @RenameError . evalState st @@ -189,20 +242,21 @@ qualifyIn mn (MaybeQualified n (Just m)) = do pure $ Qualified n m qualifyIn mn (MaybeQualified n Nothing) = pure $ Qualified n mn -qualifyTypeName :: Rename r => Located (MaybeQualified TypeName) -> Sem r (Located (Qualified TypeName)) +qualifyTypeName :: InnerRename r => Located (MaybeQualified TypeName) -> Sem r (Located (Qualified TypeName)) qualifyTypeName (Located sr (MaybeQualified n (Just m))) = do ensureExistsAndExposed m (Located sr (NTypeName n)) pure $ Located sr (Qualified n m) qualifyTypeName (Located sr (MaybeQualified n Nothing)) = do typeNames' <- use' (field' @"typeNames") + m <- ask case Map.lookup n typeNames' of - Nothing -> throw $ UnknownName (Located sr (NTypeName n)) + Nothing -> throw $ UnknownName (Located sr (NTypeName n)) m typeNames' Just ((Global (Located sr' (Qualified n' m))) :| []) -> pure $ Located sr' (Qualified n' m) Just ((Local _) :| []) -> error "can't have local type names" Just many -> throw $ AmbiguousTypeName (Located sr (NTypeName n)) many lookupGenericName :: - Rename r => + InnerRename r => (Ord name, ToName name) => Lens' RenameState (Map name (NonEmpty (VarRef name))) -> (Located Name -> NonEmpty (VarRef name) -> RenameError) -> @@ -211,17 +265,24 @@ lookupGenericName :: lookupGenericName _ _ (Located sr (MaybeQualified n (Just m))) = do ensureExistsAndExposed m (Located sr (toName n)) pure $ Located sr $ Global (Located sr (Qualified n m)) -lookupGenericName lens err (Located sr (MaybeQualified n Nothing)) = do +lookupGenericName lens ambiguousError (Located sr (MaybeQualified n Nothing)) = do names' <- use' lens - case Map.lookup n names' of - Just (v :| []) -> pure $ Located sr v - Just many -> throw $ err (Located sr $ toName n) many - Nothing -> throw $ UnknownName (Located sr $ toName n) - -lookupVarName :: Rename r => Located (MaybeQualified VarName) -> Sem r (Located (VarRef VarName)) + m <- ask + case m of + Nothing -> + case Map.lookup n names' of + Nothing -> throw $ UnknownName (Located sr $ toName n) m names' + Just (v :| []) -> pure $ Located sr v + Just many -> throw $ ambiguousError (Located sr $ toName n) many + Just m -> case maybe [] (NonEmpty.filter ((m `isImportedBy`) . fmap toName)) (Map.lookup n names') of + [v] -> pure $ Located sr v + [] -> throw $ UnknownName (Located sr $ toName n) (Just m) names' + (x : xs) -> throw $ ambiguousError (Located sr $ toName n) (x :| xs) + +lookupVarName :: InnerRename r => Located (MaybeQualified VarName) -> Sem r (Located (VarRef VarName)) lookupVarName = lookupGenericName (field' @"varNames") AmbiguousVarName -lookupTypeName :: Rename r => Located (MaybeQualified TypeName) -> Sem r (Located (Qualified TypeName)) +lookupTypeName :: InnerRename r => Located (MaybeQualified TypeName) -> Sem r (Located (Qualified TypeName)) lookupTypeName n = lookupGenericName (field' @"typeNames") AmbiguousTypeName n <<&>> \case Local _ -> error "can't have local type names" @@ -240,7 +301,8 @@ sortDeclarations :: [RenamedDeclaration] -> Sem r [RenamedDeclaration] sortDeclarations = pure rename :: Rename r => Module 'Desugared -> Sem r (Module 'Renamed) -rename = +rename m = do + Log.debug $ "Renaming module " <> showPretty (m ^. _Unwrapped % unlocated % field' @"name") traverseOf (_Unwrapped % unlocated) ( \m' -> do @@ -248,10 +310,11 @@ rename = traverseOf_ (field' @"declarations" % each) (addDeclarationToContext False) m' -- add our own declarations to field' context exposing' <- renameExposing (m' ^. field' @"name" % unlocated) (m' ^. field' @"exposing") imports' <- traverse renameImport (m' ^. field' @"imports") - declarations' <- traverse renameDeclaration (m' ^. field' @"declarations") + declarations' <- runReader (Just m) (traverse renameDeclaration (m' ^. field' @"declarations")) sorted <- sortDeclarations declarations' pure (Module' (m' ^. field' @"name") exposing' imports' sorted) ) + m where renameExposing :: Rename r => ModuleName -> Exposing 'Desugared -> Sem r (Exposing 'Renamed) renameExposing _ ExposingAll = pure ExposingAll @@ -311,14 +374,16 @@ addDeclarationToContext _ decl = do traverseOf_ (each % _1 % unlocated) (\tn -> modify $ over (the @"typeNames") $ insertMerging tn (global tn)) ctors _ -> pass -ensureExistsAndExposed :: Rename r => ModuleName -> Located Name -> Sem r () +-- | Ensure that a name exists in the context and is exposed +ensureExistsAndExposed :: InnerRename r => ModuleName -> Located Name -> Sem r () ensureExistsAndExposed mn n = do modules <- ask + thisMod <- ask case moduleFromName mn modules of Nothing -> throw $ UnknownModule mn Just m -> do unless (elementExistsInModule m (n ^. unlocated)) $ throw $ NonExistentModuleDeclaration mn n - unless (isExposingAndExists m (n ^. unlocated)) $ throw $ UnknownName n + unless (isExposingAndExists m (n ^. unlocated)) $ throw $ UnknownName @Name n thisMod mempty elementExistsInModule :: Module 'Desugared -> Name -> Bool elementExistsInModule m' n' = @@ -331,6 +396,9 @@ elementExistsInModule m' n' = ) (m' ^. _Unwrapped % unlocated % field' @"declarations") +{- | Tests that n is exposed in m +I.e. that it is in the exposing list, or that the module is exposing everything +-} isExposingAndExists :: Module 'Desugared -> Name -> Bool isExposingAndExists m n = let mn = m ^. _Unwrapped % unlocated % field' @"name" % unlocated @@ -344,10 +412,40 @@ isExposingAndExists m n = isExposition mn (NTypeName tn) (ExposedTypeAndAllConstructors tn') = MaybeQualified tn (Just mn) == tn' ^. unlocated isExposition _ _ _ = False -renameDeclaration :: Rename r => DesugaredDeclaration -> Sem r RenamedDeclaration +{- | Tests that m imports n +This is determined by 2 conditions: +n's module name is in the import list of m +n is exposed by the import +-} +isImportedBy :: Module 'Desugared -> VarRef Name -> Bool +isImportedBy _ (Local _) = True -- we always assume a local variable exists, even if it doesn't. this condition is checked elsewhere +isImportedBy m (Global (Located _ (Qualified n' nameMod))) = do + (nameMod == m ^. _Unwrapped % unlocated % field' @"name" % unlocated) || isImportedBy' m n' nameMod + where + isImportedBy' :: Module 'Desugared -> Name -> ModuleName -> Bool + isImportedBy' m n' nameMod = do + let mn = m ^. _Unwrapped % unlocated % field' @"name" % unlocated + let imports' = m ^. _Unwrapped % unlocated % field' @"imports" + case findImport nameMod imports' of + Nothing -> False + Just imp -> do + let exposing' = imp ^. _Unwrapped % unlocated % field' @"exposing" + case exposing' of + ExposingAll -> True + ExposingSome es -> any (isExposition mn n') es + findImport :: ModuleName -> [Import 'Desugared] -> Maybe (Import 'Desugared) + findImport mn' = find ((mn' ==) . view (_Unwrapped % unlocated % field' @"importing" % unlocated)) + + isExposition :: ModuleName -> Name -> Exposition 'Desugared -> Bool + isExposition mn (NVarName vn) (ExposedValue vn') = MaybeQualified vn (Just mn) == vn' ^. unlocated + isExposition mn (NTypeName tn) (ExposedType tn') = MaybeQualified tn (Just mn) == tn' ^. unlocated + isExposition mn (NTypeName tn) (ExposedTypeAndAllConstructors tn') = MaybeQualified tn (Just mn) == tn' ^. unlocated + isExposition _ _ _ = False + +renameDeclaration :: InnerRename r => DesugaredDeclaration -> Sem r RenamedDeclaration renameDeclaration decl@(Declaration ld) = Declaration <$> traverseOf unlocated renameDeclaration' ld where - renameDeclaration' :: Rename r => DesugaredDeclaration' -> Sem r RenamedDeclaration' + renameDeclaration' :: InnerRename r => DesugaredDeclaration' -> Sem r RenamedDeclaration' renameDeclaration' fd = do -- qualify the name with the module name let name' = @@ -360,10 +458,10 @@ renameDeclaration decl@(Declaration ld) = Declaration <$> traverseOf unlocated r pure $ Declaration' (fd ^. field' @"moduleName") name' body' - renameDeclarationBody :: (Rename r, Member (Reader (Maybe DesugaredDeclaration)) r) => DesugaredDeclarationBody -> Sem r RenamedDeclarationBody + renameDeclarationBody :: (InnerRename r, Member (Reader (Maybe DesugaredDeclaration)) r) => DesugaredDeclarationBody -> Sem r RenamedDeclarationBody renameDeclarationBody (DeclarationBody ldb) = DeclarationBody <$> traverseOf unlocated renameDeclarationBody' ldb - renameDeclarationBody' :: (Rename r, Member (Reader (Maybe DesugaredDeclaration)) r) => DesugaredDeclarationBody' -> Sem r RenamedDeclarationBody' + renameDeclarationBody' :: (InnerRename r, Member (Reader (Maybe DesugaredDeclaration)) r) => DesugaredDeclarationBody' -> Sem r RenamedDeclarationBody' renameDeclarationBody' (Value val _ ty ann) = scoped $ do ty' <- traverse (traverseOf (_Unwrapped % _1 % unlocated) (renameType True)) ty val' <- renameExpr val @@ -383,7 +481,7 @@ renameDeclaration decl@(Declaration ld) = Declaration <$> traverseOf unlocated r let ann' = coerceTypeDeclAnnotations ann pure $ TypeDeclaration vars' ty' ann' -renameTypeDeclaration :: Rename r => ModuleName -> DesugaredTypeDeclaration -> Sem r RenamedTypeDeclaration +renameTypeDeclaration :: InnerRename r => ModuleName -> DesugaredTypeDeclaration -> Sem r RenamedTypeDeclaration renameTypeDeclaration _ (Alias t) = do t' <- traverseOf (_Unwrapped % _1 % unlocated) (renameType False) t pure $ Alias t' @@ -396,7 +494,7 @@ renameTypeDeclaration thisMod (ADT constructors) = do -- | Renames a type, qualifying type constructors and type variables where necessary renameType :: - Rename r => + InnerRename r => -- | If new type variables are allowed - if False, this will throw an error if a type variable is not in scope -- This is useful for type declarations, where something like @type Invalid a = b@ would clearly be invalid -- But for local type annotations, we want to allow this, as it may be valid @@ -422,7 +520,7 @@ renameType antv (RecordType ln) = RecordType <$> traverse (traverseOf (_2 % _Unw renameType antv (TupleType ts) = TupleType <$> traverse (traverseOf (_Unwrapped % _1 % unlocated) (renameType antv)) ts renameType antv (ListType t) = ListType <$> traverseOf (_Unwrapped % _1 % unlocated) (renameType antv) t -renameExpr :: (Rename r, Member (Reader (Maybe DesugaredDeclaration)) r) => DesugaredExpr -> Sem r RenamedExpr +renameExpr :: (InnerRename r, Member (Reader (Maybe DesugaredDeclaration)) r) => DesugaredExpr -> Sem r RenamedExpr renameExpr (Expr' (Block es)) = desugarBlock es renameExpr e@(Expr' (Let{})) = desugarBlock (e :| []) renameExpr (Expr le@(Located loc _, _)) = @@ -498,10 +596,10 @@ renameExpr (Expr le@(Located loc _, _)) = renameExpr' (Let{}) = error "renameExpr': Let should be handled by renameExpr" renameExpr' (Block{}) = error "renameExpr': Block should be handled by renameExpr" -renameBinaryOperator :: Rename r => DesugaredBinaryOperator -> Sem r RenamedBinaryOperator +renameBinaryOperator :: InnerRename r => DesugaredBinaryOperator -> Sem r RenamedBinaryOperator renameBinaryOperator (MkBinaryOperator op) = MkBinaryOperator <$> traverseOf unlocated renameBinaryOperator' op where - renameBinaryOperator' :: Rename r => DesugaredBinaryOperator' -> Sem r RenamedBinaryOperator' + renameBinaryOperator' :: InnerRename r => DesugaredBinaryOperator' -> Sem r RenamedBinaryOperator' renameBinaryOperator' (SymOp o) = do op' <- lookupVarName (OperatorVarName <<$>> o) let onlyOpName (OperatorVarName o') = o' @@ -520,7 +618,7 @@ renameBinaryOperator (MkBinaryOperator op) = MkBinaryOperator <$> traverseOf unl pure $ Global (ConName <<$>> tn) pure $ Infixed op' -renamePattern :: Rename r => DesugaredPattern -> Sem r RenamedPattern +renamePattern :: InnerRename r => DesugaredPattern -> Sem r RenamedPattern renamePattern (Pattern fp@(Located loc _, _)) = Pattern <$> bitraverse @@ -528,7 +626,7 @@ renamePattern (Pattern fp@(Located loc _, _)) = (traverse (traverseOf (_Unwrapped % _1 % unlocated) (renameType False))) fp where - renamePattern' :: Rename r => DesugaredPattern' -> Sem r RenamedPattern' + renamePattern' :: InnerRename r => DesugaredPattern' -> Sem r RenamedPattern' renamePattern' (IntegerPattern i) = pure $ IntegerPattern i renamePattern' (FloatPattern i) = pure $ FloatPattern i renamePattern' (StringPattern i) = pure $ StringPattern i @@ -583,7 +681,7 @@ patternToVarName (Pattern (Located _ p, _)) = ConsPattern _ -> mn "cons" UnitPattern -> "unit" -patternToMatch :: (Rename r, Member (Reader (Maybe DesugaredDeclaration)) r) => DesugaredPattern -> DesugaredExpr -> Sem r (Located (Unique VarName), RenamedExpr) +patternToMatch :: (InnerRename r, Member (Reader (Maybe DesugaredDeclaration)) r) => DesugaredPattern -> DesugaredExpr -> Sem r (Located (Unique VarName), RenamedExpr) -- Special case, no match needed -- We can just turn \x -> x into \x -> x patternToMatch (Pattern (Located _ (VarPattern vn), _)) body = do @@ -611,12 +709,12 @@ This is a little bit special because patterns have to be converted to match expr For example, @\(a, b) -> a@ becomes @\ab_ -> match ab_ with (a, b) -> a@ -} -renameLambda :: (Rename r, Member (Reader (Maybe DesugaredDeclaration)) r) => DesugaredPattern -> DesugaredExpr -> Sem r RenamedExpr' +renameLambda :: (InnerRename r, Member (Reader (Maybe DesugaredDeclaration)) r) => DesugaredPattern -> DesugaredExpr -> Sem r RenamedExpr' renameLambda p e = do (arg, match) <- patternToMatch p e pure (Lambda arg match) -desugarBlock :: (Rename r, Member (Reader (Maybe DesugaredDeclaration)) r) => NonEmpty DesugaredExpr -> Sem r RenamedExpr +desugarBlock :: (InnerRename r, Member (Reader (Maybe DesugaredDeclaration)) r) => NonEmpty DesugaredExpr -> Sem r RenamedExpr desugarBlock (e@(Expr' (Let{})) :| []) = do decl <- ask @(Maybe DesugaredDeclaration) throw (BlockEndsWithLet e (fmap (view (_Unwrapped % unlocated % the @"body")) decl)) diff --git a/stdlib/prelude.elr b/stdlib/prelude.elr index 0b7e944..c02b473 100644 --- a/stdlib/prelude.elr +++ b/stdlib/prelude.elr @@ -1,5 +1,6 @@ module Prelude import Elara.Prim +import List def (*>) : IO a -> IO b -> IO b let (*>) a b = a >>= \x -> b diff --git a/test/Infer/Common.hs b/test/Infer/Common.hs index bc01a88..a700e1d 100644 --- a/test/Infer/Common.hs +++ b/test/Infer/Common.hs @@ -39,7 +39,6 @@ import Polysemy.Log import Polysemy.Reader (runReader) import Polysemy.State (State) import Print (showPretty) -import Test.HUnit (assertFailure) pattern Forall' :: UniqueTyVar -> Domain -> Type () -> Type () pattern Forall' name domain t = Forall () () name domain t @@ -65,7 +64,14 @@ inferFully source = finalisePipeline . runInferPipeline . runShuntPipeline . run tokens <- readTokensWith fp (toString source) parsed <- parsePipeline exprParser fp (toString source, tokens) desugared <- runDesugarPipeline $ runDesugar $ desugarExpr parsed - renamed <- runRenamePipeline (createGraph []) primitiveRenameState (runReader Nothing $ renameExpr desugared) + renamed <- + runRenamePipeline + (createGraph []) + primitiveRenameState + ( runReader (Nothing @(Module 'Desugared)) $ + runReader (Nothing @(Declaration 'Desugared)) $ + renameExpr desugared + ) shunted <- runReader mempty $ shuntExpr renamed inferExpression shunted Nothing >>= completeInference diff --git a/test/Shunt.hs b/test/Shunt.hs index bf34116..4b987f1 100644 --- a/test/Shunt.hs +++ b/test/Shunt.hs @@ -4,6 +4,7 @@ import Common (diagShouldSucceed) import Elara.AST.Generic import Elara.AST.Generic.Instances () import Elara.AST.Generic.Pattern (functionCall, int, var) +import Elara.AST.Module import Elara.AST.Name (OpName (..), Qualified (..), VarName (OperatorVarName)) import Elara.AST.Region (generatedLocated) import Elara.AST.Select (LocatedAST (..), UnlocatedAST (UnlocatedShunted)) @@ -33,7 +34,7 @@ loadExpr source = finalisePipeline . runShuntPipeline . runRenamePipeline (creat parsed <- parsePipeline exprParser fp (toString source, tokens) desugared <- runDesugarPipeline $ runDesugar $ desugarExpr parsed - renamed <- runReader Nothing $ renameExpr desugared + renamed <- runReader Nothing $ runReader (Nothing :: Maybe (Module 'Desugared)) $ renameExpr desugared runReader fakeOperatorTable $ fixExpr renamed mkFakeVar :: OpName -> VarRef VarName