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

Make 'AccessEffectSet.Elements' conform to 'Collection' #1019

Merged
merged 3 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/CodeGen/LLVM/Transpilation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ extension LLVM.Module {
let transpilation = declareFunction(ir.base.mangled(f), .init(from: parameters, in: &self))

configureAttributes(transpilation, transpiledFrom: f, of: m)
configureInputAttributes(transpilation.parameters.dropFirst(), transpiledFrom: f, in: m)
configureInputAttributes(transpilation.parameters.dropLast(), transpiledFrom: f, in: m)

return transpilation
}
Expand Down
45 changes: 25 additions & 20 deletions Sources/Core/AccessEffectSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public struct AccessEffectSet: OptionSet, Hashable {

/// The weakest capability in `self`, or `nil` if `self` is empty.
public var weakest: AccessEffect? {
var s = elements
return s.next()
elements.first
}

/// Returns the strongest capability in `self` including `k`.
Expand Down Expand Up @@ -74,33 +73,39 @@ public struct AccessEffectSet: OptionSet, Hashable {

extension AccessEffectSet {

/// A sequence with the elements of an access effect set.
public struct Elements: Sequence, IteratorProtocol {
/// A collection with the elements of an access effect set.
public struct Elements: Collection {

public typealias Index = UInt8

public typealias Element = AccessEffect

/// The contents of the set being iterated over.
private let base: AccessEffectSet

/// The next effect returned by the iterator.
private var position: UInt8

/// Creates an iterator over `s`.
public init(_ s: AccessEffectSet) {
self.base = s
self.position = s.rawValue & (~s.rawValue + 1)
if self.position == 0 {
self.position = 1 << 7
}
}

/// Returns the next element in the sequence.
public mutating func next() -> AccessEffect? {
if position == (1 << 7) { return nil }
defer {
repeat {
position = position << 1
} while (position != (1 << 7)) && ((position & base.rawValue) != position)
}
return .init(rawValue: position)
public var startIndex: UInt8 {
base.rawValue & (~base.rawValue + 1)
}

public var endIndex: UInt8 {
1 << 7
}

public func index(after position: UInt8) -> UInt8 {
var next = position
repeat {
next = next << 1
} while (next != endIndex) && ((next & base.rawValue) != next)
return next
}

public subscript(position: UInt8) -> AccessEffect {
AccessEffect(rawValue: position)!
}

}
Expand Down
Loading