Skip to content

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Add atomics support in the standard library #1637

wants to merge 10 commits into from

Conversation

lucteo
Copy link
Contributor

@lucteo lucteo commented Dec 20, 2024

No description provided.

Base automatically changed from atomics_store_load_intrinsics to main December 24, 2024 12:24
@lucteo lucteo requested a review from kyouko-taiga January 2, 2025 09:30
This way, we know more about what failed, and not get just "exception".
@lucteo
Copy link
Contributor Author

lucteo commented Jan 3, 2025

@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)?

@kyouko-taiga
Copy link
Contributor

@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.

@lucteo
Copy link
Contributor Author

lucteo commented Jan 9, 2025

The failures can be seen at https://github.com/hylo-lang/hylo/actions/runs/12597537109/job/35110729555?pr=1637.
It shows me the following failed tests:

	  2 - DriverTests (ILLEGAL)
	  3 - ManglingTests (ILLEGAL)
	  4 - HyloTests (ILLEGAL)
	  5 - HyloTests_TestCases_Lowering_0 (ILLEGAL)
	  6 - HyloTests_TestCases_Lowering_1 (ILLEGAL)
	  7 - HyloTests_TestCases_Lowering_2 (ILLEGAL)
	  8 - HyloTests_TestCases_Lowering_3 (ILLEGAL)
	  9 - HyloTests_TestCases_Parsing_0 (ILLEGAL)
	 10 - HyloTests_TestCases_Parsing_1 (ILLEGAL)
	 11 - HyloTests_TestCases_Parsing_2 (ILLEGAL)
	 12 - HyloTests_TestCases_TypeChecking_0 (ILLEGAL)
	 13 - HyloTests_TestCases_TypeChecking_1 (ILLEGAL)
	 14 - HyloTests_TestCases_TypeChecking_2 (ILLEGAL)
	 15 - HyloTests_TestCases_TypeChecking_3 (ILLEGAL)
	 16 - HyloTests_TestCases_TypeChecking_4 (ILLEGAL)
	 17 - HyloTests_TestCases_TypeChecking_5 (ILLEGAL)
	 18 - HyloTests_TestCases_TypeChecking_6 (ILLEGAL)
	 19 - HyloTests_TestCases_TypeChecking_7 (ILLEGAL)
	 20 - HyloTests_TestCases_TypeChecking_8 (ILLEGAL)
	 21 - HyloTests_TestCases_TypeChecking_9 (ILLEGAL)
	 22 - HyloTests_TestCases_TypeChecking_10 (ILLEGAL)
	 23 - EndToEndTests (ILLEGAL)
	 24 - EndToEndTests_TestCases_0 (ILLEGAL)
	 25 - EndToEndTests_TestCases_1 (ILLEGAL)
	 26 - EndToEndTests_TestCases_2 (ILLEGAL)
	 27 - EndToEndTests_TestCases_3 (ILLEGAL)
	 28 - EndToEndTests_TestCases_4 (ILLEGAL)
	 29 - EndToEndTests_TestCases_Concurrency (ILLEGAL)
	 31 - LibraryTests_TestCases_0 (ILLEGAL)
	 32 - LibraryTests_TestCases_1 (ILLEGAL)

Please note that these tests only fail on Ubuntul, I haven't seen any failures on MacOS.

@kyouko-taiga
Copy link
Contributor

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).

Copy link

codecov bot commented Jan 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.75%. Comparing base (890ee11) to head (e1911dc).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@kyouko-taiga kyouko-taiga left a 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.

Comment on lines +3 to +4
///////////////////////////////////////////////////////////////////////////////
// MARK: IntPlatformAtomic
Copy link
Contributor

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.

Copy link
Contributor Author

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 {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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 {
Copy link
Contributor

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?

Copy link
Contributor Author

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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.

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