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

Miscellaneous fixes #294

Merged
merged 8 commits into from
Sep 12, 2023
Merged

Miscellaneous fixes #294

merged 8 commits into from
Sep 12, 2023

Conversation

Pat-Lafon
Copy link
Contributor

  • Update actions/checkout to v4
  • Fixed an edge case in rust bril2json positions for the first row
  • Javascript has some pretty loose parsing rules, I modified brili to be a little more strict on the cli input it expects (related to mod_inv)
  • Modified the ts2bril tool to not unconditionally output the final endif label and corresponding jump when it isn't needed(related to bitshift and fact)
  • Changed brilirs to check for main function return types on --check

The typescript stuff could use a double check, I'm not super familiar with this language. I also don't use ts2bril to know all of the edge cases.

Copy link
Owner

@sampsyo sampsyo left a comment

Choose a reason for hiding this comment

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

A bunch of good stuff here! I have one thought about the builder library utility… let me know what you think.

* Checks whether the last emitted instruction in the current function is the specified op code.
* Useful for checking for terminating instructions.
*/
isLastEmittedEffectOp(op: bril.EffectOpCode): boolean {
Copy link
Owner

Choose a reason for hiding this comment

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

Seems like useful behavior! But the name is a little odd, in two ways:

  • Emitted: Maybe it would be a little more straightforward to just say it's the last op currently in the function? It seems less material that it's the last thing we emitted.
  • Effect: I think this would look for both effect and value ops, right?

Another alternative, FWIW, would be to just get the last (non-label) instruction. So the return type would be bril.Instruction?, and callers could get this behavior by doing stuff like lastInstr()?.op === "add".

Copy link
Contributor Author

@Pat-Lafon Pat-Lafon Sep 10, 2023

Choose a reason for hiding this comment

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

Sure, works for me.

I'll just note that I don't think the the ? sugar works on return types? microsoft/TypeScript#51332 Maybe I missed something obvious.

Instead I'm using bril.Instruction | undefined which the rest of the code base seems to do.

Copy link
Owner

Choose a reason for hiding this comment

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

Oops; you're absolutely right. I forgot that T? was a special argument thing rather than an actual type.

// Number accepts empty/whitespace only strings and rejects numbers with seperators
// Use both and only accept the intersection of the results?
let f2 = Number(s);
if (!isNaN(f) && f === f2) {
Copy link
Owner

Choose a reason for hiding this comment

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

Weird but true! It'll do.

ts2bril.ts Outdated
@@ -215,12 +215,18 @@ function emitBril(prog: ts.Node, checker: ts.TypeChecker): bril.Program {
// Statement chunks.
builder.buildLabel(thenLab);
emit(if_.thenStatement);
builder.buildEffect("jmp", [], undefined, [endLab]);
const then_branch_terminated = builder.isLastEmittedEffectOp("ret");
Copy link
Owner

Choose a reason for hiding this comment

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

A little tricky, but makes sense!

Copy link
Owner

@sampsyo sampsyo left a comment

Choose a reason for hiding this comment

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

This looks perfect; thanks!!

@sampsyo sampsyo merged commit c543ae2 into sampsyo:main Sep 12, 2023
16 checks passed
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.

2 participants