Skip to content

[Incremental] Add first file removal test #694

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 4 commits into from
Jun 3, 2021

Conversation

davidungar
Copy link
Contributor

  • Adds a bunch of removal test options
  • A facility for testing all combinations of them
  • The first, most basic removal test,
  • A fix for that test, that removes priors if incremental setup fails

Comment on lines 325 to 361
fileprivate enum RemovalTestOption: String, CaseIterable, Comparable, Hashable, CustomStringConvertible {
case
removeInputFromInvocation,
removeSourceFile,
removeEntryFromOutputFileMap,
removeSwiftDepsFile,
restoreBadPriors

private static let byInt = [Int: Self](uniqueKeysWithValues: allCases.enumerated().map{($0, $1)})
private static let intFor = [Self: Int](uniqueKeysWithValues: allCases.enumerated().map{($1, $0)})

var intValue: Int {Self.intFor[self]!}
init(fromInt i: Int) {self = Self.byInt[i]!}

static func < (lhs: RemovalTestOption, rhs: RemovalTestOption) -> Bool {
lhs.intValue < rhs.intValue
}
var mask: Int { 1 << intValue}
static let maxIntValue = allCases.map {$0.intValue} .max()!
static let maxCombinedValue = (1 << maxIntValue) - 1

var description: String { rawValue }
}

/// Only 5 elements, an array is fine
fileprivate typealias RemovalTestOptions = [RemovalTestOption]

extension RemovalTestOptions {
fileprivate static let allCombinations: [RemovalTestOptions] =
(0...RemovalTestOption.maxCombinedValue) .map(decoding)

fileprivate static func decoding(_ bits: Int) -> Self {
RemovalTestOption.allCases.filter { opt in
(1 << opt.intValue) & bits != 0
}
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This feels like a lot of work for something like an option set. However, it

  • avoids manual, error-prone "= ... << 1" for every flag, and
  • prints out symbolically, without code repeating the option names.

Is there a better way?
If not, should this stuff be factored into a protocol on the enumeration?

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 know of a better way, and I think it's fine to leave as-is.
A protocol sounds like it'd be useful if we needed this more broadly but I don't think I can motivate that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Agreed!

@davidungar
Copy link
Contributor Author

@swift-ci please test

@davidungar davidungar requested a review from artemcm June 2, 2021 22:28
@davidungar
Copy link
Contributor Author

@swift-ci please test

Copy link
Contributor

@artemcm artemcm left a comment

Choose a reason for hiding this comment

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

Couple of nits, but if you'd like to merge this and iterate on it to make sure these tests are running, please go ahead.

Comment on lines 325 to 361
fileprivate enum RemovalTestOption: String, CaseIterable, Comparable, Hashable, CustomStringConvertible {
case
removeInputFromInvocation,
removeSourceFile,
removeEntryFromOutputFileMap,
removeSwiftDepsFile,
restoreBadPriors

private static let byInt = [Int: Self](uniqueKeysWithValues: allCases.enumerated().map{($0, $1)})
private static let intFor = [Self: Int](uniqueKeysWithValues: allCases.enumerated().map{($1, $0)})

var intValue: Int {Self.intFor[self]!}
init(fromInt i: Int) {self = Self.byInt[i]!}

static func < (lhs: RemovalTestOption, rhs: RemovalTestOption) -> Bool {
lhs.intValue < rhs.intValue
}
var mask: Int { 1 << intValue}
static let maxIntValue = allCases.map {$0.intValue} .max()!
static let maxCombinedValue = (1 << maxIntValue) - 1

var description: String { rawValue }
}

/// Only 5 elements, an array is fine
fileprivate typealias RemovalTestOptions = [RemovalTestOption]

extension RemovalTestOptions {
fileprivate static let allCombinations: [RemovalTestOptions] =
(0...RemovalTestOption.maxCombinedValue) .map(decoding)

fileprivate static func decoding(_ bits: Int) -> Self {
RemovalTestOption.allCases.filter { opt in
(1 << opt.intValue) & bits != 0
}
}
}
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 know of a better way, and I think it's fine to leave as-is.
A protocol sounds like it'd be useful if we needed this more broadly but I don't think I can motivate that.

}

func testRemoval(includeFailingCombos: Bool) throws {
#if !os(Linux)
Copy link
Contributor

Choose a reason for hiding this comment

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

What's special about Linux here?

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 don't recall at the moment, but these tests don't seem to work there. I'll file a radar.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The tests don't work there. I'll file a radar on myself to investigate.

let knownGoodCombos: [[RemovalTestOption]] = [
[.removeInputFromInvocation],
// next up:
// [.removeInputFromInvocation, .restoreBadPriors],
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: you probably mean some other case in this comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, best to just remove the lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, removing the lines.

removeSwiftDeps(newInput)
}
if options.contains(.removeEntryFromOutputFileMap) {
// FACTOR
Copy link
Contributor

Choose a reason for hiding this comment

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

Which entry is removed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed to removePreviouslyAddedInputFromOutputFileMap

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed for clarity.

@davidungar
Copy link
Contributor Author

@swift-ci please test

@davidungar davidungar merged commit f2a4eec into swiftlang:main Jun 3, 2021
@davidungar
Copy link
Contributor Author

rdar://77998890

@davidungar davidungar deleted the add-remove-2 branch June 18, 2021 21:29
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