Skip to content

V2 API#112

Open
tothambrus11 wants to merge 61 commits into
mainfrom
ambrus/api-v2
Open

V2 API#112
tothambrus11 wants to merge 61 commits into
mainfrom
ambrus/api-v2

Conversation

@tothambrus11
Copy link
Copy Markdown
Member

@tothambrus11 tothambrus11 commented Feb 11, 2026

This PR changes the API so that LLVM reference types no longer look like regular value-semantic objects. The wrappers themselves remained nearly identical, but all methods have been modified to return and take UnsafeReference's to objects of given type, which can be dereferenced via .unsafe[].

The new UnsafeReference type also allowed us to get rid of existentials, and implement a pseudo-subtyping of references through conversion initializers and .erased between AnyType and T: IRType, between AnyValue and T: IRValue, and between AnyAttribute and attribute types.

To reduce the need for .erased in functions that accept AnyValue/AnyType, I modified functions to accept UnsafeReference<some IRType/IRValue>. In case of functons with collection inputs, I added overloads with generic variadic tuple parameters, which are internally type-erased and forwarded to the erased overload. Since AnyType is IRType and AnyValue is IRValue, the tuple based overload works even if some of the arguments are type-erased already.

I completed adding docs for all symbols, looking at LLVM docs where needed. I also added links to the relevant LLVM docs for all intrinsics.

To review the usability of the new API, take a look at hylo-lang/hylo-new#53

@tothambrus11 tothambrus11 force-pushed the ambrus/api-v2 branch 3 times, most recently from 0b72c85 to 4ad826d Compare February 17, 2026 23:09
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 17, 2026

Codecov Report

❌ Patch coverage is 84.12538% with 157 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.32%. Comparing base (591ab6e) to head (a9cb4b7).

Files with missing lines Patch % Lines
Sources/SwiftyLLVM/Module.swift 80.88% 78 Missing ⚠️
Sources/SwiftyLLVM/Refs.swift 55.17% 26 Missing ⚠️
Sources/SwiftyLLVM/Types/FloatingPointType.swift 72.72% 12 Missing ⚠️
Sources/SwiftyLLVM/Attribute.swift 50.00% 9 Missing ⚠️
Sources/SwiftyLLVM/Utils/Unreachable.swift 0.00% 7 Missing ⚠️
Sources/SwiftyLLVM/Backend.swift 85.71% 5 Missing ⚠️
Sources/SwiftyLLVM/AtomicOrdering.swift 62.50% 3 Missing ⚠️
Sources/SwiftyLLVM/TargetMachine.swift 82.35% 3 Missing ⚠️
Sources/SwiftyLLVM/OptimizationLevel.swift 86.66% 2 Missing ⚠️
Sources/SwiftyLLVM/Types/VoidType.swift 66.66% 2 Missing ⚠️
... and 7 more
Additional details and impacted files
@@             Coverage Diff             @@
##             main     #112       +/-   ##
===========================================
+ Coverage   69.20%   84.32%   +15.11%     
===========================================
  Files          50       54        +4     
  Lines        1117     1435      +318     
===========================================
+ Hits          773     1210      +437     
+ Misses        344      225      -119     

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

Comment thread Tests/LLVMTests/CodeGenerationTests.swift Outdated
Comment thread Tests/LLVMTests/EntityStoreTests.swift Outdated
Copy link
Copy Markdown
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.

I don't understand the changes that have been made in C++ files.

I'm not super convinced about the way entity stores work and would prefer if we found a more efficient way to track how entities are being borrowed. I am also not a fan of the pattern using constructor to create temporary objects. I think we should use higher-order functions to that effect.

Comment thread Package.swift Outdated
Comment thread Sources/llvmshims/src/shim.cc
Comment thread Sources/llvmshims/include/shim.h Outdated
Comment thread Sources/SwiftyLLVM/Types/AnyType.swift Outdated
Comment thread Sources/SwiftyLLVM/Types/ArrayType.swift Outdated
Comment thread Sources/SwiftyLLVM/Utils/EntityStore.swift Outdated
Comment thread Sources/SwiftyLLVM/Utils/NonCopyable.swift Outdated
Comment thread Sources/SwiftyLLVM/Utils/NonCopyable.swift Outdated
Comment thread Sources/SwiftyLLVM/Values/Constants/Intrinsic.swift Outdated
Comment thread Sources/SwiftyLLVM/Values/Constants/Parameter.swift Outdated
@tothambrus11 tothambrus11 marked this pull request as ready for review February 28, 2026 20:08
@tothambrus11
Copy link
Copy Markdown
Member Author

@kyouko-taiga Can we merge this?

kyouko-taiga and others added 3 commits May 25, 2026 13:47
…122)

* Add support for controlling the alignement of a store

* Add support for controlling the alignement of a load

* Formatting

* Improve test coverage

* Update Sources/SwiftyLLVM/Values/Instructions/Load.swift

Co-authored-by: Ambrus Tóth <32463042+tothambrus11@users.noreply.github.com>

---------

Co-authored-by: Ambrus Tóth <32463042+tothambrus11@users.noreply.github.com>
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.

3 participants