Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐈🐈🐈 #657

Merged
merged 10 commits into from
Aug 30, 2023
Merged

🐈🐈🐈 #657

merged 10 commits into from
Aug 30, 2023

Conversation

STRd6
Copy link
Contributor

@STRd6 STRd6 commented Aug 28, 2023

I scope creeped this to now allow for .civet in our Civet build.

Key ideas:

  • No checked in generated files to clutter up diffs
  • Allow us to use .civet as our source files when building and testing
  • Not substantially slower or requiring extra bootstrapping or downloads
  • It's how TS does it: a devDependency on a previously published stable version.

Also converted lib.ts -> lib.civet it uncovered several bugs but only needed minor changes. It is however a little slower (~5s) to parse and that is sad. Hopefully we can speed up the parser at it will be no worse than TS.

Fixes #641 Config update:

  • Removed config.civet from name of config files to check
  • If not found in .config dir keep looking rather than return null
  • Added some basic tests
  • Simpler dynamic import

Copy link
Collaborator

@edemaine edemaine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think having .civet as a format would be useful, partly because we don't (yet) support YAML, and Civet is a good approximation thereof. I agree it can only use the default config, but I think that's fine when all you're writing is

export default
  coffeeCompat: true

but I'd still rather write that than

{"coffeeCompat": true}

I'm hopeful that civetconfig.civet is a sufficiently specific name that it won't conflict with user's filenames... Probably 🐈.civet too. But we obviously do need to remove config.civet.

@STRd6 STRd6 requested a review from edemaine August 29, 2023 04:43
@@ -3,9 +3,7 @@
import { readFile } from 'fs/promises';
import { pathToFileURL, fileURLToPath } from 'url';

import CoffeeScript, { compile } from "coffeescript";
// Handle cjs .coffee files
CoffeeScript.register()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's nice to keep this registration in case others want to use this as a CoffeeScript ESM handler. So I lean toward keeping it, but it's also OK to remove it and leave this for a CoffeeScript issue (actually jashkenas/coffeescript#5447).

@@ -0,0 +1,72 @@
import path from "path";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason for the move from CoffeeScript? I preferred that version, and it's more consistent with the rest of the code (e.g. main.coffee). Ah, I see, but we want to move toward full typechecking, so this makes sense.

"🐈.civet",
"civetconfig.json",
"civetconfig.civet",
].includes(name)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name in ['config.civet', 'civet.json', 'civetconfig.civet', 'civetconfig.json'] has a more efficient compilation in CoffeeScript than this. But I guess we could do even better with a Set (hoisted to global scope).

@edemaine
Copy link
Collaborator

Wait, how can main be .civet? Isn't it needed to compile with the esbuild plugin?

@STRd6
Copy link
Contributor Author

STRd6 commented Aug 29, 2023

Wait, how can main be .civet? Isn't it needed to compile with the esbuild plugin?

I added a devDependecy for a previously published civet version so we can us that in development as long as we reference it from node_modules.

Copy link
Collaborator

@edemaine edemaine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, I see it now. Amazing — we can now live the Civet future!!

Is it possible to switch lib.ts over too? Or is there an issue when mixing with Hera? That is where we could probably benefit most from Civet.

@@ -0,0 +1,72 @@
import path from "path";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a high priority, but now that we're using Civet instead of TS, we could make this code closer to the CoffeeScript version you're replacing here (but with type annotations). Could be saved for the future though.

@STRd6 STRd6 changed the title 🐈.json 🐈🐈🐈 Aug 30, 2023
@STRd6 STRd6 requested a review from edemaine August 30, 2023 02:59
Copy link
Collaborator

@edemaine edemaine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So exciting!!! Civetception!

"./build/hera-esm.mjs",
"./dist/esm.mjs"
"./node_modules/@danielx/civet/dist/esm.mjs"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this use the correct version of Civet? We need tests to run in the repo version, not in the released version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the version that will parse the source and test files. Once parsed the tests are run against main.civet, lib.civet, parser.hera, etc.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, got it. (If only we could add a comment to a JSON file. 😉)

That seems fine, because we don't generally use fancy features in the test infrastructure, only inside the triple quotes. Actually, in some ways, it will be an improvement; I've run into issues where I break the Civet compiler (and ran yarn build) and then yarn test crashes, with unhelpful error messages. This should avoid that sort of issue.

@@ -225,7 +225,7 @@ export base64Encode = (src) ->

# Accelerate VLQ decoding with a lookup table
vlqTable = new Uint8Array(128)
vlqChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
vlqChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
do ->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand how this do -> works without coffeeCompat mode enabled. Are we sure it's actually running? Funny, there was already a coffeeCompat flag in a .coffee file. Is the following comment (at the top of the file) of interest?

# NOTE: Hera has an updated version of this file converted from CoffeeScript to Civet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that directive was from some earlier testing.

We should probably export these utils from Hera as the definitive source eventually.

@@ -43,15 +42,14 @@
"@cspotcode/source-map-support": "^0.8.1"
},
"devDependencies": {
"@danielx/civet": "^0.6.26",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd feel safer if this were a pinned dep (no ^). Given how we tend to change things and just bump the patch number. 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the lockfile should take care of it but being explicit here would also be fine.

@edemaine
Copy link
Collaborator

By the way, it's also really great what a stress test this was, for both JavaScript and CoffeeScript compatibility. Thanks for writing down all the bugs you encountered. Time for another bug squashing session! 😄

@STRd6
Copy link
Contributor Author

STRd6 commented Aug 30, 2023

I'm still sad about the build getting slower with the conversion from lib.ts -> lib.civet but its not so bad as to hold this up.

We can try a few things in the future:

  • Optimization of the generated parser/grammar at the Hera level
  • Better optimized caching
  • Optimizations in the civet grammar / handlers
  • Convert to more idiomatic Civet in lib.civet (less code, fewer braces)

@STRd6 STRd6 merged commit 90daac5 into main Aug 30, 2023
3 checks passed
@STRd6 STRd6 deleted the 🐈.json branch August 30, 2023 22:56
@edemaine
Copy link
Collaborator

All good ideas. And I'd rather pay the price of slowness and be able to dogfood. Civet should speed our development too.

One thing we might try is profiling the compilation stage. I have no idea, for example, whether the dominant cost is running Hera rules/caching, or the parser.hera code blocks (if we can distinguish these, maybe somewhat because most blocks now call lib), or the AST postprocessing we do. You may be right that it's the Hera parsing cost, but it also wouldn't surprise me if there is still some quadratic behavior in AST processing (like say calling addParentPointers at multiple recursive levels). Knowing which is dominant would help focus optimization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Config.civet reserved
2 participants