Skip to content

[Concurrency] SILGenModule::emitEntryPoint crashes when exit hasn't been imported #71424

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

Merged
merged 1 commit into from
Feb 8, 2024

Conversation

ian-twilightcoder
Copy link
Contributor

If exit hasn't been imported, SILGenModule::emitEntryPoint crashes because it doesn't synthesize an exit function like SILGenFunction::emitCallToMain does. Make it do so.

rdar://122413238

Copy link
Member

@etcwilde etcwilde left a comment

Choose a reason for hiding this comment

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

Hmm, I guess we don't have any test cases that test async top-level code in an environment that doesn't have an exit imported already. I think we should be able to create one with -parse-stdlib and maybe a few other flags.
Something like swiftc -parse-stdlib <foo.swift> and the below should at least get close to repro'ing the assert:

import _Concurrency
func foo() async { }
await foo()

@ian-twilightcoder
Copy link
Contributor Author

Hmm, I guess we don't have any test cases that test async top-level code in an environment that doesn't have an exit imported already. I think we should be able to create one with -parse-stdlib and maybe a few other flags. Something like swiftc -parse-stdlib <foo.swift> and the below should at least get close to repro'ing the assert:

import _Concurrency
func foo() async { }
await foo()

Would this work from async_main_no_concurrency.swift?

// RUN: %target-typecheck-verify-swift -parse-as-library -disable-availability-checking -parse-stdlib

Should I also add a @main struct?

@etcwilde
Copy link
Member

etcwilde commented Feb 6, 2024

Would this work from async_main_no_concurrency.swift?

// RUN: %target-typecheck-verify-swift -parse-as-library -disable-availability-checking -parse-stdlib

Something like that, yeah.

Should I also add a @main struct?

To test emitEntryPoint, no. We want to emit an async top-level code snippet which uses that path instead of emitAsyncMain.

@ian-twilightcoder
Copy link
Contributor Author

Would this work from async_main_no_concurrency.swift?
// RUN: %target-typecheck-verify-swift -parse-as-library -disable-availability-checking -parse-stdlib

Something like that, yeah.

Should I also add a @main struct?

To test emitEntryPoint, no. We want to emit an async top-level code snippet which uses that path instead of emitAsyncMain.

We should probably have an explicit test for both though. Can we do that in a single test, i.e. with a top level @main struct and a top level async func, or do we need two tests for that?

@etcwilde
Copy link
Member

etcwilde commented Feb 7, 2024

We should probably have an explicit test for both though. Can we do that in a single test, i.e. with a top level @main struct and a top level async func, or do we need two tests for that?

I believe it needs to be in two tests since the #if directives don't just delete syntax like in C. The @main will not parse, even if we do something like this:

// RUN: %target-typecheck-verify-swift -parse-as-library -disable-availability-checking -parse-stdlib
// RUN: %target-typecheck-verify-swift -disable-availability-checking -parse-stdlib -DTOP_LEVEL_TEST

func foo() async {}

#if TOP_LEVEL_TEST
await foo()
#else
@main struct Main {
  static func main() async {
    await foo()
  }
}

@ian-twilightcoder
Copy link
Contributor Author

@swift-ci smoke test

… been imported

If `exit` hasn't been imported, SILGenModule::emitEntryPoint crashes because it doesn't synthesize an exit function like SILGenFunction::emitCallToMain does. Make it do so.

rdar://122413238
@ian-twilightcoder
Copy link
Contributor Author

@swift-ci smoke test

@ian-twilightcoder ian-twilightcoder merged commit c734975 into swiftlang:main Feb 8, 2024
@ian-twilightcoder ian-twilightcoder deleted the fix-exit-crash branch February 8, 2024 00:54
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