Skip to content

Obtain match output elements without materializing the output. #469

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 1 commit into from
Jun 7, 2022

Conversation

rxwei
Copy link
Contributor

@rxwei rxwei commented Jun 4, 2022

Resolves #267.

@rxwei rxwei requested review from milseman and Azoy June 4, 2022 00:43
@rxwei
Copy link
Contributor Author

rxwei commented Jun 4, 2022

@swift-ci please test

@rxwei rxwei force-pushed the fix-267 branch 2 times, most recently from 36cbe78 to 59e77ba Compare June 4, 2022 00:48
@rxwei
Copy link
Contributor Author

rxwei commented Jun 4, 2022

@swift-ci please test

@rxwei
Copy link
Contributor Author

rxwei commented Jun 4, 2022

@swift-ci please test

func sizeAndAlignMask<T>(_: T.Type) -> (Int, Int) {
(MemoryLayout<T>.size, MemoryLayout<T>.alignment - 1)
}
// The ABI of an offset-based key path only stores the byte offset, so
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lorentey just reminded me of this... 😭

> \(Void, Void).0 == \(Void, Void).1
$R0: Bool = true

@Azoy, do you have the radar number for this issue I can put in the comment?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rdar://63819465

@rxwei
Copy link
Contributor Author

rxwei commented Jun 4, 2022

@swift-ci please test

output[keyPath: keyPath]
// Note: We should be able to get the element offset from the key path
// itself even at compile time. We need a better way of doing this.
guard let outputTupleOffset = MemoryLayout.tupleElementIndex(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we store the whole match inside the capture list, we will be able to precompute these offsets for all elements in a Regex.Match. I'll do that next.

@rxwei
Copy link
Contributor Author

rxwei commented Jun 5, 2022

@swift-ci please test

Copy link
Member

@milseman milseman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be useful to write tests where a capture transform produces a Substring by e.g. returning .dropFirst(). Similarly for when that capture-transform appears inside an Optionally or is adding or removing a layer of Substring optionality.

)
return typeErasedMatch as! Output
}
}

var wholeMatchType: Any.Type {
value.map { type(of: $0) } ?? Substring.self
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if it's optional? Also, are we tracking nested optionals correctly here (I.e. do they get turned into values or are they counted)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When there's no dedicated value for whole match, it can only be a Substring.

@rxwei
Copy link
Contributor Author

rxwei commented Jun 7, 2022

@swift-ci please test

@rxwei rxwei merged commit a7001b1 into swiftlang:main Jun 7, 2022
@rxwei rxwei deleted the fix-267 branch June 7, 2022 20:30
natecook1000 pushed a commit to natecook1000/swift-experimental-string-processing that referenced this pull request Jun 17, 2022
Obtain match output elements without materializing the output.
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.

Regex.Match element accessors should not materialize the whole output
3 participants