Skip to content

Conversation

ringabout
Copy link
Member

@ringabout ringabout commented Oct 18, 2024

closes #75
ref nim-lang/threading#79

Or only when =sink is disabled for byRef

(isAnalysableFieldAccess(dest, c.owner) and isFirstWrite(dest, c)))) or
isNoInit(dest) or IsReturn in flags:
isNoInit(dest) or IsReturn in flags or
tfByRef in dest.typ.flags:
Copy link
Member

Choose a reason for hiding this comment

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

I think the logic should be "it's .byref and also has its =sink disabled".

Copy link
Member Author

Choose a reason for hiding this comment

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

make sense

@ringabout ringabout changed the title .byref always optimizes sink call into a bitwise memcopy .byref always optimizes sink call into a bitwise memcopy if =sink is disabled Oct 19, 2024
@Araq
Copy link
Member

Araq commented Oct 19, 2024

This is still not correct as it can introduce leaks for code like var x = create(); x = create(). The idea here is that .byref types do not have any bitwise copies. We need to rethink this. It probably means the whole idea of =sink() .error is just wrong. =sink is fine and doesn't copy and shallow copies are prevented by .byref.

@darkestpigeon
Copy link
Contributor

darkestpigeon commented Oct 21, 2024

I usually use =copy() .error and =sink() .error for types that are used to communicate between multiple threads (perhaps some foreign) and the object needs to be pinned to a particular address. This both signals intent and prevents dumb errors (although moving an object by accident is rare). Will .byref cover this case correctly?

@Araq
Copy link
Member

Araq commented Oct 22, 2024

I think so, yes, but making =sink an .error just because you want to tie the object to a stack location is wrong regardless.

@ringabout ringabout closed this Sep 12, 2025
@ringabout ringabout deleted the pr_dujebfr branch September 12, 2025 14:04
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.

Problem with the create* API of synchronization primitives

3 participants