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

(playdate support) delimcc.c is compiled even if Continuations isn't used #3885

Open
kubukoz opened this issue Apr 17, 2024 · 4 comments
Open

Comments

@kubukoz
Copy link
Contributor

kubukoz commented Apr 17, 2024

To reproduce:

  1. Add this line to delimcc.c, just to make it clear that the code is being included
diff --git a/nativelib/src/main/resources/scala-native/delimcc.c b/nativelib/src/main/resources/scala-native/delimcc.c
index bd00eb6aa..dd0597d1e 100644
--- a/nativelib/src/main/resources/scala-native/delimcc.c
+++ b/nativelib/src/main/resources/scala-native/delimcc.c
@@ -1,4 +1,6 @@
 #if defined(SCALANATIVE_COMPILE_ALWAYS) || defined(__SCALANATIVE_DELIMCC)
+
+#error "this shouldn't happen!"
 #include "delimcc.h"
 #include <stddef.h>
 #include <stdio.h>
  1. Publish a snapshot
  2. Try to link an app/library, even a "hello world" or a no-op main.

Output:

[info] Linking (multithreadingEnabled=true, disable if not used) (322 ms)
[info] Discovered 907 classes and 5623 methods after classloading
[info] Checking intermediate code (quick) (4 ms)
[info] Multithreading was not explicitly enabled - initial class loading has not detected any usage of system threads. Multithreading support will be disabled to improve performance.
[info] Linking (multithreadingEnabled=false) (277 ms)
[info] Discovered 774 classes and 4690 methods after classloading
[info] Checking intermediate code (quick) (2 ms)
[info] Discovered 749 classes and 3668 methods after optimization
[info] Optimizing (debug mode) (156 ms)
[info] Produced 43 LLVM IR files
[info] Generating intermediate code (413 ms)
[error] /Users/kubukoz/projects/demos/target/scala-3.3.3/native/dependencies/nativelib_native0.5_3-0/scala-native/delimcc.c:3:2: error: "this shouldn't happen!"
[error] #error "this shouldn't happen!"
[error]  ^
[error] 1 error generated.
[info] Compiling to native code (1524 ms)
[error] stack trace is suppressed; run last Compile / nativeLink for the full output
[error] stack trace is suppressed; run last Compile / nativeLink for the full output
[error] stack trace is suppressed; run last Compile / nativeLink for the full output
[error] stack trace is suppressed; run last Compile / nativeLink for the full output
[error] stack trace is suppressed; run last Compile / nativeLink for the full output
[error] stack trace is suppressed; run last Compile / nativeLink for the full output
[info] Total (2502 ms)
[error] Failed to compile /Users/kubukoz/projects/demos/target/scala-3.3.3/native/dependencies/nativelib_native0.5_3-0/scala-native/delimcc.c
[error] (Compile / nativeLink) Failed to compile /Users/kubukoz/projects/demos/target/scala-3.3.3/native/dependencies/nativelib_native0.5_3-0/scala-native/delimcc.c

Example app setup (requires a publish of 0.5.1-SNAPSHOT): https://github.com/kubukoz/demos/compare/sn-continuations-repro?expand=1

@ekrich
Copy link
Member

ekrich commented Apr 17, 2024

Won't argue that but if you look how SCALANATIVE_COMPILE_ALWAYS is used it is always like the following on the whole file:

#if defined(SCALANATIVE_COMPILE_ALWAYS) || defined(__SCALANATIVE_POSIX_PTHREAD)
#include <pthread.h>

Our glue code pthread.c has that code. Then here on the Scala side - https://github.com/scala-native/scala-native/blob/main/posixlib/src/main/scala/scala/scalanative/posix/pthread.scala#L12-L15

So if that Scala code is optimized away then no define.

@kubukoz
Copy link
Contributor Author

kubukoz commented Apr 17, 2024

right, there's a lot of this pattern in the codebase, and it seems to work correctly for my needs most of the time - the only offender I've found so far is delimcc.

@ekrich
Copy link
Member

ekrich commented Apr 18, 2024

That is not really the one you want to use because that is for the glue code. I put a note on this issue which might be better.
#3877

@ekrich
Copy link
Member

ekrich commented Apr 18, 2024

The delimcc is another factor - that should be a feature option somehow.

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

No branches or pull requests

2 participants