-
Notifications
You must be signed in to change notification settings - Fork 59
Add atomics support in the standard library #1637
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
base: main
Are you sure you want to change the base?
Conversation
This way, we know more about what failed, and not get just "exception".
@kyouko-taiga : Do you have any idea why I get a "Sources/FrontEnd/TypeChecking/TypeChecker.swift:6183: Assertion failed: type already inferred" error on many of the tests on Ubuntu builds (see https://github.com/hylo-lang/hylo/actions/runs/12597537109/job/35110729555?pr=1637)? |
It means something causes the type checker to visit the same tree twice. If you point me at the test cases that are failing I can investigate if you want. |
The failures can be seen at https://github.com/hylo-lang/hylo/actions/runs/12597537109/job/35110729555?pr=1637.
Please note that these tests only fail on Ubuntul, I haven't seen any failures on MacOS. |
If the failure is so widespread I think there's something going wrong with your code generator. It's surprising that the error occurs only on Ubuntu but perhaps that's because you're generating a duplicate declaration only on this platform? My current theory is that two identical definitions are being fed to the type checker (which currently does not check for duplicate declaration). |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1637 +/- ##
==========================================
+ Coverage 88.33% 88.75% +0.42%
==========================================
Files 382 382
Lines 31548 31548
==========================================
+ Hits 27867 28000 +133
+ Misses 3681 3548 -133 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
StandardLibrary/Sources/LowLevel/Threading/AtomicRepresentable.hylo
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work. See inline comments.
StandardLibrary/Sources/LowLevel/Threading/AtomicRepresentable.hylo
Outdated
Show resolved
Hide resolved
/////////////////////////////////////////////////////////////////////////////// | ||
// MARK: IntPlatformAtomic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably don't need these comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They help me navigate in such big files like this. But, I'm fine if you want me to delete them.
// MARK: IntPlatformAtomic | ||
|
||
/// An atomic representation of Int. | ||
public type IntPlatformAtomic: Regular { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure to understand why we need a wrapped. Why can't we simply make Hylo.Int
conform to PlatformAtomic
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't remember the exact reason why I went this route.
I think one reason is that we might not have all primitive types to be "platform atomics" and, we might have "platform atomics" that are not necessarily primitive integers. But, I guess we can work around that easily.
I will try to use directly the basic integer types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember now the reason for this choice. I don't want to expose the atomic functions on types like Int
, Int32
, etc. This is why, these primitives are hidden behind other types.
public conformance IntPlatformAtomic: IntegerPlatformAtomic { | ||
|
||
public fun load(ordering: AtomicLoadOrdering) -> Value { | ||
if /*ordering == AtomicLoadOrdering.relaxed*/ ordering.value == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I understand that AtomicLoadOrdering.relaxed
has value 0 from this comment? If so why not create a global constant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tied this, but the current version of the compiler failed on me. The comment is the code I wanted to write.
} | ||
|
||
/// A platform-specific atomic integer type. | ||
trait IntegerPlatformAtomic: PlatformAtomic { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand the trait hierarchy that's being defined and I'm under the impression that it may be simplified. Some documentation would help me understand the intent and see whether I'm wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try to simplify it.
} | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
// MARK: Int8PlatformAtomic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A specific reason why all these types are declared in a single file? The usual approach has been to declare one type per file so far. Although it is not a strict convention I'd like to understand why it is not followed here.
No description provided.