Skip to content

Update swift main #674

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

Merged
merged 39 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
0b38ca9
Atomically load the lowered program (#610)
natecook1000 Oct 6, 2022
335a0c2
Add tests for line start/end word boundary diffs (#616)
natecook1000 Dec 2, 2022
54ff516
Add tweaks for Android
finagolfin Dec 5, 2022
eb7f801
Fix documentation typo (#615)
ole Dec 6, 2022
c51e8f2
Fix abstract for Regex.dotMatchesNewlines(_:). (#614)
amartini51 Dec 6, 2022
45f752a
Remove `RegexConsumer` and fix its dependencies (#617)
natecook1000 Dec 14, 2022
ed95066
Improve StringProcessing and RegexBuilder documentation (#611)
natecook1000 Dec 14, 2022
c34cea5
Set availability for inverted character class test (#621)
natecook1000 Dec 16, 2022
3ca8b13
Merge pull request #618 from buttaface/droid
Azoy Dec 18, 2022
3a3dc7a
Add type annotations in RegexBuilder tests
natecook1000 Feb 1, 2023
6c4f291
Workaround for fileprivate array issue
natecook1000 Feb 1, 2023
7e059b7
Merge pull request #628 from apple/result_builder_changes_workaround
natecook1000 Feb 1, 2023
6a4077f
Fix an issue where named character classes weren't getting converted …
DaveEwing Feb 1, 2023
8184fc0
Merge pull request #629 from apple/dewing/CharacterClassDSLConversion
DaveEwing Feb 2, 2023
2a78475
Stop at end of search string in TwoWaySearcher (#631)
natecook1000 Feb 8, 2023
d5a6cec
Correct misspelling in DSL renderer (#627)
natecook1000 Feb 8, 2023
7756942
Fix output type mismatch with RegexBuilder (#626)
natecook1000 Feb 9, 2023
070e0ec
Revert "Merge pull request #628 from apple/result_builder_changes_wor…
natecook1000 Feb 15, 2023
1358fc0
Use `some` syntax in variadics
natecook1000 Feb 15, 2023
083d32a
Type checker workaround: adjust test
milseman Apr 2, 2023
ca92db7
Further refactor to work around type checker regression
milseman Apr 3, 2023
336f9c5
Merge pull request #643 from milseman/typechecker_workaround
milseman Apr 3, 2023
852b890
Align availability macro with OS versions (#641)
milseman Apr 4, 2023
236b47c
Speed up general character class matching (#642)
milseman Apr 4, 2023
348e6c3
Test for \s matching CRLF when scalar matching (#648)
natecook1000 Apr 4, 2023
a7ba701
General ascii fast paths for character classes (#644)
milseman Apr 4, 2023
e01e43d
Remove the unsupported `anyScalar` case (#650)
natecook1000 Apr 4, 2023
e0352a2
Fix range-based quantification fast path (#653)
natecook1000 Apr 11, 2023
923cf5e
Add in ASCII fast-path for anyNonNewline (#654)
milseman Apr 11, 2023
9ea9936
Avoid long expression type checks (#657)
natecook1000 Apr 11, 2023
58626cc
Processor cleanup (#655)
milseman Apr 14, 2023
4418183
Fix `firstRange(of:)` search (#656)
natecook1000 Apr 14, 2023
57b343d
Bug fix and hot path for quantified `.` (#658)
milseman Apr 18, 2023
6695027
Run scalar-semantic benchmark variants (#659)
milseman Apr 18, 2023
8eafd55
Refactor operations to be on String (#664)
milseman Apr 19, 2023
0354667
Provide unique generic method parameter names (#669)
natecook1000 May 16, 2023
98d5ddc
Enable quantification optimizations for scalar semantics (#671)
milseman May 22, 2023
84bc9c8
Merge remote-tracking branch 'origin/main' into swift/main
milseman May 22, 2023
59fce2f
Remove redundant test
milseman May 24, 2023
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
Prev Previous commit
Next Next commit
Remove RegexConsumer and fix its dependencies (#617)
* Remove `RegexConsumer` and fix its dependencies

This eliminates the RegexConsumer type and rewrites its users to call
through to other, existing functionality on Regex or in the Algorithms
implementations. RegexConsumer doesn't take account of the dual
subranges required for matching, so it can produce results that are
inconsistent with matches(of:) and ranges(of:), which were rewritten
earlier.

rdar://102841216

* Remove remaining from-end algorithm methods

This removes methods that are left over from when we were considering
from-end algorithms. These aren't tested and may not have the correct
semantics, so it's safer to remove them entirely.
  • Loading branch information
natecook1000 authored Dec 14, 2022
commit 45f752ab2db496db4396ca796787bbc441739038
17 changes: 2 additions & 15 deletions Sources/_StringProcessing/Algorithms/Algorithms/FirstRange.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@ extension Collection {
}
}

extension BidirectionalCollection {
func _lastRange<S: BackwardCollectionSearcher>(
of searcher: S
) -> Range<Index>? where S.BackwardSearched == Self {
var state = searcher.backwardState(for: self, in: startIndex..<endIndex)
return searcher.searchBack(self, &state)
}
}

// MARK: Fixed pattern algorithms

extension Collection where Element: Equatable {
Expand Down Expand Up @@ -78,11 +69,7 @@ extension BidirectionalCollection where SubSequence == Substring {
@_disfavoredOverload
@available(SwiftStdlib 5.7, *)
public func firstRange(of regex: some RegexComponent) -> Range<Index>? {
_firstRange(of: RegexConsumer(regex))
}

@available(SwiftStdlib 5.7, *)
func _lastRange<R: RegexComponent>(of regex: R) -> Range<Index>? {
_lastRange(of: RegexConsumer(regex))
let s = self[...]
return try? regex.regex.firstMatch(in: s)?.range
}
}
83 changes: 0 additions & 83 deletions Sources/_StringProcessing/Algorithms/Algorithms/Ranges.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,43 +115,6 @@ extension RangesCollection.Index: Comparable {
}
}

// MARK: `ReversedRangesCollection`

struct ReversedRangesCollection<Searcher: BackwardCollectionSearcher> {
typealias Base = Searcher.BackwardSearched

let base: Base
let searcher: Searcher

init(base: Base, searcher: Searcher) {
self.base = base
self.searcher = searcher
}
}

extension ReversedRangesCollection: Sequence {
public struct Iterator: IteratorProtocol {
let base: Base
let searcher: Searcher
var state: Searcher.BackwardState

init(base: Base, searcher: Searcher) {
self.base = base
self.searcher = searcher
self.state = searcher.backwardState(
for: base, in: base.startIndex..<base.endIndex)
}

public mutating func next() -> Range<Base.Index>? {
searcher.searchBack(base, &state)
}
}

public func makeIterator() -> Iterator {
Iterator(base: base, searcher: searcher)
}
}

// TODO: `Collection` conformance

// MARK: `CollectionSearcher` algorithms
Expand All @@ -164,14 +127,6 @@ extension Collection {
}
}

extension BidirectionalCollection {
func _rangesFromBack<S: BackwardCollectionSearcher>(
of searcher: S
) -> ReversedRangesCollection<S> where S.BackwardSearched == Self {
ReversedRangesCollection(base: self, searcher: searcher)
}
}

// MARK: Fixed pattern algorithms

extension Collection where Element: Equatable {
Expand All @@ -195,37 +150,6 @@ extension Collection where Element: Equatable {
}
}

extension BidirectionalCollection where Element: Equatable {
// FIXME
// public func rangesFromBack<S: Sequence>(
// of other: S
// ) -> ReversedRangesCollection<ZSearcher<SubSequence>>
// where S.Element == Element
// {
// fatalError()
// }
}

extension BidirectionalCollection where Element: Comparable {
func _ranges<C: Collection>(
of other: C
) -> RangesCollection<PatternOrEmpty<TwoWaySearcher<Self>>>
where C.Element == Element
{
_ranges(of: PatternOrEmpty(searcher: TwoWaySearcher(pattern: Array(other))))
}

// FIXME
// public func rangesFromBack<S: Sequence>(
// of other: S
// ) -> ReversedRangesCollection<PatternOrEmpty<TwoWaySearcher<SubSequence>>>
// where S.Element == Element
// {
// rangesFromBack(
// of: PatternOrEmpty(searcher: TwoWaySearcher(pattern: Array(other))))
// }
}

@available(SwiftStdlib 5.7, *)
struct RegexRangesCollection<Output> {
let base: RegexMatchesCollection<Output>
Expand Down Expand Up @@ -299,13 +223,6 @@ extension Collection where SubSequence == Substring {
}

extension BidirectionalCollection where SubSequence == Substring {
@available(SwiftStdlib 5.7, *)
func _rangesFromBack<R: RegexComponent>(
of regex: R
) -> ReversedRangesCollection<RegexConsumer<R, Self>> {
_rangesFromBack(of: RegexConsumer(regex))
}

// FIXME: Return `some Collection<Range<Index>>` for SE-0346
/// Finds and returns the ranges of the all occurrences of a given sequence
/// within the collection.
Expand Down
189 changes: 29 additions & 160 deletions Sources/_StringProcessing/Algorithms/Algorithms/Split.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,121 +106,6 @@ extension SplitCollection: Sequence {
}
}

//extension SplitCollection: Collection {
// public struct Index {
// var start: Base.Index
// var base: RangesCollection<Searcher>.Index
// var isEndIndex: Bool
// }
//
// public var startIndex: Index {
// let base = ranges.startIndex
// return Index(start: ranges.base.startIndex, base: base, isEndIndex: false)
// }
//
// public var endIndex: Index {
// Index(start: ranges.base.endIndex, base: ranges.endIndex, isEndIndex: true)
// }
//
// public func formIndex(after index: inout Index) {
// guard !index.isEndIndex else { fatalError("Cannot advance past endIndex") }
//
// if let range = index.base.range {
// let newStart = range.upperBound
// ranges.formIndex(after: &index.base)
// index.start = newStart
// } else {
// index.isEndIndex = true
// }
// }
//
// public func index(after index: Index) -> Index {
// var index = index
// formIndex(after: &index)
// return index
// }
//
// public subscript(index: Index) -> Base.SubSequence {
// guard !index.isEndIndex else {
// fatalError("Cannot subscript using endIndex")
// }
// let end = index.base.range?.lowerBound ?? ranges.base.endIndex
// return ranges.base[index.start..<end]
// }
//}
//
//extension SplitCollection.Index: Comparable {
// static func == (lhs: Self, rhs: Self) -> Bool {
// switch (lhs.isEndIndex, rhs.isEndIndex) {
// case (false, false):
// return lhs.start == rhs.start
// case (let lhs, let rhs):
// return lhs == rhs
// }
// }
//
// static func < (lhs: Self, rhs: Self) -> Bool {
// switch (lhs.isEndIndex, rhs.isEndIndex) {
// case (true, _):
// return false
// case (_, true):
// return true
// case (false, false):
// return lhs.start < rhs.start
// }
// }
//}

// MARK: `ReversedSplitCollection`

struct ReversedSplitCollection<Searcher: BackwardCollectionSearcher> {
public typealias Base = Searcher.BackwardSearched

let ranges: ReversedRangesCollection<Searcher>

init(ranges: ReversedRangesCollection<Searcher>) {
self.ranges = ranges
}

init(base: Base, searcher: Searcher) {
self.ranges = base._rangesFromBack(of: searcher)
}
}

extension ReversedSplitCollection: Sequence {
public struct Iterator: IteratorProtocol {
let base: Base
var index: Base.Index
var ranges: ReversedRangesCollection<Searcher>.Iterator
var isDone: Bool

init(ranges: ReversedRangesCollection<Searcher>) {
self.base = ranges.base
self.index = base.endIndex
self.ranges = ranges.makeIterator()
self.isDone = false
}

public mutating func next() -> Base.SubSequence? {
guard !isDone else { return nil }

guard let range = ranges.next() else {
isDone = true
return base[..<index]
}

defer { index = range.lowerBound }
return base[range.upperBound..<index]
}
}

public func makeIterator() -> Iterator {
Iterator(ranges: ranges)
}
}

// TODO: `Collection` conformance

// MARK: `CollectionSearcher` algorithms

extension Collection {
Expand All @@ -237,16 +122,6 @@ extension Collection {
}
}

extension BidirectionalCollection {
func splitFromBack<Searcher: BackwardCollectionSearcher>(
by separator: Searcher
) -> ReversedSplitCollection<Searcher>
where Searcher.BackwardSearched == Self
{
ReversedSplitCollection(base: self, searcher: separator)
}
}

// MARK: Predicate algorithms

extension Collection {
Expand All @@ -260,14 +135,6 @@ extension Collection {
}
}

extension BidirectionalCollection where Element: Equatable {
func splitFromBack(
whereSeparator predicate: @escaping (Element) -> Bool
) -> ReversedSplitCollection<PredicateConsumer<Self>> {
splitFromBack(by: PredicateConsumer(predicate: predicate))
}
}

// MARK: Single element algorithms

extension Collection where Element: Equatable {
Expand All @@ -280,14 +147,6 @@ extension Collection where Element: Equatable {
}
}

extension BidirectionalCollection where Element: Equatable {
func splitFromBack(
by separator: Element
) -> ReversedSplitCollection<PredicateConsumer<Self>> {
splitFromBack(whereSeparator: { $0 == separator })
}
}

// MARK: Fixed pattern algorithms

extension Collection where Element: Equatable {
Expand Down Expand Up @@ -399,21 +258,6 @@ extension StringProtocol where SubSequence == Substring {

@available(SwiftStdlib 5.7, *)
extension BidirectionalCollection where SubSequence == Substring {
@_disfavoredOverload
func split<R: RegexComponent>(
by separator: R,
maxSplits: Int,
omittingEmptySubsequences: Bool
) -> SplitCollection<RegexConsumer<R, Self>> {
split(by: RegexConsumer(separator), maxSplits: maxSplits, omittingEmptySubsequences: omittingEmptySubsequences)
}

func splitFromBack<R: RegexComponent>(
by separator: R
) -> ReversedSplitCollection<RegexConsumer<R, Self>> {
splitFromBack(by: RegexConsumer(separator))
}

// TODO: Is this @_disfavoredOverload necessary?
// It prevents split(separator: String) from choosing this overload instead
// of the collection-based version when String has RegexComponent conformance
Expand All @@ -431,9 +275,34 @@ extension BidirectionalCollection where SubSequence == Substring {
maxSplits: Int = .max,
omittingEmptySubsequences: Bool = true
) -> [SubSequence] {
Array(split(
by: RegexConsumer(separator),
maxSplits: maxSplits,
omittingEmptySubsequences: omittingEmptySubsequences))
var result: [SubSequence] = []
var subSequenceStart = startIndex

func appendSubsequence(end: Index) -> Bool {
if subSequenceStart == end && omittingEmptySubsequences {
return false
}
result.append(self[subSequenceStart..<end])
return true
}

guard maxSplits > 0 && !isEmpty else {
_ = appendSubsequence(end: endIndex)
return result
}

for match in _matches(of: separator) {
defer { subSequenceStart = match.range.upperBound }
let didAppend = appendSubsequence(end: match.range.lowerBound)
if didAppend && result.count == maxSplits {
break
}
}

if subSequenceStart != endIndex || !omittingEmptySubsequences {
result.append(self[subSequenceStart..<endIndex])
}

return result
}
}
Loading