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

fixes Thread initializer for ARC/ORC on Macos #20368

Merged
merged 6 commits into from
Sep 16, 2022
Merged

fixes Thread initializer for ARC/ORC on Macos #20368

merged 6 commits into from
Sep 16, 2022

Conversation

ringabout
Copy link
Member

Otherwise

2022-09-15T22:14:56.9592680Z /Users/runner/work/1/s/nimcache/tests/generics/tthread_generic.nim_4a8a08f09d37b73795649038408b5f33/@mtthread_generic.nim.c:100:101: error: scalar initializer cannot be empty
2022-09-15T22:14:56.9593710Z static NIM_CONST tyObject_Thread__zHU2p4cP5TKE0P9cAAcLY8g TM__4S7kGJlWA60L39cvweIkHuA_2 = {NIM_NIL, {}, NIM_NIL, {{(&NTIv2__Hlf80yaLZNgwpkXrygtUDA_)}, NIM_NIL, NIM_NIL}}

@@ -141,7 +141,7 @@ else:
header: "<pthread.h>".} = cint
else:
type
SysThread* {.importc: "pthread_t", header: "<sys/types.h>".} = object
SysThread* {.importc: "pthread_t", header: "<sys/types.h>".} = int
Copy link
Member Author

@ringabout ringabout Sep 16, 2022

Choose a reason for hiding this comment

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

posix.nim uses int type for all platforms:

type
  Pthread* {.importc: "pthread_t", header: "<sys/types.h>".} = int

@ringabout
Copy link
Member Author

ringabout commented Sep 16, 2022

Regarding the reason why it is specific to ARC/ORC is that ARC/ORC initializes the Thread object using const initializer while the importc symbol has the wrong types.

  of frEmbedded:
    # inheritance in C++ does not allow struct initialization: bug #18410
    if not p.module.compileToCpp and optTinyRtti in p.config.globalOptions:
      var tmp: TLoc
      if mode == constructRefObj:
        let objType = t.skipTypes(abstractInst+{tyRef})
        rawConstExpr(p, newNodeIT(nkType, a.lode.info, objType), tmp)
        linefmt(p, cpsStmts,
            "#nimCopyMem((void*)$1, (NIM_CONST void*)&$2, sizeof($3));$n",
            [rdLoc(a), rdLoc(tmp), getTypeDesc(p.module, objType, mapTypeChooser(a))])
      else:
        rawConstExpr(p, newNodeIT(nkType, a.lode.info, t), tmp)
        genAssignment(p, a, tmp, {})

And pthread_t is a pointer which should not be initialized by bracket expression.

typedef struct _opaque_pthread_t *__darwin_pthread_t;

Either ARC/ORC doesn't use static const to initialize importc objects or importc objects should have a right Nim type.

It should be related to #18844

@Varriount Varriount merged commit f6dc30e into devel Sep 16, 2022
@Varriount Varriount deleted the pr_fix_object branch September 16, 2022 20:35
@github-actions
Copy link
Contributor

Thanks for your hard work on this PR!
The lines below are statistics of the Nim compiler built from f6dc30e

Hint: mm: orc; threads: on; opt: speed; options: -d:release
164220 lines; 12.675s; 842.504MiB peakmem

capocasa pushed a commit to capocasa/Nim that referenced this pull request Mar 31, 2023
* fixes Thread initializer for ARC/ORC

* another try

* fix

* use int
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