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

fix(semantic)!: ensure program outlives semantic #8455

Merged
merged 7 commits into from
Jan 16, 2025

Conversation

valeneiko
Copy link
Contributor

@valeneiko valeneiko commented Jan 12, 2025

fixes: #8437

In semantic builder make sure Program reference has a lifetime of the Arena.

Copy link

graphite-app bot commented Jan 12, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

@github-actions github-actions bot added A-linter Area - Linter A-parser Area - Parser A-semantic Area - Semantic A-minifier Area - Minifier A-transformer Area - Transformer / Transpiler A-codegen Area - Code Generation A-prettier Area - Prettier A-isolated-declarations Isolated Declarations A-editor Area - Editor and Language Server labels Jan 12, 2025
@valeneiko valeneiko changed the title semantic: ensure program outlives semantic fix(semantic): ensure program outlives semantic Jan 12, 2025
@github-actions github-actions bot added the C-bug Category - Bug label Jan 12, 2025
Copy link

codspeed-hq bot commented Jan 12, 2025

CodSpeed Performance Report

Merging #8455 will not alter performance

Comparing valeneiko:fix-semantic-lifetimes (d0358eb) with main (04bc259)

Summary

✅ 32 untouched benchmarks

@Boshen
Copy link
Member

Boshen commented Jan 13, 2025

pub program: &'a mut Program<'a> from ParserReturn doesn't feel right, let's see if @overlookmotel knows what the underly problem is.

@overlookmotel
Copy link
Contributor

I've written up my thoughts on this problem in #8437 (comment) and #8461.

Personally, I quite like the idea of parser returning &mut Program. BUT that's a large breaking change, and I don't think it's necessary to fix this issue. I think just changing SemanticBuilder::build to take a &'a Program<'a> should be sufficient to squash the bug.

So I suggest we go one step at a time - fix #8437 first, then discuss API changes after. I have some other thoughts about API, and if we're going to make breaking changes, it'd be preferable to do that only once.

Or have I misunderstood? Is parser returning &mut Program necessary to fix the bug?

@valeneiko
Copy link
Contributor Author

Changing parser return type is not necessary. But we would still need to update all usages of semantic to first copy the program into the allocator and then use the new reference.

let program = alloc.alloc(parserReturn.program);
let semanticReturn = SemanticBuilder::new().build(program);

@valeneiko
Copy link
Contributor Author

@overlookmotel I've updated the PR to just fix semantic.

@overlookmotel overlookmotel force-pushed the fix-semantic-lifetimes branch from 1684b92 to d0358eb Compare January 15, 2025 18:41
@overlookmotel overlookmotel changed the title fix(semantic): ensure program outlives semantic fix(semantic)!: ensure program outlives semantic Jan 15, 2025
Copy link
Contributor

@overlookmotel overlookmotel left a comment

Choose a reason for hiding this comment

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

Thanks very much for doing this, and thanks for reverting the changes to ParserReturn.

Unfortunately this does make the API harder to use, but that's necessary to make it correct. SemanticBuilderReturn does borrow the Program for the duration of its existence, so we need to make sure it does actually work that way.

I've pushed 1 extra commit to remove unreachable_unchecked. The purpose of that part of the coverage runner is to make sure that Semantic contains what it should do, so it's best not to make unsafe assertions about the very thing we're trying to check.

Apart from that, great!

This is a breaking change, so before we merge this we should make sure it doesn't break downstream consumers in a terrible way. I'll try it out with Rolldown now, and will report back.

Copy link
Contributor

@overlookmotel overlookmotel left a comment

Choose a reason for hiding this comment

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

Not causing major problems in Rolldown. Given that's a large codebase which makes heavy use of Oxc, likely it's not going to cause too many problems in other downstream projects either.

@Boshen Boshen merged commit 4ce6329 into oxc-project:main Jan 16, 2025
28 checks passed
@valeneiko valeneiko deleted the fix-semantic-lifetimes branch January 16, 2025 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area - Code Generation A-editor Area - Editor and Language Server A-isolated-declarations Isolated Declarations A-linter Area - Linter A-minifier Area - Minifier A-parser Area - Parser A-prettier Area - Prettier A-semantic Area - Semantic A-transformer Area - Transformer / Transpiler C-bug Category - Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ast: Out of bounds memory access crash in AST Vititor
3 participants