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

Remove functions/methods that work on the global context #54

Merged
merged 1 commit into from
Sep 19, 2023

Conversation

aykevl
Copy link
Member

@aykevl aykevl commented Sep 18, 2023

The global context should almost never be used, but it's very easy to use accidentally. Therefore, I'd like to remove all convenience functions that use the global context.

All functionality that got removed is still accessible as methods on llvm.Context, and the global context can be obtained using llvm.GlobalContext(). So no actual functionality is lost, just the very easy to misuse "convenience" functions.

@rj45 any opinion on this? Because I suspect you're the only other user of this package and this is a breaking API change.

aykevl added a commit to tinygo-org/tinygo that referenced this pull request Sep 18, 2023
This usually works by chance, but leads to crashes. So we should never
ever do this.

I'm pretty sure this is the crash behind this issue: #3894

It may also have caused this crash: #3874

I have a suspicion this is also behind the rather crash-prone CircleCI
jobs, that we haven't been able to find the source of. But we'll find
out soon enough once this fix is merged.

To avoid hitting this issue again in the future, I've created a PR to
remove these dangerous functions altogether from the go-llvm API:
tinygo-org/go-llvm#54
The global context should almost never be used, but it's very easy to
use accidentally. Therefore, I'd like to remove all convenience
functions that use the global context.

All functionality that got removed is still accessible as methods on
llvm.Context, and the global context can be obtained using
llvm.GlobalContext(). So no actual functionality is lost, just the very
easy to misuse "convenience" functions.
deadprogram pushed a commit to tinygo-org/tinygo that referenced this pull request Sep 19, 2023
This usually works by chance, but leads to crashes. So we should never
ever do this.

I'm pretty sure this is the crash behind this issue: #3894

It may also have caused this crash: #3874

I have a suspicion this is also behind the rather crash-prone CircleCI
jobs, that we haven't been able to find the source of. But we'll find
out soon enough once this fix is merged.

To avoid hitting this issue again in the future, I've created a PR to
remove these dangerous functions altogether from the go-llvm API:
tinygo-org/go-llvm#54
@aykevl aykevl mentioned this pull request Sep 19, 2023
@rj45
Copy link
Contributor

rj45 commented Sep 19, 2023

@aykevl I agree with you on this one. If I am using any of these functions it's a bug I am happy to fix. I am trying to have my test suite run in parallel and I am not sure if Go's race detector would find any bugs where I have accidentally used the global context. I believe I am currently experiencing some flakes due to data races and I don't think the race detector found them so this could very well be the cause. So thank you!

@aykevl
Copy link
Member Author

aykevl commented Sep 19, 2023

I am trying to have my test suite run in parallel and I am not sure if Go's race detector would find any bugs where I have accidentally used the global context.

It does not. The only symptom I know is weird crashes, and that could have lots of causes (not just from using the global context). In my experience, segmentation faults are one of the more common crashes.

I believe I am currently experiencing some flakes due to data races and I don't think the race detector found them so this could very well be the cause.

Yeah, the global context is inherently not thread safe, so it should never be used from multiple goroutines at the same time. The only way to make the compiler work in parallel is by using separate contexts (and never use the same context from more than one goroutine or thread).

Anyway, thank you for your feedback!

@aykevl aykevl merged commit ffd0534 into master Sep 19, 2023
12 checks passed
@aykevl aykevl deleted the remove-global-context branch September 19, 2023 19:11
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